futian.liu
2023-11-30 86fdf3673cd8b3f34ed57a80556512cdcabdb202
consum-base/src/main/java/com/consum/base/controller/LWhFormScrappedController.java
@@ -1,14 +1,14 @@
package com.consum.base.controller;
import cn.afterturn.easypoi.excel.ExcelExportUtil;
import cn.afterturn.easypoi.excel.entity.ExportParams;
import cn.afterturn.easypoi.excel.entity.TemplateExportParams;
import com.consum.base.BaseController;
import com.consum.base.core.utils.CommonUtil;
import com.consum.base.core.utils.MapUtils;
import com.consum.base.core.utils.MapperUtil;
import com.consum.base.core.utils.PageUtil;
import com.consum.base.pojo.LWhFormScrappedParam;
import com.consum.base.pojo.excel.ScrappedInfoExport;
import com.consum.base.pojo.excel.ScrappedInfoExcelTemplate;
import com.consum.base.pojo.query.LWhFormScrappedQry;
import com.consum.base.pojo.response.FromTransferTemplateInfoVO;
import com.consum.base.pojo.response.LWhFormScrappedExtendVO;
@@ -17,25 +17,28 @@
import com.consum.model.po.FinSysTenantUser;
import com.consum.model.po.LWhFormScrapped;
import com.walker.infrastructure.utils.CollectionUtils;
import com.walker.infrastructure.utils.DateUtils;
import com.walker.web.ResponseValue;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.compress.utils.Lists;
import org.apache.poi.ss.usermodel.Workbook;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.OutputStream;
import java.net.URLEncoder;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.compress.utils.Lists;
import org.apache.poi.ss.usermodel.Workbook;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
 * @Description 报废单
@@ -188,16 +191,37 @@
     * @Author 卢庆阳
     * @Date 2023/11/2
     */
    @GetMapping("/export")
    public ResponseValue export(Long id, HttpServletRequest request, HttpServletResponse response) {
    @GetMapping("/list/export")
    public void export(Long id, HttpServletResponse response) {
        if (id == null) {
            return ResponseValue.error("报废单id为空");
            throw new RuntimeException("报废单id为空");
        }
        try {
            OutputStream outputStream = response.getOutputStream();
            List<Map<String, Object>> export = lWhFormScrappedService.export(id);
            ExportParams exportParams = new ExportParams("报废单登记", "报废单登记");
            Workbook sheets = ExcelExportUtil.exportExcel(exportParams, ScrappedInfoExport.class, export);
            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"));
@@ -206,7 +230,8 @@
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        return ResponseValue.success();
    }