//package com.slcf.controller;
|
//
|
//import com.alibaba.excel.context.AnalysisContext;
|
//import com.alibaba.excel.event.AnalysisEventListener;
|
//import com.core.common.SpringUtils;
|
//import com.core.exception.CoolException;
|
//import com.zy.asrs.entity.MatCode;
|
//import com.zy.asrs.service.MatCodeService;
|
//import com.zy.asrs.utils.VersionUtils;
|
//import org.slf4j.Logger;
|
//import org.slf4j.LoggerFactory;
|
//
|
//import java.util.ArrayList;
|
//import java.util.Date;
|
//import java.util.List;
|
//import java.util.Map;
|
//
|
///**
|
// * Created by vincent on 2019-11-25
|
// */
|
//public class MatCodeExcelListener extends AnalysisEventListener<MatCodeExcel> {
|
//
|
// private static final Logger LOGGER = LoggerFactory.getLogger(com.zy.common.utils.excel.matcode.MatCodeExcelListener.class);
|
//
|
// private int total = 0;
|
// private Long userId;
|
//
|
// public MatCodeExcelListener() {
|
// }
|
//
|
// public MatCodeExcelListener(Long userId) {
|
// this.userId = userId;
|
// }
|
//
|
// /**
|
// * 每隔5条存储数据库,实际使用中可以3000条,然后清理list ,方便内存回收
|
// */
|
// private static final int BATCH_COUNT = 50;
|
//
|
// private final List<MatCode> list = new ArrayList<>();
|
//
|
// /**
|
// * 这里会一行行的返回头
|
// */
|
// @Override
|
// public void invokeHeadMap(Map<Integer, String> headMap, AnalysisContext context) {
|
// }
|
//
|
// /**
|
// * 这个每一条数据解析都会来调用
|
// */
|
// @Override
|
// public void invoke(MatCodeExcel data, AnalysisContext ctx) {
|
// MatCodeService matCodeService = SpringUtils.getBean(MatCodeService.class);
|
// if (matCodeService.selectById(data.getMatNo()) == null) {
|
// MatCode matCode = new MatCode();
|
// VersionUtils.setMatCode(matCode, data);
|
// matCode.setModiTime(new Date());
|
// matCode.setModiUser(this.userId);
|
// matCode.setAppeTime(new Date());
|
// matCode.setAppeUser(this.userId);
|
// if (!matCodeService.insert(matCode)) {
|
// throw new CoolException("导入数据异常");
|
// } else {
|
// System.out.println("===>> "+total);
|
// }
|
// total ++;
|
// }
|
// // 达到BATCH_COUNT了,需要去存储一次数据库,防止数据几万条数据在内存,容易OOM
|
//// if (list.size() >= BATCH_COUNT) {
|
////
|
//// // 存储完成清理 list
|
//// list.clear();
|
//// }
|
// }
|
//
|
// /**
|
// * 所有数据解析完成了调用
|
// * 适合事务
|
// */
|
// @Override
|
// public void doAfterAllAnalysed(AnalysisContext ctx) {
|
// LOGGER.info("新增{}条物料信息!", total);
|
// }
|
//
|
// public int getTotal() {
|
// return total;
|
// }
|
//}
|