futian.liu
2023-11-27 df34fa79f9616167babe07b0f63da6e9ddcc9620
consum-base/src/main/java/com/consum/base/controller/LWhFormOutputController.java
@@ -1,5 +1,7 @@
package com.consum.base.controller;
import cn.afterturn.easypoi.excel.ExcelExportUtil;
import cn.afterturn.easypoi.excel.entity.TemplateExportParams;
import cn.hutool.core.util.ReflectUtil;
import com.consum.base.BaseController;
import com.consum.base.core.utils.CommonUtil;
@@ -7,7 +9,11 @@
import com.consum.base.core.utils.MapperUtil;
import com.consum.base.pojo.LWhFormOutputParam;
import com.consum.base.pojo.query.LWhFormOutputQry;
import com.consum.base.pojo.response.*;
import com.consum.base.pojo.response.FormOutputGoodsVO;
import com.consum.base.pojo.response.FormOutputTemplateInfoVO;
import com.consum.base.pojo.response.FormOutputVO;
import com.consum.base.pojo.response.GoodsModelVO;
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;
@@ -17,24 +23,31 @@
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.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.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.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;
import javax.annotation.Resource;
import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
 * @Description 出库单
@@ -190,8 +203,75 @@
        if (currentUser == null) {
            return ResponseValue.error("登录用户信息不存在");
        }
        GenericPager<Map<String, Object>> mapGenericPager = lWarehouseFlowService.queryBusinessFlowDetail(formOutputQry);
        return ResponseValue.success(mapGenericPager);
        GenericPager<Map<String, Object>> 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");
        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);
        }
        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);
        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();
        }
    }
}