wuxw
2024-01-16 a78d25ab3461bece8a9c3dd387ebf6a9ce829a40
java110-core/src/main/java/com/java110/core/smo/impl/ComputeFeeSMOImpl.java
@@ -5,13 +5,13 @@
import com.java110.core.context.Environment;
import com.java110.core.log.LoggerFactory;
import com.java110.core.smo.IComputeFeeSMO;
import com.java110.dto.RoomAttrDto;
import com.java110.dto.RoomDto;
import com.java110.dto.room.RoomAttrDto;
import com.java110.dto.room.RoomDto;
import com.java110.dto.community.CommunityDto;
import com.java110.dto.contract.ContractDto;
import com.java110.dto.contractRoom.ContractRoomDto;
import com.java110.dto.contract.ContractRoomDto;
import com.java110.dto.fee.*;
import com.java110.dto.integralRuleConfig.IntegralRuleConfigDto;
import com.java110.dto.integral.IntegralRuleConfigDto;
import com.java110.dto.machine.CarInoutDetailDto;
import com.java110.dto.machine.CarInoutDto;
import com.java110.dto.owner.OwnerCarDto;
@@ -31,14 +31,11 @@
import com.java110.intf.store.IContractRoomInnerServiceSMO;
import com.java110.intf.user.IOwnerCarInnerServiceSMO;
import com.java110.intf.user.IOwnerInnerServiceSMO;
import com.java110.po.feeReceiptDetail.FeeReceiptDetailPo;
import com.java110.po.fee.FeeReceiptDetailPo;
import com.java110.utils.constant.FeeConfigConstant;
import com.java110.utils.constant.ResponseConstant;
import com.java110.utils.exception.ListenerExecuteException;
import com.java110.utils.util.Assert;
import com.java110.utils.util.BeanConvertUtil;
import com.java110.utils.util.DateUtil;
import com.java110.utils.util.StringUtil;
import com.java110.utils.util.*;
import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@@ -161,54 +158,6 @@
    }
    private void computeFeePrice(FeeDto feeDto, RoomDto roomDto) {
        if (FeeDto.PAYER_OBJ_TYPE_ROOM.equals(feeDto.getPayerObjType())) { //房屋相关
            computeFeePriceByRoom(feeDto, roomDto);
        } else if (FeeDto.PAYER_OBJ_TYPE_CAR.equals(feeDto.getPayerObjType())) {//车位相关
            computeFeePriceByParkingSpace(feeDto);
        } else if (FeeDto.PAYER_OBJ_TYPE_CONTRACT.equals(feeDto.getPayerObjType())) { //房屋相关
            computeFeePriceByContract(feeDto, roomDto);
        }
    }
    private void computeFeePriceByParkingSpace(FeeDto feeDto) {
        Map<String, Object> targetEndDateAndOweMonth = getTargetEndDateAndOweMonth(feeDto);
        Date targetEndDate = (Date) targetEndDateAndOweMonth.get("targetEndDate");
        double oweMonth = (double) targetEndDateAndOweMonth.get("oweMonth");
        OwnerCarDto ownerCarDto = new OwnerCarDto();
        ownerCarDto.setCommunityId(feeDto.getCommunityId());
        ownerCarDto.setCarId(feeDto.getPayerObjId());
        List<OwnerCarDto> ownerCarDtos = ownerCarInnerServiceSMOImpl.queryOwnerCars(ownerCarDto);
        if (ownerCarDtos == null || ownerCarDtos.size() < 1) { //数据有问题
            return;
        }
        String computingFormula = feeDto.getComputingFormula();
        Map feePriceAll = getFeePrice(feeDto);
        feeDto.setFeePrice(Double.parseDouble(feePriceAll.get("feePrice").toString()));
        BigDecimal price = new BigDecimal(feeDto.getFeePrice());
        price = price.multiply(new BigDecimal(oweMonth));
        feeDto.setFeePrice(price.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
        feeDto.setDeadlineTime(targetEndDate);
        //动态费用
        if ("4004".equals(computingFormula)
                && FeeDto.FEE_FLAG_ONCE.equals(feeDto.getFeeFlag())
                && !FeeDto.STATE_FINISH.equals(feeDto.getState())) {
            feeDto.setAmountOwed(feeDto.getFeePrice() + "");
            //feeDto.setDeadlineTime(DateUtil.getCurrentDate()); 欠费日期不对先注释
        }
    }
    /**
     * 根据房屋来算单价
     *
     * @param feeDto
     */
    private void computeFeePriceByRoom(FeeDto feeDto, RoomDto roomDto) {
        Map<String, Object> targetEndDateAndOweMonth = getTargetEndDateAndOweMonth(feeDto);
        Date targetEndDate = (Date) targetEndDateAndOweMonth.get("targetEndDate");
        double oweMonth = (double) targetEndDateAndOweMonth.get("oweMonth");
@@ -216,47 +165,22 @@
        String computingFormula = feeDto.getComputingFormula();
        Map feePriceAll = getFeePrice(feeDto, roomDto);
        feeDto.setFeePrice(Double.parseDouble(feePriceAll.get("feePrice").toString()));
        //double month = dayCompare(feeDto.getEndTime(), DateUtil.getCurrentDate());
        BigDecimal price = new BigDecimal(feeDto.getFeePrice());
        price = price.multiply(new BigDecimal(oweMonth));
        feeDto.setFeePrice(price.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
        feeDto.setFeeTotalPrice(price.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
        feeDto.setDeadlineTime(targetEndDate);
        //动态费用
        if ("4004".equals(computingFormula)
                && FeeDto.FEE_FLAG_ONCE.equals(feeDto.getFeeFlag())
                && !FeeDto.STATE_FINISH.equals(feeDto.getState())) {
            feeDto.setAmountOwed(feeDto.getFeePrice() + "");
            feeDto.setAmountOwed(feeDto.getFeeTotalPrice() + "");
            //feeDto.setDeadlineTime(DateUtil.getCurrentDate()); 欠费日期不对先注释
        }
    }
    /**
     * 根据房屋来算单价
     *
     * @param feeDto
     */
    private void computeFeePriceByContract(FeeDto feeDto, RoomDto roomDto) {
        Map<String, Object> targetEndDateAndOweMonth = getTargetEndDateAndOweMonth(feeDto);
        Date targetEndDate = (Date) targetEndDateAndOweMonth.get("targetEndDate");
        double oweMonth = (double) targetEndDateAndOweMonth.get("oweMonth");
        String computingFormula = feeDto.getComputingFormula();
        Map feePriceAll = getFeePrice(feeDto, roomDto);
        feeDto.setFeePrice(Double.parseDouble(feePriceAll.get("feePrice").toString()));
        //double month = dayCompare(feeDto.getEndTime(), DateUtil.getCurrentDate());
        BigDecimal price = new BigDecimal(feeDto.getFeePrice());
        price = price.multiply(new BigDecimal(oweMonth));
        feeDto.setFeePrice(price.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
        feeDto.setDeadlineTime(targetEndDate);
        //动态费用
        if ("4004".equals(computingFormula)
                && FeeDto.FEE_FLAG_ONCE.equals(feeDto.getFeeFlag())
                && !FeeDto.STATE_FINISH.equals(feeDto.getState())) {
            feeDto.setAmountOwed(feeDto.getFeePrice() + "");
            //feeDto.setDeadlineTime(DateUtil.getCurrentDate()); 欠费日期不对先注释
        }
        //todo 考虑租金递增
        dealRentRate(feeDto);
    }
@@ -785,9 +709,6 @@
        Calendar endCalender = Calendar.getInstance();
        endCalender.setTime(endTime);
        endCalender.add(Calendar.MONTH, new Double(Math.floor(cycle)).intValue());
//        Calendar futureDate = Calendar.getInstance();
//        futureDate.setTime(endCalender.getTime());
//        futureDate.add(Calendar.MONTH, 1);
        int futureDay = endCalender.getActualMaximum(Calendar.DAY_OF_MONTH);
        int hours = new Double((cycle - Math.floor(cycle)) * futureDay * 24).intValue();
        endCalender.add(Calendar.HOUR, hours);
@@ -948,44 +869,7 @@
        return getFeePrice(feeDto, null);
    }
    /**
     * //计算周期
     * //                    Map<String, Object> cycleResults = dateDiff(feeDto.getEndTime(), feeDto.getCustEndTime());
     * //                    //月份大于0
     * //                    Integer months = Integer.valueOf(cycleResults.get("months").toString());
     * //                    Integer days = Integer.valueOf(cycleResults.get("days").toString());
     * //                    Integer startMonthDays = Integer.valueOf(cycleResults.get("startMonthDays").toString());
     * //                    Integer endMonthDays = Integer.valueOf(cycleResults.get("endMonthDays").toString());
     * //                    String isOneMonth = cycleResults.get("isOneMonth").toString();
     * //                    //整数月
     * //                    if (months > 0 && days == 0) {
     * //                        BigDecimal cycle = new BigDecimal(months);
     * //                        feeTotalPrice = (squarePrice.multiply(builtUpArea).add(additionalAmount)).multiply(cycle).setScale(3, BigDecimal.ROUND_HALF_UP);
     * //                    }
     * //                    //几个月几天   (单价*面积+附加费)*月份+((单价*面积+附加费)/总天数)*实际天数
     * //                    if (months > 0 && days > 0) {
     * //                        BigDecimal cycle = new BigDecimal(months);
     * //                        BigDecimal endMonthDayss = new BigDecimal(endMonthDays);
     * //                        BigDecimal dayss = new BigDecimal(days);
     * //                        BigDecimal monthPrice = squarePrice.multiply(builtUpArea).add(additionalAmount);
     * //                        feeTotalPrice = (monthPrice).multiply(cycle).add(monthPrice.divide(endMonthDayss).multiply(dayss)).setScale(3, BigDecimal.ROUND_HALF_UP);
     * //                    }
     * //                    //跨月份 不足一月  ((单价*面积+附加费)/开始月份总天数)*实际天数+((单价*面积+附加费)/结束月份总天数)*实际天数
     * //                    if (months == 0 && days > 0 && "true".equals(isOneMonth)) {
     * //                        BigDecimal startEndOfMonth = new BigDecimal(cycleResults.get("startEndOfMonth").toString());
     * //                        BigDecimal endBeginningOfMonth = new BigDecimal(cycleResults.get("endBeginningOfMonth").toString());
     * //                        BigDecimal endMonthDayss = new BigDecimal(endMonthDays);
     * //                        BigDecimal startMonthDayss = new BigDecimal(startMonthDays);
     * //                        BigDecimal monthPrice = squarePrice.multiply(builtUpArea).add(additionalAmount);
     * //                        feeTotalPrice = monthPrice.divide(startMonthDayss, 4, BigDecimal.ROUND_HALF_UP).multiply(startEndOfMonth).add(monthPrice.divide(endMonthDayss, 4, BigDecimal.ROUND_HALF_UP).multiply(endBeginningOfMonth)).setScale(3, BigDecimal.ROUND_HALF_UP);
     * //                    }
     * //                    //不跨月份 不足一月  (单价*面积+附加费/开始月份总天数)*实际天数
     * //                    if (months == 0 && days > 0 && "false".equals(isOneMonth)) {
     * //                        BigDecimal cycle = new BigDecimal(days);
     * //                        BigDecimal startMonthDayss = new BigDecimal(startMonthDays);
     * //                        BigDecimal monthPrice = squarePrice.multiply(builtUpArea).add(additionalAmount);
     * //                        feeTotalPrice = monthPrice.divide(startMonthDayss, 4, BigDecimal.ROUND_HALF_UP).multiply(cycle).setScale(3, BigDecimal.ROUND_HALF_UP);
     * //                    }
    /*
     *
     * @param feeDto
     * @param roomDto
@@ -999,6 +883,18 @@
        if (Environment.isOwnerPhone(java110Properties)) {
            return getOwnerPhoneFee(feeAmount);
        }
        //todo 如果 cycle 为105 则 根据缴费时间段 改写下
        if ("105".equals(feeDto.getCycle())) {
            double cycle = DateUtil.dayCompare(DateUtil.getDateFromStringB(feeDto.getCustomStartTime()), DateUtil.getDateFromStringB(feeDto.getCustomEndTime()));
            feeDto.setCycle(cycle + "");
        }
        // todo 按结束时间缴费
        if (!StringUtil.isEmpty(feeDto.getCustEndTime())) {
            double cycle = DateUtil.dayCompare(feeDto.getEndTime(), DateUtil.getDateFromStringB(feeDto.getCustEndTime()));
            feeDto.setCycle(cycle + "");
        }
        if (FeeDto.PAYER_OBJ_TYPE_ROOM.equals(feeDto.getPayerObjType())) { //房屋相关
            String computingFormula = feeDto.getComputingFormula();
            if (roomDto == null) {
@@ -1021,9 +917,6 @@
                if (!StringUtil.isEmpty(feeDto.getCycle())) {
                    cycle = new BigDecimal(feeDto.getCycle());
                }
                if (!StringUtil.isEmpty(feeDto.getCustEndTime())) {
                    cycle = new BigDecimal(dayCompare(feeDto.getEndTime(), DateUtil.getDateFromStringB(feeDto.getCustEndTime())));
                }
                if (cycle == null) {
                    feeTotalPrice = new BigDecimal(0);
                } else {
@@ -1036,9 +929,6 @@
                BigDecimal cycle = null;
                if (!StringUtil.isEmpty(feeDto.getCycle())) {
                    cycle = new BigDecimal(feeDto.getCycle());
                }
                if (!StringUtil.isEmpty(feeDto.getCustEndTime())) {
                    cycle = new BigDecimal(dayCompare(feeDto.getEndTime(), DateUtil.getDateFromStringB(feeDto.getCustEndTime())));
                }
                if (cycle == null) {
                    feeTotalPrice = new BigDecimal(0);
@@ -1054,9 +944,6 @@
                if (!StringUtil.isEmpty(feeDto.getCycle())) {
                    cycle = new BigDecimal(feeDto.getCycle());
                }
                if (!StringUtil.isEmpty(feeDto.getCustEndTime())) {
                    cycle = new BigDecimal(dayCompare(feeDto.getEndTime(), DateUtil.getDateFromStringB(feeDto.getCustEndTime())));
                }
                if (cycle == null) {
                    feeTotalPrice = new BigDecimal(0);
                } else {
@@ -1068,9 +955,6 @@
                BigDecimal cycle = null;
                if (!StringUtil.isEmpty(feeDto.getCycle())) {
                    cycle = new BigDecimal(feeDto.getCycle());
                }
                if (!StringUtil.isEmpty(feeDto.getCustEndTime())) {
                    cycle = new BigDecimal(dayCompare(feeDto.getEndTime(), DateUtil.getDateFromStringB(feeDto.getCustEndTime())));
                }
                if (cycle == null) {
                    feeTotalPrice = new BigDecimal(0);
@@ -1084,9 +968,6 @@
                if (!StringUtil.isEmpty(feeDto.getCycle())) {
                    cycle = new BigDecimal(feeDto.getCycle());
                }
                if (!StringUtil.isEmpty(feeDto.getCustEndTime())) {
                    cycle = new BigDecimal(dayCompare(feeDto.getEndTime(), DateUtil.getDateFromStringB(feeDto.getCustEndTime())));
                }
                if (cycle == null) {
                    feeTotalPrice = new BigDecimal(0);
                } else {
@@ -1097,9 +978,6 @@
                BigDecimal cycle = null;
                if (!StringUtil.isEmpty(feeDto.getCycle())) {
                    cycle = new BigDecimal(feeDto.getCycle());
                }
                if (!StringUtil.isEmpty(feeDto.getCustEndTime())) {
                    cycle = new BigDecimal(dayCompare(feeDto.getEndTime(), DateUtil.getDateFromStringB(feeDto.getCustEndTime())));
                }
                if (cycle == null) {
                    feeTotalPrice = new BigDecimal(0);
@@ -1123,9 +1001,6 @@
                    if (!StringUtil.isEmpty(feeDto.getCycle())) {
                        cycle = new BigDecimal(feeDto.getCycle());
                    }
                    if (!StringUtil.isEmpty(feeDto.getCustEndTime())) {
                        cycle = new BigDecimal(dayCompare(feeDto.getEndTime(), DateUtil.getDateFromStringB(feeDto.getCustEndTime())));
                    }
                    if (cycle == null) {
                        feeTotalPrice = new BigDecimal(0);
                    } else {
@@ -1138,9 +1013,6 @@
                BigDecimal cycle = null;
                if (!StringUtil.isEmpty(feeDto.getCycle())) {
                    cycle = new BigDecimal(feeDto.getCycle());
                }
                if (!StringUtil.isEmpty(feeDto.getCustEndTime())) {
                    cycle = new BigDecimal(dayCompare(feeDto.getEndTime(), DateUtil.getDateFromStringB(feeDto.getCustEndTime())));
                }
                if (cycle == null) {
                    feeTotalPrice = new BigDecimal(0);
@@ -1163,9 +1035,6 @@
                if (!StringUtil.isEmpty(feeDto.getCycle())) {
                    cycle = new BigDecimal(feeDto.getCycle());
                }
                if (!StringUtil.isEmpty(feeDto.getCustEndTime())) {
                    cycle = new BigDecimal(dayCompare(feeDto.getEndTime(), DateUtil.getDateFromStringB(feeDto.getCustEndTime())));
                }
                if (cycle == null) {
                    feeTotalPrice = new BigDecimal(0);
                } else {
@@ -1176,9 +1045,6 @@
                BigDecimal cycle = null;
                if (!StringUtil.isEmpty(feeDto.getCycle())) {
                    cycle = new BigDecimal(feeDto.getCycle());
                }
                if (!StringUtil.isEmpty(feeDto.getCustEndTime())) {
                    cycle = new BigDecimal(dayCompare(feeDto.getEndTime(), DateUtil.getDateFromStringB(feeDto.getCustEndTime())));
                }
                if (cycle == null) {
                    feeTotalPrice = new BigDecimal(0);
@@ -1200,9 +1066,6 @@
                    BigDecimal cycle = null;
                    if (!StringUtil.isEmpty(feeDto.getCycle())) {
                        cycle = new BigDecimal(feeDto.getCycle());
                    }
                    if (!StringUtil.isEmpty(feeDto.getCustEndTime())) {
                        cycle = new BigDecimal(dayCompare(feeDto.getEndTime(), DateUtil.getDateFromStringB(feeDto.getCustEndTime())));
                    }
                    if (cycle == null) {
                        feeTotalPrice = new BigDecimal(0);
@@ -1238,9 +1101,6 @@
                if (!StringUtil.isEmpty(feeDto.getCycle())) {
                    cycle = new BigDecimal(feeDto.getCycle());
                }
                if (!StringUtil.isEmpty(feeDto.getCustEndTime())) {
                    cycle = new BigDecimal(dayCompare(feeDto.getEndTime(), DateUtil.getDateFromStringB(feeDto.getCustEndTime())));
                }
                if (cycle == null) {
                    feeTotalPrice = new BigDecimal(0);
                } else {
@@ -1254,9 +1114,6 @@
                BigDecimal cycle = null;
                if (!StringUtil.isEmpty(feeDto.getCycle())) {
                    cycle = new BigDecimal(feeDto.getCycle());
                }
                if (!StringUtil.isEmpty(feeDto.getCustEndTime())) {
                    cycle = new BigDecimal(dayCompare(feeDto.getEndTime(), DateUtil.getDateFromStringB(feeDto.getCustEndTime())));
                }
                if (cycle == null) {
                    feeTotalPrice = new BigDecimal(0);
@@ -1273,9 +1130,6 @@
                if (!StringUtil.isEmpty(feeDto.getCycle())) {
                    cycle = new BigDecimal(feeDto.getCycle());
                }
                if (!StringUtil.isEmpty(feeDto.getCustEndTime())) {
                    cycle = new BigDecimal(dayCompare(feeDto.getEndTime(), DateUtil.getDateFromStringB(feeDto.getCustEndTime())));
                }
                if (cycle == null) {
                    feeTotalPrice = new BigDecimal(0);
                } else {
@@ -1288,9 +1142,6 @@
                BigDecimal cycle = null;
                if (!StringUtil.isEmpty(feeDto.getCycle())) {
                    cycle = new BigDecimal(feeDto.getCycle());
                }
                if (!StringUtil.isEmpty(feeDto.getCustEndTime())) {
                    cycle = new BigDecimal(dayCompare(feeDto.getEndTime(), DateUtil.getDateFromStringB(feeDto.getCustEndTime())));
                }
                if (cycle == null) {
                    feeTotalPrice = new BigDecimal(0);
@@ -1305,9 +1156,6 @@
                if (!StringUtil.isEmpty(feeDto.getCycle())) {
                    cycle = new BigDecimal(feeDto.getCycle());
                }
                if (!StringUtil.isEmpty(feeDto.getCustEndTime())) {
                    cycle = new BigDecimal(dayCompare(feeDto.getEndTime(), DateUtil.getDateFromStringB(feeDto.getCustEndTime())));
                }
                if (cycle == null) {
                    feeTotalPrice = new BigDecimal(0);
                } else {
@@ -1318,9 +1166,6 @@
                BigDecimal cycle = null;
                if (!StringUtil.isEmpty(feeDto.getCycle())) {
                    cycle = new BigDecimal(feeDto.getCycle());
                }
                if (!StringUtil.isEmpty(feeDto.getCustEndTime())) {
                    cycle = new BigDecimal(dayCompare(feeDto.getEndTime(), DateUtil.getDateFromStringB(feeDto.getCustEndTime())));
                }
                if (cycle == null) {
                    feeTotalPrice = new BigDecimal(0);
@@ -1344,9 +1189,6 @@
                    if (!StringUtil.isEmpty(feeDto.getCycle())) {
                        cycle = new BigDecimal(feeDto.getCycle());
                    }
                    if (!StringUtil.isEmpty(feeDto.getCustEndTime())) {
                        cycle = new BigDecimal(dayCompare(feeDto.getEndTime(), DateUtil.getDateFromStringB(feeDto.getCustEndTime())));
                    }
                    if (cycle == null) {
                        feeTotalPrice = new BigDecimal(0);
                    } else {
@@ -1360,9 +1202,6 @@
                if (!StringUtil.isEmpty(feeDto.getCycle())) {
                    cycle = new BigDecimal(feeDto.getCycle());
                }
                if (!StringUtil.isEmpty(feeDto.getCustEndTime())) {
                    cycle = new BigDecimal(dayCompare(feeDto.getEndTime(), DateUtil.getDateFromStringB(feeDto.getCustEndTime())));
                }
                if (cycle == null) {
                    feeTotalPrice = new BigDecimal(0);
                } else {
@@ -1374,9 +1213,6 @@
                BigDecimal cycle = null;
                if (!StringUtil.isEmpty(feeDto.getCycle())) {
                    cycle = new BigDecimal(feeDto.getCycle());
                }
                if (!StringUtil.isEmpty(feeDto.getCustEndTime())) {
                    cycle = new BigDecimal(dayCompare(feeDto.getEndTime(), DateUtil.getDateFromStringB(feeDto.getCustEndTime())));
                }
                if (cycle == null) {
                    feeTotalPrice = new BigDecimal(0);
@@ -1399,9 +1235,6 @@
                    BigDecimal cycle = null;
                    if (!StringUtil.isEmpty(feeDto.getCycle())) {
                        cycle = new BigDecimal(feeDto.getCycle());
                    }
                    if (!StringUtil.isEmpty(feeDto.getCustEndTime())) {
                        cycle = new BigDecimal(dayCompare(feeDto.getEndTime(), DateUtil.getDateFromStringB(feeDto.getCustEndTime())));
                    }
                    if (cycle == null) {
                        feeTotalPrice = new BigDecimal(0);
@@ -1435,9 +1268,6 @@
                if (!StringUtil.isEmpty(feeDto.getCycle())) {
                    cycle = new BigDecimal(feeDto.getCycle());
                }
                if (!StringUtil.isEmpty(feeDto.getCustEndTime())) {
                    cycle = new BigDecimal(dayCompare(feeDto.getEndTime(), DateUtil.getDateFromStringB(feeDto.getCustEndTime())));
                }
                if (cycle == null) {
                    feeTotalPrice = new BigDecimal(0);
                } else {
@@ -1454,9 +1284,6 @@
                if (!StringUtil.isEmpty(feeDto.getCycle())) {
                    cycle = new BigDecimal(feeDto.getCycle());
                }
                if (!StringUtil.isEmpty(feeDto.getCustEndTime())) {
                    cycle = new BigDecimal(dayCompare(feeDto.getEndTime(), DateUtil.getDateFromStringB(feeDto.getCustEndTime())));
                }
                if (cycle == null) {
                    feeTotalPrice = new BigDecimal(0);
                } else {
@@ -1472,9 +1299,6 @@
                if (!StringUtil.isEmpty(feeDto.getCycle())) {
                    cycle = new BigDecimal(feeDto.getCycle());
                }
                if (!StringUtil.isEmpty(feeDto.getCustEndTime())) {
                    cycle = new BigDecimal(dayCompare(feeDto.getEndTime(), DateUtil.getDateFromStringB(feeDto.getCustEndTime())));
                }
                if (cycle == null) {
                    feeTotalPrice = new BigDecimal(0);
                } else {
@@ -1487,9 +1311,6 @@
                BigDecimal cycle = null;
                if (!StringUtil.isEmpty(feeDto.getCycle())) {
                    cycle = new BigDecimal(feeDto.getCycle());
                }
                if (!StringUtil.isEmpty(feeDto.getCustEndTime())) {
                    cycle = new BigDecimal(dayCompare(feeDto.getEndTime(), DateUtil.getDateFromStringB(feeDto.getCustEndTime())));
                }
                if (cycle == null) {
                    feeTotalPrice = new BigDecimal(0);
@@ -1504,9 +1325,6 @@
                if (!StringUtil.isEmpty(feeDto.getCycle())) {
                    cycle = new BigDecimal(feeDto.getCycle());
                }
                if (!StringUtil.isEmpty(feeDto.getCustEndTime())) {
                    cycle = new BigDecimal(dayCompare(feeDto.getEndTime(), DateUtil.getDateFromStringB(feeDto.getCustEndTime())));
                }
                if (cycle == null) {
                    feeTotalPrice = new BigDecimal(0);
                } else {
@@ -1518,9 +1336,6 @@
                BigDecimal cycle = null;
                if (!StringUtil.isEmpty(feeDto.getCycle())) {
                    cycle = new BigDecimal(feeDto.getCycle());
                }
                if (!StringUtil.isEmpty(feeDto.getCustEndTime())) {
                    cycle = new BigDecimal(dayCompare(feeDto.getEndTime(), DateUtil.getDateFromStringB(feeDto.getCustEndTime())));
                }
                if (cycle == null) {
                    feeTotalPrice = new BigDecimal(0);
@@ -1545,9 +1360,6 @@
                    if (!StringUtil.isEmpty(feeDto.getCycle())) {
                        cycle = new BigDecimal(feeDto.getCycle());
                    }
                    if (!StringUtil.isEmpty(feeDto.getCustEndTime())) {
                        cycle = new BigDecimal(dayCompare(feeDto.getEndTime(), DateUtil.getDateFromStringB(feeDto.getCustEndTime())));
                    }
                    if (cycle == null) {
                        feeTotalPrice = new BigDecimal(0);
                    } else {
@@ -1561,9 +1373,6 @@
                if (!StringUtil.isEmpty(feeDto.getCycle())) {
                    cycle = new BigDecimal(feeDto.getCycle());
                }
                if (!StringUtil.isEmpty(feeDto.getCustEndTime())) {
                    cycle = new BigDecimal(dayCompare(feeDto.getEndTime(), DateUtil.getDateFromStringB(feeDto.getCustEndTime())));
                }
                if (cycle == null) {
                    feeTotalPrice = new BigDecimal(0);
                } else {
@@ -1576,9 +1385,6 @@
                if (!StringUtil.isEmpty(feeDto.getCycle())) {
                    cycle = new BigDecimal(feeDto.getCycle());
                }
                if (!StringUtil.isEmpty(feeDto.getCustEndTime())) {
                    cycle = new BigDecimal(dayCompare(feeDto.getEndTime(), DateUtil.getDateFromStringB(feeDto.getCustEndTime())));
                }
                if (cycle == null) {
                    feeTotalPrice = new BigDecimal(0);
                } else {
@@ -1590,9 +1396,6 @@
                BigDecimal cycle = null;
                if (!StringUtil.isEmpty(feeDto.getCycle())) {
                    cycle = new BigDecimal(feeDto.getCycle());
                }
                if (!StringUtil.isEmpty(feeDto.getCustEndTime())) {
                    cycle = new BigDecimal(dayCompare(feeDto.getEndTime(), DateUtil.getDateFromStringB(feeDto.getCustEndTime())));
                }
                if (cycle == null) {
                    feeTotalPrice = new BigDecimal(0);
@@ -1615,9 +1418,6 @@
                    BigDecimal cycle = null;
                    if (!StringUtil.isEmpty(feeDto.getCycle())) {
                        cycle = new BigDecimal(feeDto.getCycle());
                    }
                    if (!StringUtil.isEmpty(feeDto.getCustEndTime())) {
                        cycle = new BigDecimal(dayCompare(feeDto.getEndTime(), DateUtil.getDateFromStringB(feeDto.getCustEndTime())));
                    }
                    if (cycle == null) {
                        feeTotalPrice = new BigDecimal(0);
@@ -1772,13 +1572,13 @@
        ScriptEngineManager manager = new ScriptEngineManager();
        ScriptEngine engine = manager.getEngineByName("JavaScript");
        BigDecimal valueObj = null;
        logger.debug("计算公式为:{}",value);
        logger.debug("计算公式为:{}", value);
        try {
            value = engine.eval(value).toString();
            valueObj = new BigDecimal(Double.parseDouble(value));
        } catch (Exception e) {
            //throw new IllegalArgumentException("公式计算异常,公式为【" + feeDto.getComputingFormulaText() + "】,计算 【" + value + "】异常");
            logger.error("公式计算异常,公式为【" + feeDto.getComputingFormulaText() + "】,计算 【" + value + "】异常",e);
            logger.error("公式计算异常,公式为【" + feeDto.getComputingFormulaText() + "】,计算 【" + value + "】异常", e);
            valueObj = new BigDecimal(0);
        }
@@ -1788,6 +1588,12 @@
        return valueObj;
    }
    @Override
    public Date getDeadlineTime(FeeDto feeDto) {
        Map info = getTargetEndDateAndOweMonth(feeDto);
        return (Date) info.get("targetEndDate");
    }
    /**
@@ -1802,14 +1608,23 @@
        double oweMonth = 0.0;
        Map<String, Object> targetEndDateAndOweMonth = new HashMap<>();
        //判断当前费用是否已结束
        //todo 判断当前费用是否已结束
        if (FeeDto.STATE_FINISH.equals(feeDto.getState())) {
            targetEndDate = feeDto.getEndTime();
            targetEndDateAndOweMonth.put("oweMonth", oweMonth);
            targetEndDateAndOweMonth.put("targetEndDate", targetEndDate);
            return targetEndDateAndOweMonth;
        }
        //当前费用为一次性费用
        //todo 考虑费用项 费用提前生成
        Calendar preEndTimeCal = Calendar.getInstance();
        preEndTimeCal.setTime(feeDto.getEndTime());
        if (StringUtil.isNumber(feeDto.getPrepaymentPeriod())) {
            preEndTimeCal.add(Calendar.DAY_OF_MONTH, Integer.parseInt(feeDto.getPrepaymentPeriod()) * -1);
        }
        Date preEndTime = preEndTimeCal.getTime();
        //todo 当前费用为一次性费用
        Date maxEndTime = feeDto.getConfigEndTime();
        if (FeeDto.FEE_FLAG_ONCE.equals(feeDto.getFeeFlag())) {
            //先取 deadlineTime
@@ -1822,8 +1637,17 @@
            } else {
                targetEndDate = feeDto.getImportFeeEndTime();
            }
            //判断当前费用是不是导入费用
            oweMonth = 1.0;
            //说明欠费
            if (preEndTime.getTime() <= DateUtil.getCurrentDate().getTime()) {
                // 目标到期时间 - 到期时间 = 欠费月份
                oweMonth = 1.0;
            }
            //todo 这里考虑 账单模式的场景
            if (StringUtil.isNumber(feeDto.getMonthCycle())) {
                oweMonth = Integer.parseInt(feeDto.getMonthCycle());
            }
        } else if (FeeDto.FEE_FLAG_CYCLE_ONCE.equals(feeDto.getFeeFlag())) {
            if (feeDto.getDeadlineTime() != null) {
                maxEndTime = feeDto.getDeadlineTime();
@@ -1837,7 +1661,7 @@
            long paymentCycle = Long.parseLong(feeDto.getPaymentCycle());
            // 当前时间 - 开始时间  = 月份
            double mulMonth = 0.0;
            mulMonth = dayCompare(startDate, billEndTime);
            mulMonth = DateUtil.dayCompare(startDate, billEndTime);
            // 月份/ 周期 = 轮数(向上取整)
            double round = 0.0;
@@ -1848,20 +1672,29 @@
            }
            // 轮数 * 周期 * 30 + 开始时间 = 目标 到期时间
            targetEndDate = getTargetEndTime(round * paymentCycle, startDate);//目标结束时间
            //费用项的结束时间<缴费的结束时间  费用快结束了   取费用项的结束时间
            //todo 如果 到了 预付期 产生下个周期的费用
            if (DateUtil.getFormatTimeStringB(targetEndDate).equals(DateUtil.getFormatTimeStringB(endDate))
                    && DateUtil.getCurrentDate().getTime() > preEndTime.getTime()
            ) {
                targetEndDate = getTargetEndTime((round + 1) * paymentCycle, startDate);//目标结束时间
            }
            //todo 费用项的结束时间<缴费的结束时间  费用快结束了   取费用项的结束时间
            if (maxEndTime.getTime() < targetEndDate.getTime()) {
                targetEndDate = maxEndTime;
            }
            //说明欠费
            if (endDate.getTime() < targetEndDate.getTime()) {
                // 目标到期时间 - 到期时间 = 欠费月份
                oweMonth = dayCompare(endDate, targetEndDate);
                oweMonth = DateUtil.dayCompare(endDate, targetEndDate);
            }
            if (feeDto.getEndTime().getTime() > targetEndDate.getTime()) {
                targetEndDate = feeDto.getEndTime();
            }
        } else { //周期性费用
        } else { // todo 周期性费用
            //当前时间
            Date billEndTime = DateUtil.getCurrentDate();
            //建账时间
@@ -1872,7 +1705,7 @@
            long paymentCycle = Long.parseLong(feeDto.getPaymentCycle());
            // 当前时间 - 开始时间  = 月份
            double mulMonth = 0.0;
            mulMonth = dayCompare(startDate, billEndTime);
            mulMonth = DateUtil.dayCompare(startDate, billEndTime);
            // 月份/ 周期 = 轮数(向上取整)
            double round = 0.0;
@@ -1883,6 +1716,14 @@
            }
            // 轮数 * 周期 * 30 + 开始时间 = 目标 到期时间
            targetEndDate = getTargetEndTime(round * paymentCycle, startDate);//目标结束时间
            //todo 如果 到了 预付期 产生下个周期的费用
            if (DateUtil.getFormatTimeStringB(targetEndDate).equals(DateUtil.getFormatTimeStringB(endDate))
                    && DateUtil.getCurrentDate().getTime() > preEndTime.getTime()
            ) {
                targetEndDate = getTargetEndTime((round + 1) * paymentCycle, startDate);//目标结束时间
            }
            //费用项的结束时间<缴费的结束时间  费用快结束了   取费用项的结束时间
            if (maxEndTime.getTime() < targetEndDate.getTime()) {
                targetEndDate = maxEndTime;
@@ -1890,7 +1731,7 @@
            //说明欠费
            if (endDate.getTime() < targetEndDate.getTime()) {
                // 目标到期时间 - 到期时间 = 欠费月份
                oweMonth = dayCompare(endDate, targetEndDate);
                oweMonth = DateUtil.dayCompare(endDate, targetEndDate);
            }
            if (feeDto.getEndTime().getTime() > targetEndDate.getTime()) {
@@ -1904,79 +1745,72 @@
    }
    public Map getTargetEndDateAndOweMonth(FeeDto feeDto) {
//        if (FeeDto.PAYER_OBJ_TYPE_CAR.equals(feeDto.getPayerObjType())) {
//            OwnerCarDto ownerCarDto = new OwnerCarDto();
//            ownerCarDto.setCommunityId(feeDto.getCommunityId());
//            ownerCarDto.setCarId(feeDto.getPayerObjId());
//            List<OwnerCarDto> ownerCarDtos = ownerCarInnerServiceSMOImpl.queryOwnerCars(ownerCarDto);
//            return getTargetEndDateAndOweMonth(feeDto, ownerCarDtos == null || ownerCarDtos.size() < 1 ? null : ownerCarDtos.get(0));
//        }
        return getTargetEndDateAndOweMonth(feeDto, null);
    }
    /**
     * 计算 两个时间点月份
     *
     * @param fromDate 开始时间
     * @param toDate   结束时间
     * @return
     */
    @Override
    public double dayCompare(Date fromDate, Date toDate) {
        double resMonth = 0.0;
        Calendar from = Calendar.getInstance();
        from.setTime(fromDate);
        Calendar to = Calendar.getInstance();
        to.setTime(toDate);
        //比较月份差 可能有整数 也会负数
        int result = to.get(Calendar.MONTH) - from.get(Calendar.MONTH);
        //比较年差
        int month = (to.get(Calendar.YEAR) - from.get(Calendar.YEAR)) * 12;
        //真实 相差月份
        result = result + month;
        //开始时间  2021-06-01  2021-08-05   result = 2    2021-08-01
        Calendar newFrom = Calendar.getInstance();
        newFrom.setTime(fromDate);
        newFrom.add(Calendar.MONTH, result);
        //如果加月份后 大于了当前时间 默认加 月份 -1 情况 12-19  21-01-10
        //这个是神的逻辑一定好好理解
        if (newFrom.getTime().getTime() > toDate.getTime()) {
            newFrom.setTime(fromDate);
            result = result - 1;
            newFrom.add(Calendar.MONTH, result);
        }
        // t1 2021-08-01   t2 2021-08-05
        long t1 = newFrom.getTime().getTime();
        long t2 = to.getTime().getTime();
        //相差毫秒
        double days = (t2 - t1) * 1.00 / (24 * 60 * 60 * 1000);
        BigDecimal tmpDays = new BigDecimal(days); //相差天数
        BigDecimal monthDay = null;
        Calendar newFromMaxDay = Calendar.getInstance();
        newFromMaxDay.set(newFrom.get(Calendar.YEAR), newFrom.get(Calendar.MONTH), 1, 0, 0, 0);
        newFromMaxDay.add(Calendar.MONTH, 1); //下个月1号
        //在当前月中 这块有问题
        if (toDate.getTime() < newFromMaxDay.getTime().getTime()) {
            monthDay = new BigDecimal(newFrom.getActualMaximum(Calendar.DAY_OF_MONTH));
            return tmpDays.divide(monthDay, 4, BigDecimal.ROUND_HALF_UP).add(new BigDecimal(result)).doubleValue();
        }
        // 上月天数
        days = (newFromMaxDay.getTimeInMillis() - t1) * 1.00 / (24 * 60 * 60 * 1000);
        tmpDays = new BigDecimal(days);
        monthDay = new BigDecimal(newFrom.getActualMaximum(Calendar.DAY_OF_MONTH));
        BigDecimal preRresMonth = tmpDays.divide(monthDay, 4, BigDecimal.ROUND_HALF_UP);
        //下月天数
        days = (t2 - newFromMaxDay.getTimeInMillis()) * 1.00 / (24 * 60 * 60 * 1000);
        tmpDays = new BigDecimal(days);
        monthDay = new BigDecimal(newFromMaxDay.getActualMaximum(Calendar.DAY_OF_MONTH));
        resMonth = tmpDays.divide(monthDay, 4, BigDecimal.ROUND_HALF_UP).add(new BigDecimal(result)).add(preRresMonth).doubleValue();
        return resMonth;
    }
//    /**
//     * 计算 两个时间点月份
//     *
//     * @param fromDate 开始时间
//     * @param toDate   结束时间
//     * @return
//     */
//
//    public double dayCompareOld(Date fromDate, Date toDate) {
//        double resMonth = 0.0;
//        Calendar from = Calendar.getInstance();
//        from.setTime(fromDate);
//        Calendar to = Calendar.getInstance();
//        to.setTime(toDate);
//        //比较月份差 可能有整数 也会负数
//        int result = to.get(Calendar.MONTH) - from.get(Calendar.MONTH);
//        //比较年差
//        int month = (to.get(Calendar.YEAR) - from.get(Calendar.YEAR)) * 12;
//
//        //真实 相差月份
//        result = result + month;
//
//        //开始时间  2021-06-01  2021-08-05   result = 2    2021-08-01
//        Calendar newFrom = Calendar.getInstance();
//        newFrom.setTime(fromDate);
//        newFrom.add(Calendar.MONTH, result);
//        //如果加月份后 大于了当前时间 默认加 月份 -1 情况 12-19  21-01-10
//        //这个是神的逻辑一定好好理解
//        if (newFrom.getTime().getTime() > toDate.getTime()) {
//            newFrom.setTime(fromDate);
//            result = result - 1;
//            newFrom.add(Calendar.MONTH, result);
//        }
//
//        // t1 2021-08-01   t2 2021-08-05
//        long t1 = newFrom.getTime().getTime();
//        long t2 = to.getTime().getTime();
//        //相差毫秒
//        double days = (t2 - t1) * 1.00 / (24 * 60 * 60 * 1000);
//        BigDecimal tmpDays = new BigDecimal(days); //相差天数
//        BigDecimal monthDay = null;
//        Calendar newFromMaxDay = Calendar.getInstance();
//        newFromMaxDay.set(newFrom.get(Calendar.YEAR), newFrom.get(Calendar.MONTH), 1, 0, 0, 0);
//        newFromMaxDay.add(Calendar.MONTH, 1); //下个月1号
//        //在当前月中 这块有问题
//        if (toDate.getTime() < newFromMaxDay.getTime().getTime()) {
//            monthDay = new BigDecimal(newFrom.getActualMaximum(Calendar.DAY_OF_MONTH));
//            return tmpDays.divide(monthDay, 4, BigDecimal.ROUND_HALF_UP).add(new BigDecimal(result)).doubleValue();
//        }
//        // 上月天数
//        days = (newFromMaxDay.getTimeInMillis() - t1) * 1.00 / (24 * 60 * 60 * 1000);
//        tmpDays = new BigDecimal(days);
//        monthDay = new BigDecimal(newFrom.getActualMaximum(Calendar.DAY_OF_MONTH));
//        BigDecimal preRresMonth = tmpDays.divide(monthDay, 4, BigDecimal.ROUND_HALF_UP);
//
//        //下月天数
//        days = (t2 - newFromMaxDay.getTimeInMillis()) * 1.00 / (24 * 60 * 60 * 1000);
//        tmpDays = new BigDecimal(days);
//        monthDay = new BigDecimal(newFromMaxDay.getActualMaximum(Calendar.DAY_OF_MONTH));
//        resMonth = tmpDays.divide(monthDay, 4, BigDecimal.ROUND_HALF_UP).add(new BigDecimal(result)).add(preRresMonth).doubleValue();
//        return resMonth;
//    }
    //手机端缴费处理
@@ -2294,17 +2128,26 @@
        //计算 计费起始时间 到 rateStartTime 时的费用
        double curOweMonth = 0;
        BigDecimal curFeePrice = new BigDecimal(feeDto.getFeePrice());
        // todo 如果计费起始时间 小区 递增开始时间
        if (feeDto.getEndTime().getTime() < rateStartTime.getTime()) {
            curOweMonth = dayCompare(feeDto.getEndTime(), rateStartTime);
            //todo 递增前的欠费
            curOweMonth = DateUtil.dayCompare(feeDto.getEndTime(), rateStartTime);
            oweAmountDec = curFeePrice.multiply(new BigDecimal(curOweMonth)).setScale(FeeConfigConstant.FEE_SCALE, BigDecimal.ROUND_HALF_UP);
            // todo 递增
            curOweMonth = DateUtil.dayCompare(rateStartTime, feeDto.getDeadlineTime());
        } else {
            // todo 递增
            curOweMonth = DateUtil.dayCompare(feeDto.getEndTime(), feeDto.getDeadlineTime());
        }
        double rateMonth = DateUtil.dayCompare(rateStartTime, feeDto.getDeadlineTime());
        curOweMonth = dayCompare(rateStartTime, feeDto.getDeadlineTime());
        // todo 最大周期
        double maxCycle = Math.ceil(rateMonth / rateCycle);
        double maxCycle = Math.ceil(curOweMonth / rateCycle);
        // 增长前的欠费
        // todo 增长前的欠费
        BigDecimal addTotalAmount = oweAmountDec;
        // todo 递增周期内的 未递增费用
        BigDecimal preCycleAmount = curFeePrice.multiply(new BigDecimal(rateCycle));
        BigDecimal rateDec = null; //递增周期所收费用
        BigDecimal lastRateAmountDec = null;
@@ -2322,7 +2165,7 @@
            curEndTimeCalender.setTime(rateStartTime);
            curEndTimeCalender.add(Calendar.MONTH, new Double(curCycle).intValue());
            curEndTime = curEndTimeCalender.getTime();
            if (curCycle > curOweMonth) {
            if (curCycle > rateMonth) {
                //不足增长周期增长率
                rateDec = new BigDecimal(curOweMonth / rateCycle - Math.floor(curOweMonth / rateCycle)).multiply(rateDec).setScale(FeeConfigConstant.FEE_SCALE, BigDecimal.ROUND_HALF_UP);
                lastRateAmountDec = new BigDecimal(curOweMonth / rateCycle - Math.floor(curOweMonth / rateCycle)).multiply(preCycleAmount).setScale(FeeConfigConstant.FEE_SCALE, BigDecimal.ROUND_HALF_UP);
@@ -2332,13 +2175,15 @@
            //本期金额
            curAmount = rateDec.add(preCycleAmount);// 增长部分 + 上本期费用
            //如果计费起始时间 大于 递增开始时间 那么本轮 不计入
            if (feeDto.getEndTime().getTime() < curEndTime.getTime()) {
            if (feeDto.getEndTime().getTime() <= curEndTime.getTime()) {
                addTotalAmount = addTotalAmount.add(curAmount); // 计入总的 费用中
            }
            preCycleAmount = curAmount;
        }
        feeDto.setAmountOwed(addTotalAmount.doubleValue() + "");
        feeDto.setFeeTotalPrice(addTotalAmount.doubleValue());
        Double amountOwed = MoneyUtil.computePriceScale(addTotalAmount.doubleValue(), feeDto.getScale(), Integer.parseInt(feeDto.getDecimalPlace()));
        feeDto.setAmountOwed(amountOwed + "");
        feeDto.setFeeTotalPrice(amountOwed);
    }
}