From ae2427a653555b7e32a417464289beef65e1c0a5 Mon Sep 17 00:00:00 2001
From: wuxw <928255095@qq.com>
Date: 星期二, 21 六月 2022 00:12:59 +0800
Subject: [PATCH] 优化bug

---
 service-fee/src/main/java/com/java110/fee/cmd/fee/PayFeePreCmd.java |  366 ++++++++++++++++++++++++++++++++++++++++++++++++----
 1 files changed, 336 insertions(+), 30 deletions(-)

diff --git a/service-fee/src/main/java/com/java110/fee/cmd/fee/PayFeePreCmd.java b/service-fee/src/main/java/com/java110/fee/cmd/fee/PayFeePreCmd.java
index c78d899..62ceb02 100644
--- a/service-fee/src/main/java/com/java110/fee/cmd/fee/PayFeePreCmd.java
+++ b/service-fee/src/main/java/com/java110/fee/cmd/fee/PayFeePreCmd.java
@@ -4,27 +4,39 @@
 import com.alibaba.fastjson.JSONObject;
 import com.java110.core.annotation.Java110Cmd;
 import com.java110.core.context.ICmdDataFlowContext;
-import com.java110.core.event.cmd.AbstractServiceCmdListener;
+import com.java110.core.event.cmd.Cmd;
 import com.java110.core.event.cmd.CmdEvent;
 import com.java110.core.factory.GenerateCodeFactory;
+import com.java110.core.log.LoggerFactory;
 import com.java110.core.smo.IComputeFeeSMO;
+import com.java110.dto.account.AccountDto;
+import com.java110.dto.community.CommunityDto;
 import com.java110.dto.couponUser.CouponUserDto;
+import com.java110.dto.fee.FeeAttrDto;
+import com.java110.dto.fee.FeeConfigDto;
 import com.java110.dto.fee.FeeDetailDto;
 import com.java110.dto.fee.FeeDto;
 import com.java110.dto.feeDiscount.ComputeDiscountDto;
+import com.java110.intf.acct.IAccountDetailInnerServiceSMO;
+import com.java110.intf.acct.IAccountInnerServiceSMO;
 import com.java110.intf.acct.ICouponUserV1InnerServiceSMO;
+import com.java110.intf.community.ICommunityV1InnerServiceSMO;
 import com.java110.intf.community.IRepairUserInnerServiceSMO;
 import com.java110.intf.community.IRoomInnerServiceSMO;
 import com.java110.intf.fee.*;
 import com.java110.intf.user.IOwnerCarInnerServiceSMO;
+import com.java110.po.account.AccountPo;
+import com.java110.po.accountDetail.AccountDetailPo;
+import com.java110.po.feeAccountDetail.FeeAccountDetailPo;
 import com.java110.utils.cache.CommonCache;
 import com.java110.utils.constant.ResponseConstant;
 import com.java110.utils.exception.CmdException;
 import com.java110.utils.exception.ListenerExecuteException;
 import com.java110.utils.util.Assert;
+import com.java110.utils.util.BeanConvertUtil;
 import com.java110.utils.util.DateUtil;
+import com.java110.utils.util.StringUtil;
 import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.http.HttpStatus;
 import org.springframework.http.ResponseEntity;
@@ -33,6 +45,7 @@
 import java.text.ParseException;
 import java.text.SimpleDateFormat;
 import java.util.ArrayList;
+import java.util.Date;
 import java.util.List;
 import java.util.Map;
 
@@ -47,7 +60,7 @@
  * // modify by 寮犱笁 at 2021-09-12 绗�10琛屽湪鏌愮鍦烘櫙涓嬪瓨鍦ㄦ煇绉峛ug 闇�瑕佷慨澶嶏紝娉ㄩ噴10鑷�20琛� 鍔犲叆 20琛岃嚦30琛�
  */
 @Java110Cmd(serviceCode = "fee.payFeePre")
