From 074caee550216dfd4bb676677ae33cbd837c5710 Mon Sep 17 00:00:00 2001
From: chengf <cgf12138@163.com>
Date: 星期三, 27 八月 2025 18:17:21 +0800
Subject: [PATCH] 暂存0827

---
 service-fee/src/main/java/com/java110/fee/cmd/fee/PayFeeCmd.java |   97 ++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 97 insertions(+), 0 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 d9ee08f..20e02ef 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
@@ -8,6 +8,7 @@
 import com.java110.core.context.ICmdDataFlowContext;
 import com.java110.core.event.cmd.Cmd;
 import com.java110.core.event.cmd.CmdEvent;
+import com.java110.core.factory.CommunitySettingFactory;
 import com.java110.core.factory.GenerateCodeFactory;
 import com.java110.core.factory.Java110TransactionalFactory;
 import com.java110.core.log.LoggerFactory;
@@ -39,6 +40,7 @@
 import com.java110.po.owner.RepairUserPo;
 import com.java110.po.payFee.PayFeeDetailDiscountPo;
 import com.java110.utils.cache.CommonCache;
+import com.java110.utils.cache.MappingCache;
 import com.java110.utils.constant.FeeFlagTypeConstant;
 import com.java110.utils.exception.CmdException;
 import com.java110.utils.lock.DistributedLock;
@@ -127,6 +129,18 @@
     @Autowired
     private IFinishFeeNotify finishFeeNotifyImpl;
 
+    //鍩�
+    public static final String DOMAIN_COMMON = "DOMAIN.COMMON";
+
+    //閿�
+    public static final String TOTAL_FEE_PRICE = "TOTAL_FEE_PRICE";
+
+    //閿�
+    public static final String RECEIVED_AMOUNT_SWITCH = "RECEIVED_AMOUNT_SWITCH";
+
+    //绂佺敤鐢佃剳绔彁浜ゆ敹璐规寜閽�
+    public static final String OFFLINE_PAY_FEE_SWITCH = "OFFLINE_PAY_FEE_SWITCH";
+
     @Override
     public void validate(CmdEvent event, ICmdDataFlowContext cmdDataFlowContext, JSONObject reqJson) throws CmdException {
         Assert.jsonObjectHaveKey(reqJson, "communityId", "璇锋眰鎶ユ枃涓湭鍖呭惈communityId鑺傜偣");
@@ -203,6 +217,13 @@
                 Assert.hasKeyAndValue(param, "discountId", "鏈寘鍚紭鎯營D");
                 Assert.hasKeyAndValue(param, "discountPrice", "鏈寘鍚紭鎯犻噾棰�");
             }
+        }
+        //鏍¢獙瀹炰粯閲戦涓嶈兘澶т簬娆犳閲戦
+        computeFeePrice(feeDtos);
+        BigDecimal amountOwed = new BigDecimal(feeDtos.get(0).getAmountOwed()); //搴旀敹娆�
+        BigDecimal receivedAmount = new BigDecimal(reqJson.getString("receivedAmount"));
+        if(receivedAmount.compareTo(amountOwed) >= 1){
+            throw new IllegalArgumentException("瀹炰粯閲戦涓嶈兘澶т簬娆犺垂閲戦");
         }
     }
 
@@ -325,6 +346,82 @@
         cmdDataFlowContext.setResponseEntity(ResultVo.createResponseEntity(feeReceiptDetailDto));
     }
 
