#
luxiaotao1123
2020-06-06 1185b9fa3a42b47116403c581b892ec54503a778
#
1个文件已添加
1 文件已重命名
2个文件已删除
2个文件已修改
194 ■■■■ 已修改文件
src/main/java/com/zy/asrs/controller/MatCodeController.java 6 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/zy/common/utils/excel/EnInitData.java 54 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/zy/common/utils/excel/ExcelUtils.java 41 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/zy/common/utils/excel/matcode/MatCodeExcel.java 79 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/zy/common/utils/excel/matcode/MatCodeExcelListener.java 10 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/zy/common/web/FileController.java 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/zy/asrs/controller/MatCodeController.java
@@ -13,8 +13,8 @@
import com.core.common.R;
import com.zy.asrs.entity.MatCode;
import com.zy.asrs.service.MatCodeService;
import com.zy.common.utils.excel.EnInitData;
import com.zy.common.utils.excel.EnInitDataListener;
import com.zy.common.utils.excel.matcode.MatCodeExcelListener;
import com.zy.common.utils.excel.matcode.MatCodeExcel;
import com.zy.common.web.BaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
@@ -114,7 +114,7 @@
    @ManagerAuth
    public R matCodeImport(MultipartFile file) throws IOException, InterruptedException {
        Thread.sleep(2000);
//        EasyExcel.read(file.getInputStream(), EnInitData.class, new EnInitDataListener()).sheet().doRead();
        EasyExcel.read(file.getInputStream(), MatCodeExcel.class, new MatCodeExcelListener()).sheet().doRead();
        return R.ok();
    }
src/main/java/com/zy/common/utils/excel/EnInitData.java
File was deleted
src/main/java/com/zy/common/utils/excel/ExcelUtils.java
File was deleted
src/main/java/com/zy/common/utils/excel/matcode/MatCodeExcel.java
New file
@@ -0,0 +1,79 @@
package com.zy.common.utils.excel.matcode;
import com.alibaba.excel.annotation.ExcelProperty;
/**
 * Created by vincent on 2020/6/6
 */
public class MatCodeExcel {
    /**
     * 物料编码
     */
    @ExcelProperty(value = "物料编码", index = 0)
    private String matNo;
    /**
     * 条码
     */
    @ExcelProperty(value = "条码", index = 1)
    private String barcode;
    /**
     * 物料名称
     */
    @ExcelProperty(value = "物料名称", index = 2)
    private String matName;
    /**
     * 物料单位
     */
    @ExcelProperty(value = "物料单位", index = 3)
    private String str1;
    /**
     * 物料规格
     */
    @ExcelProperty(value = "物料规格", index = 4)
    private String str2;
    public String getMatNo() {
        return matNo;
    }
    public void setMatNo(String matNo) {
        this.matNo = matNo;
    }
    public String getBarcode() {
        return barcode;
    }
    public void setBarcode(String barcode) {
        this.barcode = barcode;
    }
    public String getMatName() {
        return matName;
    }
    public void setMatName(String matName) {
        this.matName = matName;
    }
    public String getStr1() {
        return str1;
    }
    public void setStr1(String str1) {
        this.str1 = str1;
    }
    public String getStr2() {
        return str2;
    }
    public void setStr2(String str2) {
        this.str2 = str2;
    }
}
src/main/java/com/zy/common/utils/excel/matcode/MatCodeExcelListener.java
File was renamed from src/main/java/com/zy/common/utils/excel/EnInitDataListener.java
@@ -1,4 +1,4 @@
package com.zy.common.utils.excel;
package com.zy.common.utils.excel.matcode;
import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
@@ -13,16 +13,16 @@
/**
 * Created by vincent on 2019-11-25
 */
public class EnInitDataListener extends AnalysisEventListener<EnInitData> {
public class MatCodeExcelListener extends AnalysisEventListener<MatCodeExcel> {
    private static final Logger LOGGER = LoggerFactory.getLogger(EnInitDataListener.class);
    private static final Logger LOGGER = LoggerFactory.getLogger(MatCodeExcelListener.class);
    /**
     * 每隔5条存储数据库,实际使用中可以3000条,然后清理list ,方便内存回收
     */
    private static final int BATCH_COUNT = 5;
    private List<EnInitData> list = new ArrayList<>();
    private List<MatCodeExcel> list = new ArrayList<>();
    /**
     * 这里会一行行的返回头
@@ -36,7 +36,7 @@
     * 这个每一条数据解析都会来调用
     */
    @Override
    public void invoke(EnInitData data, AnalysisContext ctx) {
    public void invoke(MatCodeExcel data, AnalysisContext ctx) {
        LOGGER.info("解析到一条数据:{}", JSON.toJSONString(data));
        list.add(data);
        // 达到BATCH_COUNT了,需要去存储一次数据库,防止数据几万条数据在内存,容易OOM
src/main/java/com/zy/common/web/FileController.java
@@ -2,7 +2,7 @@
import com.alibaba.excel.EasyExcel;
import com.zy.common.utils.excel.EnInitData;
import com.zy.common.utils.excel.EnInitDataListener;
import com.zy.common.utils.excel.matcode.MatCodeExcelListener;
import com.zy.common.utils.excel.ExcelUtils;
import com.core.common.R;
import org.springframework.stereotype.Controller;
@@ -30,7 +30,7 @@
    @PostMapping("upload")
    @ResponseBody
    public R upload(MultipartFile file) throws IOException {
        EasyExcel.read(file.getInputStream(), EnInitData.class, new EnInitDataListener()).sheet().doRead();
        EasyExcel.read(file.getInputStream(), EnInitData.class, new MatCodeExcelListener()).sheet().doRead();
        return R.ok();
    }