From f1627e52fa6e9fea7b34731beaa55dc0222344da Mon Sep 17 00:00:00 2001
From: java110 <928255095@qq.com>
Date: 星期四, 25 二月 2021 18:19:49 +0800
Subject: [PATCH] 优化代码

---
 service-report/src/main/java/com/java110/report/smo/impl/GeneratorFeeMonthStatisticsInnerServiceSMOImpl.java |   85 ++++++++++++++++++++++++++++++------------
 1 files changed, 61 insertions(+), 24 deletions(-)

diff --git a/service-report/src/main/java/com/java110/report/smo/impl/GeneratorFeeMonthStatisticsInnerServiceSMOImpl.java b/service-report/src/main/java/com/java110/report/smo/impl/GeneratorFeeMonthStatisticsInnerServiceSMOImpl.java
index 22034ce..1880c58 100644
--- a/service-report/src/main/java/com/java110/report/smo/impl/GeneratorFeeMonthStatisticsInnerServiceSMOImpl.java
+++ b/service-report/src/main/java/com/java110/report/smo/impl/GeneratorFeeMonthStatisticsInnerServiceSMOImpl.java
@@ -17,7 +17,11 @@
 import com.java110.report.dao.IReportCommunityServiceDao;
 import com.java110.report.dao.IReportFeeMonthStatisticsServiceDao;
 import com.java110.report.dao.IReportFeeServiceDao;
-import com.java110.utils.util.*;
+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 org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -26,7 +30,11 @@
 import org.springframework.web.bind.annotation.RestController;
 
 import java.math.BigDecimal;
-import java.util.*;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
 
 /**
  * @ClassName GeneratorFeeMonthStatisticsInnerServiceSMOImpl
@@ -224,15 +232,17 @@
                 && receivedAmount == 0) {
             return;
         }
-        double receivableAmount = getReceivableAmountByCar(tmpReportFeeDto, null, tmpReportCarDto); //搴旀敹
-
-        dealBeforeUploadCarFee(tmpReportFeeDto, tmpReportCarDto);
-        double oweAmount = getOweAmount(tmpReportFeeDto, receivableAmount, receivedAmount); //娆犺垂
         FeeDto feeDto = BeanConvertUtil.covertBean(tmpReportFeeDto, FeeDto.class);
         OwnerCarDto ownerCarDto = BeanConvertUtil.covertBean(tmpReportCarDto, OwnerCarDto.class);
         Map<String, Object> targetEndDateAndOweMonth = computeFeeSMOImpl.getTargetEndDateAndOweMonth(feeDto, ownerCarDto);
 
         Date targetEndDate = (Date) targetEndDateAndOweMonth.get("targetEndDate");
+        tmpReportFeeDto.setDeadlineTime(targetEndDate);
+        double oweAmount = getOweAmountByCar(tmpReportFeeDto, null, tmpReportCarDto); //搴旀敹
+
+        dealBeforeUploadCarFee(tmpReportFeeDto, tmpReportCarDto);
+        double receivableAmount = getReceivableAmount(tmpReportFeeDto,receivedAmount); //娆犺垂
+
 
         ReportFeeMonthStatisticsPo reportFeeMonthStatisticsPo = new ReportFeeMonthStatisticsPo();
         reportFeeMonthStatisticsPo.setDeadlineTime(DateUtil.getFormatTimeString(targetEndDate, DateUtil.DATE_FORMATE_STRING_A));
@@ -258,7 +268,7 @@
             reportFeeMonthStatisticsPo.setObjId(tmpReportCarDto.getCarId());
             reportFeeMonthStatisticsPo.setObjType(FeeDto.PAYER_OBJ_TYPE_CAR);
             reportFeeMonthStatisticsPo.setFeeName(tmpReportFeeDto.getFeeName());
-            reportFeeMonthStatisticsPo.setObjName(tmpReportCarDto.getCarNum() + "(" + tmpReportCarDto.getAreaNum() + "鍋滆溅鍦�" + tmpReportCarDto.getNum() + "杞︿綅");
+            reportFeeMonthStatisticsPo.setObjName(tmpReportCarDto.getCarNum() + "(" + tmpReportCarDto.getAreaNum() + "鍋滆溅鍦�" + tmpReportCarDto.getNum() + "杞︿綅)");
             reportFeeMonthStatisticsPo.setUpdateTime(DateUtil.getNow(DateUtil.DATE_FORMATE_STRING_A));
             reportFeeMonthStatisticsServiceDaoImpl.saveReportFeeMonthStatisticsInfo(BeanConvertUtil.beanCovertMap(reportFeeMonthStatisticsPo));
         }
@@ -314,9 +324,14 @@
                 reportFeeMonthStatisticsServiceDaoImpl.getReportFeeMonthStatisticsInfo(BeanConvertUtil.beanCovertMap(reportFeeMonthStatisticsDto)),
                 ReportFeeMonthStatisticsDto.class);
         //涓婁釜鏈堟湁鏁版嵁 涓嶅鐞�
-        if (statistics != null && statistics.size() > 1) {
+        if (statistics != null && statistics.size() > 0) {
             return;
         }
+
+        if (tmpReportFeeDto.getDeadlineTime().getTime() < curMonthDate.getTime().getTime()) {
+            curMonthDate.setTime(tmpReportFeeDto.getDeadlineTime());
+        }
+
         double receivableAmount = 0.0;
         if (FeeDto.FEE_FLAG_ONCE.equals(tmpReportFeeDto.getFeeFlag())) {
             receivableAmount = tmpReportFeeDto.getFeePrice();
@@ -343,7 +358,7 @@
         reportFeeMonthStatisticsPo.setObjId(tmpReportCarDto.getCarId());
         reportFeeMonthStatisticsPo.setObjType(FeeDto.PAYER_OBJ_TYPE_CAR);
         reportFeeMonthStatisticsPo.setFeeName(tmpReportFeeDto.getFeeName());
-        reportFeeMonthStatisticsPo.setObjName(tmpReportCarDto.getCarNum() + "(" + tmpReportCarDto.getAreaNum() + "鍋滆溅鍦�" + tmpReportCarDto.getNum() + "杞︿綅");
+        reportFeeMonthStatisticsPo.setObjName(tmpReportCarDto.getCarNum() + "(" + tmpReportCarDto.getAreaNum() + "鍋滆溅鍦�" + tmpReportCarDto.getNum() + "杞︿綅)");
         reportFeeMonthStatisticsPo.setUpdateTime(DateUtil.getNow(DateUtil.DATE_FORMATE_STRING_A));
         reportFeeMonthStatisticsServiceDaoImpl.saveReportFeeMonthStatisticsInfo(BeanConvertUtil.beanCovertMap(reportFeeMonthStatisticsPo));
 
@@ -398,16 +413,18 @@
                 && receivedAmount == 0) {
             return;
         }
-        double receivableAmount = getReceivableAmount(tmpReportFeeDto, reportRoomDto, null); //搴旀敹
-
-        //瑙e喅涓婄嚎鏃� 涔嬪墠娆犺垂娌℃湁鍒峰叆瀵艰嚧璐圭敤閲戦瀵逛笉涓婇棶棰樺鐞�
-        dealBeforeUploadRoomFee(reportRoomDto, tmpReportFeeDto, receivableAmount);
-
-        double oweAmount = getOweAmount(tmpReportFeeDto, receivableAmount, receivedAmount); //娆犺垂
         FeeDto feeDto = BeanConvertUtil.covertBean(tmpReportFeeDto, FeeDto.class);
         Map<String, Object> targetEndDateAndOweMonth = computeFeeSMOImpl.getTargetEndDateAndOweMonth(feeDto, null);
 
         Date targetEndDate = (Date) targetEndDateAndOweMonth.get("targetEndDate");
+        tmpReportFeeDto.setDeadlineTime(targetEndDate);
+        double oweAmount = getOweAmount(tmpReportFeeDto, reportRoomDto, null); //娆犺垂
+
+        double receivableAmount = getReceivableAmount(tmpReportFeeDto, receivedAmount); //搴旀敹
+        //瑙e喅涓婄嚎鏃� 涔嬪墠娆犺垂娌℃湁鍒峰叆瀵艰嚧璐圭敤閲戦瀵逛笉涓婇棶棰樺鐞�
+        dealBeforeUploadRoomFee(reportRoomDto, tmpReportFeeDto, receivableAmount);
+
+
 
         ReportFeeMonthStatisticsPo reportFeeMonthStatisticsPo = new ReportFeeMonthStatisticsPo();
         reportFeeMonthStatisticsPo.setDeadlineTime(DateUtil.getFormatTimeString(targetEndDate, DateUtil.DATE_FORMATE_STRING_A));
@@ -491,6 +508,10 @@
             return;
         }
 
+        if (tmpReportFeeDto.getDeadlineTime().getTime() < curMonthDate.getTime().getTime()) {
+            curMonthDate.setTime(tmpReportFeeDto.getDeadlineTime());
+        }
+
         ReportFeeMonthStatisticsDto reportFeeMonthStatisticsDto = new ReportFeeMonthStatisticsDto();
         reportFeeMonthStatisticsDto.setCommunityId(reportRoomDto.getCommunityId());
         reportFeeMonthStatisticsDto.setConfigId(tmpReportFeeDto.getConfigId());
@@ -503,7 +524,7 @@
                 reportFeeMonthStatisticsServiceDaoImpl.getReportFeeMonthStatisticsInfo(BeanConvertUtil.beanCovertMap(reportFeeMonthStatisticsDto)),
                 ReportFeeMonthStatisticsDto.class);
         //涓婁釜鏈堟湁鏁版嵁 涓嶅鐞�
-        if (statistics != null && statistics.size() > 1) {
+        if (statistics != null && statistics.size() > 0) {
             return;
         }
 
@@ -546,14 +567,16 @@
      * 褰撴湀娆犺垂
      *
      * @param tmpReportFeeDto
-     * @param receivableAmount
      * @param receivedAmount
      * @return
      */
-    private double getOweAmount(ReportFeeDto tmpReportFeeDto, double receivableAmount, double receivedAmount) {
+    private double getReceivableAmount(ReportFeeDto tmpReportFeeDto, double receivedAmount) {
 
-
-        return receivableAmount;
+        //涓�娆℃�ц垂鐢� 闄や互鏈堜唤 骞冲潎
+        if (FeeDto.FEE_FLAG_ONCE.equals(tmpReportFeeDto.getFeeFlag())) {
+            return computeOnceFee(tmpReportFeeDto);
+        }
+        return tmpReportFeeDto.getFeePrice();
 
     }
 
@@ -579,7 +602,7 @@
      * @param tmpReportFeeDto
      * @return
      */
-    private double getReceivableAmountByCar(ReportFeeDto tmpReportFeeDto, ReportRoomDto reportRoomDto, ReportCarDto reportCarDto) {
+    private double getOweAmountByCar(ReportFeeDto tmpReportFeeDto, ReportRoomDto reportRoomDto, ReportCarDto reportCarDto) {
 
         double feePrice = computeFeeSMOImpl.getReportFeePrice(tmpReportFeeDto, reportRoomDto, reportCarDto);
         tmpReportFeeDto.setFeePrice(feePrice);
@@ -590,7 +613,7 @@
         }
 
         if (FeeDto.FEE_FLAG_ONCE.equals(tmpReportFeeDto.getFeeFlag())) {
-            return feePrice;
+            return computeOnceFee(tmpReportFeeDto);
         }
         OwnerCarDto ownerCarDto = new OwnerCarDto();
         ownerCarDto.setCommunityId(tmpReportFeeDto.getCommunityId());
@@ -627,13 +650,27 @@
         return 0.0;
     }
 
+    private double computeOnceFee(ReportFeeDto tmpReportFeeDto) {
+        Date nowTime = DateUtil.getCurrentDate();
+        if (tmpReportFeeDto.getEndTime().getTime() > nowTime.getTime()
+                || tmpReportFeeDto.getDeadlineTime().getTime() < nowTime.getTime()) {
+            return 0.0;
+        }
+        double month = computeFeeSMOImpl.dayCompare(tmpReportFeeDto.getDeadlineTime(), tmpReportFeeDto.getEndTime());
+        month = Math.ceil(month);
+
+        BigDecimal feePriceDec = new BigDecimal(tmpReportFeeDto.getFeePrice());
+        double money = feePriceDec.divide(new BigDecimal(month)).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue();
+        return money;
+    }
+
     /**
      * 鑾峰彇褰撴湀搴旀敹
      *
      * @param tmpReportFeeDto
      * @return
      */
-    private double getReceivableAmount(ReportFeeDto tmpReportFeeDto, ReportRoomDto reportRoomDto, ReportCarDto reportCarDto) {
+    private double getOweAmount(ReportFeeDto tmpReportFeeDto, ReportRoomDto reportRoomDto, ReportCarDto reportCarDto) {
 
         double feePrice = computeFeeSMOImpl.getReportFeePrice(tmpReportFeeDto, reportRoomDto, reportCarDto);
         tmpReportFeeDto.setFeePrice(feePrice);
@@ -644,7 +681,7 @@
         }
 
         if (FeeDto.FEE_FLAG_ONCE.equals(tmpReportFeeDto.getFeeFlag())) {
-            return feePrice;
+            return computeOnceFee(tmpReportFeeDto);
         }
 
         //1.0 璐圭敤鍒版湡鏃堕棿鍜岃垂鐢ㄧ粨鏉熸椂闂� 閮戒笉鍦ㄥ綋鏈�

--
Gitblit v1.8.0