自动化立体仓库 - WMS系统
zhangchao
2024-11-04 4660b2e57c53fa6b798c104abbe4a6b0ad4b6a97
src/main/java/com/zy/asrs/controller/ReportDownloadController.java
@@ -8,7 +8,9 @@
import com.core.common.DateUtils;
import com.core.common.R;
import com.zy.asrs.entity.AgvWrkMastLog;
import com.zy.asrs.entity.ViewInOutBean;
import com.zy.asrs.entity.ViewWorkCountInView;
import com.zy.asrs.entity.ViewWorkInBean;
import com.zy.asrs.mapper.ReportQueryMapper;
import com.zy.asrs.service.AgvWrkMastLogService;
import com.zy.common.web.BaseController;
@@ -41,7 +43,7 @@
     *
     * @since 2.1.1
     */
    @GetMapping("/in")
    @GetMapping("/countIn")
    public void download1(HttpServletResponse response,
                          @RequestParam Map<String, Object> param) throws IOException {
        try {
@@ -85,7 +87,7 @@
     *
     * @since 2.1.1
     */
    @RequestMapping("/out")
    @RequestMapping("/countOut")
    public void download2(HttpServletResponse response,
                          @RequestParam Map<String, Object> param) throws IOException {
        try {
@@ -178,4 +180,67 @@
            }
        }
    }
    /**
     * 文件下载并且失败的时候返回json(默认失败了会返回一个有部分数据的Excel)
     * 日出库明细统计
     *
     * @since 2.1.1
     */
    @RequestMapping("/out")
    public void out(HttpServletResponse response,
                          @RequestParam ViewWorkInBean bean) throws IOException {
        try {
            response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
            response.setCharacterEncoding("utf-8");
            // 这里URLEncoder.encode可以防止中文乱码 当然和easyexcel没有关系
            String fileName = URLEncoder.encode("日出库明细统计", "UTF-8").replaceAll("\\+", "%20");
            response.setHeader("Content-disposition", "attachment;filename*=utf-8''" + fileName + ".xlsx");
            List<ViewWorkInBean> list = reportQueryMapper.queryViewWorkOutList(bean);
            // 这里需要设置不关闭流
            EasyExcel.write(response.getOutputStream(), ViewWorkCountInView.class).autoCloseStream(Boolean.FALSE).sheet("sheet1")
                    .doWrite(list);
        } catch (Exception e) {
            // 重置response
            response.reset();
            response.setContentType("application/json");
            response.setCharacterEncoding("utf-8");
            Map<String, String> map = new HashMap<>();
            map.put("status", "failure");
            map.put("message", "下载文件失败" + e.getMessage());
            response.getWriter().println(JSON.toJSONString(map));
        }
    }
    /**
     * 文件下载并且失败的时候返回json(默认失败了会返回一个有部分数据的Excel)
     * 日入库明细统计
     *
     * @since 2.1.1
     */
    @RequestMapping("/in")
    public void in(HttpServletResponse response,
                    @RequestParam ViewWorkInBean bean) throws IOException {
        try {
            response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
            response.setCharacterEncoding("utf-8");
            // 这里URLEncoder.encode可以防止中文乱码 当然和easyexcel没有关系
            String fileName = URLEncoder.encode("日入库明细统计", "UTF-8").replaceAll("\\+", "%20");
            response.setHeader("Content-disposition", "attachment;filename*=utf-8''" + fileName + ".xlsx");
            List<ViewWorkInBean> list = reportQueryMapper.queryViewWorkInList(bean);
            // 这里需要设置不关闭流
            EasyExcel.write(response.getOutputStream(), ViewWorkCountInView.class).autoCloseStream(Boolean.FALSE).sheet("sheet1")
                    .doWrite(list);
        } catch (Exception e) {
            // 重置response
            response.reset();
            response.setContentType("application/json");
            response.setCharacterEncoding("utf-8");
            Map<String, String> map = new HashMap<>();
            map.put("status", "failure");
            map.put("message", "下载文件失败" + e.getMessage());
            response.getWriter().println(JSON.toJSONString(map));
        }
    }
}