代码更新:
1.增加DBS和工单的导入
This commit is contained in:
parent
e7a061942f
commit
cfbc2a202d
|
|
@ -1,5 +1,6 @@
|
||||||
package com.wms.controller;
|
package com.wms.controller;
|
||||||
|
|
||||||
|
import cn.hutool.core.bean.BeanUtil;
|
||||||
import com.alibaba.excel.EasyExcel;
|
import com.alibaba.excel.EasyExcel;
|
||||||
import com.alibaba.excel.support.ExcelTypeEnum;
|
import com.alibaba.excel.support.ExcelTypeEnum;
|
||||||
import com.alibaba.excel.write.style.HorizontalCellStyleStrategy;
|
import com.alibaba.excel.write.style.HorizontalCellStyleStrategy;
|
||||||
|
|
@ -14,12 +15,11 @@ import com.wms.entity.app.vo.FileVo;
|
||||||
import com.wms.entity.table.*;
|
import com.wms.entity.table.*;
|
||||||
import com.wms.service.*;
|
import com.wms.service.*;
|
||||||
import com.wms.utils.StringUtils;
|
import com.wms.utils.StringUtils;
|
||||||
|
import com.wms.utils.excel.listener.UploadDbsListener;
|
||||||
|
import com.wms.utils.excel.listener.UploadKateOrdersListener;
|
||||||
import com.wms.utils.excel.listener.UploadStocksListener;
|
import com.wms.utils.excel.listener.UploadStocksListener;
|
||||||
import com.wms.utils.excel.style.ExcelContentStyle;
|
import com.wms.utils.excel.style.ExcelContentStyle;
|
||||||
import com.wms.utils.excel.vo.LocationExcelVo;
|
import com.wms.utils.excel.vo.*;
|
||||||
import com.wms.utils.excel.vo.StockExcelVo;
|
|
||||||
import com.wms.utils.excel.vo.TaskRecordExcelVo;
|
|
||||||
import com.wms.utils.excel.vo.VehicleExcelVo;
|
|
||||||
import jakarta.servlet.http.HttpServletRequest;
|
import jakarta.servlet.http.HttpServletRequest;
|
||||||
import jakarta.servlet.http.HttpServletResponse;
|
import jakarta.servlet.http.HttpServletResponse;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
|
|
@ -41,7 +41,6 @@ import java.util.List;
|
||||||
|
|
||||||
import static com.wms.utils.HttpUtils.getIpAddr;
|
import static com.wms.utils.HttpUtils.getIpAddr;
|
||||||
import static com.wms.utils.StringUtils.convertJsonString;
|
import static com.wms.utils.StringUtils.convertJsonString;
|
||||||
import static com.wms.utils.WmsUtils.generateId;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
|
@ -58,6 +57,10 @@ public class ExcelController {
|
||||||
private final VehicleService vehicleService;// 载具服务
|
private final VehicleService vehicleService;// 载具服务
|
||||||
private final LocationService locationService;// 库位服务
|
private final LocationService locationService;// 库位服务
|
||||||
private final UploadRecordService uploadRecordService;// 上传服务
|
private final UploadRecordService uploadRecordService;// 上传服务
|
||||||
|
private final KateDBSService kateDbsService;// Dbs服务
|
||||||
|
private final KateDBSLastService kateDbsLastService;// Dbs上次记录服务
|
||||||
|
private final KateOrdersService kateOrdersService;// 工单服务
|
||||||
|
private final KateOrdersLastService kateOrdersLastService;// 工单上次服务
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 导入库存信息
|
* 导入库存信息
|
||||||
|
|
@ -75,20 +78,84 @@ public class ExcelController {
|
||||||
// 导入excel
|
// 导入excel
|
||||||
EasyExcel.read(file.getInputStream(), StockExcelVo.class, new UploadStocksListener(stockService)).sheet().doRead();
|
EasyExcel.read(file.getInputStream(), StockExcelVo.class, new UploadStocksListener(stockService)).sheet().doRead();
|
||||||
// 添加导入记录
|
// 添加导入记录
|
||||||
UploadRecord uploadRecord = new UploadRecord();
|
uploadRecordService.save(UploadRecord.ofFileVo(fileVo, "库存"));
|
||||||
uploadRecord.setUploadId(generateId("UPLOAD_"));
|
|
||||||
uploadRecord.set
|
|
||||||
uploadRecordService.save(uploadRecord);
|
|
||||||
response.setCode(ResponseCode.OK.getCode());
|
response.setCode(ResponseCode.OK.getCode());
|
||||||
response.setMessage("导入库存成功。");
|
response.setMessage("导入库存成功。");
|
||||||
|
return convertJsonString(response);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logger.error("导入库存异常:{}", convertJsonString(e));
|
logger.error("导入库存异常:{}", convertJsonString(e));
|
||||||
// 回滚事务
|
// 回滚事务
|
||||||
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
||||||
response.setCode(ResponseCode.ERROR.getCode());
|
response.setCode(ResponseCode.ERROR.getCode());
|
||||||
response.setMessage("导入库存异常。");
|
response.setMessage("导入库存异常。");
|
||||||
|
return convertJsonString(response);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 导入DBS
|
||||||
|
*
|
||||||
|
* @param file 文件
|
||||||
|
* @return 导入结果
|
||||||
|
*/
|
||||||
|
@PostMapping("/uploadDbs")
|
||||||
|
@ResponseBody
|
||||||
|
@Transactional(isolation = Isolation.REPEATABLE_READ, propagation = Propagation.REQUIRED)
|
||||||
|
public String uploadDbs(@RequestPart("file") MultipartFile file, @RequestPart("obj") FileVo fileVo) {
|
||||||
|
logger.info("导入DBS,请求ip:{}", getIpAddr(servletRequest));
|
||||||
|
ResponseEntity response = new ResponseEntity();
|
||||||
|
try {
|
||||||
|
// 先移除之前last表中的内容
|
||||||
|
kateDbsLastService.remove(new LambdaQueryWrapper<>());
|
||||||
|
// 将当前Dbs表的数据存进Last表
|
||||||
|
kateDbsLastService.saveBatch(BeanUtil.copyToList(kateDbsService.list(), KateDBSLast.class));
|
||||||
|
// 移库Dbs表中的内容
|
||||||
|
kateDbsService.remove(new LambdaQueryWrapper<>());
|
||||||
|
// 导入excel
|
||||||
|
EasyExcel.read(file.getInputStream(), KateDbsExcelVo.class, new UploadDbsListener(kateDbsService, kateDbsLastService, fileVo.getUserName())).sheet().doRead();
|
||||||
|
// 添加导入记录
|
||||||
|
uploadRecordService.save(UploadRecord.ofFileVo(fileVo, "DBS"));
|
||||||
|
response.setCode(ResponseCode.OK.getCode());
|
||||||
|
response.setMessage("导入DBS成功。");
|
||||||
|
return convertJsonString(response);
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.error("导入DBS异常:{}", convertJsonString(e));
|
||||||
|
// 回滚事务
|
||||||
|
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
||||||
|
response.setCode(ResponseCode.ERROR.getCode());
|
||||||
|
response.setMessage("导入DBS异常。");
|
||||||
|
return convertJsonString(response);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 导入DBS
|
||||||
|
*
|
||||||
|
* @param file 文件
|
||||||
|
* @return 导入结果
|
||||||
|
*/
|
||||||
|
@PostMapping("/uploadKateOrders")
|
||||||
|
@ResponseBody
|
||||||
|
@Transactional(isolation = Isolation.REPEATABLE_READ, propagation = Propagation.REQUIRED)
|
||||||
|
public String uploadKateOrders(@RequestPart("file") MultipartFile file, @RequestPart("obj") FileVo fileVo) {
|
||||||
|
logger.info("导入工单,请求ip:{}", getIpAddr(servletRequest));
|
||||||
|
ResponseEntity response = new ResponseEntity();
|
||||||
|
try {
|
||||||
|
// 导入excel
|
||||||
|
EasyExcel.read(file.getInputStream(), KateOrdersExcelVo.class, new UploadKateOrdersListener(kateOrdersService, kateOrdersLastService, fileVo.getUserName())).sheet().doRead();
|
||||||
|
// 添加导入记录
|
||||||
|
uploadRecordService.save(UploadRecord.ofFileVo(fileVo, "ORDERS"));
|
||||||
|
response.setCode(ResponseCode.OK.getCode());
|
||||||
|
response.setMessage("导入工单成功。");
|
||||||
|
return convertJsonString(response);
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.error("导入工单异常:{}", convertJsonString(e));
|
||||||
|
// 回滚事务
|
||||||
|
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
||||||
|
response.setCode(ResponseCode.ERROR.getCode());
|
||||||
|
response.setMessage("导入工单异常。");
|
||||||
|
return convertJsonString(response);
|
||||||
}
|
}
|
||||||
return convertJsonString(response);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -19,22 +19,27 @@ public class UploadRecordQuery extends PageQuery {
|
||||||
/**
|
/**
|
||||||
* 上传id
|
* 上传id
|
||||||
*/
|
*/
|
||||||
@JsonProperty("upload_id")
|
@JsonProperty("uploadId")
|
||||||
private String uploadId;
|
private String uploadId;
|
||||||
/**
|
/**
|
||||||
* 文件id
|
* 文件id
|
||||||
*/
|
*/
|
||||||
@JsonProperty("file_id")
|
@JsonProperty("fileId")
|
||||||
private String fileId;
|
private String fileId;
|
||||||
/**
|
/**
|
||||||
* 文件名
|
* 文件名
|
||||||
*/
|
*/
|
||||||
@JsonProperty("file_name")
|
@JsonProperty("fileName")
|
||||||
private String fileName;
|
private String fileName;
|
||||||
|
/**
|
||||||
|
* 文件描述
|
||||||
|
*/
|
||||||
|
@JsonProperty("fileDescription")
|
||||||
|
private String fileDescription;
|
||||||
/**
|
/**
|
||||||
* 文件类型
|
* 文件类型
|
||||||
*/
|
*/
|
||||||
@JsonProperty("file_type")
|
@JsonProperty("fileType")
|
||||||
private String fileType;
|
private String fileType;
|
||||||
/**
|
/**
|
||||||
* 上传时间
|
* 上传时间
|
||||||
|
|
|
||||||
|
|
@ -17,22 +17,27 @@ public class UploadRecordVo {
|
||||||
/**
|
/**
|
||||||
* 上传id
|
* 上传id
|
||||||
*/
|
*/
|
||||||
@JsonProperty("upload_id")
|
@JsonProperty("uploadId")
|
||||||
private String uploadId;
|
private String uploadId;
|
||||||
/**
|
/**
|
||||||
* 文件id
|
* 文件id
|
||||||
*/
|
*/
|
||||||
@JsonProperty("file_id")
|
@JsonProperty("fileId")
|
||||||
private String fileId;
|
private String fileId;
|
||||||
/**
|
/**
|
||||||
* 文件名
|
* 文件名
|
||||||
*/
|
*/
|
||||||
@JsonProperty("file_name")
|
@JsonProperty("fileName")
|
||||||
private String fileName;
|
private String fileName;
|
||||||
|
/**
|
||||||
|
* 文件描述
|
||||||
|
*/
|
||||||
|
@JsonProperty("fileDescription")
|
||||||
|
private String fileDescription;
|
||||||
/**
|
/**
|
||||||
* 文件类型
|
* 文件类型
|
||||||
*/
|
*/
|
||||||
@JsonProperty("file_type")
|
@JsonProperty("fileType")
|
||||||
private String fileType;
|
private String fileType;
|
||||||
/**
|
/**
|
||||||
* 上传时间
|
* 上传时间
|
||||||
|
|
|
||||||
|
|
@ -3,10 +3,14 @@ package com.wms.entity.table;
|
||||||
import com.baomidou.mybatisplus.annotation.TableField;
|
import com.baomidou.mybatisplus.annotation.TableField;
|
||||||
import com.baomidou.mybatisplus.annotation.TableId;
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
import com.baomidou.mybatisplus.annotation.TableName;
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
|
import com.wms.entity.app.vo.FileVo;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
import static com.wms.utils.WmsUtils.generateId;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 上传历史
|
* 上传历史
|
||||||
*/
|
*/
|
||||||
|
|
@ -28,6 +32,11 @@ public class UploadRecord {
|
||||||
*/
|
*/
|
||||||
@TableField("file_name")
|
@TableField("file_name")
|
||||||
private String fileName;
|
private String fileName;
|
||||||
|
/**
|
||||||
|
* 文件描述
|
||||||
|
*/
|
||||||
|
@TableField("file_description")
|
||||||
|
private String fileDescription;
|
||||||
/**
|
/**
|
||||||
* 文件类型
|
* 文件类型
|
||||||
*/
|
*/
|
||||||
|
|
@ -43,4 +52,22 @@ public class UploadRecord {
|
||||||
*/
|
*/
|
||||||
@TableField("upload_user")
|
@TableField("upload_user")
|
||||||
private String uploadUser;
|
private String uploadUser;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 将fileVo转换为上传记录实体类
|
||||||
|
* @param fileVo 文件Vo
|
||||||
|
* @param fileDescription 文件描述
|
||||||
|
* @return 上传记录实体类
|
||||||
|
*/
|
||||||
|
public static UploadRecord ofFileVo(FileVo fileVo, String fileDescription) {
|
||||||
|
UploadRecord uploadRecord = new UploadRecord();
|
||||||
|
uploadRecord.setUploadId(generateId("UPLOAD_"));
|
||||||
|
uploadRecord.setFileId(fileVo.getFileId());
|
||||||
|
uploadRecord.setFileType(fileVo.getType());
|
||||||
|
uploadRecord.setFileName(fileVo.getName());
|
||||||
|
uploadRecord.setUploadTime(LocalDateTime.now());
|
||||||
|
uploadRecord.setUploadUser(fileVo.getUserName());
|
||||||
|
uploadRecord.setFileDescription("fileDescription");
|
||||||
|
return uploadRecord;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,115 @@
|
||||||
|
package com.wms.utils.excel.listener;
|
||||||
|
|
||||||
|
import com.alibaba.excel.context.AnalysisContext;
|
||||||
|
import com.alibaba.excel.read.listener.ReadListener;
|
||||||
|
import com.alibaba.excel.util.ListUtils;
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
|
import com.wms.entity.table.KateDBS;
|
||||||
|
import com.wms.entity.table.KateDBSLast;
|
||||||
|
import com.wms.service.KateDBSLastService;
|
||||||
|
import com.wms.service.KateDBSService;
|
||||||
|
import com.wms.utils.excel.vo.KateDbsExcelVo;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import static com.wms.utils.StringUtils.convertJsonString;
|
||||||
|
import static com.wms.utils.WmsUtils.generateId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 上传DBS监听
|
||||||
|
*/
|
||||||
|
public class UploadDbsListener implements ReadListener<KateDbsExcelVo> {
|
||||||
|
private final Logger logger = LoggerFactory.getLogger(this.getClass());
|
||||||
|
/**
|
||||||
|
* 每隔5条存储数据库,实际使用中可以100条,然后清理list ,方便内存回收
|
||||||
|
*/
|
||||||
|
private static final int BATCH_COUNT = 100;
|
||||||
|
private List<KateDbsExcelVo> cachedDataList = ListUtils.newArrayListWithExpectedSize(BATCH_COUNT);
|
||||||
|
private final KateDBSService kateDBSService;// Dbs服务
|
||||||
|
private final KateDBSLastService kateDBSLastService;// DbsLast服务
|
||||||
|
private final String uploadUser;// 用户
|
||||||
|
public UploadDbsListener(KateDBSService kateDBSService, KateDBSLastService kateDBSLastService, String uploadUser) {
|
||||||
|
this.kateDBSService = kateDBSService;
|
||||||
|
this.kateDBSLastService = kateDBSLastService;
|
||||||
|
this.uploadUser = uploadUser;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onException(Exception exception, AnalysisContext context) throws Exception {
|
||||||
|
logger.error("处理Dbs数据发生异常:{}", convertJsonString(exception));
|
||||||
|
ReadListener.super.onException(exception, context);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 这个每一条数据解析都会来调用
|
||||||
|
*
|
||||||
|
* @param kateDbsExcelVo one row value. It is same as {@link AnalysisContext#readRowHolder()}
|
||||||
|
* @param analysisContext context
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void invoke(KateDbsExcelVo kateDbsExcelVo, AnalysisContext analysisContext) {
|
||||||
|
cachedDataList.add(kateDbsExcelVo);
|
||||||
|
// 达到BATCH_COUNT了,需要去存储一次数据库,防止数据几万条数据在内存,容易OOM
|
||||||
|
if (cachedDataList.size() >= BATCH_COUNT) {
|
||||||
|
logger.info("已经导入{}条数据,开始存储数据库!", cachedDataList.size());
|
||||||
|
saveData();
|
||||||
|
// 存储完成清理 list
|
||||||
|
cachedDataList = ListUtils.newArrayListWithExpectedSize(BATCH_COUNT);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 所有数据解析完成了 都会来调用
|
||||||
|
*
|
||||||
|
* @param analysisContext context
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void doAfterAllAnalysed(AnalysisContext analysisContext) {
|
||||||
|
saveData();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 存储数据
|
||||||
|
*/
|
||||||
|
private void saveData() {
|
||||||
|
List<KateDBS> kateDbsList = new ArrayList<>();
|
||||||
|
for (KateDbsExcelVo kateDbsExcelVo : cachedDataList) {
|
||||||
|
if (kateDBSService.exists(new LambdaQueryWrapper<KateDBS>()
|
||||||
|
.eq(KateDBS::getWorkOrder, kateDbsExcelVo.getWorkOrder())
|
||||||
|
.or().eq(KateDBS::getWorkSequence, kateDbsExcelVo.getWorkSequence()))) {
|
||||||
|
// 工单号或者序号重复,那么跳过这条DBS
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
KateDBSLast kateDbsLast = kateDBSLastService.getOne(new LambdaQueryWrapper<KateDBSLast>()
|
||||||
|
.eq(KateDBSLast::getWorkOrder, kateDbsExcelVo.getWorkOrder()));
|
||||||
|
if (kateDbsLast != null) {
|
||||||
|
// 之前存在过
|
||||||
|
KateDBS oldKateDbs = new KateDBS();
|
||||||
|
oldKateDbs.setDbsId(kateDbsLast.getDbsId());
|
||||||
|
oldKateDbs.setWorkSequence(kateDbsExcelVo.getWorkSequence());
|
||||||
|
oldKateDbs.setWorkOrder(kateDbsExcelVo.getWorkOrder());
|
||||||
|
oldKateDbs.setPlanStartDate(kateDbsExcelVo.getPlanStartDate());
|
||||||
|
oldKateDbs.setDbsStatus(kateDbsLast.getDbsStatus());
|
||||||
|
oldKateDbs.setLastUpdateTime(LocalDateTime.now());
|
||||||
|
oldKateDbs.setLastUpdateUser(uploadUser);
|
||||||
|
kateDbsList.add(oldKateDbs);
|
||||||
|
} else {
|
||||||
|
// 之前没存在过
|
||||||
|
KateDBS newKateDbs = new KateDBS();
|
||||||
|
newKateDbs.setDbsId(generateId("DBS_"));
|
||||||
|
newKateDbs.setWorkSequence(kateDbsExcelVo.getWorkSequence());
|
||||||
|
newKateDbs.setWorkOrder(kateDbsExcelVo.getWorkOrder());
|
||||||
|
newKateDbs.setPlanStartDate(kateDbsExcelVo.getPlanStartDate());
|
||||||
|
newKateDbs.setDbsStatus(0);
|
||||||
|
newKateDbs.setLastUpdateTime(LocalDateTime.now());
|
||||||
|
newKateDbs.setLastUpdateUser(uploadUser);
|
||||||
|
kateDbsList.add(newKateDbs);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
kateDBSService.saveOrUpdateBatch(kateDbsList);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,138 @@
|
||||||
|
package com.wms.utils.excel.listener;
|
||||||
|
|
||||||
|
import com.alibaba.excel.context.AnalysisContext;
|
||||||
|
import com.alibaba.excel.read.listener.ReadListener;
|
||||||
|
import com.alibaba.excel.util.ListUtils;
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
|
import com.wms.entity.app.dto.extend.StockDetailInfo;
|
||||||
|
import com.wms.entity.table.*;
|
||||||
|
import com.wms.service.*;
|
||||||
|
import com.wms.utils.excel.vo.KateDbsExcelVo;
|
||||||
|
import com.wms.utils.excel.vo.KateOrdersExcelVo;
|
||||||
|
import com.wms.utils.excel.vo.StockExcelVo;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import static com.wms.utils.StringUtils.convertJsonString;
|
||||||
|
import static com.wms.utils.WmsUtils.generateId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 上传库存监听
|
||||||
|
*/
|
||||||
|
public class UploadKateOrdersListener implements ReadListener<KateOrdersExcelVo> {
|
||||||
|
private final Logger logger = LoggerFactory.getLogger(this.getClass());
|
||||||
|
/**
|
||||||
|
* 每隔5条存储数据库,实际使用中可以100条,然后清理list ,方便内存回收
|
||||||
|
*/
|
||||||
|
private static final int BATCH_COUNT = 100;
|
||||||
|
private List<KateOrdersExcelVo> cachedDataList = ListUtils.newArrayListWithExpectedSize(BATCH_COUNT);
|
||||||
|
private final KateOrdersService kateOrdersService;// Dbs服务
|
||||||
|
private final KateOrdersLastService kateOrdersLastService;// DbsLast服务
|
||||||
|
private final String uploadUser;// 用户
|
||||||
|
public UploadKateOrdersListener(KateOrdersService kateOrdersService, KateOrdersLastService kateOrdersLastService, String uploadUser) {
|
||||||
|
this.kateOrdersService = kateOrdersService;
|
||||||
|
this.kateOrdersLastService = kateOrdersLastService;
|
||||||
|
this.uploadUser = uploadUser;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onException(Exception exception, AnalysisContext context) throws Exception {
|
||||||
|
logger.error("处理工单数据发生异常:{}", convertJsonString(exception));
|
||||||
|
ReadListener.super.onException(exception, context);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 这个每一条数据解析都会来调用
|
||||||
|
*
|
||||||
|
* @param kateOrdersExcelVo one row value. It is same as {@link AnalysisContext#readRowHolder()}
|
||||||
|
* @param analysisContext context
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void invoke(KateOrdersExcelVo kateOrdersExcelVo, AnalysisContext analysisContext) {
|
||||||
|
cachedDataList.add(kateOrdersExcelVo);
|
||||||
|
// 达到BATCH_COUNT了,需要去存储一次数据库,防止数据几万条数据在内存,容易OOM
|
||||||
|
if (cachedDataList.size() >= BATCH_COUNT) {
|
||||||
|
logger.info("已经导入{}条数据,开始存储数据库!", cachedDataList.size());
|
||||||
|
saveData();
|
||||||
|
// 存储完成清理 list
|
||||||
|
cachedDataList = ListUtils.newArrayListWithExpectedSize(BATCH_COUNT);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 所有数据解析完成了 都会来调用
|
||||||
|
*
|
||||||
|
* @param analysisContext context
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void doAfterAllAnalysed(AnalysisContext analysisContext) {
|
||||||
|
saveData();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 存储数据
|
||||||
|
*/
|
||||||
|
private void saveData() {
|
||||||
|
List<KateOrders> kateOrdersList = new ArrayList<>();
|
||||||
|
for (KateOrdersExcelVo kateOrdersExcelVo : cachedDataList) {
|
||||||
|
if (kateOrdersService.exists(new LambdaQueryWrapper<KateOrders>()
|
||||||
|
.eq(KateOrders::getWorkOrder, kateOrdersExcelVo.getWorkOrder())
|
||||||
|
.eq(KateOrders::getGoodsId, kateOrdersExcelVo.getGoodsId())
|
||||||
|
.eq(KateOrders::getSupplyArea, kateOrdersExcelVo.getSupplyArea()))) {
|
||||||
|
// 数据重复
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
KateOrdersLast kateOrdersLast = kateOrdersLastService.getOne(new LambdaQueryWrapper<KateOrdersLast>()
|
||||||
|
.eq(KateOrdersLast::getWorkOrder, kateOrdersExcelVo.getWorkOrder())
|
||||||
|
.eq(KateOrdersLast::getGoodsId, kateOrdersExcelVo.getGoodsId())
|
||||||
|
.eq(KateOrdersLast::getSupplyArea, kateOrdersExcelVo.getSupplyArea()));
|
||||||
|
if (kateOrdersLast != null) {
|
||||||
|
// 之前存在过
|
||||||
|
KateOrders oldKateOrders = new KateOrders();
|
||||||
|
oldKateOrders.setOrderId(kateOrdersLast.getOrderId());
|
||||||
|
oldKateOrders.setWorkOrder(kateOrdersExcelVo.getWorkOrder());
|
||||||
|
oldKateOrders.setGoodsId(kateOrdersExcelVo.getGoodsId());
|
||||||
|
oldKateOrders.setItem(kateOrdersExcelVo.getItem());
|
||||||
|
oldKateOrders.setDescription(kateOrdersExcelVo.getDescription());
|
||||||
|
oldKateOrders.setSLoc(kateOrdersExcelVo.getSLoc());
|
||||||
|
oldKateOrders.setType(kateOrdersExcelVo.getType());
|
||||||
|
oldKateOrders.setOriginStatus(kateOrdersExcelVo.getOriginStatus());
|
||||||
|
oldKateOrders.setSupplyArea(kateOrdersExcelVo.getSupplyArea());
|
||||||
|
oldKateOrders.setSortString(kateOrdersExcelVo.getSortString());
|
||||||
|
oldKateOrders.setRequirementQuantity(kateOrdersExcelVo.getRequirementQuantity());
|
||||||
|
oldKateOrders.setGoodsUnit(kateOrdersExcelVo.getGoodsUnit());
|
||||||
|
oldKateOrders.setOrderStatus(kateOrdersLast.getOrderStatus());
|
||||||
|
oldKateOrders.setLackQuantity(kateOrdersLast.getLackQuantity());
|
||||||
|
oldKateOrders.setPickedQuantity(kateOrdersLast.getPickedQuantity());
|
||||||
|
oldKateOrders.setFinishTime(kateOrdersLast.getFinishTime());
|
||||||
|
oldKateOrders.setUserName(uploadUser);
|
||||||
|
kateOrdersList.add(oldKateOrders);
|
||||||
|
} else {
|
||||||
|
// 之前没存在过
|
||||||
|
KateOrders newKateOrders = new KateOrders();
|
||||||
|
newKateOrders.setOrderId(generateId("ORDER_"));
|
||||||
|
newKateOrders.setWorkOrder(kateOrdersExcelVo.getWorkOrder());
|
||||||
|
newKateOrders.setGoodsId(kateOrdersExcelVo.getGoodsId());
|
||||||
|
newKateOrders.setItem(kateOrdersExcelVo.getItem());
|
||||||
|
newKateOrders.setDescription(kateOrdersExcelVo.getDescription());
|
||||||
|
newKateOrders.setSLoc(kateOrdersExcelVo.getSLoc());
|
||||||
|
newKateOrders.setType(kateOrdersExcelVo.getType());
|
||||||
|
newKateOrders.setOriginStatus(kateOrdersExcelVo.getOriginStatus());
|
||||||
|
newKateOrders.setSupplyArea(kateOrdersExcelVo.getSupplyArea());
|
||||||
|
newKateOrders.setSortString(kateOrdersExcelVo.getSortString());
|
||||||
|
newKateOrders.setRequirementQuantity(kateOrdersExcelVo.getRequirementQuantity());
|
||||||
|
newKateOrders.setGoodsUnit(kateOrdersExcelVo.getGoodsUnit());
|
||||||
|
newKateOrders.setOrderStatus(0);
|
||||||
|
newKateOrders.setLackQuantity(kateOrdersExcelVo.getRequirementQuantity());
|
||||||
|
newKateOrders.setPickedQuantity(BigDecimal.ZERO);
|
||||||
|
newKateOrders.setUserName(uploadUser);
|
||||||
|
kateOrdersList.add(newKateOrders);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
kateOrdersService.saveOrUpdateBatch(kateOrdersList);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -34,7 +34,7 @@ public class UploadStocksListener implements ReadListener<StockExcelVo> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onException(Exception exception, AnalysisContext context) throws Exception {
|
public void onException(Exception exception, AnalysisContext context) throws Exception {
|
||||||
logger.error("处理数据发生异常:{}", convertJsonString(exception));
|
logger.error("处理库存数据发生异常:{}", convertJsonString(exception));
|
||||||
ReadListener.super.onException(exception, context);
|
ReadListener.super.onException(exception, context);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
62
src/main/java/com/wms/utils/excel/vo/KateDbsExcelVo.java
Normal file
62
src/main/java/com/wms/utils/excel/vo/KateDbsExcelVo.java
Normal file
|
|
@ -0,0 +1,62 @@
|
||||||
|
package com.wms.utils.excel.vo;
|
||||||
|
|
||||||
|
import cn.hutool.core.bean.BeanUtil;
|
||||||
|
import com.alibaba.excel.annotation.ExcelProperty;
|
||||||
|
import com.alibaba.excel.annotation.format.DateTimeFormat;
|
||||||
|
import com.wms.entity.table.KateDBS;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class KateDbsExcelVo {
|
||||||
|
/**
|
||||||
|
* DBS计划Id
|
||||||
|
*/
|
||||||
|
@ExcelProperty("DBS计划Id")
|
||||||
|
private String dbsId;
|
||||||
|
/**
|
||||||
|
* 顺序号
|
||||||
|
*/
|
||||||
|
@ExcelProperty("序号")
|
||||||
|
private Integer workSequence;
|
||||||
|
/**
|
||||||
|
* 工单
|
||||||
|
*/
|
||||||
|
@ExcelProperty("装配工单")
|
||||||
|
private String workOrder;
|
||||||
|
/**
|
||||||
|
* 计划开工日期
|
||||||
|
*/
|
||||||
|
@ExcelProperty("装配/测试/喷漆开工")
|
||||||
|
@DateTimeFormat("yyyy/MM/dd")
|
||||||
|
private LocalDateTime planStartDate;
|
||||||
|
/**
|
||||||
|
* dbs的状态
|
||||||
|
* 0:未开始
|
||||||
|
* 1:已开始未完成
|
||||||
|
* 2:已完成
|
||||||
|
*/
|
||||||
|
@ExcelProperty("状态")
|
||||||
|
private Integer dbsStatus;
|
||||||
|
/**
|
||||||
|
* 最近更新时间
|
||||||
|
*/
|
||||||
|
@ExcelProperty("最近更新时间")
|
||||||
|
@DateTimeFormat("yyyy-MM-dd HH:mm:ss")
|
||||||
|
private LocalDateTime lastUpdateTime;
|
||||||
|
/**
|
||||||
|
* 最近更新用户
|
||||||
|
*/
|
||||||
|
@ExcelProperty("最近更新时间")
|
||||||
|
private String lastUpdateUser;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 从数据库实体转换为excel对象
|
||||||
|
* @param dbsPo 数据库实体
|
||||||
|
* @return excel对象
|
||||||
|
*/
|
||||||
|
public static KateDbsExcelVo of(KateDBS dbsPo) {
|
||||||
|
return BeanUtil.copyProperties(dbsPo, KateDbsExcelVo.class);
|
||||||
|
}
|
||||||
|
}
|
||||||
115
src/main/java/com/wms/utils/excel/vo/KateOrdersExcelVo.java
Normal file
115
src/main/java/com/wms/utils/excel/vo/KateOrdersExcelVo.java
Normal file
|
|
@ -0,0 +1,115 @@
|
||||||
|
package com.wms.utils.excel.vo;
|
||||||
|
|
||||||
|
import cn.hutool.core.bean.BeanUtil;
|
||||||
|
import com.alibaba.excel.annotation.ExcelProperty;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableField;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
|
import com.wms.entity.table.KateOrders;
|
||||||
|
import com.wms.entity.table.Location;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class KateOrdersExcelVo {
|
||||||
|
/**
|
||||||
|
* id
|
||||||
|
*/
|
||||||
|
@ExcelProperty("order_id")
|
||||||
|
private String orderId;
|
||||||
|
/**
|
||||||
|
* Order
|
||||||
|
*/
|
||||||
|
@ExcelProperty("Order")
|
||||||
|
private String workOrder;
|
||||||
|
/**
|
||||||
|
* Material
|
||||||
|
*/
|
||||||
|
@ExcelProperty("Material")
|
||||||
|
private String goodsId;
|
||||||
|
/**
|
||||||
|
* Item
|
||||||
|
*/
|
||||||
|
@ExcelProperty("Item")
|
||||||
|
private String item;
|
||||||
|
/**
|
||||||
|
* Description
|
||||||
|
*/
|
||||||
|
@ExcelProperty("Description")
|
||||||
|
private String description;
|
||||||
|
/**
|
||||||
|
* SLoc
|
||||||
|
*/
|
||||||
|
@ExcelProperty("SLoc")
|
||||||
|
private String sLoc;
|
||||||
|
/**
|
||||||
|
* Type
|
||||||
|
*/
|
||||||
|
@ExcelProperty("Type")
|
||||||
|
private String type;
|
||||||
|
/**
|
||||||
|
* Status
|
||||||
|
*/
|
||||||
|
@ExcelProperty("Status")
|
||||||
|
private String originStatus;
|
||||||
|
/**
|
||||||
|
* SupplyArea
|
||||||
|
*/
|
||||||
|
@ExcelProperty("SupplyArea")
|
||||||
|
private String supplyArea;
|
||||||
|
/**
|
||||||
|
* SortStrng
|
||||||
|
*/
|
||||||
|
@ExcelProperty("SortStrng")
|
||||||
|
private String sortString;
|
||||||
|
/**
|
||||||
|
* Requirement Qty
|
||||||
|
*/
|
||||||
|
@ExcelProperty("Requirement Qty")
|
||||||
|
private BigDecimal requirementQuantity;
|
||||||
|
/**
|
||||||
|
* BUn
|
||||||
|
*/
|
||||||
|
@ExcelProperty("BUn")
|
||||||
|
private String goodsUnit;
|
||||||
|
/**
|
||||||
|
* 工单状态
|
||||||
|
* 0:未开始
|
||||||
|
* 1:已生成任务
|
||||||
|
* 2:已呼叫料箱
|
||||||
|
* 3:正在拣选
|
||||||
|
* 4:拣选完成
|
||||||
|
*/
|
||||||
|
@ExcelProperty("工单状态")
|
||||||
|
private Integer orderStatus;
|
||||||
|
/**
|
||||||
|
* 缺少数量
|
||||||
|
*/
|
||||||
|
@ExcelProperty("缺少数量")
|
||||||
|
private BigDecimal lackQuantity;
|
||||||
|
/**
|
||||||
|
* 实际拣选数量
|
||||||
|
*/
|
||||||
|
@ExcelProperty("实际拣选数量")
|
||||||
|
private BigDecimal pickedQuantity;
|
||||||
|
/**
|
||||||
|
* 操作人员
|
||||||
|
*/
|
||||||
|
@ExcelProperty("操作人员")
|
||||||
|
private String userName;
|
||||||
|
/**
|
||||||
|
* 完成时间
|
||||||
|
*/
|
||||||
|
@ExcelProperty("完成时间")
|
||||||
|
private LocalDateTime finishTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 从数据库实体转换为excel对象
|
||||||
|
* @param ordersPo 数据库实体
|
||||||
|
* @return excel对象
|
||||||
|
*/
|
||||||
|
public static KateOrdersExcelVo of(KateOrders ordersPo) {
|
||||||
|
return BeanUtil.copyProperties(ordersPo, KateOrdersExcelVo.class);
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user