【物料变更】大批量导入
This commit is contained in:
parent
842b9b48ff
commit
bc1a959489
|
|
@ -52,6 +52,7 @@ import java.io.IOException;
|
|||
import java.time.LocalDate;
|
||||
import java.time.ZoneId;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
|
|
@ -372,7 +373,6 @@ public class MaterialUpdateBillService extends ServiceImpl<MaterialUpdateBillMap
|
|||
}
|
||||
|
||||
int lastColIndex = ExcelReader.read(file.getInputStream()).sheet(0).getHeader().getLastColumnIndex();
|
||||
List<MaterialUpdateBillEntity> ents = new ArrayList<>();
|
||||
|
||||
AuthorityDepartmentEntity deptEnt = departmentService.getById(SessionUtil.getPartRowId());
|
||||
if (Objects.isNull(deptEnt)) {
|
||||
|
|
@ -394,263 +394,298 @@ public class MaterialUpdateBillService extends ServiceImpl<MaterialUpdateBillMap
|
|||
|
||||
if (lastColIndex == 4) {
|
||||
List<MaterialStateUpExcelDTO> excelContext = EecExcelUtil.getExcelContext(file.getInputStream(), MaterialStateUpExcelDTO.class);
|
||||
excelContext = excelContext.stream().filter(u -> StrUtil.isNotBlank(u.getMaterialNo())).collect(Collectors.toList());
|
||||
if (excelContext.size() <= 0) {
|
||||
return ResultVO.error("导入内容不允许为空");
|
||||
}
|
||||
|
||||
List<String> upMaterialNos = excelContext.stream().map(MaterialStateUpExcelDTO::getMaterialNo).collect(Collectors.toList());
|
||||
checkMaterialRep(upMaterialNos);
|
||||
|
||||
Set<String> exitstUpNos = Sets.newHashSet(this.getBaseMapper().getExtstUpdataBillMaterialNos(upMaterialNos));
|
||||
Set<String> upMaterialNosSet = Sets.newHashSet(upMaterialNos);
|
||||
Set<String> intersection = Sets.intersection(exitstUpNos, upMaterialNosSet);
|
||||
if (intersection.size() > 0) {
|
||||
throw new NflgBusinessException(STATE.ParamErr, StrUtil.join(",", intersection).concat("已有存在申请中的变更单"));
|
||||
}
|
||||
//正式物料
|
||||
HashSet<String> formalMNos = Sets.newHashSet(this.getBaseMapper().getExtstFormalMaterialNos(upMaterialNos));
|
||||
Set<String> formDifferenceSet = Sets.difference(upMaterialNosSet, formalMNos);
|
||||
if (formDifferenceSet.size() > 0) {
|
||||
throw new NflgBusinessException(STATE.ParamErr, StrUtil.join(",", formDifferenceSet).concat("为非正式物料,不允许变更"));
|
||||
}
|
||||
|
||||
List<MaterialStateUpExcelDTO> updateResionList = excelContext.stream().filter(item -> StringUtils.isEmpty(item.getUpdateResion())).collect(Collectors.toList());
|
||||
List<String> updateResionMaterialNoList = updateResionList.stream().map(MaterialStateUpExcelDTO::getMaterialNo).collect(Collectors.toList());
|
||||
if (updateResionMaterialNoList.size() > 0) {
|
||||
throw new NflgBusinessException(STATE.ParamErr, StrUtil.join(",", updateResionMaterialNoList).concat("为未填写变更原因"));
|
||||
}
|
||||
|
||||
Set<String> states = Sets.newHashSet("激活", "禁止采购", "售后专用", "冻结", "完全弃用");
|
||||
Set<String> excelStates = Sets.newHashSet(excelContext.stream().map(u -> EecExcelUtil.StringTrim(u.getNewState())).filter(StringUtils::isNotEmpty).collect(Collectors.toList()));
|
||||
Set<String> difState = Sets.difference(excelStates, states);
|
||||
if (difState.size() > 0) {
|
||||
throw new NflgBusinessException(STATE.ParamErr, StrUtil.join(",", difState).concat(" 状态错误,状态不能含有空格,状态只能选择激活/禁止采购/售后专用/冻结/完全弃用"));
|
||||
}
|
||||
// 变更后状态不是冻结的集合
|
||||
Set<String> notFreezeSet = new HashSet<>();
|
||||
for (MaterialStateUpExcelDTO data : excelContext) {
|
||||
MaterialMainEntity material = materialMainService.lambdaQuery().eq(MaterialMainEntity::getMaterialNo, data.getMaterialNo()).one();
|
||||
MaterialMainVO materialMainVO = materialMainService.selectByRowId(material.getRowId(), MaterialMainTypeEnum.ONE.getCode());
|
||||
|
||||
String checkMaterialState = checkMaterialState(material);
|
||||
if (ObjectUtil.isNotEmpty(checkMaterialState)) {
|
||||
return ResultVO.error(checkMaterialState);
|
||||
}
|
||||
|
||||
// 如果物料是状态变更,且变更状态为冻结或完全弃用,物料昨日库得值 大于 0时,不允许申请冻结
|
||||
Integer materialState = MaterialStateConstant.materialStateNameKeyMp.get(EecExcelUtil.StringTrim(data.getNewState()));
|
||||
Double materialStock = 0D;
|
||||
if (Objects.nonNull(material.getMaterialStock())) {
|
||||
materialStock = material.getMaterialStock();
|
||||
}
|
||||
boolean flagOne = materialStock.compareTo(0D) > 0;
|
||||
boolean flagTwo = materialState.compareTo(material.getMaterialState()) != 0;
|
||||
boolean flagThree = materialState.compareTo(MaterialStateEnum.FROZEN.getValue()) == 0 || materialState.compareTo(MaterialStateEnum.GIVEUP.getValue()) == 0;
|
||||
if (flagTwo && flagThree) {
|
||||
if (flagOne) {
|
||||
return ResultVO.error("物料编号为" + material.getMaterialNo() + "的物料还有库存,无法申请冻结或完全弃用");
|
||||
}
|
||||
}
|
||||
|
||||
MaterialUpdateBillEntity ent = new MaterialUpdateBillEntity();
|
||||
ent.setMaterialNo(data.getMaterialNo());
|
||||
ent.setOldMaterialState(material.getMaterialState());
|
||||
ent.setOldMaterialStateName(MaterialStateConstant.materialStateMp.get(material.getMaterialState()));
|
||||
ent.setNewMaterialState(materialState);
|
||||
ent.setNewMaterialStateName(data.getNewState());
|
||||
ent.setUpdateResion(data.getUpdateResion());
|
||||
ent.setReplaceMaterialNo(data.getReplaceMaterialNo());
|
||||
ent.setOldCategoryCode(material.getMaterialCategoryCode());
|
||||
ent.setOldCategoryNameTree(getMaterialCategoryTree(materialMainVO));
|
||||
ent.setOldMaterialDesc(material.getMaterialDesc());
|
||||
ent.setApplyDeptName(applyDeptName);
|
||||
ent.setCreatedByName(SessionUtil.getRealName());
|
||||
ent.setCreatedBy(SessionUtil.getUserCode());
|
||||
ent.setCreatedTime(new Date());
|
||||
ents.add(ent);
|
||||
|
||||
if (materialState != 4) {
|
||||
notFreezeSet.add(data.getMaterialNo());
|
||||
}
|
||||
}
|
||||
this.validateFreezeStateChangeOther(ents, deptEnt.getDptCode());
|
||||
this.saveBatch(ents);
|
||||
//同步OA
|
||||
materialUpdateToOAService.sysncToOaOnleState(ents);
|
||||
|
||||
if (CollectionUtil.isNotEmpty(notFreezeSet)) {
|
||||
// 过滤出 11、51物料 && 解冻
|
||||
List<MaterialMainEntity> notFreezeList = materialMainService.lambdaQuery()
|
||||
.and(q -> q.in(MaterialMainEntity::getMaterialNo, notFreezeSet))
|
||||
.and(q -> q.likeRight(MaterialMainEntity::getMaterialCategoryCode, "10").or().likeRight(MaterialMainEntity::getMaterialCategoryCode, "50"))
|
||||
.and(q -> q.eq(MaterialMainEntity::getMaterialState, 4))
|
||||
.list();
|
||||
if (CollectionUtil.isNotEmpty(notFreezeList)) {
|
||||
log.debug("【物料变更】解冻的物料号:\n");
|
||||
List<MaterialMainEntity> updateList = new ArrayList<>(notFreezeList.size());
|
||||
// 11、51物料 && 解冻,则运算起始时间为变更申请时间一年之后
|
||||
Date startDate = Date.from(LocalDate.now().plusYears(1L).atStartOfDay().atZone(ZoneId.systemDefault()).toInstant());
|
||||
notFreezeList.forEach(item -> {
|
||||
MaterialMainEntity entity = new MaterialMainEntity();
|
||||
entity.setRowId(item.getRowId());
|
||||
updateList.add(entity);
|
||||
log.debug("{}\t", item.getMaterialNo());
|
||||
});
|
||||
updateList.forEach(item -> item.setFreezeCalcStart(startDate));
|
||||
materialMainService.updateBatchById(updateList);
|
||||
}
|
||||
if (CollectionUtil.isNotEmpty(excelContext) && excelContext.size() > 1000) {
|
||||
// 大数据量,子线程分批次提交OA(每批1000条),主线程提前返回结果给前端
|
||||
CompletableFuture<Void> task1 = CompletableFuture.runAsync(() -> {
|
||||
List<List<MaterialStateUpExcelDTO>> lists = Lists.partition(excelContext, 1000);
|
||||
lists.forEach(items -> this.handleImportDataForState(items, applyDeptName, deptEnt));
|
||||
});
|
||||
task1.join();
|
||||
} else {
|
||||
this.handleImportDataForState(excelContext, applyDeptName, deptEnt);
|
||||
}
|
||||
} else {
|
||||
// 制作物料
|
||||
List<TwentyMaterialTemplateExcelDTO> excelContext = EecExcelUtil.getExcelContext(file.getInputStream(), TwentyMaterialTemplateExcelDTO.class);
|
||||
excelContext = excelContext.stream().filter(u -> StrUtil.isNotBlank(u.getMaterialNo())).collect(Collectors.toList());
|
||||
if (excelContext.size() <= 0) {
|
||||
return ResultVO.error("导入内容不允许为空");
|
||||
if (CollectionUtil.isNotEmpty(excelContext) && excelContext.size() > 1000) {
|
||||
// 大数据量,子线程分批次提交OA(每批1000条),主线程提前返回结果给前端
|
||||
CompletableFuture<Void> task1 = CompletableFuture.runAsync(() -> {
|
||||
List<List<TwentyMaterialTemplateExcelDTO>> lists = Lists.partition(excelContext, 1000);
|
||||
lists.forEach(items -> this.handleImportDataForSummary(items, applyDeptName, deptEnt));
|
||||
});
|
||||
task1.join();
|
||||
} else {
|
||||
this.handleImportDataForSummary(excelContext, applyDeptName, deptEnt);
|
||||
}
|
||||
|
||||
List<String> upMaterialNos = excelContext.stream().map(TwentyMaterialTemplateExcelDTO::getMaterialNo).collect(Collectors.toList());
|
||||
checkMaterialRep(upMaterialNos);
|
||||
|
||||
Set<String> exitstUpNos = Sets.newHashSet(this.getBaseMapper().getExtstUpdataBillMaterialNos(upMaterialNos));
|
||||
Set<String> upMaterialNosSet = Sets.newHashSet(upMaterialNos);
|
||||
Set<String> intersection = Sets.intersection(exitstUpNos, upMaterialNosSet);
|
||||
if (intersection.size() > 0) {
|
||||
throw new NflgBusinessException(STATE.ParamErr, StrUtil.join(",", intersection).concat("已有存在申请中的变更单"));
|
||||
}
|
||||
//正式物料
|
||||
HashSet<String> formalMNos = Sets.newHashSet(this.getBaseMapper().getExtstFormalMaterialNos(upMaterialNos));
|
||||
Set<String> formDifferenceSet = Sets.difference(upMaterialNosSet, formalMNos);
|
||||
if (formDifferenceSet.size() > 0) {
|
||||
throw new NflgBusinessException(STATE.ParamErr, StrUtil.join(",", formDifferenceSet).concat("为非正式物料,不允许变更"));
|
||||
}
|
||||
|
||||
// 判断新图号是否在数据库中已存在
|
||||
List<String> drawingNoList = excelContext.stream().map(TwentyMaterialTemplateExcelDTO::getDrawingNo).collect(Collectors.toList());
|
||||
List<MaterialMainEntity> entityList = this.materialMainService.lambdaQuery().in(MaterialMainEntity::getDrawingNo, drawingNoList).list();
|
||||
if (entityList != null && entityList.size() > 0) {
|
||||
List<String> drawingNos = entityList.stream().map(MaterialMainEntity::getDrawingNo).collect(Collectors.toList());
|
||||
List<MaterialMainEntity> others = entityList.stream().filter(item -> !upMaterialNos.contains(item.getMaterialNo())).collect(Collectors.toList());
|
||||
if (others.size() > 0) {
|
||||
throw new NflgBusinessException(STATE.ParamErr, StrUtil.join(",", drawingNos).concat("的图号在正式物料中已存在"));
|
||||
}
|
||||
}
|
||||
// 申请中的变更
|
||||
List<MaterialUpdateBillEntity> billEntityList = this.lambdaQuery().eq(MaterialUpdateBillEntity::getBillState, 1).in(MaterialUpdateBillEntity::getDrawingNo, drawingNoList).list();
|
||||
if (billEntityList != null && billEntityList.size() > 0) {
|
||||
List<String> drawingNos = billEntityList.stream().map(MaterialUpdateBillEntity::getDrawingNo).collect(Collectors.toList());
|
||||
throw new NflgBusinessException(STATE.ParamErr, StrUtil.join(",", drawingNos).concat("的新图号在变更申请中已存在,请检查"));
|
||||
}
|
||||
|
||||
Set<String> states = Sets.newHashSet("激活", "禁止采购", "售后专用", "冻结", "完全弃用");
|
||||
Set<String> excelStates = excelContext.stream().filter(item -> StringUtils.isNotEmpty(item.getNewState()))
|
||||
.map(u -> EecExcelUtil.StringTrim(u.getNewState())).filter(StringUtils::isNotEmpty).collect(Collectors.toSet());
|
||||
Set<String> difState = Sets.difference(excelStates, states);
|
||||
if (difState.size() > 0) {
|
||||
throw new NflgBusinessException(STATE.ParamErr, StrUtil.join(",", difState).concat("状态错误,状态不能含有空格,状态只能选择激活/禁止采购/售后专用/冻结/完全弃用"));
|
||||
}
|
||||
|
||||
List<TwentyMaterialTemplateExcelDTO> updateResionList = excelContext.stream().filter(item -> StringUtils.isEmpty(item.getUpdateResion())).collect(Collectors.toList());
|
||||
List<String> updateResionMaterialNoList = updateResionList.stream().map(TwentyMaterialTemplateExcelDTO::getMaterialNo).collect(Collectors.toList());
|
||||
if (updateResionMaterialNoList.size() > 0) {
|
||||
throw new NflgBusinessException(STATE.ParamErr, StrUtil.join(",", updateResionMaterialNoList).concat("为未填写变更原因"));
|
||||
}
|
||||
|
||||
for (TwentyMaterialTemplateExcelDTO data : excelContext) {
|
||||
MaterialMainEntity material = materialMainService.lambdaQuery().eq(MaterialMainEntity::getMaterialNo, data.getMaterialNo()).one();
|
||||
if (material.getProcessState().compareTo(MaterialProcessStateEnum.AUDIT.getValue()) != 0 && material.getProcessState().compareTo(MaterialProcessStateEnum.HISTORY_MATERIAL.getValue()) != 0) {
|
||||
MaterialProcessStateEnum materialProcessStateEnum = MaterialProcessStateEnum.findDescriptionByValue(material.getProcessState());
|
||||
throw new NflgBusinessException(STATE.Error, "物料号为" + data.getMaterialNo() + "的物料流程状态为" + materialProcessStateEnum.getDescription() + ",不允许导入变更");
|
||||
}
|
||||
|
||||
String checkMaterialState = checkMaterialState(material);
|
||||
if (ObjectUtil.isNotEmpty(checkMaterialState)) {
|
||||
return ResultVO.error(checkMaterialState);
|
||||
}
|
||||
|
||||
MaterialMainVO materialMainVO = new MaterialMainVO();
|
||||
BeanUtils.copyProperties(material, materialMainVO);
|
||||
MaterialUpdateBillEntity ent = new MaterialUpdateBillEntity();
|
||||
ent.setMaterialNo(data.getMaterialNo());
|
||||
if (StringUtils.isNotEmpty(data.getNewState())) {
|
||||
ent.setNewMaterialState(MaterialStateConstant.materialStateNameKeyMp.get(EecExcelUtil.StringTrim(data.getNewState())));
|
||||
ent.setNewMaterialStateName(data.getNewState());
|
||||
}
|
||||
|
||||
MaterialCategoryEntity materialCategoryEntity = materialCategoryService.lambdaQuery().eq(MaterialCategoryEntity::getCategoryCode, 20L).one();
|
||||
MaterialCategoryEntity secCategoryEntity, threeCategoryEntity;
|
||||
if (StringUtils.isNotEmpty(data.getSecondMaterialCategoryName()) && StringUtils.isNotEmpty(data.getThirdMaterialCategoryName())) {
|
||||
secCategoryEntity = materialCategoryService.getBaseMapper().selectByParentCategoryRowIdAndCategoryName(materialCategoryEntity.getRowId(), data.getSecondMaterialCategoryName().trim());
|
||||
if (secCategoryEntity == null) {
|
||||
throw new NflgBusinessException(STATE.Error, "新中类不存在,请确认是否是制作物料的中类");
|
||||
}
|
||||
threeCategoryEntity = materialCategoryService.getBaseMapper().selectByParentCategoryRowIdAndCategoryName(secCategoryEntity.getRowId(), data.getThirdMaterialCategoryName().trim());
|
||||
if (threeCategoryEntity == null) {
|
||||
throw new NflgBusinessException(STATE.Error, "新小类不存在,请确认是否是制作物料的小类");
|
||||
}
|
||||
ent.setNewCategoryCode(threeCategoryEntity.getCategoryCode());
|
||||
MaterialMainVO vo = new MaterialMainVO();
|
||||
vo.setSecondMaterialCategoryName(secCategoryEntity.getCategoryName());
|
||||
vo.setThirdMaterialCategoryName(threeCategoryEntity.getCategoryName());
|
||||
ent.setNewCategoryNameTree(getMaterialCategoryTree(vo));
|
||||
} else {
|
||||
threeCategoryEntity = materialCategoryService.lambdaQuery().eq(MaterialCategoryEntity::getCategoryCode, material.getMaterialCategoryCode()).one();
|
||||
}
|
||||
// (relCategoryCode=21)的物料,图号或者名称有变更时,导入后系统需自动重新拼接生成新物料描述。
|
||||
// (relCategoryCode=22)的物料,当前新增物料描述或申请变更时,他们的物料描述=物料名称
|
||||
if (threeCategoryEntity.getRelCategoryCode().equals("21")) {
|
||||
if (StringUtils.isNotEmpty(data.getDrawingNo()) && StringUtils.isNotEmpty(data.getMaterialName())) {
|
||||
ent.setNewMateiralDesc(data.getDrawingNo() + " " + data.getMaterialName());
|
||||
}
|
||||
if (StringUtils.isEmpty(data.getDrawingNo()) && StringUtils.isNotEmpty(data.getMaterialName())) {
|
||||
ent.setNewMateiralDesc(material.getDrawingNo() + " " + data.getMaterialName());
|
||||
}
|
||||
if (StringUtils.isNotEmpty(data.getDrawingNo()) && StringUtils.isEmpty(data.getMaterialName())) {
|
||||
ent.setNewMateiralDesc(data.getDrawingNo() + " " + material.getMaterialName());
|
||||
}
|
||||
}
|
||||
// 如果制作物料-发货直发制作包、非图纸物料,则强制赋值:物料名称=图号=物料描述
|
||||
if (threeCategoryEntity.getRelCategoryCode().equals("22")) {
|
||||
if (StringUtils.isNotEmpty(data.getMaterialName())) {
|
||||
ent.setNewMateiralDesc(data.getMaterialName());
|
||||
ent.setNewDrawingNo(data.getMaterialName());
|
||||
}
|
||||
}
|
||||
|
||||
ent.setOldMaterialState(material.getMaterialState());
|
||||
ent.setOldMaterialStateName(MaterialStateConstant.materialStateMp.get(material.getMaterialState()));
|
||||
ent.setOldCategoryCode(material.getMaterialCategoryCode());
|
||||
ent.setOldCategoryNameTree(getMaterialCategoryTree(materialMainVO));
|
||||
ent.setOldMaterialDesc(material.getMaterialDesc());
|
||||
ent.setOldShortMaterialDesc(material.getShortMaterialDesc());
|
||||
ent.setOldDrawingNo(material.getDrawingNo());
|
||||
|
||||
// 20230809--新增物料名称数据
|
||||
ent.setMaterialName(data.getMaterialName());
|
||||
ent.setNewDrawingNo(data.getDrawingNo());
|
||||
ent.setUpdateResion(data.getUpdateResion());
|
||||
ent.setReplaceMaterialNo(data.getReplaceMaterialNo());
|
||||
ent.setApplyDeptName(applyDeptName);
|
||||
ent.setCreatedByName(SessionUtil.getRealName());
|
||||
ent.setCreatedBy(SessionUtil.getUserCode());
|
||||
ent.setCreatedTime(new Date());
|
||||
ents.add(ent);
|
||||
|
||||
// 允许简化描述变更前后相同,但不可与系统内其他物料的描述或简化描述相同
|
||||
ResultVO<String> checkMaterialDesc = checkMaterialDesc(ent);
|
||||
if (Objects.nonNull(checkMaterialDesc)) {
|
||||
log.info("【checkMaterialDesc校验结果】:" + checkMaterialDesc.getMsg());
|
||||
return ResultVO.error(checkMaterialDesc.getMsg());
|
||||
}
|
||||
}
|
||||
this.validateFreezeStateChangeOther(ents, deptEnt.getDptCode());
|
||||
this.saveBatch(ents);
|
||||
//同步OA
|
||||
materialUpdateToOAService.sysnToOa(ents);
|
||||
}
|
||||
return ResultVO.success(Boolean.TRUE);
|
||||
}
|
||||
|
||||
/**
|
||||
* 状态变更
|
||||
*/
|
||||
private ResultVO<Boolean> handleImportDataForState(List<MaterialStateUpExcelDTO> excelContext, String applyDeptName, AuthorityDepartmentEntity deptEnt) {
|
||||
List<MaterialUpdateBillEntity> ents = new ArrayList<>();
|
||||
excelContext = excelContext.stream().filter(u -> StrUtil.isNotBlank(u.getMaterialNo())).collect(Collectors.toList());
|
||||
if (excelContext.size() <= 0) {
|
||||
return ResultVO.error("导入内容不允许为空");
|
||||
}
|
||||
|
||||
List<String> upMaterialNos = excelContext.stream().map(MaterialStateUpExcelDTO::getMaterialNo).collect(Collectors.toList());
|
||||
checkMaterialRep(upMaterialNos);
|
||||
|
||||
Set<String> exitstUpNos = Sets.newHashSet(this.getBaseMapper().getExtstUpdataBillMaterialNos(upMaterialNos));
|
||||
Set<String> upMaterialNosSet = Sets.newHashSet(upMaterialNos);
|
||||
Set<String> intersection = Sets.intersection(exitstUpNos, upMaterialNosSet);
|
||||
if (intersection.size() > 0) {
|
||||
throw new NflgBusinessException(STATE.ParamErr, StrUtil.join(",", intersection).concat("已有存在申请中的变更单"));
|
||||
}
|
||||
//正式物料
|
||||
HashSet<String> formalMNos = Sets.newHashSet(this.getBaseMapper().getExtstFormalMaterialNos(upMaterialNos));
|
||||
Set<String> formDifferenceSet = Sets.difference(upMaterialNosSet, formalMNos);
|
||||
if (formDifferenceSet.size() > 0) {
|
||||
throw new NflgBusinessException(STATE.ParamErr, StrUtil.join(",", formDifferenceSet).concat("为非正式物料,不允许变更"));
|
||||
}
|
||||
|
||||
List<MaterialStateUpExcelDTO> updateResionList = excelContext.stream().filter(item -> StringUtils.isEmpty(item.getUpdateResion())).collect(Collectors.toList());
|
||||
List<String> updateResionMaterialNoList = updateResionList.stream().map(MaterialStateUpExcelDTO::getMaterialNo).collect(Collectors.toList());
|
||||
if (updateResionMaterialNoList.size() > 0) {
|
||||
throw new NflgBusinessException(STATE.ParamErr, StrUtil.join(",", updateResionMaterialNoList).concat("为未填写变更原因"));
|
||||
}
|
||||
|
||||
Set<String> states = Sets.newHashSet("激活", "禁止采购", "售后专用", "冻结", "完全弃用");
|
||||
Set<String> excelStates = Sets.newHashSet(excelContext.stream().map(u -> EecExcelUtil.StringTrim(u.getNewState())).filter(StringUtils::isNotEmpty).collect(Collectors.toList()));
|
||||
Set<String> difState = Sets.difference(excelStates, states);
|
||||
if (difState.size() > 0) {
|
||||
throw new NflgBusinessException(STATE.ParamErr, StrUtil.join(",", difState).concat(" 状态错误,状态不能含有空格,状态只能选择激活/禁止采购/售后专用/冻结/完全弃用"));
|
||||
}
|
||||
// 变更后状态不是冻结的集合
|
||||
Set<String> notFreezeSet = new HashSet<>();
|
||||
for (MaterialStateUpExcelDTO data : excelContext) {
|
||||
MaterialMainEntity material = materialMainService.lambdaQuery().eq(MaterialMainEntity::getMaterialNo, data.getMaterialNo()).one();
|
||||
MaterialMainVO materialMainVO = materialMainService.selectByRowId(material.getRowId(), MaterialMainTypeEnum.ONE.getCode());
|
||||
|
||||
String checkMaterialState = checkMaterialState(material);
|
||||
if (ObjectUtil.isNotEmpty(checkMaterialState)) {
|
||||
return ResultVO.error(checkMaterialState);
|
||||
}
|
||||
|
||||
// 如果物料是状态变更,且变更状态为冻结或完全弃用,物料昨日库得值 大于 0时,不允许申请冻结
|
||||
Integer materialState = MaterialStateConstant.materialStateNameKeyMp.get(EecExcelUtil.StringTrim(data.getNewState()));
|
||||
Double materialStock = 0D;
|
||||
if (Objects.nonNull(material.getMaterialStock())) {
|
||||
materialStock = material.getMaterialStock();
|
||||
}
|
||||
boolean flagOne = materialStock.compareTo(0D) > 0;
|
||||
boolean flagTwo = materialState.compareTo(material.getMaterialState()) != 0;
|
||||
boolean flagThree = materialState.compareTo(MaterialStateEnum.FROZEN.getValue()) == 0 || materialState.compareTo(MaterialStateEnum.GIVEUP.getValue()) == 0;
|
||||
if (flagTwo && flagThree) {
|
||||
if (flagOne) {
|
||||
return ResultVO.error("物料编号为" + material.getMaterialNo() + "的物料还有库存,无法申请冻结或完全弃用");
|
||||
}
|
||||
}
|
||||
|
||||
MaterialUpdateBillEntity ent = new MaterialUpdateBillEntity();
|
||||
ent.setMaterialNo(data.getMaterialNo());
|
||||
ent.setOldMaterialState(material.getMaterialState());
|
||||
ent.setOldMaterialStateName(MaterialStateConstant.materialStateMp.get(material.getMaterialState()));
|
||||
ent.setNewMaterialState(materialState);
|
||||
ent.setNewMaterialStateName(data.getNewState());
|
||||
ent.setUpdateResion(data.getUpdateResion());
|
||||
ent.setReplaceMaterialNo(data.getReplaceMaterialNo());
|
||||
ent.setOldCategoryCode(material.getMaterialCategoryCode());
|
||||
ent.setOldCategoryNameTree(getMaterialCategoryTree(materialMainVO));
|
||||
ent.setOldMaterialDesc(material.getMaterialDesc());
|
||||
ent.setApplyDeptName(applyDeptName);
|
||||
ent.setCreatedByName(SessionUtil.getRealName());
|
||||
ent.setCreatedBy(SessionUtil.getUserCode());
|
||||
ent.setCreatedTime(new Date());
|
||||
ents.add(ent);
|
||||
|
||||
if (materialState != 4) {
|
||||
notFreezeSet.add(data.getMaterialNo());
|
||||
}
|
||||
}
|
||||
this.validateFreezeStateChangeOther(ents, deptEnt.getDptCode());
|
||||
this.saveBatch(ents);
|
||||
//同步OA
|
||||
materialUpdateToOAService.sysncToOaOnleState(ents);
|
||||
|
||||
if (CollectionUtil.isNotEmpty(notFreezeSet)) {
|
||||
// 过滤出 11、51物料 && 解冻
|
||||
List<MaterialMainEntity> notFreezeList = materialMainService.lambdaQuery()
|
||||
.and(q -> q.in(MaterialMainEntity::getMaterialNo, notFreezeSet))
|
||||
.and(q -> q.likeRight(MaterialMainEntity::getMaterialCategoryCode, "10").or().likeRight(MaterialMainEntity::getMaterialCategoryCode, "50"))
|
||||
.and(q -> q.eq(MaterialMainEntity::getMaterialState, 4))
|
||||
.list();
|
||||
if (CollectionUtil.isNotEmpty(notFreezeList)) {
|
||||
log.debug("【物料变更】解冻的物料号:\n");
|
||||
List<MaterialMainEntity> updateList = new ArrayList<>(notFreezeList.size());
|
||||
// 11、51物料 && 解冻,则运算起始时间为变更申请时间一年之后
|
||||
Date startDate = Date.from(LocalDate.now().plusYears(1L).atStartOfDay().atZone(ZoneId.systemDefault()).toInstant());
|
||||
notFreezeList.forEach(item -> {
|
||||
MaterialMainEntity entity = new MaterialMainEntity();
|
||||
entity.setRowId(item.getRowId());
|
||||
updateList.add(entity);
|
||||
log.debug("{}\t", item.getMaterialNo());
|
||||
});
|
||||
updateList.forEach(item -> item.setFreezeCalcStart(startDate));
|
||||
materialMainService.updateBatchById(updateList);
|
||||
}
|
||||
}
|
||||
return ResultVO.success(Boolean.TRUE);
|
||||
}
|
||||
|
||||
/**
|
||||
* 制作物料综合变更
|
||||
*/
|
||||
private ResultVO<Boolean> handleImportDataForSummary(List<TwentyMaterialTemplateExcelDTO> excelContext, String applyDeptName, AuthorityDepartmentEntity deptEnt) {
|
||||
List<MaterialUpdateBillEntity> ents = new ArrayList<>();
|
||||
excelContext = excelContext.stream().filter(u -> StrUtil.isNotBlank(u.getMaterialNo())).collect(Collectors.toList());
|
||||
if (excelContext.size() <= 0) {
|
||||
return ResultVO.error("导入内容不允许为空");
|
||||
}
|
||||
|
||||
List<String> upMaterialNos = excelContext.stream().map(TwentyMaterialTemplateExcelDTO::getMaterialNo).collect(Collectors.toList());
|
||||
checkMaterialRep(upMaterialNos);
|
||||
|
||||
Set<String> exitstUpNos = Sets.newHashSet(this.getBaseMapper().getExtstUpdataBillMaterialNos(upMaterialNos));
|
||||
Set<String> upMaterialNosSet = Sets.newHashSet(upMaterialNos);
|
||||
Set<String> intersection = Sets.intersection(exitstUpNos, upMaterialNosSet);
|
||||
if (intersection.size() > 0) {
|
||||
throw new NflgBusinessException(STATE.ParamErr, StrUtil.join(",", intersection).concat("已有存在申请中的变更单"));
|
||||
}
|
||||
//正式物料
|
||||
HashSet<String> formalMNos = Sets.newHashSet(this.getBaseMapper().getExtstFormalMaterialNos(upMaterialNos));
|
||||
Set<String> formDifferenceSet = Sets.difference(upMaterialNosSet, formalMNos);
|
||||
if (formDifferenceSet.size() > 0) {
|
||||
throw new NflgBusinessException(STATE.ParamErr, StrUtil.join(",", formDifferenceSet).concat("为非正式物料,不允许变更"));
|
||||
}
|
||||
|
||||
// 判断新图号是否在数据库中已存在
|
||||
List<String> drawingNoList = excelContext.stream().map(TwentyMaterialTemplateExcelDTO::getDrawingNo).collect(Collectors.toList());
|
||||
List<MaterialMainEntity> entityList = this.materialMainService.lambdaQuery().in(MaterialMainEntity::getDrawingNo, drawingNoList).list();
|
||||
if (entityList != null && entityList.size() > 0) {
|
||||
List<String> drawingNos = entityList.stream().map(MaterialMainEntity::getDrawingNo).collect(Collectors.toList());
|
||||
List<MaterialMainEntity> others = entityList.stream().filter(item -> !upMaterialNos.contains(item.getMaterialNo())).collect(Collectors.toList());
|
||||
if (others.size() > 0) {
|
||||
throw new NflgBusinessException(STATE.ParamErr, StrUtil.join(",", drawingNos).concat("的图号在正式物料中已存在"));
|
||||
}
|
||||
}
|
||||
// 申请中的变更
|
||||
List<MaterialUpdateBillEntity> billEntityList = this.lambdaQuery().eq(MaterialUpdateBillEntity::getBillState, 1).in(MaterialUpdateBillEntity::getDrawingNo, drawingNoList).list();
|
||||
if (billEntityList != null && billEntityList.size() > 0) {
|
||||
List<String> drawingNos = billEntityList.stream().map(MaterialUpdateBillEntity::getDrawingNo).collect(Collectors.toList());
|
||||
throw new NflgBusinessException(STATE.ParamErr, StrUtil.join(",", drawingNos).concat("的新图号在变更申请中已存在,请检查"));
|
||||
}
|
||||
|
||||
Set<String> states = Sets.newHashSet("激活", "禁止采购", "售后专用", "冻结", "完全弃用");
|
||||
Set<String> excelStates = excelContext.stream().filter(item -> StringUtils.isNotEmpty(item.getNewState()))
|
||||
.map(u -> EecExcelUtil.StringTrim(u.getNewState())).filter(StringUtils::isNotEmpty).collect(Collectors.toSet());
|
||||
Set<String> difState = Sets.difference(excelStates, states);
|
||||
if (difState.size() > 0) {
|
||||
throw new NflgBusinessException(STATE.ParamErr, StrUtil.join(",", difState).concat("状态错误,状态不能含有空格,状态只能选择激活/禁止采购/售后专用/冻结/完全弃用"));
|
||||
}
|
||||
|
||||
List<TwentyMaterialTemplateExcelDTO> updateResionList = excelContext.stream().filter(item -> StringUtils.isEmpty(item.getUpdateResion())).collect(Collectors.toList());
|
||||
List<String> updateResionMaterialNoList = updateResionList.stream().map(TwentyMaterialTemplateExcelDTO::getMaterialNo).collect(Collectors.toList());
|
||||
if (updateResionMaterialNoList.size() > 0) {
|
||||
throw new NflgBusinessException(STATE.ParamErr, StrUtil.join(",", updateResionMaterialNoList).concat("为未填写变更原因"));
|
||||
}
|
||||
|
||||
for (TwentyMaterialTemplateExcelDTO data : excelContext) {
|
||||
MaterialMainEntity material = materialMainService.lambdaQuery().eq(MaterialMainEntity::getMaterialNo, data.getMaterialNo()).one();
|
||||
if (material.getProcessState().compareTo(MaterialProcessStateEnum.AUDIT.getValue()) != 0 && material.getProcessState().compareTo(MaterialProcessStateEnum.HISTORY_MATERIAL.getValue()) != 0) {
|
||||
MaterialProcessStateEnum materialProcessStateEnum = MaterialProcessStateEnum.findDescriptionByValue(material.getProcessState());
|
||||
throw new NflgBusinessException(STATE.Error, "物料号为" + data.getMaterialNo() + "的物料流程状态为" + materialProcessStateEnum.getDescription() + ",不允许导入变更");
|
||||
}
|
||||
|
||||
String checkMaterialState = checkMaterialState(material);
|
||||
if (ObjectUtil.isNotEmpty(checkMaterialState)) {
|
||||
return ResultVO.error(checkMaterialState);
|
||||
}
|
||||
|
||||
MaterialMainVO materialMainVO = new MaterialMainVO();
|
||||
BeanUtils.copyProperties(material, materialMainVO);
|
||||
MaterialUpdateBillEntity ent = new MaterialUpdateBillEntity();
|
||||
ent.setMaterialNo(data.getMaterialNo());
|
||||
if (StringUtils.isNotEmpty(data.getNewState())) {
|
||||
ent.setNewMaterialState(MaterialStateConstant.materialStateNameKeyMp.get(EecExcelUtil.StringTrim(data.getNewState())));
|
||||
ent.setNewMaterialStateName(data.getNewState());
|
||||
}
|
||||
|
||||
MaterialCategoryEntity materialCategoryEntity = materialCategoryService.lambdaQuery().eq(MaterialCategoryEntity::getCategoryCode, 20L).one();
|
||||
MaterialCategoryEntity secCategoryEntity, threeCategoryEntity;
|
||||
if (StringUtils.isNotEmpty(data.getSecondMaterialCategoryName()) && StringUtils.isNotEmpty(data.getThirdMaterialCategoryName())) {
|
||||
secCategoryEntity = materialCategoryService.getBaseMapper().selectByParentCategoryRowIdAndCategoryName(materialCategoryEntity.getRowId(), data.getSecondMaterialCategoryName().trim());
|
||||
if (secCategoryEntity == null) {
|
||||
throw new NflgBusinessException(STATE.Error, "新中类不存在,请确认是否是制作物料的中类");
|
||||
}
|
||||
threeCategoryEntity = materialCategoryService.getBaseMapper().selectByParentCategoryRowIdAndCategoryName(secCategoryEntity.getRowId(), data.getThirdMaterialCategoryName().trim());
|
||||
if (threeCategoryEntity == null) {
|
||||
throw new NflgBusinessException(STATE.Error, "新小类不存在,请确认是否是制作物料的小类");
|
||||
}
|
||||
ent.setNewCategoryCode(threeCategoryEntity.getCategoryCode());
|
||||
MaterialMainVO vo = new MaterialMainVO();
|
||||
vo.setSecondMaterialCategoryName(secCategoryEntity.getCategoryName());
|
||||
vo.setThirdMaterialCategoryName(threeCategoryEntity.getCategoryName());
|
||||
ent.setNewCategoryNameTree(getMaterialCategoryTree(vo));
|
||||
} else {
|
||||
threeCategoryEntity = materialCategoryService.lambdaQuery().eq(MaterialCategoryEntity::getCategoryCode, material.getMaterialCategoryCode()).one();
|
||||
}
|
||||
// (relCategoryCode=21)的物料,图号或者名称有变更时,导入后系统需自动重新拼接生成新物料描述。
|
||||
// (relCategoryCode=22)的物料,当前新增物料描述或申请变更时,他们的物料描述=物料名称
|
||||
if (threeCategoryEntity.getRelCategoryCode().equals("21")) {
|
||||
if (StringUtils.isNotEmpty(data.getDrawingNo()) && StringUtils.isNotEmpty(data.getMaterialName())) {
|
||||
ent.setNewMateiralDesc(data.getDrawingNo() + " " + data.getMaterialName());
|
||||
}
|
||||
if (StringUtils.isEmpty(data.getDrawingNo()) && StringUtils.isNotEmpty(data.getMaterialName())) {
|
||||
ent.setNewMateiralDesc(material.getDrawingNo() + " " + data.getMaterialName());
|
||||
}
|
||||
if (StringUtils.isNotEmpty(data.getDrawingNo()) && StringUtils.isEmpty(data.getMaterialName())) {
|
||||
ent.setNewMateiralDesc(data.getDrawingNo() + " " + material.getMaterialName());
|
||||
}
|
||||
}
|
||||
// 如果制作物料-发货直发制作包、非图纸物料,则强制赋值:物料名称=图号=物料描述
|
||||
if (threeCategoryEntity.getRelCategoryCode().equals("22")) {
|
||||
if (StringUtils.isNotEmpty(data.getMaterialName())) {
|
||||
ent.setNewMateiralDesc(data.getMaterialName());
|
||||
ent.setNewDrawingNo(data.getMaterialName());
|
||||
}
|
||||
}
|
||||
|
||||
ent.setOldMaterialState(material.getMaterialState());
|
||||
ent.setOldMaterialStateName(MaterialStateConstant.materialStateMp.get(material.getMaterialState()));
|
||||
ent.setOldCategoryCode(material.getMaterialCategoryCode());
|
||||
ent.setOldCategoryNameTree(getMaterialCategoryTree(materialMainVO));
|
||||
ent.setOldMaterialDesc(material.getMaterialDesc());
|
||||
ent.setOldShortMaterialDesc(material.getShortMaterialDesc());
|
||||
ent.setOldDrawingNo(material.getDrawingNo());
|
||||
|
||||
// 20230809--新增物料名称数据
|
||||
ent.setMaterialName(data.getMaterialName());
|
||||
ent.setNewDrawingNo(data.getDrawingNo());
|
||||
ent.setUpdateResion(data.getUpdateResion());
|
||||
ent.setReplaceMaterialNo(data.getReplaceMaterialNo());
|
||||
ent.setApplyDeptName(applyDeptName);
|
||||
ent.setCreatedByName(SessionUtil.getRealName());
|
||||
ent.setCreatedBy(SessionUtil.getUserCode());
|
||||
ent.setCreatedTime(new Date());
|
||||
ents.add(ent);
|
||||
|
||||
// 允许简化描述变更前后相同,但不可与系统内其他物料的描述或简化描述相同
|
||||
ResultVO<String> checkMaterialDesc = checkMaterialDesc(ent);
|
||||
if (Objects.nonNull(checkMaterialDesc)) {
|
||||
log.info("【checkMaterialDesc校验结果】:" + checkMaterialDesc.getMsg());
|
||||
return ResultVO.error(checkMaterialDesc.getMsg());
|
||||
}
|
||||
}
|
||||
this.validateFreezeStateChangeOther(ents, deptEnt.getDptCode());
|
||||
this.saveBatch(ents);
|
||||
//同步OA
|
||||
materialUpdateToOAService.sysnToOa(ents);
|
||||
}
|
||||
|
||||
// 申请部门是 营销中心,11,21变更,由冻结改成其他状态,不允许改成激活
|
||||
private void validateFreezeStateChangeOther(List<MaterialUpdateBillEntity> updateList, String applyDeptCode) {
|
||||
if (CollectionUtil.isEmpty(updateList)) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue