chengf
2025-08-27 074caee550216dfd4bb676677ae33cbd837c5710
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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
package com.java110.fee.cmd.fee;
 
import com.alibaba.fastjson.JSONObject;
import com.java110.core.annotation.Java110Cmd;
import com.java110.core.context.ICmdDataFlowContext;
import com.java110.core.event.cmd.Cmd;
import com.java110.core.event.cmd.CmdEvent;
import com.java110.dto.community.CommunityDto;
import com.java110.dto.dict.DictDto;
import com.java110.dto.fee.FeeConfigDto;
import com.java110.dto.fee.FeeDto;
import com.java110.dto.report.ReportExcelDto;
import com.java110.dto.report.ReportQueryRecord;
import com.java110.dto.room.RoomDto;
import com.java110.intf.community.ICommunityInnerServiceSMO;
import com.java110.intf.community.IRoomInnerServiceSMO;
import com.java110.intf.dev.IDictV1InnerServiceSMO;
import com.java110.intf.fee.IFeeConfigInnerServiceSMO;
import com.java110.intf.fee.IReportFeeInnerServiceSMO;
import com.java110.utils.exception.CmdException;
import com.java110.utils.util.Assert;
import com.java110.utils.util.BeanConvertUtil;
import com.java110.utils.util.DateUtil;
import com.java110.vo.FeeQueryParams;
import com.java110.vo.ResultVo;
import com.sun.org.apache.regexp.internal.RE;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
 
import java.math.BigDecimal;
import java.text.ParseException;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
 
@Java110Cmd(serviceCode = "fee.reportPropertyFeeCmd")
public class ReportFeePropertyCmd extends Cmd {
 
    @Autowired
    private IReportFeeInnerServiceSMO reportFeeInnerServiceSMOImpl;
 
    @Autowired
    private ICommunityInnerServiceSMO communityInnerServiceSMOImpl;
 
    @Autowired
    private IDictV1InnerServiceSMO dictV1InnerServiceSMOImpl;
 
    @Autowired
    private IRoomInnerServiceSMO roomInnerServiceSMOImpl;
 
    @Autowired
    private IFeeConfigInnerServiceSMO  feeConfigInnerServiceSMOImpl;
 
    @Override
    public void validate(CmdEvent event, ICmdDataFlowContext context, JSONObject reqJson) throws CmdException, ParseException {
        Assert.hasKey(reqJson, "communityId", "请求报文中未包含小区编号");
    }
 
    @Override
    public void doCmd(CmdEvent event, ICmdDataFlowContext context, JSONObject reqJson) throws CmdException, ParseException {
        int startYear = 2020;
        CommunityDto communityDto = new CommunityDto();
        communityDto.setCommunityId(reqJson.getString("communityId"));
        List<CommunityDto> communityDtos = communityInnerServiceSMOImpl.queryCommunitys(communityDto);
        FeeQueryParams feeQueryParams = new FeeQueryParams();
        feeQueryParams.setCommunityId(reqJson.getString("communityId"));
        feeQueryParams.setStartYear(startYear);
        int currentYear = java.time.Year.now().getValue();
        feeQueryParams.setEndYear(currentYear + 2);
        if(reqJson.containsKey("endYear") && !reqJson.get("endYear").equals("") && reqJson.get("endYear") != null) {
            currentYear=Integer.parseInt(reqJson.get("endYear")+"");
            feeQueryParams.setEndYear(Integer.parseInt(reqJson.get("endYear")+"")+2);
        }
        int endYear = feeQueryParams.getEndYear();
        int doYear = endYear - startYear;
 
        ReportQueryRecord reportQueryRecord = new ReportQueryRecord();
        reportQueryRecord.setCommunityId(reqJson.getString("communityId"));
        reportQueryRecord.setQueryStatus("0");
        reportQueryRecord.setEndYear(currentYear+"");
        reportQueryRecord.setOperator("白单流水物业表");
        List<ReportQueryRecord> reportQueryRecords = reportFeeInnerServiceSMOImpl.queryReport(BeanConvertUtil.beanCovertMap(reportQueryRecord));
 
        if (reqJson.containsKey("roomId")){
            ReportExcelDto reportExcelDto = new ReportExcelDto();
//            reportExcelDto.setRoomDto(roomInnerServiceSMOImpl.queryRooms());
        }
 
        else if(reportQueryRecords.size()>0 && !reqJson.containsKey("reload")){
            ResultVo resultVo = new ResultVo(JSONObject.parse(reportQueryRecords.get(reportQueryRecords.size()-1).getReportContent()));
 
            ResponseEntity<String> responseEntity = new ResponseEntity<String>(resultVo.toString(), HttpStatus.OK);
 
            context.setResponseEntity(responseEntity);
        }
 
        else{
            int row = Integer.parseInt(reqJson.containsKey("row")?reqJson.getString("row"):"10");
            int page = Integer.parseInt(reqJson.containsKey("page")?reqJson.getString("page"):"1");
            startYear = 2016;
            endYear = 2025;
            Object[][] test = new Object[row][];
            RoomDto roomDto = new RoomDto();
            roomDto.setCommunityId(reqJson.getString("communityId"));
            roomDto.setRow(row);
            roomDto.setPage(page);
            int count = roomInnerServiceSMOImpl.queryRoomsCount(roomDto);
            List<Map> rooms = roomInnerServiceSMOImpl.queryRoomsAsReport(roomDto);
            FeeConfigDto feeConfigDto = new FeeConfigDto();
            feeConfigDto.setCommunityId(reqJson.getString("communityId"));
            feeConfigDto.setFeeTypeCds(new String[]{"630000001","630000002"});
            feeConfigDto.setRow(2);
            feeConfigDto.setPage(1);
            List<FeeConfigDto> feeConfigDtos = feeConfigInnerServiceSMOImpl.queryFeeConfigs(feeConfigDto);
            int arrLength = 11 + (2 * feeConfigDtos.size()) + 8 + ((endYear - startYear + 1) * 3 + 10) - 9;
            ReportExcelDto[] header = new ReportExcelDto[arrLength];
            List<List<ReportExcelDto>> lists = headerDoing(feeConfigDtos, startYear, endYear, arrLength);
            test[0] = header;
            for (int i = 1; i <= rooms.size(); i++) {
                Map map = rooms.get(i - 1);
                String[] strings = new String[arrLength];
                strings[0] = String.valueOf(row * (page - 1) + i);
                strings[1] = String.valueOf(rooms.get(i - 1).get("property_type"));
                strings[2] = rooms.get(i - 1).get("floor_num").toString();
                strings[3] = rooms.get(i - 1).get("unit_num").toString();
                strings[4] = rooms.get(i - 1).get("room_num").toString();
                strings[5] = strings[3] + "-" +  strings[4];
                strings[6] = rooms.get(i - 1).get("property_address").toString();
                strings[7] = rooms.get(i - 1).get("room_area").toString();
                strings[8] = rooms.get(i - 1).get("name").toString();
                for (int j = 1; j <= feeConfigDtos.size(); j++) {
                    strings[8 + j] = feeConfigDtos.get(j - 1).getSquarePrice();
                }
                strings[8 + feeConfigDtos.size() + 1] = "";
                for (int j = 1; j <= feeConfigDtos.size(); j++) {
                    strings[8 + feeConfigDtos.size() + 1 + j] = (doublequ2(Double.parseDouble(feeConfigDtos.get(j - 1).getSquarePrice()) * Double.parseDouble(String.valueOf((BigDecimal) rooms.get(i - 1).get("room_area")))))+"";
                }
                strings[8 + (2 * feeConfigDtos.size()) + 2] = (doublequ2(Double.parseDouble(feeConfigDtos.get(feeConfigDtos.size() - 1).getSquarePrice()) * Double.parseDouble(String.valueOf((BigDecimal) rooms.get(i - 1).get("room_area")))))+"";
                HashMap<Object, Object> objectObjectHashMap = new HashMap<>();
                objectObjectHashMap.put("payObjId", map.get("room_id"));
                List<Map> fee = reportFeeInnerServiceSMOImpl.onceRoomFee(objectObjectHashMap);
                double allMoney = 0;
                double allPayMoney = 0;
                int monthCount = 0;
                int noPayMoney = 0;
                int year1 = 0;
                int year2 = 0;
                double discountMoney = 0;
                String noPayDate = "";
                currentYear = DateUtil.getYear();
                for (Map map1 : fee){
                    if(map1.containsKey("统计维度") && !(map1.get("统计维度").toString().contains("总计"))){
                        allMoney += ((BigDecimal) map1.get("应收金额")).doubleValue();
                        allPayMoney += ((BigDecimal) map1.get("实收金额")).doubleValue();
                        monthCount += ((BigDecimal)map1.get("未收月数")).intValue();
                        noPayMoney += ((BigDecimal)map1.get("未收金额")).intValue();
                        noPayDate = noPayDate + map1.get("未收区间");
                        discountMoney += ((BigDecimal)map1.get("折扣金额")).doubleValue();
                        if(map1.get("统计维度").equals("2026")){
                            year1 += ((BigDecimal) map1.get("应收金额")).doubleValue();
                        }
                        if(map1.get("统计维度").equals("2027")){
                            year2 += ((BigDecimal) map1.get("应收金额")).doubleValue();
                        }
                    }
 
                }
                for (int x = endYear ; x >= startYear ; x --){
                    strings[8 + (2 * feeConfigDtos.size()) + 10 + (3 * (endYear - x)) + 1] = "0";
                    strings[8 + (2 * feeConfigDtos.size()) + 10 + (3 * (endYear - x)) + 2] = "";
                    strings[8 + (2 * feeConfigDtos.size()) + 10 + (3 * (endYear - x)) + 3] = "";
                    for (Map map1 : fee){
                        if(map1.get("统计维度").equals((endYear - x + startYear)+"年")) {
                            strings[8 + (2 * feeConfigDtos.size()) + 10 + (3 * (endYear - x)) + 1] = Integer.parseInt(strings[8 + (2 * feeConfigDtos.size()) + 10 + (3 * (endYear - x)) + 1]) + ((BigDecimal) map1.get("已收月数")).intValue() + "";
                            if(map1.containsKey("已收区间")){
                                strings[8 + (2 * feeConfigDtos.size()) + 10 + (3 * (endYear - x)) + 2] = strings[8 + (2 * feeConfigDtos.size()) + 10 + (3 * (endYear - x)) + 2] + "  " + map1.get("已收区间");
                            }
                            if(map1.containsKey("未收区间")){
                                strings[8 + (2 * feeConfigDtos.size()) + 10 + (3 * (endYear - x)) + 3] = strings[8 + (2 * feeConfigDtos.size()) + 10 + (3 * (endYear - x)) + 3] + "  " + map1.get("未收区间");
                            }
                        }
                    }
                }
                strings[8 + (2 * feeConfigDtos.size()) + 3] = allMoney+"";
                strings[8 + (2 * feeConfigDtos.size()) + 4] = allPayMoney+"";
                strings[8 + (2 * feeConfigDtos.size()) + 5] = "";
                strings[8 + (2 * feeConfigDtos.size()) + 6] = year1+"";//2026
                strings[8 + (2 * feeConfigDtos.size()) + 7] = year2+"";//2027
                strings[8 + (2 * feeConfigDtos.size()) + 8] = monthCount+"";
                strings[8 + (2 * feeConfigDtos.size()) + 9] = noPayMoney+"";
                strings[8 + (2 * feeConfigDtos.size()) + 10] = "";//22
                strings[8 + (2 * feeConfigDtos.size()) + 11] = "";//23历年待收
                strings[8 + (2 * feeConfigDtos.size()) + 10 + (3 * (endYear - startYear)) + 3 + 1] = discountMoney+"";
                test[i - 1] = strings;
            }
 
 
            reportQueryRecord.setCommunityId(reqJson.getString("communityId"));
            reportQueryRecord.setQueryStatus("0");
            reportQueryRecord.setEndYear(currentYear+"");
            ReportExcelDto reportExcelDto = new ReportExcelDto();
            reportExcelDto.setHeader(lists);
            reportExcelDto.setData(test);
            reportQueryRecord.setReportContent(JSONObject.toJSONString(reportExcelDto));
            reportQueryRecord.setOperator("白单流水物业表");
 
//            int i = reportFeeInnerServiceSMOImpl.saveReport(BeanConvertUtil.beanCovertMap(reportQueryRecord));
            ResultVo resultVo = new ResultVo(reportExcelDto);
            resultVo.setTotal(count);
            resultVo.setRecords(count / row);
            ResponseEntity<String> responseEntity = new ResponseEntity<String>(resultVo.toString(), HttpStatus.OK);
 
            context.setResponseEntity(responseEntity);
        }
    }
 
    private List<List<ReportExcelDto>> headerDoing(List<FeeConfigDto> feeConfigDtos, int startYear, int endYear, int arrLength) {
        LinkedList<List<ReportExcelDto>> reportExcelDtos = new LinkedList<>();
        int feeRow = feeConfigDtos.size();
        LinkedList<ReportExcelDto> header = new LinkedList<>();
 
// 1. 固定表头项:严格按原代码col值设置
        header.add(createHeaderRow("序号", 1, 3));          // 原row.setCol(1)
        header.add(createHeaderRow("物业类型", 1, 3));      // 原未改col,沿用前一个1
        header.add(createHeaderRow("楼栋号/弄", 1, 3));    // 原未改col,沿用1
        header.add(createHeaderRow("门号", 1, 3));          // 原未改col,沿用1
        header.add(createHeaderRow("室号", 1, 3));          // 原未改col,沿用1
        header.add(createHeaderRow("门室号", 1, 3));        // 原未改col,沿用1
        header.add(createHeaderRow("产证地址", 1, 3));      // 原未改col,沿用1
        header.add(createHeaderRow("收费面积(m²)", 1, 3));// 原未改col,沿用1
        header.add(createHeaderRow("购房人姓名", 1, 3));    // 原未改col,沿用1
 
// 2. 第一个feeRow循环:原未显式改col,沿用前一个1(按原逻辑保持col=1)
        for (int i = 0; i < feeRow; i++) {
            header.add(createHeaderRow(feeConfigDtos.get(0).getFeeName(), 1, 3));
        }
 
// 3. 设备运作费:原未改col,沿用前一个1
        header.add(createHeaderRow("设备运作费", 1, 3));
 
// 4. 第二个feeRow循环:原未显式改col,沿用前一个1(按原逻辑保持col=1)
        for (int i = 0; i < feeRow; i++) {
            header.add(createHeaderRow(feeConfigDtos.get(0).getFeeName(), 1, 3));
        }
 
// 5. 年应收款:原显式setCol(1),保持col=1
        header.add(createHeaderRow("年应收款", 1, 3));
 
// 6. 合计(2020年1月-至今):原显式setCol(8),保持col=8;原setRow(1),保持row=1
        header.add(createHeaderRow("合计(2020年1月-至今)", 8, 1));
 
// 7. 历年实收:原显式setCol((endYear - startYear + 1) * 3),保持该计算逻辑
        int yearCol = (endYear - startYear + 1) * 3;
        header.add(createHeaderRow("历年实收", yearCol+1, 1));
        header.add(createHeaderRow("操作", 1, 3));    // 原未改col,沿用1
 
// 最终添加表头到报表列表
        reportExcelDtos.add(header);
 
 
        // 初始化 LinkedList(而非数组,支持顺序添加)
        LinkedList<ReportExcelDto> header2 = new LinkedList<>();
 
// 1. 应收、实收、代收等固定项:按顺序add,对应原数组0-7下标
        header2.add(createHeaderRow("应收", 1, 2));          // 对应原header[0]
        header2.add(createHeaderRow("实收", 1, 2));          // 对应原header[1]
        header2.add(createHeaderRow("代收", 1, 2));          // 对应原header[2]
        header2.add(createHeaderRow("2026年", 1, 2));        // 对应原header[3]
        header2.add(createHeaderRow("2027年", 1, 2));        // 对应原header[4]
        header2.add(createHeaderRow("待收月数", 1, 2));      // 对应原header[5]
        header2.add(createHeaderRow("待收金额", 1, 2));      // 对应原header[6]
        header2.add(createHeaderRow("代收区间", 1, 2));      // 对应原header[7]
 
// 2. 年份循环:按原下标逻辑计算顺序,继续add(原header[8]及以后)
        for (int i = startYear; i <= endYear; i++) {
            // 原逻辑:index = 7 + (i - startYear + 1) → 首次循环i=startYear时,index=8
            // LinkedList无需关心下标,直接add即可保持顺序(与原数组下标顺序一致)
            header2.add(createHeaderRow(String.valueOf(i), 3, 1));
        }
 
// 3. 打折金额汇总:原逻辑中"年份循环后"的下一个位置,继续add
        header2.add(createHeaderRow("打折金额汇总", 1, 2));
 
// 4. 最终添加到报表列表
        reportExcelDtos.add(header2);
 
        LinkedList<ReportExcelDto> header3 = new LinkedList<>();
 
        for (int i = startYear ; i <= endYear ; i++){
            header3.add(createHeaderRow("已收月数", 1, 1));
            header3.add(createHeaderRow("已收区间", 1, 1));
            header3.add(createHeaderRow("未收区间", 1, 1));
        }
        reportExcelDtos.add(header3);
 
        return reportExcelDtos;
    }
 
    private ReportExcelDto createHeaderRow(String text, int col, int row) {
        ReportExcelDto reportExcelDto = new ReportExcelDto();
        reportExcelDto.setTest(text); // 注意:可能是setText()的笔误
        reportExcelDto.setCol(col);
        reportExcelDto.setRow(row);
        return reportExcelDto;
    }
 
    public double doublequ2(double num){
        return (int)(num * 100) / 100.0;
    }
}