From fc8e7ef81fb2e3e65f96009065b501c860b23019 Mon Sep 17 00:00:00 2001
From: java110 <928255095@qq.com>
Date: 星期五, 26 十一月 2021 11:09:26 +0800
Subject: [PATCH] 优化代码

---
 service-report/src/main/java/com/java110/report/bmo/reportFeeMonthStatistics/impl/GetReportFeeMonthStatisticsBMOImpl.java |   57 +++++++++++++++++++++++++++++++++++++++++++++++----------
 1 files changed, 47 insertions(+), 10 deletions(-)

diff --git a/service-report/src/main/java/com/java110/report/bmo/reportFeeMonthStatistics/impl/GetReportFeeMonthStatisticsBMOImpl.java b/service-report/src/main/java/com/java110/report/bmo/reportFeeMonthStatistics/impl/GetReportFeeMonthStatisticsBMOImpl.java
index 0a56229..57351e0 100755
--- a/service-report/src/main/java/com/java110/report/bmo/reportFeeMonthStatistics/impl/GetReportFeeMonthStatisticsBMOImpl.java
+++ b/service-report/src/main/java/com/java110/report/bmo/reportFeeMonthStatistics/impl/GetReportFeeMonthStatisticsBMOImpl.java
@@ -31,6 +31,7 @@
 import org.springframework.http.ResponseEntity;
 import org.springframework.stereotype.Service;
 
+import java.lang.reflect.Field;
 import java.math.BigDecimal;
 import java.text.ParseException;
 import java.util.*;
@@ -390,17 +391,19 @@
         Double allVacantHousingDiscount = 0.0;
         //绌虹疆鎴垮噺鍏�(澶ц)
         Double allVacantHousingReduction = 0.0;
-        int size = 0;
+        //鍚村鏂� 娉ㄩ噴 鎰熻鍜屼笂闈㈢殑369 鍔熻兘閲嶅
+        //int size = 0;
         if (count > 0) {
             //鏌ヨ缂磋垂鏄庣粏
             reportFeeMonthStatisticsDtos = reportFeeMonthStatisticsInnerServiceSMOImpl.queryPayFeeDetail(reportFeeMonthStatisticsDto);
-            if (reportFeeMonthStatisticsDtos != null && reportFeeMonthStatisticsDtos.size() > 0) {
-                //鏌ヨ鎵�鏈夌即璐规槑缁嗚褰�
-                ReportFeeMonthStatisticsDto reportFeeMonthStatisticsDto1 = BeanConvertUtil.covertBean(reportFeeMonthStatisticsDto, ReportFeeMonthStatisticsDto.class);
-                reportFeeMonthStatisticsDto1.setPage(PageDto.DEFAULT_PAGE);
-                List<ReportFeeMonthStatisticsDto> reportFeeMonthStatisticsDtos1 = reportFeeMonthStatisticsInnerServiceSMOImpl.queryPayFeeDetail(reportFeeMonthStatisticsDto1);
-                size = reportFeeMonthStatisticsDtos1.size();
-            }
+            //鍚村鏂� 娉ㄩ噴 鎰熻鍜屼笂闈㈢殑369 鍔熻兘閲嶅
+//            if (reportFeeMonthStatisticsDtos != null && reportFeeMonthStatisticsDtos.size() > 0) {
+//                //鏌ヨ鎵�鏈夌即璐规槑缁嗚褰�
+//                ReportFeeMonthStatisticsDto reportFeeMonthStatisticsDto1 = BeanConvertUtil.covertBean(reportFeeMonthStatisticsDto, ReportFeeMonthStatisticsDto.class);
+//                reportFeeMonthStatisticsDto1.setPage(PageDto.DEFAULT_PAGE);
+//                List<ReportFeeMonthStatisticsDto> reportFeeMonthStatisticsDtos1 = reportFeeMonthStatisticsInnerServiceSMOImpl.queryPayFeeDetail(reportFeeMonthStatisticsDto1);
+//                size = reportFeeMonthStatisticsDtos1.size();
+//            }
             //鏌ヨ搴旀敹銆佸疄鏀舵�婚噾棰�(澶ц)
             List<ReportFeeMonthStatisticsDto> reportFeeMonthStatisticsList = reportFeeMonthStatisticsInnerServiceSMOImpl.queryAllPayFeeDetail(reportFeeMonthStatisticsDto);
             //鏌ヨ(浼樻儬銆佸噺鍏嶃�佹粸绾抽噾銆佺┖缃埧鎵撴姌銆佺┖缃埧鍑忓厤閲戦绛�)澶ц鎬婚噾棰�
@@ -575,7 +578,9 @@
                         }
                     }
                 }
-                reportList.add(reportFeeMonthStatistics);
+                if (!hasInReportListAndMerge(reportList, reportFeeMonthStatistics)) {
+                    reportList.add(reportFeeMonthStatistics);
+                }
             }
             //搴旀敹鎬婚噾棰�(灏忚)
             reportFeeMonthStatisticsTotalDto.setTotalReceivableAmount(String.format("%.2f", totalReceivableAmount));
@@ -611,13 +616,45 @@
             reportFeeMonthStatisticsTotalDto = new ReportFeeMonthStatisticsTotalDto();
         }
 
-        ResultVo resultVo = new ResultVo((int) Math.ceil((double) size / (double) reportFeeMonthStatisticsDto.getRow()), size, reportList, reportFeeMonthStatisticsTotalDto);
+        ResultVo resultVo = new ResultVo((int) Math.ceil((double) count / (double) reportFeeMonthStatisticsDto.getRow()), count, reportList, reportFeeMonthStatisticsTotalDto);
 
         ResponseEntity<String> responseEntity = new ResponseEntity<String>(resultVo.toString(), HttpStatus.OK);
 
         return responseEntity;
     }
 
+    private boolean hasInReportListAndMerge(List<ReportFeeMonthStatisticsDto> reportList, ReportFeeMonthStatisticsDto reportFeeMonthStatistics) {
+        for (ReportFeeMonthStatisticsDto reportFeeMonthStatisticsDto : reportList) {
+            if (reportFeeMonthStatisticsDto.getDetailId().equals(reportFeeMonthStatistics.getDetailId())) {
+                combineSydwCore(reportFeeMonthStatistics, reportFeeMonthStatisticsDto);
+                return true;
+            }
+        }
+        return false;
+    }
+
+    //閽堝鎵�鐢ㄥ璞�
+    private static ReportFeeMonthStatisticsDto combineSydwCore(ReportFeeMonthStatisticsDto sourceBean, ReportFeeMonthStatisticsDto targetBean) {
+        Class sourceBeanClass = sourceBean.getClass();
+        Class targetBeanClass = targetBean.getClass();
+        Field[] sourceFields = sourceBeanClass.getDeclaredFields();
+        Field[] targetFields = sourceBeanClass.getDeclaredFields();
+        for (int i = 0; i < sourceFields.length; i++) {
+            Field sourceField = sourceFields[i];
+            Field targetField = targetFields[i];
+            sourceField.setAccessible(true);
+            targetField.setAccessible(true);
+            try {
+                if (!(sourceField.get(sourceBean) == null)) {
+                    targetField.set(targetBean, sourceField.get(sourceBean));
+                }
+            } catch (IllegalArgumentException | IllegalAccessException e) {
+                e.printStackTrace();
+            }
+        }
+        return targetBean;
+    }
+
     @Override
     public ResponseEntity<String> queryDeadlineFee(ReportFeeMonthStatisticsDto reportFeeMonthStatisticsDto) {
         int count = reportFeeMonthStatisticsInnerServiceSMOImpl.queryDeadlineFeeCount(reportFeeMonthStatisticsDto);

--
Gitblit v1.8.0