自动化立体仓库 - WMS系统
pang.jiabao
2024-04-18 cddfcdf68ff7fff6b1be82bc5edf822458de6749
商品档案全量导出修改
3个文件已修改
161 ■■■■ 已修改文件
src/main/java/com/zy/asrs/controller/MatController.java 69 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/zy/asrs/entity/Mat.java 59 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/webapp/static/js/mat/mat.js 33 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/zy/asrs/controller/MatController.java
@@ -1,6 +1,8 @@
package com.zy.asrs.controller;
import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.ExcelWriter;
import com.alibaba.excel.write.metadata.WriteSheet;
import com.alibaba.excel.write.style.column.LongestMatchColumnWidthStyleStrategy;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
@@ -25,6 +27,7 @@
import com.zy.common.utils.BarcodeUtils;
import com.zy.common.utils.QrCode;
import com.zy.common.web.BaseController;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;
@@ -34,10 +37,12 @@
import javax.servlet.http.HttpServletResponse;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.io.OutputStream;
import java.net.URLEncoder;
import java.util.*;
@RestController
@Slf4j
public class MatController extends BaseController {
    @Autowired
@@ -179,13 +184,63 @@
    @RequestMapping(value = "/mat/export/auth")
    @ManagerAuth
    public R export(@RequestBody JSONObject param){
        EntityWrapper<Mat> wrapper = new EntityWrapper<>();
        List<String> fields = JSONObject.parseArray(param.getJSONArray("fields").toJSONString(), String.class);
        Map<String, Object> map = excludeTrash(param.getJSONObject("mat"));
        convert(map, wrapper);
        List<Mat> list = matService.selectList(wrapper);
        return R.ok(exportSupport(list, fields));
    public void export(@RequestBody JSONObject param, HttpServletResponse response) throws IOException {
        //文件名
        String fileName =String.valueOf(System.currentTimeMillis());
        OutputStream outputStream =null;
        try {
            //记录总数:实际中需要根据查询条件进行统计即可:一共多少条
            int totalCount=matService.selectCount(null);
            //每一个Sheet存放100w条数据
            Integer sheetDataRows = 400000;
            //每次写入的数据量20w,每页查询20W
            Integer writeDataRows = 200000;
            //计算需要的Sheet数量
            Integer sheetNum = totalCount % sheetDataRows == 0 ? (totalCount / sheetDataRows) : (totalCount / sheetDataRows + 1);
            //计算一般情况下每一个Sheet需要写入的次数(一般情况不包含最后一个sheet,因为最后一个sheet不确定会写入多少条数据)
            Integer oneSheetWriteCount = sheetDataRows / writeDataRows;
            //计算最后一个sheet需要写入的次数
            Integer lastSheetWriteCount = totalCount % sheetDataRows == 0 ? oneSheetWriteCount : (totalCount % sheetDataRows % writeDataRows == 0 ? (totalCount / sheetDataRows / writeDataRows) : ((totalCount % sheetDataRows) / writeDataRows + 1));
            outputStream = response.getOutputStream();
            //必须放到循环外,否则会刷新流
            ExcelWriter excelWriter = EasyExcel.write(outputStream).build();
            //开始分批查询分次写入
            for (int i = 0; i < sheetNum; i++) {
                //创建Sheet
                WriteSheet sheet = new WriteSheet();
                sheet.setSheetName("Sheet"+i);
                sheet.setSheetNo(i);
                //循环写入次数: j的自增条件是当不是最后一个Sheet的时候写入次数为正常的每个Sheet写入的次数,如果是最后一个就需要使用计算的次数lastSheetWriteCount
                for (int j = 0; j < (i != sheetNum - 1 ? oneSheetWriteCount : lastSheetWriteCount); j++) {
                    //分页查询一次20w
                    Page page1 = new Page(j + 1 + oneSheetWriteCount * i, writeDataRows);
                    //查询分页列表---按照自己的业务查列表,分页这个一定要使用这个:page1.getPageNum(),page1.getPageSize()!!!
                    List<Mat> list = matService.selectPage(new Page<>(page1.getCurrent(), page1.getLimit())).getRecords();
//                    List<AltitudeMonExportExcelVO > SurfDayList = new ArrayList<>();
                    //写入到excel:
                    /**************z只需要选择一种方式即可*****************/
                    //这里可以通过设置includeColumnFiledNames、excludeColumnFiledNames导出什么字段,可以动态配置,前端传过来那些列,就导出那些列
                    //方式3、不做设置,全部导出
                    WriteSheet writeSheet = EasyExcel.writerSheet(i, "Sheet" + (i + 1)).head(Mat.class)
                            .registerWriteHandler(new LongestMatchColumnWidthStyleStrategy()).build();
                    excelWriter.write(list, writeSheet);
                }
            }
            // 下载EXCEL,返回给前段stream流
            response.setContentType("application/octet-stream");
            response.setCharacterEncoding("utf-8");
            response.setHeader("Content-disposition", "attachment;filename*=utf-8''" + fileName + ".xlsx");
            excelWriter.finish();
            outputStream.flush();
            outputStream.close();
        } catch (Exception e) {
            e.printStackTrace();
        }finally {
            if (outputStream != null) {
                outputStream.close();
            }
        }
    }
    @RequestMapping(value = "/matQuery/auth")
src/main/java/com/zy/asrs/entity/Mat.java
@@ -1,5 +1,6 @@
package com.zy.asrs.entity;
import com.alibaba.excel.annotation.ExcelIgnore;
import com.alibaba.excel.annotation.ExcelProperty;
import com.baomidou.mybatisplus.annotations.TableField;
import com.baomidou.mybatisplus.annotations.TableId;
@@ -23,6 +24,7 @@
@TableName("man_mat")
public class Mat implements Serializable {
    @ExcelIgnore
    @TableField(exist = false)
    private Double stock;
@@ -39,6 +41,7 @@
    /**
     * ID
     */
    @ExcelIgnore
    @ApiModelProperty(value= "ID")
    @TableId(value = "id", type = IdType.AUTO)
    private Long id;
@@ -46,6 +49,7 @@
    /**
     * 编号
     */
    @ExcelIgnore
    @ApiModelProperty(value= "编号")
    private String uuid;
@@ -54,6 +58,7 @@
     */
    @ApiModelProperty(value= "所属归类")
    @TableField("tag_id")
    @ExcelProperty(value = "归类")
    private Long tagId;
    /**
@@ -75,7 +80,7 @@
     * 别名
     */
    @ApiModelProperty(value= "别名")
    @ExcelProperty(value = "别名")
    @ExcelIgnore
    private String name;
    /**
@@ -89,14 +94,14 @@
     * 型号
     */
    @ApiModelProperty(value= "型号")
    @ExcelProperty(value = "型号")
    @ExcelIgnore
    private String model;
    /**
     * 颜色
     */
    @ApiModelProperty(value= "颜色")
    @ExcelProperty(value = "颜色")
    @ExcelIgnore
    private String color;
    /**
@@ -104,63 +109,63 @@
     */
    @ApiModelProperty(value= "类型")
//    @ApiModelProperty(value= "品牌")
    @ExcelProperty(value = "类型")
    @ExcelIgnore
    private String brand;
    /**
     * 单位
     */
    @ApiModelProperty(value= "单位")
    @ExcelProperty(value = "单位")
    @ExcelIgnore
    private String unit;
    /**
     * 单价
     */
    @ApiModelProperty(value= "单价")
    @ExcelProperty(value = "单价")
    @ExcelIgnore
    private Double price;
    /**
     * sku
     */
    @ApiModelProperty(value= "sku")
    @ExcelProperty(value = "sku")
    @ExcelIgnore
    private String sku;
    /**
     * 单位量
     */
    @ApiModelProperty(value= "单位量")
    @ExcelProperty(value = "单位量")
    @ExcelIgnore
    private Double units;
    /**
     * 条码
     */
    @ApiModelProperty(value= "条码")
    @ExcelProperty(value = "条码")
    @ExcelIgnore
    private String barcode;
    /**
     * 产地
     */
    @ApiModelProperty(value= "产地")
    @ExcelProperty(value = "产地")
    @ExcelIgnore
    private String origin;
    /**
     * 厂家
     */
    @ApiModelProperty(value= "厂家")
    @ExcelProperty(value = "厂家")
    @ExcelIgnore
    private String manu;
    /**
     * 生产日期
     */
    @ApiModelProperty(value= "生产日期")
    @ExcelProperty(value = "生产日期")
    @ExcelIgnore
    @TableField("manu_date")
    private String manuDate;
@@ -168,7 +173,7 @@
     * 品项数
     */
    @ApiModelProperty(value= "品项数")
    @ExcelProperty(value = "品项数")
    @ExcelIgnore
    @TableField("item_num")
    private String itemNum;
@@ -176,7 +181,7 @@
     * 安全库存量
     */
    @ApiModelProperty(value= "安全库存量")
    @ExcelProperty(value = "安全库存量")
    @ExcelIgnore
    @TableField("safe_qty")
    private Double safeQty;
@@ -184,28 +189,28 @@
     * 重量
     */
    @ApiModelProperty(value= "重量")
    @ExcelProperty(value = "重量")
    @ExcelIgnore
    private Double weight;
    /**
     * 长度
     */
    @ApiModelProperty(value= "长度")
    @ExcelProperty(value = "长度")
    @ExcelIgnore
    private Double length;
    /**
     * 体积
     */
    @ApiModelProperty(value= "体积")
    @ExcelProperty(value = "体积")
    @ExcelIgnore
    private Double volume;
    /**
     * 三方编码
     */
    @ApiModelProperty(value= "三方编码")
    @ExcelProperty(value = "三方编码")
    @ExcelIgnore
    @TableField("three_code")
    private String threeCode;
@@ -213,14 +218,14 @@
     * 供应商
     */
    @ApiModelProperty(value= "供应商")
    @ExcelProperty(value = "供应商")
    @ExcelIgnore
    private String supp;
    /**
     * 供应商编码
     */
    @ApiModelProperty(value= "供应商编码")
    @ExcelProperty(value = "供应商编码")
    @ExcelIgnore
    @TableField("supp_code")
    private String suppCode;
@@ -228,7 +233,7 @@
     * 是否批次 1: 是  0: 否
     */
    @ApiModelProperty(value= "是否批次 1: 是  0: 否  ")
    @TableField("be_batch")
    @ExcelIgnore
    private Integer beBatch;
    /**
@@ -236,7 +241,7 @@
     */
    @ApiModelProperty(value= "保质期")
    @TableField("dead_time")
    @ExcelProperty(value = "保质期")
    @ExcelIgnore
    private String deadTime;
    /**
@@ -244,36 +249,41 @@
     */
    @ApiModelProperty(value= "预警天数")
    @TableField("dead_warn")
    @ExcelProperty(value = "预警天数")
    @ExcelIgnore
    private Integer deadWarn;
    /**
     * 制购 1: 制造  2: 采购  3: 外协
     */
    @ExcelIgnore
    @ApiModelProperty(value= "制购 1: 制造  2: 采购  3: 外协  ")
    private Integer source;
    /**
     * 要求检验 1: 是  0: 否
     */
    @ExcelIgnore
    @ApiModelProperty(value= "要求检验 1: 是  0: 否  ")
    private Integer inspect;
    /**
     * 危险品 1: 是  0: 否
     */
    @ExcelIgnore
    @ApiModelProperty(value= "危险品 1: 是  0: 否  ")
    private Integer danger;
    /**
     * 状态 1: 正常  0: 禁用
     */
    @ExcelIgnore
    @ApiModelProperty(value= "状态 1: 正常  0: 禁用  ")
    private Integer status;
    /**
     * 添加人员
     */
    @ExcelIgnore
    @ApiModelProperty(value= "添加人员")
    @TableField("create_by")
    private Long createBy;
@@ -281,6 +291,7 @@
    /**
     * 添加时间
     */
    @ExcelIgnore
    @ApiModelProperty(value= "添加时间")
    @TableField("create_time")
    @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
@@ -289,6 +300,7 @@
    /**
     * 修改人员
     */
    @ExcelIgnore
    @ApiModelProperty(value= "修改人员")
    @TableField("update_by")
    private Long updateBy;
@@ -296,6 +308,7 @@
    /**
     * 修改时间
     */
    @ExcelIgnore
    @ApiModelProperty(value= "修改时间")
    @TableField("update_time")
    @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
src/main/webapp/static/js/mat/mat.js
@@ -167,18 +167,35 @@
                        url: baseUrl+"/mat/export/auth",
                        headers: {'token': localStorage.getItem('token')},
                        data: JSON.stringify(param),
                        dataType:'json',
                        // dataType:'json',
                        contentType:'application/json;charset=UTF-8',
                        method: 'POST',
                        xhrFields: {
                            responseType: "blob" // 设置响应类型为二进制数据
                        },
                        success: function (res) {
                            // 创建一个临时的下载链接
                            const url = window.URL.createObjectURL(res);
                            // 创建一个隐藏的 <a> 元素并设置下载链接
                            const a = document.createElement("a");
                            a.style.display = "none";
                            a.href = url;
                            a.download = "export.xlsx"; // 指定下载的文件名
                            document.body.appendChild(a);
                            // 触发点击事件以开始下载
                            a.click();
                            // 清理临时资源
                            setTimeout(function () {
                                window.URL.revokeObjectURL(url);
                                document.body.removeChild(a);
                                layer.closeAll();
                            }, 100);
                        },
                        fail: function (){
                            layer.msg('导出失败', {icon: 2})
                            layer.closeAll();
                            if (res.code === 200) {
                                table.exportFile(titles,res.data,'xls');
                            } else if (res.code === 403) {
                                top.location.href = baseUrl+"/";
                            } else {
                                layer.msg(res.msg)
                            }
                        }
                    });
                });