java110
2023-05-16 173b6b8fd81b710c10cd6b3b1d4143d04a256340
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
package com.java110.job.export.adapt;
 
import com.alibaba.fastjson.JSONObject;
import com.java110.dto.FloorDto;
import com.java110.dto.data.ExportDataDto;
import com.java110.dto.report.QueryStatisticsDto;
import com.java110.intf.community.IFloorV1InnerServiceSMO;
import com.java110.intf.report.IReportFeeStatisticsInnerServiceSMO;
import com.java110.job.export.IExportDataAdapt;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.xssf.streaming.SXSSFWorkbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
import java.math.BigDecimal;
import java.util.List;
 
@Service("reportFeeSummary")
public class ReportFeeSummaryAdapt implements IExportDataAdapt {
 
    @Autowired
    private IFloorV1InnerServiceSMO floorV1InnerServiceSMOImpl;
 
    @Autowired
    private IReportFeeStatisticsInnerServiceSMO reportFeeStatisticsInnerServiceSMOImpl;
 
    @Override
    public SXSSFWorkbook exportData(ExportDataDto exportDataDto) {
        SXSSFWorkbook workbook = null;  //工作簿
        String userId = "";
        //工作表
        workbook = new SXSSFWorkbook();
        workbook.setCompressTempFiles(false);
 
        Sheet sheet = workbook.createSheet("费用汇总表");
        Row row = sheet.createRow(0);
        row.createCell(0).setCellValue("楼栋");
        row.createCell(1).setCellValue("收费户");
        row.createCell(2).setCellValue("欠费户");
        row.createCell(3).setCellValue("历史欠费+当期欠费=欠费");
        row.createCell(6).setCellValue("欠费追回+当期实收+预交=实收");
        row.createCell(10).setCellValue("已交户/收费户=户收费率");
        row.createCell(11).setCellValue("(实收-预交)/(历史欠费+当期应收)=收费率");
 
        JSONObject reqJson = exportDataDto.getReqJson();
 
        //查询数据
        doReportFeeSummary(sheet, reqJson);
 
        //todo 合并 3 4 5
        sheet.addMergedRegion(new CellRangeAddress(0, 0, 3, 5));
        sheet.addMergedRegion(new CellRangeAddress(0, 0, 6, 9));
        return workbook;
 
    }
 
    private void doReportFeeSummary(Sheet sheet, JSONObject reqJson) {
 
        FloorDto floorDto = new FloorDto();
        floorDto.setCommunityId(reqJson.getString("communityId"));
        List<FloorDto> floorDtos = floorV1InnerServiceSMOImpl.queryFloors(floorDto);
 
        JSONObject floorSummaryData = null;
        for (int floorIndex = 0; floorIndex < floorDtos.size(); floorIndex++) {
            floorSummaryData = queryFloorFeeSummary(floorDtos.get(floorIndex), reqJson);
            appendData(floorSummaryData, sheet, floorIndex + 1, floorDtos.get(floorIndex));
        }
    }
 
 
    private void appendData(JSONObject dataObj, Sheet sheet, int step, FloorDto floorDto) {
 
        Row row = null;
        row = sheet.createRow(step);
        row.createCell(0).setCellValue(floorDto.getFloorName());
        row.createCell(1).setCellValue(dataObj.getString("feeRoomCount"));
        row.createCell(2).setCellValue(dataObj.getString("oweRoomCount"));
        row.createCell(3).setCellValue(dataObj.getString("hisOweFee"));
        row.createCell(4).setCellValue(dataObj.getString("curOweFee"));
 
        BigDecimal curOweFee = new BigDecimal(dataObj.getDouble("curOweFee"));
        BigDecimal hisOweFee = new BigDecimal(dataObj.getDouble("hisOweFee"));
        row.createCell(5).setCellValue(curOweFee.add(hisOweFee).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
        row.createCell(6).setCellValue(dataObj.getString("hisReceivedFee"));
        //(fee.receivedFee-fee.hisReceivedFee-fee.preReceivedFee)
        BigDecimal receivedFee = new BigDecimal(dataObj.getDouble("receivedFee"));
        BigDecimal hisReceivedFee = new BigDecimal(dataObj.getDouble("hisReceivedFee"));
        BigDecimal preReceivedFee = new BigDecimal(dataObj.getDouble("preReceivedFee"));
        row.createCell(7).setCellValue(receivedFee.subtract(hisReceivedFee).subtract(preReceivedFee).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
        row.createCell(8).setCellValue(dataObj.getString("preReceivedFee"));
        row.createCell(9).setCellValue(dataObj.getString("receivedFee"));
        //((fee.feeRoomCount-fee.oweRoomCount)/fee.feeRoomCount*100).toFixed(2)
 
        BigDecimal feeRoomCount = new BigDecimal(dataObj.getDouble("feeRoomCount"));
        BigDecimal oweRoomCount = new BigDecimal(dataObj.getDouble("oweRoomCount"));
        BigDecimal roomFeeRate = feeRoomCount.subtract(oweRoomCount).divide(feeRoomCount, 4, BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal(100)).setScale(2, BigDecimal.ROUND_HALF_UP);
        row.createCell(10).setCellValue(roomFeeRate.doubleValue() + "%");
        //((fee.receivedFee-fee.preReceivedFee)/(fee.hisOweFee+fee.curReceivableFee)*100).toFixed(2)
        BigDecimal curReceivableFee = new BigDecimal(dataObj.getDouble("curReceivableFee"));
        curReceivableFee = hisOweFee.add(curReceivableFee);
        roomFeeRate = receivedFee.subtract(preReceivedFee).divide(curReceivableFee, 4, BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal(100)).setScale(2, BigDecimal.ROUND_HALF_UP);
        row.createCell(11).setCellValue(roomFeeRate.doubleValue() + "%");
 
    }
 
    /**
     * 查询楼栋费用汇总信息
     *
     * @param floorDto
     * @param reqJson
     * @return
     */
    private JSONObject queryFloorFeeSummary(FloorDto floorDto, JSONObject reqJson) {
 
        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(floorDto.getFloorId());
        queryStatisticsDto.setObjName(reqJson.getString("objName"));
        queryStatisticsDto.setFeeTypeCd(reqJson.getString("feeTypeCd"));
        if (reqJson.containsKey("configIds")) {
            queryStatisticsDto.setConfigIds(reqJson.getString("configIds").split(","));
        }
 
        //todo 查询历史欠费
        double hisOweFee = reportFeeStatisticsInnerServiceSMOImpl.getHisMonthOweFee(queryStatisticsDto);
 
        //todo 查询 单月欠费
        double curOweFee = reportFeeStatisticsInnerServiceSMOImpl.getCurMonthOweFee(queryStatisticsDto);
 
        //todo 查询当月应收
        double curReceivableFee = reportFeeStatisticsInnerServiceSMOImpl.getCurReceivableFee(queryStatisticsDto);
 
        //todo 查询 欠费追回
        double hisReceivedFee = reportFeeStatisticsInnerServiceSMOImpl.getHisReceivedFee(queryStatisticsDto);
 
        //todo  查询 预交费用
        double preReceivedFee = reportFeeStatisticsInnerServiceSMOImpl.getPreReceivedFee(queryStatisticsDto);
 
        //todo 查询实收
        double receivedFee = reportFeeStatisticsInnerServiceSMOImpl.getReceivedFee(queryStatisticsDto);
 
        //todo 空闲房屋数
        long feeRoomCount = reportFeeStatisticsInnerServiceSMOImpl.getFeeRoomCount(queryStatisticsDto);
 
        //todo 欠费户数
        int oweRoomCount = reportFeeStatisticsInnerServiceSMOImpl.getOweRoomCount(queryStatisticsDto);
 
        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("feeRoomCount", feeRoomCount);
        data.put("oweRoomCount", oweRoomCount);
        data.put("curReceivableFee", curReceivableFee);
 
        return data;
    }
}