Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package org.jleaf.pos2.bo.productmerchantcommission;
- import org.jleaf.common.ComboIdConstants;
- import org.jleaf.core.BusinessFunction;
- import org.jleaf.core.BusinessTransaction;
- import org.jleaf.core.CoreException;
- import org.jleaf.core.DefaultBusinessTransaction;
- import org.jleaf.core.Dto;
- import org.jleaf.core.GeneralConstants;
- import org.jleaf.core.annotation.ErrorList;
- import org.jleaf.core.annotation.Info;
- import org.jleaf.core.annotation.InfoIn;
- import org.jleaf.core.annotation.InfoOut;
- import org.jleaf.pos2.PosComboIdMasterConstans;
- import org.jleaf.pos2.PosMasterConstants;
- import org.jleaf.pos2.PosMasterExceptionConstants;
- import org.jleaf.pos2.dao.ProductMerchantCommissionDao;
- import org.jleaf.pos2.entity.Product;
- import org.jleaf.pos2.entity.ProductMerchantCommission;
- import org.jleaf.pos2.util.PosUtil;
- import org.jleaf.util.GsonUtil;
- import org.jleaf.util.ValidationUtil;
- import org.jleaf.validator.CommonBusinessValidator;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.beans.factory.annotation.Qualifier;
- import org.springframework.stereotype.Service;
- @Service
- @InfoIn(value= {
- @Info(name = "productCode", description = "Product code", type = String.class, required = true),
- @Info(name = "merchantGroupProductCode", description = "Merchant group product code", type = String.class, required = true),
- @Info(name = "active", description = "active", type = String.class),
- @Info(name = "userLoginId", description = "user login id", type = Long.class),
- @Info(name = "userLoginName", description = "user login name", type = String.class),
- @Info(name = "roleLoginId", description = "role login id", type = Long.class),
- @Info(name = "roleLoginName", description = "role login name", type = String.class),
- @Info(name = "datetime", description = "date time", type = String.class)
- })
- @InfoOut(value = {
- @Info(name = "productCode", description = "Product code", type = String.class, required = true),
- @Info(name = "merchantGroupProductCode", description = "Merchant group product code", type = String.class, required = true),
- @Info(name = "active", description = "Active", type = String.class, required = true),
- @Info(name = "activeDateTime", description = "Active date time", type = String.class, required = true),
- @Info(name = "nonActiveDateTime", description = "Non active date time", type = String.class, required = true),
- @Info(name = "createUsername", description = "create username", type = String.class),
- @Info(name = "updateUsername", description = "update username", type = String.class),
- @Info(name = "createDateTime", description = "create date time", type = String.class),
- @Info(name = "updateDateTime", description = "update date time", type = String.class),
- @Info(name = "version", description = "version", type = Long.class)
- })
- @ErrorList(errorKeys={
- })
- public class EditProductMerchant extends DefaultBusinessTransaction implements BusinessTransaction{
- @Autowired
- ProductMerchantDao productMerchantDao;
- @Autowired
- @Qualifier("isProductMerchantExistsById")
- BusinessFunction isProductMerchantExistsById;
- @Autowired
- @Qualifier("findMerchantGroupProductById")
- BusinessFunction findMerchantGroupProductById;
- @Autowired
- @Qualifier("valComboValueByCode")
- BusinessFunction valComboValueByCode;
- @Autowired
- @Qualifier("findProductById")
- BusinessFunction findProductById;
- @Override
- public String getDescription() {
- return "edit product merchant";
- }
- @Override
- public Dto prepare(Dto inputDto, Dto originalDto) throws Exception {
- ValidationUtil.valBlankOrNull(inputDto, "productCode");
- ValidationUtil.valBlankOrNull(inputDto, "merchantGroupProductCode");
- ValidationUtil.valDtoContainsKey(inputDto, "userLoginId");
- ValidationUtil.valDtoContainsKey(inputDto, "roleLoginId");
- ValidationUtil.valBlankOrNull(inputDto, "userLoginName");
- ValidationUtil.valBlankOrNull(inputDto, "roleLoginName");
- ValidationUtil.valDatetime(inputDto, "datetime");
- valComboValueByCode(inputDto, "active");
- // Validation merchant product code must exists
- findMerchantGroupProductById.execute(new Dto().put("merchantGroupProductCode", inputDto.getString("merchantGroupProductCode")));
- // Validation product code must exists
- findProductById.execute(new Dto().put("productCode", inputDto.getString("productCode")));
- // Validation data (business key) is not exists yet in db (add)
- Dto paramCheckUniqueDto = new Dto();
- paramCheckUniqueDto.put("productCode", inputDto.getString("productCode"));
- paramCheckUniqueDto.put("merchantGroupProductCode", inputDto.getString("merchantGroupProductCode"));
- Dto resultCheckUniqueDto = isProductMerchantExistsById.execute(paramCheckUniqueDto);
- if (resultCheckUniqueDto.getBoolean("exists")) {
- throw new CoreException(PosMasterExceptionConstants.PRODUCT_MERCHANT_ALREADY_EXISTS, resultCheckUniqueDto.getString("productMerchantDto.productMerchantPk.productCode"), resultCheckUniqueDto.getString("productMerchantDto.productMerchantPk.merchantGroupProductCode"));
- }
- Dto productMerchantDto = new Dto();
- productMerchantDto.put("productMerchantPk.productCode", inputDto.getString("productCode"));
- productMerchantDto.put("productMerchantPk.merchantGroupProductCode", inputDto.getString("merchantGroupProductCode"));
- // Set active datetime if active = Y
- if (inputDto.getString("active").equals(GeneralConstants.YES)) {
- productMerchantDto.put("activeDateTime", inputDto.get("datetime"));
- productMerchantDto.put("nonActiveDateTime", GeneralConstants.SPACE_VALUE);
- } else {
- productMerchantDto.put("activeDateTime", GeneralConstants.SPACE_VALUE);
- productMerchantDto.put("nonActiveDateTime", GeneralConstants.SPACE_VALUE);
- }
- PosUtil.prepareInsertAudit(productMerchantDto, inputDto.getString("userLoginName"), inputDto.getString("datetime"));
- PosUtil.prepareUpdateAudit(productMerchantDto, inputDto.getString("userLoginName"), inputDto.getString("datetime"));
- inputDto.put("productMerchantDto", productMerchantDto);
- return null;
- }
- @Override
- public Dto process(Dto inputDto, Dto originalDto) throws Exception {
- Dto productMerchantDto = inputDto.getDto("productMerchantDto");
- ProductMerchant productMerchant = GsonUtil.fromDto(productMerchantDto, ProductMerchant.class);
- productMerchantDao.persist(productMerchant);
- return new Dto(productMerchant);
- }
- private void valComboValueByCode(Dto inputDto, String paramKey) throws Exception {
- Dto paramDto = new Dto();
- paramDto.put("comboId", ComboIdConstants.COMBO_YES_NO);
- paramDto.put("code", inputDto.getString(paramKey));
- paramDto.put("varName", paramKey);
- valComboValueByCode.execute(paramDto);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement