fix(ebom): 优化从excel导入
This commit is contained in:
parent
1da8f1f7bb
commit
cb8c71bca6
|
|
@ -105,16 +105,32 @@ public class BomNewEbomGenerateVirtualPackageServiceFor31Impl implements IBomNew
|
|||
|
||||
private void selected1020Cancel1010(BomNewEbomParentEntity root, BomNewEbomChildEntity child, ChildListForGenerateVirtualPackageVO old) {
|
||||
if (old.isHasGenerated1010()) {
|
||||
buildDelDeliveryVirtualPackage(root, child, false);
|
||||
buildDelVirtualPackage(root, child, false);
|
||||
}
|
||||
if (!old.isHasGenerated1020()) {
|
||||
build1020VirtualPackage(root, true, child);
|
||||
} else {
|
||||
String dnMaking = buildDrawingNo(root.getDrawingNo(), child.getMaterialName(), VirtualPackageTypeEnum.MAKING_PACKAGE, true);
|
||||
BomNewEbomParentEntity p = ebomParentService.lambdaQuery()
|
||||
.eq(BomNewEbomParentEntity::getDrawingNo, dnMaking)
|
||||
.one();
|
||||
if (Objects.isNull(p)) {
|
||||
BomNewEbomChildEntity c = ebomChildService.lambdaQuery()
|
||||
.eq(BomNewEbomChildEntity::getDrawingNo, dnMaking)
|
||||
.one();
|
||||
p = buildVirtualPackage(ebomParentService.lambdaQuery()
|
||||
.eq(BomNewEbomParentEntity::getDrawingNo, buildDrawingNo(root.getDrawingNo(), child.getMaterialName(), VirtualPackageTypeEnum.DELIVERY_PACKAGE, true))
|
||||
.one(), c);
|
||||
}
|
||||
child.setParentRowId(p.getRowId());
|
||||
child.setModifyTime(LocalDateTime.now());
|
||||
children.add(child);
|
||||
}
|
||||
}
|
||||
|
||||
private void selected1010Cancel1020(BomNewEbomParentEntity root, BomNewEbomChildEntity child, ChildListForGenerateVirtualPackageVO old) {
|
||||
if (old.isHasGenerated1020()) {
|
||||
buildDelDeliveryVirtualPackage(root, child, true);
|
||||
buildDelVirtualPackage(root, child, true);
|
||||
}
|
||||
if (!old.isHasGenerated1010()) {
|
||||
build1010VirtualPackage(root, child);
|
||||
|
|
@ -168,28 +184,33 @@ public class BomNewEbomGenerateVirtualPackageServiceFor31Impl implements IBomNew
|
|||
child.setModifyTime(LocalDateTime.now());
|
||||
children.add(child);
|
||||
if (old.isHasGenerated1010()) {
|
||||
buildDelDeliveryVirtualPackage(root, child, false);
|
||||
buildDelVirtualPackage(root, child, false);
|
||||
}
|
||||
if (old.isHasGenerated1020()) {
|
||||
buildDelDeliveryVirtualPackage(root, child, true);
|
||||
buildDelVirtualPackage(root, child, true);
|
||||
}
|
||||
}
|
||||
|
||||
// private void buildDelAllVirtualPackage(BomNewEbomParentEntity root, BomNewEbomChildEntity child, boolean is1020Factory) {
|
||||
// buildDelVirtualPackage(root, child, VirtualPackageTypeEnum.DELIVERY_PACKAGE, is1020Factory);
|
||||
// buildDelVirtualPackage(root, child, VirtualPackageTypeEnum.MAKING_PACKAGE, is1020Factory);
|
||||
// buildDelVirtualPackage(root, child, VirtualPackageTypeEnum.DIRECT_DELIVERY_PACKAGE, is1020Factory);
|
||||
// }
|
||||
|
||||
/**
|
||||
* 删除发货包
|
||||
* @param root 根节点
|
||||
* @param child 物料
|
||||
* @param is1020Factory 是否是仙桃工厂
|
||||
*/
|
||||
private void buildDelDeliveryVirtualPackage(BomNewEbomParentEntity root, BomNewEbomChildEntity child, boolean is1020Factory) {
|
||||
//发货包
|
||||
private void buildDelVirtualPackage(BomNewEbomParentEntity root, BomNewEbomChildEntity child, boolean is1020Factory) {
|
||||
String drawingNo = buildDrawingNo(root.getDrawingNo(), child.getMaterialName(), VirtualPackageTypeEnum.DELIVERY_PACKAGE, is1020Factory);
|
||||
BomNewEbomChildEntity c = ebomChildService.lambdaQuery()
|
||||
.eq(BomNewEbomChildEntity::getParentRowId, root.getRowId())
|
||||
.eq(BomNewEbomChildEntity::getDrawingNo, drawingNo)
|
||||
.one();
|
||||
if (Objects.isNull(c)) {
|
||||
LOGGER.error("{}应有发货包“{}”但未找到", root.getMaterialNo(), drawingNo);
|
||||
LOGGER.error("{}应有{}“{}”但未找到", root.getMaterialNo(), VirtualPackageTypeEnum.DELIVERY_PACKAGE.getDescription(), drawingNo);
|
||||
} else {
|
||||
childRowIdsForDel.add(c.getRowId());
|
||||
}
|
||||
|
|
@ -224,26 +245,39 @@ public class BomNewEbomGenerateVirtualPackageServiceFor31Impl implements IBomNew
|
|||
|
||||
private BomNewEbomChildEntity buildVirtualPackage(boolean is1020Factory, Long parentRowId, BomNewEbomParentEntity root
|
||||
, BomNewEbomChildEntity material, VirtualPackageTypeEnum type, String orderNo) {
|
||||
BomNewEbomChildEntity child = new BomNewEbomChildEntity();
|
||||
child.setRowId(IdWorker.getId());
|
||||
child.setParentRowId(parentRowId);
|
||||
child.setIdentityNo(parentRowId + "_" + child.getRowId());
|
||||
child.setOrderNumber(orderNo);
|
||||
child.setNum(new BigDecimal(1));
|
||||
child.setEditStatus(root.getEditStatus());
|
||||
child.setSource(EBomSourceEnum.FROM_MDM.getValue());
|
||||
child.setVirtualPartType(type.getValue());
|
||||
child.setProjectType("L");
|
||||
child.setProjectTypeInputType(ProjectTypeInputTypeEnum.MANUAL_INPUT.getValue());
|
||||
child.setMaterialUnit("PC");
|
||||
child.setMaterialOriginalUnit("PC");
|
||||
//child.setVirtualPartRootMaterialNo(rootMaterialNo);
|
||||
child.setCreatedBy(SessionUtil.getUserCode());
|
||||
child.setDrawingNo(buildDrawingNo(root.getDrawingNo(), material.getMaterialName(), type, is1020Factory));
|
||||
child.setMaterialDesc(child.getDrawingNo());
|
||||
child.setMaterialName(child.getDrawingNo());
|
||||
child.setMaterialCategoryCode(type.getMaterialCategoryCode());
|
||||
children.add(child);
|
||||
String drawingNo = buildDrawingNo(root.getDrawingNo(), material.getMaterialName(), type, is1020Factory);
|
||||
BomNewEbomChildEntity child = ebomChildService.lambdaQuery()
|
||||
.eq(BomNewEbomChildEntity::getParentRowId, parentRowId)
|
||||
.eq(BomNewEbomChildEntity::getDrawingNo, drawingNo)
|
||||
.one();
|
||||
if (Objects.isNull(child)) {
|
||||
child = new BomNewEbomChildEntity();
|
||||
child.setRowId(IdWorker.getId());
|
||||
BomNewEbomParentEntity p = ebomParentService.lambdaQuery()
|
||||
.eq(BomNewEbomParentEntity::getDrawingNo, drawingNo)
|
||||
.one();
|
||||
if (Objects.nonNull(p)) {
|
||||
child.setMaterialNo(p.getMaterialNo());
|
||||
}
|
||||
child.setParentRowId(parentRowId);
|
||||
child.setIdentityNo(parentRowId + "_" + child.getRowId());
|
||||
child.setOrderNumber(orderNo);
|
||||
child.setNum(new BigDecimal(1));
|
||||
child.setEditStatus(root.getEditStatus());
|
||||
child.setSource(EBomSourceEnum.FROM_MDM.getValue());
|
||||
child.setVirtualPartType(type.getValue());
|
||||
child.setProjectType("L");
|
||||
child.setProjectTypeInputType(ProjectTypeInputTypeEnum.MANUAL_INPUT.getValue());
|
||||
child.setMaterialUnit("PC");
|
||||
child.setMaterialOriginalUnit("PC");
|
||||
child.setCreatedBy(SessionUtil.getUserCode());
|
||||
child.setDrawingNo(drawingNo);
|
||||
child.setMaterialDesc(child.getDrawingNo());
|
||||
child.setMaterialName(child.getDrawingNo());
|
||||
child.setMaterialCategoryCode(type.getMaterialCategoryCode());
|
||||
child.setVirtualPartRootMaterialNo(root.getMaterialNo());
|
||||
children.add(child);
|
||||
}
|
||||
return child;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2373,6 +2373,7 @@ public class BomNewEbomParentService extends ServiceImpl<BomNewEbomParentMapper,
|
|||
public List<ChildListForGenerateVirtualPackageVO> getChildListForGenerateVirtualPackage(BomNewEbomParentEntity parent) {
|
||||
List<BomNewEbomChildEntity> children = ebomChildService.lambdaQuery()
|
||||
.eq(BomNewEbomChildEntity::getVirtualPartRootMaterialNo, parent.getMaterialNo())
|
||||
.eq(BomNewEbomChildEntity::getVirtualPartType, VirtualPackageTypeEnum.UN_VIRTUAL_PACKAGE.getValue())
|
||||
.ne(BomNewEbomChildEntity::getProjectType, BomConstant.PROJECT_TYPE_TEMPORARY)
|
||||
.orderByAsc(BomNewEbomChildEntity::getOrderNumber)
|
||||
.list();
|
||||
|
|
|
|||
|
|
@ -70,13 +70,18 @@ public class EBomImportService {
|
|||
}
|
||||
|
||||
Pair<List<BomNewEbomParentEntity>, List<BomNewEbomChildEntity>> pcs = convertToBom(datas);
|
||||
VUtils.isTure(checkInconsistentData(pcs.getLeft().get(0), pcs.getLeft(), pcs.getRight()))
|
||||
.throwMessage("导入的数据已存在,请勿重复导入");
|
||||
VUtils.isTure(checkInconsistentData(pcs.getLeft().get(0), pcs.getLeft(), pcs.getRight())).throwMessage("导入的数据已存在,请勿重复导入");
|
||||
|
||||
save(pcs.getLeft(), pcs.getRight());
|
||||
|
||||
bomNewEbomParentService.resetAllBomExist();
|
||||
|
||||
bomNewEbomParentService.batchCheckAndSaveEBomException(pcs.getLeft().stream()
|
||||
.filter(p -> p.getRootIs() == 1)
|
||||
.map(BomNewEbomParentEntity::getRowId)
|
||||
.collect(Collectors.toList())
|
||||
);
|
||||
|
||||
return Collections.emptyList();
|
||||
} finally {
|
||||
excelContextTL.remove();
|
||||
|
|
@ -87,14 +92,10 @@ public class EBomImportService {
|
|||
public void save(List<BomNewEbomParentEntity> parents, List<BomNewEbomChildEntity> children) {
|
||||
Set<String> pMaterialNos = parents.stream().map(BomNewEbomParentEntity::getMaterialNo).collect(Collectors.toSet());
|
||||
List<BomNewEbomParentEntity> oldParents = bomNewEbomParentService.getLatestByMaterialNo(pMaterialNos);
|
||||
parents.forEach(p -> {
|
||||
BomNewEbomParentEntity oldParent = oldParents.stream()
|
||||
.filter(op -> op.getMaterialNo().equals(p.getMaterialNo()))
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
if (!Objects.isNull(oldParent) && !Objects.equals(oldParent.getStatus(), EBomStatusEnum.PUBLISHED.getValue())) {
|
||||
bomNewEbomParentService.getBaseMapper().deleteById(oldParent.getRowId());
|
||||
bomNewEbomChildService.deleteAllChildren(oldParent.getRowId());
|
||||
oldParents.forEach(p -> {
|
||||
if (!Objects.equals(p.getStatus(), EBomStatusEnum.PUBLISHED.getValue())) {
|
||||
bomNewEbomParentService.getBaseMapper().deleteById(p.getRowId());
|
||||
bomNewEbomChildService.deleteAllChildren(p.getRowId());
|
||||
}
|
||||
});
|
||||
bomNewEbomParentService.setLastVersionIs0(pMaterialNos);
|
||||
|
|
@ -108,7 +109,15 @@ public class EBomImportService {
|
|||
BomNewEbomParentEntity oldParent = bomNewEbomParentService.getLatestByMaterialNo(parent.getMaterialNo());
|
||||
boolean isSame = true;
|
||||
if (Objects.isNull(oldParent)) {
|
||||
return false;
|
||||
List<BomNewEbomChildEntity> cc = children.stream()
|
||||
.filter(c -> c.getParentRowId().equals(parent.getRowId()))
|
||||
.collect(Collectors.toList());
|
||||
for (BomNewEbomChildEntity ccc : cc) {
|
||||
if (!checkInconsistentData(parent.getRowId(), ccc, parents, children)) {
|
||||
isSame = false;
|
||||
}
|
||||
}
|
||||
return isSame;
|
||||
}
|
||||
isSame = Objects.equals(parent.getMaterialUnit(), oldParent.getMaterialUnit())
|
||||
&& NumberUtil.equals(parent.getNum(), oldParent.getNum())
|
||||
|
|
@ -205,6 +214,12 @@ public class EBomImportService {
|
|||
String id = RandomUtil.randomNumbers(9);
|
||||
dto.setMaterialNo(BomConstant.PROJECT_TYPE_TEMPORARY + id);
|
||||
dto.setDrawingNo(BomConstant.PROJECT_TYPE_TEMPORARY + id);
|
||||
if (Objects.isNull(dto.getNum())) {
|
||||
dto.setNum(BigDecimal.ONE);
|
||||
}
|
||||
if (Objects.isNull(dto.getUnit())) {
|
||||
dto.setUnit("PC");
|
||||
}
|
||||
}
|
||||
|
||||
excelContextTL.get().add(dto);
|
||||
|
|
@ -260,6 +275,15 @@ public class EBomImportService {
|
|||
);
|
||||
}
|
||||
|
||||
numError = datas.stream().filter(u -> StrUtil.equals(u.getMaterialNo(), u.getParentMaterialNo()))
|
||||
.map(BaseImportExcelDTO::getRowNum)
|
||||
.collect(Collectors.toList());
|
||||
if (!numError.isEmpty()) {
|
||||
errorMsg.addAll(numError.stream().map(n -> OperationErrorMsgVO.create("第" + n + "行", "项目物料与抬头物料相同"))
|
||||
.collect(Collectors.toList())
|
||||
);
|
||||
}
|
||||
|
||||
return errorMsg;
|
||||
}
|
||||
|
||||
|
|
@ -336,6 +360,7 @@ public class EBomImportService {
|
|||
BomNewEbomParentEntity parent = new BomNewEbomParentEntity();
|
||||
parent.setRowId(IdWorker.getId());
|
||||
|
||||
parent.setCurrentVersion(OriginalConstant.DEFAULT_BOM_VERSION);
|
||||
parent.setMaterialNo(data.getMaterialNo());
|
||||
parent.setMaterialDesc(data.getMaterialDesc());
|
||||
BaseMaterialVO vo = materialBaseInfos.stream()
|
||||
|
|
@ -355,7 +380,6 @@ public class EBomImportService {
|
|||
parent.setMaterialOriginalUnit(data.getUnit());
|
||||
parent.setNum(data.getNum());
|
||||
parent.setTotalWeight(BomUtil.calculateTotalWeight(parent.getNum(), parent.getUnitWeight()));
|
||||
parent.setCurrentVersion(OriginalConstant.DEFAULT_BOM_VERSION);
|
||||
parent.setUserRootIs(0);
|
||||
parent.setRootIs(0);
|
||||
if (userRoleService.technician()) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue