From d6b30c6097618391359565de48519614363e8a26 Mon Sep 17 00:00:00 2001
From: wuxw <928255095@qq.com>
Date: 星期五, 05 四月 2024 22:23:13 +0800
Subject: [PATCH] 优化时间不对bug

---
 service-fee/src/main/java/com/java110/fee/cmd/fee/PayFeeCmd.java |  164 ++++++++++++++++++++++++++++--------------------------
 1 files changed, 85 insertions(+), 79 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 a84c14f..d2a74df 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
@@ -4,6 +4,7 @@
 import com.alibaba.fastjson.JSONObject;
 import com.java110.core.annotation.Java110Cmd;
 import com.java110.core.annotation.Java110Transactional;
+import com.java110.core.context.CmdContextUtils;
 import com.java110.core.context.ICmdDataFlowContext;
 import com.java110.core.event.cmd.Cmd;
 import com.java110.core.event.cmd.CmdEvent;
@@ -38,9 +39,7 @@
 import com.java110.po.payFee.PayFeeDetailDiscountPo;
 import com.java110.utils.cache.CommonCache;
 import com.java110.utils.constant.FeeFlagTypeConstant;
-import com.java110.utils.constant.ResponseConstant;
 import com.java110.utils.exception.CmdException;
-import com.java110.utils.exception.ListenerExecuteException;
 import com.java110.utils.lock.DistributedLock;
 import com.java110.utils.util.*;
 import com.java110.vo.ResultVo;
@@ -144,7 +143,7 @@
         feeDto = feeDtos.get(0);
 
         if (FeeDto.STATE_FINISH.equals(feeDto.getState())) {
-            throw new IllegalArgumentException("鏀惰垂宸茬粡缁撴潫锛屼笉鑳藉啀缂磋垂");
+            throw new CmdException("鏀惰垂宸茬粡缁撴潫锛屼笉鑳藉啀缂磋垂");
         }
 
         Date endTime = feeDto.getEndTime();
@@ -153,22 +152,15 @@
         feeConfigDto.setConfigId(feeDto.getConfigId());
         feeConfigDto.setCommunityId(reqJson.getString("communityId"));
         List<FeeConfigDto> feeConfigDtos = feeConfigInnerServiceSMOImpl.queryFeeConfigs(feeConfigDto);
-
-        if (feeConfigDtos == null || feeConfigDtos.size() != 1) {
-            throw new IllegalArgumentException("璐圭敤椤逛笉瀛樺湪");
+        if (ListUtil.isNull(feeConfigDtos)) {
+            throw new CmdException("璐圭敤椤逛笉瀛樺湪");
         }
-        //涓�娆℃�ц垂鐢� 鍜岄棿鎺ユ�ц垂鐢�
+        // 鑾峰彇璐圭敤缁撴潫鏃堕棿
         Date maxEndTime = feeDtos.get(0).getDeadlineTime();
         //鍛ㄦ湡鎬ц垂鐢�
-        if (maxEndTime == null || FeeDto.FEE_FLAG_CYCLE.equals(feeConfigDtos.get(0).getFeeFlag())) {
+        if (maxEndTime == null) {
             maxEndTime = DateUtil.getDateFromStringA(feeConfigDtos.get(0).getEndTime());
         }
-//        Date maxEndTime = null;
-//        if (!StringUtil.isEmpty(feeDto.getFeeFlag()) && feeDto.getFeeFlag().equals(FeeDto.FEE_FLAG_CYCLE)) { //鍛ㄦ湡鎬ц垂鐢�
-//            maxEndTime = DateUtil.getDateFromStringA(feeConfigDtos.get(0).getEndTime());
-//        } else { //涓�娆℃�ц垂鐢� 鍜岄棿鎺ユ�ц垂鐢�
-//            maxEndTime = feeDtos.get(0).getDeadlineTime();
-//        }
 
         if (maxEndTime != null && endTime != null && !FeeDto.FEE_FLAG_ONCE.equals(feeDtos.get(0).getFeeFlag())) {
             Date newDate = DateUtil.stepMonth(endTime, reqJson.getDouble("cycles").intValue());
@@ -181,9 +173,7 @@
         for (int paramIndex = 0; paramIndex < selectUserAccount.size(); paramIndex++) {
             JSONObject param = selectUserAccount.getJSONObject(paramIndex);
             String maximumNumber = param.getString("maximumNumber");
-
         }
-
 
 
         //todo 鏄惁鎸夌即璐规椂闂存缂磋垂
@@ -191,7 +181,7 @@
 
         //todo 鏍¢獙 浼樻儬
         JSONArray selectDiscounts = reqJson.getJSONArray("selectDiscount");
-        if(!ListUtil.isNull(selectDiscounts)) {
+        if (!ListUtil.isNull(selectDiscounts)) {
             for (int discountIndex = 0; discountIndex < selectDiscounts.size(); discountIndex++) {
                 JSONObject param = selectDiscounts.getJSONObject(discountIndex);
                 Assert.hasKeyAndValue(param, "discountId", "鏈寘鍚紭鎯營D");
@@ -207,7 +197,7 @@
         logger.debug("paramObj : {}", paramObj);
         String payOrderId = paramObj.getString("payOrderId");
 
-        String userId = cmdDataFlowContext.getReqHeaders().get("user-id");
+        String userId = CmdContextUtils.getUserId(cmdDataFlowContext);
         UserDto userDto = new UserDto();
         userDto.setUserId(userId);
         List<UserDto> userDtos = userV1InnerServiceSMOImpl.queryUsers(userDto);
@@ -229,16 +219,18 @@
             FeeDto feeInfo = (FeeDto) paramObj.get("feeInfo");
             endTime = feeInfo.getEndTime();
             feeDetail.put("payableAmount", feeDetail.getString("receivableAmount"));
-            //todo 灏佽 淇敼璐圭敤鏃堕棿鎶ユ枃
-            JSONObject fee = modifyFee(paramObj);
-            payFeePo = BeanConvertUtil.covertBean(fee, PayFeePo.class);
+
             PayFeeDetailPo payFeeDetailPo = BeanConvertUtil.covertBean(feeDetail, PayFeeDetailPo.class);
             payFeeDetailPo.setReceivableAmount(feeDetail.getString("totalFeePrice"));
             //todo 缂撳瓨鏀舵嵁缂栧彿
             CommonCache.setValue(payFeeDetailPo.getDetailId() + CommonCache.RECEIPT_CODE, receiptCode, CommonCache.DEFAULT_EXPIRETIME_TWO_MIN);
 
+            //todo 灏佽 淇敼璐圭敤鏃堕棿鎶ユ枃
+            JSONObject fee = modifyFee(paramObj, payFeeDetailPo);
+            payFeePo = BeanConvertUtil.covertBean(fee, PayFeePo.class);
+
             //todo 鍒ゆ柇鏄惁鏈夋姌鎵h鍒�
-            hasDiscount(paramObj, payFeePo, payFeeDetailPo,feeInfo);
+            hasDiscount(paramObj, payFeePo, payFeeDetailPo, feeInfo);
 
             // todo 澶勭悊鐢ㄦ埛璐︽埛
             dealUserAccount(paramObj, payFeeDetailPo);
@@ -257,6 +249,31 @@
             payFeeDetailPo.setCashierId(userDtos.get(0).getUserId());
             payFeeDetailPo.setCashierName(userDtos.get(0).getName());
             payFeeDetailPo.setOpenInvoice("N");
+            if (!StringUtil.isEmpty(paramObj.getString("cashAmount")) && !StringUtil.isEmpty(paramObj.getString("integralAmount"))) {
+                BigDecimal cashAmount = new BigDecimal(paramObj.getString("cashAmount")).setScale(2, BigDecimal.ROUND_HALF_UP);
+                BigDecimal integralAmount = new BigDecimal(paramObj.getString("integralAmount")).setScale(2, BigDecimal.ROUND_HALF_UP);
+                if (!StringUtil.isEmpty(payFeeDetailPo.getRemark())) {
+                    payFeeDetailPo.setRemark(payFeeDetailPo.getRemark() + "锛岀幇閲戣处鎴锋姷鎵�" + cashAmount + "鍏冿紝绉垎璐︽埛鎶垫墸" + integralAmount + "鍏�");
+                } else {
+                    payFeeDetailPo.setRemark("鐜伴噾璐︽埛鎶垫墸" + cashAmount + "鍏冿紝绉垎璐︽埛鎶垫墸" + integralAmount + "鍏�");
+                }
+            }
+            if (!StringUtil.isEmpty(paramObj.getString("cashAmount")) && StringUtil.isEmpty(paramObj.getString("integralAmount"))) {
+                BigDecimal cashAmount = new BigDecimal(paramObj.getString("cashAmount")).setScale(2, BigDecimal.ROUND_HALF_UP);
+                if (!StringUtil.isEmpty(payFeeDetailPo.getRemark())) {
+                    payFeeDetailPo.setRemark(payFeeDetailPo.getRemark() + "锛岀幇閲戣处鎴锋姷鎵�" + cashAmount + "鍏�");
+                } else {
+                    payFeeDetailPo.setRemark("鐜伴噾璐︽埛鎶垫墸" + cashAmount + "鍏�");
+                }
+            }
+            if (StringUtil.isEmpty(paramObj.getString("cashAmount")) && !StringUtil.isEmpty(paramObj.getString("integralAmount"))) {
+                BigDecimal integralAmount = new BigDecimal(paramObj.getString("integralAmount")).setScale(2, BigDecimal.ROUND_HALF_UP);
+                if (!StringUtil.isEmpty(payFeeDetailPo.getRemark())) {
+                    payFeeDetailPo.setRemark(payFeeDetailPo.getRemark() + "锛岀Н鍒嗚处鎴锋姷鎵�" + integralAmount + "鍏�");
+                } else {
+                    payFeeDetailPo.setRemark("绉垎璐︽埛鎶垫墸" + integralAmount + "鍏�");
+                }
+            }
             int flag = payFeeDetailNewV1InnerServiceSMOImpl.savePayFeeDetailNew(payFeeDetailPo);
             if (flag < 1) {
                 throw new CmdException("缂磋垂澶辫触");
@@ -355,8 +372,19 @@
                 } else if (flag < 1) { //绉垎鎹㈢畻閲戦灏忎簬绛変簬瀹炰粯閲戦
                     subtract = receivedAmount.subtract(divide);
                 }
-                integralSum = integralSum.add(subtract);
+//                integralSum = integralSum.add(subtract);
                 payFeeDetailPo.setReceivedAmount(subtract.toString());
+                integralSum = integralSum.add(divide);
+                // todo 濡傛灉绉垎澶т簬0
+                if (integralSum.doubleValue() > 0) {
+                    FeeAccountDetailPo feeAccountDetailPo = new FeeAccountDetailPo();
+                    feeAccountDetailPo.setFadId(GenerateCodeFactory.getGeneratorId(GenerateCodeFactory.CODE_PREFIX_fadId));
+                    feeAccountDetailPo.setDetailId(payFeeDetailPo.getDetailId());
+                    feeAccountDetailPo.setCommunityId(payFeeDetailPo.getCommunityId());
+                    feeAccountDetailPo.setAmount(integralSum.doubleValue() + "");
+                    feeAccountDetailPo.setState("1003"); //1001 鏃犳姷鎵� 1002 鐜伴噾璐︽埛鎶垫墸 1003 绉垎璐︽埛鎶垫墸 1004 浼樻儬鍒告姷鎵�
+                    feeAccountDetailServiceSMOImpl.saveFeeAccountDetail(feeAccountDetailPo);
+                }
             } else if (AccountDto.ACCT_TYPE_CASH.equals(param.getString("acctType"))) { //鐜伴噾璐︽埛
                 //瀹炴敹閲戦
                 BigDecimal receivedAmount = new BigDecimal(payFeeDetailPo.getReceivedAmount());
@@ -416,7 +444,7 @@
      * @param payFeeDetailPo
      * @throws ParseException
      */
-    private void hasDiscount(JSONObject paramObj, PayFeePo payFeePo, PayFeeDetailPo payFeeDetailPo,FeeDto feeDto) throws ParseException {
+    private void hasDiscount(JSONObject paramObj, PayFeePo payFeePo, PayFeeDetailPo payFeeDetailPo, FeeDto feeDto) throws ParseException {
         if (!paramObj.containsKey("selectDiscount")) {
             return;
         }
@@ -451,7 +479,7 @@
                 payFeePo.setEndTime(df.format(cal.getTime()));
 
                 BigDecimal value = new BigDecimal(payFeeDetailPo.getGiftAmount());
-                value = value.add(new BigDecimal(specValue).multiply(new BigDecimal((double)feePriceMap.get("feePrice"))));
+                value = value.add(new BigDecimal(specValue).multiply(new BigDecimal(feePriceMap.get("feePrice").toString())));
                 payFeeDetailPo.setGiftAmount(value.doubleValue() + "");
             }
         }
@@ -562,7 +590,7 @@
         feeDto.setCommunityId(paramObj.getString("communityId"));
         List<FeeDto> feeDtos = feeInnerServiceSMOImpl.queryFees(feeDto);
 
-        if (feeDtos == null || feeDtos.size() < 1) {
+        if (ListUtil.isNull(feeDtos)) {
             return;
         }
         if (!FeeDto.PAYER_OBJ_TYPE_CAR.equals(feeDtos.get(0).getPayerObjType())) {
@@ -575,7 +603,7 @@
         ownerCarDto.setCarTypeCd("1001"); //涓氫富杞﹁締
         List<OwnerCarDto> ownerCarDtos = ownerCarInnerServiceSMOImpl.queryOwnerCars(ownerCarDto);
 
-        if (ownerCarDtos == null || ownerCarDtos.size() < 1) {
+        if (ListUtil.isNull(ownerCarDtos)) {
             return;
         }
         //鑾峰彇杞︿綅id
@@ -744,7 +772,6 @@
         }
         feeDto = feeDtos.get(0);
         businessFeeDetail.put("startTime", DateUtil.getFormatTimeStringA(feeDto.getEndTime()));
-        int hours = 0;
         Date targetEndTime = null;
         BigDecimal cycles = null;
         Map feePriceAll = computeFeeSMOImpl.getFeePrice(feeDto);
@@ -837,60 +864,15 @@
         return businessFeeDetail;
     }
 
-    public JSONObject modifyFee(JSONObject paramInJson) {
+    public JSONObject modifyFee(JSONObject paramInJson, PayFeeDetailPo payFeeDetailPo) {
 
         JSONObject businessFee = new JSONObject();
         FeeDto feeInfo = (FeeDto) paramInJson.get("feeInfo");
-        Date endTime = feeInfo.getEndTime();
-        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")));
-        } 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();//杩欐槸鏄庡ぉ
-            endCalender.setTime(endDates);
-        } else if ("-105".equals(paramInJson.getString("cycles"))) {
-            String customEndTime = paramInJson.getString("customEndTime");
-            Date endDates = DateUtil.getDateFromStringB(customEndTime);
-            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")));
-        }
-        if (FeeDto.FEE_FLAG_ONCE.equals(feeInfo.getFeeFlag())) {
-            if (feeInfo.getDeadlineTime() != null) {
-                endCalender.setTime(feeInfo.getDeadlineTime());
-            } else if (!StringUtil.isEmpty(feeInfo.getCurDegrees())) {
-                endCalender.setTime(feeInfo.getCurReadingTime());
-            } else if (feeInfo.getImportFeeEndTime() == null) {
-                endCalender.setTime(feeInfo.getConfigEndTime());
-            } else {
-                endCalender.setTime(feeInfo.getImportFeeEndTime());
-            }
-            //businessFee.put("state",FeeDto.STATE_FINISH);
-            feeInfo.setState(FeeDto.STATE_FINISH);
-        }
-        feeInfo.setEndTime(endCalender.getTime());
-        Date maxEndTime = feeInfo.getDeadlineTime();
-        if (FeeDto.FEE_FLAG_CYCLE.equals(feeInfo.getFeeFlag())) {
-            maxEndTime = feeInfo.getConfigEndTime();
-        }
 
-        if (FeeDto.FEE_FLAG_CYCLE_ONCE.equals(feeInfo.getFeeFlag())) {
-            maxEndTime = feeInfo.getMaxEndTime();
-        }
+        String endTime = DateUtil.getNextSecTime(payFeeDetailPo.getEndTime());
+        feeInfo.setEndTime(DateUtil.getDateFromStringA(endTime));
 
-        //濡傛灉闂存瓏鎬ц垂鐢ㄦ病鏈夎缃粨鏉熸椂闂� 鍒欏彇璐圭敤椤圭殑
+        Date maxEndTime = feeInfo.getMaxEndTime();
         if (maxEndTime == null) {
             maxEndTime = feeInfo.getConfigEndTime();
         }
@@ -931,7 +913,7 @@
     public void dealAccount(JSONObject paramObj) {
         //鍒ゆ柇閫夋嫨鐨勮处鍙�
         JSONArray jsonArray = paramObj.getJSONArray("selectUserAccount");
-        if (jsonArray == null || jsonArray.size() < 1) {
+        if (ListUtil.isNull(jsonArray)) {
             return;
         }
         List<AccountDto> accountDtos = new ArrayList<>();
@@ -1121,8 +1103,32 @@
         tmpPayFeeDetailPo.setEndTime(reqJson.getString("customStartTime"));
         tmpPayFeeDetailPo.setState(FeeDetailDto.STATE_OWE);
         tmpPayFeeDetailPo.setOpenInvoice("N");
-
         tmpPayFeeDetailPo.setRemark("鎸夌即璐规椂闂存缂磋垂,杩欓儴鍒嗚垂鐢ㄦ寜娆犺垂鐨勬柟寮忛噸鏂扮敓鎴愶紝璇峰湪" + payObjNameRemark + "涓婃煡鐪�");
+        if (!StringUtil.isEmpty(reqJson.getString("cashAmount")) && !StringUtil.isEmpty(reqJson.getString("integralAmount"))) {
+            BigDecimal cashAmount = new BigDecimal(reqJson.getString("cashAmount")).setScale(2, BigDecimal.ROUND_HALF_UP);
+            BigDecimal integralAmount = new BigDecimal(reqJson.getString("integralAmount")).setScale(2, BigDecimal.ROUND_HALF_UP);
+            if (!StringUtil.isEmpty(tmpPayFeeDetailPo.getRemark())) {
+                tmpPayFeeDetailPo.setRemark(tmpPayFeeDetailPo.getRemark() + "锛岀幇閲戣处鎴锋姷鎵�" + cashAmount + "鍏冿紝绉垎璐︽埛鎶垫墸" + integralAmount + "鍏�");
+            } else {
+                tmpPayFeeDetailPo.setRemark("鐜伴噾璐︽埛鎶垫墸" + cashAmount + "鍏冿紝绉垎璐︽埛鎶垫墸" + integralAmount + "鍏�");
+            }
+        }
+        if (!StringUtil.isEmpty(reqJson.getString("cashAmount")) && StringUtil.isEmpty(reqJson.getString("integralAmount"))) {
+            BigDecimal cashAmount = new BigDecimal(reqJson.getString("cashAmount")).setScale(2, BigDecimal.ROUND_HALF_UP);
+            if (!StringUtil.isEmpty(tmpPayFeeDetailPo.getRemark())) {
+                tmpPayFeeDetailPo.setRemark(tmpPayFeeDetailPo.getRemark() + "锛岀幇閲戣处鎴锋姷鎵�" + cashAmount + "鍏�");
+            } else {
+                tmpPayFeeDetailPo.setRemark("鐜伴噾璐︽埛鎶垫墸" + cashAmount + "鍏�");
+            }
+        }
+        if (StringUtil.isEmpty(reqJson.getString("cashAmount")) && !StringUtil.isEmpty(reqJson.getString("integralAmount"))) {
+            BigDecimal integralAmount = new BigDecimal(reqJson.getString("integralAmount")).setScale(2, BigDecimal.ROUND_HALF_UP);
+            if (!StringUtil.isEmpty(tmpPayFeeDetailPo.getRemark())) {
+                tmpPayFeeDetailPo.setRemark(tmpPayFeeDetailPo.getRemark() + "锛岀Н鍒嗚处鎴锋姷鎵�" + integralAmount + "鍏�");
+            } else {
+                tmpPayFeeDetailPo.setRemark("绉垎璐︽埛鎶垫墸" + integralAmount + "鍏�");
+            }
+        }
         int flag = payFeeDetailNewV1InnerServiceSMOImpl.savePayFeeDetailNew(tmpPayFeeDetailPo);
 
         if (flag < 1) {

--
Gitblit v1.8.0