From 91ff9f520b66fc38a0ce8e7e2e06bdd54487ae1e Mon Sep 17 00:00:00 2001
From: wuxw <928255095@qq.com>
Date: 星期五, 22 七月 2022 00:01:05 +0800
Subject: [PATCH] 优化 间歇费用 相关bug

---
 service-fee/src/main/java/com/java110/fee/bmo/impl/QueryOweFeeImpl.java |  215 +++++++++++++++++++++++++++++++++++++++++++++++++----
 1 files changed, 197 insertions(+), 18 deletions(-)

diff --git a/service-fee/src/main/java/com/java110/fee/bmo/impl/QueryOweFeeImpl.java b/service-fee/src/main/java/com/java110/fee/bmo/impl/QueryOweFeeImpl.java
old mode 100644
new mode 100755
index 4d7a4f2..2759ecb
--- a/service-fee/src/main/java/com/java110/fee/bmo/impl/QueryOweFeeImpl.java
+++ b/service-fee/src/main/java/com/java110/fee/bmo/impl/QueryOweFeeImpl.java
@@ -1,6 +1,9 @@
 package com.java110.fee.bmo.impl;
 
 import com.alibaba.fastjson.JSONArray;
+import com.java110.core.factory.CommunitySettingFactory;
+import com.java110.core.factory.Java110ThreadPoolFactory;
+import com.java110.core.log.LoggerFactory;
 import com.java110.core.smo.IComputeFeeSMO;
 import com.java110.dto.RoomDto;
 import com.java110.dto.fee.FeeConfigDto;
@@ -17,19 +20,23 @@
 import com.java110.intf.user.IOwnerInnerServiceSMO;
 import com.java110.utils.cache.MappingCache;
 import com.java110.utils.constant.ResponseConstant;
+import com.java110.utils.exception.CmdException;
 import com.java110.utils.exception.ListenerExecuteException;
 import com.java110.utils.util.Assert;
 import com.java110.utils.util.DateUtil;
+import com.java110.utils.util.NumberUtil;
 import com.java110.utils.util.StringUtil;
 import com.java110.vo.ResultVo;
 import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.http.ResponseEntity;
 import org.springframework.stereotype.Service;
 
 import java.math.BigDecimal;
 import java.math.RoundingMode;
+import java.text.ParseException;
+import java.time.LocalDate;
+import java.time.format.DateTimeFormatter;
 import java.util.*;
 
 @Service
@@ -69,6 +76,9 @@
     //閿�
     public static final String RECEIVED_AMOUNT_SWITCH = "RECEIVED_AMOUNT_SWITCH";
 
+    //绂佺敤鐢佃剳绔彁浜ゆ敹璐规寜閽�
+    public static final String OFFLINE_PAY_FEE_SWITCH = "OFFLINE_PAY_FEE_SWITCH";
+
     @Override
     public ResponseEntity<String> query(FeeDto feeDto) {
 
@@ -83,10 +93,15 @@
         }
         List<FeeDto> tmpFeeDtos = new ArrayList<>();
         for (FeeDto tmpFeeDto : feeDtos) {
-            computeFeeSMOImpl.computeEveryOweFee(tmpFeeDto);//璁$畻娆犺垂閲戦
-            //濡傛灉閲戦涓�0 灏辨帓闄�
-            if (tmpFeeDto.getFeePrice() > 0 && tmpFeeDto.getEndTime().getTime() <= DateUtil.getCurrentDate().getTime()) {
-                tmpFeeDtos.add(tmpFeeDto);
+            try {
+                computeFeeSMOImpl.computeEveryOweFee(tmpFeeDto);//璁$畻娆犺垂閲戦
+                //濡傛灉閲戦涓�0 灏辨帓闄�
+                //if (tmpFeeDto.getFeePrice() > 0 && tmpFeeDto.getEndTime().getTime() <= DateUtil.getCurrentDate().getTime()) {
+                if (tmpFeeDto.getFeePrice() > 0) {
+                    tmpFeeDtos.add(tmpFeeDto);
+                }
+            } catch (Exception e) {
+                logger.error("鍙兘璐圭敤璧勬枡鏈夐棶棰樺鑷寸畻璐瑰け璐�", e);
             }
         }
 
@@ -118,8 +133,21 @@
         if (feeDtos == null || feeDtos.size() < 1) {
             return ResultVo.success();
         }
-
+        String cycel = null;
+        String custEndTime = null;
+        if (!StringUtil.isEmpty(feeDto.getCycle())) {
+            cycel = feeDto.getCycle();
+        }
+        if (!StringUtil.isEmpty(feeDto.getCustEndTime())) {
+            custEndTime = feeDto.getCustEndTime();
+        }
         feeDto = feeDtos.get(0);
+        if (!StringUtil.isEmpty(cycel)) {
+            feeDto.setCycle(cycel);
+        }
+        if (!StringUtil.isEmpty(custEndTime)) {
+            feeDto.setCustEndTime(custEndTime);
+        }
 
         if (FeeDto.PAYER_OBJ_TYPE_ROOM.equals(feeDto.getPayerObjType())) { //鎴垮眿鐩稿叧
             RoomDto roomDto = new RoomDto();
@@ -135,6 +163,7 @@
 
         } else if (FeeDto.PAYER_OBJ_TYPE_CAR.equals(feeDto.getPayerObjType())) {//杞︿綅鐩稿叧
             OwnerCarDto ownerCarDto = new OwnerCarDto();
+            ownerCarDto.setCarTypeCd("1001"); //涓氫富杞﹁締
             ownerCarDto.setCommunityId(feeDto.getCommunityId());
             ownerCarDto.setCarId(feeDto.getPayerObjId());
             List<OwnerCarDto> ownerCarDtos = ownerCarInnerServiceSMOImpl.queryOwnerCars(ownerCarDto);
@@ -151,18 +180,120 @@
             feeDto.setPayerObjName(ownerCarDto.getCarNum() + "(" + parkingSpaceDto.getAreaNum() + "鍋滆溅鍦�" + parkingSpaceDto.getNum() + "杞︿綅)");
             feeDto.setBuiltUpArea(parkingSpaceDto.getArea());
         }
-        double feePrice = computeFeeSMOImpl.getFeePrice(feeDto);
-        feeDto.setFeePrice(feePrice);
-        //搴旀敹娆惧彇鍊�
-        String val = MappingCache.getValue(DOMAIN_COMMON, TOTAL_FEE_PRICE);
-        feeDto.setVal(val);
-        String received_amount_switch = MappingCache.getValue(DOMAIN_COMMON, RECEIVED_AMOUNT_SWITCH);
-        if(StringUtil.isEmpty(received_amount_switch)){
-            feeDto.setReceivedAmountSwitch("1");//榛樿鍚敤瀹炴敹娆捐緭鍏ユ
+        Map feePriceAll = computeFeeSMOImpl.getFeePrice(feeDto);
+        feeDto.setFeePrice(Double.parseDouble(feePriceAll.get("feePrice").toString()));
+        feeDto.setFeeTotalPrice(Double.parseDouble(feePriceAll.get("feeTotalPrice").toString()));
+
+        if(!StringUtil.isEmpty(custEndTime)){
+            try {
+                computeFeeSMOImpl.dealRentRateCustEndTime(feeDto, DateUtil.getDateFromString(custEndTime,DateUtil.DATE_FORMATE_STRING_B));
+            } catch (Exception e) {
+                throw new CmdException("璁$畻璐圭敤澶辫触"+e);
+            }
         }else {
+            computeFeeSMOImpl.dealRentRateCycle(feeDto, NumberUtil.getDouble(feeDto.getCycle()));
+        }
+
+
+        //搴旀敹娆惧彇鍊�
+        //鍏堝彇鍗曞皬鍖虹殑濡傛灉娌℃湁閰嶇疆 鍙� 鍏ㄥ眬鐨�
+        String val = CommunitySettingFactory.getValue(feeDto.getCommunityId(), TOTAL_FEE_PRICE);
+        if (StringUtil.isEmpty(val)) {
+            val = MappingCache.getValue(DOMAIN_COMMON, TOTAL_FEE_PRICE);
+        }
+        feeDto.setVal(val);
+        //鍏堝彇鍗曞皬鍖虹殑濡傛灉娌℃湁閰嶇疆 鍙� 鍏ㄥ眬鐨�
+        String received_amount_switch = CommunitySettingFactory.getValue(feeDto.getCommunityId(), RECEIVED_AMOUNT_SWITCH);
+        if (StringUtil.isEmpty(received_amount_switch)) {
+            received_amount_switch = MappingCache.getValue(DOMAIN_COMMON, RECEIVED_AMOUNT_SWITCH);
+        }
+        //鍏抽棴 绾夸笅鏀堕摱鍔熻兘
+        if (StringUtil.isEmpty(received_amount_switch)) {
+            feeDto.setReceivedAmountSwitch("1");//榛樿鍚敤瀹炴敹娆捐緭鍏ユ
+        } else {
             feeDto.setReceivedAmountSwitch(received_amount_switch);
         }
-         return ResultVo.createResponseEntity(feeDto);
+        //鍏堝彇鍗曞皬鍖虹殑濡傛灉娌℃湁閰嶇疆 鍙� 鍏ㄥ眬鐨�
+        String offlinePayFeeSwitch = CommunitySettingFactory.getValue(feeDto.getCommunityId(), OFFLINE_PAY_FEE_SWITCH);
+        if (StringUtil.isEmpty(offlinePayFeeSwitch)) {
+            offlinePayFeeSwitch = MappingCache.getValue(DOMAIN_COMMON, OFFLINE_PAY_FEE_SWITCH);
+        }
+        feeDto.setOfflinePayFeeSwitch(offlinePayFeeSwitch);
+        return ResultVo.createResponseEntity(feeDto);
+    }
+
+    @Override
+    public ResponseEntity<String> querys(FeeDto feeDto) {
+        RoomDto roomDto = new RoomDto();
+        roomDto.setCommunityId(feeDto.getCommunityId());
+        roomDto.setRoomId(feeDto.getPayerObjId());
+        List<RoomDto> roomDtos = roomInnerServiceSMOImpl.queryRooms(roomDto);
+
+        if (roomDtos == null || roomDtos.size() < 1) {
+            return ResultVo.createResponseEntity(ResultVo.CODE_OK, "鎴愬姛", new JSONArray());
+        }
+        //鏌ヨ璐圭敤淇℃伅arrearsEndTime
+        List<RoomDto> tmpRoomDtos = new ArrayList<>();
+        List<RoomDto> tempRooms = new ArrayList<>();
+        int threadNum = Java110ThreadPoolFactory.JAVA110_DEFAULT_THREAD_NUM;
+
+        tempRooms.addAll(doGetTmpRoomDto(roomDtos, feeDto, threadNum));
+        for (RoomDto tmpRoomDto : tempRooms) {
+            if (tmpRoomDto == null) {
+                continue;
+            }
+            tmpRoomDtos.add(tmpRoomDto);
+        }
+
+        return ResultVo.createResponseEntity(tmpRoomDtos);
+    }
+
+    private List<RoomDto> doGetTmpRoomDto(List<RoomDto> roomDtos, FeeDto feeDto, int threadNum) {
+        Java110ThreadPoolFactory java110ThreadPoolFactory = null;
+        try {
+            java110ThreadPoolFactory = Java110ThreadPoolFactory.getInstance().createThreadPool(threadNum);
+            for (RoomDto roomDto1 : roomDtos) {
+                java110ThreadPoolFactory.submit(() -> {
+                    return getTmpRoomDtos(roomDto1, feeDto);
+                });
+            }
+            return java110ThreadPoolFactory.get();
+        } finally {
+            if (java110ThreadPoolFactory != null) {
+                java110ThreadPoolFactory.stop();
+            }
+        }
+    }
+
+    private RoomDto getTmpRoomDtos(RoomDto tmpRoomDto, FeeDto feeDto) {
+        FeeDto tmpFeeDto = null;
+        tmpFeeDto = new FeeDto();
+        tmpFeeDto.setArrearsEndTime(DateUtil.getCurrentDate());
+        tmpFeeDto.setState(FeeDto.STATE_DOING);
+        tmpFeeDto.setPayerObjId(tmpRoomDto.getRoomId());
+        tmpFeeDto.setPayerObjType(FeeDto.PAYER_OBJ_TYPE_ROOM);
+        List<FeeDto> feeDtos = feeInnerServiceSMOImpl.querySimpleFees(tmpFeeDto);
+
+        if (feeDtos == null || feeDtos.size() < 1) {
+            return null;
+        }
+
+        List<FeeDto> tmpFeeDtos = new ArrayList<>();
+        for (FeeDto tempFeeDto : feeDtos) {
+
+            computeFeeSMOImpl.computeEveryOweFee(tempFeeDto, tmpRoomDto);//璁$畻娆犺垂閲戦
+            //濡傛灉閲戦涓�0 灏辨帓闄�
+            //if (tempFeeDto.getFeePrice() > 0 && tempFeeDto.getEndTime().getTime() <= DateUtil.getCurrentDate().getTime()) {
+            if (tempFeeDto.getFeePrice() > 0) {
+                tmpFeeDtos.add(tempFeeDto);
+            }
+        }
+
+        if (tmpFeeDtos.size() < 1) {
+            return null;
+        }
+        tmpRoomDto.setFees(tmpFeeDtos);
+        return tmpRoomDto;
     }
 
     private boolean freshFeeDtoParam(FeeDto feeDto) {
@@ -328,6 +459,12 @@
 
             BigDecimal additionalAmount = new BigDecimal(Double.parseDouble(feeDto.getAdditionalAmount()));
             feePrice = additionalAmount.setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue();
+        } else if ("3003".equals(computingFormula)) { // 鍥哄畾璐圭敤
+            feePrice = 0.0;
+        } else if ("1101".equals(computingFormula)) { // 绉熼噾
+            feePrice = 0.0;
+        }else if ("1102".equals(computingFormula)) { // 绉熼噾
+            feePrice = 0.0;
         } else if ("4004".equals(computingFormula)) {
             feePrice = Double.parseDouble(feeDto.getAmount());
         } else if ("5005".equals(computingFormula)) {
@@ -337,6 +474,19 @@
                 BigDecimal curDegree = new BigDecimal(Double.parseDouble(feeDto.getCurDegrees()));
                 BigDecimal preDegree = new BigDecimal(Double.parseDouble(feeDto.getPreDegrees()));
                 BigDecimal squarePrice = new BigDecimal(Double.parseDouble(feeDto.getSquarePrice()));
+                BigDecimal additionalAmount = new BigDecimal(Double.parseDouble(feeDto.getAdditionalAmount()));
+                BigDecimal sub = curDegree.subtract(preDegree);
+                feePrice = sub.multiply(squarePrice)
+                        .add(additionalAmount)
+                        .setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue();
+            }
+        } else if ("9009".equals(computingFormula)) {  //(鏈湡搴︽暟-涓婃湡搴︽暟)*鍔ㄦ�佸崟浠�+闄勫姞璐�
+            if (StringUtil.isEmpty(feeDto.getCurDegrees())) {
+                feePrice = -1.00;
+            } else {
+                BigDecimal curDegree = new BigDecimal(Double.parseDouble(feeDto.getCurDegrees()));
+                BigDecimal preDegree = new BigDecimal(Double.parseDouble(feeDto.getPreDegrees()));
+                BigDecimal squarePrice = new BigDecimal(Double.parseDouble(feeDto.getMwPrice()));
                 BigDecimal additionalAmount = new BigDecimal(Double.parseDouble(feeDto.getAdditionalAmount()));
                 BigDecimal sub = curDegree.subtract(preDegree);
                 feePrice = sub.multiply(squarePrice)
@@ -354,7 +504,9 @@
         feeDto.setAmountOwed(price.setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue() + "");
         feeDto.setDeadlineTime(targetEndDate);
         //鍔ㄦ�佽垂鐢�
-        if ("4004".equals(computingFormula)) {
+        if ("4004".equals(computingFormula)
+                && FeeDto.FEE_FLAG_ONCE.equals(feeDto.getFeeFlag())
+        ) {
             feeDto.setAmountOwed(feeDto.getFeePrice() + "");
             feeDto.setDeadlineTime(DateUtil.getCurrentDate());
         }
@@ -424,7 +576,18 @@
         } else if ("2002".equals(computingFormula)) { // 鍥哄畾璐圭敤
             BigDecimal additionalAmount = new BigDecimal(Double.parseDouble(feeDto.getAdditionalAmount()));
             feePrice = additionalAmount.setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue();
-        } else if ("4004".equals(computingFormula)) {
+        } else if ("3003".equals(computingFormula)) { // 鍥哄畾璐圭敤
+            BigDecimal squarePrice = new BigDecimal(Double.parseDouble(feeDto.getSquarePrice()));
+            BigDecimal builtUpArea = new BigDecimal(Double.parseDouble(tmpRoomDto.getRoomArea()));
+            BigDecimal additionalAmount = new BigDecimal(Double.parseDouble(feeDto.getAdditionalAmount()));
+            feePrice = squarePrice.multiply(builtUpArea).add(additionalAmount).setScale(3, BigDecimal.ROUND_HALF_EVEN).doubleValue();
+        } else if ("1101".equals(computingFormula)) { // 绉熼噾
+            BigDecimal additionalAmount = new BigDecimal(Double.parseDouble(tmpRoomDto.getRoomRent()));
+            feePrice = additionalAmount.setScale(3, BigDecimal.ROUND_HALF_EVEN).doubleValue();
+        } else if ("1102".equals(computingFormula)) { // 绉熼噾
+            BigDecimal additionalAmount = new BigDecimal(Double.parseDouble(tmpRoomDto.getRoomRent()));
+            feePrice = additionalAmount.setScale(3, BigDecimal.ROUND_HALF_EVEN).doubleValue();
+        }else if ("4004".equals(computingFormula)) {
             feePrice = Double.parseDouble(feeDto.getAmount());
         } else if ("5005".equals(computingFormula)) {
 
@@ -434,6 +597,20 @@
                 BigDecimal curDegree = new BigDecimal(Double.parseDouble(feeDto.getCurDegrees()));
                 BigDecimal preDegree = new BigDecimal(Double.parseDouble(feeDto.getPreDegrees()));
                 BigDecimal squarePrice = new BigDecimal(Double.parseDouble(feeDto.getSquarePrice()));
+                BigDecimal additionalAmount = new BigDecimal(Double.parseDouble(feeDto.getAdditionalAmount()));
+                BigDecimal sub = curDegree.subtract(preDegree);
+                feePrice = sub.multiply(squarePrice)
+                        .add(additionalAmount)
+                        .setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue();
+            }
+        } else if ("9009".equals(computingFormula)) {
+
+            if (StringUtil.isEmpty(feeDto.getCurDegrees())) {
+                feePrice = -1.00;
+            } else {
+                BigDecimal curDegree = new BigDecimal(Double.parseDouble(feeDto.getCurDegrees()));
+                BigDecimal preDegree = new BigDecimal(Double.parseDouble(feeDto.getPreDegrees()));
+                BigDecimal squarePrice = new BigDecimal(Double.parseDouble(feeDto.getMwPrice()));
                 BigDecimal additionalAmount = new BigDecimal(Double.parseDouble(feeDto.getAdditionalAmount()));
                 BigDecimal sub = curDegree.subtract(preDegree);
                 feePrice = sub.multiply(squarePrice)
@@ -500,7 +677,9 @@
             return targetEndDateAndOweMonth;
         }
         if (FeeDto.FEE_FLAG_ONCE.equals(feeDto.getFeeFlag())) {
-            if (!StringUtil.isEmpty(feeDto.getCurDegrees())) {
+            if (feeDto.getDeadlineTime() != null) {
+                targetEndDate = feeDto.getDeadlineTime();
+            } else if (!StringUtil.isEmpty(feeDto.getCurDegrees())) {
                 targetEndDate = feeDto.getCurReadingTime();
             } else if (feeDto.getImportFeeEndTime() == null) {
                 targetEndDate = feeDto.getConfigEndTime();

--
Gitblit v1.8.0