java110
2023-05-17 402d54b051a96b61a5bab774437e98705b64708d
service-fee/src/main/java/com/java110/fee/feeMonth/PayFeeMonthHelp.java
@@ -4,6 +4,7 @@
import com.java110.dto.fee.FeeAttrDto;
import com.java110.dto.fee.FeeDetailDto;
import com.java110.dto.fee.FeeDto;
import com.java110.dto.fee.MonthFeeDetailDto;
import com.java110.dto.payFeeDetailMonth.PayFeeMonthOwnerDto;
import com.java110.intf.community.IRoomInnerServiceSMO;
import com.java110.utils.util.BeanConvertUtil;
@@ -13,10 +14,7 @@
import org.springframework.stereotype.Service;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.*;
@Service
public class PayFeeMonthHelp implements IPayFeeMonthHelp {
@@ -53,58 +51,34 @@
        if (!FeeDto.FEE_FLAG_ONCE.equals(feeDto.getPayerObjType())) {
            return feePrice;
        }
        double maxMonth = Math.ceil(computeFeeSMOImpl.dayCompare(feeDto.getStartTime(), feeDto.getEndTime()));
        if (maxMonth <= 0) {
        List<String> months = DateUtil.getMonthBetweenDate(feeDto.getStartTime(), feeDto.getEndTime());
        //double maxMonth = Math.ceil(computeFeeSMOImpl.dayCompare(feeDto.getStartTime(), feeDto.getEndTime()));
        if (months == null || months.size() <= 0) {
            return feePrice;
        }
        BigDecimal feePriceDec = new BigDecimal(feePrice).divide(new BigDecimal(maxMonth), 2, BigDecimal.ROUND_HALF_UP);
        BigDecimal feePriceDec = new BigDecimal(feePrice).divide(new BigDecimal(months.size()), 4, BigDecimal.ROUND_HALF_UP);
        feePrice = feePriceDec.doubleValue();
        return feePrice;
    }
    public Double getReceivableAmount(List<FeeDetailDto> feeDetailDtos, Double feePrice, Date curDate, FeeDto feeDto) {
        FeeDetailDto feeDetailDto = getCurFeeDetail(feeDetailDtos, curDate);
        if (feeDetailDto == null && curDate.getTime() < feeDto.getEndTime().getTime()) {
    public Double getReceivableAmount(List<FeeDetailDto> feeDetailDtos, Map<String, MonthFeeDetailDto> monthFeeDetailDtos, Double feePrice, Date curDate, FeeDto feeDto) {
        MonthFeeDetailDto monthFeeDetailDto = getCurMonthFeeDetail(monthFeeDetailDtos, curDate);
        if (monthFeeDetailDto == null && curDate.getTime() < feeDto.getEndTime().getTime()) {
            return 0.00;
        }
        return feePrice;
    }
    @Override
    public Double getReceivedAmount(List<FeeDetailDto> feeDetailDtos, Double feePrice, Date curDate, FeeDto feeDto) {
        //todo 这种情况下应该 实收为0
        if (curDate.getTime() >= feeDto.getEndTime().getTime()) {
            return 0.00;
    public Double getReceivedAmount(List<FeeDetailDto> feeDetailDtos, Map<String, MonthFeeDetailDto> monthFeeDetailDtos, Double feePrice, Date curDate, FeeDto feeDto) {
        MonthFeeDetailDto monthFeeDetailDto = getCurMonthFeeDetail(monthFeeDetailDtos, curDate);
        if (monthFeeDetailDto == null) {
            return 0.0;
        }
        //todo 如果 fee 为空
        if (feeDetailDtos == null) {
            return feePrice;
        }
        FeeDetailDto feeDetailDto = getCurFeeDetail(feeDetailDtos, curDate);
        if (feeDetailDto == null && curDate.getTime() < feeDto.getEndTime().getTime()) {
            return 0.00;
        }
        if (feeDetailDto == null) {
            return feePrice;
        }
        double maxMonth = Math.ceil(computeFeeSMOImpl.dayCompare(feeDetailDto.getStartTime(), feeDetailDto.getEndTime()));
        if (maxMonth < 1) {
            return Double.parseDouble(feeDetailDto.getReceivedAmount());
        }
        BigDecimal totalRecDec = new BigDecimal(feeDetailDto.getReceivedAmount());
        //每月平均值
        BigDecimal priRecDec = totalRecDec.divide(new BigDecimal(maxMonth), 4, BigDecimal.ROUND_HALF_UP);
        return priRecDec.doubleValue();
        return monthFeeDetailDto.getReceivedAmount();
    }
    @Override
@@ -143,6 +117,7 @@
        return null;
    }
    /**
     * 获取当前缴费记录
     *
@@ -157,7 +132,7 @@
        List<FeeDetailDto> tFeeDetailDtos = new ArrayList<>();
        for (FeeDetailDto feeDetailDto : feeDetailDtos) {
            if (feeDetailDto.getStartTime().getTime() <= curDate.getTime() && feeDetailDto.getEndTime().getTime() > curDate.getTime()) {
                tFeeDetailDtos.add(BeanConvertUtil.covertBean(feeDetailDto,FeeDetailDto.class));
                tFeeDetailDtos.add(BeanConvertUtil.covertBean(feeDetailDto, FeeDetailDto.class));
            }
        }
@@ -179,4 +154,85 @@
    }
    @Override
    public Map<String, MonthFeeDetailDto> analysisMonthFeeDetail(List<FeeDetailDto> feeDetailDtos) {
        if (feeDetailDtos == null || feeDetailDtos.size() < 1) {
            return null;
        }
        Map<String, MonthFeeDetailDto> monthFeeDetailDtos = new HashMap<>();
        for (FeeDetailDto feeDetailDto : feeDetailDtos) {
            //计算两个日期包含的月份
            List<String> months = DateUtil.getMonthBetweenDate(feeDetailDto.getStartTime(), feeDetailDto.getEndTime());
            if (months == null || months.size() < 1) {
                putReceivedAmountToMonthFeeDetailDtos(monthFeeDetailDtos,
                        DateUtil.getFormatTimeString(feeDetailDto.getStartTime(), DateUtil.DATE_FORMATE_STRING_M),
                        Double.parseDouble(feeDetailDto.getReceivedAmount()),
                        feeDetailDto);
                continue;
            }
            BigDecimal totalRecDec = new BigDecimal(feeDetailDto.getReceivedAmount());
            //每月平均值
            BigDecimal priRecDec = totalRecDec.divide(new BigDecimal(months.size()), 4, BigDecimal.ROUND_HALF_UP);
            for (String month : months) {
                putReceivedAmountToMonthFeeDetailDtos(monthFeeDetailDtos,
                        month,
                        priRecDec.doubleValue(),
                        feeDetailDto);
            }
        }
        return null;
    }
    /**
     * 月份存放起来
     *
     * @param monthFeeDetailDtos
     * @param month
     * @param receivedAmount
     */
    private void putReceivedAmountToMonthFeeDetailDtos(Map<String, MonthFeeDetailDto> monthFeeDetailDtos,
                                                       String month,
                                                       double receivedAmount,
                                                       FeeDetailDto feeDetailDto) {
        if (!monthFeeDetailDtos.containsKey(month)) {
            monthFeeDetailDtos.put(month, new MonthFeeDetailDto(receivedAmount, feeDetailDto));
            return;
        }
        MonthFeeDetailDto monthFeeDetailDto = monthFeeDetailDtos.get(month);
        BigDecimal recDec = new BigDecimal(monthFeeDetailDto.getReceivedAmount()).add(new BigDecimal(receivedAmount)).setScale(4, BigDecimal.ROUND_HALF_UP);
        monthFeeDetailDto.setReceivedAmount(recDec.doubleValue());
        monthFeeDetailDto.getFeeDetailDtos().add(feeDetailDto);
        monthFeeDetailDtos.put(month, monthFeeDetailDto);
    }
    /**
     * 月离散数据
     *
     * @param monthFeeDetailDtos
     * @param curDate
     * @return
     */
    private MonthFeeDetailDto getCurMonthFeeDetail(Map<String, MonthFeeDetailDto> monthFeeDetailDtos, Date curDate) {
        String month = DateUtil.getFormatTimeString(curDate, DateUtil.DATE_FORMATE_STRING_M);
        if (monthFeeDetailDtos == null) {
            return null;
        }
        if (!monthFeeDetailDtos.containsKey(month)) {
            return null;
        }
        MonthFeeDetailDto monthFeeDetailDto = monthFeeDetailDtos.get(month);
        return monthFeeDetailDto;
    }
}