【物料变更】批量导入任务
This commit is contained in:
parent
7972909aa6
commit
7888566477
|
|
@ -4,9 +4,10 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
|
|||
import com.nflg.product.base.core.api.BaseApi;
|
||||
import com.nflg.product.base.core.exception.NflgBusinessException;
|
||||
import com.nflg.product.material.pojo.dto.MaterialStateUpExcelDTO;
|
||||
import com.nflg.product.material.pojo.dto.TwentyMaterialTemplateExcelDTO;
|
||||
import com.nflg.product.material.pojo.dto.MaterialUpdateBillDTO;
|
||||
import com.nflg.product.material.pojo.dto.TwentyMaterialTemplateExcelDTO;
|
||||
import com.nflg.product.material.pojo.entity.MaterialUpdateBillEntity;
|
||||
import com.nflg.product.material.pojo.entity.MaterialUpdateImportTaskEntity;
|
||||
import com.nflg.product.material.pojo.query.MaterialUpdateBillQuery;
|
||||
import com.nflg.product.material.pojo.vo.MaterialBatchImportVO;
|
||||
import com.nflg.product.material.pojo.vo.MaterialMainVO;
|
||||
|
|
@ -191,4 +192,10 @@ public class MaterialUpdateBillApi extends BaseApi {
|
|||
public void doCalcRecommend() {
|
||||
materialUpdateToOAService.doFreezeState();
|
||||
}
|
||||
|
||||
@GetMapping("getMaterialUpdateImportTaskList")
|
||||
@ApiOperation("获取物料变更批量导入任务表")
|
||||
public ResultVO<List<MaterialUpdateImportTaskEntity>> getMaterialUpdateImportTaskList() {
|
||||
return ResultVO.success(materialUpdateBillService.getMaterialUpdateImportTaskList());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,10 @@ package com.nflg.product.material.mapper.master;
|
|||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.nflg.product.material.pojo.entity.MaterialUpdateImportTaskEntity;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface MaterialUpdateImportTaskMapper extends BaseMapper<MaterialUpdateImportTaskEntity> {
|
||||
List<MaterialUpdateImportTaskEntity> getMaterialUpdateImportTaskList(@Param("userCode") String userCode);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -66,7 +66,7 @@ public class MaterialUpdateImportTaskEntity implements Serializable {
|
|||
* 任务状态:0进行中 1已完成
|
||||
*/
|
||||
@TableField(value = "task_status")
|
||||
@ApiModelProperty(value = "任务状态:0进行中 1已完成")
|
||||
@ApiModelProperty(value = "任务状态:0进行中 1已完成 2已中止")
|
||||
private Integer taskStatus;
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -409,27 +409,25 @@ public class MaterialUpdateBillService extends ServiceImpl<MaterialUpdateBillMap
|
|||
String userCode = SessionUtil.getUserCode();
|
||||
MaterialBatchImportVO importVO = new MaterialBatchImportVO();
|
||||
importVO.setInBatches(false);
|
||||
int batchSize = 1000;
|
||||
if (lastColIndex == 4) {
|
||||
List<MaterialStateUpExcelDTO> excelContext = EecExcelUtil.getExcelContext(file.getInputStream(), MaterialStateUpExcelDTO.class);
|
||||
if (CollectionUtil.isNotEmpty(excelContext) && excelContext.size() > 1000) {
|
||||
if (CollectionUtil.isNotEmpty(excelContext) && excelContext.size() > batchSize) {
|
||||
if (excelContext.size() > 10000) {
|
||||
return ResultVO.error("导入失败,最多支持10000条批量导入");
|
||||
}
|
||||
redisTemplate.opsForValue().set(buildKey(userCode + ":updateBatchImport"), file.getOriginalFilename());
|
||||
Map<Integer, String> indexMaterialMap = new HashMap<>(excelContext.size());
|
||||
Map<String, Integer> indexMaterialMap = new HashMap<>(excelContext.size());
|
||||
for (int i = 0; i < excelContext.size(); i++) {
|
||||
indexMaterialMap.put(i + 1, excelContext.get(i).getMaterialNo());
|
||||
indexMaterialMap.put(excelContext.get(i).getMaterialNo(), i + 1);
|
||||
}
|
||||
Long rowId = IdWorker.getId();
|
||||
// 大数据量,子线程分批次提交OA(每批1000条),主线程提前返回结果给前端
|
||||
CompletableFuture<Integer> task1 = CompletableFuture.supplyAsync(() -> {
|
||||
long startTime = System.currentTimeMillis();
|
||||
insertMaterialUpdateImportTask(rowId, excelContext.size(), file.getOriginalFilename(), userCode);
|
||||
List<List<MaterialStateUpExcelDTO>> lists = Lists.partition(excelContext, 1000);
|
||||
for (int i = 0; i < lists.size(); i++) {
|
||||
List<MaterialStateUpExcelDTO> items = lists.get(i);
|
||||
this.handleImportDataForState(items, applyDeptName, deptEnt, realName, userCode);
|
||||
}
|
||||
List<List<MaterialStateUpExcelDTO>> lists = Lists.partition(excelContext, batchSize);
|
||||
lists.forEach(items -> this.handleImportDataForState(items, applyDeptName, deptEnt, realName, userCode));
|
||||
updateMaterialUpdateImportTask(rowId, excelContext.size(), excelContext.size(), 0, "");
|
||||
long endTime = System.currentTimeMillis();
|
||||
log.info("物料变更批量导入耗时(ms): {}", endTime - startTime);
|
||||
|
|
@ -440,7 +438,14 @@ public class MaterialUpdateBillService extends ServiceImpl<MaterialUpdateBillMap
|
|||
// 异常处理器,打印异常信息并返回默认值
|
||||
log.error("物料变更批量导入异常: " + ex.getMessage());
|
||||
String errMaterialNo = getErrMaterialNo(ex.getMessage());
|
||||
updateMaterialUpdateImportTask(rowId, excelContext.size(), excelContext.size(), 0, "");
|
||||
int successNum = 0;
|
||||
int failNum = excelContext.size();
|
||||
if (StrUtil.isNotEmpty(errMaterialNo)) {
|
||||
Integer idx = indexMaterialMap.get(errMaterialNo);
|
||||
successNum = idx / batchSize;
|
||||
failNum = excelContext.size() - (idx / batchSize);
|
||||
}
|
||||
updateMaterialUpdateImportTask(rowId, excelContext.size(), successNum, failNum, ex.getMessage());
|
||||
redisTemplate.delete(buildKey(userCode + ":updateBatchImport"));
|
||||
return -1;
|
||||
});
|
||||
|
|
@ -453,16 +458,23 @@ public class MaterialUpdateBillService extends ServiceImpl<MaterialUpdateBillMap
|
|||
} else {
|
||||
// 制作物料
|
||||
List<TwentyMaterialTemplateExcelDTO> excelContext = EecExcelUtil.getExcelContext(file.getInputStream(), TwentyMaterialTemplateExcelDTO.class);
|
||||
if (CollectionUtil.isNotEmpty(excelContext) && excelContext.size() > 1000) {
|
||||
if (CollectionUtil.isNotEmpty(excelContext) && excelContext.size() > batchSize) {
|
||||
if (excelContext.size() > 10000) {
|
||||
return ResultVO.error("导入失败,最多支持10000条批量导入");
|
||||
}
|
||||
redisTemplate.opsForValue().set(buildKey(userCode + ":updateBatchImport"), file.getOriginalFilename());
|
||||
Map<String, Integer> indexMaterialMap = new HashMap<>(excelContext.size());
|
||||
for (int i = 0; i < excelContext.size(); i++) {
|
||||
indexMaterialMap.put(excelContext.get(i).getMaterialNo(), i + 1);
|
||||
}
|
||||
Long rowId = IdWorker.getId();
|
||||
// 大数据量,子线程分批次提交OA(每批1000条),主线程提前返回结果给前端
|
||||
CompletableFuture<Integer> task1 = CompletableFuture.supplyAsync(() -> {
|
||||
long startTime = System.currentTimeMillis();
|
||||
List<List<TwentyMaterialTemplateExcelDTO>> lists = Lists.partition(excelContext, 1000);
|
||||
insertMaterialUpdateImportTask(rowId, excelContext.size(), file.getOriginalFilename(), userCode);
|
||||
List<List<TwentyMaterialTemplateExcelDTO>> lists = Lists.partition(excelContext, batchSize);
|
||||
lists.forEach(items -> this.handleImportDataForSummary(items, applyDeptName, deptEnt, realName, userCode));
|
||||
updateMaterialUpdateImportTask(rowId, excelContext.size(), excelContext.size(), 0, "");
|
||||
long endTime = System.currentTimeMillis();
|
||||
log.info("物料变更批量导入耗时(ms): {}", endTime - startTime);
|
||||
redisTemplate.delete(buildKey(userCode + ":updateBatchImport"));
|
||||
|
|
@ -471,6 +483,15 @@ public class MaterialUpdateBillService extends ServiceImpl<MaterialUpdateBillMap
|
|||
task1.exceptionally(ex -> {
|
||||
// 异常处理器,打印异常信息并返回默认值
|
||||
log.error("物料变更批量导入异常: " + ex.getMessage());
|
||||
String errMaterialNo = getErrMaterialNo(ex.getMessage());
|
||||
int successNum = 0;
|
||||
int failNum = excelContext.size();
|
||||
if (StrUtil.isNotEmpty(errMaterialNo)) {
|
||||
Integer idx = indexMaterialMap.get(errMaterialNo);
|
||||
successNum = idx / batchSize;
|
||||
failNum = excelContext.size() - (idx / batchSize);
|
||||
}
|
||||
updateMaterialUpdateImportTask(rowId, excelContext.size(), successNum, failNum, ex.getMessage());
|
||||
redisTemplate.delete(buildKey(userCode + ":updateBatchImport"));
|
||||
return -1;
|
||||
});
|
||||
|
|
@ -489,6 +510,8 @@ public class MaterialUpdateBillService extends ServiceImpl<MaterialUpdateBillMap
|
|||
save.setRowId(rowId);
|
||||
save.setFileName(fileName);
|
||||
save.setTotalNum(totalNum);
|
||||
save.setSuccessNum(0);
|
||||
save.setFailNum(0);
|
||||
save.setTaskStatus(0);
|
||||
save.setCreatedBy(userCode);
|
||||
save.setCreatedTime(LocalDateTime.now());
|
||||
|
|
@ -498,15 +521,18 @@ public class MaterialUpdateBillService extends ServiceImpl<MaterialUpdateBillMap
|
|||
|
||||
private void updateMaterialUpdateImportTask(Long rowId, Integer totalNum, Integer successNum, Integer failNum, String exceptionMsg) {
|
||||
MaterialUpdateImportTaskEntity update = new MaterialUpdateImportTaskEntity();
|
||||
update.setRowId(rowId);
|
||||
update.setSuccessNum(successNum);
|
||||
update.setFailNum(failNum);
|
||||
// 批量导入总条数${total_num}条,成功${success_num}条,失败${fail_num}条,第${success_num}条后因为“${fail_reason}”而终止
|
||||
String desc = StrUtil.format("批量导入总条数{}条,成功{}条,失败${}条", totalNum, successNum, failNum);
|
||||
// 批量导入总条数{total_num}条,成功{success_num}条,失败{fail_num}条,第{success_num}条后因为“{fail_reason}”而中止
|
||||
String desc = StrUtil.format("批量导入总条数{}条,成功{}条,失败{}条", totalNum, successNum, failNum);
|
||||
if (failNum > 0) {
|
||||
desc += StrUtil.format(",第{}条后因为“{}”而终止", successNum, exceptionMsg);
|
||||
desc += StrUtil.format(",第{}条起因为“{}”而中止", successNum + 1, exceptionMsg);
|
||||
update.setTaskStatus(2); // 已中止
|
||||
} else {
|
||||
update.setTaskStatus(1); // 已完成
|
||||
}
|
||||
update.setFailReason(desc);
|
||||
update.setTaskStatus(1);
|
||||
materialUpdateImportTaskMapper.updateById(update);
|
||||
}
|
||||
|
||||
|
|
@ -1172,4 +1198,8 @@ public class MaterialUpdateBillService extends ServiceImpl<MaterialUpdateBillMap
|
|||
private String buildKey(String key) {
|
||||
return StrUtil.format("{}:{}", PREFIX, key);
|
||||
}
|
||||
|
||||
public List<MaterialUpdateImportTaskEntity> getMaterialUpdateImportTaskList() {
|
||||
return materialUpdateImportTaskMapper.getMaterialUpdateImportTaskList(SessionUtil.getUserCode());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,13 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.nflg.product.material.mapper.master.MaterialUpdateImportTaskMapper">
|
||||
|
||||
<select id="getMaterialUpdateImportTaskList" resultType="com.nflg.product.material.pojo.entity.MaterialUpdateImportTaskEntity">
|
||||
select * from t_material_update_import_task where 1=1
|
||||
and task_status in (0,2)
|
||||
<if test="userCode != null and userCode != ''">
|
||||
and created_by = #{userCode}
|
||||
</if>
|
||||
order by created_time desc
|
||||
</select>
|
||||
</mapper>
|
||||
|
|
|
|||
Loading…
Reference in New Issue