futian.liu
2023-11-28 89495b208235d2e30244ce9485c75ac2f1690c79
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();
            }
        }
    }