From b88a288f4f787b509463678e3cd9ccfa3f37014b Mon Sep 17 00:00:00 2001
From: chengf <cgf12138@163.com>
Date: 星期三, 11 三月 2026 12:01:05 +0800
Subject: [PATCH] 导入测试

---
 service-fee/src/main/java/com/java110/fee/cmd/fee/PayFeePreCmd.java |  224 +++++++++++++++++++++++++++++++++++++++++++++++++------
 1 files changed, 199 insertions(+), 25 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..33c9969 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,32 +4,40 @@
 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.CommunitySettingFactory;
 import com.java110.core.factory.GenerateCodeFactory;
 import com.java110.core.log.LoggerFactory;
 import com.java110.core.smo.IComputeFeeSMO;
+import com.java110.dto.account.AccountDetailDto;
 import com.java110.dto.account.AccountDto;
 import com.java110.dto.community.CommunityDto;
-import com.java110.dto.couponUser.CouponUserDto;
+import com.java110.dto.coupon.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.IAccountInnerServiceSMO;
-import com.java110.intf.acct.ICouponUserV1InnerServiceSMO;
+import com.java110.dto.fee.ComputeDiscountDto;
+import com.java110.dto.payment.PaymentPoolDto;
+import com.java110.dto.payment.PaymentPoolValueDto;
+import com.java110.dto.wechat.SmallWeChatDto;
+import com.java110.intf.acct.*;
 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.AccountDetailPo;
+import com.java110.po.account.AccountPo;
 import com.java110.utils.cache.CommonCache;
+import com.java110.utils.cache.MappingCache;
+import com.java110.utils.constant.MappingConstant;
 import com.java110.utils.constant.ResponseConstant;
+import com.java110.utils.constant.WechatConstant;
 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.*;
 import org.slf4j.Logger;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.http.HttpStatus;
@@ -39,8 +47,10 @@
 import java.text.ParseException;
 import java.text.SimpleDateFormat;
 import java.util.ArrayList;
+import java.util.Date;
 import java.util.List;
 import java.util.Map;
+import java.util.stream.Collectors;
 
 /**
  * 绫昏〃杩帮細鍒犻櫎
@@ -53,15 +63,21 @@
  * // modify by 寮犱笁 at 2021-09-12 绗�10琛屽湪鏌愮鍦烘櫙涓嬪瓨鍦ㄦ煇绉峛ug 闇�瑕佷慨澶嶏紝娉ㄩ噴10鑷�20琛� 鍔犲叆 20琛岃嚦30琛�
  */
 @Java110Cmd(serviceCode = "fee.payFeePre")
