Browse Source

代码退回到报表统计误差最小时

Your Name 2 years ago
parent
commit
7d6ef391e9

+ 3 - 8
service-fee/src/main/java/com/java110/fee/feeMonth/IPayFeeMonthHelp.java

@@ -16,7 +16,7 @@ public interface IPayFeeMonthHelp {
     Double getMonthFeePrice(FeeDto feeDto);
 
 
-    Double getReceivableAmount(List<FeeDetailDto> feeDetailDtos,Map<String, MonthFeeDetailDto> monthFeeDetailDtos, Double feePrice, Date curDate, FeeDto feeDto);
+    Double getReceivableAmount(List<FeeDetailDto> feeDetailDtos, Double feePrice, Date curDate, FeeDto feeDto);
 
     /**
      * 计算实收
@@ -24,7 +24,7 @@ public interface IPayFeeMonthHelp {
      * @param feePrice
      * @return
      */
-    Double getReceivedAmount(List<FeeDetailDto> feeDetailDtos,Map<String ,MonthFeeDetailDto> monthFeeDetailDtos, Double feePrice, Date curDate, FeeDto feeDto);
+    Double getReceivedAmount(List<FeeDetailDto> feeDetailDtos, Double feePrice, Date curDate, FeeDto feeDto);
 
     Double getDiscountAmount(Double feePrice, double receivedAmount, Date curDate, FeeDto feeDto);
 
@@ -44,10 +44,5 @@ public interface IPayFeeMonthHelp {
      */
     String getFeeFeeTime(List<FeeDetailDto> feeDetailDtos, String detailId);
 
-    /**
-     * 缴费记录转换为月缴费记录,金额 除以 缴费时间段内所包含的月个数
-     * @param feeDetailDtos
-     * @return
-     */
-    Map<String ,MonthFeeDetailDto> analysisMonthFeeDetail(List<FeeDetailDto> feeDetailDtos);
+
 }

+ 42 - 105
service-fee/src/main/java/com/java110/fee/feeMonth/PayFeeMonthHelp.java

@@ -4,7 +4,6 @@ import com.java110.core.smo.IComputeFeeSMO;
 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;
@@ -14,7 +13,10 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
 import java.math.BigDecimal;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+import java.util.Map;
 
 @Service
 public class PayFeeMonthHelp implements IPayFeeMonthHelp {
@@ -51,34 +53,58 @@ public class PayFeeMonthHelp implements IPayFeeMonthHelp {
         if (!FeeDto.FEE_FLAG_ONCE.equals(feeDto.getPayerObjType())) {
             return feePrice;
         }
-        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) {
+        double maxMonth = Math.ceil(computeFeeSMOImpl.dayCompare(feeDto.getStartTime(), feeDto.getEndTime()));
+        if (maxMonth <= 0) {
             return feePrice;
 
         }
-        BigDecimal feePriceDec = new BigDecimal(feePrice).divide(new BigDecimal(months.size()), 4, BigDecimal.ROUND_HALF_UP);
+        BigDecimal feePriceDec = new BigDecimal(feePrice).divide(new BigDecimal(maxMonth), 2, BigDecimal.ROUND_HALF_UP);
         feePrice = feePriceDec.doubleValue();
         return feePrice;
     }
 
 
-    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()) {
+    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()) {
             return 0.00;
         }
+
         return feePrice;
     }
 
-
     @Override
-    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;
+    public Double getReceivedAmount(List<FeeDetailDto> feeDetailDtos, Double feePrice, Date curDate, FeeDto feeDto) {
+        //todo 这种情况下应该 实收为0
+        if (curDate.getTime() >= feeDto.getEndTime().getTime()) {
+            return 0.00;
+        }
+        //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());
         }
-        return monthFeeDetailDto.getReceivedAmount();
+
+        BigDecimal totalRecDec = new BigDecimal(feeDetailDto.getReceivedAmount());
+        //每月平均值
+        BigDecimal priRecDec = totalRecDec.divide(new BigDecimal(maxMonth), 4, BigDecimal.ROUND_HALF_UP);
+
+        return priRecDec.doubleValue();
     }
 
     @Override
@@ -117,7 +143,6 @@ public class PayFeeMonthHelp implements IPayFeeMonthHelp {
         return null;
     }
 
-
     /**
      * 获取当前缴费记录
      *
@@ -132,7 +157,7 @@ public class PayFeeMonthHelp implements IPayFeeMonthHelp {
         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));
             }
         }
 
@@ -154,92 +179,4 @@ public class PayFeeMonthHelp implements IPayFeeMonthHelp {
     }
 
 
-    @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) {
-            Date endTime =  feeDetailDto.getEndTime();
-            Calendar calendar = Calendar.getInstance();
-            calendar.setTime(endTime);
-            calendar.add(Calendar.DAY_OF_MONTH,-1);
-            if(feeDetailDto.getStartTime().getTime()< calendar.getTime().getTime()){
-                endTime = calendar.getTime();
-            }
-            //计算两个日期包含的月份
-            List<String> months = DateUtil.getMonthBetweenDate(feeDetailDto.getStartTime(), endTime);
-
-            if (months == null || months.size() < 1) {
-                putReceivedAmountToMonthFeeDetailDtos(monthFeeDetailDtos,
-                        DateUtil.getFormatTimeString(feeDetailDto.getStartTime(), DateUtil.DATE_FORMATE_STRING_Q),
-                        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 monthFeeDetailDtos;
-    }
-
-
-    /**
-     * 月份存放起来
-     *
-     * @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_Q);
-        if (monthFeeDetailDtos == null) {
-            return null;
-        }
-        if (!monthFeeDetailDtos.containsKey(month)) {
-            return null;
-        }
-        MonthFeeDetailDto monthFeeDetailDto = monthFeeDetailDtos.get(month);
-        return monthFeeDetailDto;
-    }
-
-
 }

+ 10 - 38
service-fee/src/main/java/com/java110/fee/feeMonth/PayFeeMonthImpl.java

@@ -6,7 +6,6 @@ import com.java110.core.log.LoggerFactory;
 import com.java110.core.smo.IComputeFeeSMO;
 import com.java110.dto.fee.FeeDetailDto;
 import com.java110.dto.fee.FeeDto;
-import com.java110.dto.fee.MonthFeeDetailDto;
 import com.java110.dto.payFeeDetailMonth.PayFeeDetailMonthDto;
 import com.java110.dto.payFeeDetailMonth.PayFeeMonthOwnerDto;
 import com.java110.intf.fee.*;
@@ -100,14 +99,9 @@ public class PayFeeMonthImpl implements IPayFeeMonth {
         if (payFeeDetailMonthDtos == null || payFeeDetailMonthDtos.size() < 1) {
             startTime = feeDto.getStartTime();
         } else {
-
-            //todo 删除最大月 从最大月开始离散,主要担心缴费时间不是1号导致 最大月收入不对
-            PayFeeDetailMonthPo payFeeDetailMonthPo = new PayFeeDetailMonthPo();
-            payFeeDetailMonthPo.setMonthId(payFeeDetailMonthDtos.get(0).getMonthId());
-            payFeeDetailMonthInnerServiceSMOImpl.deletePayFeeDetailMonth(payFeeDetailMonthPo);
             Calendar calendar = Calendar.getInstance();
             calendar.setTime(DateUtil.getDateFromStringA(payFeeDetailMonthDtos.get(0).getCurMonthTime()));
-            //calendar.add(Calendar.MONTH, 1);
+            calendar.add(Calendar.MONTH, 1);
             startTime = calendar.getTime();
         }
 
@@ -117,16 +111,9 @@ public class PayFeeMonthImpl implements IPayFeeMonth {
     }
 
     private void doGeneratorTimeMonthData(FeeDto feeDto, PayFeeMonthOwnerDto payFeeMonthOwnerDto, Double feePrice, Date startTime, Date endTime) {
-       // double maxMonth = Math.ceil(computeFeeSMOImpl.dayCompare(startTime, endTime));
-        Calendar calendar = Calendar.getInstance();
-        calendar.setTime(endTime);
-        calendar.add(Calendar.DAY_OF_MONTH,-1);
-        if(startTime.getTime()< calendar.getTime().getTime()){
-            endTime = calendar.getTime();
-        }
-        List<String> months = DateUtil.getMonthBetweenDate(startTime,endTime);
+        double maxMonth = Math.ceil(computeFeeSMOImpl.dayCompare(startTime, endTime));
 
-        if (months == null || months.size() < 1) {
+        if (maxMonth < 1) {
             return;
         }
         //todo 查询 缴费明细
@@ -136,39 +123,28 @@ public class PayFeeMonthImpl implements IPayFeeMonth {
         feeDetailDto.setStates(new String[]{FeeDetailDto.STATE_NORMAL,FeeDetailDto.STATE_RETURNING});
         List<FeeDetailDto> feeDetailDtos = feeDetailInnerServiceSMOImpl.queryFeeDetails(feeDetailDto);
 
-
-        //todo 将缴费记录转换为月的方式
-        Map<String ,MonthFeeDetailDto> monthFeeDetailDtos = payFeeMonthHelp.analysisMonthFeeDetail(feeDetailDtos);
-
         //todo 生成 月离散数据
         PayFeeDetailMonthPo tmpPayFeeDetailMonthPo;
         List<PayFeeDetailMonthPo> payFeeDetailMonthPos = new ArrayList<>();
         double receivableAmount = 0.0;
-        int detailYear = 0;
-        int detailMonth = 0;
-        for (String month:months) {
-            detailYear = Integer.parseInt(month.split("-")[0]);
-            detailMonth = Integer.parseInt(month.split("-")[1]);
-
-            calendar = Calendar.getInstance();
+        for (int month = 0; month < maxMonth; month++) {
+            Calendar calendar = Calendar.getInstance();
             calendar.setTime(startTime);
-            calendar.set(Calendar.YEAR, detailYear);
-            calendar.set(Calendar.MONTH, detailMonth-1);
-
+            calendar.add(Calendar.MONTH, month);
             //calendar.set(Calendar.DAY_OF_MONTH, 1);
             tmpPayFeeDetailMonthPo = new PayFeeDetailMonthPo();
             tmpPayFeeDetailMonthPo.setFeeId(feeDto.getFeeId());
             tmpPayFeeDetailMonthPo.setCommunityId(feeDto.getCommunityId());
             tmpPayFeeDetailMonthPo.setDetailId(payFeeMonthHelp.getFeeDetailId(feeDetailDtos, calendar.getTime()));
-            tmpPayFeeDetailMonthPo.setDetailYear(detailYear + "");
-            tmpPayFeeDetailMonthPo.setDetailMonth(detailMonth + "");
-            receivableAmount = payFeeMonthHelp.getReceivableAmount(feeDetailDtos,monthFeeDetailDtos, feePrice, calendar.getTime(), feeDto);
+            tmpPayFeeDetailMonthPo.setDetailYear(calendar.get(Calendar.YEAR) + "");
+            tmpPayFeeDetailMonthPo.setDetailMonth((calendar.get(Calendar.MONTH) + 1) + "");
+            receivableAmount = payFeeMonthHelp.getReceivableAmount(feeDetailDtos, feePrice, calendar.getTime(), feeDto);
             //todo 应收小于等于0 不统计
             if(receivableAmount <=0){
                 continue;
             }
             tmpPayFeeDetailMonthPo.setReceivableAmount( receivableAmount + "");
-            tmpPayFeeDetailMonthPo.setReceivedAmount(payFeeMonthHelp.getReceivedAmount(feeDetailDtos,monthFeeDetailDtos, feePrice, calendar.getTime(), feeDto) + "");
+            tmpPayFeeDetailMonthPo.setReceivedAmount(payFeeMonthHelp.getReceivedAmount(feeDetailDtos, feePrice, calendar.getTime(), feeDto) + "");
             tmpPayFeeDetailMonthPo.setDiscountAmount(
                     payFeeMonthHelp.getDiscountAmount(Double.parseDouble(tmpPayFeeDetailMonthPo.getReceivableAmount()),
                             Double.parseDouble(tmpPayFeeDetailMonthPo.getReceivedAmount()),
@@ -187,10 +163,6 @@ public class PayFeeMonthImpl implements IPayFeeMonth {
             tmpPayFeeDetailMonthPo.setConfigId(feeDto.getConfigId());
             payFeeDetailMonthPos.add(tmpPayFeeDetailMonthPo);
         }
-        //todo 没有数据就返回
-        if(payFeeDetailMonthPos.size()<1){
-            return;
-        }
         payFeeDetailMonthInnerServiceSMOImpl.savePayFeeDetailMonths(payFeeDetailMonthPos);
     }