-public class PayFeePreCmd extends AbstractServiceCmdListener {
+public class PayFeePreCmd extends Cmd {
     private static Logger logger = LoggerFactory.getLogger(PayFeePreCmd.class);
 
 
@@ -80,8 +93,21 @@
 
     @Autowired
     private IComputeFeeSMO computeFeeSMOImpl;
+
     @Autowired
     private ICouponUserV1InnerServiceSMO couponUserV1InnerServiceSMOImpl;
+
+    @Autowired
+    private IAccountInnerServiceSMO accountInnerServiceSMOImpl;
+
+    @Autowired
+    private ICommunityV1InnerServiceSMO communityV1InnerServiceSMOImpl;
+
+    @Autowired
+    private IAccountDetailInnerServiceSMO accountDetailInnerServiceSMOImpl;
+
+    @Autowired
+    private IFeeAccountDetailServiceSMO feeAccountDetailServiceSMOImpl;
 
     @Override
     public void validate(CmdEvent event, ICmdDataFlowContext cmdDataFlowContext, JSONObject reqJson) {
@@ -96,22 +122,54 @@
         Assert.hasLength(reqJson.getString("receivedAmount"), "瀹炴敹閲戦涓嶈兘涓虹┖");
         Assert.hasLength(reqJson.getString("feeId"), "璐圭敤ID涓嶈兘涓虹┖");
         Assert.hasLength(reqJson.getString("appId"), "appId涓嶈兘涓虹┖");
+
+
+        //鍒ゆ柇鏄惁 璐圭敤鐘舵�佷负缂磋垂缁撴潫
+        FeeDto feeDto = new FeeDto();
+        feeDto.setFeeId(reqJson.getString("feeId"));
+        feeDto.setCommunityId(reqJson.getString("communityId"));
+        List<FeeDto> feeDtos = feeInnerServiceSMOImpl.queryFees(feeDto);
+
+        Assert.listOnlyOne(feeDtos, "浼犲叆璐圭敤ID閿欒");
+
+        feeDto = feeDtos.get(0);
+
+        if (FeeDto.STATE_FINISH.equals(feeDto.getState())) {
+            throw new IllegalArgumentException("鏀惰垂宸茬粡缁撴潫锛屼笉鑳藉啀缂磋垂");
+        }
+
+        Date endTime = feeDto.getEndTime();
+
+        FeeConfigDto feeConfigDto = new FeeConfigDto();
+        feeConfigDto.setConfigId(feeDto.getConfigId());
+        feeConfigDto.setCommunityId(reqJson.getString("communityId"));
+        List<FeeConfigDto> feeConfigDtos = feeConfigInnerServiceSMOImpl.queryFeeConfigs(feeConfigDto);
+
+        if (feeConfigDtos != null && feeConfigDtos.size() == 1) {
+            try {
+                Date configEndTime = DateUtil.getDateFromString(feeConfigDtos.get(0).getEndTime(), DateUtil.DATE_FORMATE_STRING_A);
+                configEndTime = DateUtil.stepDay(configEndTime,5);
+
+                Date newDate = DateUtil.stepMonth(endTime, reqJson.getInteger("cycles"));
+
+                if (newDate.getTime() > configEndTime.getTime()) {
+                    throw new IllegalArgumentException("缂磋垂鍛ㄦ湡瓒呰繃 缂磋垂缁撴潫鏃堕棿");
+                }
+
+            } catch (Exception e) {
+                logger.error("姣旇緝璐圭敤鏃ユ湡澶辫触", e);
+            }
+        }
+
     }
 
     @Override
     public void doCmd(CmdEvent event, ICmdDataFlowContext cmdDataFlowContext, JSONObject reqJson) throws CmdException {
         logger.debug("ServiceDataFlowEvent : {}", event);
 
-        JSONObject paramObj = reqJson;
-
-        JSONArray businesses = new JSONArray();
-        //鍒ゆ柇鏄惁鏈夋姌鎵f儏鍐�
-        judgeDiscount(paramObj);
-        //3.0 鑰冭檻浼樻儬鍗�
-        checkCouponUser(paramObj);
-
         String appId = cmdDataFlowContext.getReqHeaders().get("app-id");
         reqJson.put("appId", appId);
+
         FeeDto feeDto = new FeeDto();
         feeDto.setFeeId(reqJson.getString("feeId"));
         feeDto.setCommunityId(reqJson.getString("communityId"));
@@ -120,40 +178,286 @@
             throw new ListenerExecuteException(ResponseConstant.RESULT_CODE_ERROR, "鏌ヨ璐圭敤淇℃伅澶辫触锛屾湭鏌ュ埌鏁版嵁鎴栨煡鍒板鏉℃暟鎹�");
         }
         feeDto = feeDtos.get(0);
-
+        reqJson.put("feeTypeCd", feeDto.getFeeTypeCd());
+        reqJson.put("feeId", feeDto.getFeeId());
         Map feePriceAll = computeFeeSMOImpl.getFeePrice(feeDto);
-
         BigDecimal receivableAmount = new BigDecimal(feePriceAll.get("feePrice").toString());
         BigDecimal cycles = new BigDecimal(Double.parseDouble(reqJson.getString("cycles")));
         double tmpReceivableAmount = cycles.multiply(receivableAmount).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue();
-        double discountPrice = reqJson.getDouble("discountPrice");
-        double couponPrice = reqJson.getDouble("couponPrice");
         JSONObject paramOut = new JSONObject();
         paramOut.put("receivableAmount", tmpReceivableAmount);
         paramOut.put("oId", GenerateCodeFactory.getGeneratorId(GenerateCodeFactory.CODE_PREFIX_oId));
-        //1.0 鑰冭檻浼樻儬閲戦
+
+        //瀹炴敹閲戦
+        BigDecimal tmpReceivedAmout = new BigDecimal(tmpReceivableAmount);
+
+        //鍒ゆ柇鏄惁鏈夋姌鎵f儏鍐�
+        double discountPrice = judgeDiscount(reqJson);
+        tmpReceivedAmout = tmpReceivedAmout.subtract(new BigDecimal(discountPrice)).setScale(2, BigDecimal.ROUND_HALF_EVEN);
         //2.0 鑰冭檻璐︽埛鎶垫秷
+        double accountPrice = judgeAccount(reqJson);
+        tmpReceivedAmout = tmpReceivedAmout.subtract(new BigDecimal(accountPrice)).setScale(2, BigDecimal.ROUND_HALF_EVEN);
+
         //3.0 鑰冭檻浼樻儬鍗�
-        BigDecimal tmpReceivedAmout = new BigDecimal(tmpReceivableAmount).subtract(new BigDecimal(discountPrice)).setScale(2, BigDecimal.ROUND_HALF_EVEN);
-        double receivedAmount = tmpReceivedAmout.subtract(new BigDecimal(couponPrice)).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue();
+        double couponPrice = checkCouponUser(reqJson);
+        tmpReceivedAmout = tmpReceivedAmout.subtract(new BigDecimal(couponPrice)).setScale(2, BigDecimal.ROUND_HALF_EVEN);
+
+
+        double receivedAmount = tmpReceivedAmout.doubleValue();
         //鎵�鏈� 浼樻儬鎶樻墸璁$畻瀹屽悗锛屽鏋滄�婚噾棰濆皬浜庣瓑浜�0锛屽垯杩斿洖鎬绘墸娆句负0
         if (receivedAmount <= 0) {
             receivedAmount = 0.0;
         }
         paramOut.put("receivedAmount", receivedAmount);
+
+        String feeName = getObjName(feeDto);
+        paramOut.put("feeName", feeName);
+
         ResponseEntity<String> responseEntity = new ResponseEntity<>(paramOut.toJSONString(), HttpStatus.OK);
+        reqJson.putAll(paramOut);
         CommonCache.setValue("payFeePre" + paramOut.getString("oId"), reqJson.toJSONString(), 24 * 60 * 60);
         cmdDataFlowContext.setResponseEntity(responseEntity);
     }
 
-    private void checkCouponUser(JSONObject paramObj) {
+    private String getObjName(FeeDto feeDto) {
+        //鏌ヨ灏忓尯鍚嶇О
+        CommunityDto communityDto = new CommunityDto();
+        communityDto.setCommunityId(feeDto.getCommunityId());
+        List<CommunityDto> communityDtos = communityV1InnerServiceSMOImpl.queryCommunitys(communityDto);
+
+        Assert.listOnlyOne(communityDtos, "灏忓尯涓嶅瓨鍦�");
+
+        List<FeeAttrDto> feeAttrDtos = feeDto.getFeeAttrDtos();
+        if (feeAttrDtos == null || feeAttrDtos.size() < 1) {
+            return communityDtos.get(0).getName() + "-" + feeDto.getFeeName();
+        }
+
+        for (FeeAttrDto feeAttrDto : feeAttrDtos) {
+            if (FeeAttrDto.SPEC_CD_PAY_OBJECT_NAME.equals(feeAttrDto.getSpecCd())) {
+                return communityDtos.get(0).getName() + "-" + feeAttrDto.getValue() + "-" + feeDto.getFeeName();
+            }
+        }
+
+        return communityDtos.get(0).getName() + "-" + feeDto.getFeeName();
+    }
+
+    /**
+     * 鑰冭檻璐︽埛鎶垫秷
+     *
+     * @param reqJson
+     */
+    private double judgeAccount(JSONObject reqJson) {
+        if (!reqJson.containsKey("deductionAmount")) {
+            reqJson.put("deductionAmount", 0.0);
+            return 0.0;
+        }
+
+        double deductionAmount = reqJson.getDouble("deductionAmount");
+        if (deductionAmount <= 0) {
+            reqJson.put("deductionAmount", 0.0);
+            return 0.0;
+        }
+
+        if (!reqJson.containsKey("selectUserAccount")) {
+            reqJson.put("deductionAmount", 0.0);
+            return 0.0;
+        }
+
+        JSONArray selectUserAccount = reqJson.getJSONArray("selectUserAccount");
+        if (selectUserAccount == null || selectUserAccount.size() < 1) {
+            reqJson.put("deductionAmount", 0.0);
+            return 0.0;
+        }
+        List<String> acctIds = new ArrayList<>();
+        for (int userAccountIndex = 0; userAccountIndex < selectUserAccount.size(); userAccountIndex++) {
+            acctIds.add(selectUserAccount.getJSONObject(userAccountIndex).getString("acctId"));
+        }
+
+        AccountDto accountDto = new AccountDto();
+        accountDto.setAcctIds(acctIds.toArray(new String[acctIds.size()]));
+        List<AccountDto> accountDtos = accountInnerServiceSMOImpl.queryAccounts(accountDto);
+
+        if (accountDtos == null || accountDtos.size() < 1) {
+            reqJson.put("deductionAmount", 0.0);
+            return 0.0;
+        }
+
+        BigDecimal money = new BigDecimal(0);
+        BigDecimal totalAccountAmount = new BigDecimal(0);
+        for (AccountDto tmpAccountDto : accountDtos) {
+            if (!StringUtil.isEmpty(tmpAccountDto.getAcctType()) && tmpAccountDto.getAcctType().equals("2004")) { //绉垎璐︽埛
+                //璐︽埛閲戦
+                BigDecimal amount = new BigDecimal(tmpAccountDto.getAmount());
+                //鑾峰彇鏈�澶ф姷鎵gН鍒�
+                BigDecimal maximumNumber = new BigDecimal(tmpAccountDto.getMaximumNumber());
+                //鑾峰彇绉垎鎶垫墸姣斾緥
+                BigDecimal deductionProportion = new BigDecimal(tmpAccountDto.getDeductionProportion());
+                int flag = amount.compareTo(maximumNumber);
+                BigDecimal redepositAmount = new BigDecimal("0.00");
+                BigDecimal integralAmount = new BigDecimal("0.00");
+                if (flag == 1) { //璐︽埛绉垎澶т簬鏈�澶т娇鐢ㄧН鍒嗭紝灏辩敤鏈�澶т娇鐢ㄧН鍒嗘姷鎵�
+                    redepositAmount = maximumNumber;
+                    integralAmount = amount.subtract(maximumNumber);
+                }
+                if (flag > -1) { //璐︽埛绉垎澶т簬绛変簬鏈�澶т娇鐢ㄧН鍒嗭紝灏辩敤鏈�澶т娇鐢ㄧН鍒嗘姷鎵�
+                    redepositAmount = maximumNumber;
+                    integralAmount = amount.subtract(maximumNumber);
+                }
+                if (flag == -1) { //璐︽埛绉垎灏忎簬鏈�澶т娇鐢ㄧН鍒嗭紝灏辩敤璐︽埛绉垎鎶垫墸
+                    redepositAmount = amount;
+                }
+                if (flag < 1) { //璐︽埛绉垎灏忎簬绛変簬鏈�澶т娇鐢ㄧН鍒嗭紝灏辩敤璐︽埛绉垎鎶垫墸
+                    redepositAmount = amount;
+                }
+                if (flag == 0) { //璐︽埛绉垎绛変簬鏈�澶т娇鐢ㄧН鍒�
+                    redepositAmount = amount;
+                }
+                //鏇存柊璐︽埛淇℃伅
+                AccountPo accountPo = new AccountPo();
+                accountPo.setAcctId(tmpAccountDto.getAcctId());
+                accountPo.setAmount(integralAmount.toString());
+                accountInnerServiceSMOImpl.updateAccount(accountPo);
+                //鐢熸垚璐︽埛璇︽儏
+                AccountDetailPo accountDetailPo = new AccountDetailPo();
+                accountDetailPo.setDetailId(GenerateCodeFactory.getGeneratorId(GenerateCodeFactory.CODE_PREFIX_detailId));
+                accountDetailPo.setAcctId(tmpAccountDto.getAcctId());
+                accountDetailPo.setDetailType("2002"); //1001 杞叆 2002 杞嚭
+                accountDetailPo.setRelAcctId("-1");
+                accountDetailPo.setAmount(redepositAmount.toString());
+                accountDetailPo.setObjType("6006"); //6006 涓汉 7007 鍟嗘埛
+                accountDetailPo.setObjId(tmpAccountDto.getObjId());
+                accountDetailPo.setOrderId("-1");
+                accountDetailPo.setbId("-1");
+                accountDetailPo.setRemark("鎵嬫満绔Н鍒嗘姷鎵�");
+                accountDetailPo.setCreateTime(new Date());
+                accountDetailInnerServiceSMOImpl.saveAccountDetails(accountDetailPo);
+                //璁$畻绉垎鎹㈢畻鐨勯噾棰�
+                BigDecimal divide = redepositAmount.divide(deductionProportion);
+                BigDecimal dedAmount = new BigDecimal(deductionAmount);
+                //璁$畻瀹炰粯閲戦
+                int flag2 = divide.compareTo(dedAmount);
+                BigDecimal subtract = new BigDecimal("0.00");
+                //鐢熸垚鎶垫墸鏄庣粏璁板綍
+                FeeAccountDetailPo feeAccountDetailPo = new FeeAccountDetailPo();
+                if (flag2 == -1) { //绉垎鎹㈢畻閲戦灏忎簬搴斾粯閲戦
+                    subtract = dedAmount.subtract(divide);
+                    BigDecimal multiply = divide.multiply(deductionProportion);
+                    feeAccountDetailPo.setAmount(multiply.toString()); //绉垎鎶垫墸閲戦
+                } else if (flag < 1) { //绉垎鎹㈢畻閲戦灏忎簬绛変簬搴斾粯閲戦
+                    subtract = dedAmount.subtract(divide);
+                    BigDecimal multiply = divide.multiply(deductionProportion);
+                    feeAccountDetailPo.setAmount(multiply.toString()); //绉垎鎶垫墸閲戦
+                } else {
+                    BigDecimal multiply = dedAmount.multiply(deductionProportion);
+                    feeAccountDetailPo.setAmount(multiply.toString()); //绉垎鎶垫墸閲戦
+                }
+                reqJson.put("receivedMoney", subtract);
+                feeAccountDetailPo.setFadId(GenerateCodeFactory.getGeneratorId(GenerateCodeFactory.CODE_PREFIX_fadId));
+                feeAccountDetailPo.setDetailId(accountDetailPo.getDetailId());
+                feeAccountDetailPo.setCommunityId(reqJson.getString("communityId"));
+                feeAccountDetailPo.setState("1003"); //1001 鏃犳姷鎵� 1002 鐜伴噾璐︽埛鎶垫墸 1003 绉垎璐︽埛鎶垫墸 1004 浼樻儬鍒告姷鎵�
+                feeAccountDetailServiceSMOImpl.saveFeeAccountDetail(feeAccountDetailPo);
+                money = subtract;
+            } else if (!StringUtil.isEmpty(tmpAccountDto.getAcctType()) && tmpAccountDto.getAcctType().equals("2003")) { //鐜伴噾璐︽埛
+                //璐︽埛閲戦
+                BigDecimal amount = new BigDecimal(tmpAccountDto.getAmount());
+                //鑾峰彇搴旀敹閲戦
+                BigDecimal dedAmount = new BigDecimal("0.00");
+                if (reqJson.containsKey("receivedMoney") && !StringUtil.isEmpty(reqJson.getString("receivedMoney"))) {
+                    dedAmount = new BigDecimal(reqJson.getString("receivedMoney"));
+                } else {
+                    dedAmount = new BigDecimal(reqJson.getString("deductionAmount"));
+                }
+                int flag = amount.compareTo(dedAmount);
+                BigDecimal redepositAmount = new BigDecimal("0.00");
+                BigDecimal integralAmount = new BigDecimal("0.00");
+                if (flag == 1) { //鐜伴噾璐︽埛澶т簬搴旀敹閲戦锛屽氨鐢ㄥ簲鏀堕噾棰濇姷鎵�
+                    redepositAmount = dedAmount;
+                    integralAmount = amount.subtract(dedAmount);
+                }
+                if (flag > -1) { //鐜伴噾璐︽埛澶т簬绛変簬搴旀敹閲戦锛屽氨鐢ㄥ簲鏀堕噾棰濇姷鎵�
+                    redepositAmount = dedAmount;
+                    integralAmount = amount.subtract(dedAmount);
+                }
+                if (flag == -1) { //鐜伴噾璐︽埛灏忎簬瀹炴敹閲戦锛屽氨鐢ㄧ幇閲戣处鎴锋姷鎵�
+                    redepositAmount = amount;
+                }
+                if (flag < 1) { //鐜伴噾璐︽埛灏忎簬绛変簬搴旀敹閲戦锛屽氨鐢ㄧ幇閲戣处鎴锋姷鎵�
+                    redepositAmount = amount;
+                }
+                if (flag == 0) { //鐜伴噾璐︽埛绛変簬搴旀敹閲戦
+                    redepositAmount = amount;
+                }
+                //鏇存柊璐︽埛淇℃伅
+                AccountPo accountPo = new AccountPo();
+                accountPo.setAcctId(tmpAccountDto.getAcctId());
+                accountPo.setAmount(integralAmount.toString());
+                accountInnerServiceSMOImpl.updateAccount(accountPo);
+                //鐢熸垚璐︽埛璇︽儏
+                AccountDetailPo accountDetailPo = new AccountDetailPo();
+                accountDetailPo.setDetailId(GenerateCodeFactory.getGeneratorId(GenerateCodeFactory.CODE_PREFIX_detailId));
+                accountDetailPo.setAcctId(tmpAccountDto.getAcctId());
+                accountDetailPo.setDetailType("2002"); //1001 杞叆 2002 杞嚭
+                accountDetailPo.setRelAcctId("-1");
+                accountDetailPo.setAmount(redepositAmount.toString());
+                accountDetailPo.setObjType("6006"); //6006 涓汉 7007 鍟嗘埛
+                accountDetailPo.setObjId(tmpAccountDto.getObjId());
+                accountDetailPo.setOrderId("-1");
+                accountDetailPo.setbId("-1");
+                accountDetailPo.setRemark("鎵嬫満绔幇閲戣处鎴锋姷鎵�");
+                accountDetailPo.setCreateTime(new Date());
+                accountDetailInnerServiceSMOImpl.saveAccountDetails(accountDetailPo);
+                //鐢熸垚鎶垫墸鏄庣粏璁板綍
+                FeeAccountDetailPo feeAccountDetailPo = new FeeAccountDetailPo();
+                feeAccountDetailPo.setFadId(GenerateCodeFactory.getGeneratorId(GenerateCodeFactory.CODE_PREFIX_fadId));
+                feeAccountDetailPo.setDetailId(accountDetailPo.getDetailId());
+                feeAccountDetailPo.setCommunityId(reqJson.getString("communityId"));
+                feeAccountDetailPo.setState("1002"); //1001 鏃犳姷鎵� 1002 鐜伴噾璐︽埛鎶垫墸 1003 绉垎璐︽埛鎶垫墸 1004 浼樻儬鍒告姷鎵�
+                feeAccountDetailPo.setAmount(redepositAmount.toString()); //绉垎鎶垫墸閲戦
+                feeAccountDetailServiceSMOImpl.saveFeeAccountDetail(feeAccountDetailPo);
+                int flag2 = money.compareTo(amount);
+                if (flag2 == 1) { //鍓╀綑閲戦澶т簬鐜伴噾璐︽埛
+                    money = money.subtract(amount);
+                }
+                if (flag > -1) { //鍓╀綑閲戦澶т簬绛変簬鐜伴噾璐︽埛
+                    money = money.subtract(amount);
+                }
+                if (flag == -1) { //鍓╀綑閲戦灏忎簬鐜伴噾璐︽埛
+                    money = new BigDecimal(0);
+                }
+                if (flag < 1) { //鍓╀綑閲戦灏忎簬绛変簬鐜伴噾璐︽埛
+                    money = new BigDecimal(0);
+                }
+                if (flag == 0) { //鍓╀綑閲戦绛変簬鐜伴噾璐︽埛
+                    money = new BigDecimal(0);
+                }
+            }
+//            totalAccountAmount = totalAccountAmount.add(new BigDecimal(tmpAccountDto.getAmount()));
+        }
+
+       /* double tmpDeductionAmount = totalAccountAmount.subtract(new BigDecimal(deductionAmount)).doubleValue();
+        if (tmpDeductionAmount < 0) {
+            reqJson.put("deductionAmount", totalAccountAmount.doubleValue());
+            reqJson.put("selectUserAccount", BeanConvertUtil.beanCovertJSONArray(accountDtos));
+            return totalAccountAmount.doubleValue();
+        }
+        reqJson.put("deductionAmount", deductionAmount);
+        reqJson.put("selectUserAccount", BeanConvertUtil.beanCovertJSONArray(accountDtos));
+        return deductionAmount;*/
+        reqJson.put("deductionAmount", money.doubleValue());
+        reqJson.put("selectUserAccount", BeanConvertUtil.beanCovertJSONArray(accountDtos));
+        return money.doubleValue();
+    }
+
+    private double checkCouponUser(JSONObject paramObj) {
         JSONArray couponList = paramObj.getJSONArray("couponList");
         BigDecimal couponPrice = new BigDecimal(0.0);
         List<String> couponIds = new ArrayList<String>();
 
         if (couponList == null || couponList.size() < 1) {
-            paramObj.put("couponPrice", couponPrice);
-            return;
+            paramObj.put("couponPrice", couponPrice.doubleValue());
+            paramObj.put("couponUserDtos", new JSONArray()); //杩欓噷鑰冭檻绌�
+            return couponPrice.doubleValue();
         }
         for (int couponIndex = 0; couponIndex < couponList.size(); couponIndex++) {
             couponIds.add(couponList.getJSONObject(couponIndex).getString("couponId"));
@@ -162,21 +466,22 @@
         couponUserDto.setCouponIds(couponIds.toArray(new String[couponIds.size()]));
         List<CouponUserDto> couponUserDtos = couponUserV1InnerServiceSMOImpl.queryCouponUsers(couponUserDto);
         if (couponUserDtos == null || couponUserDtos.size() < 1) {
-            paramObj.put("couponPrice", couponPrice);
-            return;
+            paramObj.put("couponPrice", couponPrice.doubleValue());
+            return couponPrice.doubleValue();
         }
         for (CouponUserDto couponUser : couponUserDtos) {
             //涓嶈绠楀凡杩囨湡璐墿鍒搁噾棰�
             if (couponUser.getEndTime().compareTo(DateUtil.getNow(DateUtil.DATE_FORMATE_STRING_B)) >= 0) {
-                couponPrice.add(new BigDecimal(Double.parseDouble(couponUser.getActualPrice())));
+                couponPrice = couponPrice.add(new BigDecimal(Double.parseDouble(couponUser.getActualPrice())));
             }
         }
-        paramObj.put("couponPrice", couponPrice);
-        paramObj.put("couponUserDtos", couponUserDtos);
+        paramObj.put("couponPrice", couponPrice.doubleValue());
+        paramObj.put("couponUserDtos", BeanConvertUtil.beanCovertJSONArray(couponUserDtos));
+        return couponPrice.doubleValue();
     }
 
 
-    private void judgeDiscount(JSONObject paramObj) {
+    private double judgeDiscount(JSONObject paramObj) {
         FeeDetailDto feeDetailDto = new FeeDetailDto();
         feeDetailDto.setCommunityId(paramObj.getString("communityId"));
         feeDetailDto.setFeeId(paramObj.getString("feeId"));
@@ -197,13 +502,14 @@
 
         if (computeDiscountDtos == null || computeDiscountDtos.size() < 1) {
             paramObj.put("discountPrice", 0.0);
-            return;
+            return 0.0;
         }
         BigDecimal discountPrice = new BigDecimal(0);
         for (ComputeDiscountDto computeDiscountDto : computeDiscountDtos) {
             discountPrice = discountPrice.add(new BigDecimal(computeDiscountDto.getDiscountPrice()));
         }
-        paramObj.put("discountPrice", discountPrice);
-        paramObj.put("computeDiscountDtos", computeDiscountDtos);
+        paramObj.put("discountPrice", discountPrice.doubleValue());
+        paramObj.put("computeDiscountDtos", BeanConvertUtil.beanCovertJSONArray(computeDiscountDtos));
+        return discountPrice.doubleValue();
     }
 }

--
Gitblit v1.8.0