diff --git a/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/pojo/entity/BomNewEbomChildEntity.java b/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/pojo/entity/BomNewEbomChildEntity.java index d4385a8a..8fe01c27 100644 --- a/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/pojo/entity/BomNewEbomChildEntity.java +++ b/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/pojo/entity/BomNewEbomChildEntity.java @@ -1,6 +1,5 @@ package com.nflg.product.bomnew.pojo.entity; -import cn.hutool.core.util.StrUtil; import com.baomidou.mybatisplus.annotation.IdType; import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableId; @@ -225,7 +224,9 @@ public class BomNewEbomChildEntity implements Serializable { @ApiModelProperty(value = "原始单位-来自cad") private String materialOriginalUnit; - + @TableField(value = "initial_parent_row_id") + @ApiModelProperty(value = "刚转过来或刚导入时的父行ID") + private Long initialParentRowId; // private String materialNoAndProjectType; // public String getMaterialNoAndProjectType() { diff --git a/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/service/BomNewEbomGenerateVirtualPackageServiceFor31Impl.java b/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/service/BomNewEbomGenerateVirtualPackageServiceFor31Impl.java index 85415ebd..054f3afe 100644 --- a/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/service/BomNewEbomGenerateVirtualPackageServiceFor31Impl.java +++ b/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/service/BomNewEbomGenerateVirtualPackageServiceFor31Impl.java @@ -4,13 +4,11 @@ import cn.hutool.core.collection.CollUtil; import cn.hutool.core.convert.Convert; import cn.hutool.core.util.StrUtil; import cn.hutool.extra.spring.SpringUtil; +import com.alibaba.fastjson.JSON; import com.baomidou.mybatisplus.core.toolkit.IdWorker; import com.nflg.product.base.core.conmon.util.SessionUtil; import com.nflg.product.bomnew.client.MaterialMainClient; -import com.nflg.product.bomnew.constant.EBomSourceEnum; -import com.nflg.product.bomnew.constant.OriginalConstant; -import com.nflg.product.bomnew.constant.ProjectTypeInputTypeEnum; -import com.nflg.product.bomnew.constant.VirtualPackageTypeEnum; +import com.nflg.product.bomnew.constant.*; import com.nflg.product.bomnew.pojo.dto.AddVirtrualMaterialDTO; import com.nflg.product.bomnew.pojo.dto.MaterialUpdateBillDTO; import com.nflg.product.bomnew.pojo.entity.BomNewEbomChildEntity; @@ -20,6 +18,8 @@ import com.nflg.product.bomnew.pojo.vo.ChildListForGenerateVirtualPackageVO; import com.nflg.product.bomnew.pojo.vo.MaterialMainVO; import com.nflg.product.bomnew.pojo.vo.OperationErrorMsgVO; import com.nflg.product.bomnew.util.VUtils; +import com.nflg.product.bomnew.util.VersionUtil; +import nflg.product.common.dto.LoginUserInfoDTO; import nflg.product.common.vo.ResultVO; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -27,11 +27,8 @@ import org.springframework.transaction.annotation.Transactional; import java.math.BigDecimal; import java.time.LocalDateTime; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.Objects; -import java.util.stream.Collectors; +import java.util.*; +import java.util.concurrent.CompletableFuture; /** * @author 曹鹏飞 @@ -43,15 +40,20 @@ public class BomNewEbomGenerateVirtualPackageServiceFor31Impl implements IBomNew private final BomNewEbomParentService ebomParentService = SpringUtil.getBean(BomNewEbomParentService.class); private final BomNewEbomChildService ebomChildService = SpringUtil.getBean(BomNewEbomChildService.class); - private final MaterialMainClient materialMainClient = SpringUtil.getBean(MaterialMainClient.class); private final MaterialService materialService = SpringUtil.getBean(MaterialService.class); - private final List children = new ArrayList<>(); - private final List parents = new ArrayList<>(); + private final List childrenForAdd = Collections.synchronizedList(new ArrayList<>()); + private final List childrenForUpdate = Collections.synchronizedList(new ArrayList<>()); + private final List parentsForAdd = Collections.synchronizedList(new ArrayList<>()); + private final List parentsForUpdate = Collections.synchronizedList(new ArrayList<>()); private final List childRowIdsForDel = new ArrayList<>(); + private final List errorMsgList = Collections.synchronizedList(new ArrayList<>()); + private final Map materialUpdateBill = new HashMap<>(); - private final List errorMsgList = new ArrayList<>(); + private final static List DOING_ROWID = Collections.synchronizedList(new ArrayList<>()); + + private final LoginUserInfoDTO userInfo = SessionUtil.getUser(); @Override public List generate(GenerateVirtualPackageQuery query) { @@ -61,42 +63,58 @@ public class BomNewEbomGenerateVirtualPackageServiceFor31Impl implements IBomNew VUtils.isTure(root.getMaterialNo().startsWith("21")).throwMessage("21编码接口调用错误"); VUtils.isTure(!root.getMaterialNo().startsWith("31")).throwMessage("该编码的物料不能生成发货包:" + root.getMaterialNo()); - List olds = ebomParentService.getChildListForGenerateVirtualPackage(root); - query.getChildren().forEach(it -> { - ChildListForGenerateVirtualPackageVO old = olds.stream().filter(f -> Objects.equals(f.getRowId(), it.getRowId())).findFirst().orElse(null); - VUtils.isTure(Objects.isNull(old)).throwMessage(it.getRowId() + "无效"); - BomNewEbomChildEntity child = ebomChildService.getById(it.getRowId()); - if (it.isGenerate1010() && it.isGenerate1020()) { - selectedAll(root, child, old); - } else if (!it.isGenerate1010() && !it.isGenerate1020()) { - cancelAll(root, child, old); - } else if (it.isGenerate1010()) { - selected1010Cancel1020(root, child, old); - } else { - selected1020Cancel1010(root, child, old); + VUtils.isTure(DOING_ROWID.contains(query.getParentRowId())).throwMessage(root.getMaterialNo() + "正在生成虚拟包,请勿重复操作"); + try { + DOING_ROWID.add(query.getParentRowId()); + List olds = ebomParentService.getChildListForGenerateVirtualPackage(root); + List> futures = new ArrayList<>(); + query.getChildren().forEach(it -> { + CompletableFuture future = CompletableFuture.runAsync(() -> { + ChildListForGenerateVirtualPackageVO old = olds.stream().filter(f -> Objects.equals(f.getRowId(), it.getRowId())).findFirst().orElse(null); + VUtils.isTure(Objects.isNull(old)).throwMessage(it.getRowId() + "无效"); + BomNewEbomChildEntity child = ebomChildService.getById(it.getRowId()); + if (it.isGenerate1010() && it.isGenerate1020()) { + selectedAll(root, child, old); + } else if (!it.isGenerate1010() && !it.isGenerate1020()) { + cancelAll(root, child, old); + } else if (it.isGenerate1010()) { + selected1010Cancel1020(root, child, old); + } else { + selected1020Cancel1010(root, child, old); + } + }); + futures.add(future); + }); + CompletableFuture combinedFuture = CompletableFuture.allOf(futures.toArray(new CompletableFuture[0])); + combinedFuture.join(); + + // List addM = children.stream().filter(c -> StrUtil.isBlank(c.getMaterialNo())).map(c -> { + // AddVirtrualMaterialDTO ent = new AddVirtrualMaterialDTO(); + // ent.setKey(c.getRowId().toString()); + // ent.setDrawingNo(c.getDrawingNo()); + // ent.setMaterialName(c.getMaterialName()); + // ent.setMaterialDesc(c.getMaterialDesc()); + // ent.setMaterialCategoryCode(c.getMaterialCategoryCode()); + // return ent; + // }).collect(Collectors.toList()); + // Map vMNosResult = materialService.batchAddMaterial(addM); + // vMNosResult.forEach((k, v) -> { + // children.stream().filter(c -> Objects.equals(c.getRowId(), Convert.toLong(k))).forEach(c -> { + // c.setMaterialNo(v.getMaterialNo()); + // }); + // parents.stream().filter(c -> Objects.equals(c.getRowId(), Convert.toLong(k))).forEach(c -> { + // c.setMaterialNo(v.getMaterialNo()); + // }); + // }); + + save(); + + if (!materialUpdateBill.isEmpty()) { + materialUpdateBill.forEach(this::addMaterialUpdateBillEntity); } - }); - - List addM = children.stream().filter(c -> StrUtil.isBlank(c.getMaterialNo())).map(c -> { - AddVirtrualMaterialDTO ent = new AddVirtrualMaterialDTO(); - ent.setKey(c.getRowId().toString()); - ent.setDrawingNo(c.getDrawingNo()); - ent.setMaterialName(c.getMaterialName()); - ent.setMaterialDesc(c.getMaterialDesc()); - ent.setMaterialCategoryCode(c.getMaterialCategoryCode()); - return ent; - }).collect(Collectors.toList()); - Map vMNosResult = materialService.batchAddMaterial(addM); - vMNosResult.forEach((k, v) -> { - children.stream().filter(c -> Objects.equals(c.getRowId(), Convert.toLong(k))).forEach(c -> { - c.setMaterialNo(v.getMaterialNo()); - }); - parents.stream().filter(c -> Objects.equals(c.getRowId(), Convert.toLong(k))).forEach(c -> { - c.setMaterialNo(v.getMaterialNo()); - }); - }); - - save(); + } finally { + DOING_ROWID.remove(query.getParentRowId()); + } return errorMsgList; } @@ -106,11 +124,25 @@ public class BomNewEbomGenerateVirtualPackageServiceFor31Impl implements IBomNew if (CollUtil.isNotEmpty(childRowIdsForDel)) { ebomChildService.getBaseMapper().deleteBatchIds(childRowIdsForDel); } - if (CollUtil.isNotEmpty(children)) { - ebomChildService.saveOrUpdateBatch(children); + if (CollUtil.isNotEmpty(childrenForAdd)) { + LOGGER.debug("ebomChildService.saveBatch"); + LOGGER.debug(JSON.toJSONString(childrenForAdd)); + ebomChildService.saveBatch(childrenForAdd); } - if (CollUtil.isNotEmpty(parents)) { - ebomParentService.saveOrUpdateBatch(parents); + if (CollUtil.isNotEmpty(childrenForUpdate)) { + LOGGER.debug("ebomChildService.updateBatchById"); + LOGGER.debug(JSON.toJSONString(childrenForUpdate)); + ebomChildService.updateBatchById(childrenForUpdate); + } + if (CollUtil.isNotEmpty(parentsForAdd)) { + LOGGER.debug("ebomParentService.saveBatch"); + LOGGER.debug(JSON.toJSONString(parentsForAdd)); + ebomParentService.saveBatch(parentsForAdd); + } + if (CollUtil.isNotEmpty(parentsForUpdate)) { + LOGGER.debug("ebomParentService.updateBatchById"); + LOGGER.debug(JSON.toJSONString(parentsForUpdate)); + ebomParentService.updateBatchById(parentsForUpdate); } } @@ -120,6 +152,7 @@ public class BomNewEbomGenerateVirtualPackageServiceFor31Impl implements IBomNew String dnMaking = buildDrawingNo(root.getDrawingNo(), child.getMaterialName(), VirtualPackageTypeEnum.MAKING_PACKAGE, true); BomNewEbomParentEntity p = ebomParentService.lambdaQuery() .eq(BomNewEbomParentEntity::getDrawingNo, dnMaking) + .lt(BomNewEbomParentEntity::getStatus, EBomStatusEnum.PUBLISHED.getValue()) .one(); if (Objects.isNull(p)) { BomNewEbomChildEntity c = ebomChildService.lambdaQuery() @@ -131,7 +164,7 @@ public class BomNewEbomGenerateVirtualPackageServiceFor31Impl implements IBomNew } child.setParentRowId(p.getRowId()); child.setModifyTime(LocalDateTime.now()); - children.add(child); + childrenForUpdate.add(child); } else if (!old.isHasGenerated1010() && !old.isHasGenerated1020()) { build1020VirtualPackage(root, true, child); } else if (old.isHasGenerated1010()) { @@ -140,12 +173,14 @@ public class BomNewEbomGenerateVirtualPackageServiceFor31Impl implements IBomNew String newDrawingNo = buildDrawingNo(root.getDrawingNo(), child.getMaterialName(), VirtualPackageTypeEnum.DELIVERY_PACKAGE, true); BomNewEbomParentEntity fp = ebomParentService.lambdaQuery() .eq(BomNewEbomParentEntity::getDrawingNo, newDrawingNo) + .lt(BomNewEbomParentEntity::getStatus, EBomStatusEnum.PUBLISHED.getValue()) .one(); if (Objects.nonNull(fp)) { buildVirtualPackage(true, root.getRowId(), root, child, VirtualPackageTypeEnum.DELIVERY_PACKAGE, child.getOrderNumber()); String dnMaking = buildDrawingNo(root.getDrawingNo(), child.getMaterialName(), VirtualPackageTypeEnum.MAKING_PACKAGE, true); BomNewEbomParentEntity zp = ebomParentService.lambdaQuery() .eq(BomNewEbomParentEntity::getDrawingNo, dnMaking) + .lt(BomNewEbomParentEntity::getStatus, EBomStatusEnum.PUBLISHED.getValue()) .one(); if (Objects.isNull(zp)) { BomNewEbomChildEntity c = ebomChildService.lambdaQuery() @@ -158,7 +193,7 @@ public class BomNewEbomGenerateVirtualPackageServiceFor31Impl implements IBomNew //挂载物料 child.setParentRowId(zp.getRowId()); child.setModifyTime(LocalDateTime.now()); - children.add(child); + childrenForUpdate.add(child); } else { fp = updateParentVirtualPackage(oldDrawingNo, newDrawingNo); updateChildVirtualPackage(root.getRowId(), oldDrawingNo, newDrawingNo); @@ -174,7 +209,7 @@ public class BomNewEbomGenerateVirtualPackageServiceFor31Impl implements IBomNew //挂载物料 child.setParentRowId(zp.getRowId()); child.setModifyTime(LocalDateTime.now()); - children.add(child); + childrenForUpdate.add(child); } } } @@ -182,15 +217,17 @@ public class BomNewEbomGenerateVirtualPackageServiceFor31Impl implements IBomNew private BomNewEbomParentEntity updateParentVirtualPackage(String oldDrawingNo, String newDrawingNo) { BomNewEbomParentEntity p = ebomParentService.lambdaQuery() .eq(BomNewEbomParentEntity::getDrawingNo, newDrawingNo) + .lt(BomNewEbomParentEntity::getStatus, EBomStatusEnum.PUBLISHED.getValue()) .one(); if (Objects.isNull(p)) { p = ebomParentService.lambdaQuery() .eq(BomNewEbomParentEntity::getDrawingNo, oldDrawingNo) + .lt(BomNewEbomParentEntity::getStatus, EBomStatusEnum.PUBLISHED.getValue()) .one(); p.setDrawingNo(newDrawingNo); p.setMaterialDesc(newDrawingNo); p.setMaterialName(newDrawingNo); - parents.add(p); + parentsForUpdate.add(p); } return p; } @@ -200,32 +237,38 @@ public class BomNewEbomGenerateVirtualPackageServiceFor31Impl implements IBomNew .eq(BomNewEbomChildEntity::getParentRowId, parentRowId) .eq(BomNewEbomChildEntity::getDrawingNo, oldDrawingNo) .one(); - addMaterialUpdateBillEntity(c.getMaterialNo(), newDrawingNo); + //addMaterialUpdateBillEntity(c.getMaterialNo(), newDrawingNo); c.setDrawingNo(newDrawingNo); c.setMaterialDesc(newDrawingNo); c.setMaterialName(newDrawingNo); - children.add(c); + childrenForUpdate.add(c); + materialUpdateBill.putIfAbsent(c.getMaterialNo(), newDrawingNo); } private void addMaterialUpdateBillEntity(String materialNo, String newDrawingNo) { - ResultVO result = materialMainClient.selectByMaterialNo(materialNo); - if (result.getState() != 200) { - errorMsgList.add(OperationErrorMsgVO.create(materialNo, result.getMsg())); - return; - } - MaterialMainVO vo = result.getData(); - MaterialUpdateBillDTO dto = Convert.convert(MaterialUpdateBillDTO.class, vo); - dto.setOpEnum(1); - dto.setDrawingNo(newDrawingNo); - dto.setMaterialDesc(newDrawingNo); - dto.setMaterialName(newDrawingNo); - dto.setOldMaterialDesc(vo.getMaterialDesc()); - dto.setOldMaterialState(vo.getMaterialState()); - dto.setOldCategoryCode(vo.getMaterialCategoryCode()); - dto.setUpdateResion("发货包工厂切换"); - ResultVO result1 = materialMainClient.addMaterialUpdateBillEntity(dto); - if (result1.getState() != 200) { - errorMsgList.add(OperationErrorMsgVO.create(materialNo, result1.getMsg())); + try { + ResultVO result = materialMainClient.selectByMaterialNo(materialNo); + if (result.getState() != 200) { + errorMsgList.add(OperationErrorMsgVO.create(materialNo, result.getMsg())); + return; + } + MaterialMainVO vo = result.getData(); + MaterialUpdateBillDTO dto = Convert.convert(MaterialUpdateBillDTO.class, vo); + dto.setOpEnum(1); + dto.setDrawingNo(newDrawingNo); + dto.setMaterialDesc(newDrawingNo); + dto.setMaterialName(newDrawingNo); + dto.setOldMaterialDesc(vo.getMaterialDesc()); + dto.setOldMaterialState(vo.getMaterialState()); + dto.setOldCategoryCode(vo.getMaterialCategoryCode()); + dto.setUpdateResion("发货包工厂切换"); + ResultVO result1 = materialMainClient.addMaterialUpdateBillEntity(dto); + if (result1.getState() != 200) { + errorMsgList.add(OperationErrorMsgVO.create(materialNo, result1.getMsg())); + } + } catch (Exception ex) { + LOGGER.error(StrUtil.format("物料变更失败,materialNo:{},drawingNo:", materialNo, newDrawingNo), ex); + errorMsgList.add(OperationErrorMsgVO.create(materialNo, "物料变更失败:" + ex.getMessage())); } } @@ -241,12 +284,14 @@ public class BomNewEbomGenerateVirtualPackageServiceFor31Impl implements IBomNew String newDrawingNo = buildDrawingNo(root.getDrawingNo(), child.getMaterialName(), VirtualPackageTypeEnum.DELIVERY_PACKAGE, false); BomNewEbomParentEntity fp = ebomParentService.lambdaQuery() .eq(BomNewEbomParentEntity::getDrawingNo, newDrawingNo) + .lt(BomNewEbomParentEntity::getStatus, EBomStatusEnum.PUBLISHED.getValue()) .one(); if (Objects.nonNull(fp)) { buildVirtualPackage(true, root.getRowId(), root, child, VirtualPackageTypeEnum.DELIVERY_PACKAGE, child.getOrderNumber()); - String dnMaking = buildDrawingNo(root.getDrawingNo(), child.getMaterialName(), VirtualPackageTypeEnum.MAKING_PACKAGE, true); + String dnMaking = buildDrawingNo(root.getDrawingNo(), child.getMaterialName(), VirtualPackageTypeEnum.MAKING_PACKAGE, false); BomNewEbomParentEntity zp = ebomParentService.lambdaQuery() .eq(BomNewEbomParentEntity::getDrawingNo, dnMaking) + .lt(BomNewEbomParentEntity::getStatus, EBomStatusEnum.PUBLISHED.getValue()) .one(); if (Objects.isNull(zp)) { BomNewEbomChildEntity c = ebomChildService.lambdaQuery() @@ -259,7 +304,7 @@ public class BomNewEbomGenerateVirtualPackageServiceFor31Impl implements IBomNew //挂载物料 child.setParentRowId(zp.getRowId()); child.setModifyTime(LocalDateTime.now()); - children.add(child); + childrenForUpdate.add(child); } else { fp = updateParentVirtualPackage(oldDrawingNo, newDrawingNo); updateChildVirtualPackage(root.getRowId(), oldDrawingNo, newDrawingNo); @@ -275,7 +320,7 @@ public class BomNewEbomGenerateVirtualPackageServiceFor31Impl implements IBomNew //挂载物料 child.setParentRowId(zp.getRowId()); child.setModifyTime(LocalDateTime.now()); - children.add(child); + childrenForUpdate.add(child); } } } @@ -289,7 +334,7 @@ public class BomNewEbomGenerateVirtualPackageServiceFor31Impl implements IBomNew BomNewEbomParentEntity qp2 = buildVirtualPackage(qp1, qc2); child.setParentRowId(qp2.getRowId()); child.setModifyTime(LocalDateTime.now()); - children.add(child); + childrenForUpdate.add(child); //直发包 buildVirtualPackage(false, qp1.getRowId(), root, child, VirtualPackageTypeEnum.DIRECT_DELIVERY_PACKAGE, "002"); } @@ -304,7 +349,7 @@ public class BomNewEbomGenerateVirtualPackageServiceFor31Impl implements IBomNew BomNewEbomParentEntity xp2 = buildVirtualPackage(xp1, xc2); child.setParentRowId(xp2.getRowId()); child.setModifyTime(LocalDateTime.now()); - children.add(child); + childrenForUpdate.add(child); } //直发包 buildVirtualPackage(true, xp1.getRowId(), root, child, VirtualPackageTypeEnum.DIRECT_DELIVERY_PACKAGE, "002"); @@ -325,7 +370,7 @@ public class BomNewEbomGenerateVirtualPackageServiceFor31Impl implements IBomNew private void cancelAll(BomNewEbomParentEntity root, BomNewEbomChildEntity child, ChildListForGenerateVirtualPackageVO old) { child.setParentRowId(root.getRowId()); child.setModifyTime(LocalDateTime.now()); - children.add(child); + childrenForUpdate.add(child); if (old.isHasGenerated1010()) { buildDelVirtualPackage(root, child, false); } @@ -362,30 +407,46 @@ public class BomNewEbomGenerateVirtualPackageServiceFor31Impl implements IBomNew private BomNewEbomParentEntity buildVirtualPackage(BomNewEbomParentEntity parent, BomNewEbomChildEntity child) { BomNewEbomParentEntity p = ebomParentService.lambdaQuery() .eq(BomNewEbomParentEntity::getDrawingNo, child.getDrawingNo()) + .orderByDesc(BomNewEbomParentEntity::getRowId) + .last(" limit 1") .one(); - if (Objects.isNull(p)) { - p = Convert.convert(BomNewEbomParentEntity.class, child); - p.setCreatedBy(SessionUtil.getUserCode()); - p.setCurrentVersion(OriginalConstant.DEFAULT_BOM_VERSION); - p.setVirtualPackageIs(1); - p.setRootIs(0); - p.setUserRootIs(0); - p.setDeviseName(SessionUtil.getRealName()); - p.setDeviseUserCode(SessionUtil.getUserCode()); - p.setDeptName(SessionUtil.getDepartName()); - p.setRootIsForWaitReview(0); - p.setAuditTime(parent.getAuditTime()); - p.setAuditUserName(parent.getAuditUserName()); - p.setStatus(parent.getStatus()); - p.setLastVersionIs(1); - p.setBatchNo(""); - p.setLevelNum(parent.getLevelNum() + 1); - p.setBomExist(1); - parents.add(p); + if (Objects.nonNull(p)) { + if (Objects.equals(p.getStatus(), EBomStatusEnum.PUBLISHED.getValue())) { + p.setLastVersionIs(0); + parentsForUpdate.add(p); + BomNewEbomParentEntity p1 = buildParent(parent, child); + p1.setCurrentVersion(VersionUtil.getNextVersion(p.getCurrentVersion())); + parentsForAdd.add(p1); + return p1; + } + } else { + p = buildParent(parent, child); + parentsForAdd.add(p); } return p; } + private BomNewEbomParentEntity buildParent(BomNewEbomParentEntity parent, BomNewEbomChildEntity child) { + BomNewEbomParentEntity p = Convert.convert(BomNewEbomParentEntity.class, child); + p.setCreatedBy(userInfo.getUserCode()); + p.setCurrentVersion(OriginalConstant.DEFAULT_BOM_VERSION); + p.setVirtualPackageIs(1); + p.setRootIs(0); + p.setUserRootIs(0); + p.setDeviseName(userInfo.getRealName()); + p.setDeviseUserCode(userInfo.getUserCode()); + p.setDeptName(userInfo.getDepartName()); + p.setRootIsForWaitReview(0); + p.setAuditTime(parent.getAuditTime()); + p.setAuditUserName(parent.getAuditUserName()); + p.setStatus(parent.getStatus()); + p.setLastVersionIs(1); + p.setBatchNo(""); + p.setLevelNum(parent.getLevelNum() + 1); + p.setBomExist(1); + return p; + } + private BomNewEbomChildEntity buildVirtualPackage(boolean is1020Factory, Long parentRowId, BomNewEbomParentEntity root , BomNewEbomChildEntity material, VirtualPackageTypeEnum type, String orderNo) { String drawingNo = buildDrawingNo(root.getDrawingNo(), material.getMaterialName(), type, is1020Factory); @@ -396,12 +457,6 @@ public class BomNewEbomGenerateVirtualPackageServiceFor31Impl implements IBomNew 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); @@ -413,13 +468,22 @@ public class BomNewEbomGenerateVirtualPackageServiceFor31Impl implements IBomNew child.setProjectTypeInputType(ProjectTypeInputTypeEnum.MANUAL_INPUT.getValue()); child.setMaterialUnit("PC"); child.setMaterialOriginalUnit("PC"); - child.setCreatedBy(SessionUtil.getUserCode()); + child.setCreatedBy(userInfo.getUserCode()); child.setDrawingNo(drawingNo); child.setMaterialDesc(child.getDrawingNo()); child.setMaterialName(child.getDrawingNo()); child.setMaterialCategoryCode(type.getMaterialCategoryCode()); child.setVirtualPartRootMaterialNo(root.getMaterialNo()); - children.add(child); + BomNewEbomParentEntity p = ebomParentService.lambdaQuery() + .eq(BomNewEbomParentEntity::getDrawingNo, drawingNo) + .lt(BomNewEbomParentEntity::getStatus, EBomStatusEnum.PUBLISHED.getValue()) + .one(); + if (Objects.nonNull(p)) { + child.setMaterialNo(p.getMaterialNo()); + } else { + child.setMaterialNo(getMaterialNoForAdd(child)); + } + childrenForAdd.add(child); } return child; } @@ -427,4 +491,15 @@ public class BomNewEbomGenerateVirtualPackageServiceFor31Impl implements IBomNew public static String buildDrawingNo(String drawingNo, String materialName, VirtualPackageTypeEnum type, boolean is1020Factory) { return StrUtil.format("({})({}{})({})", drawingNo, materialName, is1020Factory ? "仙桃" : "", type.getConMaterialName()); } + + private String getMaterialNoForAdd(BomNewEbomChildEntity c) { + AddVirtrualMaterialDTO ent = new AddVirtrualMaterialDTO(); + ent.setKey(c.getRowId().toString()); + ent.setDrawingNo(c.getDrawingNo()); + ent.setMaterialName(c.getMaterialName()); + ent.setMaterialDesc(c.getMaterialDesc()); + ent.setMaterialCategoryCode(c.getMaterialCategoryCode()); + Map vMNosResult = materialService.batchAddMaterial(Collections.singletonList(ent), userInfo); + return vMNosResult.get(c.getRowId().toString()).getMaterialNo(); + } } diff --git a/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/service/BomNewEbomParentService.java b/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/service/BomNewEbomParentService.java index 6bc5d50e..0f69d768 100644 --- a/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/service/BomNewEbomParentService.java +++ b/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/service/BomNewEbomParentService.java @@ -2383,12 +2383,24 @@ public class BomNewEbomParentService extends ServiceImpl getChildListForGenerateVirtualPackage(BomNewEbomParentEntity parent) { List children = ebomChildService.lambdaQuery() - .eq(BomNewEbomChildEntity::getVirtualPartRootMaterialNo, parent.getMaterialNo()) + .eq(BomNewEbomChildEntity::getInitialParentRowId, parent.getRowId()) .eq(BomNewEbomChildEntity::getVirtualPartType, VirtualPackageTypeEnum.UN_VIRTUAL_PACKAGE.getValue()) .ne(BomNewEbomChildEntity::getProjectType, BomConstant.PROJECT_TYPE_TEMPORARY) .orderByAsc(BomNewEbomChildEntity::getOrderNumber) .list(); if (CollUtil.isNotEmpty(children)) { + //是否有物料名称相同的物料 + StringBuilder sb = new StringBuilder(); + Map> gc = children.stream().collect(Collectors.groupingBy(BomNewEbomChildEntity::getMaterialName)); + gc.forEach((k, v) -> { + if (v.size() > 1) { + sb.append(StrUtil.format("{}的物料名称相同。", + StrUtil.join(",", v.stream().map(BomNewEbomChildEntity::getMaterialNo).collect(Collectors.toList())))); + } + }); + String err = sb.toString(); + VUtils.isTure(StrUtil.isNotBlank(err)).throwMessage("请先处理下面的错误:" + err); + List cvos = new ArrayList<>(); children.forEach(it -> { ChildListForGenerateVirtualPackageVO cvo = Convert.convert(ChildListForGenerateVirtualPackageVO.class, it); diff --git a/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/service/EBomImportService.java b/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/service/EBomImportService.java index 9fa7a53f..e134dddf 100644 --- a/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/service/EBomImportService.java +++ b/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/service/EBomImportService.java @@ -359,9 +359,7 @@ public class EBomImportService { child.setProjectType(data.getProjectType()); child.setProjectTypeInputType(ProjectTypeInputTypeEnum.MANUAL_INPUT.getValue()); child.setIdentityNo(child.getParentRowId() + "_" + child.getRowId()); - if (p.getMaterialNo().startsWith("31")) { - child.setVirtualPartRootMaterialNo(p.getMaterialNo()); - } + child.setInitialParentRowId(p.getRowId()); child.setEditStatus(EbomEditStatusEnum.HANDLER_CREATED.getValue()); child.setExceptionStatus(EBomExceptionStatusEnum.INIT.getValue()); child.setCreatedBy(SessionUtil.getUserCode()); diff --git a/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/service/MaterialService.java b/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/service/MaterialService.java index 79590791..bf0e0304 100644 --- a/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/service/MaterialService.java +++ b/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/service/MaterialService.java @@ -23,6 +23,7 @@ import com.nflg.product.bomnew.util.ListCommonUtil; import com.nflg.product.bomnew.util.VUtils; import lombok.extern.slf4j.Slf4j; import nflg.product.common.constant.STATE; +import nflg.product.common.dto.LoginUserInfoDTO; import nflg.product.common.vo.ResultVO; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Qualifier; @@ -168,7 +169,7 @@ public class MaterialService { @Transactional(rollbackFor = Exception.class) //****************************************本地生成,不调主数据************************************************** - public Map batchAddMaterial(List mds){ + public Map batchAddMaterial(List mds, LoginUserInfoDTO userInfo) { List resultList=new ArrayList<>(); List syncOaEnts=new ArrayList<>(); @@ -182,14 +183,14 @@ public class MaterialService { ma.setMaterialName(md.getMaterialName()); ma.setMaterialDesc(md.getMaterialDesc()); ma.setMaterialCategoryCode(md.getMaterialCategoryCode()); - ma.setCreatedBy(SessionUtil.getUserCode()); + ma.setCreatedBy(userInfo.getUserCode()); ma.setCreatedTime(LocalDateTime.now()); - ma.setUpdatedBy(SessionUtil.getUserCode()); + ma.setUpdatedBy(userInfo.getUserCode()); ma.setUpdatedTime(LocalDateTime.now()); ma.setMaterialClass(0); ma.setProcessState(0); - ma.setApplyUserCode(SessionUtil.getRealName()); - ma.setApplyDeptName(SessionUtil.getDepartName()); + ma.setApplyUserCode(userInfo.getRealName()); + ma.setApplyDeptName(userInfo.getDepartName()); ma.setMaterialUnit("PC"); ma.setProcessState(10); if(StrUtil.isNotBlank(md.getProjectType())){ @@ -213,6 +214,10 @@ public class MaterialService { return result; } + public Map batchAddMaterial(List mds) { + return batchAddMaterial(mds, SessionUtil.getUser()); + } + private void checkMaterial(List mds){ List noCateGoryCodes = mds.stream().filter(u -> StrUtil.isBlank(u.getMaterialCategoryCode())).collect(Collectors.toList()); VUtils.isTure(CollUtil.isNotEmpty(noCateGoryCodes)).throwMessage("最小物料类别不能为空"); @@ -281,7 +286,7 @@ public class MaterialService { * @param materialCategoryCode * @return */ - public String generateMaterialNo(String materialCategoryCode ,String preCategory) { + public synchronized String generateMaterialNo(String materialCategoryCode, String preCategory) { // String preCategory =materialMainService.getBaseMapper().getMaterialCategory(materialCategoryCode); if (StrUtil.isBlank(preCategory)) { throw new NflgBusinessException(STATE.ParamErr, materialCategoryCode.concat("未设置对应分类")); diff --git a/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/service/domain/EBom/EBomEdit.java b/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/service/domain/EBom/EBomEdit.java index 66bca524..56687122 100644 --- a/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/service/domain/EBom/EBomEdit.java +++ b/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/service/domain/EBom/EBomEdit.java @@ -228,9 +228,7 @@ public class EBomEdit { child.setNum(BigDecimal.ONE); } } - if (parentEntity.getMaterialNo().startsWith("31")) { - child.setVirtualPartRootMaterialNo(parentEntity.getMaterialNo()); - } + child.setInitialParentRowId(parentEntity.getRowId()); } diff --git a/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/service/domain/EBom/VirtualPackageBase.java b/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/service/domain/EBom/VirtualPackageBase.java index 0acdd001..d07df2ec 100644 --- a/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/service/domain/EBom/VirtualPackageBase.java +++ b/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/service/domain/EBom/VirtualPackageBase.java @@ -313,7 +313,7 @@ public abstract class VirtualPackageBase { childEntity.setProjectType("L"); childEntity.setMaterialUnit("PC"); childEntity.setProjectTypeInputType(ProjectTypeInputTypeEnum.AUTO_MATCH.getValue()); - childEntity.setVirtualPartRootMaterialNo(rootMaterialNo); + childEntity.setInitialParentRowId(parentRowId); this.childResult.add(childEntity); return childEntity; } diff --git a/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/service/domain/OriginalBom/OriginalBomToEBomV2Convert.java b/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/service/domain/OriginalBom/OriginalBomToEBomV2Convert.java index bf3332f8..fa6e7df7 100644 --- a/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/service/domain/OriginalBom/OriginalBomToEBomV2Convert.java +++ b/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/service/domain/OriginalBom/OriginalBomToEBomV2Convert.java @@ -428,9 +428,7 @@ public class OriginalBomToEBomV2Convert extends BaseConvert { // childEntity.setDrawingNo(childEntity.getMaterialNo()); // } childEntity.setMaterialOriginalUnit(childEntity.getMaterialUnit()); - if (parent.getMaterialNo().startsWith("31")) { - childEntity.setVirtualPartRootMaterialNo(parent.getMaterialNo()); - } + childEntity.setInitialParentRowId(parent.getEBomRowId()); this.eBomChildResult.add(childEntity);