From 7800f6c9e8ec485c2add2549b4ade61a5f0cea53 Mon Sep 17 00:00:00 2001
From: java110 <928255095@qq.com>
Date: 星期二, 04 七月 2023 12:49:59 +0800
Subject: [PATCH] 优化代码

---
 service-job/src/main/java/com/java110/job/export/adapt/DataReportFeeStatisticsAdapt.java |   87 +++++++++++++++++++++++++++++++++----------
 1 files changed, 66 insertions(+), 21 deletions(-)

diff --git a/service-job/src/main/java/com/java110/job/export/adapt/DataReportFeeStatisticsAdapt.java b/service-job/src/main/java/com/java110/job/export/adapt/DataReportFeeStatisticsAdapt.java
index f70bbb6..cc61e0f 100644
--- a/service-job/src/main/java/com/java110/job/export/adapt/DataReportFeeStatisticsAdapt.java
+++ b/service-job/src/main/java/com/java110/job/export/adapt/DataReportFeeStatisticsAdapt.java
@@ -21,7 +21,9 @@
 import org.springframework.stereotype.Service;
 
 import java.math.BigDecimal;
+import java.util.Calendar;
 import java.util.List;
+
 @Service("dataReportFeeStatistics")
 public class DataReportFeeStatisticsAdapt implements IExportDataAdapt {
 
@@ -120,23 +122,31 @@
         row.createCell(7).setCellValue(data.getString("hisOweReceivedRoomCount"));
         row.createCell(8).setCellValue(data.getString("hisOweReceivedRoomAmount"));
         row.createCell(9).setCellValue(data.getString("monthReceivedRoomCount"));
-        row.createCell(10).setCellValue(data.getIntValue("roomCount")-data.getIntValue("freeCount")-data.getIntValue("monthReceivedRoomCount"));
-        BigDecimal monthReceivedRoomCount = new BigDecimal(data.getIntValue("monthReceivedRoomCount"));
-        BigDecimal roomCount = new BigDecimal(data.getIntValue("roomCount")-data.getIntValue("freeCount"));
-        monthReceivedRoomCount = monthReceivedRoomCount.divide(roomCount,4,BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal(100)).setScale(2,BigDecimal.ROUND_HALF_UP);
-        row.createCell(11).setCellValue(monthReceivedRoomCount.doubleValue()+"%");
+        row.createCell(10).setCellValue(data.getIntValue("oweRoomCount"));
+        BigDecimal feeRoomCount = new BigDecimal(data.getIntValue("feeRoomCount"));
+        if (feeRoomCount.doubleValue() == 0) {
+            row.createCell(11).setCellValue("0%");
+        } else {
+            BigDecimal roomCount = new BigDecimal(data.getIntValue("feeRoomCount") - data.getIntValue("oweRoomCount"));
+            feeRoomCount = roomCount.divide(feeRoomCount, 4, BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal(100)).setScale(2, BigDecimal.ROUND_HALF_UP);
+            row.createCell(11).setCellValue(feeRoomCount.doubleValue() + "%");
+        }
         row.createCell(12).setCellValue(data.getString("monthReceivedRoomAmount"));
         row.createCell(13).setCellValue(data.getString("curMonthOweFee"));
 
         BigDecimal monthReceivedRoomAmount = new BigDecimal(data.getIntValue("monthReceivedRoomAmount"));
-        BigDecimal curMonthOweFee = new BigDecimal(data.getIntValue("curMonthOweFee"));
+        BigDecimal hisMonthOweFee = new BigDecimal(data.getIntValue("hisMonthOweFee"));
+        BigDecimal hisReceivedFee = new BigDecimal(data.getIntValue("hisReceivedFee"));
+        BigDecimal curReceivableFee = new BigDecimal(data.getIntValue("curReceivableFee"));
 
-        curMonthOweFee = monthReceivedRoomAmount.add(curMonthOweFee);
-        curMonthOweFee = monthReceivedRoomAmount.divide(curMonthOweFee,4,BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal(100)).setScale(2,BigDecimal.ROUND_HALF_UP);
-
-        row.createCell(14).setCellValue(curMonthOweFee.doubleValue()+"%");
-
-
+       BigDecimal divideFee = hisMonthOweFee.add(hisReceivedFee).add(curReceivableFee);
+       if(divideFee.doubleValue() == 0){
+           row.createCell(14).setCellValue("0%");
+       }else{
+           BigDecimal preReceivedFee = new BigDecimal(data.getIntValue("preReceivedFee"));
+           monthReceivedRoomAmount = monthReceivedRoomAmount.subtract(preReceivedFee).divide(divideFee, 4, BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal(100)).setScale(2, BigDecimal.ROUND_HALF_UP);
+           row.createCell(14).setCellValue(monthReceivedRoomAmount.doubleValue() + "%");
+       }
     }
 
     /**
@@ -154,6 +164,14 @@
         queryStatisticsDto.setEndDate(reqJson.getString("endDate"));
         queryStatisticsDto.setFeeTypeCd(reqJson.getString("feeTypeCd"));
 
+        String monthFastDate = DateUtil.getFormatTimeStringB(DateUtil.getFirstDate(reqJson.getString("startDate")));
+        String monthLastDate = DateUtil.getFormatTimeStringB(DateUtil.getNextMonthFirstDate(reqJson.getString("startDate")));
+        String startDate = reqJson.getString("startDate");
+        Calendar calendar = Calendar.getInstance();
+        calendar.setTime(DateUtil.getDateFromStringB(startDate));
+        calendar.add(Calendar.DAY_OF_MONTH, 1);
+        String endDate = DateUtil.getFormatTimeStringB(calendar.getTime());
+
         // todo 鏌ヨ妤兼爧
         FloorDto floorDto = new FloorDto();
         floorDto.setFloorId(floorId);
@@ -166,22 +184,21 @@
         long roomCount = getRoomCount(queryStatisticsDto);
         data.put("roomCount", roomCount);
 
-        // todo 鏌ヨ绌虹疆鎴锋暟
-        long freeCount = getFreeRoomCount(queryStatisticsDto);
-        data.put("freeCount", freeCount);
 
         // todo 鏌ヨ 鍘嗗彶娆犺垂
+        //杩欓噷璁剧疆鏌ヨ鏈�1鏃� 涓嶇劧鍘嗗彶鍜屾�绘瑺璐逛竴鏍锋湁鐐瑰鎬�
+        queryStatisticsDto.setStartDate(monthFastDate);
         double hisMonthOweFee = reportFeeStatisticsInnerServiceSMOImpl.getHisMonthOweFee(queryStatisticsDto);
         data.put("hisMonthOweFee", hisMonthOweFee);
 
         // todo 鏌ヨ鎬绘瑺璐�
+        queryStatisticsDto.setEndDate(monthLastDate);
         double oweFee = reportFeeStatisticsInnerServiceSMOImpl.getOweFee(queryStatisticsDto);
         data.put("oweFee", oweFee);
 
         // todo 鏈棩宸蹭氦鎴锋暟
-        queryStatisticsDto.setStartDate(DateUtil.getFormatTimeStringB(DateUtil.getCurrentDate()) + " 00:00:00");
-        queryStatisticsDto.setEndDate(DateUtil.getFormatTimeStringB(DateUtil.getCurrentDate()) + " 23:59:59");
-        queryStatisticsDto.setHisDate(DateUtil.getFormatTimeStringB(DateUtil.getFirstDate()));
+        queryStatisticsDto.setStartDate(startDate);
+        queryStatisticsDto.setEndDate(endDate);
         double todayReceivedRoomCount = reportFeeStatisticsInnerServiceSMOImpl.getReceivedRoomCount(queryStatisticsDto);
         data.put("todayReceivedRoomCount", todayReceivedRoomCount);
 
@@ -190,18 +207,28 @@
         data.put("todayReceivedRoomAmount", todayReceivedRoomAmount);
 
         // todo 鍘嗗彶娆犺垂娓呯即鎴�
+        queryStatisticsDto.setStartDate(startDate);
+        queryStatisticsDto.setEndDate(endDate);
+        queryStatisticsDto.setHisDate(monthFastDate);
         double hisOweReceivedRoomCount = reportFeeStatisticsInnerServiceSMOImpl.getHisOweReceivedRoomCount(queryStatisticsDto);
         data.put("hisOweReceivedRoomCount", hisOweReceivedRoomCount);
         // todo 鍘嗗彶娆犺垂娓呯即閲戦
         double hisOweReceivedRoomAmount = reportFeeStatisticsInnerServiceSMOImpl.getHisOweReceivedRoomAmount(queryStatisticsDto);
         data.put("hisOweReceivedRoomAmount", hisOweReceivedRoomAmount);
 
-        // todo 杩欓噷鏃堕棿鍙堟敼鍥炴潵
-        queryStatisticsDto.setStartDate(reqJson.getString("startDate"));
-        queryStatisticsDto.setEndDate(reqJson.getString("endDate"));
         // todo 鏈湀宸叉敹鎴�
+        queryStatisticsDto.setStartDate(monthFastDate);
+        queryStatisticsDto.setEndDate(monthLastDate);
         double monthReceivedRoomCount = reportFeeStatisticsInnerServiceSMOImpl.getReceivedRoomCount(queryStatisticsDto);
         data.put("monthReceivedRoomCount", monthReceivedRoomCount);
+
+        // todo 鏌ヨ鏀惰垂鎴�
+        long feeRoomCount = reportFeeStatisticsInnerServiceSMOImpl.getFeeRoomCount(queryStatisticsDto);
+        data.put("feeRoomCount", feeRoomCount);
+
+        // todo 璁$畻娆犺垂鎴�
+        int oweRoomCount = reportFeeStatisticsInnerServiceSMOImpl.getOweRoomCount(queryStatisticsDto);
+        data.put("oweRoomCount", oweRoomCount);
 
         // todo 宸叉敹閲戦
         double monthReceivedRoomAmount = reportFeeStatisticsInnerServiceSMOImpl.getReceivedRoomAmount(queryStatisticsDto);
@@ -210,6 +237,24 @@
         double curMonthOweFee = reportFeeStatisticsInnerServiceSMOImpl.getCurMonthOweFee(queryStatisticsDto);
         data.put("curMonthOweFee", curMonthOweFee);
 
+        //todo 鏌ヨ褰撴湀搴旀敹
+        queryStatisticsDto.setStartDate(monthFastDate);
+        queryStatisticsDto.setEndDate(monthLastDate);
+        double curReceivableFee = reportFeeStatisticsInnerServiceSMOImpl.getCurReceivableFee(queryStatisticsDto);
+        data.put("curReceivableFee", curReceivableFee);
+
+        //todo 鏌ヨ 娆犺垂杩藉洖
+        queryStatisticsDto.setStartDate(monthFastDate);
+        queryStatisticsDto.setEndDate(monthLastDate);
+        double hisReceivedFee = reportFeeStatisticsInnerServiceSMOImpl.getHisReceivedFee(queryStatisticsDto);
+        data.put("hisReceivedFee", hisReceivedFee);
+
+        //todo  鏌ヨ 棰勪氦璐圭敤
+        queryStatisticsDto.setStartDate(monthFastDate);
+        queryStatisticsDto.setEndDate(monthLastDate);
+        double preReceivedFee = reportFeeStatisticsInnerServiceSMOImpl.getPreReceivedFee(queryStatisticsDto);
+        data.put("preReceivedFee", preReceivedFee);
+
         datas.add(data);
 
 

--
Gitblit v1.8.0