-public class PayFeePreCmd extends AbstractServiceCmdListener {
-    private static Logger logger = LoggerFactory.getLogger(PayFeePreCmd.class);
+public class PayFeePreCmd extends Cmd {
 
+    private static Logger logger = LoggerFactory.getLogger(PayFeePreCmd.class);
 
     @Autowired
     private IFeeInnerServiceSMO feeInnerServiceSMOImpl;
 
     @Autowired
     private IRoomInnerServiceSMO roomInnerServiceSMOImpl;
+
+    @Autowired
+    private IPaymentPoolV1InnerServiceSMO paymentPoolV1InnerServiceSMOImpl;
+
+    @Autowired
+    private IPaymentPoolValueV1InnerServiceSMO paymentPoolValueV1InnerServiceSMOImpl;
 
     @Autowired
     private IFeeConfigInnerServiceSMO feeConfigInnerServiceSMOImpl;
@@ -86,6 +102,7 @@
 
     @Autowired
     private IComputeFeeSMO computeFeeSMOImpl;
+
     @Autowired
     private ICouponUserV1InnerServiceSMO couponUserV1InnerServiceSMOImpl;
 
@@ -93,7 +110,19 @@
     private IAccountInnerServiceSMO accountInnerServiceSMOImpl;
 
     @Autowired
+    private IAccountDetailInnerServiceSMO accountDetailInnerServiceSMOImpl;
+
+    @Autowired
     private ICommunityV1InnerServiceSMO communityV1InnerServiceSMOImpl;
+
+    @Autowired
+    private IFeeAccountDetailServiceSMO feeAccountDetailServiceSMOImpl;
+
+    //閿�(绉垎璐︽埛鏈�澶т娇鐢ㄧН鍒�)
+    public static final String MAXIMUM_NUMBER = "MAXIMUM_NUMBER";
+
+    //閿�(绉垎璐︽埛鎶垫墸姣斾緥)
+    public static final String DEDUCTION_PROPORTION = "DEDUCTION_PROPORTION";
 
     @Override
     public void validate(CmdEvent event, ICmdDataFlowContext cmdDataFlowContext, JSONObject reqJson) {
@@ -108,14 +137,56 @@
         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);
 
+        String userId = cmdDataFlowContext.getReqHeaders().get("user-id");
+
         String appId = cmdDataFlowContext.getReqHeaders().get("app-id");
         reqJson.put("appId", appId);
+        reqJson.put("userId", userId);
 
         FeeDto feeDto = new FeeDto();
         feeDto.setFeeId(reqJson.getString("feeId"));
@@ -127,13 +198,19 @@
         feeDto = feeDtos.get(0);
         reqJson.put("feeTypeCd", feeDto.getFeeTypeCd());
         reqJson.put("feeId", feeDto.getFeeId());
+
         Map feePriceAll = computeFeeSMOImpl.getFeePrice(feeDto);
+        //todo 璁$畻搴旀敹
         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 tmpReceivableAmount = cycles.multiply(receivableAmount).setScale(4, BigDecimal.ROUND_HALF_EVEN).doubleValue();
+        tmpReceivableAmount = MoneyUtil.computePriceScale(tmpReceivableAmount, feeDto.getScale(), Integer.parseInt(feeDto.getDecimalPlace()));
+
         JSONObject paramOut = new JSONObject();
         paramOut.put("receivableAmount", tmpReceivableAmount);
-        paramOut.put("oId", GenerateCodeFactory.getGeneratorId(GenerateCodeFactory.CODE_PREFIX_oId));
+        SmallWeChatDto smallWeChatDto = get(reqJson.getString("communityId"));
+        paramOut.put("oId", smallWeChatDto.getOrderPre() + GenerateCodeFactory.getGeneratorId(GenerateCodeFactory.CODE_PREFIX_oId));
+
 
         //瀹炴敹閲戦
         BigDecimal tmpReceivedAmout = new BigDecimal(tmpReceivableAmount);
@@ -155,6 +232,13 @@
         if (receivedAmount <= 0) {
             receivedAmount = 0.0;
         }
+        //todo 灏忔暟鐐瑰鐞�
+        receivedAmount = MoneyUtil.computePriceScale(
+                receivedAmount,
+                feeDto.getScale(),
+                Integer.parseInt(feeDto.getDecimalPlace())
+        );
+
         paramOut.put("receivedAmount", receivedAmount);
 
         String feeName = getObjName(feeDto);
@@ -164,6 +248,43 @@
         reqJson.putAll(paramOut);
         CommonCache.setValue("payFeePre" + paramOut.getString("oId"), reqJson.toJSONString(), 24 * 60 * 60);
         cmdDataFlowContext.setResponseEntity(responseEntity);
+    }
+
+    public SmallWeChatDto get(String community){
+        SmallWeChatDto smallWeChatDto = new SmallWeChatDto();
+        //鐢变簬瀵屾湁鏀粯鏂瑰紡瑕佷粠鏁版嵁搴撻噷闈㈠彇鍊硷紝鎵�浠ユ澶勮鏌ヨ
+        PaymentPoolDto paymentPoolDto = new PaymentPoolDto();
+//        paymentPoolDto.setCommunityId(community);
+        paymentPoolDto.setPage(1);
+        paymentPoolDto.setRow(10);
+        List<PaymentPoolDto> paymentPoolDtos = paymentPoolV1InnerServiceSMOImpl.queryPaymentPools(paymentPoolDto);
+        List<PaymentPoolDto> collect = paymentPoolDtos.stream().filter(e -> e.getPaymentType().equals("FUIOU")).collect(Collectors.toList());
+        PaymentPoolValueDto paymentPoolValueDto = new PaymentPoolValueDto();
+        paymentPoolValueDto.setPpId(collect.get(0).getPpId());
+        paymentPoolValueDto.setCommunityId(community);
+        List<PaymentPoolValueDto> values =  paymentPoolValueV1InnerServiceSMOImpl.queryPaymentPoolValues(paymentPoolValueDto);
+        Map<String, List<PaymentPoolValueDto>> payMap = values.stream().collect(Collectors.groupingBy(PaymentPoolValueDto::getColumnKey));
+        if(payMap.containsKey("FUIOU_APP_ID")){
+            smallWeChatDto.setAppId(payMap.get("FUIOU_APP_ID").get(0).getColumnValue());
+        }else{
+            smallWeChatDto.setAppId(MappingCache.getValue(WechatConstant.WECHAT_DOMAIN, "appId"));
+        }
+        if(payMap.containsKey("FUIOU_MCHNT_KEY")){
+            smallWeChatDto.setAppSecret(payMap.get("FUIOU_MCHNT_KEY").get(0).getColumnValue());
+        }else{
+            smallWeChatDto.setAppSecret(MappingCache.getValue(WechatConstant.WECHAT_DOMAIN, "appSecret"));
+        }
+        if(payMap.containsKey("FUIOU_MERCHANT_ID")){
+            smallWeChatDto.setMchId(payMap.get("FUIOU_MERCHANT_ID").get(0).getColumnValue());
+        }else{
+            smallWeChatDto.setMchId(MappingCache.getValue(MappingConstant.WECHAT_STORE_DOMAIN, "mchId"));
+        }
+        if(payMap.containsKey("FUIOU_ORDER_PRE")){
+            smallWeChatDto.setOrderPre(payMap.get("FUIOU_ORDER_PRE").get(0).getColumnValue());
+        }else{
+            smallWeChatDto.setOrderPre("1066");
+        }
+        return smallWeChatDto;
     }
 
     private String getObjName(FeeDto feeDto) {
@@ -224,25 +345,78 @@
         accountDto.setAcctIds(acctIds.toArray(new String[acctIds.size()]));
         List<AccountDto> accountDtos = accountInnerServiceSMOImpl.queryAccounts(accountDto);
 
-        if (accountDtos == null || accountDtos.size() < 1) {
+        if (ListUtil.isNull(accountDtos)) {
             reqJson.put("deductionAmount", 0.0);
             return 0.0;
         }
-
-        BigDecimal totalAccountAmount = new BigDecimal(0);
+        BigDecimal money = new BigDecimal(0);
+        BigDecimal cashMoney = new BigDecimal("0.00"); //鎶垫墸鐨勭幇閲戣处鎴�
+        BigDecimal pointsMoney = new BigDecimal(0.00); //鎶垫墸鐨勭Н鍒嗘暟
+        BigDecimal pointsMoneyNow = new BigDecimal(0.00); //绉垎杞崲涓虹幇閲戠殑瀹為檯鏁�
+        BigDecimal totalAccountAmount = new BigDecimal(0.00);
+        //鑾峰彇搴旀敹閲戦
+        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"));
+        }
         for (AccountDto tmpAccountDto : accountDtos) {
-            totalAccountAmount = totalAccountAmount.add(new BigDecimal(tmpAccountDto.getAmount()));
+            int compare = dedAmount.compareTo(BigDecimal.ZERO);
+            if (AccountDto.ACCT_TYPE_CASH.equals(tmpAccountDto.getAcctType()) && compare > 0) { //鐜伴噾璐︽埛
+                //璐︽埛閲戦
+                BigDecimal amount = new BigDecimal(tmpAccountDto.getAmount());
+                int flag = amount.compareTo(dedAmount);
+                if (flag == 1 || flag == 0) { //鐜伴噾璐︽埛澶т簬搴旀敹閲戦锛屾垨鐜伴噾璐︽埛绛変簬搴旀敹閲戦锛屽氨鐢ㄥ簲鏀堕噾棰濇姷鎵�
+                    cashMoney = dedAmount;
+                    dedAmount = new BigDecimal("0.0");
+                }
+                if (flag == -1) { //鐜伴噾璐︽埛灏忎簬搴旀敹閲戦锛屽氨鐢ㄧ幇閲戣处鎴锋姷鎵�
+                    cashMoney = amount;
+                    dedAmount = dedAmount.subtract(amount);
+                }
+                money = money.add(cashMoney);
+            } else if ("2004".equals(tmpAccountDto.getAcctType()) && compare > 0) { //绉垎璐︽埛
+                //绉垎璐︽埛鏈�澶т娇鐢ㄧН鍒�
+                String maximumNumber = CommunitySettingFactory.getValue(reqJson.getString("communityId"), MAXIMUM_NUMBER);
+                BigDecimal maxNumber = new BigDecimal(maximumNumber);
+                //绉垎璐︽埛鎶垫墸姣斾緥
+                String deductionProportion = CommunitySettingFactory.getValue(reqJson.getString("communityId"), DEDUCTION_PROPORTION);
+                BigDecimal deductionProportionNum = new BigDecimal(deductionProportion);
+                //绉垎璐︽埛閲戦
+                BigDecimal amount = new BigDecimal(tmpAccountDto.getAmount());
+                int flag = amount.compareTo(maxNumber);
+                if (flag == -1) { //绉垎璐︽埛閲戦灏忎簬绉垎璐︽埛鏈�澶т娇鐢ㄧН鍒嗭紝灏辩敤绉垎璐︽埛鎶垫墸
+                    pointsMoney = amount;
+                } else if (flag == 0) { //绉垎璐︽埛閲戦绛変簬绉垎璐︽埛鏈�澶т娇鐢ㄧН鍒嗭紝灏辩敤绉垎璐︽埛鎶垫墸
+                    pointsMoney = amount;
+                } else if (flag == 1) { //绉垎璐︽埛閲戦澶т簬绉垎璐︽埛鏈�澶т娇鐢ㄧН鍒嗭紝灏辩敤鏈�澶т娇鐢ㄧН鍒嗘姷鎵�
+                    pointsMoney = maxNumber;
+                }
+                //璁$畻鎶垫墸绉垎鎶垫墸鐨勯噾棰�  绉垎闄や互姣斾緥绛変簬璐︽埛鑳芥姷鎵g殑閽辨暟
+                BigDecimal integralMoney = pointsMoney.divide(deductionProportionNum);
+                BigDecimal redepositAmount = new BigDecimal("0.00");
+                int count = integralMoney.compareTo(dedAmount);
+                if (count == 1 || count == 0) { //绉垎鎶垫墸鐨勯噾棰濆ぇ浜庡簲鏀堕噾棰濓紝鎴栫Н鍒嗘姷鎵g殑閲戦绛変簬搴旀敹閲戦锛屽氨鐢ㄥ簲鏀堕噾棰濇姷鎵�
+                    redepositAmount = dedAmount;
+                    pointsMoney = dedAmount.multiply(deductionProportionNum);//搴旀敹閲戦涔樹互鎶垫墸姣斾緥鍗充负闇�瑕佹墸闄ょ殑绉垎鏁�
+                    pointsMoneyNow = dedAmount;
+                    dedAmount = new BigDecimal("0.0");
+                }
+                if (count == -1) { //绉垎鎶垫墸鐨勯噾棰濆皬浜庡簲鏀堕噾棰濓紝灏辩敤绉垎鎶垫墸鐨勯噾棰濇姷鎵�
+                    redepositAmount = integralMoney;
+                    dedAmount = dedAmount.subtract(integralMoney);//鍓╀綑搴旀敹閲戦
+                    pointsMoneyNow = integralMoney;
+                }
+                money = money.add(redepositAmount);
+            }
         }
-
-        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("deductionAmount", money.doubleValue());
+        reqJson.put("cashMoney", cashMoney); //鐜伴噾鎶垫墸
+        reqJson.put("pointsMoney", pointsMoney); //绉垎鎶垫墸鎵i櫎鏁�
+        reqJson.put("pointsMoneyNow", pointsMoneyNow); //绉垎鎶垫墸 瀹為檯鐜伴噾鏁�
         reqJson.put("selectUserAccount", BeanConvertUtil.beanCovertJSONArray(accountDtos));
-        return deductionAmount;
+        return money.doubleValue();
     }
 
     private double checkCouponUser(JSONObject paramObj) {

--
Gitblit v1.8.0