futian.liu
2023-12-01 79a57e0844bdd3b5f06ebaac807a0896624be70f
consum-base/src/main/java/com/consum/base/controller/LWhFormScrappedController.java
@@ -168,51 +168,41 @@
        return ResponseValue.success(pageUtil);
    }
    /**
     * @Description 导出报废登记单
     * @Author 卢庆阳
     * @Date 2023/11/2
     */
    @ApiOperation(value = "导出报废单", notes = "导出报废单")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "id", value = "报废单id", dataType = "Long", paramType = "query")
    })
    @GetMapping("/list/export")
    public void export(Long id, HttpServletResponse response) {
    public void export(Long id, HttpServletResponse response) throws Exception {
        if (id == null) {
            throw new RuntimeException("报废单id为空");
        }
        try {
            OutputStream outputStream = response.getOutputStream();
            List<ScrappedInfoExcelTemplate> export = lWhFormScrappedService.export(id);
            if (CollectionUtils.isEmpty(export)) {
                throw new RuntimeException("数据为空");
            }
            TemplateExportParams exportParams = new TemplateExportParams("import/报废登记单.xlsx");
            exportParams.setHeadingStartRow(2);
            Optional<ScrappedInfoExcelTemplate> first = export.stream().findFirst();
            ScrappedInfoExcelTemplate scrappedInfoExcelTemplate = first.get();
            Long dealTime = scrappedInfoExcelTemplate.getDealTime();
            String operatorName = scrappedInfoExcelTemplate.getOperatorName();
            String businessFormCode = scrappedInfoExcelTemplate.getBusinessFormCode();
            int countNum = export.stream().filter(item -> item.getNum() != null).mapToInt(ScrappedInfoExcelTemplate::getNum).sum();
            int totalAmount = export.stream().filter(item -> item.getTotalAmount() != null).mapToInt(ScrappedInfoExcelTemplate::getTotalAmount).sum();
            Map<String, Object> map = new HashMap<>();
            map.put("code", businessFormCode);
            map.put("date", DateUtils.toShowDate(dealTime));
            map.put("name", operatorName);
            map.put("countNum", countNum);
            map.put("totalAmount", totalAmount);
            Workbook sheets = ExcelExportUtil.exportExcel(exportParams, ScrappedInfoExcelTemplate.class, export, map);
            // 设置响应头
            response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8");
            response.setHeader("Content-disposition", "attachment;filename=" + URLEncoder.encode("报废单登记.xlsx", "utf-8"));
            sheets.write(outputStream);
            sheets.close();
        } catch (IOException e) {
            throw new RuntimeException(e);
        List<ScrappedInfoExcelTemplate> export = lWhFormScrappedService.export(id);
        if (CollectionUtils.isEmpty(export)) {
            throw new RuntimeException("数据为空");
        }
        TemplateExportParams exportParams = new TemplateExportParams("import/报废登记单.xlsx");
        exportParams.setHeadingStartRow(2);
        Optional<ScrappedInfoExcelTemplate> first = export.stream().findFirst();
        ScrappedInfoExcelTemplate scrappedInfoExcelTemplate = first.get();
        Long dealTime = scrappedInfoExcelTemplate.getDealTime();
        String operatorName = scrappedInfoExcelTemplate.getOperatorName();
        String businessFormCode = scrappedInfoExcelTemplate.getBusinessFormCode();
        int countNum = export.stream().filter(item -> item.getNum() != null).mapToInt(ScrappedInfoExcelTemplate::getNum).sum();
        int totalAmount = export.stream().filter(item -> item.getTotalAmount() != null).mapToInt(ScrappedInfoExcelTemplate::getTotalAmount).sum();
        Map<String, Object> map = new HashMap<>();
        map.put("code", businessFormCode);
        map.put("date", DateUtils.toShowDate(dealTime));
        map.put("name", operatorName);
        map.put("countNum", countNum);
        map.put("totalAmount", totalAmount);
        Workbook sheets = ExcelExportUtil.exportExcel(exportParams, ScrappedInfoExcelTemplate.class, export, map);
        downLoadExcel("报废登记单", response, sheets);
    }