From 1ac555ce49a45e2c7fc015dbb16b104840788c21 Mon Sep 17 00:00:00 2001
From: chengf <2156125618@qq.com>
Date: 星期一, 18 八月 2025 11:51:42 +0800
Subject: [PATCH] 费用导入修复2025/08/15

---
 service-fee/src/main/java/com/java110/fee/bmo/impl/QueryOweFeeImpl.java |  618 +++++++++++++++++++++++++++++++++++++++++++++----------
 1 files changed, 498 insertions(+), 120 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 2951db4..777191f
--- 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,33 +1,52 @@
 package com.java110.fee.bmo.impl;
 
-import com.java110.dto.RoomDto;
-import com.java110.dto.fee.BillDto;
-import com.java110.dto.fee.BillOweFeeDto;
+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.room.RoomDto;
 import com.java110.dto.fee.FeeConfigDto;
 import com.java110.dto.fee.FeeDto;
+import com.java110.dto.owner.OwnerCarDto;
+import com.java110.dto.owner.OwnerDto;
 import com.java110.dto.parking.ParkingSpaceDto;
 import com.java110.fee.bmo.IQueryOweFee;
 import com.java110.intf.community.IParkingSpaceInnerServiceSMO;
 import com.java110.intf.community.IRoomInnerServiceSMO;
 import com.java110.intf.fee.IFeeConfigInnerServiceSMO;
 import com.java110.intf.fee.IFeeInnerServiceSMO;
+import com.java110.intf.user.IOwnerCarInnerServiceSMO;
 import com.java110.intf.user.IOwnerInnerServiceSMO;
-import com.java110.utils.util.DateUtil;
+import com.java110.utils.cache.MappingCache;
+import com.java110.utils.constant.ResponseConstant;
+import com.java110.utils.exception.ListenerExecuteException;
+import com.java110.utils.util.*;
 import com.java110.vo.ResultVo;
+import com.java110.vo.api.fee.ApiFeeDataVo;
+import com.java110.vo.api.fee.ApiFeeVo;
+import com.java110.vo.api.feeConfig.ApiFeeConfigDataVo;
+import org.slf4j.Logger;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.http.ResponseEntity;
 import org.springframework.stereotype.Service;
 
 import java.math.BigDecimal;
-import java.util.ArrayList;
-import java.util.List;
+import java.math.RoundingMode;
+import java.util.*;
 
 @Service
 public class QueryOweFeeImpl implements IQueryOweFee {
 
 
+    private final static Logger logger = LoggerFactory.getLogger(QueryOweFeeImpl.class);
+
+
     @Autowired
     private IFeeInnerServiceSMO feeInnerServiceSMOImpl;
+
+    @Autowired
+    private IOwnerCarInnerServiceSMO ownerCarInnerServiceSMOImpl;
 
     @Autowired
     private IFeeConfigInnerServiceSMO feeConfigInnerServiceSMOImpl;
@@ -41,26 +60,70 @@
     @Autowired
     private IOwnerInnerServiceSMO ownerInnerServiceSMOImpl;
 
+    @Autowired
+    private IComputeFeeSMO computeFeeSMOImpl;
+
+    //鍩�
+    public static final String DOMAIN_COMMON = "DOMAIN.COMMON";
+
+    //閿�
+    public static final String TOTAL_FEE_PRICE = "TOTAL_FEE_PRICE";
+
+    //閿�
+    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) {
 
         //鏌ヨ璐圭敤淇℃伅arrearsEndTime
-        feeDto.setArrearsEndTime(DateUtil.getCurrentDate());
+        // todo 杩欓噷鑰冭檻棰勪粯鏈熺殑璐圭敤 鎵�浠ユ煡璇㈠叏閲忓啀鐢ㄨ垂鐢�
         feeDto.setState(FeeDto.STATE_DOING);
         List<FeeDto> feeDtos = feeInnerServiceSMOImpl.queryFees(feeDto);
 
-        if (feeDtos == null || feeDtos.size() < 1) {
+        if (ListUtil.isNull(feeDtos)) {
             feeDtos = new ArrayList<>();
             return ResultVo.createResponseEntity(feeDtos);
         }
+        String val = CommunitySettingFactory.getValue(feeDtos.get(0).getCommunityId(), TOTAL_FEE_PRICE);
+        if (StringUtil.isEmpty(val)) {
+            val = MappingCache.getValue(DOMAIN_COMMON, TOTAL_FEE_PRICE);
+        }
         List<FeeDto> tmpFeeDtos = new ArrayList<>();
         for (FeeDto tmpFeeDto : feeDtos) {
-            computeOweFee(tmpFeeDto);//璁$畻娆犺垂閲戦
+            try {
+                if (!StringUtil.isEmpty(tmpFeeDto.getAdditionalAmount())) {
+                    tmpFeeDto.setAdditionalAmount(Double.parseDouble(tmpFeeDto.getAdditionalAmount()) + "");
+                }
+                if (!StringUtil.isEmpty(tmpFeeDto.getSquarePrice())) {
+                    tmpFeeDto.setSquarePrice(Double.parseDouble(tmpFeeDto.getSquarePrice()) + "");
+                }
 
-            //濡傛灉閲戦涓�0 灏辨帓闄�
-            if (tmpFeeDto.getFeePrice() > 0) {
-                tmpFeeDtos.add(tmpFeeDto);
+                //todo 鏈夌洰鏍囩粨鏉熸椂闂�,骞朵笖涓嶆槸涓�娆℃�ц垂鐢�
+                if (!StringUtil.isEmpty(feeDto.getTargetEndTime())
+                        && !FeeDto.FEE_FLAG_ONCE.equals(tmpFeeDto.getFeeFlag())
+                ) {
+                    computeFeeSMOImpl.computeEveryOweFeeByTargetEndTime(tmpFeeDto, feeDto.getTargetEndTime());//璁$畻娆犺垂閲戦
+                } else {
+                    computeFeeSMOImpl.computeEveryOweFee(tmpFeeDto);//璁$畻娆犺垂閲戦
+                }
+                //濡傛灉閲戦涓�0 灏辨帓闄�
+                tmpFeeDto.setFeeTotalPrice(
+                        MoneyUtil.computePriceScale(
+                                tmpFeeDto.getFeeTotalPrice(),
+                                tmpFeeDto.getScale(),
+                                Integer.parseInt(tmpFeeDto.getDecimalPlace())
+                        )
+                );
+
+                tmpFeeDto.setVal(val);
+                if (tmpFeeDto.getFeeTotalPrice() != 0) {
+                    tmpFeeDtos.add(tmpFeeDto);
+                }
+            } catch (Exception e) {
+                logger.error("鍙兘璐圭敤璧勬枡鏈夐棶棰樺鑷寸畻璐瑰け璐�", e);
             }
         }
 
@@ -71,12 +134,258 @@
     @Override
     public ResponseEntity<String> queryAllOwneFee(FeeDto feeDto) {
         ResponseEntity<String> responseEntity = null;
+
+        if (!freshFeeDtoParam(feeDto)) {
+            return ResultVo.createResponseEntity(1, 0, new JSONArray());
+        }
+
         if (FeeConfigDto.BILL_TYPE_EVERY.equals(feeDto.getBillType())) {
             responseEntity = computeEveryOweFee(feeDto);
         } else {
             responseEntity = computeBillOweFee(feeDto);
         }
         return responseEntity;
+    }
+
+    @Override
+    public ResponseEntity<String> listFeeObj(FeeDto feeDto) {
+
+        List<FeeDto> feeDtos = feeInnerServiceSMOImpl.queryFees(feeDto);
+
+        if (ListUtil.isNull(feeDtos)) {
+            return ResultVo.success();
+        }
+        String cycel = null;
+        String custEndTime = null;
+        String customStartTime = "";
+        String customEndTime = "";
+        if (!StringUtil.isEmpty(feeDto.getCycle())) {
+            cycel = feeDto.getCycle();
+        }
+        if (!StringUtil.isEmpty(feeDto.getCustEndTime())) {
+            custEndTime = feeDto.getCustEndTime();
+        }
+        customStartTime = feeDto.getCustomStartTime();
+        customEndTime = feeDto.getCustomEndTime();
+        feeDto = feeDtos.get(0);
+        //todo 鑰冭檻璐﹀崟妯″紡
+        if (FeeDto.FEE_FLAG_ONCE.equals(feeDto.getFeeFlag()) && StringUtil.isNumber(feeDto.getMonthCycle())) {
+            cycel = feeDto.getMonthCycle();
+        }
+        if (!StringUtil.isEmpty(cycel)) {
+            feeDto.setCycle(cycel);
+        }
+        if (!StringUtil.isEmpty(custEndTime)) {
+            feeDto.setCustEndTime(custEndTime);
+        }
+
+        feeDto.setCustomStartTime(customStartTime);
+        feeDto.setCustomEndTime(customEndTime);
+
+        if (FeeDto.PAYER_OBJ_TYPE_ROOM.equals(feeDto.getPayerObjType())) { //鎴垮眿鐩稿叧
+            RoomDto roomDto = new RoomDto();
+            roomDto.setRoomId(feeDto.getPayerObjId());
+            roomDto.setCommunityId(feeDto.getCommunityId());
+            List<RoomDto> roomDtos = roomInnerServiceSMOImpl.queryRooms(roomDto);
+            if (roomDtos == null || roomDtos.size() != 1) {
+                throw new ListenerExecuteException(ResponseConstant.RESULT_CODE_ERROR, "鏈煡鍒版埧灞嬩俊鎭紝鏌ヨ澶氭潯鏁版嵁");
+            }
+            roomDto = roomDtos.get(0);
+            feeDto.setPayerObjName(roomDto.getFloorNum() + "-" + roomDto.getUnitNum() + "-" + roomDto.getRoomNum());
+            feeDto.setBuiltUpArea(roomDto.getBuiltUpArea());
+
+        } 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);
+            Assert.listOnlyOne(ownerCarDtos, "鏈壘鍒拌溅杈嗕俊鎭�");
+            ParkingSpaceDto parkingSpaceDto = new ParkingSpaceDto();
+            parkingSpaceDto.setCommunityId(feeDto.getCommunityId());
+            parkingSpaceDto.setPsId(ownerCarDtos.get(0).getPsId());
+            List<ParkingSpaceDto> parkingSpaceDtos = parkingSpaceInnerServiceSMOImpl.queryParkingSpaces(parkingSpaceDto);
+            if (ListUtil.isNull(parkingSpaceDtos)) { //鏁版嵁鏈夐棶棰�
+                throw new ListenerExecuteException(ResponseConstant.RESULT_CODE_ERROR, "鏈煡鍒板仠杞︿綅淇℃伅锛屾煡璇㈠鏉℃暟鎹�");
+            }
+            ownerCarDto = ownerCarDtos.get(0);
+            parkingSpaceDto = parkingSpaceDtos.get(0);
+            feeDto.setPayerObjName(ownerCarDto.getCarNum() + "(" + parkingSpaceDto.getAreaNum() + "鍋滆溅鍦�" + parkingSpaceDto.getNum() + "杞︿綅)");
+            feeDto.setBuiltUpArea(parkingSpaceDto.getArea());
+        }
+
+        Map feePriceAll = computeFeeSMOImpl.getFeePrice(feeDto);
+        feeDto.setFeePrice(Double.parseDouble(feePriceAll.get("feePrice").toString()));
+
+        feeDto.setFeeTotalPrice(
+                MoneyUtil.computePriceScale(
+                        Double.parseDouble(feePriceAll.get("feeTotalPrice").toString()),
+                        feeDto.getScale(),
+                        Integer.parseInt(feeDto.getDecimalPlace())
+                )
+        );
+
+        if (!StringUtil.isEmpty(custEndTime)) {
+            Date date = DateUtil.getDateFromStringB(custEndTime);
+            computeFeeSMOImpl.dealRentRateCustEndTime(feeDto, date);
+        } 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);
+        }
+        //鍏堝彇鍗曞皬鍖虹殑濡傛灉娌℃湁閰嶇疆 鍙� 鍏ㄥ眬鐨�
+        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);
+        //鍘绘帀澶氫綑0
+        feeDto.setSquarePrice(Double.parseDouble(feeDto.getSquarePrice()) + "");
+        feeDto.setAdditionalAmount(Double.parseDouble(feeDto.getAdditionalAmount()) + "");
+        ApiFeeDataVo apiFeeDataVo = BeanConvertUtil.covertBeanList(feeDtos, ApiFeeDataVo.class).get(0);
+        apiFeeDataVo.setStartTime(apiFeeDataVo.getStartTime() == null ? null : apiFeeDataVo.getStartTime().split(" ")[0]);
+        apiFeeDataVo.setEndTime(apiFeeDataVo.getEndTime() == null ? null : apiFeeDataVo.getEndTime().split(" ")[0]);
+        apiFeeDataVo.setMaxEndTime(apiFeeDataVo.getMaxEndTime() == null ? null : apiFeeDataVo.getMaxEndTime().split(" ")[0]);
+        apiFeeDataVo.setDeadlineTime(apiFeeDataVo.getDeadlineTime() == null ? null : apiFeeDataVo.getDeadlineTime().split(" ")[0]);
+        return ResultVo.createResponseEntity(apiFeeDataVo);
+    }
+
+    @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) {
+
+        if (StringUtil.isEmpty(feeDto.getPayerObjId())) {
+            return true;
+        }
+
+        if (!feeDto.getPayerObjId().contains("-")) {
+            return false;
+        }
+        if (FeeDto.PAYER_OBJ_TYPE_ROOM.equals(feeDto.getPayerObjType())) {
+            String[] nums = feeDto.getPayerObjId().split("-");
+            if (nums.length != 3) {
+                return false;
+            }
+            RoomDto roomDto = new RoomDto();
+            roomDto.setFloorNum(nums[0]);
+            roomDto.setUnitNum(nums[1]);
+            roomDto.setRoomNum(nums[2]);
+            roomDto.setCommunityId(feeDto.getCommunityId());
+            List<RoomDto> roomDtos = roomInnerServiceSMOImpl.queryRooms(roomDto);
+
+            if (roomDtos == null || roomDtos.size() < 1) {
+                return false;
+            }
+            feeDto.setPayerObjId(roomDtos.get(0).getRoomId());
+
+        } else {
+            String[] nums = feeDto.getPayerObjId().split("-");
+            if (nums.length != 2) {
+                return false;
+            }
+            ParkingSpaceDto parkingSpaceDto = new ParkingSpaceDto();
+            parkingSpaceDto.setAreaNum(nums[0]);
+            parkingSpaceDto.setNum(nums[1]);
+            parkingSpaceDto.setCommunityId(feeDto.getCommunityId());
+            List<ParkingSpaceDto> parkingSpaceDtos = parkingSpaceInnerServiceSMOImpl.queryParkingSpaces(parkingSpaceDto);
+
+            if (parkingSpaceDtos == null || parkingSpaceDtos.size() < 1) {
+                return false;
+            }
+            feeDto.setPayerObjId(parkingSpaceDtos.get(0).getPsId());
+        }
+
+        return true;
     }
 
     /**
@@ -124,6 +433,7 @@
         List<String> psIds = new ArrayList<>();
 
         for (FeeDto fee : feeDtos) {
+            // 杞暟 * 鍛ㄦ湡 * 30 + 寮�濮嬫椂闂� = 鐩爣 鍒版湡鏃堕棿
             if ("3333".equals(fee.getPayerObjType())) { //鎴垮眿鐩稿叧
                 roomFees.add(fee);
                 roomIds.add(fee.getPayerObjId());
@@ -137,7 +447,7 @@
             computeRoomFee(roomFees, roomIds);
         }
 
-        if (roomFees.size() > 0) {
+        if (psFees.size() > 0) {
             computePsFee(psFees, psIds);
         }
     }
@@ -148,6 +458,104 @@
      * @param psFees
      */
     private void computePsFee(List<FeeDto> psFees, List<String> psIds) {
+        ParkingSpaceDto parkingSpaceDto = new ParkingSpaceDto();
+        parkingSpaceDto.setCommunityId(psFees.get(0).getCommunityId());
+        parkingSpaceDto.setPsIds(psIds.toArray(new String[psIds.size()]));
+        List<ParkingSpaceDto> parkingSpaceDtos = parkingSpaceInnerServiceSMOImpl.queryParkingSpaces(parkingSpaceDto);
+
+        if (parkingSpaceDtos == null || parkingSpaceDtos.size() < 1) { //鏁版嵁鏈夐棶棰�
+            return;
+        }
+        for (ParkingSpaceDto tmpParkingSpaceDto : parkingSpaceDtos) {
+            for (FeeDto feeDto : psFees) {
+                dealFeePs(tmpParkingSpaceDto, feeDto);
+            }
+        }
+
+        OwnerDto ownerDto = new OwnerDto();
+        ownerDto.setOwnerIds(psIds.toArray(new String[psIds.size()]));
+        ownerDto.setCommunityId(psFees.get(0).getCommunityId());
+        List<OwnerDto> ownerDtos = ownerInnerServiceSMOImpl.queryOwnersByParkingSpace(ownerDto);
+
+        for (OwnerDto tmpOwnerDto : ownerDtos) {
+            for (FeeDto feeDto : psFees) {
+                dealFeeOwner(tmpOwnerDto, feeDto);
+            }
+        }
+    }
+
+    private void dealFeePs(ParkingSpaceDto tmpParkingSpaceDto, FeeDto feeDto) {
+        // 杞暟 * 鍛ㄦ湡 * 30 + 寮�濮嬫椂闂� = 鐩爣 鍒版湡鏃堕棿
+        Map<String, Object> targetEndDateAndOweMonth = computeFeeSMOImpl.getTargetEndDateAndOweMonth(feeDto);
+        Date targetEndDate = (Date) targetEndDateAndOweMonth.get("targetEndDate");
+        double oweMonth = (double) targetEndDateAndOweMonth.get("oweMonth");
+        if (!tmpParkingSpaceDto.getPsId().equals(feeDto.getPayerObjId())) {
+            return;
+        }
+        feeDto.setRoomName(tmpParkingSpaceDto.getAreaNum() + "鍋滆溅鍦�" + tmpParkingSpaceDto.getNum() + "杞︿綅");
+
+        String computingFormula = feeDto.getComputingFormula();
+        double feePrice = 0.00;
+        if ("1001".equals(computingFormula)) { //闈㈢Н*鍗曚环+闄勫姞璐�
+            BigDecimal squarePrice = new BigDecimal(Double.parseDouble(feeDto.getSquarePrice()));
+            BigDecimal builtUpArea = new BigDecimal(Double.parseDouble(tmpParkingSpaceDto.getArea()));
+            BigDecimal additionalAmount = new BigDecimal(Double.parseDouble(feeDto.getAdditionalAmount()));
+            feePrice = squarePrice.multiply(builtUpArea).add(additionalAmount).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue();
+        } else if ("2002".equals(computingFormula)) { // 鍥哄畾璐圭敤
+
+            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)) {
+            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.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)
+                        .add(additionalAmount)
+                        .setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue();
+            }
+        } else {
+            feePrice = 0.00;
+        }
+
+        feeDto.setFeePrice(feePrice);
+        // double month = dayCompare(feeDto.getEndTime(), DateUtil.getCurrentDate());
+        BigDecimal price = new BigDecimal(feeDto.getFeePrice());
+        price = price.multiply(new BigDecimal(oweMonth));
+        feeDto.setAmountOwed(price.setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue() + "");
+        feeDto.setDeadlineTime(targetEndDate);
+        //鍔ㄦ�佽垂鐢�
+        if ("4004".equals(computingFormula)
+                && FeeDto.FEE_FLAG_ONCE.equals(feeDto.getFeeFlag())
+        ) {
+            feeDto.setAmountOwed(feeDto.getFeePrice() + "");
+            feeDto.setDeadlineTime(DateUtil.getCurrentDate());
+        }
     }
 
     /**
@@ -165,17 +573,40 @@
             return;
         }
 
+
         for (RoomDto tmpRoomDto : roomDtos) {
             for (FeeDto feeDto : roomFees) {
                 dealFeeRoom(tmpRoomDto, feeDto);
             }
         }
 
+        OwnerDto ownerDto = new OwnerDto();
+        ownerDto.setRoomIds(roomIds.toArray(new String[roomIds.size()]));
+        ownerDto.setCommunityId(roomFees.get(0).getCommunityId());
+        List<OwnerDto> ownerDtos = ownerInnerServiceSMOImpl.queryOwners(ownerDto);
+
+        for (OwnerDto tmpOwnerDto : ownerDtos) {
+            for (FeeDto feeDto : roomFees) {
+                dealFeeOwner(tmpOwnerDto, feeDto);
+            }
+        }
 
     }
 
-    private void dealFeeRoom(RoomDto tmpRoomDto, FeeDto feeDto) {
+    private void dealFeeOwner(OwnerDto tmpOwnerDto, FeeDto feeDto) {
 
+        if (!tmpOwnerDto.getRoomId().equals(feeDto.getPayerObjId())) {
+            return;
+        }
+
+        feeDto.setOwnerName(tmpOwnerDto.getName());
+        feeDto.setOwnerTel(tmpOwnerDto.getLink());
+    }
+
+    private void dealFeeRoom(RoomDto tmpRoomDto, FeeDto feeDto) {
+        Map<String, Object> targetEndDateAndOweMonth = computeFeeSMOImpl.getTargetEndDateAndOweMonth(feeDto);
+        Date targetEndDate = (Date) targetEndDateAndOweMonth.get("targetEndDate");
+        double oweMonth = (double) targetEndDateAndOweMonth.get("oweMonth");
         if (!tmpRoomDto.getRoomId().equals(feeDto.getPayerObjId())) {
             return;
         }
@@ -191,125 +622,72 @@
         } 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)) {
-            feePrice = Double.parseDouble(feeDto.getAmount());
-        } else {
-            feePrice = 0.00;
-        }
-        feeDto.setFeePrice(feePrice);
-
-    }
-
-    /**
-     * 璁$畻娆犺垂閲戦
-     *
-     * @param tmpFeeDto
-     */
-    private void computeOweFee(FeeDto tmpFeeDto) {
-        String billType = tmpFeeDto.getBillType();
-
-        if (FeeConfigDto.BILL_TYPE_EVERY.equals(billType)) {
-            computeFeePrice(tmpFeeDto);
-            return;
-        }
-        BillDto billDto = new BillDto();
-        billDto.setCommunityId(tmpFeeDto.getCommunityId());
-        billDto.setConfigId(tmpFeeDto.getConfigId());
-        billDto.setCurBill("T");
-        List<BillDto> billDtos = feeInnerServiceSMOImpl.queryBills(billDto);
-        if (billDtos == null || billDtos.size() < 1) {
-            tmpFeeDto.setFeePrice(0.00);
-            return;
-        }
-        BillOweFeeDto billOweFeeDto = new BillOweFeeDto();
-        billOweFeeDto.setCommunityId(tmpFeeDto.getCommunityId());
-        billOweFeeDto.setFeeId(tmpFeeDto.getFeeId());
-        billOweFeeDto.setState(BillOweFeeDto.STATE_WILL_FEE);
-        billOweFeeDto.setBillId(billDtos.get(0).getBillId());
-        List<BillOweFeeDto> billOweFeeDtos = feeInnerServiceSMOImpl.queryBillOweFees(billOweFeeDto);
-        if (billOweFeeDtos == null || billOweFeeDtos.size() < 1) {
-            tmpFeeDto.setFeePrice(0.00);
-            return;
-        }
-        tmpFeeDto.setFeePrice(Double.parseDouble(billOweFeeDtos.get(0).getAmountOwed()));
-    }
-
-
-    private void computeFeePrice(FeeDto feeDto) {
-
-        if ("3333".equals(feeDto.getPayerObjType())) { //鎴垮眿鐩稿叧
-            computeFeePriceByRoom(feeDto);
-        } else if ("6666".equals(feeDto.getPayerObjType())) {//杞︿綅鐩稿叧
-            computeFeePriceByParkingSpace(feeDto);
-        }
-    }
-
-    private void computeFeePriceByParkingSpace(FeeDto feeDto) {
-
-        ParkingSpaceDto parkingSpaceDto = new ParkingSpaceDto();
-        parkingSpaceDto.setCommunityId(feeDto.getCommunityId());
-        parkingSpaceDto.setPsId(feeDto.getPayerObjId());
-        List<ParkingSpaceDto> parkingSpaceDtos = parkingSpaceInnerServiceSMOImpl.queryParkingSpaces(parkingSpaceDto);
-
-        if (parkingSpaceDtos == null || parkingSpaceDtos.size() < 1) { //鏁版嵁鏈夐棶棰�
-            return;
-        }
-
-        String computingFormula = feeDto.getComputingFormula();
-        double feePrice = 0.00;
-        if ("1001".equals(computingFormula)) { //闈㈢Н*鍗曚环+闄勫姞璐�
+        } else if ("3003".equals(computingFormula)) { // 鍥哄畾璐圭敤
             BigDecimal squarePrice = new BigDecimal(Double.parseDouble(feeDto.getSquarePrice()));
-            BigDecimal builtUpArea = new BigDecimal(Double.parseDouble(parkingSpaceDtos.get(0).getArea()));
+            BigDecimal builtUpArea = new BigDecimal(Double.parseDouble(tmpRoomDto.getRoomArea()));
             BigDecimal additionalAmount = new BigDecimal(Double.parseDouble(feeDto.getAdditionalAmount()));
-            feePrice = squarePrice.multiply(builtUpArea).add(additionalAmount).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue();
-        } else if ("2002".equals(computingFormula)) { // 鍥哄畾璐圭敤
-
-            BigDecimal additionalAmount = new BigDecimal(Double.parseDouble(feeDto.getAdditionalAmount()));
-            feePrice = additionalAmount.setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue();
+            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)) {
+
+            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.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)
+                        .add(additionalAmount)
+                        .setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue();
+            }
         } else {
             feePrice = 0.00;
         }
