feat(ebom): 修复31码生成虚拟包的问题

This commit is contained in:
曹鹏飞 2024-05-25 12:05:18 +08:00
parent 17ac4f6591
commit b4693fa64a
8 changed files with 215 additions and 128 deletions

View File

@ -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() {

View File

@ -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<BomNewEbomChildEntity> children = new ArrayList<>();
private final List<BomNewEbomParentEntity> parents = new ArrayList<>();
private final List<BomNewEbomChildEntity> childrenForAdd = Collections.synchronizedList(new ArrayList<>());
private final List<BomNewEbomChildEntity> childrenForUpdate = Collections.synchronizedList(new ArrayList<>());
private final List<BomNewEbomParentEntity> parentsForAdd = Collections.synchronizedList(new ArrayList<>());
private final List<BomNewEbomParentEntity> parentsForUpdate = Collections.synchronizedList(new ArrayList<>());
private final List<Long> childRowIdsForDel = new ArrayList<>();
private final List<OperationErrorMsgVO> errorMsgList = Collections.synchronizedList(new ArrayList<>());
private final Map<String, String> materialUpdateBill = new HashMap<>();
private final List<OperationErrorMsgVO> errorMsgList = new ArrayList<>();
private final static List<Long> DOING_ROWID = Collections.synchronizedList(new ArrayList<>());
private final LoginUserInfoDTO userInfo = SessionUtil.getUser();
@Override
public List<OperationErrorMsgVO> 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<ChildListForGenerateVirtualPackageVO> 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<ChildListForGenerateVirtualPackageVO> olds = ebomParentService.getChildListForGenerateVirtualPackage(root);
List<CompletableFuture<Void>> futures = new ArrayList<>();
query.getChildren().forEach(it -> {
CompletableFuture<Void> 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<Void> combinedFuture = CompletableFuture.allOf(futures.toArray(new CompletableFuture[0]));
combinedFuture.join();
// List<AddVirtrualMaterialDTO> 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<String, AddVirtrualMaterialDTO> 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<AddVirtrualMaterialDTO> 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<String, AddVirtrualMaterialDTO> 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<MaterialMainVO> 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<Boolean> result1 = materialMainClient.addMaterialUpdateBillEntity(dto);
if (result1.getState() != 200) {
errorMsgList.add(OperationErrorMsgVO.create(materialNo, result1.getMsg()));
try {
ResultVO<MaterialMainVO> 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<Boolean> 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<String, AddVirtrualMaterialDTO> vMNosResult = materialService.batchAddMaterial(Collections.singletonList(ent), userInfo);
return vMNosResult.get(c.getRowId().toString()).getMaterialNo();
}
}

View File

@ -2383,12 +2383,24 @@ public class BomNewEbomParentService extends ServiceImpl<BomNewEbomParentMapper,
public List<ChildListForGenerateVirtualPackageVO> getChildListForGenerateVirtualPackage(BomNewEbomParentEntity parent) {
List<BomNewEbomChildEntity> 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<String, List<BomNewEbomChildEntity>> 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<ChildListForGenerateVirtualPackageVO> cvos = new ArrayList<>();
children.forEach(it -> {
ChildListForGenerateVirtualPackageVO cvo = Convert.convert(ChildListForGenerateVirtualPackageVO.class, it);

View File

@ -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());

View File

@ -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<String,AddVirtrualMaterialDTO> batchAddMaterial(List<AddVirtrualMaterialDTO> mds){
public Map<String, AddVirtrualMaterialDTO> batchAddMaterial(List<AddVirtrualMaterialDTO> mds, LoginUserInfoDTO userInfo) {
List<MaterialMainEntity> resultList=new ArrayList<>();
List<AddMaterialMainDTO> 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<String, AddVirtrualMaterialDTO> batchAddMaterial(List<AddVirtrualMaterialDTO> mds) {
return batchAddMaterial(mds, SessionUtil.getUser());
}
private void checkMaterial(List<AddVirtrualMaterialDTO> mds){
List<AddVirtrualMaterialDTO> 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("未设置对应分类"));

View File

@ -228,9 +228,7 @@ public class EBomEdit {
child.setNum(BigDecimal.ONE);
}
}
if (parentEntity.getMaterialNo().startsWith("31")) {
child.setVirtualPartRootMaterialNo(parentEntity.getMaterialNo());
}
child.setInitialParentRowId(parentEntity.getRowId());
}

View File

@ -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;
}

View File

@ -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);