1、CAD转EBOM新逻辑调整

This commit is contained in:
大米 2024-06-14 14:40:58 +08:00
parent dfa6939f43
commit 0dd9dd5943
4 changed files with 105 additions and 81 deletions

View File

@ -63,11 +63,9 @@ public class EbomV2Api extends BaseApi {
ebomParentService.getBaseMapper().updateRootForWaitReview(); ebomParentService.getBaseMapper().updateRootForWaitReview();
ebomParentService.resetAllBomExist(); ebomParentService.resetAllBomExist();
} } catch (Exception e) {
catch (Exception e){
VUtils.isTure(true).throwMessage("转换失败:" + e.getMessage()); VUtils.isTure(true).throwMessage("转换失败:" + e.getMessage());
} } finally {
finally {
List<Integer> delRowIds = parents.stream().map(BomOriginalCadParentEntity::getRowId).collect(Collectors.toList()); List<Integer> delRowIds = parents.stream().map(BomOriginalCadParentEntity::getRowId).collect(Collectors.toList());
if (CollUtil.isNotEmpty(delRowIds)) { if (CollUtil.isNotEmpty(delRowIds)) {
originalParentV2Service.delCadData(delRowIds); originalParentV2Service.delCadData(delRowIds);

View File

@ -9,11 +9,13 @@ import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.toolkit.IdWorker; import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.google.common.collect.Sets; import com.google.common.collect.Sets;
import com.nflg.product.bomnew.constant.EBomStatusEnum;
import com.nflg.product.bomnew.constant.OriginalEditStatusEnum; import com.nflg.product.bomnew.constant.OriginalEditStatusEnum;
import com.nflg.product.bomnew.constant.OriginalStatusEnum; import com.nflg.product.bomnew.constant.OriginalStatusEnum;
import com.nflg.product.bomnew.mapper.master.BomNewOriginalParentMapper; import com.nflg.product.bomnew.mapper.master.BomNewOriginalParentMapper;
import com.nflg.product.bomnew.pojo.dto.BaseImportExcelDTO; import com.nflg.product.bomnew.pojo.dto.BaseImportExcelDTO;
import com.nflg.product.bomnew.pojo.dto.BomNewOriginalExcelDTO; import com.nflg.product.bomnew.pojo.dto.BomNewOriginalExcelDTO;
import com.nflg.product.bomnew.pojo.entity.BomNewEbomParentEntity;
import com.nflg.product.bomnew.pojo.entity.BomNewOriginalParentEntity; import com.nflg.product.bomnew.pojo.entity.BomNewOriginalParentEntity;
import com.nflg.product.bomnew.pojo.entity.BomOriginalCadChildEntity; import com.nflg.product.bomnew.pojo.entity.BomOriginalCadChildEntity;
import com.nflg.product.bomnew.pojo.entity.BomOriginalCadParentEntity; import com.nflg.product.bomnew.pojo.entity.BomOriginalCadParentEntity;
@ -108,10 +110,9 @@ public class BomNewOriginalParentV2Service extends ServiceImpl<BomNewOriginalPar
* @param * @param
* @return * @return
*/ */
@Transactional(rollbackFor = Exception.class)
public List<ImportOriginalBomVO> pullFromCadAndToEBom(List<BomOriginalCadParentEntity> parents) throws ExecutionException, InterruptedException { public List<ImportOriginalBomVO> pullFromCadAndToEBom(List<BomOriginalCadParentEntity> parents) throws ExecutionException, InterruptedException {
List<ImportOriginalBomVO> toEBomResult = new ArrayList();
VUtils.isTure(CollUtil.isEmpty(parents)).throwMessage("没有你的数据,你无需转换"); VUtils.isTure(CollUtil.isEmpty(parents)).throwMessage("没有你的数据,你无需转换");
//检查物料编码在主数据中是否存在 //检查物料编码在主数据中是否存在
List<BomOriginalCadChildEntity> childs = originalCadChildService.lambdaQuery().in(BomOriginalCadChildEntity::getParentRowId, parents.stream().map(u -> u.getRowId()).collect(Collectors.toList())).list(); List<BomOriginalCadChildEntity> childs = originalCadChildService.lambdaQuery().in(BomOriginalCadChildEntity::getParentRowId, parents.stream().map(u -> u.getRowId()).collect(Collectors.toList())).list();
@ -123,7 +124,45 @@ public class BomNewOriginalParentV2Service extends ServiceImpl<BomNewOriginalPar
Set<String> noMaterialNoChartNos = parents.stream().filter(u -> StrUtil.isBlank(u.getMaterialNo())).map(u -> u.getChartNo()).collect(Collectors.toSet()); Set<String> noMaterialNoChartNos = parents.stream().filter(u -> StrUtil.isBlank(u.getMaterialNo())).map(u -> u.getChartNo()).collect(Collectors.toSet());
VUtils.isTure(CollUtil.isNotEmpty(noMaterialNoChartNos)).throwMessage(StrUtil.join(",", noMaterialNoChartNos) + "物料编码为空,请检查(父级物料编码不能为空)"); VUtils.isTure(CollUtil.isNotEmpty(noMaterialNoChartNos)).throwMessage(StrUtil.join(",", noMaterialNoChartNos) + "物料编码为空,请检查(父级物料编码不能为空)");
//判断当前用户创建的bom(工作列表)是否已创建了虚拟包,有则中断此次转换
List<String> parentMaterialNos = parents.stream().filter(u -> StrUtil.isNotBlank(u.getMaterialNo())).map(u -> u.getMaterialNo()).collect(Collectors.toList());
List<BomNewEbomParentEntity> checkList = ebomParentService.lambdaQuery().in(BomNewEbomParentEntity::getMaterialNo, parentMaterialNos).lt(BomNewEbomParentEntity::getStatus, EBomStatusEnum.PUBLISHED.getValue())
.gt(BomNewEbomParentEntity::getVirtrualPackageEnum, 0).list();
if(CollUtil.isNotEmpty(checkList)){
List<String> hasVirtualPackageMaterialNo = checkList.stream().map(u ->StrUtil.join("-",u.getMaterialNo(),u.getCurrentVersion()) ).collect(Collectors.toList());
VUtils.isTure(true).throwMessage(StrUtil.join(",", hasVirtualPackageMaterialNo)+"已生成虚拟包,请先删除再导入");
}
PlmBomToOriginalConvertV2 convert = new PlmBomToOriginalConvertV2(); PlmBomToOriginalConvertV2 convert = new PlmBomToOriginalConvertV2();
//存原始BOM
toOriginalBom(parents,convert);
//转Ebom
return toEbom(convert);
}
/**
* 转换EBOM
* @param convert
* @return
* @throws ExecutionException
* @throws InterruptedException
*/
@Transactional(rollbackFor = Exception.class)
public List<ImportOriginalBomVO> toEbom(PlmBomToOriginalConvertV2 convert) throws ExecutionException, InterruptedException {
if (CollUtil.isNotEmpty(convert.getResultParent())) {
return convertToEBomV2(convert.getResultParent().stream().map(u -> u.getRowId()).collect(Collectors.toList()));
}
return Collections.emptyList();
}
/**
* 转原始BOM
*/
@Transactional(rollbackFor = Exception.class)
public void toOriginalBom(List<BomOriginalCadParentEntity> parents,PlmBomToOriginalConvertV2 convert ){
for (BomOriginalCadParentEntity parent : parents) { for (BomOriginalCadParentEntity parent : parents) {
//转原始BOM //转原始BOM
convert.convertOriginalBom(parent); convert.convertOriginalBom(parent);
@ -135,13 +174,6 @@ public class BomNewOriginalParentV2Service extends ServiceImpl<BomNewOriginalPar
if (CollUtil.isNotEmpty(convert.getResultChild())) { if (CollUtil.isNotEmpty(convert.getResultChild())) {
originalChildService.saveOrUpdateBatch(convert.getResultChild()); originalChildService.saveOrUpdateBatch(convert.getResultChild());
} }
//转Ebom
if (CollUtil.isNotEmpty(convert.getResultParent())) {
toEBomResult = convertToEBomV2(convert.getResultParent().stream().map(u -> u.getRowId()).collect(Collectors.toList()));
}
return toEBomResult;
} }
@Transactional() @Transactional()

View File

@ -307,10 +307,10 @@ public abstract class BaseConvert {
if (oldChildList.size() != newChildList.size()) { if (oldChildList.size() != newChildList.size()) {
return false; return false;
} }
Map<String, List<BomNewEbomChildEntity> > oldChildMap = oldChildList.stream().collect(Collectors.groupingBy(u->StrUtil.join(u.getMaterialNo(),u.getProjectType()) )); Map<String, List<BomNewEbomChildEntity> > oldChildMap = oldChildList.stream().collect(Collectors.groupingBy(u->StrUtil.join("",u.getMaterialNo(),u.getProjectType(),u.getNum()) ));
for (BomNewEbomChildEntity newChild : newChildList) { for (BomNewEbomChildEntity newChild : newChildList) {
String key=StrUtil.join(newChild.getMaterialNo(),newChild.getProjectType()); String key=StrUtil.join("",newChild.getMaterialNo(),newChild.getProjectType(),newChild.getNum());
if(!oldChildMap.containsKey(key) || Objects.equals(newChild.getNum(), oldChildMap.get(key).get(0).getNum()) ){ if(!oldChildMap.containsKey(key)){
return false; return false;
} }
} }

View File

@ -99,6 +99,7 @@ public class OriginalBomToEBomV2Convert extends BaseConvert {
/** /**
* 合并一般零部件 * 合并一般零部件
*
* @param list * @param list
* @return * @return
*/ */
@ -148,68 +149,60 @@ public class OriginalBomToEBomV2Convert extends BaseConvert {
//子节点 //子节点
List<BomOriginalListVO> parentChild = bomDetail.stream().filter(u -> Objects.nonNull(u.getParentRowId()) && u.getParentRowId().equals(parentEnt.getBomRowId())).distinct().collect(Collectors.toList()); List<BomOriginalListVO> parentChild = bomDetail.stream().filter(u -> Objects.nonNull(u.getParentRowId()) && u.getParentRowId().equals(parentEnt.getBomRowId())).distinct().collect(Collectors.toList());
BomNewEbomParentEntity oldEBom = ebomParentService.lambdaQuery().eq(BomNewEbomParentEntity::getMaterialNo, parentEnt.getMaterialNo()).last(" order by current_version desc limit 1").one(); BomNewEbomParentEntity oldEBom = ebomParentService.lambdaQuery().eq(BomNewEbomParentEntity::getMaterialNo, parentEnt.getMaterialNo()).last(" order by current_version desc limit 1").one();
List<BomNewEbomChildEntity> oldParenChild = ebomChildService.getBaseMapper().getChildByMaterialNo(parentEnt.getMaterialNo());
//无Ebom时 //无Ebom时
if (Objects.isNull(oldEBom)) { if (Objects.isNull(oldEBom)) {
Long parentRowId = buildEBomParent(parentEnt); Long parentRowId = buildEBomParent(parentEnt, "V00");
parentEnt.setEBomRowId(parentRowId); parentEnt.setEBomRowId(parentRowId);
handlerChild(parentEnt, parentChild); handlerChild(parentEnt, parentChild);
return; return;
} }
// List<BomNewEbomChildEntity> oldParenChild = ebomChildService.lambdaQuery().eq(BomNewEbomChildEntity::getParentRowId,oldEBom.getRowId()).list();
//草稿态 //草稿态
if (!EBomStatusEnum.PUBLISHED.equalsValue(oldEBom.getStatus())) { if (!EBomStatusEnum.PUBLISHED.equalsValue(oldEBom.getStatus())) {
//不是同一个人跳过并返回告知用户
if (!parent.getCreatedBy().equals(oldEBom.getCreatedBy())) {
VUtils.isTure(true).throwMessage(parent.getMaterialNo() + ":已存在" + oldEBom.getCreatedBy() + "创建的BOM版本改BOM已跳过");
return;
}
if (CollUtil.isNotEmpty(parentChild)) { if (CollUtil.isNotEmpty(parentChild)) {
//结构不一致且用户是一人则覆盖 // 当前处理人为同一人则直接覆盖
if (!isSameEBomV2(Convert.toList(BomNewEbomChildEntity.class, parentChild), oldParenChild)) {
if (parent.getCreatedBy().equals(oldEBom.getCreatedBy())) { if (parent.getCreatedBy().equals(oldEBom.getCreatedBy())) {
ebomParentService.getBaseMapper().deleteById(oldEBom.getRowId()); ebomParentService.getBaseMapper().deleteById(oldEBom.getRowId());
ebomChildService.getBaseMapper().deleteByMap(ImmutableMap.of("parent_row_id", oldEBom.getRowId())); ebomChildService.getBaseMapper().deleteByMap(ImmutableMap.of("parent_row_id", oldEBom.getRowId()));
Long parentRowId = buildEBomParent(parentEnt); Long parentRowId = buildEBomParent(parentEnt, oldEBom.getCurrentVersion());
parentEnt.setEBomRowId(parentRowId); parentEnt.setEBomRowId(parentRowId);
handlerChild(parentEnt, parentChild); handlerChild(parentEnt, parentChild);
} }
}
} else { } else {
if (parentEnt.getMaterialCategoryCode().equals(OriginalConstant.COMMON_MATERIAL_CATEGORY_CODE)) { if (parentEnt.getMaterialCategoryCode().equals(OriginalConstant.COMMON_MATERIAL_CATEGORY_CODE)) {
//通过名称找子级 //通过名称找子级
BaseMaterialVO materialBaseInfo = getCommonMaterialByRel(parentEnt); BaseMaterialVO materialBaseInfo = getCommonMaterialByRel(parentEnt);
if (Objects.nonNull(materialBaseInfo)) { if (Objects.nonNull(materialBaseInfo)) {
List<BomNewEbomChildEntity> oldChild = ebomChildService.getBaseMapper().getChildByMaterialNo(parentEnt.getMaterialNo()); // List<BomNewEbomChildEntity> oldChild = ebomChildService.getBaseMapper().getChildByMaterialNo(parentEnt.getMaterialNo());
BomNewEbomChildEntity newChild = buildCommonEbomChildEntity(materialBaseInfo, parentEnt); BomNewEbomChildEntity newChild = buildCommonEbomChildEntity(materialBaseInfo, parentEnt);
//存在旧版本
if (CollUtil.isNotEmpty(oldChild)) {
//结构是否相同 且为同一处理人 //结构是否相同 且为同一处理人
if (!isSameEBom(oldChild, ImmutableList.of(newChild)) && parent.getCreatedBy().equals(oldEBom.getCreatedBy())) { if (parent.getCreatedBy().equals(oldEBom.getCreatedBy())) {
ebomParentService.getBaseMapper().deleteById(oldEBom.getRowId()); ebomParentService.getBaseMapper().deleteById(oldEBom.getRowId());
ebomChildService.getBaseMapper().deleteByMap(ImmutableMap.of("parent_row_id", oldEBom.getRowId())); ebomChildService.getBaseMapper().deleteByMap(ImmutableMap.of("parent_row_id", oldEBom.getRowId()));
Long parentRowId = buildEBomParent(parentEnt); Long parentRowId = buildEBomParent(parentEnt, oldEBom.getCurrentVersion());
newChild.setParentRowId(parentRowId); newChild.setParentRowId(parentRowId);
this.eBomChildResult.add(newChild); this.eBomChildResult.add(newChild);
} }
} }
//
}
//
}
} else { //正式版生成临时小版本
} else { String smallBomVersion = VersionUtil.getNextVersionForSmallVersion(oldEBom.getCurrentVersion());
buildEBomParent(parentEnt); Long parentRowId = buildEBomParent(parentEnt, smallBomVersion);
}
} else {
buildEBomParent(parentEnt);
}
}
} else { //正式版
//bom不
if (!isSameEBomV2(Convert.toList(BomNewEbomChildEntity.class, parentChild), oldParenChild)) {
Long parentRowId = buildEBomParent(parentEnt);
parentEnt.setEBomRowId(parentRowId); parentEnt.setEBomRowId(parentRowId);
handlerChild(parentEnt, parentChild); handlerChild(parentEnt, parentChild);
} }
}
} }
@ -253,7 +246,7 @@ public class OriginalBomToEBomV2Convert extends BaseConvert {
List<BomNewEbomChildEntity> oldParenChild = SpringUtil.getBean(BomNewEbomChildMapper.class).getChildByMaterialNo(parentEntity.getMaterialNo()); List<BomNewEbomChildEntity> oldParenChild = SpringUtil.getBean(BomNewEbomChildMapper.class).getChildByMaterialNo(parentEntity.getMaterialNo());
//不存在EBom //不存在EBom
if (Objects.isNull(oldEBom)) { if (Objects.isNull(oldEBom)) {
buildCommonMaterialChildBom(childVo, materialBaseInfo); buildCommonMaterialChildBom(childVo, materialBaseInfo, "V00");
} else { } else {
if (!EBomStatusEnum.PUBLISHED.equalsValue(oldEBom.getStatus())) { if (!EBomStatusEnum.PUBLISHED.equalsValue(oldEBom.getStatus())) {
@ -263,13 +256,13 @@ public class OriginalBomToEBomV2Convert extends BaseConvert {
ebomParentService.getBaseMapper().deleteById(oldEBom.getRowId()); ebomParentService.getBaseMapper().deleteById(oldEBom.getRowId());
ebomChildService.getBaseMapper().deleteByMap(ImmutableMap.of("parent_row_id", oldEBom.getRowId())); ebomChildService.getBaseMapper().deleteByMap(ImmutableMap.of("parent_row_id", oldEBom.getRowId()));
Long parentRowId = buildEBomParent(childVo); Long parentRowId = buildEBomParent(childVo, oldEBom.getCurrentVersion());
newChild.setParentRowId(parentRowId); newChild.setParentRowId(parentRowId);
this.eBomChildResult.add(newChild); this.eBomChildResult.add(newChild);
} }
} } else { //正式则直接升级
else { //正式则直接升级 String smallBomVersion = VersionUtil.getNextVersionForSmallVersion(oldEBom.getCurrentVersion());
buildCommonMaterialChildBom(childVo, materialBaseInfo); buildCommonMaterialChildBom(childVo, materialBaseInfo, smallBomVersion);
} }
} }
} }
@ -281,11 +274,12 @@ public class OriginalBomToEBomV2Convert extends BaseConvert {
/** /**
* 创建一般零部件BOM * 创建一般零部件BOM
*
* @param childVo * @param childVo
* @param materialBaseInfo * @param materialBaseInfo
*/ */
private void buildCommonMaterialChildBom(BomOriginalListVO childVo,BaseMaterialVO materialBaseInfo){ private void buildCommonMaterialChildBom(BomOriginalListVO childVo, BaseMaterialVO materialBaseInfo, String bomVersion) {
Long parentRowId = buildEBomParent(childVo); Long parentRowId = buildEBomParent(childVo, bomVersion);
childVo.setEBomRowId(parentRowId); childVo.setEBomRowId(parentRowId);
BomNewEbomChildEntity childEntity = buildCommonEbomChildEntity(materialBaseInfo, childVo); BomNewEbomChildEntity childEntity = buildCommonEbomChildEntity(materialBaseInfo, childVo);
this.eBomChildResult.add(childEntity); this.eBomChildResult.add(childEntity);
@ -362,7 +356,7 @@ public class OriginalBomToEBomV2Convert extends BaseConvert {
/** /**
* 构建EBom父级 * 构建EBom父级
*/ */
private Long buildEBomParent(BomOriginalListVO parentEnt) { private Long buildEBomParent(BomOriginalListVO parentEnt, String bomVersion) {
Map<String, BomNewEbomParentEntity> parentMap = ListCommonUtil.listToMap(this.getEBomParentResult(), BomNewEbomParentEntity::getMaterialNo); Map<String, BomNewEbomParentEntity> parentMap = ListCommonUtil.listToMap(this.getEBomParentResult(), BomNewEbomParentEntity::getMaterialNo);
if (parentMap.containsKey(parentEnt.getMaterialNo())) { if (parentMap.containsKey(parentEnt.getMaterialNo())) {
return parentMap.get(parentEnt.getMaterialNo()).getRowId(); return parentMap.get(parentEnt.getMaterialNo()).getRowId();
@ -372,7 +366,7 @@ public class OriginalBomToEBomV2Convert extends BaseConvert {
BeanUtil.copyProperties(parentEnt, eBomParent, "materialGetType"); BeanUtil.copyProperties(parentEnt, eBomParent, "materialGetType");
eBomParent.setRowId(parentEnt.getEBomRowId() > 0 ? parentEnt.getEBomRowId() : IdWorker.getId()); eBomParent.setRowId(parentEnt.getEBomRowId() > 0 ? parentEnt.getEBomRowId() : IdWorker.getId());
eBomParent.setSource(EBomSourceEnum.FROM_BOM.getValue()); eBomParent.setSource(EBomSourceEnum.FROM_BOM.getValue());
eBomParent.setCurrentVersion(VersionUtil.getNextVersion(Objects.isNull(ebom) ? "" : ebom.getCurrentVersion())); eBomParent.setCurrentVersion(bomVersion);
eBomParent.setConvertToEbomTime(LocalDateTime.now()); eBomParent.setConvertToEbomTime(LocalDateTime.now());
eBomParent.setSourceRowId(StrUtil.isNotBlank(parentEnt.getSourceRowId()) ? parentEnt.getSourceRowId() : parentEnt.getRowId().toString()); eBomParent.setSourceRowId(StrUtil.isNotBlank(parentEnt.getSourceRowId()) ? parentEnt.getSourceRowId() : parentEnt.getRowId().toString());
eBomParent.setLastVersionIs(1); eBomParent.setLastVersionIs(1);