【物料变更】大批量导入

This commit is contained in:
10001392 2024-09-12 09:17:43 +08:00
parent bc1a959489
commit 4613acf253
10 changed files with 138 additions and 54 deletions

View File

@ -7,6 +7,7 @@ import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.toolkit.IdWorker; import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import com.nflg.product.base.core.api.BaseApi; import com.nflg.product.base.core.api.BaseApi;
import com.nflg.product.base.core.conmon.util.SessionUtil;
import com.nflg.product.base.core.exception.NflgBusinessException; import com.nflg.product.base.core.exception.NflgBusinessException;
import com.nflg.product.material.pojo.dto.FindLastAttrValuesDTO; import com.nflg.product.material.pojo.dto.FindLastAttrValuesDTO;
import com.nflg.product.material.pojo.dto.MaterialMainDTO; import com.nflg.product.material.pojo.dto.MaterialMainDTO;
@ -94,7 +95,7 @@ public class MaterialMainApi extends BaseApi {
@GetMapping("selectByRowId") @GetMapping("selectByRowId")
@ApiOperation("auto-根据rowId查询物料主数据表") @ApiOperation("auto-根据rowId查询物料主数据表")
public ResultVO<MaterialMainVO> selectByRowId(@RequestParam("rowId") Long rowId, @RequestParam("type") Integer type) { public ResultVO<MaterialMainVO> selectByRowId(@RequestParam("rowId") Long rowId, @RequestParam("type") Integer type) {
return ResultVO.success(materialMainService.selectByRowId(rowId, type)); return ResultVO.success(materialMainService.selectByRowId(rowId, type, SessionUtil.getUserCode()));
} }
/** /**

View File

@ -8,6 +8,7 @@ import com.nflg.product.material.pojo.dto.TwentyMaterialTemplateExcelDTO;
import com.nflg.product.material.pojo.dto.MaterialUpdateBillDTO; import com.nflg.product.material.pojo.dto.MaterialUpdateBillDTO;
import com.nflg.product.material.pojo.entity.MaterialUpdateBillEntity; import com.nflg.product.material.pojo.entity.MaterialUpdateBillEntity;
import com.nflg.product.material.pojo.query.MaterialUpdateBillQuery; import com.nflg.product.material.pojo.query.MaterialUpdateBillQuery;
import com.nflg.product.material.pojo.vo.MaterialBatchImportVO;
import com.nflg.product.material.pojo.vo.MaterialMainVO; import com.nflg.product.material.pojo.vo.MaterialMainVO;
import com.nflg.product.material.pojo.vo.MaterialUpdateBillVO; import com.nflg.product.material.pojo.vo.MaterialUpdateBillVO;
import com.nflg.product.material.service.MaterialUpdateBillService; import com.nflg.product.material.service.MaterialUpdateBillService;
@ -132,7 +133,7 @@ public class MaterialUpdateBillApi extends BaseApi {
@ApiOperation("批量变更") @ApiOperation("批量变更")
@PostMapping("batchImport") @PostMapping("batchImport")
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public ResultVO<Boolean> batchImport(@RequestParam(required = true, value = "file") MultipartFile file) throws IOException { public ResultVO<MaterialBatchImportVO> batchImport(@RequestParam(required = true, value = "file") MultipartFile file) throws IOException {
try { try {
return materialUpdateBillService.batchImport(file); return materialUpdateBillService.batchImport(file);
} catch (Exception ex) { } catch (Exception ex) {

View File

@ -0,0 +1,10 @@
package com.nflg.product.material.pojo.vo;
import lombok.Data;
@Data
public class MaterialBatchImportVO {
private Boolean inBatches; // 是否分批次
}

View File

@ -823,12 +823,12 @@ public class MaterialMainService extends ServiceImpl<MaterialMainMapper, Materia
* *
* @param list * @param list
*/ */
private void initFavoritesState(List<MaterialMainVO> list) { private void initFavoritesState(List<MaterialMainVO> list, String userCode) {
if (list.size() <= 0) { if (list.size() <= 0) {
return; return;
} }
List<Long> materialRowIds = list.stream().map(MaterialMainVO::getRowId).collect(Collectors.toList()); List<Long> materialRowIds = list.stream().map(MaterialMainVO::getRowId).collect(Collectors.toList());
List<MaterialFavoritesEntity> favorityList = materialFavoritesService.lambdaQuery().eq(MaterialFavoritesEntity::getUserCode, SessionUtil.getUserCode()).in(MaterialFavoritesEntity::getMaterialRowId, materialRowIds).list(); List<MaterialFavoritesEntity> favorityList = materialFavoritesService.lambdaQuery().eq(MaterialFavoritesEntity::getUserCode, userCode).in(MaterialFavoritesEntity::getMaterialRowId, materialRowIds).list();
Map<Long, MaterialFavoritesEntity> favorityMap = ListCommonUtil.listToMap(favorityList, MaterialFavoritesEntity::getMaterialRowId); Map<Long, MaterialFavoritesEntity> favorityMap = ListCommonUtil.listToMap(favorityList, MaterialFavoritesEntity::getMaterialRowId);
list.forEach(k -> { list.forEach(k -> {
k.setFavoritesState(0); k.setFavoritesState(0);
@ -862,7 +862,7 @@ public class MaterialMainService extends ServiceImpl<MaterialMainMapper, Materia
* @param rowId 主键 * @param rowId 主键
* @return 单条数据 * @return 单条数据
*/ */
public MaterialMainVO selectByRowId(@RequestParam("rowId") Long rowId, Integer type) { public MaterialMainVO selectByRowId(@RequestParam("rowId") Long rowId, Integer type, String userCode) {
long Date10 = new Date().getTime(); long Date10 = new Date().getTime();
log.info("[计算耗时][selectByRowId]================================" + Date10 ); log.info("[计算耗时][selectByRowId]================================" + Date10 );
MaterialMainEntity materialMainEntity = materialMainMapper.selectById(rowId); MaterialMainEntity materialMainEntity = materialMainMapper.selectById(rowId);
@ -879,7 +879,7 @@ public class MaterialMainService extends ServiceImpl<MaterialMainMapper, Materia
//task.add(CompletableFuture.runAsync(() -> { //task.add(CompletableFuture.runAsync(() -> {
List<MaterialMainVO> list = new ArrayList<>(); List<MaterialMainVO> list = new ArrayList<>();
list.add(materialMainVO); list.add(materialMainVO);
initFavoritesState(list); initFavoritesState(list, userCode);
//})); //}));
long Date20 = new Date().getTime(); long Date20 = new Date().getTime();
@ -1108,7 +1108,7 @@ public class MaterialMainService extends ServiceImpl<MaterialMainMapper, Materia
public MaterialMainVO selectByMaterialNo(String materialNo) { public MaterialMainVO selectByMaterialNo(String materialNo) {
MaterialMainEntity ent = this.lambdaQuery().eq(MaterialMainEntity::getMaterialNo, materialNo).one(); MaterialMainEntity ent = this.lambdaQuery().eq(MaterialMainEntity::getMaterialNo, materialNo).one();
if (!Objects.isNull(ent)) { if (!Objects.isNull(ent)) {
return selectByRowId(ent.getRowId(), MaterialMainTypeEnum.ONE.getCode()); return selectByRowId(ent.getRowId(), MaterialMainTypeEnum.ONE.getCode(), SessionUtil.getUserCode());
} }
return null; return null;
} }
@ -1119,7 +1119,7 @@ public class MaterialMainService extends ServiceImpl<MaterialMainMapper, Materia
list.add("22"); list.add("22");
MaterialMainEntity ent = materialMainMapper.selectByMaterialNoAndRelCategoryCode(materialNo, list); MaterialMainEntity ent = materialMainMapper.selectByMaterialNoAndRelCategoryCode(materialNo, list);
if (!Objects.isNull(ent)) { if (!Objects.isNull(ent)) {
return selectByRowId(ent.getRowId(), MaterialMainTypeEnum.ONE.getCode()); return selectByRowId(ent.getRowId(), MaterialMainTypeEnum.ONE.getCode(), SessionUtil.getUserCode());
} }
return null; return null;
} }

View File

@ -73,7 +73,7 @@ public class MaterialSubmitService {
public void submitOne(Long rowId) { public void submitOne(Long rowId) {
MaterialMainVO materialMainVO = materialMainService.selectByRowId(rowId, MaterialMainTypeEnum.ONE.getCode()); MaterialMainVO materialMainVO = materialMainService.selectByRowId(rowId, MaterialMainTypeEnum.ONE.getCode(), SessionUtil.getUserCode());
if (materialMainVO.getProcessState() > 0) { if (materialMainVO.getProcessState() > 0) {
throw new NflgBusinessException(STATE.ParamErr, materialMainVO.getMaterialNo().concat("物料已提交,不能重复提交")); throw new NflgBusinessException(STATE.ParamErr, materialMainVO.getMaterialNo().concat("物料已提交,不能重复提交"));

View File

@ -28,10 +28,7 @@ import com.nflg.product.material.pojo.dto.MaterialMainAttrDTO;
import com.nflg.product.material.pojo.dto.MaterialUpdateBillDTO; import com.nflg.product.material.pojo.dto.MaterialUpdateBillDTO;
import com.nflg.product.material.pojo.entity.*; import com.nflg.product.material.pojo.entity.*;
import com.nflg.product.material.pojo.query.MaterialUpdateBillQuery; import com.nflg.product.material.pojo.query.MaterialUpdateBillQuery;
import com.nflg.product.material.pojo.vo.MaterialHomeMainVO; import com.nflg.product.material.pojo.vo.*;
import com.nflg.product.material.pojo.vo.MaterialMainAttrValuesVO;
import com.nflg.product.material.pojo.vo.MaterialMainVO;
import com.nflg.product.material.pojo.vo.MaterialUpdateBillVO;
import com.nflg.product.material.util.EecExcelUtil; import com.nflg.product.material.util.EecExcelUtil;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import nflg.product.common.constant.STATE; import nflg.product.common.constant.STATE;
@ -40,6 +37,7 @@ import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils; import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestBody;
@ -89,6 +87,11 @@ public class MaterialUpdateBillService extends ServiceImpl<MaterialUpdateBillMap
@Value("${material.home.day:30}") @Value("${material.home.day:30}")
private Integer homeDay; private Integer homeDay;
@Resource
private RedisTemplate<String, String> redisTemplate;
private static final String PREFIX = "frontend:material";
/** /**
* 分页查询所有数据 * 分页查询所有数据
* *
@ -347,7 +350,7 @@ public class MaterialUpdateBillService extends ServiceImpl<MaterialUpdateBillMap
List<MaterialUpdateBillEntity> ents = new ArrayList<>(); List<MaterialUpdateBillEntity> ents = new ArrayList<>();
for (MaterialStateUpExcelDTO data : excelContext) { for (MaterialStateUpExcelDTO data : excelContext) {
MaterialMainEntity material = materialMainService.lambdaQuery().eq(MaterialMainEntity::getMaterialNo, data.getMaterialNo()).one(); MaterialMainEntity material = materialMainService.lambdaQuery().eq(MaterialMainEntity::getMaterialNo, data.getMaterialNo()).one();
MaterialMainVO materialMainVO = materialMainService.selectByRowId(material.getRowId(), MaterialMainTypeEnum.ONE.getCode()); MaterialMainVO materialMainVO = materialMainService.selectByRowId(material.getRowId(), MaterialMainTypeEnum.ONE.getCode(), SessionUtil.getUserCode());
MaterialUpdateBillEntity ent = new MaterialUpdateBillEntity(); MaterialUpdateBillEntity ent = new MaterialUpdateBillEntity();
ent.setMaterialNo(data.getMaterialNo()); ent.setMaterialNo(data.getMaterialNo());
ent.setOldMaterialState(material.getMaterialState()); ent.setOldMaterialState(material.getMaterialState());
@ -364,13 +367,17 @@ public class MaterialUpdateBillService extends ServiceImpl<MaterialUpdateBillMap
} }
this.saveBatch(ents); this.saveBatch(ents);
//同步OA //同步OA
materialUpdateToOAService.sysncToOaOnleState(ents); materialUpdateToOAService.sysncToOaOnleState(ents, SessionUtil.getUserCode());
} }
public ResultVO<Boolean> batchImport(MultipartFile file) throws IOException { public ResultVO<MaterialBatchImportVO> batchImport(MultipartFile file) throws IOException {
if (file != null && !file.getOriginalFilename().endsWith("xls") && !file.getOriginalFilename().endsWith("xlsx")) { if (file != null && !file.getOriginalFilename().endsWith("xls") && !file.getOriginalFilename().endsWith("xlsx")) {
return ResultVO.error("上传的文件非Excel文件"); return ResultVO.error("上传的文件非Excel文件");
} }
Object cacheFileName = redisTemplate.boundValueOps(buildKey(SessionUtil.getUserCode() + ":updateBatchImport")).get();
if (ObjectUtil.isNotEmpty(cacheFileName) && file.getOriginalFilename().equals(cacheFileName)) {
return ResultVO.error("当前Excel文件正在处理中请勿重复导入");
}
int lastColIndex = ExcelReader.read(file.getInputStream()).sheet(0).getHeader().getLastColumnIndex(); int lastColIndex = ExcelReader.read(file.getInputStream()).sheet(0).getHeader().getLastColumnIndex();
@ -392,43 +399,74 @@ public class MaterialUpdateBillService extends ServiceImpl<MaterialUpdateBillMap
applyDeptName = String.join("/", deptNameList); applyDeptName = String.join("/", deptNameList);
} }
String realName = SessionUtil.getRealName();
String userCode = SessionUtil.getUserCode();
MaterialBatchImportVO importVO = new MaterialBatchImportVO();
importVO.setInBatches(false);
if (lastColIndex == 4) { if (lastColIndex == 4) {
List<MaterialStateUpExcelDTO> excelContext = EecExcelUtil.getExcelContext(file.getInputStream(), MaterialStateUpExcelDTO.class); List<MaterialStateUpExcelDTO> excelContext = EecExcelUtil.getExcelContext(file.getInputStream(), MaterialStateUpExcelDTO.class);
if (CollectionUtil.isNotEmpty(excelContext) && excelContext.size() > 1000) { if (CollectionUtil.isNotEmpty(excelContext) && excelContext.size() > 100) {
redisTemplate.opsForValue().set(buildKey(userCode + "1:updateBatchImport"), file.getOriginalFilename());
redisTemplate.opsForValue().set(buildKey(userCode + "2:updateBatchImport"), file.getOriginalFilename());
redisTemplate.opsForValue().set(buildKey(userCode + "3:updateBatchImport"), file.getOriginalFilename());
// 大数据量子线程分批次提交OA每批1000条主线程提前返回结果给前端 // 大数据量子线程分批次提交OA每批1000条主线程提前返回结果给前端
CompletableFuture<Void> task1 = CompletableFuture.runAsync(() -> { CompletableFuture<Integer> task1 = CompletableFuture.supplyAsync(() -> {
List<List<MaterialStateUpExcelDTO>> lists = Lists.partition(excelContext, 1000); long startTime = System.currentTimeMillis();
lists.forEach(items -> this.handleImportDataForState(items, applyDeptName, deptEnt)); List<List<MaterialStateUpExcelDTO>> lists = Lists.partition(excelContext, 100);
lists.forEach(items -> this.handleImportDataForState(items, applyDeptName, deptEnt, realName, userCode));
long endTime = System.currentTimeMillis();
log.info("物料变更批量导入耗时ms: {}", endTime - startTime);
redisTemplate.delete(buildKey(userCode + ":updateBatchImport"));
return 1;
}); });
task1.join(); task1.exceptionally(ex -> {
// 异常处理器打印异常信息并返回默认值
log.error("物料变更批量导入异常: " + ex.getMessage());
redisTemplate.delete(buildKey(userCode + ":updateBatchImport"));
return -1;
});
// task1.join(); // 阻塞获取结果
importVO.setInBatches(true);
return ResultVO.success(importVO);
} else { } else {
this.handleImportDataForState(excelContext, applyDeptName, deptEnt); this.handleImportDataForState(excelContext, applyDeptName, deptEnt, realName, userCode);
} }
} else { } else {
// 制作物料 // 制作物料
List<TwentyMaterialTemplateExcelDTO> excelContext = EecExcelUtil.getExcelContext(file.getInputStream(), TwentyMaterialTemplateExcelDTO.class); List<TwentyMaterialTemplateExcelDTO> excelContext = EecExcelUtil.getExcelContext(file.getInputStream(), TwentyMaterialTemplateExcelDTO.class);
if (CollectionUtil.isNotEmpty(excelContext) && excelContext.size() > 1000) { if (CollectionUtil.isNotEmpty(excelContext) && excelContext.size() > 1000) {
// 大数据量子线程分批次提交OA每批1000条主线程提前返回结果给前端 // 大数据量子线程分批次提交OA每批1000条主线程提前返回结果给前端
CompletableFuture<Void> task1 = CompletableFuture.runAsync(() -> { CompletableFuture<Integer> task1 = CompletableFuture.supplyAsync(() -> {
long startTime = System.currentTimeMillis();
List<List<TwentyMaterialTemplateExcelDTO>> lists = Lists.partition(excelContext, 1000); List<List<TwentyMaterialTemplateExcelDTO>> lists = Lists.partition(excelContext, 1000);
lists.forEach(items -> this.handleImportDataForSummary(items, applyDeptName, deptEnt)); lists.forEach(items -> this.handleImportDataForSummary(items, applyDeptName, deptEnt, realName, userCode));
long endTime = System.currentTimeMillis();
log.info("物料变更批量导入耗时ms: {}", endTime - startTime);
return 1;
}); });
task1.join(); task1.exceptionally(ex -> {
// 异常处理器打印异常信息并返回默认值
log.error("物料变更批量导入异常: " + ex.getMessage());
return -1;
});
// task1.join(); // 阻塞获取结果
importVO.setInBatches(true);
return ResultVO.success(importVO);
} else { } else {
this.handleImportDataForSummary(excelContext, applyDeptName, deptEnt); this.handleImportDataForSummary(excelContext, applyDeptName, deptEnt, realName, userCode);
} }
} }
return ResultVO.success(Boolean.TRUE); return ResultVO.success(importVO);
} }
/** /**
* 状态变更 * 状态变更
*/ */
private ResultVO<Boolean> handleImportDataForState(List<MaterialStateUpExcelDTO> excelContext, String applyDeptName, AuthorityDepartmentEntity deptEnt) { private void handleImportDataForState(List<MaterialStateUpExcelDTO> excelContext, String applyDeptName, AuthorityDepartmentEntity deptEnt, String realName, String userCode) {
List<MaterialUpdateBillEntity> ents = new ArrayList<>(); List<MaterialUpdateBillEntity> ents = new ArrayList<>();
excelContext = excelContext.stream().filter(u -> StrUtil.isNotBlank(u.getMaterialNo())).collect(Collectors.toList()); excelContext = excelContext.stream().filter(u -> StrUtil.isNotBlank(u.getMaterialNo())).collect(Collectors.toList());
if (excelContext.size() <= 0) { if (excelContext.size() <= 0) {
return ResultVO.error("导入内容不允许为空"); throw new NflgBusinessException(STATE.ParamErr, "导入内容不允许为空");
} }
List<String> upMaterialNos = excelContext.stream().map(MaterialStateUpExcelDTO::getMaterialNo).collect(Collectors.toList()); List<String> upMaterialNos = excelContext.stream().map(MaterialStateUpExcelDTO::getMaterialNo).collect(Collectors.toList());
@ -463,11 +501,11 @@ public class MaterialUpdateBillService extends ServiceImpl<MaterialUpdateBillMap
Set<String> notFreezeSet = new HashSet<>(); Set<String> notFreezeSet = new HashSet<>();
for (MaterialStateUpExcelDTO data : excelContext) { for (MaterialStateUpExcelDTO data : excelContext) {
MaterialMainEntity material = materialMainService.lambdaQuery().eq(MaterialMainEntity::getMaterialNo, data.getMaterialNo()).one(); MaterialMainEntity material = materialMainService.lambdaQuery().eq(MaterialMainEntity::getMaterialNo, data.getMaterialNo()).one();
MaterialMainVO materialMainVO = materialMainService.selectByRowId(material.getRowId(), MaterialMainTypeEnum.ONE.getCode()); MaterialMainVO materialMainVO = materialMainService.selectByRowId(material.getRowId(), MaterialMainTypeEnum.ONE.getCode(), userCode);
String checkMaterialState = checkMaterialState(material); String checkMaterialState = checkMaterialState(material);
if (ObjectUtil.isNotEmpty(checkMaterialState)) { if (ObjectUtil.isNotEmpty(checkMaterialState)) {
return ResultVO.error(checkMaterialState); throw new NflgBusinessException(STATE.ParamErr, checkMaterialState);
} }
// 如果物料是状态变更且变更状态为冻结或完全弃用物料昨日库得值 大于 0时不允许申请冻结 // 如果物料是状态变更且变更状态为冻结或完全弃用物料昨日库得值 大于 0时不允许申请冻结
@ -481,7 +519,7 @@ public class MaterialUpdateBillService extends ServiceImpl<MaterialUpdateBillMap
boolean flagThree = materialState.compareTo(MaterialStateEnum.FROZEN.getValue()) == 0 || materialState.compareTo(MaterialStateEnum.GIVEUP.getValue()) == 0; boolean flagThree = materialState.compareTo(MaterialStateEnum.FROZEN.getValue()) == 0 || materialState.compareTo(MaterialStateEnum.GIVEUP.getValue()) == 0;
if (flagTwo && flagThree) { if (flagTwo && flagThree) {
if (flagOne) { if (flagOne) {
return ResultVO.error("物料编号为" + material.getMaterialNo() + "的物料还有库存,无法申请冻结或完全弃用"); throw new NflgBusinessException(STATE.ParamErr, "物料编号为" + material.getMaterialNo() + "的物料还有库存,无法申请冻结或完全弃用");
} }
} }
@ -497,8 +535,8 @@ public class MaterialUpdateBillService extends ServiceImpl<MaterialUpdateBillMap
ent.setOldCategoryNameTree(getMaterialCategoryTree(materialMainVO)); ent.setOldCategoryNameTree(getMaterialCategoryTree(materialMainVO));
ent.setOldMaterialDesc(material.getMaterialDesc()); ent.setOldMaterialDesc(material.getMaterialDesc());
ent.setApplyDeptName(applyDeptName); ent.setApplyDeptName(applyDeptName);
ent.setCreatedByName(SessionUtil.getRealName()); ent.setCreatedByName(realName);
ent.setCreatedBy(SessionUtil.getUserCode()); ent.setCreatedBy(userCode);
ent.setCreatedTime(new Date()); ent.setCreatedTime(new Date());
ents.add(ent); ents.add(ent);
@ -509,7 +547,7 @@ public class MaterialUpdateBillService extends ServiceImpl<MaterialUpdateBillMap
this.validateFreezeStateChangeOther(ents, deptEnt.getDptCode()); this.validateFreezeStateChangeOther(ents, deptEnt.getDptCode());
this.saveBatch(ents); this.saveBatch(ents);
//同步OA //同步OA
materialUpdateToOAService.sysncToOaOnleState(ents); materialUpdateToOAService.sysncToOaOnleState(ents, userCode);
if (CollectionUtil.isNotEmpty(notFreezeSet)) { if (CollectionUtil.isNotEmpty(notFreezeSet)) {
// 过滤出 1151物料 && 解冻 // 过滤出 1151物料 && 解冻
@ -533,17 +571,16 @@ public class MaterialUpdateBillService extends ServiceImpl<MaterialUpdateBillMap
materialMainService.updateBatchById(updateList); materialMainService.updateBatchById(updateList);
} }
} }
return ResultVO.success(Boolean.TRUE);
} }
/** /**
* 制作物料综合变更 * 制作物料综合变更
*/ */
private ResultVO<Boolean> handleImportDataForSummary(List<TwentyMaterialTemplateExcelDTO> excelContext, String applyDeptName, AuthorityDepartmentEntity deptEnt) { private void handleImportDataForSummary(List<TwentyMaterialTemplateExcelDTO> excelContext, String applyDeptName, AuthorityDepartmentEntity deptEnt, String realName, String userCode) {
List<MaterialUpdateBillEntity> ents = new ArrayList<>(); List<MaterialUpdateBillEntity> ents = new ArrayList<>();
excelContext = excelContext.stream().filter(u -> StrUtil.isNotBlank(u.getMaterialNo())).collect(Collectors.toList()); excelContext = excelContext.stream().filter(u -> StrUtil.isNotBlank(u.getMaterialNo())).collect(Collectors.toList());
if (excelContext.size() <= 0) { if (excelContext.size() <= 0) {
return ResultVO.error("导入内容不允许为空"); throw new NflgBusinessException(STATE.ParamErr, "导入内容不允许为空");
} }
List<String> upMaterialNos = excelContext.stream().map(TwentyMaterialTemplateExcelDTO::getMaterialNo).collect(Collectors.toList()); List<String> upMaterialNos = excelContext.stream().map(TwentyMaterialTemplateExcelDTO::getMaterialNo).collect(Collectors.toList());
@ -602,7 +639,7 @@ public class MaterialUpdateBillService extends ServiceImpl<MaterialUpdateBillMap
String checkMaterialState = checkMaterialState(material); String checkMaterialState = checkMaterialState(material);
if (ObjectUtil.isNotEmpty(checkMaterialState)) { if (ObjectUtil.isNotEmpty(checkMaterialState)) {
return ResultVO.error(checkMaterialState); throw new NflgBusinessException(STATE.ParamErr, checkMaterialState);
} }
MaterialMainVO materialMainVO = new MaterialMainVO(); MaterialMainVO materialMainVO = new MaterialMainVO();
@ -668,8 +705,8 @@ public class MaterialUpdateBillService extends ServiceImpl<MaterialUpdateBillMap
ent.setUpdateResion(data.getUpdateResion()); ent.setUpdateResion(data.getUpdateResion());
ent.setReplaceMaterialNo(data.getReplaceMaterialNo()); ent.setReplaceMaterialNo(data.getReplaceMaterialNo());
ent.setApplyDeptName(applyDeptName); ent.setApplyDeptName(applyDeptName);
ent.setCreatedByName(SessionUtil.getRealName()); ent.setCreatedByName(realName);
ent.setCreatedBy(SessionUtil.getUserCode()); ent.setCreatedBy(userCode);
ent.setCreatedTime(new Date()); ent.setCreatedTime(new Date());
ents.add(ent); ents.add(ent);
@ -677,13 +714,13 @@ public class MaterialUpdateBillService extends ServiceImpl<MaterialUpdateBillMap
ResultVO<String> checkMaterialDesc = checkMaterialDesc(ent); ResultVO<String> checkMaterialDesc = checkMaterialDesc(ent);
if (Objects.nonNull(checkMaterialDesc)) { if (Objects.nonNull(checkMaterialDesc)) {
log.info("【checkMaterialDesc校验结果】" + checkMaterialDesc.getMsg()); log.info("【checkMaterialDesc校验结果】" + checkMaterialDesc.getMsg());
return ResultVO.error(checkMaterialDesc.getMsg()); throw new NflgBusinessException(STATE.ParamErr, checkMaterialDesc.getMsg());
} }
} }
this.validateFreezeStateChangeOther(ents, deptEnt.getDptCode()); this.validateFreezeStateChangeOther(ents, deptEnt.getDptCode());
this.saveBatch(ents); this.saveBatch(ents);
//同步OA //同步OA
materialUpdateToOAService.sysnToOa(ents); materialUpdateToOAService.sysnToOa(ents, userCode);
} }
// 申请部门是 营销中心11,21变更由冻结改成其他状态不允许改成激活 // 申请部门是 营销中心11,21变更由冻结改成其他状态不允许改成激活
@ -885,7 +922,7 @@ public class MaterialUpdateBillService extends ServiceImpl<MaterialUpdateBillMap
MaterialUpdateBillEntity materialUpdateBillEntity = this.lambdaQuery().eq(MaterialUpdateBillEntity::getRowId, rowId).one(); MaterialUpdateBillEntity materialUpdateBillEntity = this.lambdaQuery().eq(MaterialUpdateBillEntity::getRowId, rowId).one();
MaterialMainEntity ent = materialMainService.lambdaQuery().eq(MaterialMainEntity::getMaterialNo, materialNo).one(); MaterialMainEntity ent = materialMainService.lambdaQuery().eq(MaterialMainEntity::getMaterialNo, materialNo).one();
if (!Objects.isNull(ent)) { if (!Objects.isNull(ent)) {
materialMainVO = materialMainService.selectByRowId(ent.getRowId(), MaterialMainTypeEnum.ONE.getCode()); materialMainVO = materialMainService.selectByRowId(ent.getRowId(), MaterialMainTypeEnum.ONE.getCode(), SessionUtil.getUserCode());
materialMainVO.setMaterialDesc(materialUpdateBillEntity.getNewMateiralDesc()); materialMainVO.setMaterialDesc(materialUpdateBillEntity.getNewMateiralDesc());
materialMainVO.setOldMaterialDesc(materialUpdateBillEntity.getOldMaterialDesc()); materialMainVO.setOldMaterialDesc(materialUpdateBillEntity.getOldMaterialDesc());
materialMainVO.setShortMaterialDesc(materialUpdateBillEntity.getNewShortMaterialDesc()); materialMainVO.setShortMaterialDesc(materialUpdateBillEntity.getNewShortMaterialDesc());
@ -1066,4 +1103,8 @@ public class MaterialUpdateBillService extends ServiceImpl<MaterialUpdateBillMap
} }
return rlist; return rlist;
} }
private String buildKey(String key) {
return StrUtil.format("{}:{}", PREFIX, key);
}
} }

View File

@ -74,13 +74,13 @@ public class MaterialUpdateToOAService {
public void submit(List<Long> rowIds) { public void submit(List<Long> rowIds) {
List<MaterialUpdateBillEntity> entityList = materialUpdateBillService.lambdaQuery().in(MaterialUpdateBillEntity::getRowId, rowIds).list(); List<MaterialUpdateBillEntity> entityList = materialUpdateBillService.lambdaQuery().in(MaterialUpdateBillEntity::getRowId, rowIds).list();
sysnToOa(entityList); sysnToOa(entityList, SessionUtil.getUserCode());
} }
public Map<String, Object> getHttpMap() { public Map<String, Object> getHttpMap(String userCode) {
Map<String, Object> result = new LinkedHashMap<>(); Map<String, Object> result = new LinkedHashMap<>();
result.put("userid", SessionUtil.getUserCode()); result.put("userid", userCode);
result.put("summary", NacosConfig.getNacosConfig().getSummary()); result.put("summary", NacosConfig.getNacosConfig().getSummary());
return result; return result;
} }
@ -89,9 +89,9 @@ public class MaterialUpdateToOAService {
* 同步OA变更状态 * 同步OA变更状态
* @param data * @param data
*/ */
public void sysncToOaOnleState(List<MaterialUpdateBillEntity> data) { public void sysncToOaOnleState(List<MaterialUpdateBillEntity> data, String userCode) {
Map<String, Object> result = getHttpMap(); Map<String, Object> result = getHttpMap(userCode);
List<Map<String, String>> list = new ArrayList<>(); List<Map<String, String>> list = new ArrayList<>();
data.forEach(u -> { data.forEach(u -> {
Map<String, String> material = new LinkedHashMap<>(); Map<String, String> material = new LinkedHashMap<>();
@ -133,14 +133,14 @@ public class MaterialUpdateToOAService {
httpStateToOa(result, data); httpStateToOa(result, data);
} }
public void sysnToOa(List<MaterialUpdateBillEntity> data) { public void sysnToOa(List<MaterialUpdateBillEntity> data, String userCode) {
// 批量提交校验是否有重复物料变更 // 批量提交校验是否有重复物料变更
Set<String> materialNoSet = data.stream().map(MaterialUpdateBillEntity::getMaterialNo).collect(Collectors.toSet()); Set<String> materialNoSet = data.stream().map(MaterialUpdateBillEntity::getMaterialNo).collect(Collectors.toSet());
if (data.size() != materialNoSet.size()) { if (data.size() != materialNoSet.size()) {
throw new NflgBusinessException(STATE.BusinessError, "批量提交的物料含重复项,请先删除重复项"); throw new NflgBusinessException(STATE.BusinessError, "批量提交的物料含重复项,请先删除重复项");
} }
Map<String, Object> result = getHttpMap(); Map<String, Object> result = getHttpMap(userCode);
List<Map<String, String>> list = new ArrayList<>(); List<Map<String, String>> list = new ArrayList<>();
preHandleCategoryNameTree(data); preHandleCategoryNameTree(data);
data.forEach(u -> { data.forEach(u -> {

View File

@ -1,4 +1,14 @@
#nacos.server-addr=114.132.64.230:8123 #nacos.server-addr=114.132.64.230:8123
nacos.server-addr=192.168.0.194:8848 nacos.server-addr=192.168.0.194:8848
spring.cache.type=redis
spring.redis.database=1
spring.redis.host=192.168.0.194
spring.redis.password=
spring.redis.port=6379
spring.redis.timeout=0
spring.redis.ssl=false
spring.redis.lettuce.pool.max-wait=-1ms
spring.redis.lettuce.pool.max-active=8
spring.redis.lettuce.pool.max-idle=8
spring.redis.lettuce.pool.min-idle=0

View File

@ -1 +1,12 @@
nacos.server-addr=192.168.0.191:8848 nacos.server-addr=192.168.0.191:8848
spring.cache.type=redis
spring.redis.database=0
spring.redis.host=192.168.0.191
spring.redis.password=
spring.redis.port=6379
spring.redis.timeout=0
spring.redis.ssl=false
spring.redis.lettuce.pool.max-wait=-1ms
spring.redis.lettuce.pool.max-active=8
spring.redis.lettuce.pool.max-idle=8
spring.redis.lettuce.pool.min-idle=0

View File

@ -1,4 +1,14 @@
#nacos.server-addr=114.132.64.230:8123 #nacos.server-addr=114.132.64.230:8123
nacos.server-addr=192.168.0.194:8848 nacos.server-addr=192.168.0.194:8848
spring.cache.type=redis
spring.redis.database=1
spring.redis.host=192.168.0.194
spring.redis.password=
spring.redis.port=6379
spring.redis.timeout=0
spring.redis.ssl=false
spring.redis.lettuce.pool.max-wait=-1ms
spring.redis.lettuce.pool.max-active=8
spring.redis.lettuce.pool.max-idle=8
spring.redis.lettuce.pool.min-idle=0