From 91ff9f520b66fc38a0ce8e7e2e06bdd54487ae1e Mon Sep 17 00:00:00 2001
From: wuxw <928255095@qq.com>
Date: 星期五, 22 七月 2022 00:01:05 +0800
Subject: [PATCH] 优化 间歇费用 相关bug

---
 service-fee/src/main/java/com/java110/fee/cmd/fee/PayFeeCmd.java |  357 ++++++++++++++++++++++++++++++++++++++++++++++++++--------
 1 files changed, 305 insertions(+), 52 deletions(-)

diff --git a/service-fee/src/main/java/com/java110/fee/cmd/fee/PayFeeCmd.java b/service-fee/src/main/java/com/java110/fee/cmd/fee/PayFeeCmd.java
index c39c169..2c81f42 100644
--- a/service-fee/src/main/java/com/java110/fee/cmd/fee/PayFeeCmd.java
+++ b/service-fee/src/main/java/com/java110/fee/cmd/fee/PayFeeCmd.java
@@ -5,7 +5,7 @@
 import com.java110.core.annotation.Java110Cmd;
 import com.java110.core.annotation.Java110Transactional;
 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;
@@ -29,12 +29,14 @@
 import com.java110.intf.community.IRepairUserInnerServiceSMO;
 import com.java110.intf.community.IRoomInnerServiceSMO;
 import com.java110.intf.fee.*;
+import com.java110.intf.fee.IFeeAccountDetailServiceSMO;
 import com.java110.intf.user.IOwnerCarInnerServiceSMO;
 import com.java110.po.accountDetail.AccountDetailPo;
 import com.java110.po.applyRoomDiscount.ApplyRoomDiscountPo;
 import com.java110.po.car.OwnerCarPo;
 import com.java110.po.fee.PayFeeDetailPo;
 import com.java110.po.fee.PayFeePo;
+import com.java110.po.feeAccountDetail.FeeAccountDetailPo;
 import com.java110.po.owner.RepairPoolPo;
 import com.java110.po.owner.RepairUserPo;
 import com.java110.po.payFeeDetailDiscount.PayFeeDetailDiscountPo;
@@ -53,18 +55,18 @@
 import org.springframework.beans.factory.annotation.Autowired;
 
 import java.math.BigDecimal;
-import java.util.Calendar;
-import java.util.Date;
-import java.util.List;
-import java.util.Map;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.*;
 
 @Java110Cmd(serviceCode = "fee.payFee")
