chengf
2025-08-25 4fafe2304ab5e3df321808f5120b29baf27c7eab
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
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
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.FeeDto;
import com.java110.dto.report.ReportQueryRecord;
import com.java110.intf.community.ICommunityInnerServiceSMO;
import com.java110.intf.dev.IDictV1InnerServiceSMO;
import com.java110.intf.fee.IReportFeeInnerServiceSMO;
import com.java110.po.fee.PayFeePo;
import com.java110.utils.exception.CmdException;
import com.java110.utils.util.Assert;
import com.java110.utils.util.BeanConvertUtil;
import com.java110.vo.FeeQueryParams;
import com.java110.vo.ResultVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
 
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.text.ParseException;
import java.util.*;
 
@Java110Cmd(serviceCode = "fee.reportFeeCmd")
public class ReportFeeCmd extends Cmd {
 
    @Autowired
    private IReportFeeInnerServiceSMO reportFeeInnerServiceSMOImpl;
 
    @Autowired
    private ICommunityInnerServiceSMO communityInnerServiceSMOImpl;
 
    @Autowired
    private IDictV1InnerServiceSMO dictV1InnerServiceSMOImpl;
 
    @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(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{
            List<List<FeeDto>> reportFeeDtoLists = new LinkedList<>();
            queryFee(reportFeeDtoLists ,reqJson);
            int[] arr = new int[endYear - startYear + 1];
            int[] arr2 = new int[endYear - startYear + 1 - 3];
            for (int i = startYear; i <= endYear; i++) {
                arr[i-startYear] = i;
            }
            for (int i = startYear; i < currentYear; i++) {
                arr2[i-startYear] = i;
            }
 
            FeeDto feeDto = new FeeDto();
            feeDto.setRepostList(reportFeeDtoLists);
            feeDto.setYearArr(arr);
            feeDto.setYearArr2(arr2);
            feeDto.setReportLength(doYear - 1 + 20);
 
            reportQueryRecord.setCommunityId(reqJson.getString("communityId"));
            reportQueryRecord.setQueryStatus("0");
            reportQueryRecord.setEndYear(currentYear+"");
            reportQueryRecord.setReportContent(JSONObject.toJSONString(feeDto));
            reportQueryRecord.setOperator("白单流水汇总表");
 
 
            int i = reportFeeInnerServiceSMOImpl.saveReport(BeanConvertUtil.beanCovertMap(reportQueryRecord));
 
            ResultVo resultVo = new ResultVo(feeDto);
 
            ResponseEntity<String> responseEntity = new ResponseEntity<String>(resultVo.toString(), HttpStatus.OK);
 
            context.setResponseEntity(responseEntity);
        }
    }
    public void queryFee(List<List<FeeDto>> reportFeeDtoLists, JSONObject reqJson) {
        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;
        LinkedList<FeeDto> col1 = new LinkedList<>();
        FeeDto col = new FeeDto();
        double[] col1Fee = new double[doYear - 1 + 20];
        col.setReport(col1Fee);
        col.setCurYear("收入合计(白单流水)");
        col1.add(col);
 
        LinkedList<FeeDto> col2 = new LinkedList<>();
        double[] col2Fee = new double[doYear - 1 + 20];
        col = new FeeDto();
        col.setReport(col2Fee);
        col.setCurYear("物业费+代收合计");
        col2.add(col);
 
        LinkedList<FeeDto> col3 = new LinkedList<>();
        col = new FeeDto();
        col.setReport(col2Fee);
        col.setCurYear("物业费合计(1+2)");
        col3.add(col);
 
        LinkedList<FeeDto> col4 = new LinkedList<>();
        col = new FeeDto();
        col.setReport(new double[doYear - 1 + 20]);
        col.setCurYear("物业费代收合计");
        col3.add(col);
 
        double[] col4Fee = new double[doYear - 1 + 20];
        double[] colByCar = new double[doYear - 1 + 20];
        double[] colByOther = new double[doYear - 1 + 20];
        reportFeeDtoLists.add(col1);
        reportFeeDtoLists.add(col2);
        reportFeeDtoLists.add(col2);
        reportFeeDtoLists.add(col4);
        int ind = 1;
 
        int[] arr = new int[endYear - startYear + 1];
        for (int i = startYear; i <= endYear; i++) {
            arr[i-startYear] = i;
        }
        List<Map> result = reportFeeInnerServiceSMOImpl.repostPaidInFee(feeQueryParams);
        DictDto dictDto = new DictDto();
        dictDto.setTableName("pay_fee_config");
        dictDto.setTableColumns("fee_type_cd");
        List<DictDto> dictDtos = dictV1InnerServiceSMOImpl.queryDicts(dictDto);
        for (DictDto dictDto1 : dictDtos) {//类型
            List<FeeDto> reportFeeDtos = new LinkedList<>();//该类型的数组
            FeeDto feeDto = new FeeDto();
            LinkedList<FeeDto> feeDtos = new LinkedList<>();//总的
            int kg = 0;
            for (Map map : result){
                if(map.get("费用所属年份").equals("类型总计") && map.containsKey("fee_type_cd") && map.get("fee_type_cd").equals(dictDto1.getStatusCd())){
                    double[] doubles = new double[doYear - 1 + 20];
                    doubles[0] = doubleUse(((BigDecimal) map.get("该年应缴总额")).doubleValue());
                    doubles[1] = doubleUse(((BigDecimal) map.get("每月费用")).doubleValue());
                    doubles[2] = doubleUse(((Long) map.get("应收月份数")).doubleValue());
                    doubles[3] = doubleUse(((BigDecimal) map.get("当年收缴率")).doubleValue());
                    doubles[4] = doubleUse(((BigDecimal) map.get("折扣金额")).doubleValue());
                    int inde = 0;
                    for (int i : arr){
                        if(i < currentYear){
                            inde++;
                            doubles[i - startYear + 5] = doubleUse(((BigDecimal) map.get(i + "年实缴")).doubleValue());
                        }
                    }
                    doubles[inde + 5] =doubleUse(((BigDecimal) map.get("当年预算")).doubleValue());
                    doubles[inde + 6] =doubleUse(((BigDecimal) map.get(currentYear + "年实缴")).doubleValue());
                    doubles[inde + 7] =doubleUse(((BigDecimal) map.get("当年折扣总额")).doubleValue());
                    doubles[inde + 8] =doubleUse(((BigDecimal) map.get("当年欠款")).doubleValue());
 
                    for (int i = 1 ; i <= 12 ; i++){
                        doubles[inde + 8 + i] =doubleUse(((BigDecimal) map.get("当年"+(i < 10 ? "0"+i : i) +"月实缴")).doubleValue());
                    }
                    feeDto.setCurYear(dictDto1.getName()+"总计");
                    if(Integer.parseInt(dictDto1.getStatusCd())%630000000 < 3){
                        for(int i = 0 ; i < doubles.length ; i++){
                            if(i == 3){
                                if (doubles[i] != 0){
                                    col1Fee[i] = (doubles[i]+col1Fee[i])/2;
                                    col2Fee[i] = (doubles[i]+col2Fee[i])/2;
                                }
                            }else{
                                col1Fee[i] += doubleUse(doubles[i]);
                                col2Fee[i] += doubleUse(doubles[i]);
                            }
                        }
                    }
                    else if(Integer.parseInt(dictDto1.getStatusCd())%630000000 < 8){
                        for(int i = 0 ; i < doubles.length ; i++){
                            if(i == 3){
                                if (doubles[i] != 0){
                                    col1Fee[i] = (doubles[i]+col1Fee[i])/2;
//                                    col2Fee[i] = (doubles[i]+col2Fee[i])/2;
                                }
                            }else{
                                col1Fee[i] += doubleUse(doubles[i]);
//                                col2Fee[i] += doubleUse(doubles[i]);
                            }
                        }
                    }else{
                        for(int i = 0 ; i < doubles.length ; i++){
                            if(i == 3){
                                if (doubles[i] != 0){
                                    col1Fee[i] = (doubles[i]+col1Fee[i])/2;
//                                    col2Fee[i] = (doubles[i]+col2Fee[i])/2;
                                }
                            }else{
                                col1Fee[i] += doubleUse(doubles[i]);
//                                col2Fee[i] += doubleUse(doubles[i]);
                            }
                        }
                    }
                    feeDto.setReport(doubles);
                    feeDto.setCount(ind);
 
                }
            }
            if (feeDto.getCurYear() == null){
                feeDto.setCurYear("类型总计");
            }
            if (feeDto.getReport() == null){
                feeDto.setReport(new double[doYear - 1 + 20]);
            }
            if(feeDto.getFeeTypeCdName() == null) {
                feeDto.setFeeTypeCdName(dictDto1.getName());
            }
            LinkedList<FeeDto> feeDtos1 = new LinkedList<>();
            feeDtos1.add(feeDto);
            reportFeeDtoLists.add(feeDtos1);//添加总金额的
            feeDtos1 = new LinkedList<>();
            feeDto = new FeeDto();
            LinkedList<FeeDto> feeDtos2 = new LinkedList<>();
            for (int i = startYear; i <= endYear; i++) {//年份
                kg = 0;
                for (Map map : result){
                    if(map.get("费用所属年份").equals(i+"") && map.get("fee_type_cd").equals(dictDto1.getStatusCd())){
                        double[] doubles = new double[doYear - 1 + 20];
                        doubles[0] = doubleUse(((BigDecimal) map.get("该年应缴总额")).doubleValue());
                        doubles[1] = doubleUse(((BigDecimal) map.get("每月费用")).doubleValue());
                        doubles[2] = doubleUse(((Long) map.get("应收月份数")).doubleValue());
                        doubles[3] = doubleUse(((BigDecimal) map.get("当年收缴率")).doubleValue());
                        doubles[4] = doubleUse(((BigDecimal) map.get("折扣金额")).doubleValue());
                        int inde = 0;
                        for (int in : arr){
                            if(in < currentYear && (in+"").equals(map.get("费用所属年份"))){
                                inde++;
                                doubles[in - startYear + 5] = doubleUse(((BigDecimal) map.get(i + "年实缴")).doubleValue());
                            }
                        }
                        doubles[inde + 5] =doubleUse(((BigDecimal) map.get("当年预算")).doubleValue());
                        doubles[inde + 6] =doubleUse(((BigDecimal) map.get(currentYear + "年实缴")).doubleValue());
                        doubles[inde + 7] =doubleUse(((BigDecimal) map.get("当年折扣总额")).doubleValue());
                        doubles[inde + 8] =doubleUse(((BigDecimal) map.get("当年欠款")).doubleValue());
 
                        for (int in = 1 ; in <= 12 ; in++){
                            doubles[inde + 8 + in] =doubleUse(((BigDecimal) map.get("当年"+(in < 10 ? "0"+in : in) +"月实缴")).doubleValue());
                        }
                        feeDto = new FeeDto();
                        feeDto.setFeeTypeCdName(dictDto1.getName());
                        feeDto.setCurYear(String.valueOf(i));
                        feeDto.setReport(doubles);
                        feeDto.setCount(ind);
                        feeDtos2.add(feeDto);
                        kg = 1;
                    }
                }
                if(kg == 0){
                    feeDto = new FeeDto();
                    feeDto.setFeeTypeCdName(dictDto1.getName());
                    feeDto.setCurYear(String.valueOf(i));
                    feeDto.setReport(new double[doYear - 1 + 20]);
                    feeDto.setCount(ind);
                    feeDtos2.add(feeDto);
                }
            }
            reportFeeDtoLists.add(feeDtos2);
            if (ind == 1){
                LinkedList linkedList = new LinkedList();
                FeeDto feeDto1 = new FeeDto();
                feeDto1.setCurYear("住宅物业费代收合计");
                linkedList.add(feeDto1);
                reportFeeDtoLists.add(linkedList);
            }
            if (ind == 2){
                LinkedList linkedList = new LinkedList();
                FeeDto feeDto1 = new FeeDto();
                feeDto1.setCurYear("商铺物业费代收合计");
                linkedList.add(feeDto1);
                reportFeeDtoLists.add(linkedList);
            }
            if (ind == 3){
                LinkedList linkedList = new LinkedList();
                FeeDto feeDto1 = new FeeDto();
                feeDto1.setCurYear("停车费合计(3+...+7)");
                feeDto1.setReport(colByCar);
                linkedList.add(feeDto1);
                reportFeeDtoLists.add(linkedList);
            }
            if (ind == 8){
                LinkedList linkedList = new LinkedList();
                FeeDto feeDto1 = new FeeDto();
                feeDto1.setCurYear("其他类合计(8+...+22)");
                feeDto1.setReport(colByOther);
                linkedList.add(feeDto1);
                reportFeeDtoLists.add(linkedList);
            }
            ind ++;
        }
    }
    public double doubleUse(double num){
        return  (int)(num * 100) / 100.0;
    }
}