java110
2023-07-26 b0841762fd036a469dd712ee8f6d72faf2345b61
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
package com.java110.job.export.adapt;
 
import com.alibaba.fastjson.JSONObject;
import com.java110.dto.data.ExportDataDto;
import com.java110.dto.reportFee.ReportFeeYearCollectionDetailDto;
import com.java110.dto.reportFee.ReportFeeYearCollectionDto;
import com.java110.intf.report.IReportFeeYearCollectionDetailInnerServiceSMO;
import com.java110.intf.report.IReportFeeYearCollectionInnerServiceSMO;
import com.java110.job.export.IExportDataAdapt;
import com.java110.utils.util.BeanConvertUtil;
import com.java110.utils.util.StringUtil;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.xssf.streaming.SXSSFWorkbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
import java.util.List;
 
/**
 * 报表专家导出
 */
@Service("reportProficient")
public class ReportProficientAdapt implements IExportDataAdapt {
 
    @Autowired
    private IReportFeeYearCollectionInnerServiceSMO reportFeeYearCollectionInnerServiceSMOImpl;
 
    @Autowired
    private IReportFeeYearCollectionDetailInnerServiceSMO reportFeeYearCollectionDetailInnerServiceSMOImpl;
 
    private static final int MAX_ROW = 200;
 
    @Override
    public SXSSFWorkbook exportData(ExportDataDto exportDataDto) {
        SXSSFWorkbook workbook = null;  //工作簿
        String userId = "";
        //工作表
        workbook = new SXSSFWorkbook();
        workbook.setCompressTempFiles(false);
        JSONObject reqJson = exportDataDto.getReqJson();
        //获取付费对象类型
        String objType = reqJson.getString("objType");
        if (!StringUtil.isEmpty(objType) && objType.equals("3333")) { //房屋
            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(4).setCellValue("收费类型");
            row.createCell(5).setCellValue("费用名称");
            ReportFeeYearCollectionDto reportFeeYearCollectionDto = BeanConvertUtil.covertBean(reqJson, ReportFeeYearCollectionDto.class);
            reportFeeYearCollectionDto.setPage(1);
            reportFeeYearCollectionDto.setRow(MAX_ROW);
            List<ReportFeeYearCollectionDto> reportFeeYearCollections = reportFeeYearCollectionInnerServiceSMOImpl.queryReportFeeYearCollections(reportFeeYearCollectionDto);
            JSONObject dataObj = null;
            for (int index = 0; index < reportFeeYearCollections.size(); index++) {
                dataObj = JSONObject.parseObject(JSONObject.toJSONString(reportFeeYearCollections.get(index)));
                ReportFeeYearCollectionDetailDto reportFeeYearCollectionDetailDto = new ReportFeeYearCollectionDetailDto();
                reportFeeYearCollectionDetailDto.setCollectionId(dataObj.getString("collectionId"));
                List<ReportFeeYearCollectionDetailDto> reportFeeYearCollectionDetails =
                        reportFeeYearCollectionDetailInnerServiceSMOImpl.queryReportFeeYearCollectionDetails(reportFeeYearCollectionDetailDto);
                for (int detailIndex = 0; detailIndex < reportFeeYearCollectionDetails.size(); detailIndex++) {
                    row.createCell(6 + detailIndex).setCellValue(reportFeeYearCollectionDetails.get(detailIndex).getCollectionYear() + "年");
                }
                appendRoomData(dataObj, sheet, 0, index);
            }
        } else if (!StringUtil.isEmpty(objType) && objType.equals("6666")) { //车辆
            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(4).setCellValue("费用名称");
            ReportFeeYearCollectionDto reportFeeYearCollectionDto = BeanConvertUtil.covertBean(reqJson, ReportFeeYearCollectionDto.class);
            reportFeeYearCollectionDto.setPage(1);
            reportFeeYearCollectionDto.setRow(MAX_ROW);
            List<ReportFeeYearCollectionDto> reportFeeYearCollections = reportFeeYearCollectionInnerServiceSMOImpl.queryReportFeeYearCollections(reportFeeYearCollectionDto);
            JSONObject dataObj = null;
            for (int index = 0; index < reportFeeYearCollections.size(); index++) {
                dataObj = JSONObject.parseObject(JSONObject.toJSONString(reportFeeYearCollections.get(index)));
                ReportFeeYearCollectionDetailDto reportFeeYearCollectionDetailDto = new ReportFeeYearCollectionDetailDto();
                reportFeeYearCollectionDetailDto.setCollectionId(dataObj.getString("collectionId"));
                List<ReportFeeYearCollectionDetailDto> reportFeeYearCollectionDetails =
                        reportFeeYearCollectionDetailInnerServiceSMOImpl.queryReportFeeYearCollectionDetails(reportFeeYearCollectionDetailDto);
                for (int detailIndex = 0; detailIndex < reportFeeYearCollectionDetails.size(); detailIndex++) {
                    row.createCell(6 + detailIndex).setCellValue(reportFeeYearCollectionDetails.get(detailIndex).getCollectionYear() + "年");
                }
                appendCarData(dataObj, sheet, 0, index);
            }
        }
        return workbook;
    }
 
