Advertisement
Guest User

Untitled

a guest
Sep 29th, 2016
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.75 KB | None | 0 0
  1. package org.jleaf.pos2.bo.productmerchantcommission;
  2.  
  3. import org.jleaf.common.ComboIdConstants;
  4. import org.jleaf.core.BusinessFunction;
  5. import org.jleaf.core.BusinessTransaction;
  6. import org.jleaf.core.CoreException;
  7. import org.jleaf.core.DefaultBusinessTransaction;
  8. import org.jleaf.core.Dto;
  9. import org.jleaf.core.GeneralConstants;
  10. import org.jleaf.core.annotation.ErrorList;
  11. import org.jleaf.core.annotation.Info;
  12. import org.jleaf.core.annotation.InfoIn;
  13. import org.jleaf.core.annotation.InfoOut;
  14. import org.jleaf.pos2.PosComboIdMasterConstans;
  15. import org.jleaf.pos2.PosMasterConstants;
  16. import org.jleaf.pos2.PosMasterExceptionConstants;
  17. import org.jleaf.pos2.dao.ProductMerchantCommissionDao;
  18. import org.jleaf.pos2.entity.Product;
  19. import org.jleaf.pos2.entity.ProductMerchantCommission;
  20. import org.jleaf.pos2.util.PosUtil;
  21. import org.jleaf.util.GsonUtil;
  22. import org.jleaf.util.ValidationUtil;
  23. import org.jleaf.validator.CommonBusinessValidator;
  24. import org.springframework.beans.factory.annotation.Autowired;
  25. import org.springframework.beans.factory.annotation.Qualifier;
  26. import org.springframework.stereotype.Service;
  27.  
  28. @Service
  29. @InfoIn(value= {
  30. @Info(name = "productCode", description = "Product code", type = String.class, required = true),
  31. @Info(name = "merchantGroupProductCode", description = "Merchant group product code", type = String.class, required = true),
  32. @Info(name = "active", description = "active", type = String.class),
  33. @Info(name = "userLoginId", description = "user login id", type = Long.class),
  34. @Info(name = "userLoginName", description = "user login name", type = String.class),
  35. @Info(name = "roleLoginId", description = "role login id", type = Long.class),
  36. @Info(name = "roleLoginName", description = "role login name", type = String.class),
  37. @Info(name = "datetime", description = "date time", type = String.class)
  38. })
  39.  
  40. @InfoOut(value = {
  41. @Info(name = "productCode", description = "Product code", type = String.class, required = true),
  42. @Info(name = "merchantGroupProductCode", description = "Merchant group product code", type = String.class, required = true),
  43. @Info(name = "active", description = "Active", type = String.class, required = true),
  44. @Info(name = "activeDateTime", description = "Active date time", type = String.class, required = true),
  45. @Info(name = "nonActiveDateTime", description = "Non active date time", type = String.class, required = true),
  46. @Info(name = "createUsername", description = "create username", type = String.class),
  47. @Info(name = "updateUsername", description = "update username", type = String.class),
  48. @Info(name = "createDateTime", description = "create date time", type = String.class),
  49. @Info(name = "updateDateTime", description = "update date time", type = String.class),
  50. @Info(name = "version", description = "version", type = Long.class)
  51. })
  52. @ErrorList(errorKeys={
  53.  
  54. })
  55. public class EditProductMerchant extends DefaultBusinessTransaction implements BusinessTransaction{
  56.  
  57. @Autowired
  58. ProductMerchantDao productMerchantDao;
  59.  
  60. @Autowired
  61. @Qualifier("isProductMerchantExistsById")
  62. BusinessFunction isProductMerchantExistsById;
  63.  
  64. @Autowired
  65. @Qualifier("findMerchantGroupProductById")
  66. BusinessFunction findMerchantGroupProductById;
  67.  
  68. @Autowired
  69. @Qualifier("valComboValueByCode")
  70. BusinessFunction valComboValueByCode;
  71.  
  72. @Autowired
  73. @Qualifier("findProductById")
  74. BusinessFunction findProductById;
  75.  
  76. @Override
  77. public String getDescription() {
  78. return "edit product merchant";
  79. }
  80.  
  81. @Override
  82. public Dto prepare(Dto inputDto, Dto originalDto) throws Exception {
  83. ValidationUtil.valBlankOrNull(inputDto, "productCode");
  84. ValidationUtil.valBlankOrNull(inputDto, "merchantGroupProductCode");
  85.  
  86. ValidationUtil.valDtoContainsKey(inputDto, "userLoginId");
  87. ValidationUtil.valDtoContainsKey(inputDto, "roleLoginId");
  88. ValidationUtil.valBlankOrNull(inputDto, "userLoginName");
  89. ValidationUtil.valBlankOrNull(inputDto, "roleLoginName");
  90. ValidationUtil.valDatetime(inputDto, "datetime");
  91.  
  92. valComboValueByCode(inputDto, "active");
  93.  
  94. // Validation merchant product code must exists
  95. findMerchantGroupProductById.execute(new Dto().put("merchantGroupProductCode", inputDto.getString("merchantGroupProductCode")));
  96.  
  97. // Validation product code must exists
  98. findProductById.execute(new Dto().put("productCode", inputDto.getString("productCode")));
  99.  
  100. // Validation data (business key) is not exists yet in db (add)
  101. Dto paramCheckUniqueDto = new Dto();
  102. paramCheckUniqueDto.put("productCode", inputDto.getString("productCode"));
  103. paramCheckUniqueDto.put("merchantGroupProductCode", inputDto.getString("merchantGroupProductCode"));
  104. Dto resultCheckUniqueDto = isProductMerchantExistsById.execute(paramCheckUniqueDto);
  105.  
  106. if (resultCheckUniqueDto.getBoolean("exists")) {
  107. throw new CoreException(PosMasterExceptionConstants.PRODUCT_MERCHANT_ALREADY_EXISTS, resultCheckUniqueDto.getString("productMerchantDto.productMerchantPk.productCode"), resultCheckUniqueDto.getString("productMerchantDto.productMerchantPk.merchantGroupProductCode"));
  108. }
  109.  
  110. Dto productMerchantDto = new Dto();
  111. productMerchantDto.put("productMerchantPk.productCode", inputDto.getString("productCode"));
  112. productMerchantDto.put("productMerchantPk.merchantGroupProductCode", inputDto.getString("merchantGroupProductCode"));
  113.  
  114. // Set active datetime if active = Y
  115. if (inputDto.getString("active").equals(GeneralConstants.YES)) {
  116. productMerchantDto.put("activeDateTime", inputDto.get("datetime"));
  117. productMerchantDto.put("nonActiveDateTime", GeneralConstants.SPACE_VALUE);
  118. } else {
  119. productMerchantDto.put("activeDateTime", GeneralConstants.SPACE_VALUE);
  120. productMerchantDto.put("nonActiveDateTime", GeneralConstants.SPACE_VALUE);
  121. }
  122.  
  123. PosUtil.prepareInsertAudit(productMerchantDto, inputDto.getString("userLoginName"), inputDto.getString("datetime"));
  124. PosUtil.prepareUpdateAudit(productMerchantDto, inputDto.getString("userLoginName"), inputDto.getString("datetime"));
  125.  
  126. inputDto.put("productMerchantDto", productMerchantDto);
  127.  
  128. return null;
  129. }
  130. @Override
  131. public Dto process(Dto inputDto, Dto originalDto) throws Exception {
  132. Dto productMerchantDto = inputDto.getDto("productMerchantDto");
  133.  
  134. ProductMerchant productMerchant = GsonUtil.fromDto(productMerchantDto, ProductMerchant.class);
  135. productMerchantDao.persist(productMerchant);
  136. return new Dto(productMerchant);
  137. }
  138.  
  139. private void valComboValueByCode(Dto inputDto, String paramKey) throws Exception {
  140. Dto paramDto = new Dto();
  141. paramDto.put("comboId", ComboIdConstants.COMBO_YES_NO);
  142. paramDto.put("code", inputDto.getString(paramKey));
  143. paramDto.put("varName", paramKey);
  144. valComboValueByCode.execute(paramDto);
  145. }
  146. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement