From 7003cc7e7f3d541f6b1664eebe8238fa2b8774eb Mon Sep 17 00:00:00 2001
From: wuxw <928255095@qq.com>
Date: 星期日, 13 十一月 2022 21:36:07 +0800
Subject: [PATCH] 优化 小数点位数处理

---
 service-report/src/main/java/com/java110/report/smo/impl/GeneratorFeeMonthStatisticsInnerServiceSMOImpl.java |   58 ++++++++++++++++++++++++++++++++++++----------------------
 1 files changed, 36 insertions(+), 22 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 2a261ae..df552c5 100755
--- 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
@@ -23,6 +23,7 @@
 import com.java110.report.dao.IReportCommunityServiceDao;
 import com.java110.report.dao.IReportFeeMonthStatisticsServiceDao;
 import com.java110.report.dao.IReportFeeServiceDao;
+import com.java110.utils.constant.FeeConfigConstant;
 import com.java110.utils.util.*;
 import org.slf4j.Logger;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -394,7 +395,7 @@
         } else {
             double month = computeFeeSMOImpl.dayCompare(tmpReportFeeDto.getEndTime(), curMonthDate.getTime());
             BigDecimal curDegree = new BigDecimal(month);
-            receivableAmount = curDegree.multiply(new BigDecimal(tmpReportFeeDto.getFeePrice())).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue();
+            receivableAmount = curDegree.multiply(new BigDecimal(tmpReportFeeDto.getFeePrice())).setScale(FeeConfigConstant.FEE_SCALE, BigDecimal.ROUND_HALF_EVEN).doubleValue();
         }
 
 
@@ -503,12 +504,25 @@
             reportFeeMonthStatisticsPo.setUpdateTime(DateUtil.getNow(DateUtil.DATE_FORMATE_STRING_A));
             reportFeeMonthStatisticsPo.setFeeName(StringUtil.isEmpty(tmpReportFeeDto.getImportFeeName()) ? tmpReportFeeDto.getFeeName() : tmpReportFeeDto.getImportFeeName());
             // 缂磋垂浜嗗氨寰楀埛
-            reportFeeMonthStatisticsPo.setHisOweAmount(getHisOweAmount(tmpReportFeeDto) + "");
+            reportFeeMonthStatisticsPo.setHisOweAmount(MoneyUtil.computePriceScale(getHisOweAmount(tmpReportFeeDto),
+                    tmpReportFeeDto.getScale(),
+                    Integer.parseInt(tmpReportFeeDto.getDecimalPlace())) + "");
             //鏈夊彲鑳芥槸鏈堝唴鍒涘缓鐨勮垂鐢� 姣斿鐢佃垂姘磋垂
-            reportFeeMonthStatisticsPo.setCurReceivableAmount(getCurFeeReceivableAmount(tmpReportFeeDto) + "");
-            reportFeeMonthStatisticsPo.setCurReceivedAmount(getReceivedAmount(tmpReportFeeDto, 1) + "");
-            reportFeeMonthStatisticsPo.setHisOweReceivedAmount(getReceivedAmount(tmpReportFeeDto, 2) + "");
-            reportFeeMonthStatisticsPo.setPreReceivedAmount(getReceivedAmount(tmpReportFeeDto, 3) + "");
+            reportFeeMonthStatisticsPo.setCurReceivableAmount(
+                    MoneyUtil.computePriceScale(getCurFeeReceivableAmount(tmpReportFeeDto),
+                            tmpReportFeeDto.getScale(),
+                            Integer.parseInt(tmpReportFeeDto.getDecimalPlace())) + "");
+            reportFeeMonthStatisticsPo.setCurReceivedAmount(
+                    MoneyUtil.computePriceScale(getReceivedAmount(tmpReportFeeDto, 1),
+                            tmpReportFeeDto.getScale(),
+                            Integer.parseInt(tmpReportFeeDto.getDecimalPlace())) + "");
+            reportFeeMonthStatisticsPo.setHisOweReceivedAmount(
+                    MoneyUtil.computePriceScale(getReceivedAmount(tmpReportFeeDto, 2),
+                            tmpReportFeeDto.getScale(),
+                            Integer.parseInt(tmpReportFeeDto.getDecimalPlace())) + "");
+            reportFeeMonthStatisticsPo.setPreReceivedAmount(MoneyUtil.computePriceScale(getReceivedAmount(tmpReportFeeDto, 3),
+                    tmpReportFeeDto.getScale(),
+                    Integer.parseInt(tmpReportFeeDto.getDecimalPlace())) + "");
             /*if (!StringUtil.isEmpty(statistic.getObjType()) && statistic.getObjType().equals("3333")) { //鎴垮眿
                 if (!StringUtil.isEmpty(statistic.getObjId())) {
                     //鑾峰彇浠樿垂瀵硅薄ID
@@ -592,13 +606,13 @@
         if (!FeeConfigDto.FEE_TYPE_CD_METER.equals(tmpReportFeeDto.getFeeTypeCd())
                 && !FeeConfigDto.FEE_TYPE_CD_WATER.equals(tmpReportFeeDto.getFeeTypeCd())
                 && !FeeConfigDto.FEE_TYPE_CD_GAS.equals(tmpReportFeeDto.getFeeTypeCd())
-        ) {
+                ) {
             return;
         }
         //鏍规嵁璐圭敤寮�濮嬫椂闂� 璁$畻鏈堜唤
         Date endTime = tmpReportFeeDto.getEndTime();
         //鍘婚櫎 0 鍥犱负琛ㄩ噷鐨勬湀浠芥槸娌℃湁闆�
-        String curMonth = Integer.parseInt(DateUtil.getFormatTimeString(endTime, "MM"))+"";
+        String curMonth = Integer.parseInt(DateUtil.getFormatTimeString(endTime, "MM")) + "";
         String curYear = DateUtil.getFormatTimeString(endTime, "YYYY");
         //鏌ヨ鏄惁瀛樺湪 鏁版嵁
         ReportFeeMonthStatisticsDto reportFeeMonthStatisticsDto = new ReportFeeMonthStatisticsDto();
@@ -669,15 +683,15 @@
             if (allDays == 0) { // 闃叉闄ゆ暟涓�0
                 return 0;
             }
-            BigDecimal moneyPreDay = feePriceDec.divide(new BigDecimal(allDays), 2, BigDecimal.ROUND_HALF_EVEN);
+            BigDecimal moneyPreDay = feePriceDec.divide(new BigDecimal(allDays), FeeConfigConstant.FEE_SCALE, 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();
+                return moneyPreDay.multiply(new BigDecimal(day)).setScale(FeeConfigConstant.FEE_SCALE, 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();
+            BigDecimal hisDayDec = moneyPreDay.multiply(new BigDecimal(hisDays)).setScale(FeeConfigConstant.FEE_SCALE, BigDecimal.ROUND_HALF_UP);
+            return feePriceDec.subtract(hisDayDec).setScale(FeeConfigConstant.FEE_SCALE, BigDecimal.ROUND_HALF_UP).doubleValue();
         }
 
         month = computeFeeSMOImpl.dayCompare(curDate, tmpReportFeeDto.getDeadlineTime());
@@ -685,7 +699,7 @@
             return 0;
         }
         if (month < 1) {
-            return feePriceDec.multiply(new BigDecimal(month)).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue();
+            return feePriceDec.multiply(new BigDecimal(month)).setScale(FeeConfigConstant.FEE_SCALE, BigDecimal.ROUND_HALF_EVEN).doubleValue();
         }
 
         return tmpReportFeeDto.getFeePrice();
@@ -718,11 +732,11 @@
                 return 0;
             }
             //杩欐槸姣忓ぉ鐨勯挶
-            BigDecimal moneyPreDay = feePriceDec.divide(new BigDecimal(allDays), 2, BigDecimal.ROUND_HALF_EVEN);
+            BigDecimal moneyPreDay = feePriceDec.divide(new BigDecimal(allDays), FeeConfigConstant.FEE_SCALE, BigDecimal.ROUND_HALF_EVEN);
 
             double hisDays = computeFeeSMOImpl.daysBetween(tmpReportFeeDto.getEndTime(), curDate);
 
-            return moneyPreDay.multiply(new BigDecimal(hisDays)).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
+            return moneyPreDay.multiply(new BigDecimal(hisDays)).setScale(FeeConfigConstant.FEE_SCALE, BigDecimal.ROUND_HALF_UP).doubleValue();
         }
 
         double month = 0.0;
@@ -732,7 +746,7 @@
             month = computeFeeSMOImpl.dayCompare(tmpReportFeeDto.getEndTime(), curDate);
         }
         BigDecimal curDegree = new BigDecimal(month);
-        return curDegree.multiply(feePriceDec).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue();
+        return curDegree.multiply(feePriceDec).setScale(FeeConfigConstant.FEE_SCALE, BigDecimal.ROUND_HALF_EVEN).doubleValue();
     }
 
 
@@ -785,7 +799,7 @@
         } else {
             double month = computeFeeSMOImpl.dayCompare(tmpReportFeeDto.getEndTime(), curMonthDate.getTime());
             BigDecimal curDegree = new BigDecimal(month);
-            receivableAmount = curDegree.multiply(new BigDecimal(tmpReportFeeDto.getFeePrice())).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue();
+            receivableAmount = curDegree.multiply(new BigDecimal(tmpReportFeeDto.getFeePrice())).setScale(FeeConfigConstant.FEE_SCALE, BigDecimal.ROUND_HALF_EVEN).doubleValue();
         }
         ReportFeeMonthStatisticsPo reportFeeMonthStatisticsPo = new ReportFeeMonthStatisticsPo();
         reportFeeMonthStatisticsPo.setDeadlineTime(DateUtil.getFormatTimeString(curMonthDate.getTime(), DateUtil.DATE_FORMATE_STRING_A));
@@ -923,7 +937,7 @@
             //绠楀ぉ鏁�
             double month = computeFeeSMOImpl.dayCompare(tmpReportFeeDto.getEndTime(), DateUtil.getNextMonthFirstDate());
             BigDecimal curDegree = new BigDecimal(month);
-            return curDegree.multiply(feePriceDec).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue();
+            return curDegree.multiply(feePriceDec).setScale(FeeConfigConstant.FEE_SCALE, BigDecimal.ROUND_HALF_EVEN).doubleValue();
         }
         //3.0 璐圭敤鍒版湡鏃堕棿 涓嶅湪褰撴湀锛岃垂鐢ㄧ粨鏉熸椂闂村湪褰撴湀
         if (!belongCurMonth(tmpReportFeeDto.getEndTime())
@@ -931,7 +945,7 @@
             //绠楀ぉ鏁�
             double month = computeFeeSMOImpl.dayCompare(DateUtil.getFirstDate(), maxEndDate);
             BigDecimal curDegree = new BigDecimal(month);
-            return curDegree.multiply(feePriceDec).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue();
+            return curDegree.multiply(feePriceDec).setScale(FeeConfigConstant.FEE_SCALE, BigDecimal.ROUND_HALF_EVEN).doubleValue();
         }
         return 0.0;
     }
@@ -951,7 +965,7 @@
         }
 
         BigDecimal feePriceDec = new BigDecimal(tmpReportFeeDto.getFeePrice());
-        double money = feePriceDec.divide(new BigDecimal(month), 2, BigDecimal.ROUND_HALF_EVEN).doubleValue();
+        double money = feePriceDec.divide(new BigDecimal(month), FeeConfigConstant.FEE_SCALE, BigDecimal.ROUND_HALF_EVEN).doubleValue();
         return money;
     }
 
@@ -993,7 +1007,7 @@
             //绠楀ぉ鏁�
             double month = computeFeeSMOImpl.dayCompare(tmpReportFeeDto.getEndTime(), DateUtil.getNextMonthFirstDate());
             BigDecimal curDegree = new BigDecimal(month);
-            return curDegree.multiply(feePriceDec).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue();
+            return curDegree.multiply(feePriceDec).setScale(FeeConfigConstant.FEE_SCALE, BigDecimal.ROUND_HALF_EVEN).doubleValue();
         }
         //3.0 璐圭敤鍒版湡鏃堕棿 涓嶅湪褰撴湀锛岃垂鐢ㄧ粨鏉熸椂闂村湪褰撴湀
         if (!belongCurMonth(tmpReportFeeDto.getEndTime())
@@ -1001,7 +1015,7 @@
             //绠楀ぉ鏁�
             double month = computeFeeSMOImpl.dayCompare(DateUtil.getFirstDate(), maxEndDate);
             BigDecimal curDegree = new BigDecimal(month);
-            return curDegree.multiply(feePriceDec).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue();
+            return curDegree.multiply(feePriceDec).setScale(FeeConfigConstant.FEE_SCALE, BigDecimal.ROUND_HALF_EVEN).doubleValue();
         }
         return 0.0;
     }

--
Gitblit v1.8.0