    //房屋费台账
    private void appendRoomData(JSONObject dataObj, Sheet sheet, int step, int index) {
        Row row = null;
        row = sheet.createRow(index + step + 1);
        ReportFeeYearCollectionDetailDto reportFeeYearCollectionDetailDto = new ReportFeeYearCollectionDetailDto();
        reportFeeYearCollectionDetailDto.setCollectionId(dataObj.getString("collectionId"));
        List<ReportFeeYearCollectionDetailDto> reportFeeYearCollectionDetails =
                reportFeeYearCollectionDetailInnerServiceSMOImpl.queryReportFeeYearCollectionDetails(reportFeeYearCollectionDetailDto);
        row.createCell(0).setCellValue(dataObj.getString("ownerName"));
        row.createCell(1).setCellValue(dataObj.getString("objName"));
        row.createCell(2).setCellValue(dataObj.getString("ownerLink"));
        row.createCell(3).setCellValue(dataObj.getString("builtUpArea"));
        row.createCell(4).setCellValue(dataObj.getString("feeTypeCdName"));
        row.createCell(5).setCellValue(dataObj.getString("feeName"));
        for (int detailIndex = 0; detailIndex < reportFeeYearCollectionDetails.size(); detailIndex++) {
            row.createCell(6 + detailIndex).setCellValue(reportFeeYearCollectionDetails.get(detailIndex).getReceivedAmount());
        }
    }
 
    //车辆费台账
    private void appendCarData(JSONObject dataObj, Sheet sheet, int step, int index) {
        Row row = null;
        row = sheet.createRow(index + step + 1);
        ReportFeeYearCollectionDetailDto reportFeeYearCollectionDetailDto = new ReportFeeYearCollectionDetailDto();
        reportFeeYearCollectionDetailDto.setCollectionId(dataObj.getString("collectionId"));
        List<ReportFeeYearCollectionDetailDto> reportFeeYearCollectionDetails =
                reportFeeYearCollectionDetailInnerServiceSMOImpl.queryReportFeeYearCollectionDetails(reportFeeYearCollectionDetailDto);
        row.createCell(0).setCellValue(dataObj.getString("ownerName"));
        row.createCell(1).setCellValue(dataObj.getString("objName"));
        row.createCell(2).setCellValue(dataObj.getString("ownerLink"));
        row.createCell(3).setCellValue(dataObj.getString("feeTypeCdName"));
        row.createCell(4).setCellValue(dataObj.getString("feeName"));
        for (int detailIndex = 0; detailIndex < reportFeeYearCollectionDetails.size(); detailIndex++) {
            row.createCell(5 + detailIndex).setCellValue(reportFeeYearCollectionDetails.get(detailIndex).getReceivedAmount());
        }
    }
}