Merge branch 'feature/DM/nflg-bom-transition'

This commit is contained in:
jing's 2024-09-10 16:45:30 +08:00
commit f243456805
2 changed files with 76 additions and 77 deletions

View File

@ -2140,10 +2140,7 @@ public class BomNewEbomParentService extends ServiceImpl<BomNewEbomParentMapper,
// return dto.getParent(); // return dto.getParent();
// } // }
//检查是否在主数据里
if (CollUtil.isNotEmpty(dto.getDatas())) {
CheckEBomException.checkMaterialNoInMain(dto.getDatas());
}
EBomEdit eBomEdit = new EBomEdit(EBomSourceEnum.FROM_MDM.getValue()); EBomEdit eBomEdit = new EBomEdit(EBomSourceEnum.FROM_MDM.getValue());
dto.setOpType(EbomEditStatusEnum.HANDLER_CREATED.getValue()); dto.setOpType(EbomEditStatusEnum.HANDLER_CREATED.getValue());
@ -2163,12 +2160,14 @@ public class BomNewEbomParentService extends ServiceImpl<BomNewEbomParentMapper,
//ebomChildService.getBaseMapper().updateEBomMaterialUse(); //ebomChildService.getBaseMapper().updateEBomMaterialUse();
} }
superMaterialStatus(dto.getDatas()); if(CollUtil.isNotEmpty(dto.getDatas())) {
superMaterialStatus(dto.getDatas());
}
// checkAndSaveEBomException(childList);
//不要异步 //不要异步
ebomChildService.updateEBomMaterialUse(eBomEdit.childEntities.stream().map(BomNewEbomChildEntity::getMaterialNo).collect(Collectors.toSet())); ebomChildService.updateEBomMaterialUse(eBomEdit.childEntities.stream().map(BomNewEbomChildEntity::getMaterialNo).collect(Collectors.toSet()));
// ThreadUtil.execAsync(() -> computeLevelNumAndRootState());
if (eBomEdit.isRootForWaitReview()) { if (eBomEdit.isRootForWaitReview()) {
updateRootForWaitReview(); updateRootForWaitReview();
@ -2197,10 +2196,7 @@ public class BomNewEbomParentService extends ServiceImpl<BomNewEbomParentMapper,
//检查是否在主数据里
if (CollUtil.isNotEmpty(dto.getDatas())) {
CheckEBomException.checkMaterialNoInMain(dto.getDatas());
}
//构建操作数据 //构建操作数据
EBomEdit eBomEdit = new EBomEdit(EBomSourceEnum.FROM_MDM.getValue()); EBomEdit eBomEdit = new EBomEdit(EBomSourceEnum.FROM_MDM.getValue());
dto.setOpType(EbomEditStatusEnum.HANDLER_FINISHED.getValue()); dto.setOpType(EbomEditStatusEnum.HANDLER_FINISHED.getValue());
@ -2242,7 +2238,9 @@ public class BomNewEbomParentService extends ServiceImpl<BomNewEbomParentMapper,
ebomChildService.saveOrUpdateBatch(eBomEdit.childEntities); ebomChildService.saveOrUpdateBatch(eBomEdit.childEntities);
} }
superMaterialStatus(dto.getDatas()); if (CollectionUtil.isNotEmpty(dto.getDatas())) {
superMaterialStatus(dto.getDatas());
}
// checkAndSaveEBomException(dto.getParent().getBomRowId()); // checkAndSaveEBomException(dto.getParent().getBomRowId());
if (eBomEdit.isRootForWaitReview()) { if (eBomEdit.isRootForWaitReview()) {

View File

@ -37,9 +37,9 @@ public class EBomEdit {
@Getter @Getter
private BomNewEbomParentEntity parentEntity; private BomNewEbomParentEntity parentEntity;
@Getter @Getter
private boolean isRootForWaitReview=false; private boolean isRootForWaitReview = false;
@Getter @Getter
private boolean isNewBom=false; private boolean isNewBom = false;
public List<BomNewEbomChildEntity> childEntities; public List<BomNewEbomChildEntity> childEntities;
@ -84,22 +84,22 @@ public class EBomEdit {
parent.setEditStatus(EbomEditStatusEnum.HANDLER_CREATED.getValue()); parent.setEditStatus(EbomEditStatusEnum.HANDLER_CREATED.getValue());
parent.setExceptionStatus(EBomExceptionStatusEnum.OK.getValue()); parent.setExceptionStatus(EBomExceptionStatusEnum.OK.getValue());
boolean isTechnician= SpringUtil.getBean(UserRoleService.class).technician(); boolean isTechnician = SpringUtil.getBean(UserRoleService.class).technician();
parent.setStatus(isTechnician? EBomStatusEnum.CHECKED.getValue() : EBomStatusEnum.WAIT_CHECK.getValue()); parent.setStatus(isTechnician ? EBomStatusEnum.CHECKED.getValue() : EBomStatusEnum.WAIT_CHECK.getValue());
parent.setCreatedJob(isTechnician? UserJobEnum.ENGINEER.getValue() : UserJobEnum.DESIGNER.getValue()); parent.setCreatedJob(isTechnician ? UserJobEnum.ENGINEER.getValue() : UserJobEnum.DESIGNER.getValue());
//工艺人不用更新 //工艺人不用更新
if(isTechnician){ if (isTechnician) {
isRootForWaitReview=false; isRootForWaitReview = false;
}else{ } else {
isRootForWaitReview=true; isRootForWaitReview = true;
} }
isNewBom=true; isNewBom = true;
parent.setCreatedTime(LocalDateTime.now()); parent.setCreatedTime(LocalDateTime.now());
parent.setModifyTime(LocalDateTime.now()); parent.setModifyTime(LocalDateTime.now());
parent.setExpireEndTime( LocalDateTime.parse("9999-12-31 23:59:59", DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss") )); parent.setExpireEndTime(LocalDateTime.parse("9999-12-31 23:59:59", DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
parent.setRootIs(0); parent.setRootIs(0);
parent.setUserRootIs(0); parent.setUserRootIs(0);
parent.setMaterialOriginalUnit(parent.getMaterialUnit()); parent.setMaterialOriginalUnit(parent.getMaterialUnit());
@ -113,24 +113,22 @@ public class EBomEdit {
/** /**
* 如果有定版后才能新建bom * 如果有定版后才能新建bom
*
* @param materialNo * @param materialNo
*/ */
void checkHadBom(String materialNo){ void checkHadBom(String materialNo) {
QueryWrapper<BomNewEbomParentEntity> queryWrapper = new QueryWrapper<>(); QueryWrapper<BomNewEbomParentEntity> queryWrapper = new QueryWrapper<>();
queryWrapper.lambda().eq(BomNewEbomParentEntity::getMaterialNo, materialNo) queryWrapper.lambda().eq(BomNewEbomParentEntity::getMaterialNo, materialNo)
.ne(BomNewEbomParentEntity::getStatus, EBomStatusEnum.PUBLISHED.getValue()); .ne(BomNewEbomParentEntity::getStatus, EBomStatusEnum.PUBLISHED.getValue());
List<BomNewEbomParentEntity> existBomlist = SpringUtil.getBean(BomNewEbomParentService.class).list(queryWrapper); List<BomNewEbomParentEntity> existBomlist = SpringUtil.getBean(BomNewEbomParentService.class).list(queryWrapper);
VUtils.isTure(CollUtil.isNotEmpty(existBomlist)).throwMessage(materialNo+"该物料已存在BOM"); VUtils.isTure(CollUtil.isNotEmpty(existBomlist)).throwMessage(materialNo + "该物料已存在BOM");
} }
void createRootBom(BomNewEBomParentEditDTO createDTO) { void createRootBom(BomNewEBomParentEditDTO createDTO) {
checkHadBom(createDTO.getParent().getMaterialNo()); checkHadBom(createDTO.getParent().getMaterialNo());
parentEntity = createParentBomInfo(createDTO.getParent()); parentEntity = createParentBomInfo(createDTO.getParent());
parentEntity.setEditStatus(createDTO.getOpType()); parentEntity.setEditStatus(createDTO.getOpType());
@ -155,7 +153,7 @@ public class EBomEdit {
} }
public static void checkVirtualPackage(BomNewEbomChildEntity child){ public static void checkVirtualPackage(BomNewEbomChildEntity child) {
if (StrUtil.equals(child.getProjectType(), BomConstant.PROJECT_TYPE_TEMPORARY)) { if (StrUtil.equals(child.getProjectType(), BomConstant.PROJECT_TYPE_TEMPORARY)) {
child.setVirtualPartType(VirtualPackageTypeEnum.UN_VIRTUAL_PACKAGE.getValue()); child.setVirtualPartType(VirtualPackageTypeEnum.UN_VIRTUAL_PACKAGE.getValue());
} else { } else {
@ -190,7 +188,7 @@ public class EBomEdit {
// child.setVirtualPartIs(1); // child.setVirtualPartIs(1);
// } // }
EBomEdit.checkVirtualPackage(child); EBomEdit.checkVirtualPackage(child);
//新增数据 //新增数据
if (child.getRowId() == null || child.getRowId() == 0) { if (child.getRowId() == null || child.getRowId() == 0) {
@ -200,7 +198,7 @@ public class EBomEdit {
child.setCreatedBy(SessionUtil.getUserCode()); child.setCreatedBy(SessionUtil.getUserCode());
child.setSourceRowId(""); child.setSourceRowId("");
child.setParentRowId(parentEntity.getRowId()); child.setParentRowId(parentEntity.getRowId());
if(StrUtil.isEmpty(child.getOrderNumber())){ if (StrUtil.isEmpty(child.getOrderNumber())) {
child.setOrderNumber("001"); child.setOrderNumber("001");
} }
if (dto.getOpType() == EbomEditStatusEnum.HANDLER_FINISHED.getValue()) { if (dto.getOpType() == EbomEditStatusEnum.HANDLER_FINISHED.getValue()) {
@ -262,20 +260,22 @@ public class EBomEdit {
throw new NflgBusinessException(STATE.Error, "parent 数据不能为空"); throw new NflgBusinessException(STATE.Error, "parent 数据不能为空");
} }
// if (CollUtil.isEmpty(dto.getDatas())) {
// throw new NflgBusinessException(STATE.Error, "datas 数据不能为空");
// }
List<String> materialNos = dto.getDatas().stream() List<String> materialNos = dto.getDatas().stream()
.filter(f -> !StrUtil.equals(f.getProjectType(), BomConstant.PROJECT_TYPE_TEMPORARY, true)) .filter(f -> !StrUtil.equals(f.getProjectType(), BomConstant.PROJECT_TYPE_TEMPORARY, true))
.map(BaseMaterialVO::getMaterialNo) .map(BaseMaterialVO::getMaterialNo)
.collect(Collectors.toList()); .collect(Collectors.toList());
if(materialNos.contains(dto.getParent().getMaterialNo())){ if (materialNos.contains(dto.getParent().getMaterialNo())) {
VUtils.isTure(true).throwMessage(StrUtil.format("上下级存在相同物料{}",dto.getParent().getMaterialNo())); VUtils.isTure(true).throwMessage(StrUtil.format("上下级存在相同物料{}", dto.getParent().getMaterialNo()));
} }
//检查物料编码是否在主数据中存在 //检查物料编码是否在主数据中存在
//暂存不需检查提交时检查 //暂存不需检查提交时检查
if(ObjectUtil.equal(EbomEditStatusEnum.HANDLER_FINISHED.getValue(),dto.getOpType())) { if (ObjectUtil.equal(EbomEditStatusEnum.HANDLER_FINISHED.getValue(), dto.getOpType())) {
List<String> checkMaterialInNull = materialNos.stream().filter(item -> StrUtil.isEmpty(item)).collect(Collectors.toList());
if (CollUtil.isNotEmpty(checkMaterialInNull)) {
VUtils.isTure(true).throwMessage("提交数据包含空物料编码");
}
materialNos.add(dto.getParent().getMaterialNo()); materialNos.add(dto.getParent().getMaterialNo());
List<BaseMaterialVO> materialBaseInfo = SpringUtil.getBean(MaterialMainService.class).getMaterialBaseInfo(materialNos); List<BaseMaterialVO> materialBaseInfo = SpringUtil.getBean(MaterialMainService.class).getMaterialBaseInfo(materialNos);
List<String> effectiveMaterialNos = materialBaseInfo.stream().map(BaseMaterialVO::getMaterialNo).collect(Collectors.toList()); List<String> effectiveMaterialNos = materialBaseInfo.stream().map(BaseMaterialVO::getMaterialNo).collect(Collectors.toList());
@ -284,43 +284,44 @@ public class EBomEdit {
} }
//检查数据是否可修改 //检查数据是否可修改
List<BomNewEbomParentVO> notNullRowIdList= dto.getDatas().stream().filter(u->u.getRowId()!=null && u.getRowId()>0).collect(Collectors.toList()); List<BomNewEbomParentVO> notNullRowIdList = dto.getDatas().stream().filter(u -> u.getRowId() != null && u.getRowId() > 0).collect(Collectors.toList());
Map<Long,BomNewEbomParentVO> mapList= ListCommonUtil.listToMap(notNullRowIdList,BomNewEbomParentVO::getRowId); Map<Long, BomNewEbomParentVO> mapList = ListCommonUtil.listToMap(notNullRowIdList, BomNewEbomParentVO::getRowId);
QueryWrapper<BomNewEbomChildEntity> queryChildWrapper=new QueryWrapper<>(); QueryWrapper<BomNewEbomChildEntity> queryChildWrapper = new QueryWrapper<>();
List<Long> rowIds=notNullRowIdList.stream().filter(u->ObjectUtil.isNotNull(u.getRowId()) && u.getRowId()>0 ).map(BomNewEbomParentVO::getRowId).collect(Collectors.toList()); List<Long> rowIds = notNullRowIdList.stream().filter(u -> ObjectUtil.isNotNull(u.getRowId()) && u.getRowId() > 0).map(BomNewEbomParentVO::getRowId).collect(Collectors.toList());
if(CollUtil.isEmpty(rowIds)){ if (CollUtil.isEmpty(rowIds)) {
return; return;
} }
queryChildWrapper.lambda().in(BomNewEbomChildEntity::getRowId,rowIds); queryChildWrapper.lambda().in(BomNewEbomChildEntity::getRowId, rowIds);
List<BomNewEbomChildEntity> childList=SpringUtil.getBean(BomNewEbomChildService.class).list(queryChildWrapper); List<BomNewEbomChildEntity> childList = SpringUtil.getBean(BomNewEbomChildService.class).list(queryChildWrapper);
// 数据不存在异常的情况下数据是不能被修改 // 数据不存在异常的情况下数据是不能被修改
List<BomNewEbomChildEntity> check1List = childList.stream().filter(u -> Objects.equals(EBomSourceEnum.FROM_BOM.getValue(), u.getSource()) List<BomNewEbomChildEntity> check1List = childList.stream().filter(u -> Objects.equals(EBomSourceEnum.FROM_BOM.getValue(), u.getSource())
&& Objects.equals(u.getExceptionStatus(), EBomExceptionStatusEnum.OK.getValue())).collect(Collectors.toList()); && Objects.equals(u.getExceptionStatus(), EBomExceptionStatusEnum.OK.getValue())).collect(Collectors.toList());
for (BomNewEbomChildEntity childEntity: if (CollUtil.isEmpty(check1List)) {
check1List ) { return;
if(mapList.get(childEntity.getRowId()) ==null){
continue;
} }
//忽略物料编码空的 for (BomNewEbomChildEntity childEntity :
if(ObjectUtil.isNull(childEntity.getMaterialNo())){ check1List) {
if (mapList.get(childEntity.getRowId()) == null) {
continue;
}
//忽略物料编码空的
if (ObjectUtil.isNull(childEntity.getMaterialNo())) {
continue; continue;
} }
//检查物料id是否被修改根据情况还可加入其他条件 //检查物料id是否被修改根据情况还可加入其他条件
if(!mapList.get(childEntity.getRowId()).getMaterialNo().equals(childEntity.getMaterialNo())){ if (!mapList.get(childEntity.getRowId()).getMaterialNo().equals(childEntity.getMaterialNo())) {
throw new NflgBusinessException(STATE.Error,StrUtil.format("从原始Bom导入的数据数据没有异常的情况下{} 不可以修改 ", childEntity.getMaterialNo())); throw new NflgBusinessException(STATE.Error, StrUtil.format("从原始Bom导入的数据数据没有异常的情况下{} 不可以修改 ", childEntity.getMaterialNo()));
} }
} }
} }
public void handleBom(BomNewEBomParentEditDTO dto) { public void handleBom(BomNewEBomParentEditDTO dto) {
checkDataRule(dto); checkDataRule(dto);
//添加根节点数据 //添加根节点数据
@ -334,17 +335,17 @@ public class EBomEdit {
//缺bom //缺bom
if (dto.getParent().getBomRowId() == null || dto.getParent().getBomRowId().longValue() == 0) { if (dto.getParent().getBomRowId() == null || dto.getParent().getBomRowId().longValue() == 0) {
checkHadBom(dto.getParent().getMaterialNo()); checkHadBom(dto.getParent().getMaterialNo());
parentEntity = createParentBomInfo(dto.getParent()); parentEntity = createParentBomInfo(dto.getParent());
// dto.getParent().setBomRowId(dto.getParent().getRowId()); // dto.getParent().setBomRowId(dto.getParent().getRowId());
dto.getDatas().forEach(k -> { dto.getDatas().forEach(k -> {
k.setParentRowId(parentEntity.getRowId()); k.setParentRowId(parentEntity.getRowId());
}); });
// parentEntity.setEditStatus(dto.getOpType()); // parentEntity.setEditStatus(dto.getOpType());
}else{ } else {
parentEntity = Convert.convert(BomNewEbomParentEntity.class, dto.getParent()); parentEntity = Convert.convert(BomNewEbomParentEntity.class, dto.getParent());
parentEntity.setModifyTime(LocalDateTime.now()); parentEntity.setModifyTime(LocalDateTime.now());
} }
@ -363,31 +364,31 @@ public class EBomEdit {
} }
public void nextVersion(){ public void nextVersion() {
if(!isNewBom){ if (!isNewBom) {
return; return;
} }
//缺bom新建的bom 版本增加 //缺bom新建的bom 版本增加
//同一物料且存在一个 lastVersionIs=1 //同一物料且存在一个 lastVersionIs=1
if(ObjectUtil.isNotNull(getParentEntity().getLastVersionIs()) if (ObjectUtil.isNotNull(getParentEntity().getLastVersionIs())
&& ObjectUtil.equal(getParentEntity().getLastVersionIs(),1)) { && ObjectUtil.equal(getParentEntity().getLastVersionIs(), 1)) {
QueryWrapper<BomNewEbomParentEntity> queryWrapper=new QueryWrapper<>(); QueryWrapper<BomNewEbomParentEntity> queryWrapper = new QueryWrapper<>();
queryWrapper.lambda() queryWrapper.lambda()
.eq(BomNewEbomParentEntity::getMaterialNo, getParentEntity().getMaterialNo()) .eq(BomNewEbomParentEntity::getMaterialNo, getParentEntity().getMaterialNo())
.eq(BomNewEbomParentEntity::getLastVersionIs,1) .eq(BomNewEbomParentEntity::getLastVersionIs, 1)
// .eq(BomNewEbomParentEntity::getStatus, EBomStatusEnum.PUBLISHED.getValue()) // .eq(BomNewEbomParentEntity::getStatus, EBomStatusEnum.PUBLISHED.getValue())
.orderByDesc(BomNewEbomParentEntity::getCurrentVersion); .orderByDesc(BomNewEbomParentEntity::getCurrentVersion);
List<BomNewEbomParentEntity> oldParent=SpringUtil.getBean(BomNewEbomParentService.class).list(queryWrapper); List<BomNewEbomParentEntity> oldParent = SpringUtil.getBean(BomNewEbomParentService.class).list(queryWrapper);
if(CollUtil.isNotEmpty(oldParent)){ if (CollUtil.isNotEmpty(oldParent)) {
// oldParent.setLastVersionIs(0); // oldParent.setLastVersionIs(0);
BomNewEbomParentEntity lastParent=oldParent.get(0); BomNewEbomParentEntity lastParent = oldParent.get(0);
for (BomNewEbomParentEntity u: for (BomNewEbomParentEntity u :
oldParent) { oldParent) {
u.setLastVersionIs(0); u.setLastVersionIs(0);
lastParent=u; lastParent = u;
} }
getParentEntity().setCurrentVersion(VersionUtil.getNextVersion(lastParent.getCurrentVersion())); getParentEntity().setCurrentVersion(VersionUtil.getNextVersion(lastParent.getCurrentVersion()));
SpringUtil.getBean(BomNewEbomParentService.class).updateBatchById(oldParent); SpringUtil.getBean(BomNewEbomParentService.class).updateBatchById(oldParent);