CitReportController.java 12.3 KB
Newer Older
1 2
package pwc.taxtech.atms.controller;

kevin's avatar
kevin committed
3
import org.apache.commons.lang3.StringUtils;
4
import org.apache.poi.ss.usermodel.Workbook;
5 6
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
7 8 9 10
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
11
import pwc.taxtech.atms.common.message.ErrorMessage;
12 13
import pwc.taxtech.atms.constant.enums.EnumServiceType;
import pwc.taxtech.atms.dpo.ReportDto;
zhkwei's avatar
zhkwei committed
14
import pwc.taxtech.atms.dto.*;
15
import pwc.taxtech.atms.dto.periodReport.PeriodReportDataParam;
kevin's avatar
kevin committed
16
import pwc.taxtech.atms.dto.vatdto.ManualDataSourceDto;
zhkwei's avatar
zhkwei committed
17
import pwc.taxtech.atms.dto.vatdto.PeriodJobDto;
kevin's avatar
kevin committed
18
import pwc.taxtech.atms.dto.vatdto.ReportDataDto;
19
import pwc.taxtech.atms.service.impl.CitReportServiceImpl;
20 21
import pwc.taxtech.atms.service.impl.CitReportUploadService;
import pwc.taxtech.atms.service.impl.ReportUploadService;
zhkwei's avatar
zhkwei committed
22
import pwc.taxtech.atms.vat.entity.PeriodJob;
23
import pwc.taxtech.atms.vat.entity.ReportUpload;
24 25
import pwc.taxtech.atms.vat.service.impl.ReportServiceImpl;

26
import javax.servlet.http.HttpServletResponse;
27
import java.io.ByteArrayOutputStream;
zhkwei's avatar
zhkwei committed
28
import java.io.OutputStream;
29 30 31
import java.util.List;
import java.util.Optional;

32 33 34
import static javax.servlet.http.HttpServletResponse.SC_NO_CONTENT;
import static javax.servlet.http.HttpServletResponse.SC_OK;

35 36 37 38 39
/**
 * @author zhikai.z.wei
 * @description CIT报表生成(数据处理)
 */
@RestController
zhkwei's avatar
zhkwei committed
40
@RequestMapping(value = "/api/v1/citReport/")
41
public class CitReportController {
42 43
    private static Logger logger = LoggerFactory.getLogger(CitReportController.class);

44
    @Autowired
kevin's avatar
kevin committed
45
    CitReportServiceImpl reportService;
46 47
    @Autowired
    CitReportServiceImpl citReportService;
48 49
    @Autowired
    CitReportUploadService citReportUploadService;
50 51 52

    /**
     * 获取CIT所有要生成的报表模板相关信息,
53
     * 注意CIT不存在月份期间,默认为0
54 55 56 57 58 59
     * @param projectId
     * @param serviceType
     * @return
     */
    @RequestMapping(value = "citTemplate/{projectId}/{serviceType}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public OperationResultDto<List<ReportDto>> getCitTemplate(@PathVariable String projectId, @PathVariable int serviceType) {
60
        logger.info("获取CIT所有要生成的报表模板相关信息,参数");
61
        return citReportService.getReportTemplate(projectId, EnumServiceType.getEnumByCode(serviceType),0);
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
    }

    /**
     * 生成CIT所有的报表
     * @param projectId
     * @param generator
     * @param mergeManual
     * @return
     */
    @RequestMapping(value = "generateByTotal/{projectId}/{mergeManual}", method = RequestMethod.POST,
            produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public ResponseEntity generateAllData(@PathVariable String projectId,
                                          @RequestParam Optional<String> generator, @PathVariable Boolean mergeManual) {
        return ResponseEntity.ok(citReportService.generateCitData(projectId, EnumServiceType.CIT, mergeManual,0,null, generator));
    }

zhkwei's avatar
zhkwei committed
78 79 80 81
    /**
     * 生成CIT总分机构分配表
     * @return
     */
zhkwei's avatar
zhkwei committed
82 83
    @RequestMapping(value = "generateDistributionTable", method = RequestMethod.POST)
    public @ResponseBody ApiResultDto generateDistributionTable(@RequestBody CitDistributionDto citDistributionDto) {
zhkwei's avatar
zhkwei committed
84 85 86 87
        ApiResultDto apiResultDto = new ApiResultDto();
        try{
            apiResultDto.setCode(1);
            apiResultDto.setMessage("生成成功");
zhkwei's avatar
zhkwei committed
88
            apiResultDto.setData(citReportService.generateTotalBranchOrgDisTable(citDistributionDto.getProjectId()));
zhkwei's avatar
zhkwei committed
89 90 91 92 93 94 95 96 97
            return apiResultDto;
        }catch(Exception e){
            e.printStackTrace();
            apiResultDto.setCode(0);
            apiResultDto.setMessage("生成失败");
            return apiResultDto;
        }
    }

98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117
    /**
     * 生成CIT固资损失计算
     * @return
     */
    @RequestMapping(value = "generateAssetEamMapping", method = RequestMethod.POST)
    public @ResponseBody ApiResultDto generateAssetEamMapping(@RequestBody CitAssetsListDto citAssetsListDto) {
        ApiResultDto apiResultDto = new ApiResultDto();
        try{
            apiResultDto.setCode(1);
            apiResultDto.setMessage("生成成功");
            apiResultDto.setData(citReportService.generateAssetEamMapping(citAssetsListDto));
            return apiResultDto;
        }catch(Exception e){
            e.printStackTrace();
            apiResultDto.setCode(0);
            apiResultDto.setMessage("生成失败");
            return apiResultDto;
        }
    }

118 119 120 121 122 123 124
    /**
     * 获取当前卡片所拥有的模板
     * @param projectId
     * @param serviceType
     * @param period
     * @return
     */
125 126 127 128 129
    @RequestMapping(value = "filterTemplate/{projectId}/{serviceType}/{period}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public OperationResultDto<List<ReportDto>> getFilterTemplate(@PathVariable String projectId, @PathVariable int serviceType, @PathVariable Integer period) {
        return citReportService.getFilterReportTemplate(projectId, EnumServiceType.getEnumByCode(serviceType), period);
    }

130 131 132 133 134 135
    /**
     * 获取当前卡片的线程任务
     * @param projectId
     * @param period
     * @return
     */
zhkwei's avatar
zhkwei committed
136 137 138 139 140 141 142 143 144 145 146
    @RequestMapping(value = "getPeriodJob/{projectId}/{period}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ResponseBody
    public PeriodJobDto getPeriodJob(@PathVariable String projectId, @PathVariable Integer period) {
        PeriodJob job = citReportService.getPeriodJob(projectId, period);
        if (job != null) {
            return new PeriodJobDto().copyFromPeriodJob(job);
        } else {
            return null;
        }
    }

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
    /**
     * 获取固定资产及EAM Mapping的数据
     * @param citAssetsListDto
     * @return
     */
    @RequestMapping(value = "/getAssetEamMappingsPage", method = RequestMethod.POST)
    public @ResponseBody
    ApiResultDto getAssetEamMappingsPage(@RequestBody CitAssetsListDto citAssetsListDto){
        logger.info("获取固定资产及EAM Mapping的数据");
        ApiResultDto apiResultDto = new ApiResultDto();
        try{
            apiResultDto.setCode(1);
            apiResultDto.setMessage("获取成功");
            apiResultDto.setData(citReportService.getAssetEamMappingPage(citAssetsListDto));
            return apiResultDto;
        }catch(Exception e){
            e.printStackTrace();
            apiResultDto.setCode(0);
            apiResultDto.setMessage("获取失败");
            return apiResultDto;
        }
    }


    /**
172
     * 固定资产及EAM Mapping导出
173 174 175 176 177 178 179 180 181 182 183 184 185
     * @param paras
     * @param response
     */
    @RequestMapping(value = "exportAEMData", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public void exportAEMData(@RequestBody CitAssetsListDto paras, HttpServletResponse response) {
        int count = citReportService.exportAEMData2(paras, response);
        if (count == 0) {
            response.setStatus(SC_NO_CONTENT);
        } else {
            response.setStatus(SC_OK);
        }

    }
186 187 188

    /**
     * 获取  企业所得税汇总纳税分支机构所得税分配表(A202000)
zhkwei's avatar
zhkwei committed
189
     * @param citDistributionDto
190 191
     * @return
     */
zhkwei's avatar
zhkwei committed
192
    @RequestMapping(value = "/getDistributionTables", method = RequestMethod.POST)
193
    public @ResponseBody
zhkwei's avatar
zhkwei committed
194
    ApiResultDto getCitDistribution(@RequestBody CitDistributionDto citDistributionDto){
195 196 197 198 199
        logger.info("获取 企业所得税汇总纳税分支机构所得税分配表 的数据");
        ApiResultDto apiResultDto = new ApiResultDto();
        try{
            apiResultDto.setCode(1);
            apiResultDto.setMessage("获取成功");
zhkwei's avatar
zhkwei committed
200
            apiResultDto.setData(citReportService.getCitDistribution(citDistributionDto));
201 202 203 204 205 206 207 208
            return apiResultDto;
        }catch(Exception e){
            e.printStackTrace();
            apiResultDto.setCode(0);
            apiResultDto.setMessage("获取失败");
            return apiResultDto;
        }
    }
zhkwei's avatar
zhkwei committed
209 210 211 212 213 214 215 216 217 218 219 220 221
    /**
     * 固定资产及EAM Mapping导出
     * @param paras
     * @param response
     */
    @RequestMapping(value = "exportDTData", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public void exportDTData(@RequestBody CitDistributionDto paras, HttpServletResponse response) {
        int count = citReportService.exportDTData2(paras, response);
        if (count == 0) {
            response.setStatus(SC_NO_CONTENT);
        } else {
            response.setStatus(SC_OK);
        }
222

zhkwei's avatar
zhkwei committed
223
    }
224 225 226 227 228 229
    /**
     * 获取单元格相关数据
     * @param reportId
     * @param from
     * @return
     */
kevin's avatar
kevin committed
230 231 232 233 234 235 236 237 238
    @RequestMapping(value = "reportData/{reportId}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public OperationResultDto<ReportDataDto> getReportData(@PathVariable Long reportId, @RequestHeader String from) {
        OperationResultDto resultDto = new OperationResultDto();
        if (reportId == null || reportId == 0L) {
            resultDto.setResult(false);
            return resultDto;
        }
        return reportService.getCellData(reportId, from);
    }
239

240 241 242 243 244 245
    /**
     * 添加手工数据源
     * @param data
     * @param from
     * @return
     */
kevin's avatar
kevin committed
246 247 248 249 250 251 252 253
    @RequestMapping(value = "addCellManualData", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public ResponseEntity addCellManualDataSource(@RequestBody ManualDataSourceDto data, @RequestHeader String from) {
        String projectId = StringUtils.EMPTY;
        if (StringUtils.isNotBlank(from) && from.split("@").length > 0) {
            projectId = from.split("@")[0];
        }
        return ResponseEntity.ok(reportService.addCellManualDataSource(data, from));
    }
254

zhkwei's avatar
zhkwei committed
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
    @RequestMapping(value = "exportReportData/{projectId}/{period}", method = RequestMethod.POST,
            produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ResponseBody
    public void exportReportData(HttpServletResponse response, @RequestBody PeriodReportDataParam param,
                                 @PathVariable(name = "period", required = false) Integer period,
                                 @PathVariable(name = "projectId", required = false) String projectId) {
        OutputStream ouputStream = null;
        try {
            Workbook tWorkbook = citReportService.generateReportData(param.getReportIds(), projectId, period);
            response.setContentType("multipart/form-data");
//            response.setHeader("Content-Disposition", "attachment;fileName=" + new String(param.getFileName().getBytes("GB2312"), "ISO-8859-1"));
            ouputStream = response.getOutputStream();
            tWorkbook.write(ouputStream);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            try {
                if (ouputStream != null) {
                    ouputStream.close();
                }
            } catch (Exception e) {
                e.printStackTrace();
            }

        }

    }

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
    @RequestMapping(value = "uploadReportData/{projectId}/{period}", method = RequestMethod.POST,
            produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ResponseBody
    public OperationResultDto uploadReportData(@RequestBody PeriodReportDataParam param,
                                               @PathVariable(name = "period", required = false) Integer period,
                                               @PathVariable(name = "projectId", required = false) String projectId) {
        ByteArrayOutputStream bout = new ByteArrayOutputStream();
        try {
            Workbook tWorkbook = citReportService.generateReportData(param.getReportIds(), projectId, period);
            tWorkbook.write(bout);
            ReportUpload data = new ReportUpload();
            data.setProjectId(projectId);
            data.setPeriod(period);
            citReportUploadService.saveData(bout.toByteArray(), data);
            return OperationResultDto.success();
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            try {
                if (bout != null) {
                    bout.close();
                }
            } catch (Exception e) {
                e.printStackTrace();
            }

        }
        return OperationResultDto.error(ErrorMessage.SystemError);
    }

313
}