From 0b3ff378a9faaf9d7a4831b7f0de67378fe0dfea Mon Sep 17 00:00:00 2001
From: java110 <928255095@qq.com>
Date: 星期二, 30 五月 2023 12:20:15 +0800
Subject: [PATCH] optimize 统计

---
 service-fee/src/main/java/com/java110/fee/cmd/fee/PayOweFeeCmd.java |  137 ++++++++++++++++++++++++++++++++++++++-------
 1 files changed, 116 insertions(+), 21 deletions(-)

diff --git a/service-fee/src/main/java/com/java110/fee/cmd/fee/PayOweFeeCmd.java b/service-fee/src/main/java/com/java110/fee/cmd/fee/PayOweFeeCmd.java
index c900878..bf77990 100644
--- a/service-fee/src/main/java/com/java110/fee/cmd/fee/PayOweFeeCmd.java
+++ b/service-fee/src/main/java/com/java110/fee/cmd/fee/PayOweFeeCmd.java
@@ -4,31 +4,36 @@
 import com.alibaba.fastjson.JSONObject;
 import com.java110.core.annotation.Java110Cmd;
 import com.java110.core.annotation.Java110Transactional;
-import com.java110.core.context.DataFlowContext;
 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.GenerateCodeFactory;
+import com.java110.core.factory.Java110TransactionalFactory;
 import com.java110.core.log.LoggerFactory;
 import com.java110.core.smo.IComputeFeeSMO;
 import com.java110.dto.app.AppDto;
 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.feeReceipt.FeeReceiptDetailDto;
+import com.java110.dto.fee.FeeReceiptDetailDto;
+import com.java110.dto.owner.OwnerCarDto;
 import com.java110.dto.owner.OwnerDto;
+import com.java110.dto.parking.ParkingSpaceDto;
 import com.java110.dto.repair.RepairDto;
 import com.java110.dto.repair.RepairUserDto;
+import com.java110.dto.user.UserDto;
 import com.java110.intf.community.*;
 import com.java110.intf.fee.*;
+import com.java110.intf.user.IOwnerCarInnerServiceSMO;
+import com.java110.intf.user.IUserV1InnerServiceSMO;
+import com.java110.po.car.OwnerCarPo;
 import com.java110.po.fee.PayFeeDetailPo;
 import com.java110.po.fee.PayFeePo;
 import com.java110.po.feeReceipt.FeeReceiptPo;
 import com.java110.po.feeReceiptDetail.FeeReceiptDetailPo;
 import com.java110.po.owner.RepairPoolPo;
 import com.java110.po.owner.RepairUserPo;
-import com.java110.utils.constant.BusinessTypeConstant;
-import com.java110.utils.constant.CommonConstant;
 import com.java110.utils.constant.ResponseConstant;
 import com.java110.utils.exception.CmdException;
 import com.java110.utils.exception.ListenerExecuteException;
@@ -87,7 +92,16 @@
     private IRepairUserV1InnerServiceSMO repairUserV1InnerServiceSMOImpl;
 
     @Autowired
+    private IOwnerCarNewV1InnerServiceSMO ownerCarNewV1InnerServiceSMOImpl;
+
+    @Autowired
+    private IOwnerCarInnerServiceSMO ownerCarInnerServiceSMOImpl;
+
+    @Autowired
     private IComputeFeeSMO computeFeeSMOImpl;
+
+    @Autowired
+    private IUserV1InnerServiceSMO userV1InnerServiceSMOImpl;
 
 
     @Override
