From 89495b208235d2e30244ce9485c75ac2f1690c79 Mon Sep 17 00:00:00 2001 From: futian.liu <liufutianyoo@163.com> Date: 星期二, 28 十一月 2023 20:48:08 +0800 Subject: [PATCH] 部门分发 --- consum-base/src/main/java/com/consum/base/controller/LWhFormOutputController.java | 100 ++++++++++++++++++++------------------------------ 1 files changed, 40 insertions(+), 60 deletions(-) diff --git a/consum-base/src/main/java/com/consum/base/controller/LWhFormOutputController.java b/consum-base/src/main/java/com/consum/base/controller/LWhFormOutputController.java index 2b87db8..4cceb53 100644 --- a/consum-base/src/main/java/com/consum/base/controller/LWhFormOutputController.java +++ b/consum-base/src/main/java/com/consum/base/controller/LWhFormOutputController.java @@ -7,6 +7,7 @@ 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.LWhFormOutputParam; import com.consum.base.pojo.query.LWhFormOutputQry; import com.consum.base.pojo.response.FormOutputGoodsVO; @@ -16,34 +17,34 @@ import com.consum.base.pojo.response.LWhFormOutputExtendVO; import com.consum.base.service.LWarehouseFlowService; import com.consum.base.service.LWhFormOutputServiceImpl; -import com.consum.base.service.LWhGoodsService; import com.consum.base.service.LWhProcureModelService; import com.consum.model.po.FinSysTenantUser; import com.consum.model.po.LWhFormOutput; 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.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.ByteArrayOutputStream; import java.io.IOException; +import java.io.InputStream; import java.io.OutputStream; import java.lang.reflect.Field; import java.net.URLEncoder; -import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import javax.annotation.Resource; -import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.commons.compress.utils.Lists; +import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.poi.ss.usermodel.Workbook; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.core.io.ClassPathResource; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; @@ -63,8 +64,6 @@ private LWhFormOutputServiceImpl lWhFormOutputService; @Autowired private LWhProcureModelService lWhProcureModelService; - @Autowired - private LWhGoodsService lWhGoodsService; @Resource private LWarehouseFlowService lWarehouseFlowService; @@ -203,74 +202,55 @@ if (currentUser == null) { return ResponseValue.error("鐧诲綍鐢ㄦ埛淇℃伅涓嶅瓨鍦�"); } - GenericPager<Map<String, Object>> genericPager = lWarehouseFlowService.queryAllBusinessFlow(formOutputQry); + PageUtil genericPager = lWarehouseFlowService.queryAllBusinessFlow(formOutputQry); return ResponseValue.success(genericPager); } @ApiOperation(value = "鍑哄簱鍗曞鍑�", notes = "鍑哄簱鍗曞鍑�") @GetMapping("/list/export") - public void export(Long id, HttpServletRequest request, HttpServletResponse response) throws IOException { - TemplateExportParams params = new TemplateExportParams( - "import/閲囪喘閫�璐у崟.xls"); + public void export(Long id, HttpServletResponse response) throws IOException { + ClassPathResource classPathResource = new ClassPathResource("import/閲囪喘閫�璐у崟.xls"); + // 鑾峰彇鏂囦欢杈撳叆娴� + InputStream inputStream = classPathResource.getInputStream(); + Workbook wb = new HSSFWorkbook(inputStream); + TemplateExportParams params = new TemplateExportParams(); + params.setTemplateWb(wb); FinSysTenantUser sysInfo = this.getSysInfo(); String userName = sysInfo.getUserName(); - String sql = "SELECT\n" - + "\tfo.BUSINESS_FORM_CODE,\n" - + "\tfo.AGENCY_NAME tenantName,\n" - + "\tGOODS_NAME goodsName,\n" - + "\tpm.BASE_GOODS_MODELS_NAME goodsModeName,\n" - + "\tcounts num,\n" - + "\ttotal_amount sqje,\n" - + "\tBEIZ remark\n" - + "FROM\n" - + "\tl_wh_procure_model pm\n" - + "\tLEFT JOIN base_goods_models bgm ON pm.BASE_GOODS_MODELS_ID = bgm.id\n" - + "\tLEFT JOIN base_goods_template bgt ON bgm.GOODS_TEMPLATES_ID = bgt.id\n" - + "\tLEFT JOIN l_wh_form_output fo ON fo.ID = pm.BUSINESS_ID\n" - + "WHERE\n" - + "\tpm.BUSINESS_ID = 1393373943914496"; - - Map<String, Object> param = new HashMap<>(); - param.put("id", id); - List<Map<String, Object>> select = lWhFormOutputService.select(sql, param, new MapperUtil()); - - String dateForHuman = DateUtils.getDateForHuman(System.currentTimeMillis()); - Map<String, Object> map = new HashMap<>(); - //鑾峰彇select涓殑BUSINESS_FORM_CODE鍊硷紝 - for (Map<String, Object> item : select) { - String businessFormCode = (String) item.get("businessFormCode"); - map.put("code", businessFormCode); - Object num = item.get("num"); - map.put("numCount", 100); - map.put("amountCount", 100); + Map<String, Object> map = lWhFormOutputService.getExportList(id, userName); + if (CollectionUtils.isEmpty(map)) { + throw new RuntimeException("鏁版嵁涓虹┖"); } - List<Map<String, String>> listMap = new ArrayList<>(); - map.put("code", "璐颁桨涓�"); - map.put("date", dateForHuman); - map.put("name", userName); -// for (int i = 0; i < 4; i++) { -// Map<String, String> lm = new HashMap<>(); -// lm.put("tenantName", i + 1 + ""); -// lm.put("goodsName", "A001"); -// lm.put("goodsModeName", "璁捐"); -// lm.put("num", "EasyPoi " + i + "鏈�"); -// lm.put("price", "寮�婧愰」鐩�"); -// lm.put("sqje", i * 10000 + ""); -// lm.put("remark", i * 10000 + ""); -// listMap.add(lm); -// } - map.put("maplist", select); Workbook workbook = ExcelExportUtil.exportExcel(params, map); + downLoadExcel("111", response, workbook); - 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(); +// try (OutputStream outputStream = response.getOutputStream()) { +// response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8"); +// response.setHeader("Content-disposition", "attachment;filename=" + URLEncoder.encode("閲囪喘閫�璐у崟1.xlsx", "utf-8")); +// workbook.write(outputStream); +// workbook.close(); +// } + } + + private void downLoadExcel(String fileName, HttpServletResponse response, Workbook workbook) throws IOException { + try (OutputStream out = response.getOutputStream()) { + response.setCharacterEncoding("UTF-8"); + response.setHeader("content-Type", "application/vnd.ms-excel"); + response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(fileName + ".xls", "UTF-8")); + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + workbook.write(baos); + response.setHeader("Content-Length", String.valueOf(baos.size())); + out.write(baos.toByteArray()); + } catch (Exception e) { + try { + throw new Exception(e.getMessage()); + } catch (Exception e1) { + e1.printStackTrace(); + } } } -- Gitblit v1.9.1