wuxw лет назад: 2
Родитель
Сommit
3c81667571

+ 70 - 11
service-fee/src/main/java/com/java110/fee/discount/impl/LateFeeByDayRule.java

@@ -27,6 +27,7 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 
 import java.math.BigDecimal;
+import java.util.Calendar;
 import java.util.Date;
 import java.util.List;
 import java.util.Map;
@@ -42,7 +43,7 @@ public class LateFeeByDayRule implements IComputeDiscount {
      */
     private static final String SPEC_RATE = "89002020980005"; // 打折率
 
-
+    private static final String SPEC_DAY = "89002020980018"; // 延迟天数
     @Autowired
     private IFeeInnerServiceSMO feeInnerServiceSMOImpl;
 
@@ -52,14 +53,18 @@ public class LateFeeByDayRule implements IComputeDiscount {
     @Override
     public ComputeDiscountDto compute(FeeDiscountDto feeDiscountDto) {
         List<FeeDiscountSpecDto> feeDiscountSpecDtos = feeDiscountDto.getFeeDiscountSpecs();
-        if (feeDiscountSpecDtos.size() < 1) {
+        if (feeDiscountSpecDtos.isEmpty()) {
             return null;
         }
         double rate = 0.0;
+        int delayDay = 1;
         for (FeeDiscountSpecDto feeDiscountSpecDto : feeDiscountSpecDtos) {
             if (SPEC_RATE.equals(feeDiscountSpecDto.getSpecId())) {
                 rate = Double.parseDouble(feeDiscountSpecDto.getSpecValue());
             }
+            if (SPEC_DAY.equals(feeDiscountSpecDto.getSpecId())) {
+                delayDay = Integer.parseInt(feeDiscountSpecDto.getSpecValue());
+            }
         }
 
         FeeDto feeDto = new FeeDto();
@@ -67,8 +72,11 @@ public class LateFeeByDayRule implements IComputeDiscount {
         feeDto.setFeeId(feeDiscountDto.getFeeId());
         List<FeeDto> feeDtos = feeInnerServiceSMOImpl.queryFees(feeDto);
 
-        Date curTime = DateUtil.getCurrentDate();
+        // Date curTime = DateUtil.getCurrentDate();
 
+        Calendar calendar = Calendar.getInstance();
+        calendar.add(Calendar.DAY_OF_MONTH, delayDay * -1);
+        Date curTime = calendar.getTime();
         Date endTime = feeDtos.get(0).getEndTime();
 
         if (endTime.getTime() > curTime.getTime()) {
@@ -82,6 +90,8 @@ public class LateFeeByDayRule implements IComputeDiscount {
             computeDiscountDto.setFeeDiscountSpecs(feeDiscountSpecDtos);
             return computeDiscountDto;
         }
+
+
         //查询费用
         int day = DateUtil.daysBetween(curTime, endTime);
 
@@ -103,7 +113,13 @@ public class LateFeeByDayRule implements IComputeDiscount {
 
         BigDecimal dayDec = new BigDecimal(day);
 
-        double discountPrice = priceDec.divide(new BigDecimal(30), 2, BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal(rate)).multiply(dayDec).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue();
+        double discountPrice = 0.0;
+        //todo 一次性计算滞纳金
+        if (FeeDto.FEE_FLAG_ONCE.equals(feeDtos.get(0).getFeeFlag())) {
+            discountPrice = priceDec.multiply(new BigDecimal(rate)).multiply(dayDec).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue();
+        } else {//todo 计算 滞纳金,
+            discountPrice = computeLateDiscountPrice(priceDec, feeDtos.get(0), curTime,rate);
+        }
 
         ComputeDiscountDto computeDiscountDto = new ComputeDiscountDto();
         computeDiscountDto.setDiscountId(feeDiscountDto.getDiscountId());
@@ -116,14 +132,57 @@ public class LateFeeByDayRule implements IComputeDiscount {
         return computeDiscountDto;
     }
 
-    public static void main(String[] args) throws Exception {
-        int day = 316;
-        double money = 0.0;
-        for (int i = 1; i< day+1;i++){
-            money += ((124.51/30 * (i-1) +money)  * 0.003);
-            System.out.println("第"+i+"天 违约金 = "+money + ",计算公式为:(124.51/30 * ("+i+"-1) + " + money +") * 0.003");
+    private  double computeLateDiscountPrice(BigDecimal priceDec, FeeDto feeDto,Date curTime,double rate) {
+
+        //todo 欠费最大结束时间
+        Date targetEndDate = computeFeeSMOImpl.getDeadlineTime(feeDto);
+        //Date targetEndDate = DateUtil.getDateFromStringB("2023-11-01");
+
+        //todo 周期开始时间
+        Date targetStartDate = getTargetStartDate(feeDto);
+
+        double allMonth = DateUtil.dayCompare(feeDto.getEndTime(), targetEndDate);
+
+        int paymentCycle = Integer.parseInt(feeDto.getPaymentCycle());
+
+        double maxCycle = Math.ceil(allMonth / paymentCycle);
+
+        int lateDay = 0;
+        BigDecimal discountPriceDec = new BigDecimal("0.00");
+        BigDecimal curCycleDiscountPriceDec = null;
+        for (int cycleIndex = 0; cycleIndex < maxCycle; cycleIndex++) {
+            //todo 计算 违约天数
+            lateDay = DateUtil.daysBetween(curTime, targetStartDate)-15;
+            curCycleDiscountPriceDec = priceDec.multiply(new BigDecimal(paymentCycle)).multiply(new BigDecimal(rate)).multiply(new BigDecimal(lateDay)).setScale(2, BigDecimal.ROUND_HALF_EVEN);
+            System.out.println(DateUtil.getFormatTimeStringB(targetStartDate)+">"+lateDay+":"+curCycleDiscountPriceDec.doubleValue());
+            discountPriceDec = discountPriceDec.add(curCycleDiscountPriceDec);
+            targetStartDate = DateUtil.stepMonth(targetStartDate,paymentCycle);
         }
 
-        System.out.println(money);
+        return discountPriceDec.doubleValue();
+    }
+
+    private static Date getTargetStartDate(FeeDto feeDto) {
+
+
+        Calendar startCal = Calendar.getInstance();
+        startCal.setTime(feeDto.getStartTime());
+        Date targetStartTime = feeDto.getStartTime();
+
+        while (startCal.getTime().before(feeDto.getEndTime())) {
+            targetStartTime = startCal.getTime();
+            startCal.add(Calendar.MONTH, Integer.parseInt(feeDto.getPaymentCycle()));
+        }
+        return targetStartTime;
+    }
+
+    public static void main(String[] args) throws Exception {
+        BigDecimal priceDec = new BigDecimal("195.78");
+        FeeDto feeDto = new FeeDto();
+        feeDto.setStartTime(DateUtil.getDateFromStringB("2020-01-01"));
+        feeDto.setEndTime(DateUtil.getDateFromStringB("2020-01-01"));
+        feeDto.setPaymentCycle("1");
+        //double discountPrice = computeLateDiscountPrice(priceDec, feeDto, DateUtil.getDateFromStringB("2023-11-01"),0.0005);
+        //System.out.println("discountPrice = "+discountPrice);
     }
 }

+ 13 - 3
service-fee/src/main/java/com/java110/fee/discount/impl/LateFeeZaoZhuangPropertyByDayRule.java

@@ -27,6 +27,7 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 
 import java.math.BigDecimal;
+import java.util.Calendar;
 import java.util.Date;
 import java.util.List;
 import java.util.Map;
@@ -45,6 +46,7 @@ public class LateFeeZaoZhuangPropertyByDayRule implements IComputeDiscount {
      */
     private static final String SPEC_RATE = "89002020980005"; // 打折率
 
+    private static final String SPEC_DAY = "89002020980018"; // 延迟天数
 
     @Autowired
     private IFeeInnerServiceSMO feeInnerServiceSMOImpl;
@@ -59,10 +61,14 @@ public class LateFeeZaoZhuangPropertyByDayRule implements IComputeDiscount {
             return null;
         }
         double rate = 0.0;
+        int delayDay = 1;
         for (FeeDiscountSpecDto feeDiscountSpecDto : feeDiscountSpecDtos) {
             if (SPEC_RATE.equals(feeDiscountSpecDto.getSpecId())) {
                 rate = Double.parseDouble(feeDiscountSpecDto.getSpecValue());
             }
+            if (SPEC_DAY.equals(feeDiscountSpecDto.getSpecId())) {
+                delayDay = Integer.parseInt(feeDiscountSpecDto.getSpecValue());
+            }
         }
 
         FeeDto feeDto = new FeeDto();
@@ -70,7 +76,11 @@ public class LateFeeZaoZhuangPropertyByDayRule implements IComputeDiscount {
         feeDto.setFeeId(feeDiscountDto.getFeeId());
         List<FeeDto> feeDtos = feeInnerServiceSMOImpl.queryFees(feeDto);
 
-        Date curTime = DateUtil.getCurrentDate();
+        //Date curTime = DateUtil.getCurrentDate();
+
+        Calendar calendar = Calendar.getInstance();
+        calendar.add(Calendar.DAY_OF_MONTH, delayDay * -1);
+        Date curTime = calendar.getTime();
 
         Date endTime = feeDtos.get(0).getEndTime();
 
@@ -138,14 +148,14 @@ public class LateFeeZaoZhuangPropertyByDayRule implements IComputeDiscount {
         BigDecimal yearFee = null;
         BigDecimal monthFee = null;
         BigDecimal dayMoney = null;
-        BigDecimal priceDec = new BigDecimal(118.24);
+        BigDecimal priceDec = new BigDecimal(300);
         for (int i = 1; i < day + 1; i++) {
             yearFee = priceDec.multiply(new BigDecimal(12));
             monthFee = yearFee.divide(new BigDecimal(365), 2, BigDecimal.ROUND_HALF_UP);
             dayMoney = monthFee.multiply(new BigDecimal(i - 1));
             dayMoney = dayMoney.multiply(new BigDecimal(0.003));
             money = money.add(dayMoney).setScale(2, BigDecimal.ROUND_HALF_EVEN);
-            System.out.println("第" + i + "天 违约金 = " + money.doubleValue() + ",计算公式为:(124.51/30 * (" + i + "-1) + " + money.doubleValue() + ") * 0.003");
+            System.out.println("第" + i + "天 违约金 = " + money.doubleValue() + ",计算公式为:(300/30 * (" + i + "-1) + " + money.doubleValue() + ") * 0.003");
         }
 
         System.out.println(money);