From 900829daab40ea7e29440c9de75592cd58a7562a Mon Sep 17 00:00:00 2001
From: java110 <928255095@qq.com>
Date: 星期二, 30 五月 2023 15:52:03 +0800
Subject: [PATCH] optimize

---
 service-report/src/main/java/com/java110/report/cmd/reportFeeMonthStatistics/QueryReportFeeSummaryCmd.java |  217 +++++++++++++++++------------------------------------
 1 files changed, 70 insertions(+), 147 deletions(-)

diff --git a/service-report/src/main/java/com/java110/report/cmd/reportFeeMonthStatistics/QueryReportFeeSummaryCmd.java b/service-report/src/main/java/com/java110/report/cmd/reportFeeMonthStatistics/QueryReportFeeSummaryCmd.java
index 4a012b2..cd14232 100644
--- a/service-report/src/main/java/com/java110/report/cmd/reportFeeMonthStatistics/QueryReportFeeSummaryCmd.java
+++ b/service-report/src/main/java/com/java110/report/cmd/reportFeeMonthStatistics/QueryReportFeeSummaryCmd.java
@@ -1,5 +1,6 @@
 package com.java110.report.cmd.reportFeeMonthStatistics;
 
+import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.java110.core.annotation.Java110Cmd;
 import com.java110.core.annotation.Java110Transactional;
@@ -8,10 +9,13 @@
 import com.java110.core.event.cmd.CmdEvent;
 import com.java110.dto.data.DataPrivilegeStaffDto;
 import com.java110.dto.fee.FeeConfigDto;
+import com.java110.dto.report.QueryStatisticsDto;
 import com.java110.dto.reportFeeMonthStatistics.ReportFeeMonthStatisticsDto;
 import com.java110.intf.community.IDataPrivilegeUnitV1InnerServiceSMO;
 import com.java110.intf.report.IReportFeeMonthStatisticsInnerServiceSMO;
 import com.java110.report.bmo.reportFeeMonthStatistics.IGetReportFeeMonthStatisticsBMO;
+import com.java110.report.statistics.IBaseDataStatistics;
+import com.java110.report.statistics.IFeeStatistics;
 import com.java110.utils.exception.CmdException;
 import com.java110.utils.util.Assert;
 import com.java110.utils.util.BeanConvertUtil;
@@ -27,182 +31,101 @@
 import java.util.List;
 
 /**
- * 鏌ヨ璐圭敤姹囨�昏〃
+ * 鏌ヨ 璐圭敤姹囨�昏〃
+ * <p>
+ * add by  wuxw
  */
 @Java110Cmd(serviceCode = "reportFeeMonthStatistics.queryReportFeeSummary")
 public class QueryReportFeeSummaryCmd extends Cmd {
 
     @Autowired
-    private IGetReportFeeMonthStatisticsBMO getReportFeeMonthStatisticsBMOImpl;
+    private IFeeStatistics feeStatisticsImpl;
 
     @Autowired
-    private IReportFeeMonthStatisticsInnerServiceSMO reportFeeMonthStatisticsInnerServiceSMOImpl;
+    private IBaseDataStatistics baseDataStatisticsImpl;
 
-    @Autowired
-    private IDataPrivilegeUnitV1InnerServiceSMO dataPrivilegeUnitV1InnerServiceSMOImpl;
 
+    /**
+     * 鏍¢獙鏌ヨ鏉′欢
+     * <p>
+     * 寮�濮嬫椂闂�
+     * 缁撴潫鏃堕棿
+     * 鎴垮眿
+     * 涓氫富
+     * 妤兼爧
+     * 璐圭敤椤�
+     *
+     * @param event   浜嬩欢瀵硅薄
+     * @param context 璇锋眰鎶ユ枃鏁版嵁
+     * @param reqJson
+     * @throws CmdException
+     */
     @Override
     public void validate(CmdEvent event, ICmdDataFlowContext context, JSONObject reqJson) throws CmdException {
         super.validatePageInfo(reqJson);
+        Assert.hasKeyAndValue(reqJson, "startDate", "鏈寘鍚紑濮嬫棩鏈�");
+        Assert.hasKeyAndValue(reqJson, "endDate", "鏈寘鍚粨鏉熸棩鏈�");
         Assert.hasKeyAndValue(reqJson, "communityId", "鏈寘鍚皬鍖轰俊鎭�");
     }
 
     @Override
-    @Java110Transactional
-    public void doCmd(CmdEvent event, ICmdDataFlowContext context, JSONObject reqJson) throws CmdException, ParseException {
-        String configIds = "";
-        if (reqJson.containsKey("configIds")) {
-            configIds = reqJson.getString("configIds");
-            reqJson.remove("configIds");
-        }
-        ReportFeeMonthStatisticsDto reportFeeMonthStatisticsDto = BeanConvertUtil.covertBean(reqJson, ReportFeeMonthStatisticsDto.class);
+    public void doCmd(CmdEvent event, ICmdDataFlowContext context, JSONObject reqJson) throws CmdException {
 
-        String staffId = context.getReqHeaders().get("user-id");
-        DataPrivilegeStaffDto dataPrivilegeStaffDto = new DataPrivilegeStaffDto();
-        dataPrivilegeStaffDto.setStaffId(staffId);
-        String[] unitIds = dataPrivilegeUnitV1InnerServiceSMOImpl.queryDataPrivilegeUnitsByStaff(dataPrivilegeStaffDto);
+        QueryStatisticsDto queryStatisticsDto = new QueryStatisticsDto();
+        queryStatisticsDto.setCommunityId(reqJson.getString("communityId"));
+        queryStatisticsDto.setStartDate(reqJson.getString("startDate"));
+        queryStatisticsDto.setEndDate(reqJson.getString("endDate"));
+        queryStatisticsDto.setConfigId(reqJson.getString("configId"));
+        queryStatisticsDto.setFloorId(reqJson.getString("floorId"));
+        queryStatisticsDto.setObjName(reqJson.getString("objName"));
+        queryStatisticsDto.setFeeTypeCd(reqJson.getString("feeTypeCd"));
+        queryStatisticsDto.setOwnerName(reqJson.getString("ownerName"));
+        queryStatisticsDto.setLink(reqJson.getString("link"));
 
-        if (unitIds != null && unitIds.length > 0) {
-            reportFeeMonthStatisticsDto.setUnitIds(unitIds);
+        if(reqJson.containsKey("configIds")){
+            queryStatisticsDto.setConfigIds(reqJson.getString("configIds").split(","));
         }
 
-        if (!StringUtil.isEmpty(configIds)) {
-            reportFeeMonthStatisticsDto.setConfigIds(configIds.split(","));
-        }
-        int count = reportFeeMonthStatisticsInnerServiceSMOImpl.queryReportFeeSummaryCount(reportFeeMonthStatisticsDto);
+        //todo 鏌ヨ鍘嗗彶娆犺垂
+        double hisOweFee = feeStatisticsImpl.getHisMonthOweFee(queryStatisticsDto);
 
-        List<ReportFeeMonthStatisticsDto> reportFeeMonthStatisticsDtos = new ArrayList<>();
-        if (count > 0) {
-            List<ReportFeeMonthStatisticsDto> reportFeeMonthStatisticsList = reportFeeMonthStatisticsInnerServiceSMOImpl.queryReportFeeSummary(reportFeeMonthStatisticsDto);
-            if (reportFeeMonthStatisticsDto.getConfigIds() != null) {
-                reportFeeMonthStatisticsList = dealConfigReportFeeMonthStatisticsList(reportFeeMonthStatisticsList, "FeeSummary");
-            }
-            for (ReportFeeMonthStatisticsDto reportFeeMonthStatistics : reportFeeMonthStatisticsList) {
-                //鑾峰彇搴旀敹閲戦
-                double receivableAmount = Double.parseDouble(reportFeeMonthStatistics.getReceivableAmount());
-                //鑾峰彇瀹炴敹閲戦
-                double receivedAmount = Double.parseDouble(reportFeeMonthStatistics.getReceivedAmount());
-                if (receivableAmount != 0) {
-                    double chargeRate = (receivedAmount / receivableAmount) * 100.0;
-                    reportFeeMonthStatistics.setChargeRate(String.format("%.2f", chargeRate) + "%");
-                } else {
-                    reportFeeMonthStatistics.setChargeRate("0%");
+        //todo 鏌ヨ 鍗曟湀娆犺垂
+        double curOweFee = feeStatisticsImpl.getCurMonthOweFee(queryStatisticsDto);
 
-                }
-                reportFeeMonthStatisticsDtos.add(reportFeeMonthStatistics);
+        //todo 鏌ヨ褰撴湀搴旀敹
+        double curReceivableFee = feeStatisticsImpl.getCurReceivableFee(queryStatisticsDto);
 
-            }
-            ReportFeeMonthStatisticsDto tmpReportFeeMonthStatisticsDto = reportFeeMonthStatisticsInnerServiceSMOImpl.queryReportFeeSummaryMajor(reportFeeMonthStatisticsDto);
-            if (reportFeeMonthStatisticsList != null && reportFeeMonthStatisticsList.size() > 0) {
-                for (ReportFeeMonthStatisticsDto reportFeeMonthStatisticsDto1 : reportFeeMonthStatisticsList) {
-                    reportFeeMonthStatisticsDto1.setAllReceivableAmount(tmpReportFeeMonthStatisticsDto.getAllReceivableAmount());
-                    reportFeeMonthStatisticsDto1.setAllReceivedAmount(tmpReportFeeMonthStatisticsDto.getAllReceivedAmount());
-                    reportFeeMonthStatisticsDto1.setAllHisOweReceivedAmount(tmpReportFeeMonthStatisticsDto.getAllHisOweReceivedAmount());
-                }
-            }
-        } else {
-            reportFeeMonthStatisticsDtos = new ArrayList<>();
-        }
+        //todo 鏌ヨ 娆犺垂杩藉洖
+        double hisReceivedFee = feeStatisticsImpl.getHisReceivedFee(queryStatisticsDto);
 
-        ResultVo resultVo = new ResultVo((int) Math.ceil((double) count / (double) reportFeeMonthStatisticsDto.getRow()), count, reportFeeMonthStatisticsDtos);
+        //todo  鏌ヨ 棰勪氦璐圭敤
+        double preReceivedFee = feeStatisticsImpl.getPreReceivedFee(queryStatisticsDto);
 
-        ResponseEntity<String> responseEntity = new ResponseEntity<String>(resultVo.toString(), HttpStatus.OK);
-        context.setResponseEntity(responseEntity);
-    }
+        //todo 鏌ヨ瀹炴敹
+        double receivedFee = feeStatisticsImpl.getReceivedFee(queryStatisticsDto);
 
-    private List<ReportFeeMonthStatisticsDto> dealConfigReportFeeMonthStatisticsList(List<ReportFeeMonthStatisticsDto> reportFeeMonthStatisticsList, String flag) {
-        List<ReportFeeMonthStatisticsDto> reportFeeMonthStatisticsDtos = new ArrayList<>();
-        BigDecimal hisOweAmountDec = null;
-        BigDecimal curReceivableAmountDec = null;
-        BigDecimal curReceivedAmountDec = null;
-        BigDecimal hisOweReceivedAmountDec = null;
-        BigDecimal preReceivedAmountDec = null;
-        BigDecimal receivableAmountDec = null;
-        BigDecimal receivedAmountDec = null;
-        List<FeeConfigDto> feeConfigDtos = null;
-        FeeConfigDto feeConfigDto = null;
-        for (ReportFeeMonthStatisticsDto reportFeeMonthStatisticsDto : reportFeeMonthStatisticsList) {
-            ReportFeeMonthStatisticsDto tmpReportFeeMonthStatisticsDto = hasReportFeeMonthStatisticsDto(reportFeeMonthStatisticsDtos, reportFeeMonthStatisticsDto, flag);
-            if (tmpReportFeeMonthStatisticsDto == null) {
-                feeConfigDtos = new ArrayList<>();
-                feeConfigDto = new FeeConfigDto();
-                feeConfigDto.setConfigId(reportFeeMonthStatisticsDto.getConfigId());
-                feeConfigDto.setAmount(Double.parseDouble(reportFeeMonthStatisticsDto.getReceivedAmount()));
-                feeConfigDtos.add(feeConfigDto);
-                reportFeeMonthStatisticsDto.setFeeConfigDtos(feeConfigDtos);
-                reportFeeMonthStatisticsDtos.add(reportFeeMonthStatisticsDto);
-                continue;
-            }
-            feeConfigDtos = tmpReportFeeMonthStatisticsDto.getFeeConfigDtos();
-            feeConfigDto = new FeeConfigDto();
-            feeConfigDto.setConfigId(reportFeeMonthStatisticsDto.getConfigId());
-            feeConfigDto.setAmount(Double.parseDouble(reportFeeMonthStatisticsDto.getReceivedAmount()));
-            feeConfigDtos.add(feeConfigDto);
-            tmpReportFeeMonthStatisticsDto.setFeeConfigDtos(feeConfigDtos);
+        //todo 鎴垮眿鏁�
+        long roomCount = baseDataStatisticsImpl.getRoomCount(queryStatisticsDto);
 
-            //鍘嗗彶娆犺垂
-            hisOweAmountDec = new BigDecimal(tmpReportFeeMonthStatisticsDto.getHisOweAmount());
-            hisOweAmountDec = hisOweAmountDec.add(new BigDecimal(reportFeeMonthStatisticsDto.getHisOweAmount()))
-                    .setScale(2, BigDecimal.ROUND_HALF_UP);
-            tmpReportFeeMonthStatisticsDto.setHisOweAmount(hisOweAmountDec.doubleValue());
+        //todo 绌洪棽鎴垮眿鏁�
+        long feeRoomCount = feeStatisticsImpl.getFeeRoomCount(queryStatisticsDto);
 
+        //todo 娆犺垂鎴锋暟
+        int oweRoomCount = feeStatisticsImpl.getOweRoomCount(queryStatisticsDto);
 
-            //褰撴湀搴旀敹
-            curReceivableAmountDec = new BigDecimal(tmpReportFeeMonthStatisticsDto.getCurReceivableAmount());
-            curReceivableAmountDec = curReceivableAmountDec.add(new BigDecimal(reportFeeMonthStatisticsDto.getCurReceivableAmount()))
-                    .setScale(2, BigDecimal.ROUND_HALF_UP);
-            tmpReportFeeMonthStatisticsDto.setCurReceivableAmount(curReceivableAmountDec.doubleValue());
+        JSONObject data = new JSONObject();
+        data.put("hisOweFee", hisOweFee);
+        data.put("curOweFee", curOweFee);
+        data.put("hisReceivedFee", hisReceivedFee);
+        data.put("preReceivedFee", preReceivedFee);
+        data.put("receivedFee", receivedFee);
+        data.put("roomCount", roomCount);
+        data.put("feeRoomCount", feeRoomCount);
+        data.put("oweRoomCount", oweRoomCount);
+        data.put("curReceivableFee", curReceivableFee);
 
-            //褰撴湀瀹炴敹
-            curReceivedAmountDec = new BigDecimal(tmpReportFeeMonthStatisticsDto.getCurReceivedAmount());
-            curReceivedAmountDec = curReceivedAmountDec.add(new BigDecimal(reportFeeMonthStatisticsDto.getCurReceivedAmount()))
-                    .setScale(2, BigDecimal.ROUND_HALF_UP);
-            tmpReportFeeMonthStatisticsDto.setCurReceivedAmount(curReceivedAmountDec.doubleValue());
-
-            //娆犺垂杩藉洖
-            hisOweReceivedAmountDec = new BigDecimal(tmpReportFeeMonthStatisticsDto.getHisOweReceivedAmount());
-            hisOweReceivedAmountDec = hisOweReceivedAmountDec.add(new BigDecimal(reportFeeMonthStatisticsDto.getHisOweReceivedAmount()))
-                    .setScale(2, BigDecimal.ROUND_HALF_UP);
-            tmpReportFeeMonthStatisticsDto.setHisOweReceivedAmount(hisOweReceivedAmountDec.doubleValue());
-
-            //棰勪氦璐�
-            preReceivedAmountDec = new BigDecimal(tmpReportFeeMonthStatisticsDto.getPreReceivedAmount());
-            preReceivedAmountDec = preReceivedAmountDec.add(new BigDecimal(reportFeeMonthStatisticsDto.getPreReceivedAmount()))
-                    .setScale(2, BigDecimal.ROUND_HALF_UP);
-            tmpReportFeeMonthStatisticsDto.setPreReceivedAmount(preReceivedAmountDec.doubleValue());
-
-            //鎬昏垂鐢�
-            receivableAmountDec = new BigDecimal(Double.parseDouble(tmpReportFeeMonthStatisticsDto.getReceivableAmount()));
-            receivableAmountDec = receivableAmountDec.add(new BigDecimal(Double.parseDouble(reportFeeMonthStatisticsDto.getReceivableAmount())))
-                    .setScale(2, BigDecimal.ROUND_HALF_UP);
-            tmpReportFeeMonthStatisticsDto.setReceivableAmount(receivableAmountDec.doubleValue() + "");
-
-            //瀹炴敹
-            receivedAmountDec = new BigDecimal(Double.parseDouble(tmpReportFeeMonthStatisticsDto.getReceivedAmount()));
-            receivedAmountDec = receivedAmountDec.add(new BigDecimal(Double.parseDouble(reportFeeMonthStatisticsDto.getReceivedAmount())))
-                    .setScale(2, BigDecimal.ROUND_HALF_UP);
-            tmpReportFeeMonthStatisticsDto.setReceivedAmount(receivedAmountDec.doubleValue() + "");
-        }
-
-        return reportFeeMonthStatisticsDtos;
-    }
-
-
-    private ReportFeeMonthStatisticsDto hasReportFeeMonthStatisticsDto(List<ReportFeeMonthStatisticsDto> reportFeeMonthStatisticsDtos, ReportFeeMonthStatisticsDto reportFeeMonthStatisticsDto, String flag) {
-        for (ReportFeeMonthStatisticsDto tmpReportFeeMonthStatisticsDto : reportFeeMonthStatisticsDtos) {
-            if ("FeeSummary".equals(flag) && tmpReportFeeMonthStatisticsDto.getFeeYear().equals(reportFeeMonthStatisticsDto.getFeeYear())
-                    && tmpReportFeeMonthStatisticsDto.getFeeMonth().equals(reportFeeMonthStatisticsDto.getFeeMonth())) {
-                return tmpReportFeeMonthStatisticsDto;
-            }
-            if ("FloorUnitFeeSummary".equals(flag) && tmpReportFeeMonthStatisticsDto.getFeeYear().equals(reportFeeMonthStatisticsDto.getFeeYear())
-                    && tmpReportFeeMonthStatisticsDto.getFeeMonth().equals(reportFeeMonthStatisticsDto.getFeeMonth())
-                    && tmpReportFeeMonthStatisticsDto.getFloorNum().equals(reportFeeMonthStatisticsDto.getFloorNum())
-                    && tmpReportFeeMonthStatisticsDto.getUnitNum().equals(reportFeeMonthStatisticsDto.getUnitNum())
-            ) {
-                return tmpReportFeeMonthStatisticsDto;
-            }
-        }
-
-        return null;
+        JSONArray datas = new JSONArray();
+        datas.add(data);
+        context.setResponseEntity(ResultVo.createResponseEntity(datas));
     }
 }

--
Gitblit v1.8.0