feat: 电气专用bom功能

This commit is contained in:
曹鹏飞 2024-04-24 09:14:25 +08:00
parent affa1426b8
commit 49708ff593
2 changed files with 41 additions and 25 deletions

View File

@ -110,7 +110,10 @@ public class DQBomImportService {
Set<String> materialNos = parents.stream().map(BomNewDQbomParentEntity::getMaterialNo).collect(Collectors.toSet()); Set<String> materialNos = parents.stream().map(BomNewDQbomParentEntity::getMaterialNo).collect(Collectors.toSet());
List<BomNewDQbomParentEntity> oldParents = dQBomParentService.getLatestByMaterialNo(materialNos); List<BomNewDQbomParentEntity> oldParents = dQBomParentService.getLatestByMaterialNo(materialNos);
parents.forEach(p -> { parents.forEach(p -> {
BomNewDQbomParentEntity oldParent = oldParents.stream().filter(op -> op.getMaterialNo().equals(p.getMaterialNo())).findFirst().orElse(null); BomNewDQbomParentEntity oldParent = oldParents.stream()
.filter(op -> op.getMaterialNo().equals(p.getMaterialNo()))
.findFirst()
.orElse(null);
if (!Objects.isNull(oldParent) && Objects.equals(oldParent.getStatus(), DQBomStatusEnum.WAIT_CONVERT.getValue())) { if (!Objects.isNull(oldParent) && Objects.equals(oldParent.getStatus(), DQBomStatusEnum.WAIT_CONVERT.getValue())) {
dQBomParentService.getBaseMapper().deleteById(oldParent.getRowId()); dQBomParentService.getBaseMapper().deleteById(oldParent.getRowId());
dQBomChildService.deleteAllChildren(oldParent.getRowId()); dQBomChildService.deleteAllChildren(oldParent.getRowId());
@ -119,7 +122,10 @@ public class DQBomImportService {
dQBomParentService.setLastVersionIs0(materialNos); dQBomParentService.setLastVersionIs0(materialNos);
dQBomParentService.saveBatch(parents); dQBomParentService.saveBatch(parents);
dQBomChildService.saveBatch(children); dQBomChildService.saveBatch(children);
BomNewDQbomParentEntity root = parents.stream().filter(p -> p.getRootIs() == 1).findFirst().orElseThrow(() -> new NflgBusinessException(STATE.BusinessError, "根节点不存在")); BomNewDQbomParentEntity root = parents.stream()
.filter(p -> p.getRootIs() == 1)
.findFirst()
.orElseThrow(() -> new NflgBusinessException(STATE.BusinessError, "根节点不存在"));
dQBomService.checkException(root.getRowId()); dQBomService.checkException(root.getRowId());
} }

View File

@ -12,7 +12,6 @@ import cn.hutool.extra.spring.SpringUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.IdWorker; import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.google.common.collect.Sets;
import com.nflg.product.base.core.conmon.util.SessionUtil; import com.nflg.product.base.core.conmon.util.SessionUtil;
import com.nflg.product.bomnew.constant.*; import com.nflg.product.bomnew.constant.*;
import com.nflg.product.bomnew.pojo.dto.sap.impart2.ImportSapParamDTO; import com.nflg.product.bomnew.pojo.dto.sap.impart2.ImportSapParamDTO;
@ -438,13 +437,17 @@ public class DQBomService {
BomNewDQbomParentEntity root = dQBomParentService.getById(rootBomRowId); BomNewDQbomParentEntity root = dQBomParentService.getById(rootBomRowId);
VUtils.isTure(Objects.isNull(root)).throwMessage("未找到数据"); VUtils.isTure(Objects.isNull(root)).throwMessage("未找到数据");
VUtils.isTure(root.getStatus() == 2).throwMessage("已转pbom不能再次转换");
if (Objects.equals(root.getExceptionStatus(), EBomExceptionStatusEnum.OK.getValue())) {
//如果没有异常则再进行一次异常检查避免手动添加数据后没做异常检查就转pbom
checkException(rootBomRowId);
}
VUtils.isTure(!Objects.equals(root.getExceptionStatus(), EBomExceptionStatusEnum.OK.getValue())) VUtils.isTure(!Objects.equals(root.getExceptionStatus(), EBomExceptionStatusEnum.OK.getValue()))
.throwMessage("异常状态不能转pbom"); .throwMessage("异常状态不能转pbom");
VUtils.isTure(root.getStatus() == 2).throwMessage("已转pbom不能再次转换");
List<BomNewDQbomParentEntity> parents = new ArrayList<>(); List<BomNewDQbomParentEntity> parents = new ArrayList<>();
List<BomNewDQbomChildEntity> children = new ArrayList<>(); List<BomNewDQbomChildEntity> children = new ArrayList<>();
buildPbom(root, parents, children); buildTree(root, parents, children);
dQBomParentService.updateBatchById(parents); dQBomParentService.updateBatchById(parents);
dQBomChildService.updateBatchById(children); dQBomChildService.updateBatchById(children);
savePbomParents(parents); savePbomParents(parents);
@ -467,12 +470,18 @@ public class DQBomService {
c.setModifyTime(null); c.setModifyTime(null);
c.setIdentityNo(c.getParentRowId() + "_" + c.getRowId()); c.setIdentityNo(c.getParentRowId() + "_" + c.getRowId());
if (CollUtil.isNotEmpty(materialBaseInfos)) { if (CollUtil.isNotEmpty(materialBaseInfos)) {
BaseMaterialVO materialVO = materialBaseInfos.stream().filter(m -> m.getMaterialNo().equals(c.getMaterialNo())).findFirst().orElse(null); BaseMaterialVO materialVO = materialBaseInfos.stream()
.filter(m -> m.getMaterialNo().equals(c.getMaterialNo()))
.findFirst()
.orElse(null);
if (!Objects.isNull(materialVO)) { if (!Objects.isNull(materialVO)) {
c.setMaterialCategoryCode(materialVO.getMaterialCategoryCode()); c.setMaterialCategoryCode(materialVO.getMaterialCategoryCode());
} }
} }
BomNewDQbomParentEntity parent = parents.stream().filter(p -> p.getMaterialNo().equals(c.getMaterialNo())).findFirst().orElse(null); BomNewDQbomParentEntity parent = parents.stream()
.filter(p -> p.getMaterialNo().equals(c.getMaterialNo()))
.findFirst()
.orElse(null);
if (!Objects.isNull(parent)) { if (!Objects.isNull(parent)) {
c.setBomVersionRowId(parent.getRowId()); c.setBomVersionRowId(parent.getRowId());
} }
@ -496,7 +505,7 @@ public class DQBomService {
bomNewPbomParentService.saveBatch(pparents); bomNewPbomParentService.saveBatch(pparents);
} }
private void buildPbom(BomNewDQbomParentEntity parent, List<BomNewDQbomParentEntity> parents, List<BomNewDQbomChildEntity> children) { private void buildTree(BomNewDQbomParentEntity parent, List<BomNewDQbomParentEntity> parents, List<BomNewDQbomChildEntity> children) {
parent.setStatus(2); parent.setStatus(2);
parent.setConvertToPbomTime(LocalDateTime.now()); parent.setConvertToPbomTime(LocalDateTime.now());
parent.setModifyTime(LocalDateTime.now()); parent.setModifyTime(LocalDateTime.now());
@ -521,24 +530,25 @@ public class DQBomService {
VUtils.isTure(true).throwMessage(StrUtil.format("{}的当前版本为{}比pbom中版本{}低", parent.getMaterialNo() VUtils.isTure(true).throwMessage(StrUtil.format("{}的当前版本为{}比pbom中版本{}低", parent.getMaterialNo()
, parent.getCurrentVersion(), pp.getCurrentVersion())); , parent.getCurrentVersion(), pp.getCurrentVersion()));
} else { } else {
if (pp.getStatus() == 4) { if (pp.getStatus() >= 4) {
List<BomNewDQbomVO> dqChildren = getChild(parent.getRowId()); // List<BomNewDQbomVO> dqChildren = getChild(parent.getRowId());
Set<String> pChildren = bomNewPbomChildService.lambdaQuery() // Set<String> pChildren = bomNewPbomChildService.lambdaQuery()
.select(BomNewPbomChildEntity::getMaterialNo) // .select(BomNewPbomChildEntity::getMaterialNo)
.eq(BomNewPbomChildEntity::getParentRowId, pp.getRowId()) // .eq(BomNewPbomChildEntity::getParentRowId, pp.getRowId())
.list() // .list()
.stream() // .stream()
.map(BomNewPbomChildEntity::getMaterialNo) // .map(BomNewPbomChildEntity::getMaterialNo)
.collect(Collectors.toSet()); // .collect(Collectors.toSet());
if (dqChildren.size() != pChildren.size() // if (dqChildren.size() != pChildren.size()
|| !Sets.difference(dqChildren.stream().map(BomNewDQbomVO::getMaterialNo).collect(Collectors.toSet()), pChildren).isEmpty()) { // || !Sets.difference(dqChildren.stream().map(BomNewDQbomVO::getMaterialNo).collect(Collectors.toSet()), pChildren).isEmpty()) {
parent.setCurrentVersion(VersionUtil.getNextVersion(parent.getCurrentVersion())); parent.setCurrentVersion(VersionUtil.getNextVersion(pp.getCurrentVersion()));
pp.setLastVersionIs(0); pp.setLastVersionIs(0);
bomNewPbomParentService.updateById(pp); bomNewPbomParentService.updateById(pp);
} // }
} else { } else {
parent.setCurrentVersion(pp.getCurrentVersion());
bomNewPbomParentService.getBaseMapper().deleteById(pp.getRowId()); bomNewPbomParentService.getBaseMapper().deleteById(pp.getRowId());
bomNewPbomChildService.getBaseMapper().delete(new LambdaQueryWrapper<BomNewPbomChildEntity>() bomNewPbomChildService.getBaseMapper().delete(bomNewPbomChildService.lambdaQuery()
.eq(BomNewPbomChildEntity::getParentRowId, pp.getRowId())); .eq(BomNewPbomChildEntity::getParentRowId, pp.getRowId()));
} }
} }
@ -548,7 +558,7 @@ public class DQBomService {
.in(BomNewDQbomParentEntity::getMaterialNo, cc.stream().map(BomNewDQbomChildEntity::getMaterialNo).collect(Collectors.toList())) .in(BomNewDQbomParentEntity::getMaterialNo, cc.stream().map(BomNewDQbomChildEntity::getMaterialNo).collect(Collectors.toList()))
.eq(BomNewDQbomParentEntity::getStatus, 1) .eq(BomNewDQbomParentEntity::getStatus, 1)
.list() .list()
.forEach(p -> buildPbom(p, parents, children)); .forEach(p -> buildTree(p, parents, children));
} }
private int versionCompare(String version1, String version2) { private int versionCompare(String version1, String version2) {