@@ -112,7 +126,11 @@
     @Java110Transactional
     public void doCmd(CmdEvent event, ICmdDataFlowContext dataFlowContext, JSONObject paramObj) throws CmdException, ParseException {
         logger.info("======娆犺垂缂磋垂杩斿洖======锛�" + JSONArray.toJSONString(paramObj));
-
+        String userId = dataFlowContext.getReqHeaders().get("user-id");
+        UserDto userDto = new UserDto();
+        userDto.setUserId(userId);
+        List<UserDto> userDtos = userV1InnerServiceSMOImpl.queryUsers(userDto);
+        Assert.listOnlyOne(userDtos, "鐢ㄦ埛鏈櫥褰�");
         //娣诲姞鍗曞厓淇℃伅
         List<FeeReceiptPo> feeReceiptPos = new ArrayList<>();
         List<FeeReceiptDetailPo> feeReceiptDetailPos = new ArrayList<>();
@@ -123,7 +141,7 @@
         for (int feeIndex = 0; feeIndex < fees.size(); feeIndex++) {
             feeObj = fees.getJSONObject(feeIndex);
             feeObj.put("communityId", paramObj.getString("communityId"));
-            if(paramObj.containsKey("oId")) {
+            if (paramObj.containsKey("oId")) {
                 feeObj.put("oId", paramObj.getString("oId"));
             }
             String remark = paramObj.getString("remark");
@@ -133,7 +151,8 @@
                 feeObj.put("remark", "绾夸笂鍏紬鍙锋敮浠�");
             }
 
-            getFeeReceiptDetailPo(dataFlowContext, feeObj, feeReceiptDetailPos, feeReceiptPos);
+            //todo 鍘荤即璐�
+            getFeeReceiptDetailPo(dataFlowContext, feeObj, feeReceiptDetailPos, feeReceiptPos, userDtos.get(0));
         }
 
         //杩欓噷鍙槸鍐欏叆 鏀舵嵁琛紝鏆備笉鑰冭檻 浜嬪姟涓�鑷存�ч棶棰橈紝灏辩畻鍐欏叆澶辫触 涔熷彧鏄奖鍝� 鏀舵嵁鎵撳嵃锛屽鏋� 璐靛叕鍙稿 鏀舵嵁瑕佹眰 姣旇緝楂橈紝涓嶈兘鏈夊け璐ョ殑鎯呭喌 璇峰姞鍏ヤ簨鍔$鐞�
@@ -164,7 +183,8 @@
 
     private void getFeeReceiptDetailPo(ICmdDataFlowContext dataFlowContext, JSONObject paramObj,
                                        List<FeeReceiptDetailPo> feeReceiptDetailPos,
-                                       List<FeeReceiptPo> feeReceiptPos) {
+                                       List<FeeReceiptPo> feeReceiptPos,
+                                       UserDto userDto) {
         int flag = 0;
         if (!paramObj.containsKey("primeRate")) {
             paramObj.put("primeRate", "6");
@@ -179,8 +199,12 @@
             paramObj.put("remark", "绾夸笂灏忕▼搴忔敮浠�");
         }
         paramObj.put("state", "1400");
-        addOweFeeDetail(paramObj, dataFlowContext, feeReceiptDetailPos, feeReceiptPos);
+        // todo 娣诲姞浜よ垂鏄庣粏
+        addOweFeeDetail(paramObj, dataFlowContext, feeReceiptDetailPos, feeReceiptPos, userDto);
         modifyOweFee(paramObj, dataFlowContext);
+
+        //淇敼杞﹁締
+        updateCarEndTime(paramObj);
 
         //鍒ゆ柇鏄惁鏈夋淳鍗曞睘鎬D
         FeeAttrDto feeAttrDto = new FeeAttrDto();
@@ -197,7 +221,7 @@
             repairPoolPo.setCommunityId(paramObj.getString("communityId"));
             repairPoolPo.setState(RepairDto.STATE_APPRAISE);
             flag = repairPoolV1InnerServiceSMOImpl.updateRepairPoolNew(repairPoolPo);
-            if(flag < 1){
+            if (flag < 1) {
                 throw new CmdException("淇敼澶辫触");
             }
         }
@@ -240,7 +264,7 @@
                 repairUser.setPreRuId(repairUserDtoList.get(0).getRuId());
                 repairUser.setRepairEvent("auditUser");
                 flag = repairUserV1InnerServiceSMOImpl.saveRepairUserNew(repairUserPo);
-                if(flag < 1){
+                if (flag < 1) {
                     throw new CmdException("淇敼澶辫触");
                 }
             } else {  //濡傛灉鏄憳宸ヤ唬瀹㈡姤淇垨鐢佃瘽鎶ヤ慨锛岀姸鎬佸氨鍙樻垚宸叉敮浠�
@@ -249,7 +273,7 @@
                 repairUserPo.setEndTime(DateUtil.getNow(DateUtil.DATE_FORMATE_STRING_A));
                 repairUserPo.setContext("宸叉敮浠�" + paramObj.getString("receivedAmount") + "鍏�");
                 flag = repairUserV1InnerServiceSMOImpl.updateRepairUserNew(repairUserPo);
-                if(flag < 1){
+                if (flag < 1) {
                     throw new CmdException("淇敼澶辫触");
                 }
             }
@@ -281,7 +305,7 @@
         if (!FeeDto.FEE_FLAG_CYCLE.equals(feeInfo.getFeeFlag())) {
             maxEndTime = feeInfo.getDeadlineTime();
         }
-        if(maxEndTime != null) { //杩欓噷鏁版嵁闂鐨勬儏鍐典笅
+        if (maxEndTime != null) { //杩欓噷鏁版嵁闂鐨勬儏鍐典笅
             Date endTime = DateUtil.getDateFromStringA(paramInJson.getString("endTime"));
             if (endTime.getTime() >= maxEndTime.getTime()) {
                 feeMap.put("state", FeeDto.STATE_FINISH);
@@ -289,7 +313,7 @@
         }
 
         businessFee.putAll(feeMap);
-        PayFeePo payFeePo =  BeanConvertUtil.covertBean(businessFee,PayFeePo.class);
+        PayFeePo payFeePo = BeanConvertUtil.covertBean(businessFee, PayFeePo.class);
         int flag = payFeeV1InnerServiceSMOImpl.updatePayFee(payFeePo);
         if (flag < 1) {
             throw new CmdException("淇敼澶辫触");
@@ -297,8 +321,9 @@
     }
 
     public void addOweFeeDetail(JSONObject paramInJson, ICmdDataFlowContext dataFlowContext,
-                                      List<FeeReceiptDetailPo> feeReceiptDetailPos,
-                                      List<FeeReceiptPo> feeReceiptPos) {
+                                List<FeeReceiptDetailPo> feeReceiptDetailPos,
+                                List<FeeReceiptPo> feeReceiptPos,
+                                UserDto userDto) {
 
         JSONObject businessFeeDetail = new JSONObject();
         businessFeeDetail.putAll(paramInJson);
@@ -327,8 +352,8 @@
         cycles = receivedAmount.divide(feePrice, 4, BigDecimal.ROUND_HALF_EVEN);
         businessFeeDetail.put("cycles", receivedAmount.divide(feePrice, 2, BigDecimal.ROUND_HALF_UP).doubleValue());
 
-        if(!paramInJson.containsKey("receivableAmount") || StringUtil.isEmpty(paramInJson.getString("receivableAmount"))){
-            paramInJson.put("receivableAmount",paramInJson.getString("receivedAmount"));
+        if (!paramInJson.containsKey("receivableAmount") || StringUtil.isEmpty(paramInJson.getString("receivableAmount"))) {
+            paramInJson.put("receivableAmount", paramInJson.getString("receivedAmount"));
         }
 
         businessFeeDetail.put("receivableAmount", paramInJson.getString("receivableAmount"));
@@ -338,12 +363,18 @@
         paramInJson.put("feeInfo", feeDto);
         paramInJson.put("cycles", cycles.doubleValue());
         PayFeeDetailPo payFeeDetailPo = BeanConvertUtil.covertBean(businessFeeDetail, PayFeeDetailPo.class);
-        if(paramInJson.containsKey("oId")) {
+        if (paramInJson.containsKey("oId")) {
             payFeeDetailPo.setPayOrderId(paramInJson.getString("oId"));
-        }else{
-            payFeeDetailPo.setPayOrderId(payFeeDetailPo.getDetailId());
+        } else {
+            String oId = Java110TransactionalFactory.getOId();
+            if (StringUtil.isEmpty(oId)) {
+                oId = payFeeDetailPo.getDetailId();
+            }
+            payFeeDetailPo.setPayOrderId(oId);
 
         }
+        payFeeDetailPo.setCashierId(userDto.getUserId());
+        payFeeDetailPo.setCashierName(userDto.getName());
 
         int flag = payFeeDetailV1InnerServiceSMOImpl.savePayFeeDetailNew(payFeeDetailPo);
 
@@ -380,4 +411,68 @@
         feeReceiptPos.add(feeReceiptPo);
     }
 
+    private void updateCarEndTime(JSONObject paramObj) {
+        int flag;
+        FeeDto feeDto = new FeeDto();
+        feeDto.setFeeId(paramObj.getString("feeId"));
+        feeDto.setCommunityId(paramObj.getString("communityId"));
+        List<FeeDto> feeDtos = feeInnerServiceSMOImpl.queryFees(feeDto);
+
+        if (feeDtos == null || feeDtos.size() < 1) {
+            return;
+        }
+        if (!FeeDto.PAYER_OBJ_TYPE_CAR.equals(feeDtos.get(0).getPayerObjType())) {
+            return;
+        }
+        Date feeEndTime = feeDtos.get(0).getEndTime();
+        OwnerCarDto ownerCarDto = new OwnerCarDto();
+        ownerCarDto.setCommunityId(paramObj.getString("communityId"));
+        ownerCarDto.setCarId(feeDtos.get(0).getPayerObjId());
+        ownerCarDto.setCarTypeCd("1001"); //涓氫富杞﹁締
+        List<OwnerCarDto> ownerCarDtos = ownerCarInnerServiceSMOImpl.queryOwnerCars(ownerCarDto);
+
+        if (ownerCarDtos == null || ownerCarDtos.size() < 1) {
+            return;
+        }
+        //鑾峰彇杞︿綅id
+        String psId = ownerCarDtos.get(0).getPsId();
+        //鑾峰彇杞﹁締鐘舵��(1001 姝e父鐘舵�侊紝2002 娆犺垂鐘舵��  3003 杞︿綅閲婃斁)
+        String carState = ownerCarDtos.get(0).getState();
+        if (!StringUtil.isEmpty(psId) && "3003".equals(carState)) {
+            ParkingSpaceDto parkingSpaceDto = new ParkingSpaceDto();
+            parkingSpaceDto.setPsId(psId);
+            List<ParkingSpaceDto> parkingSpaceDtos = parkingSpaceInnerServiceSMOImpl.queryParkingSpaces(parkingSpaceDto);
+            Assert.listOnlyOne(parkingSpaceDtos, "鏌ヨ杞︿綅淇℃伅閿欒锛�");
+            //鑾峰彇杞︿綅鐘舵��(鍑哄敭 S锛屽嚭绉� H 锛岀┖闂� F)
+            String state = parkingSpaceDtos.get(0).getState();
+            if (!StringUtil.isEmpty(state) && !state.equals("F")) {
+                throw new IllegalArgumentException("杞︿綅宸茶浣跨敤锛屼笉鑳藉啀缂磋垂锛�");
+            }
+        }
+
+
+        Calendar endTimeCalendar = null;
+        //杞︿綅璐圭敤缁
+        for (OwnerCarDto tmpOwnerCarDto : ownerCarDtos) {
+            //鍚庝粯璐� 鎴栬�呬俊鐢ㄦ湡杞﹁締 鍔犱竴涓湀
+            if (FeeConfigDto.PAYMENT_CD_AFTER.equals(feeDtos.get(0).getPaymentCd())
+                    || OwnerCarDto.CAR_TYPE_CREDIT.equals(tmpOwnerCarDto.getCarType())) {
+                endTimeCalendar = Calendar.getInstance();
+                endTimeCalendar.setTime(feeEndTime);
+                endTimeCalendar.add(Calendar.MONTH, 1);
+                feeEndTime = endTimeCalendar.getTime();
+            }
+            if (tmpOwnerCarDto.getEndTime().getTime() >= feeEndTime.getTime()) {
+                continue;
+            }
+            OwnerCarPo ownerCarPo = new OwnerCarPo();
+            ownerCarPo.setMemberId(tmpOwnerCarDto.getMemberId());
+            ownerCarPo.setEndTime(DateUtil.getFormatTimeString(feeEndTime, DateUtil.DATE_FORMATE_STRING_A));
+            flag = ownerCarNewV1InnerServiceSMOImpl.updateOwnerCarNew(ownerCarPo);
+            if (flag < 1) {
+                throw new CmdException("缂磋垂澶辫触");
+            }
+        }
+    }
+
 }

--
Gitblit v1.8.0