From 7958f1dddb8a7f4e70d232b07a7703955ecedae0 Mon Sep 17 00:00:00 2001
From: Your Name <you@example.com>
Date: 星期六, 26 八月 2023 12:45:33 +0800
Subject: [PATCH] 优化diamante

---
 service-fee/src/main/java/com/java110/fee/cmd/fee/PayBatchFeeCmd.java |   32 +++++++++++++++++++++-----------
 1 files changed, 21 insertions(+), 11 deletions(-)

diff --git a/service-fee/src/main/java/com/java110/fee/cmd/fee/PayBatchFeeCmd.java b/service-fee/src/main/java/com/java110/fee/cmd/fee/PayBatchFeeCmd.java
index 3c6651b..c6e5f56 100644
--- a/service-fee/src/main/java/com/java110/fee/cmd/fee/PayBatchFeeCmd.java
+++ b/service-fee/src/main/java/com/java110/fee/cmd/fee/PayBatchFeeCmd.java
@@ -29,6 +29,7 @@
 import com.java110.po.fee.PayFeePo;
 import com.java110.po.owner.RepairPoolPo;
 import com.java110.po.owner.RepairUserPo;
+import com.java110.utils.cache.CommonCache;
 import com.java110.utils.constant.FeeFlagTypeConstant;
 import com.java110.utils.constant.FeeConfigConstant;
 import com.java110.utils.constant.ResponseConstant;
@@ -103,6 +104,9 @@
     @Autowired
     private IUserV1InnerServiceSMO userV1InnerServiceSMOImpl;
 
+    @Autowired
+    private IFeeReceiptInnerServiceSMO feeReceiptInnerServiceSMOImpl;
+
 
     @Override
     public void validate(CmdEvent event, ICmdDataFlowContext cmdDataFlowContext, JSONObject reqJson) throws CmdException {
@@ -139,15 +143,15 @@
                 throw new IllegalArgumentException("璐圭敤椤逛笉瀛樺湪");
             }
             Date maxEndTime = feeDtos.get(0).getDeadlineTime();
-            if (!FeeDto.FEE_FLAG_ONCE.equals(feeConfigDtos.get(0).getFeeFlag())) {
-                try {
-                    maxEndTime = DateUtil.getDateFromString(feeConfigDtos.get(0).getEndTime(), DateUtil.DATE_FORMATE_STRING_A);
-                } catch (ParseException e) {
-                    logger.error("姣旇緝璐圭敤鏃ユ湡澶辫触", e);
-                }
-                Date newDate = DateUtil.stepMonth(endTime, paramInObj.getInteger("cycles") - 1);
+            //鍛ㄦ湡鎬ц垂鐢�
+            if (maxEndTime == null || FeeDto.FEE_FLAG_CYCLE.equals(feeConfigDtos.get(0).getFeeFlag())) {
+                maxEndTime = DateUtil.getDateFromStringA(feeConfigDtos.get(0).getEndTime());
+            }
+
+            if (maxEndTime != null && endTime != null && !FeeDto.FEE_FLAG_ONCE.equals(feeConfigDtos.get(0).getFeeFlag())) {
+                Date newDate = DateUtil.stepMonth(endTime, reqJson.getDouble("cycles").intValue());
                 if (newDate.getTime() > maxEndTime.getTime()) {
-                    throw new IllegalArgumentException("缂磋垂鍛ㄦ湡瓒呰繃 缂磋垂缁撴潫鏃堕棿");
+                    throw new IllegalArgumentException("缂磋垂鍛ㄦ湡瓒呰繃 缂磋垂缁撴潫鏃堕棿,璇风敤鎸夌粨鏉熸椂闂存柟寮忕即璐�");
                 }
             }
 
@@ -164,13 +168,17 @@
         List<UserDto> userDtos = userV1InnerServiceSMOImpl.queryUsers(userDto);
         Assert.listOnlyOne(userDtos, "鐢ㄦ埛鏈櫥褰�");
 
+        //todo 鐢熸垚鏀舵嵁缂栧彿
+        String receiptCode = feeReceiptInnerServiceSMOImpl.generatorReceiptCode(reqJson.getString("communityId"));
+
+
         JSONArray fees = reqJson.getJSONArray("fees");
         JSONObject paramInObj = null;
         JSONArray details = new JSONArray();
         for (int feeIndex = 0; feeIndex < fees.size(); feeIndex++) {
             try {
                 paramInObj = fees.getJSONObject(feeIndex);
-                doDeal(paramInObj, reqJson.getString("communityId"), cmdDataFlowContext, userDtos.get(0));
+                doDeal(paramInObj, reqJson.getString("communityId"),receiptCode, cmdDataFlowContext, userDtos.get(0));
             } catch (Exception e) {
                 logger.error("澶勭悊寮傚父", e);
                 throw new CmdException(e.getMessage());
@@ -184,7 +192,7 @@
         cmdDataFlowContext.setResponseEntity(ResultVo.createResponseEntity(data));
     }
 
-    private void doDeal(JSONObject paramObj, String communityId, ICmdDataFlowContext cmdDataFlowContext, UserDto userDto) throws Exception {
+    private void doDeal(JSONObject paramObj, String communityId,String receiptCode, ICmdDataFlowContext cmdDataFlowContext, UserDto userDto) throws Exception {
         paramObj.put("communityId", communityId);
         //鑾峰彇璁㈠崟ID
         String oId = Java110TransactionalFactory.getOId();
@@ -203,6 +211,8 @@
             payFeeDetailPo.setPayOrderId(oId);
             payFeeDetailPo.setCashierId(userDto.getUserId());
             payFeeDetailPo.setCashierName(userDto.getName());
+            //todo 缂撳瓨鏀舵嵁缂栧彿
+            CommonCache.setValue(payFeeDetailPo.getDetailId()+CommonCache.RECEIPT_CODE,receiptCode,CommonCache.DEFAULT_EXPIRETIME_TWO_MIN);
             int flag = payFeeDetailNewV1InnerServiceSMOImpl.savePayFeeDetailNew(payFeeDetailPo);
             if (flag < 1) {
                 throw new CmdException("缂磋垂澶辫触");
@@ -215,7 +225,7 @@
                 throw new CmdException("缂磋垂澶辫触");
             }
         } finally {
-            DistributedLock.releaseDistributedLock(requestId, key);
+            DistributedLock.releaseDistributedLock(key,requestId);
         }
         //杞﹁締寤舵湡
         updateOwnerCarEndTime(payFeePo, paramObj);

--
Gitblit v1.8.0