From b8d1f25f4fdb9d8bc109c103e84307d6925ce218 Mon Sep 17 00:00:00 2001
From: wuxw <928255095@qq.com>
Date: 星期三, 21 十二月 2022 17:16:04 +0800
Subject: [PATCH] 优化代码

---
 service-acct/src/main/java/com/java110/acct/cmd/couponRule/SaveCouponRuleFeeCmd.java |   39 ++++++++++++++++++++++++++++++++-------
 1 files changed, 32 insertions(+), 7 deletions(-)

diff --git a/service-acct/src/main/java/com/java110/acct/cmd/couponRule/SaveCouponRuleFeeCmd.java b/service-acct/src/main/java/com/java110/acct/cmd/couponRule/SaveCouponRuleFeeCmd.java
index 65a5e80..f5e4e64 100644
--- a/service-acct/src/main/java/com/java110/acct/cmd/couponRule/SaveCouponRuleFeeCmd.java
+++ b/service-acct/src/main/java/com/java110/acct/cmd/couponRule/SaveCouponRuleFeeCmd.java
@@ -22,15 +22,20 @@
 import com.java110.core.event.cmd.Cmd;
 import com.java110.core.event.cmd.CmdEvent;
 import com.java110.core.factory.GenerateCodeFactory;
+import com.java110.dto.couponRuleFee.CouponRuleFeeDto;
+import com.java110.dto.fee.FeeConfigDto;
 import com.java110.intf.acct.ICouponRuleFeeV1InnerServiceSMO;
+import com.java110.intf.fee.IFeeConfigInnerServiceSMO;
 import com.java110.po.couponRuleFee.CouponRuleFeePo;
 import com.java110.utils.exception.CmdException;
 import com.java110.utils.util.Assert;
 import com.java110.utils.util.BeanConvertUtil;
 import com.java110.vo.ResultVo;
-import org.springframework.beans.factory.annotation.Autowired;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+
+import java.util.List;
 
 /**
  * 绫昏〃杩帮細淇濆瓨
@@ -52,14 +57,27 @@
     @Autowired
     private ICouponRuleFeeV1InnerServiceSMO couponRuleFeeV1InnerServiceSMOImpl;
 
+    @Autowired
+    private IFeeConfigInnerServiceSMO feeConfigInnerServiceSMOImpl;
+
+
     @Override
     public void validate(CmdEvent event, ICmdDataFlowContext cmdDataFlowContext, JSONObject reqJson) {
         Assert.hasKeyAndValue(reqJson, "ruleId", "璇锋眰鎶ユ枃涓湭鍖呭惈ruleId");
-Assert.hasKeyAndValue(reqJson, "feeConfigId", "璇锋眰鎶ユ枃涓湭鍖呭惈feeConfigId");
-Assert.hasKeyAndValue(reqJson, "communityId", "璇锋眰鎶ユ枃涓湭鍖呭惈communityId");
-Assert.hasKeyAndValue(reqJson, "payStartTime", "璇锋眰鎶ユ枃涓湭鍖呭惈payStartTime");
-Assert.hasKeyAndValue(reqJson, "payEndTime", "璇锋眰鎶ユ枃涓湭鍖呭惈payEndTime");
-Assert.hasKeyAndValue(reqJson, "payMonth", "璇锋眰鎶ユ枃涓湭鍖呭惈payMonth");
+        Assert.hasKeyAndValue(reqJson, "feeConfigId", "璇锋眰鎶ユ枃涓湭鍖呭惈feeConfigId");
+        Assert.hasKeyAndValue(reqJson, "communityId", "璇锋眰鎶ユ枃涓湭鍖呭惈communityId");
+        Assert.hasKeyAndValue(reqJson, "payStartTime", "璇锋眰鎶ユ枃涓湭鍖呭惈payStartTime");
+        Assert.hasKeyAndValue(reqJson, "payEndTime", "璇锋眰鎶ユ枃涓湭鍖呭惈payEndTime");
+        Assert.hasKeyAndValue(reqJson, "payMonth", "璇锋眰鎶ユ枃涓湭鍖呭惈payMonth");
+
+        CouponRuleFeeDto couponRuleFeeDto = new CouponRuleFeeDto();
+        couponRuleFeeDto.setRuleId(reqJson.getString("ruleId"));
+        couponRuleFeeDto.setFeeConfigId(reqJson.getString("feeConfigId"));
+        long count = couponRuleFeeV1InnerServiceSMOImpl.queryCouponRuleFeesCount(couponRuleFeeDto);
+
+        if(count > 0){
+            throw new CmdException("璐圭敤椤瑰凡缁忓叧鑱�");
+        }
 
     }
 
@@ -67,8 +85,15 @@
     @Java110Transactional
     public void doCmd(CmdEvent event, ICmdDataFlowContext cmdDataFlowContext, JSONObject reqJson) throws CmdException {
 
-       CouponRuleFeePo couponRuleFeePo = BeanConvertUtil.covertBean(reqJson, CouponRuleFeePo.class);
+        FeeConfigDto feeConfigDto = new FeeConfigDto();
+        feeConfigDto.setConfigId(reqJson.getString("feeConfigId"));
+        List<FeeConfigDto> feeConfigDtos = feeConfigInnerServiceSMOImpl.queryFeeConfigs(feeConfigDto);
+
+        Assert.listOnlyOne(feeConfigDtos,"璐圭敤椤逛笉瀛樺湪");
+
+        CouponRuleFeePo couponRuleFeePo = BeanConvertUtil.covertBean(reqJson, CouponRuleFeePo.class);
         couponRuleFeePo.setCrfId(GenerateCodeFactory.getGeneratorId(CODE_PREFIX_ID));
+        couponRuleFeePo.setFeeConfigName(feeConfigDtos.get(0).getFeeName());
         int flag = couponRuleFeeV1InnerServiceSMOImpl.saveCouponRuleFee(couponRuleFeePo);
 
         if (flag < 1) {

--
Gitblit v1.8.0