futian.liu
2023-12-01 79a57e0844bdd3b5f06ebaac807a0896624be70f
consum-base/src/main/java/com/consum/base/controller/LWhFormProcureController.java
@@ -14,6 +14,7 @@
import com.consum.base.pojo.LWhFormProcureGoodsInfoParam;
import com.consum.base.pojo.LWhFormProcureParam;
import com.consum.base.pojo.LWhProcureModelParam;
import com.consum.base.pojo.excel.ProcureExcelTemplate;
import com.consum.base.pojo.query.FormProcureQry;
import com.consum.base.pojo.response.FormProcureVO;
import com.consum.base.pojo.response.FromProcureTemplateInfoVO;
@@ -38,21 +39,20 @@
import com.iplatform.model.po.S_user_core;
import com.walker.db.page.GenericPager;
import com.walker.infrastructure.utils.CollectionUtils;
import com.walker.infrastructure.utils.DateUtils;
import com.walker.infrastructure.utils.NumberGenerator;
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 java.io.IOException;
import java.io.OutputStream;
import java.lang.reflect.Field;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
@@ -421,25 +421,41 @@
    }
    @ApiOperation(value = "采购单导出", notes = "采购单导出")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "id", value = "采购单id", required = true, dataType = "Long", paramType = "query")
    })
    @GetMapping("/list/export")
    public void export(Long id, HttpServletResponse response) throws IOException {
    public void export(Long id, HttpServletResponse response) throws Exception {
        TemplateExportParams params = new TemplateExportParams(
            "import/采购入库单.xls");
        params.setHeadingStartRow(2);
        FinSysTenantUser sysInfo = this.getSysInfo();
        String userName = sysInfo.getUserName();
        if (sysInfo == null) {
            throw new RuntimeException("登录用户信息不存在");
        }
        Map<String, Object> map = lWhFormProcureService.getExportList(id, userName);
        if (CollectionUtils.isEmpty(map)) {
        List<ProcureExcelTemplate> exportList = lWhFormProcureService.getExportList(id);
        if (CollectionUtils.isEmpty(exportList)) {
            throw new RuntimeException("数据为空");
        }
        Workbook workbook = ExcelExportUtil.exportExcel(params, map);
        try (OutputStream outputStream = response.getOutputStream()) {
            response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8");
            response.setHeader("Content-disposition", "attachment;filename=" + URLEncoder.encode("采购入库单.xls", "utf-8"));
            workbook.write(outputStream);
            workbook.close();
        }
        int countNum = exportList.stream().filter(item -> item.getNum() != null).mapToInt(ProcureExcelTemplate::getNum).sum();
        int totalAmount = exportList.stream().filter(export -> export.getTotalAmount() != null).mapToInt(ProcureExcelTemplate::getTotalAmount).sum();
        Optional<ProcureExcelTemplate> first = exportList.stream().findFirst();
        ProcureExcelTemplate templateExcelExport = first.get();
        String businessFormCode = templateExcelExport.getBusinessFormCode();
        Long createTime = templateExcelExport.getCreateTime();
        String operatorName = templateExcelExport.getOperatorName();
        Map<String, Object> map = new HashMap<>();
        map.put("code", businessFormCode);
        map.put("date", DateUtils.toShowDate(createTime));
        map.put("name", operatorName);
        map.put("countNum", countNum);
        map.put("totalAmount", totalAmount);
        Workbook workbook = ExcelExportUtil.exportExcel(params, ProcureExcelTemplate.class, exportList, map);
        downLoadExcel("采购入库单", response, workbook);
    }
}