+    private void computeFeePrice(List<FeeDto> feeDtos) {
+        if (ListUtil.isNull(feeDtos)) {
+            return;
+        }
+        String val = CommunitySettingFactory.getValue(feeDtos.get(0).getCommunityId(), TOTAL_FEE_PRICE);
+        if (StringUtil.isEmpty(val)) {
+            val = MappingCache.getValue(DOMAIN_COMMON, TOTAL_FEE_PRICE);
+        }
+        //鍏堝彇鍗曞皬鍖虹殑濡傛灉娌℃湁閰嶇疆 鍙� 鍏ㄥ眬鐨�
+        String received_amount_switch = CommunitySettingFactory.getValue(feeDtos.get(0).getCommunityId(), RECEIVED_AMOUNT_SWITCH);
+        if (StringUtil.isEmpty(received_amount_switch)) {
+            received_amount_switch = MappingCache.getValue(DOMAIN_COMMON, RECEIVED_AMOUNT_SWITCH);
+        }
+        //鍏堝彇鍗曞皬鍖虹殑濡傛灉娌℃湁閰嶇疆 鍙� 鍏ㄥ眬鐨�
+        String offlinePayFeeSwitch = CommunitySettingFactory.getValue(feeDtos.get(0).getCommunityId(), OFFLINE_PAY_FEE_SWITCH);
+        if (StringUtil.isEmpty(offlinePayFeeSwitch)) {
+            offlinePayFeeSwitch = MappingCache.getValue(DOMAIN_COMMON, OFFLINE_PAY_FEE_SWITCH);
+        }
+        for (FeeDto feeDto : feeDtos) {
+            try {
+                // 杞暟 * 鍛ㄦ湡 * 30 + 寮�濮嬫椂闂� = 鐩爣 鍒版湡鏃堕棿
+                Map<String, Object> targetEndDateAndOweMonth = computeFeeSMOImpl.getTargetEndDateAndOweMonth(feeDto);
+                Date targetEndDate = (Date) targetEndDateAndOweMonth.get("targetEndDate");
+                double oweMonth = (double) targetEndDateAndOweMonth.get("oweMonth");
+                feeDto.setCycle(feeDto.getPaymentCycle());
+                //todo 杩欓噷鑰冭檻 璐﹀崟妯″紡鐨勫満鏅�
+                if (FeeDto.FEE_FLAG_ONCE.equals(feeDto.getFeeFlag())) {
+                    feeDto.setCycle(oweMonth + "");
+                }
+                feeDto.setDeadlineTime(targetEndDate);
+                //todo 绠楄垂
+                doComputeFeePrice(feeDto, oweMonth);
+
+                feeDto.setVal(val);
+                //鍏抽棴 绾夸笅鏀堕摱鍔熻兘
+                if (StringUtil.isEmpty(received_amount_switch)) {
+                    feeDto.setReceivedAmountSwitch("1");//榛樿鍚敤瀹炴敹娆捐緭鍏ユ
+                } else {
+                    feeDto.setReceivedAmountSwitch(received_amount_switch);
+                }
+                feeDto.setOfflinePayFeeSwitch(offlinePayFeeSwitch);
+            } catch (Exception e) {
+                logger.error("鏌ヨ璐圭敤淇℃伅 锛岃垂鐢ㄤ俊鎭敊璇�", e);
+            }
+            //鍘绘帀澶氫綑0
+            feeDto.setSquarePrice(Double.parseDouble(feeDto.getSquarePrice()) + "");
+            feeDto.setAdditionalAmount(Double.parseDouble(feeDto.getAdditionalAmount()) + "");
+        }
+    }
+
+    /**
+     * 鏍规嵁鎴垮眿鏉ョ畻鍗曚环
+     *
+     * @param feeDto
+     */
+    private void doComputeFeePrice(FeeDto feeDto, double oweMonth) {
+        String computingFormula = feeDto.getComputingFormula();
+        Map feePriceAll = computeFeeSMOImpl.getFeePrice(feeDto);
+        feeDto.setFeePrice(Double.parseDouble(feePriceAll.get("feePrice").toString()));
+        //BigDecimal feeTotalPrice = new BigDecimal(Double.parseDouble(feePriceAll.get("feeTotalPrice").toString()));
+        feeDto.setFeeTotalPrice(MoneyUtil.computePriceScale(Double.parseDouble(feePriceAll.get("feeTotalPrice").toString()),
+                feeDto.getScale(),
+                Integer.parseInt(feeDto.getDecimalPlace())));
+        BigDecimal curFeePrice = new BigDecimal(feeDto.getFeePrice());
+        curFeePrice = curFeePrice.multiply(new BigDecimal(oweMonth));
+        feeDto.setAmountOwed(MoneyUtil.computePriceScale(curFeePrice.doubleValue(), feeDto.getScale(), Integer.parseInt(feeDto.getDecimalPlace())) + "");
+        //鍔ㄦ�佽垂鐢�
+        if ("4004".equals(computingFormula)
+                && FeeDto.FEE_FLAG_ONCE.equals(feeDto.getFeeFlag())
+                && !FeeDto.STATE_FINISH.equals(feeDto.getState())
+                && feeDto.getDeadlineTime() == null) {
+            feeDto.setDeadlineTime(DateUtil.getCurrentDate());
+        }
+        //鑰冭檻绉熼噾閫掑
+        computeFeeSMOImpl.dealRentRate(feeDto);
+    }
 
     private void dealUserAccount(JSONObject paramObj, PayFeeDetailPo payFeeDetailPo) {
         //鍒ゆ柇閫夋嫨鐨勮处鍙�

--
Gitblit v1.8.0