java110
2022-06-23 3343885406b4fb874e82c5238bc31c0348e99ee7
service-report/src/main/java/com/java110/report/smo/impl/GeneratorFeeMonthStatisticsInnerServiceSMOImpl.java
@@ -17,24 +17,16 @@
import com.java110.report.dao.IReportCommunityServiceDao;
import com.java110.report.dao.IReportFeeMonthStatisticsServiceDao;
import com.java110.report.dao.IReportFeeServiceDao;
import com.java110.utils.util.Assert;
import com.java110.utils.util.BeanConvertUtil;
import com.java110.utils.util.DateUtil;
import com.java110.utils.util.ListUtil;
import com.java110.utils.util.StringUtil;
import com.java110.utils.util.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.java110.core.log.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import java.math.BigDecimal;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;
/**
 * @ClassName GeneratorFeeMonthStatisticsInnerServiceSMOImpl
@@ -79,6 +71,9 @@
        Assert.hasLength(communityId, "未包含小区信息");
        //这里处理 报表中的费用是否被人为 取消 或者费用项是否被删除,这种数据 报表中做清理,以防影响 报表的准确度
        feeDataFiltering(communityId);
        //处理房屋费用
        dealRoomFee(reportFeeMonthStatisticsPo);
@@ -87,6 +82,12 @@
        //处理缴费结束的情况
        dealFinishFee(communityId);
    }
    private void feeDataFiltering(String communityId) {
        Map reportFeeDto = new HashMap();
        reportFeeDto.put("communityId", communityId);
        reportFeeMonthStatisticsServiceDaoImpl.deleteInvalidFee(reportFeeDto);
    }
    private void dealFinishFee(String communityId) {
@@ -256,6 +257,10 @@
//            reportFeeMonthStatisticsPo.setReceivedAmount("0");
            reportFeeMonthStatisticsPo.setOweAmount(oweAmount + "");
            reportFeeMonthStatisticsPo.setUpdateTime(DateUtil.getNow(DateUtil.DATE_FORMATE_STRING_A));
            // 缴费了就得刷
            reportFeeMonthStatisticsPo.setHisOweAmount(getHisOweAmount(tmpReportFeeDto) + "");
            //有可能是月内创建的费用 比如电费水费
            reportFeeMonthStatisticsPo.setCurReceivableAmount(getCurFeeReceivableAmount(tmpReportFeeDto) + "");
            reportFeeMonthStatisticsPo.setCurReceivedAmount(getReceivedAmount(tmpReportFeeDto, 1) + "");
            reportFeeMonthStatisticsPo.setHisOweReceivedAmount(getReceivedAmount(tmpReportFeeDto, 2) + "");
            reportFeeMonthStatisticsPo.setPreReceivedAmount(getReceivedAmount(tmpReportFeeDto, 3) + "");
@@ -453,6 +458,10 @@
            reportFeeMonthStatisticsPo.setFeeId(tmpReportFeeDto.getFeeId());
            reportFeeMonthStatisticsPo.setUpdateTime(DateUtil.getNow(DateUtil.DATE_FORMATE_STRING_A));
            reportFeeMonthStatisticsPo.setFeeName(StringUtil.isEmpty(tmpReportFeeDto.getImportFeeName()) ? tmpReportFeeDto.getFeeName() : tmpReportFeeDto.getImportFeeName());
            // 缴费了就得刷
            reportFeeMonthStatisticsPo.setHisOweAmount(getHisOweAmount(tmpReportFeeDto) + "");
            //有可能是月内创建的费用 比如电费水费
            reportFeeMonthStatisticsPo.setCurReceivableAmount(getCurFeeReceivableAmount(tmpReportFeeDto) + "");
            reportFeeMonthStatisticsPo.setCurReceivedAmount(getReceivedAmount(tmpReportFeeDto, 1) + "");
            reportFeeMonthStatisticsPo.setHisOweReceivedAmount(getReceivedAmount(tmpReportFeeDto, 2) + "");
            reportFeeMonthStatisticsPo.setPreReceivedAmount(getReceivedAmount(tmpReportFeeDto, 3) + "");
@@ -529,16 +538,34 @@
                || curDate.getTime() < tmpReportFeeDto.getEndTime().getTime()) {
            return 0.0;
        }
        //这里需要判断 结束时间 是否 大于了当月最后一天,当月天数 * 每天金额
        Calendar nextDateC = Calendar.getInstance();
        nextDateC.setTime(curDate);
        nextDateC.add(Calendar.MONTH, 1);
        Date nextDate = nextDateC.getTime();
        if (FeeDto.FEE_FLAG_ONCE.equals(tmpReportFeeDto.getFeeFlag())) {
            month = computeFeeSMOImpl.dayCompare(tmpReportFeeDto.getEndTime(), tmpReportFeeDto.getDeadlineTime());
            month = Math.ceil(month);
            if (month == 0) {
                return 0.0;
            double allDays = computeFeeSMOImpl.daysBetween(tmpReportFeeDto.getEndTime(), tmpReportFeeDto.getDeadlineTime());
            allDays = Math.ceil(allDays);
            if (allDays == 0) { // 防止除数为0
                return 0;
            }
            double money = feePriceDec.divide(new BigDecimal(month), 2, BigDecimal.ROUND_HALF_EVEN).doubleValue();
            return money;
            BigDecimal moneyPreDay = feePriceDec.divide(new BigDecimal(allDays), 2, BigDecimal.ROUND_HALF_EVEN);
            if (tmpReportFeeDto.getDeadlineTime().getTime() > nextDate.getTime()) {
                int day = DateUtil.getCurrentMonthDay();
                return moneyPreDay.multiply(new BigDecimal(day)).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
            }
            // 结束时间 在当月内
            double hisDays = computeFeeSMOImpl.daysBetween(tmpReportFeeDto.getEndTime(), curDate);
            BigDecimal hisDayDec = moneyPreDay.multiply(new BigDecimal(hisDays)).setScale(2, BigDecimal.ROUND_HALF_UP);
            return feePriceDec.subtract(hisDayDec).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
        }
        month = computeFeeSMOImpl.dayCompare(tmpReportFeeDto.getEndTime(), curDate);
        month = computeFeeSMOImpl.dayCompare(curDate, tmpReportFeeDto.getDeadlineTime());
        if (month < 0) {
            return 0;
        }
        if (month < 1) {
            return feePriceDec.multiply(new BigDecimal(month)).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue();
        }
@@ -556,7 +583,7 @@
    private double getHisOweAmount(ReportFeeDto tmpReportFeeDto) {
        BigDecimal feePriceDec = new BigDecimal(tmpReportFeeDto.getFeePrice());
        Date curDate = DateUtil.getFirstDate();
        Date curDate = DateUtil.getFirstDate();//11月1日
        //说明没有历史欠费
        if (curDate.getTime() < tmpReportFeeDto.getEndTime().getTime()) {
            return 0.0;
@@ -567,10 +594,17 @@
            if (tmpReportFeeDto.getDeadlineTime().getTime() < curDate.getTime()) {
                return tmpReportFeeDto.getFeePrice();
            }
            double month = computeFeeSMOImpl.dayCompare(tmpReportFeeDto.getDeadlineTime(), tmpReportFeeDto.getEndTime());
            month = Math.ceil(month);
            double money = feePriceDec.divide(new BigDecimal(month), 2, BigDecimal.ROUND_HALF_EVEN).doubleValue();
            return money;
            double allDays = computeFeeSMOImpl.daysBetween(tmpReportFeeDto.getEndTime(), tmpReportFeeDto.getDeadlineTime());
            allDays = Math.ceil(allDays);
            if (allDays == 0) { // 防止除数为0
                return 0;
            }
            //这是每天的钱
            BigDecimal moneyPreDay = feePriceDec.divide(new BigDecimal(allDays), 2, BigDecimal.ROUND_HALF_EVEN);
            double hisDays = computeFeeSMOImpl.daysBetween(tmpReportFeeDto.getEndTime(), curDate);
            return moneyPreDay.multiply(new BigDecimal(hisDays)).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
        }
        double month = 0.0;
@@ -751,6 +785,11 @@
        }
        Date endTime = ownerCarDtos.get(0).getEndTime();
        Date maxEndDate = tmpReportFeeDto.getDeadlineTime();
        if(FeeDto.FEE_FLAG_CYCLE.equals(tmpReportFeeDto.getFeeFlag())){
            maxEndDate = tmpReportFeeDto.getConfigEndTime();
        }
        //1.0 费用到期时间和费用结束时间 都不在当月
        if (!belongCurMonth(tmpReportFeeDto.getEndTime())
                && !belongCurMonth(endTime)
@@ -770,7 +809,7 @@
        if (!belongCurMonth(tmpReportFeeDto.getEndTime())
                && belongCurMonth(endTime)) {
            //算天数
            double month = computeFeeSMOImpl.dayCompare(DateUtil.getFirstDate(), tmpReportFeeDto.getConfigEndTime());
            double month = computeFeeSMOImpl.dayCompare(DateUtil.getFirstDate(), maxEndDate);
            BigDecimal curDegree = new BigDecimal(month);
            return curDegree.multiply(feePriceDec).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue();
        }
@@ -816,16 +855,21 @@
            return computeOnceFee(tmpReportFeeDto);
        }
        Date maxEndDate = tmpReportFeeDto.getDeadlineTime();
        if(FeeDto.FEE_FLAG_CYCLE.equals(tmpReportFeeDto.getFeeFlag())){
            maxEndDate = tmpReportFeeDto.getConfigEndTime();
        }
        //1.0 费用到期时间和费用结束时间 都不在当月
        if (!belongCurMonth(tmpReportFeeDto.getEndTime())
                && !belongCurMonth(tmpReportFeeDto.getConfigEndTime())
                && !belongCurMonth(maxEndDate)
                && tmpReportFeeDto.getEndTime().getTime() < DateUtil.getFirstDate().getTime()) {
            return feePrice;
        }
        //2.0 费用到期时间 在当月,费用结束时间不在当月
        if (belongCurMonth(tmpReportFeeDto.getEndTime())
                && !belongCurMonth(tmpReportFeeDto.getConfigEndTime())) {
                && !belongCurMonth(maxEndDate)) {
            //算天数
            double month = computeFeeSMOImpl.dayCompare(tmpReportFeeDto.getEndTime(), DateUtil.getNextMonthFirstDate());
            BigDecimal curDegree = new BigDecimal(month);
@@ -833,9 +877,9 @@
        }
        //3.0 费用到期时间 不在当月,费用结束时间在当月
        if (!belongCurMonth(tmpReportFeeDto.getEndTime())
                && belongCurMonth(tmpReportFeeDto.getConfigEndTime())) {
                && belongCurMonth(maxEndDate)) {
            //算天数
            double month = computeFeeSMOImpl.dayCompare(DateUtil.getFirstDate(), tmpReportFeeDto.getConfigEndTime());
            double month = computeFeeSMOImpl.dayCompare(DateUtil.getFirstDate(), maxEndDate);
            BigDecimal curDegree = new BigDecimal(month);
            return curDegree.multiply(feePriceDec).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue();
        }