-
         feeDto.setFeePrice(feePrice);
 
+        //double month = dayCompare(feeDto.getEndTime(), DateUtil.getCurrentDate());
+        BigDecimal price = new BigDecimal(feeDto.getFeePrice());
+        price = price.multiply(new BigDecimal(oweMonth));
+        feeDto.setAmountOwed(price.setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue() + "");
+        feeDto.setDeadlineTime(targetEndDate);
+
+        //鍔ㄦ�佽垂鐢�
+        if ("4004".equals(computingFormula)) {
+            feeDto.setAmountOwed(feeDto.getFeePrice() + "");
+            feeDto.setDeadlineTime(DateUtil.getCurrentDate());
+        }
 
     }
 
-    /**
-     * 鏍规嵁鎴垮眿鏉ョ畻鍗曚环
-     *
-     * @param feeDto
-     */
-    private void computeFeePriceByRoom(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;
-        }
-
-        String computingFormula = feeDto.getComputingFormula();
-        double feePrice = 0.00;
-        if ("1001".equals(computingFormula)) { //闈㈢Н*鍗曚环+闄勫姞璐�
-            BigDecimal squarePrice = new BigDecimal(Double.parseDouble(feeDto.getSquarePrice()));
-            BigDecimal builtUpArea = new BigDecimal(Double.parseDouble(roomDtos.get(0).getBuiltUpArea()));
-            BigDecimal additionalAmount = new BigDecimal(Double.parseDouble(feeDto.getAdditionalAmount()));
-            feePrice = squarePrice.multiply(builtUpArea).add(additionalAmount).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue();
-        } 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)) {
-            feePrice = Double.parseDouble(feeDto.getAmount());
-        } else {
-            feePrice = 0.00;
-        }
-
-
-        feeDto.setFeePrice(feePrice);
+    private Date getTargetEndTime(double v, Date startDate) {
+        Calendar endDate = Calendar.getInstance();
+        endDate.setTime(startDate);
+        endDate.add(Calendar.MONTH, (int) v);
+        return endDate.getTime();
     }
 
 }

--
Gitblit v1.8.0