From 75cbaa2d0ce62ea8f6752a917627591ab918ab22 Mon Sep 17 00:00:00 2001
From: xiaogang <905166056@qq.com>
Date: 星期一, 20 六月 2022 17:36:02 +0800
Subject: [PATCH] 1、缴费积分抵扣从小区设置里面配置并且进行抵扣2、抵扣明细3、超时相关bug

---
 service-fee/src/main/java/com/java110/fee/cmd/fee/PayFeePreCmd.java |  171 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 168 insertions(+), 3 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 3ae0451..99847f6 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
@@ -16,13 +16,18 @@
 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.feeAccountDetail.IFeeAccountDetailServiceSMO;
 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;
@@ -30,6 +35,7 @@
 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.springframework.beans.factory.annotation.Autowired;
 import org.springframework.http.HttpStatus;
@@ -39,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;
 
@@ -86,6 +93,7 @@
 
     @Autowired
     private IComputeFeeSMO computeFeeSMOImpl;
+
     @Autowired
     private ICouponUserV1InnerServiceSMO couponUserV1InnerServiceSMOImpl;
 
@@ -94,6 +102,12 @@
 
     @Autowired
     private ICommunityV1InnerServiceSMO communityV1InnerServiceSMOImpl;
+
+    @Autowired
+    private IAccountDetailInnerServiceSMO accountDetailInnerServiceSMOImpl;
+
+    @Autowired
+    private IFeeAccountDetailServiceSMO feeAccountDetailServiceSMOImpl;
 
     @Override
     public void validate(CmdEvent event, ICmdDataFlowContext cmdDataFlowContext, JSONObject reqJson) {
@@ -229,12 +243,160 @@
             return 0.0;
         }
 
+        BigDecimal money = new BigDecimal(0);
         BigDecimal totalAccountAmount = new BigDecimal(0);
         for (AccountDto tmpAccountDto : accountDtos) {
-            totalAccountAmount = totalAccountAmount.add(new BigDecimal(tmpAccountDto.getAmount()));
+            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();
+       /* double tmpDeductionAmount = totalAccountAmount.subtract(new BigDecimal(deductionAmount)).doubleValue();
         if (tmpDeductionAmount < 0) {
             reqJson.put("deductionAmount", totalAccountAmount.doubleValue());
             reqJson.put("selectUserAccount", BeanConvertUtil.beanCovertJSONArray(accountDtos));
@@ -242,7 +404,10 @@
         }
         reqJson.put("deductionAmount", deductionAmount);
         reqJson.put("selectUserAccount", BeanConvertUtil.beanCovertJSONArray(accountDtos));
-        return deductionAmount;
+        return deductionAmount;*/
+        reqJson.put("deductionAmount", money.doubleValue());
+        reqJson.put("selectUserAccount", BeanConvertUtil.beanCovertJSONArray(accountDtos));
+        return money.doubleValue();
     }
 
     private double checkCouponUser(JSONObject paramObj) {

--
Gitblit v1.8.0