-public class PayFeeCmd extends AbstractServiceCmdListener {
-    private static Logger logger = LoggerFactory.getLogger(PayFeeCmd.class);
+public class PayFeeCmd extends Cmd {
 
+    private static Logger logger = LoggerFactory.getLogger(PayFeeCmd.class);
 
     @Autowired
     private IPayFeeV1InnerServiceSMO payFeeV1InnerServiceSMOImpl;
+
     @Autowired
     private IPayFeeDetailNewV1InnerServiceSMO payFeeDetailNewV1InnerServiceSMOImpl;
 
@@ -83,7 +85,6 @@
     @Autowired
     private IOwnerCarInnerServiceSMO ownerCarInnerServiceSMOImpl;
 
-
     @Autowired
     private IFeeReceiptDetailInnerServiceSMO feeReceiptDetailInnerServiceSMOImpl;
 
@@ -99,31 +100,35 @@
     @Autowired
     private IParkingSpaceInnerServiceSMO parkingSpaceInnerServiceSMOImpl;
 
-
     @Autowired
     private IAccountDetailInnerServiceSMO accountDetailInnerServiceSMOImpl;
 
     @Autowired
     private IAccountInnerServiceSMO accountInnerServiceSMOImpl;
 
-
     @Autowired
     private IComputeFeeSMO computeFeeSMOImpl;
 
     @Autowired
     private IPayFeeDetailDiscountNewV1InnerServiceSMO payFeeDetailDiscountNewV1InnerServiceSMOImpl;
+
     @Autowired
     private IRepairPoolNewV1InnerServiceSMO repairPoolNewV1InnerServiceSMOImpl;
+
     @Autowired
     private IRepairUserNewV1InnerServiceSMO repairUserNewV1InnerServiceSMOImpl;
+
     @Autowired
     private ICouponUserV1InnerServiceSMO couponUserV1InnerServiceSMOImpl;
+
     @Autowired
     private ICouponUserDetailV1InnerServiceSMO couponUserDetailV1InnerServiceSMOImpl;
 
     @Autowired
     private IOwnerCarNewV1InnerServiceSMO ownerCarNewV1InnerServiceSMOImpl;
 
+    @Autowired
+    private IFeeAccountDetailServiceSMO feeAccountDetailServiceSMOImpl;
 
     @Override
     public void validate(CmdEvent event, ICmdDataFlowContext cmdDataFlowContext, JSONObject reqJson) throws CmdException {
@@ -158,21 +163,34 @@
         feeConfigDto.setCommunityId(reqJson.getString("communityId"));
         List<FeeConfigDto> feeConfigDtos = feeConfigInnerServiceSMOImpl.queryFeeConfigs(feeConfigDto);
 
-        if (feeConfigDtos != null && feeConfigDtos.size() == 1) {
+        if (feeConfigDtos == null || feeConfigDtos.size() != 1) {
+            throw new IllegalArgumentException("璐圭敤椤逛笉瀛樺湪");
+        }
+        //涓�娆℃�ц垂鐢� 鍜岄棿鎺ユ�ц垂鐢�
+        Date maxEndTime = feeDtos.get(0).getDeadlineTime();
+        //鍛ㄦ湡鎬ц垂鐢�
+        if (FeeDto.FEE_FLAG_CYCLE.equals(feeConfigDtos.get(0).getFeeFlag())
+                || FeeDto.FEE_FLAG_CYCLE_ONCE.equals(feeConfigDtos.get(0).getFeeFlag())) {
             try {
-                Date configEndTime = DateUtil.getDateFromString(feeConfigDtos.get(0).getEndTime(), DateUtil.DATE_FORMATE_STRING_A);
-
-                Date newDate = DateUtil.stepMonth(endTime, reqJson.getInteger("cycles") - 1);
-
-                if (newDate.getTime() > configEndTime.getTime()) {
-                    throw new IllegalArgumentException("缂磋垂鍛ㄦ湡瓒呰繃 缂磋垂缁撴潫鏃堕棿");
-                }
-
+                maxEndTime = DateUtil.getDateFromString(feeConfigDtos.get(0).getEndTime(), DateUtil.DATE_FORMATE_STRING_A);
+            } catch (ParseException e) {
             } catch (Exception e) {
                 logger.error("姣旇緝璐圭敤鏃ユ湡澶辫触", e);
             }
+            Date newDate = DateUtil.stepMonth(endTime, reqJson.getDouble("cycles").intValue());
+            if (newDate.getTime() > maxEndTime.getTime()) {
+                throw new IllegalArgumentException("缂磋垂鍛ㄦ湡瓒呰繃 缂磋垂缁撴潫鏃堕棿");
+            }
+        }
+
+        String selectUserAccount = reqJson.getString("selectUserAccount");
+        JSONArray params = JSONArray.parseArray(selectUserAccount);
+        for (int paramIndex = 0; paramIndex < params.size(); paramIndex++) {
+            JSONObject param = params.getJSONObject(paramIndex);
+            String maximumNumber = param.getString("maximumNumber");
         }
     }
+
 
     @Override
     @Java110Transactional
@@ -185,18 +203,140 @@
         try {
             DistributedLock.waitGetDistributedLock(key, requestId);
             JSONObject feeDetail = addFeeDetail(paramObj);
+            JSONObject fee = modifyFee(paramObj);
+            payFeePo = BeanConvertUtil.covertBean(fee, PayFeePo.class);
             PayFeeDetailPo payFeeDetailPo = BeanConvertUtil.covertBean(feeDetail, PayFeeDetailPo.class);
+            //鍒ゆ柇鏄惁鏈夎禒閫佽鍒�
+            if (paramObj.containsKey("selectDiscount")) {
+                JSONArray selectDiscount = paramObj.getJSONArray("selectDiscount");
+                if (selectDiscount != null && selectDiscount.size() > 0) {
+                    for (int index = 0; index < selectDiscount.size(); index++) {
+                        JSONObject paramJson = selectDiscount.getJSONObject(index);
+                        if (!StringUtil.isEmpty(paramJson.getString("ruleId")) && paramJson.getString("ruleId").equals("102020008")) { //璧犻�佽鍒�
+                            JSONArray feeDiscountSpecs = paramJson.getJSONArray("feeDiscountSpecs");
+                            if (feeDiscountSpecs.size() > 0) {
+                                for (int specIndex = 0; specIndex < feeDiscountSpecs.size(); specIndex++) {
+                                    JSONObject paramIn = feeDiscountSpecs.getJSONObject(specIndex);
+                                    if (!StringUtil.isEmpty(paramIn.getString("specId")) && paramIn.getString("specId").equals("89002020980015")) { //璧犻�佹湀浠�
+                                        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+                                        String specValue = paramIn.getString("specValue");
+                                        //鑾峰彇璐圭敤缁撴潫鏃堕棿(涔熷氨鏄笅娆¤垂鐢ㄥ紑濮嬫椂闂�)
+                                        Date endTime = df.parse(payFeeDetailPo.getEndTime());
+                                        Calendar cal = Calendar.getInstance();
+                                        cal.setTime(endTime);
+                                        cal.add(Calendar.MONTH, Integer.parseInt(specValue));
+                                        payFeeDetailPo.setEndTime(df.format(cal.getTime()));
+                                        payFeePo.setEndTime(df.format(cal.getTime()));
+                                    }
+                                }
+                            }
+                        }
+                    }
+                }
+            }
+            //鍒ゆ柇閫夋嫨鐨勮处鍙�
+            JSONArray jsonArray = paramObj.getJSONArray("selectUserAccount");
+            if (jsonArray == null || jsonArray.size() < 1) {
+                FeeAccountDetailPo feeAccountDetailPo = new FeeAccountDetailPo();
+                feeAccountDetailPo.setFadId(GenerateCodeFactory.getGeneratorId(GenerateCodeFactory.CODE_PREFIX_fadId));
+                feeAccountDetailPo.setDetailId(payFeeDetailPo.getDetailId());
+                feeAccountDetailPo.setCommunityId(payFeeDetailPo.getCommunityId());
+                feeAccountDetailPo.setState("1001"); //1001 鏃犳姷鎵� 1002 鐜伴噾璐︽埛鎶垫墸 1003 绉垎璐︽埛鎶垫墸 1004 浼樻儬鍒告姷鎵�
+                feeAccountDetailPo.setAmount(paramObj.getString("receivedAmount"));
+                feeAccountDetailServiceSMOImpl.saveFeeAccountDetail(feeAccountDetailPo);
+            }
+            for (int columnIndex = 0; columnIndex < jsonArray.size(); columnIndex++) {
+                JSONObject param = jsonArray.getJSONObject(columnIndex);
+                if (AccountDto.ACCT_TYPE_INTEGRAL.equals(param.getString("acctType"))) { //绉垎璐︽埛
+                    //璐︽埛閲戦
+                    BigDecimal amount = new BigDecimal(param.getString("amount"));
+                    //鑾峰彇鏈�澶ф姷鎵gН鍒�
+                    BigDecimal maximumNumber = new BigDecimal(param.getString("maximumNumber"));
+                    //鑾峰彇绉垎鎶垫墸
+                    BigDecimal deductionProportion = new BigDecimal(param.getString("deductionProportion"));
+                    int flag = amount.compareTo(maximumNumber);
+                    BigDecimal redepositAmount = new BigDecimal("0.00");
+                    if (flag == 1) { //璐︽埛绉垎澶т簬鏈�澶т娇鐢ㄧН鍒嗭紝灏辩敤鏈�澶т娇鐢ㄧН鍒嗘姷鎵�
+                        redepositAmount = maximumNumber;
+                    }
+                    if (flag > -1) { //璐︽埛绉垎澶т簬绛変簬鏈�澶т娇鐢ㄧН鍒嗭紝灏辩敤鏈�澶т娇鐢ㄧН鍒嗘姷鎵�
+                        redepositAmount = maximumNumber;
+                    }
+                    if (flag == -1) { //璐︽埛绉垎灏忎簬鏈�澶т娇鐢ㄧН鍒嗭紝灏辩敤璐︽埛绉垎鎶垫墸
+                        redepositAmount = amount;
+                    }
+                    if (flag < 1) { //璐︽埛绉垎灏忎簬绛変簬鏈�澶т娇鐢ㄧН鍒嗭紝灏辩敤璐︽埛绉垎鎶垫墸
+                        redepositAmount = amount;
+                    }
+                    if (flag == 0) { //璐︽埛绉垎绛変簬鏈�澶т娇鐢ㄧН鍒�
+                        redepositAmount = amount;
+                    }
+                    //璁$畻绉垎鎹㈢畻鐨勯噾棰�
+                    BigDecimal divide = redepositAmount.divide(deductionProportion);
+                    BigDecimal receivedAmount = new BigDecimal(payFeeDetailPo.getReceivedAmount());
+                    //璁$畻瀹炰粯閲戦
+                    int flag2 = divide.compareTo(receivedAmount);
+                    BigDecimal subtract = new BigDecimal("0.00");
+                    //鐢熸垚鎶垫墸鏄庣粏璁板綍
+                    FeeAccountDetailPo feeAccountDetailPo = new FeeAccountDetailPo();
+                    if (flag2 == -1) { //绉垎鎹㈢畻閲戦灏忎簬瀹炰粯閲戦
+                        subtract = receivedAmount.subtract(divide);
+                        feeAccountDetailPo.setAmount(divide.toString()); //绉垎鎶垫墸閲戦
+                    } else if (flag < 1) { //绉垎鎹㈢畻閲戦灏忎簬绛変簬瀹炰粯閲戦
+                        subtract = receivedAmount.subtract(divide);
+                        feeAccountDetailPo.setAmount(divide.toString()); //绉垎鎶垫墸閲戦
+                    } else {
+                        feeAccountDetailPo.setAmount(receivedAmount.toString()); //绉垎鎶垫墸閲戦
+                    }
+                    payFeeDetailPo.setReceivedAmount(subtract.toString());
+                    feeAccountDetailPo.setFadId(GenerateCodeFactory.getGeneratorId(GenerateCodeFactory.CODE_PREFIX_fadId));
+                    feeAccountDetailPo.setDetailId(payFeeDetailPo.getDetailId());
+                    feeAccountDetailPo.setCommunityId(payFeeDetailPo.getCommunityId());
+                    feeAccountDetailPo.setState("1003"); //1001 鏃犳姷鎵� 1002 鐜伴噾璐︽埛鎶垫墸 1003 绉垎璐︽埛鎶垫墸 1004 浼樻儬鍒告姷鎵�
+                    feeAccountDetailServiceSMOImpl.saveFeeAccountDetail(feeAccountDetailPo);
+                } else if (!StringUtil.isEmpty(param.getString("acctType")) && param.getString("acctType").equals("2003")) { //鐜伴噾璐︽埛
+                    //璐︽埛閲戦
+                    BigDecimal amount = new BigDecimal(param.getString("amount"));
+                    //瀹炴敹閲戦
+                    BigDecimal receivedAmount = new BigDecimal(payFeeDetailPo.getReceivedAmount());
+                    int flag = amount.compareTo(receivedAmount);
+                    BigDecimal redepositAmount = new BigDecimal("0.00");
+                    if (flag == 1) { //鐜伴噾璐︽埛澶т簬瀹炴敹閲戦锛屽氨鐢ㄥ疄鏀堕噾棰�
+                        redepositAmount = receivedAmount;
+                    }
+                    if (flag > -1) { //鐜伴噾璐︽埛澶т簬绛変簬瀹炴敹閲戦锛屽氨鐢ㄥ疄鏀堕噾棰�
+                        redepositAmount = receivedAmount;
+                    }
+                    if (flag == -1) { //鐜伴噾璐︽埛灏忎簬瀹炴敹閲戦锛屽氨鐢ㄧ幇閲戣处鎴�
+                        redepositAmount = amount;
+                    }
+                    if (flag < 1) { //鐜伴噾璐︽埛灏忎簬绛変簬瀹炴敹閲戦锛屽氨鐢ㄧ幇閲戣处鎴�
+                        redepositAmount = amount;
+                    }
+                    if (flag == 0) { //鐜伴噾璐︽埛绛変簬瀹炴敹閲戦
+                        redepositAmount = amount;
+                    }
+                    //鐢熸垚鎶垫墸鏄庣粏璁板綍
+                    FeeAccountDetailPo feeAccountDetailPo = new FeeAccountDetailPo();
+                    feeAccountDetailPo.setFadId(GenerateCodeFactory.getGeneratorId(GenerateCodeFactory.CODE_PREFIX_fadId));
+                    feeAccountDetailPo.setDetailId(payFeeDetailPo.getDetailId());
+                    feeAccountDetailPo.setCommunityId(payFeeDetailPo.getCommunityId());
+                    feeAccountDetailPo.setState("1002"); //1001 鏃犳姷鎵� 1002 鐜伴噾璐︽埛鎶垫墸 1003 绉垎璐︽埛鎶垫墸 1004 浼樻儬鍒告姷鎵�
+                    feeAccountDetailPo.setAmount(redepositAmount.toString()); //绉垎鎶垫墸閲戦
+                    feeAccountDetailServiceSMOImpl.saveFeeAccountDetail(feeAccountDetailPo);
+                }
+            }
             int flag = payFeeDetailNewV1InnerServiceSMOImpl.savePayFeeDetailNew(payFeeDetailPo);
             if (flag < 1) {
                 throw new CmdException("缂磋垂澶辫触");
             }
-            JSONObject fee = modifyFee(paramObj);
-            payFeePo = BeanConvertUtil.covertBean(fee, PayFeePo.class);
 
             flag = payFeeV1InnerServiceSMOImpl.updatePayFee(payFeePo);
             if (flag < 1) {
                 throw new CmdException("缂磋垂澶辫触");
             }
+        } catch (ParseException e) {
+            e.printStackTrace();
         } finally {
             DistributedLock.releaseDistributedLock(requestId, key);
         }
@@ -207,7 +347,11 @@
             JSONObject discountBusiness = null;
             JSONArray selectDiscounts = paramObj.getJSONArray("selectDiscount");
             for (int discountIndex = 0; discountIndex < selectDiscounts.size(); discountIndex++) {
-                addPayFeeDetailDiscount(paramObj, selectDiscounts.getJSONObject(discountIndex));
+                JSONObject param = selectDiscounts.getJSONObject(discountIndex);
+                if (!StringUtil.isEmpty(param.getString("ruleId")) && param.getString("ruleId").equals("102020008")) {
+                    return;
+                }
+                addPayFeeDetailDiscount(paramObj, param);
             }
         }
 
@@ -412,11 +556,6 @@
      * @return 璁㈠崟鏈嶅姟鑳藉鎺ュ彈鐨勬姤鏂�
      */
     public JSONObject addFeeDetail(JSONObject paramInJson) {
-        String remark = paramInJson.getString("remark");
-        if (!StringUtil.isEmpty(remark)) {
-            remark = "-" + remark;
-        }
-        paramInJson.put("remark", "鐜板満鏀堕摱鍙版敮浠�" + remark);
         JSONObject businessFeeDetail = new JSONObject();
         businessFeeDetail.putAll(paramInJson);
         businessFeeDetail.put("detailId", GenerateCodeFactory.getGeneratorId(GenerateCodeFactory.CODE_PREFIX_detailId));
@@ -451,12 +590,44 @@
             targetEndTime = endCalender.getTime();
             paramInJson.put("tmpCycles", cycles.doubleValue());
             businessFeeDetail.put("cycles", cycles.doubleValue());
-            businessFeeDetail.put("receivableAmount", receivedAmount.doubleValue());
+            //澶勭悊 鍙兘杩樺瓨鍦� 瀹炴敹鎵嬪伐鍑忓厤鐨勬儏鍐�
+            if(paramInJson.containsKey("receivableAmount") && !StringUtil.isEmpty(paramInJson.getString("receivableAmount"))){
+                businessFeeDetail.put("receivableAmount", paramInJson.getString("receivableAmount"));
+            }else {
+                businessFeeDetail.put("receivableAmount", receivedAmount.doubleValue());
+            }
+        } else if ("-103".equals(paramInJson.getString("cycles"))) { //杩欓噷鎸夌即璐圭粨鏉熸椂闂寸即璐�
+            String custEndTime = paramInJson.getString("custEndTime");
+            Date endDates = DateUtil.getDateFromStringB(custEndTime);
+            Calendar c = Calendar.getInstance();
+            c.setTime(endDates);
+            c.add(Calendar.DAY_OF_MONTH, 1);
+            endDates = c.getTime();//杩欐槸鏄庡ぉ
+            targetEndTime = endDates;
+            BigDecimal receivedAmount1 =  new BigDecimal(Double.parseDouble(paramInJson.getString("receivedAmount")));
+            cycles = receivedAmount1.divide(feePrice, 4, BigDecimal.ROUND_HALF_EVEN);
+            paramInJson.put("tmpCycles", cycles.doubleValue());
+            businessFeeDetail.put("cycles", cycles.doubleValue());
+            BigDecimal receivedAmount = new BigDecimal(Double.parseDouble(paramInJson.getString("receivedAmount")));
+            //澶勭悊 鍙兘杩樺瓨鍦� 瀹炴敹鎵嬪伐鍑忓厤鐨勬儏鍐�
+            if(paramInJson.containsKey("receivableAmount") && !StringUtil.isEmpty(paramInJson.getString("receivableAmount"))){
+                businessFeeDetail.put("receivableAmount", paramInJson.getString("receivableAmount"));
+            }else {
+                businessFeeDetail.put("receivableAmount", receivedAmount.doubleValue());
+            }
         } else {
-            targetEndTime = computeFeeSMOImpl.getFeeEndTimeByCycles(feeDto, paramInJson.getString("cycles"));
+            targetEndTime = computeFeeSMOImpl.getFeeEndTimeByCycles(feeDto, paramInJson.getString("cycles"));//鏍规嵁缂磋垂鍛ㄦ湡璁$畻 缁撴潫鏃堕棿
             cycles = new BigDecimal(Double.parseDouble(paramInJson.getString("cycles")));
             double tmpReceivableAmount = cycles.multiply(feePrice).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue();
             businessFeeDetail.put("receivableAmount", tmpReceivableAmount);
+
+            //鍑虹閫掑闂澶勭悊
+            if (FeeConfigDto.COMPUTING_FORMULA_RANT_RATE.equals(feeDto.getComputingFormula())) {
+                computeFeeSMOImpl.dealRentRateCycle(feeDto,cycles.doubleValue());
+                if(feeDto.getOweFee()> 0){
+                    businessFeeDetail.put("receivableAmount", feeDto.getOweFee());
+                }
+            }
         }
         businessFeeDetail.put("endTime", DateUtil.getFormatTimeString(targetEndTime, DateUtil.DATE_FORMATE_STRING_A));
         paramInJson.put("feeInfo", feeDto);
@@ -472,8 +643,24 @@
         Calendar endCalender = Calendar.getInstance();
         endCalender.setTime(endTime);
         int hours = 0;
+        //-101鑷畾涔夐噾棰� -102鑷畾涔夊懆鏈� -103 鑷畾涔夌粨鏉熸椂闂�
         if ("-101".equals(paramInJson.getString("cycles"))) {
             endCalender = getTargetEndTime(endCalender, Double.parseDouble(paramInJson.getString("tmpCycles")));
+            System.out.println(endCalender);
+        } else if ("-103".equals(paramInJson.getString("cycles"))) {
+            String custEndTime = paramInJson.getString("custEndTime");
+            SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
+            Date endDates = null;
+            try {
+                endDates = format.parse(custEndTime);
+            } catch (ParseException e) {
+                e.printStackTrace();
+            }
+            Calendar c = Calendar.getInstance();
+            c.setTime(endDates);
+            c.add(Calendar.DAY_OF_MONTH, 1);
+            endDates = c.getTime();//杩欐槸鏄庡ぉ
+            endCalender.setTime(endDates);
         } else {
             endCalender.add(Calendar.MONTH, Integer.parseInt(paramInJson.getString("cycles")));
         }
@@ -491,8 +678,12 @@
             feeInfo.setState(FeeDto.STATE_FINISH);
         }
         feeInfo.setEndTime(endCalender.getTime());
+        Date maxEndTime = feeInfo.getDeadlineTime();
+        if (FeeDto.FEE_FLAG_CYCLE.equals(feeInfo.getFeeFlag())) {
+            maxEndTime = feeInfo.getConfigEndTime();
+        }
         //鍒ゆ柇 缁撴潫鏃堕棿 鏄惁澶т簬 璐圭敤椤� 缁撴潫鏃堕棿锛岃繖閲� 瀹归敊涓�涓嬶紝濡傛灉 璐圭敤缁撴潫鏃堕棿澶т簬 璐圭敤椤圭粨鏉熸椂闂� 30澶� 璧版姤閿� 灞炰簬澶氱即璐�
-        if (feeInfo.getEndTime().getTime() - feeInfo.getConfigEndTime().getTime() > 30 * 24 * 60 * 60 * 1000L) {
+        if (feeInfo.getEndTime().getTime() - maxEndTime.getTime() > 30 * 24 * 60 * 60 * 1000L) {
             throw new IllegalArgumentException("缂磋垂瓒呰繃浜� 璐圭敤椤圭粨鏉熸椂闂�");
         }
         Map feeMap = BeanConvertUtil.beanCovertMap(feeInfo);
@@ -507,16 +698,15 @@
         paramInJson.put("carPayerObjId", feeInfo.getPayerObjId());
 
         // 鍛ㄦ湡鎬ф敹璐广�佺即璐瑰悗锛屽埌鏈熸棩鏈熷湪璐圭敤椤圭粓姝㈡棩鏈熷悗锛屽垯璁剧疆缂磋垂鐘舵�佺粨鏉燂紝璁剧疆缁撴潫鏃ユ湡涓鸿垂鐢ㄩ」缁堟鏃ユ湡
-        if (FeeFlagTypeConstant.CYCLE.equals(feeInfo.getFeeFlag())) {
+        if (!FeeFlagTypeConstant.ONETIME.equals(feeInfo.getFeeFlag())) {
             //杩欓噷 瀹归敊浜斿ぉ鏃堕棿
-            Date configEndTime = feeInfo.getConfigEndTime();
             Calendar calendar = Calendar.getInstance();
-            calendar.setTime(configEndTime);
+            calendar.setTime(maxEndTime);
             calendar.add(Calendar.DAY_OF_MONTH, -5);
-            configEndTime = calendar.getTime();
-            if (feeInfo.getEndTime().after(configEndTime)) {
+            maxEndTime = calendar.getTime();
+            if (feeInfo.getEndTime().after(maxEndTime)) {
                 businessFee.put("state", FeeStateConstant.END);
-                businessFee.put("endTime", feeInfo.getConfigEndTime());
+                businessFee.put("endTime", maxEndTime);
             }
         }
         return businessFee;
@@ -529,25 +719,92 @@
         if (jsonArray == null || jsonArray.size() < 1) {
             return;
         }
-        //搴旀敹娆� totalFeePrice
-        BigDecimal totalFeePrice = new BigDecimal(paramObj.getString("totalFeePrice")); //搴旀敹娆�
-        //瀹炴敹娆� receivedAmount
-        BigDecimal receivedAmount = new BigDecimal(paramObj.getString("receivedAmount")); //瀹炴敹娆撅紙鎵f閲戦锛�
-
-        BigDecimal redepositAmount = new BigDecimal("0.00");//鎶垫墸閲戦
+        List<AccountDto> accountDtos = new ArrayList<>();
         for (int columnIndex = 0; columnIndex < jsonArray.size(); columnIndex++) {
+            //搴旀敹娆� totalFeePrice
+            BigDecimal totalFeePrice = new BigDecimal(paramObj.getString("totalFeePrice")); //搴旀敹娆�
+            //瀹炴敹娆� receivedAmount
+            BigDecimal receivedAmount = new BigDecimal(paramObj.getString("receivedAmount")); //瀹炴敹娆撅紙鎵f閲戦锛�
+            BigDecimal redepositAmount = new BigDecimal("0.00");//鎶垫墸閲戦
             JSONObject param = jsonArray.getJSONObject(columnIndex);
+            if (!StringUtil.isEmpty(param.getString("acctType")) && param.getString("acctType").equals("2004")) { //绉垎璐︽埛
+                //鑾峰彇鎶垫墸姣斾緥
+                BigDecimal deductionProportion = new BigDecimal(param.getString("deductionProportion"));
+                //璁$畻瀹炴敹娆炬墍鎵g殑绉垎
+                BigDecimal multiply = receivedAmount.multiply(deductionProportion);
+                receivedAmount = multiply;
+            }
             //璐︽埛閲戦
-            BigDecimal amount = new BigDecimal(param.getString("amount")); //璐︽埛閲戦
+            BigDecimal amount = new BigDecimal(param.getString("amount"));
             int flag = amount.compareTo(receivedAmount);
-            if (flag == -1) {//璐︽埛閲戦灏忎簬瀹炴敹娆�
-                receivedAmount = receivedAmount.subtract(amount);
+            if (flag == -1) { //璐︽埛閲戦灏忎簬瀹炴敹娆�
                 redepositAmount = amount;//鎶垫墸閲戦
             } else {
                 redepositAmount = receivedAmount;//鎶垫墸閲戦
             }
-            //鍓╀綑閲戦
-            amount.compareTo(receivedAmount);
+            if (!StringUtil.isEmpty(param.getString("acctType")) && param.getString("acctType").equals("2004")) {
+                //鑾峰彇鏈�澶ф姷鎵gН鍒�
+                BigDecimal maximumNumber = new BigDecimal(param.getString("maximumNumber"));
+                //鑾峰彇绉垎鎶垫墸
+                BigDecimal deductionProportion = new BigDecimal(param.getString("deductionProportion"));
+                int flag2 = amount.compareTo(maximumNumber);
+                if (flag2 == 1) { //璐︽埛绉垎澶т簬鏈�澶т娇鐢ㄧН鍒嗭紝灏辩敤鏈�澶т娇鐢ㄧН鍒嗘姷鎵�
+                    int flag3 = maximumNumber.compareTo(receivedAmount);
+                    if (flag3 == 1) { //濡傛灉鏈�澶т娇鐢ㄧН鍒嗗ぇ浜庡疄鏀堕噾棰濇姷鎵gН鍒嗭紝灏辨妸瀹炴敹閲戦鎶垫墸绉垎璧嬪�肩粰鎶垫墸绉垎
+                        redepositAmount = receivedAmount;
+                    } else if (flag3 > -1) {//濡傛灉鏈�澶т娇鐢ㄧН鍒嗗ぇ浜庣瓑浜庡疄鏀堕噾棰濇姷鎵gН鍒嗭紝灏辨妸瀹炴敹閲戦鎶垫墸绉垎璧嬪�肩粰鎶垫墸绉垎
+                        redepositAmount = receivedAmount;
+                    } else {
+                        redepositAmount = maximumNumber;
+                    }
+                }
+                if (flag2 > -1) { //璐︽埛绉垎澶т簬绛変簬鏈�澶т娇鐢ㄧН鍒嗭紝灏辩敤鏈�澶т娇鐢ㄧН鍒嗘姷鎵�
+                    int flag3 = maximumNumber.compareTo(receivedAmount);
+                    if (flag3 == 1) { //濡傛灉鏈�澶т娇鐢ㄧН鍒嗗ぇ浜庡疄鏀堕噾棰濇姷鎵gН鍒嗭紝灏辨妸瀹炴敹閲戦鎶垫墸绉垎璧嬪�肩粰鎶垫墸绉垎
+                        redepositAmount = receivedAmount;
+                    } else if (flag3 > -1) {//濡傛灉鏈�澶т娇鐢ㄧН鍒嗗ぇ浜庣瓑浜庡疄鏀堕噾棰濇姷鎵gН鍒嗭紝灏辨妸瀹炴敹閲戦鎶垫墸绉垎璧嬪�肩粰鎶垫墸绉垎
+                        redepositAmount = receivedAmount;
+                    } else {
+                        redepositAmount = maximumNumber;
+                    }
+                }
+                if (flag2 == -1) { //璐︽埛绉垎灏忎簬鏈�澶т娇鐢ㄧН鍒嗭紝灏辩敤璐︽埛绉垎鎶垫墸
+                    int flag3 = amount.compareTo(receivedAmount);
+                    if (flag3 == 1) { //濡傛灉绉垎璐︽埛澶т簬瀹炴敹閲戦鎶垫墸绉垎锛屽氨鎶婂疄鏀堕噾棰濇姷鎵gН鍒嗚祴鍊肩粰鎶垫墸绉垎
+                        redepositAmount = receivedAmount;
+                    } else if (flag3 > -1) {//濡傛灉绉垎璐︽埛澶т簬绛変簬瀹炴敹閲戦鎶垫墸绉垎锛屽氨鎶婂疄鏀堕噾棰濇姷鎵gН鍒嗚祴鍊肩粰鎶垫墸绉垎
+                        redepositAmount = receivedAmount;
+                    } else {
+                        redepositAmount = amount;
+                    }
+                }
+                if (flag2 < 1) { //璐︽埛绉垎灏忎簬绛変簬鏈�澶т娇鐢ㄧН鍒嗭紝灏辩敤璐︽埛绉垎鎶垫墸
+                    int flag3 = amount.compareTo(receivedAmount);
+                    if (flag3 == 1) { //濡傛灉绉垎璐︽埛澶т簬瀹炴敹閲戦鎶垫墸绉垎锛屽氨鎶婂疄鏀堕噾棰濇姷鎵gН鍒嗚祴鍊肩粰鎶垫墸绉垎
+                        redepositAmount = receivedAmount;
+                    } else if (flag3 > -1) {//濡傛灉绉垎璐︽埛澶т簬绛変簬瀹炴敹閲戦鎶垫墸绉垎锛屽氨鎶婂疄鏀堕噾棰濇姷鎵gН鍒嗚祴鍊肩粰鎶垫墸绉垎
+                        redepositAmount = receivedAmount;
+                    } else {
+                        redepositAmount = amount;
+                    }
+                }
+                if (flag2 == 0) { //璐︽埛绉垎绛変簬鏈�澶т娇鐢ㄧН鍒�
+                    int flag3 = amount.compareTo(receivedAmount);
+                    if (flag3 == 1) { //濡傛灉绉垎璐︽埛澶т簬瀹炴敹閲戦鎶垫墸绉垎锛屽氨鎶婂疄鏀堕噾棰濇姷鎵gН鍒嗚祴鍊肩粰鎶垫墸绉垎
+                        redepositAmount = receivedAmount;
+                    } else if (flag3 > -1) {//濡傛灉绉垎璐︽埛澶т簬绛変簬瀹炴敹閲戦鎶垫墸绉垎锛屽氨鎶婂疄鏀堕噾棰濇姷鎵gН鍒嗚祴鍊肩粰鎶垫墸绉垎
+                        redepositAmount = receivedAmount;
+                    } else {
+                        redepositAmount = amount;
+                    }
+                }
+                //璁$畻绉垎鎹㈢畻鐨勯噾棰�
+                BigDecimal divide = redepositAmount.divide(deductionProportion);
+                BigDecimal divide1 = receivedAmount.divide(deductionProportion);
+                //璁$畻杩橀渶鏀粯鐨勯噾棰�
+                BigDecimal subtract = divide1.subtract(divide);
+                paramObj.put("receivedAmount", subtract);
+            }
             String acctId = param.getString("acctId");
             if (StringUtil.isEmpty(acctId)) {
                 throw new IllegalArgumentException("璐︽埛id涓虹┖锛�");
@@ -555,7 +812,7 @@
             AccountDto accountDto = new AccountDto();
             accountDto.setAcctId(acctId);
             //鏌ヨ璐︽埛閲戦
-            List<AccountDto> accountDtos = accountInnerServiceSMOImpl.queryAccounts(accountDto);
+            accountDtos = accountInnerServiceSMOImpl.queryAccounts(accountDto);
             Assert.listOnlyOne(accountDtos, "鏌ヨ璐︽埛閲戦閿欒锛�");
             if (accountDtos != null && accountDtos.size() > 0) {
                 AccountDto accountDto1 = accountDtos.get(0);
@@ -564,8 +821,6 @@
                     throw new UnsupportedOperationException("璐︽埛閲戦鎶垫墸涓嶈冻锛岃鎮ㄧ‘璁よ处鎴烽噾棰濓紒");
                 }
             }
-
-
             AccountDetailPo accountDetailPo = new AccountDetailPo();
             accountDetailPo.setDetailId(GenerateCodeFactory.getGeneratorId(GenerateCodeFactory.CODE_PREFIX_detailId));
             int flag1 = redepositAmount.compareTo(BigDecimal.ZERO);
@@ -586,8 +841,6 @@
                 throw new CmdException("鎵f澶辫触");
             }
         }
-
-
     }
 
     private static Calendar getTargetEndTime(Calendar endCalender, Double cycles) {

--
Gitblit v1.8.0