Merge branch 'feature/DM/nflg-bom' of http://112.74.186.154:3000/nflj/nflg_project into feature/DM/nflg-bom

This commit is contained in:
jing's 2024-01-26 15:50:47 +08:00
commit 2530f56254
9 changed files with 427 additions and 263 deletions

View File

@ -133,6 +133,12 @@ public class PBomApi extends BaseApi {
bomNewPbomParentService.editExport(bomRowId,response);
}
@PostMapping("editExportV2")
@ApiOperation("编辑-导出Excel(可选中导出)")
public void editExportV2(@RequestBody PBomEditExportParamDTO param, HttpServletResponse response) throws IOException {
bomNewPbomParentService.editExportV2(param,response);
}
@PostMapping("insertTechnologyPackage")
@ApiOperation("编辑-插入工艺包")

View File

@ -0,0 +1,21 @@
package com.nflg.product.bomnew.pojo.dto;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.List;
/**
* pbom 可选择导出
*/
@Data
public class PBomEditExportParamDTO {
@ApiModelProperty("bom版本行ID")
private Long bomRowId;
@ApiModelProperty("需导出的行ID列表")
private List<Long> rowIds;
}

View File

@ -377,6 +377,18 @@ public class BomNewPbomParentService extends ServiceImpl<BomNewPbomParentMapper,
}
public void editExportV2(PBomEditExportParamDTO param, HttpServletResponse response) throws IOException {
EecExcelUtil.setResponseExcelHeader(response, "bom明细列表");
List<BomNewPbomParentVO> child = this.getChild(param.getBomRowId());
if(CollUtil.isNotEmpty(param.getRowIds())){
child=child.stream().filter(u->param.getRowIds().contains(u.getRowId())).collect(Collectors.toList());
}
List<BomNewPbomEditExcelVO> result = Convert.toList(BomNewPbomEditExcelVO.class, child);
new Workbook().addSheet(result).writeTo(response.getOutputStream());
}
/**
* 创建工艺包
@ -749,12 +761,12 @@ public class BomNewPbomParentService extends ServiceImpl<BomNewPbomParentMapper,
List<String> noProductionFactoryCodeList = allChild.stream().filter(u -> StrUtil.isBlank(u.getProductionFactoryCode())).map(u -> u.getMaterialNo()).collect(Collectors.toList());
VUtils.isTure(CollUtil.isNotEmpty(noProductionFactoryCodeList)).throwMessage(StrUtil.join(",", noProductionFactoryCodeList) + "物料暂未分工厂,请分完工厂再进行发布");
ConvertToMBom convertToMBom = new ConvertToMBom(rootParent, allChild);
convertToMBom.convertToMBom(true, true);
convertToMBom.convertToMBomNew(true, true);
if (CollUtil.isNotEmpty(convertToMBom.getMBomParentResult())) {
mBomParentService.saveOrUpdateBatch(convertToMBom.getMBomParentResult());
}
if (CollUtil.isNotEmpty(convertToMBom.getMBomDetailResult())) {
mBomDetailService.saveOrUpdateBatch(convertToMBom.getMBomDetailResult());
mBomDetailService.saveBatch(convertToMBom.getMBomDetailResult());
}
//将PBOM改为已发布
List<Long> bomRowIds = allChild.stream().filter(u -> u.getBomRowId() > 0).map(u -> u.getBomRowId()).collect(Collectors.toList());
@ -795,7 +807,7 @@ public class BomNewPbomParentService extends ServiceImpl<BomNewPbomParentMapper,
List<String> noProductionFactoryCodeList = allChild.stream().filter(u -> StrUtil.isBlank(u.getProductionFactoryCode())).map(u -> u.getMaterialNo()).collect(Collectors.toList());
VUtils.isTure(CollUtil.isNotEmpty(noProductionFactoryCodeList)).throwMessage(StrUtil.join(",", noProductionFactoryCodeList) + "物料暂未分工厂,请分完工厂再进行发布");
ConvertToMBom convertToMBom = new ConvertToMBom(rootParent, allChild);
convertToMBom.convertToMBom(false, true);
convertToMBom.convertToMBomNew(false, true);
if (CollUtil.isNotEmpty(convertToMBom.getMBomParentResult())) {
mBomParentService.saveOrUpdateBatch(convertToMBom.getMBomParentResult());
}

View File

@ -185,6 +185,7 @@ public class MaterialService {
ma.setMaterialClass(0);
ma.setProcessState(0);
ma.setApplyUserCode(SessionUtil.getRealName());
ma.setApplyDeptName(SessionUtil.getDepartName());
ma.setMaterialUnit("PC");
ma.setProcessState(10);
if(StrUtil.isNotBlank(md.getProjectType())){

View File

@ -48,9 +48,7 @@ public class ConvertToMBom {
private List<ConvertToMBomDTO> allChild_1010;
private List<ConvertToMBomDTO> allChildTreeList_1020 = new ArrayList<>();
private List<ConvertToMBomDTO> allChildTreeList_1010 = new ArrayList();
@Getter
List<BomNewMbomParentEntity> mBomParentResult = new ArrayList<>();
@ -59,277 +57,33 @@ public class ConvertToMBom {
List<BomNewMbomDetailEntity> mBomDetailResult = new ArrayList<>();
public ConvertToMBom(BomNewPbomParentEntity inRootParent, List<BomNewPbomParentVO> inAllChild) {
this.parent = inRootParent;
this.allChild_1010 = Convert.toList(ConvertToMBomDTO.class, inAllChild);
allChild_1020 = (List<ConvertToMBomDTO>) ((ArrayList<ConvertToMBomDTO>) allChild_1010).clone();
}
/**
* 转换MBom
*/
public void convertToMBom(Boolean convert1010 ,Boolean convert1020) {
//handler1010();
if(convert1020) {
handler1020();
buildMBom(EBomConstant.XIAN_TAO_FACTORY_CODE_1020);
public void convertToMBomNew(Boolean g1010, Boolean g1020){
if(g1010){
ConvertToMBom1010 convertToMBom1010 =new ConvertToMBom1010(parent, allChild_1010);
convertToMBom1010.convertMBom();
this.mBomParentResult.addAll(convertToMBom1010.mBomParentResult);
this.mBomDetailResult.addAll(convertToMBom1010.mBomDetailResult);
}
if(convert1010) {
buildMBom(EBomConstant.MAIN_FACTORY_CODE_1010);
if(g1020){
ConvertToMBom1020 convertToMBom1020 = new ConvertToMBom1020(parent, allChild_1020);
convertToMBom1020.convertMBom();
this.mBomParentResult.addAll(convertToMBom1020.getMBomParentResult());
this.mBomDetailResult.addAll(convertToMBom1020.getMBomDetailResult());
}
}
/**
* 构建MBom明细
*
* @param
*/
private void buildMBom(String facCode) {
BomNewMbomParentEntity mBomParent = new BomNewMbomParentEntity();
BeanUtil.copyProperties(parent, mBomParent);
BomNewMbomParentEntity oldParent = SpringUtil.getBean(BomNewMbomParentService.class).lambdaQuery().eq(BomNewMbomParentEntity::getMaterialNo, parent.getMaterialNo())
.eq(BomNewMbomParentEntity::getLastVersionIs, 1).eq(BomNewMbomParentEntity::getFacCode, facCode).one();
if (Objects.nonNull(oldParent)) {
if(MBomConstantEnum.MBomStatusEnum.PUB_SAP.equalsValue(oldParent.getStatus()) ) {
mBomParent.setCurrentVersion(VersionUtil.getNextVersion(oldParent.getCurrentVersion()));
oldParent.setLastVersionIs(0);
this.mBomParentResult.add(oldParent);
}
else {
SpringUtil.getBean(BomNewMbomDetailService.class).getBaseMapper().deleteByMap(ImmutableMap.of("bom_row_id", oldParent.getRowId()));
SpringUtil.getBean(BomNewMbomParentService.class).getBaseMapper().deleteById(oldParent.getRowId());
mBomParent.setCurrentVersion(oldParent.getCurrentVersion());
}
} else {
mBomParent.setCurrentVersion(VersionUtil.getNextVersion(""));
}
mBomParent.setRowId(IdWorker.getId());
mBomParent.setFacCode(facCode);
mBomParent.setCreatedBy(SessionUtil.getUserCode());
mBomParent.setCreatedTime(LocalDateTime.now());
mBomParent.setModifyTime(LocalDateTime.now());
mBomParent.setSourceRowId(parent.getRowId());
mBomParent.setLastVersionIs(1);
mBomParent.setStatus(MBomConstantEnum.MBomStatusEnum.UNPUB_SAP.getValue());
//当10120 bom 内容为空时不创建31 的Mbom
if(EBomConstant.XIAN_TAO_FACTORY_CODE_1020.equals(facCode) ){
List<ConvertToMBomDTO> bomContent1020 = allChildTreeList_1020.stream().filter(u -> u.getDelIs().equals(0) && u.getVirtualPartType().equals(0)).collect(Collectors.toList());
if(CollUtil.isEmpty(bomContent1020)){
return;
}
}
this.mBomParentResult.add(mBomParent);
//1010 不做处理
// buildChild(EBomConstant.MAIN_FACTORY_CODE_1010.equals(facCode) ? allChildTreeList_1010 : allChildTreeList_1020, mBomParent.getRowId());
allChild_1010.forEach(u->{
u.setRelParentRowId(u.getParentRowId());
});
buildChild(facCode, EBomConstant.MAIN_FACTORY_CODE_1010.equals(facCode) ? allChild_1010 : allChildTreeList_1020, mBomParent.getRowId());
}
/**
* 构建子级
*
* @param allChild
*/
private void buildChild(String facCode, List<ConvertToMBomDTO> allChild, Long bomRowId) {
List<ConvertToMBomDTO> childBomTree = ConvertToMbomUtil.toTree(parent.getRowId(), allChild, ConvertToMBomDTO::getRelParentRowId, ConvertToMBomDTO::getBomRowId);
; for (ConvertToMBomDTO item : childBomTree) {
//构建子级
if (item.getDelIs().equals(0)) {
buildMBomChildDo(facCode, item, 0L,bomRowId);
}
}
}
private void buildMBomChildDo(String facCode , ConvertToMBomDTO item , Long parentRowId ,Long bomRowId){
if (item.getDelIs().equals(0)) {
parentRowId = buildChildDo(facCode,item, bomRowId, parentRowId);
}
for (ConvertToMBomDTO itemChild : item.getChildNodes()) {
buildMBomChildDo(facCode, itemChild, parentRowId,bomRowId);
}
}
/**
* 处理制作下为空的虚拟包
* 当制作下子级为空时--删除该发货制作和直发
*
* @param
*/
private void handEmptyMakePackage(List<ConvertToMBomDTO> childBomTree) {
// List<ConvertToMBomDTO> childBomTree = ConvertToMbomUtil.toTree(parent.getRowId(), allChildTreeList_1020, ConvertToMBomDTO::getRelParentRowId, ConvertToMBomDTO::getBomRowId);
for (ConvertToMBomDTO item : childBomTree) {
if (VirtualPackageTypeEnum.DELIVERY_PACKAGE.equalsValue(item.getVirtualPartType())) {
List<ConvertToMBomDTO> makeChild = item.getChildNodes().stream().filter(u -> VirtualPackageTypeEnum.MAKING_PACKAGE.equalsValue(u.getVirtualPartType())).collect(Collectors.toList());
if (CollUtil.isEmpty(makeChild) || CollUtil.isEmpty(makeChild.get(0).getChildNodes().stream().filter(u -> u.getDelIs().equals(0)).collect(Collectors.toList()))) {
item.setRelParentRowId(0L);
}
}
}
}
private Long buildChildDo(String facCode, ConvertToMBomDTO dto, Long bomRowId, Long parentRowId) {
BomNewMbomDetailEntity child = new BomNewMbomDetailEntity();
BeanUtil.copyProperties(dto, child);
child.setRowId(IdWorker.getId());
child.setBomRowId(bomRowId);
// child.setFacCode(dto.getProductionFactoryCode());
child.setFacCode(facCode);
child.setParentRowId(parentRowId);
child.setCreatedBy(SessionUtil.getUserCode());
child.setCreatedTime(LocalDateTime.now());
child.setModifyTime(LocalDateTime.now());
child.setSourceRowId(dto.getRowId());
this.mBomDetailResult.add(child);
return child.getRowId();
}
private void handler1010() {
List<ConvertToMBomDTO> childBomTree = ConvertToMbomUtil.toTree(parent.getRowId(), allChild_1010, ConvertToMBomDTO::getParentRowId, ConvertToMBomDTO::getBomRowId);
for (ConvertToMBomDTO item : childBomTree) {
//默认
recursionHandlerChild1010(item);
}
}
private void recursionHandlerChild1010(ConvertToMBomDTO item) {
item.setRelParentRowId(item.getParentRowId());
setDel(item, EBomConstant.MAIN_FACTORY_CODE_1010);
handlerMaterial(item, EBomConstant.MAIN_FACTORY_CODE_1010);
this.allChildTreeList_1010.add(item);
for (ConvertToMBomDTO itemChild : item.getChildNodes()) {
recursionHandlerChild1010(itemChild);
}
}
private void handler1020() {
List<ConvertToMBomDTO> childBomTree = ConvertToMbomUtil.toTree(parent.getRowId(), allChild_1020, ConvertToMBomDTO::getParentRowId, ConvertToMBomDTO::getBomRowId);
//虚拟包名称加仙桃
initFac1020Info(childBomTree);
for (ConvertToMBomDTO item : childBomTree) {
ConvertToMBomDTO directDeliveryPackage = item.getChildNodes().stream().filter(u -> VirtualPackageTypeEnum.DIRECT_DELIVERY_PACKAGE.equalsValue(u.getVirtualPartType())).collect(Collectors.toList()).get(0);
VUtils.isTure(Objects.isNull(directDeliveryPackage)).throwMessage("发货包下,没有直发包");
recursionHandlerChild1020(item, directDeliveryPackage);
}
//处理制作包无下级的情况
handEmptyMakePackage(childBomTree);
}
private void recursionHandlerChild1020(ConvertToMBomDTO item, ConvertToMBomDTO directDeliveryPackage) {
item.setRelParentRowId(item.getParentRowId());
setDel(item, EBomConstant.XIAN_TAO_FACTORY_CODE_1020);
//非31下的直发包
if(!item.getParentRowId().equals(parent.getRowId())) {
ConvertToMBomDTO parentNode = getParent(item.getParentRowId(), EBomConstant.XIAN_TAO_FACTORY_CODE_1020);
if (VirtualPackageTypeEnum.DIRECT_DELIVERY_PACKAGE.equalsValue(parentNode.getVirtualPartType()) && parentNode.getRowId() != directDeliveryPackage.getRowId()) {
handlerDirectDeliveryPackage(item, EBomConstant.XIAN_TAO_FACTORY_CODE_1020, directDeliveryPackage);
} else {
handlerMaterial(item, EBomConstant.XIAN_TAO_FACTORY_CODE_1020);
}
}
this.allChildTreeList_1020.add(item);
for (ConvertToMBomDTO itemChild : item.getChildNodes()) {
recursionHandlerChild1020(itemChild, directDeliveryPackage);
}
}
/**
* 处理直发包下的物料
* 所有直发包归到31下的直发包
*/
private void handlerDirectDeliveryPackage(ConvertToMBomDTO childItem, String facCode, ConvertToMBomDTO directDeliveryPackage) {
if (!childItem.getParentRowId().equals(parent.getRowId())) {
ConvertToMBomDTO relParent = getParent(childItem.getParentRowId(), facCode);
while (Objects.nonNull(relParent) && !VirtualPackageTypeEnum.MAKING_PACKAGE.equalsValue(relParent.getVirtualPartType())) {
childItem.setNum(NumberUtil.mul(childItem.getNum(), relParent.getNum()));
relParent = getParent(relParent.getParentRowId(), facCode);
}
childItem.setRelParentRowId(directDeliveryPackage.getBomRowId());
}
}
/**
* 处理一般材料(提层)
*
* @param childItem
* @param facCode
*/
private void handlerMaterial(ConvertToMBomDTO childItem, String facCode) {
if (!childItem.getParentRowId().equals(parent.getRowId())) {
ConvertToMBomDTO relParent = getParent(childItem.getParentRowId(), facCode);
while (Objects.nonNull(relParent) && relParent.getDelIs().equals(1)) {
childItem.setNum(NumberUtil.mul(childItem.getNum(), relParent.getNum()));
relParent = getParent(relParent.getParentRowId(), facCode);
}
childItem.setRelParentRowId(relParent.getBomRowId());
}
}
private void setDel(ConvertToMBomDTO item, String facCode) {
if (!item.getProductionFactoryCode().equals(facCode)) {
item.setDelIs(1);
}
}
//获取父节点
private ConvertToMBomDTO getParent(Long parentRowId, String facCode) {
if (parentRowId <= 0) return null;
List<ConvertToMBomDTO> data = EBomConstant.MAIN_FACTORY_CODE_1010.equals(facCode) ? allChild_1010 : allChild_1020;
return data.stream().filter(u -> parentRowId.equals(u.getBomRowId())).collect(Collectors.toList()).get(0);
}
/**
* 1020-名称加仙桃
*/
private void initFac1020Info(List<ConvertToMBomDTO> childBomTree) {
for (ConvertToMBomDTO item : childBomTree) {
item.setMaterialName(item.getMaterialName() + EBomConstant.XIAN_TAO_FACTORY_Name_1020);
item.setProductionFactoryCode(EBomConstant.XIAN_TAO_FACTORY_CODE_1020);
item.setProductionFactoryCode(EBomConstant.XIAN_TAO_FACTORY_CODE_1020);
item.setProductionFactoryCodeInputType(ProductionFactoryCodeInputTypeEnum.DEFAULT.getValue());
for (ConvertToMBomDTO itemChild : item.getChildNodes()) {
itemChild.setMaterialName(item.getMaterialName() + EBomConstant.XIAN_TAO_FACTORY_Name_1020);
itemChild.setProductionFactoryCode(EBomConstant.XIAN_TAO_FACTORY_CODE_1020);
itemChild.setProductionFactoryCode(EBomConstant.XIAN_TAO_FACTORY_CODE_1020);
itemChild.setProductionFactoryCodeInputType(ProductionFactoryCodeInputTypeEnum.DEFAULT.getValue());
}
}
}
}

View File

@ -0,0 +1,62 @@
package com.nflg.product.bomnew.service.domain.PBom;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.convert.Convert;
import cn.hutool.extra.spring.SpringUtil;
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.google.common.collect.ImmutableMap;
import com.nflg.product.base.core.conmon.util.SessionUtil;
import com.nflg.product.bomnew.constant.EBomConstant;
import com.nflg.product.bomnew.constant.MBomConstantEnum;
import com.nflg.product.bomnew.pojo.entity.BomNewMbomDetailEntity;
import com.nflg.product.bomnew.pojo.entity.BomNewMbomParentEntity;
import com.nflg.product.bomnew.pojo.entity.BomNewPbomParentEntity;
import com.nflg.product.bomnew.pojo.vo.BomNewPbomParentVO;
import com.nflg.product.bomnew.service.BomNewMbomDetailService;
import com.nflg.product.bomnew.service.BomNewMbomParentService;
import com.nflg.product.bomnew.util.VersionUtil;
import lombok.Getter;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
public class ConvertToMBom1010 extends ConvertToMBomBase {
public ConvertToMBom1010(BomNewPbomParentEntity inRootParent, List<ConvertToMBomDTO> inAllChild){
this.parent = inRootParent;
this.allChild = inAllChild;
}
public void convertMBom() {
BomNewMbomParentEntity mBomParent = buildMBomParent(EBomConstant.MAIN_FACTORY_CODE_1010);
this.mBomParentResult.add(mBomParent);
allChild.forEach(u -> {
u.setRelParentRowId(u.getParentRowId());
u.setDelIs(0);
});
buildChild(EBomConstant.MAIN_FACTORY_CODE_1010, allChild, mBomParent.getRowId());
}
private void buildChild(String facCode, List<ConvertToMBomDTO> allChild, Long bomRowId) {
List<ConvertToMBomDTO> childBomTree = ConvertToMbomUtil.toTree(parent.getRowId(), allChild, ConvertToMBomDTO::getRelParentRowId, ConvertToMBomDTO::getBomRowId);
for (ConvertToMBomDTO item : childBomTree) {
buildMBomChildDo(facCode, item, 0L, bomRowId);
}
}
}

View File

@ -0,0 +1,181 @@
package com.nflg.product.bomnew.service.domain.PBom;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.convert.Convert;
import cn.hutool.core.util.NumberUtil;
import com.nflg.product.bomnew.constant.EBomConstant;
import com.nflg.product.bomnew.constant.ProductionFactoryCodeInputTypeEnum;
import com.nflg.product.bomnew.constant.VirtualPackageTypeEnum;
import com.nflg.product.bomnew.pojo.entity.BomNewMbomParentEntity;
import com.nflg.product.bomnew.pojo.entity.BomNewPbomParentEntity;
import com.nflg.product.bomnew.pojo.vo.BomNewPbomParentVO;
import com.nflg.product.bomnew.util.VUtils;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
public class ConvertToMBom1020 extends ConvertToMBomBase{
private List<ConvertToMBomDTO> allChildTreeList_1020 = new ArrayList<>();
public ConvertToMBom1020(BomNewPbomParentEntity inRootParent, List<ConvertToMBomDTO> inAllChild){
this.parent = inRootParent;
this.allChild = inAllChild;
initFacAllChild();
}
private void initFacAllChild() {
List<ConvertToMBomDTO> firstLevelNodes = allChild.stream().filter(u -> u.getParentRowId().equals(parent.getRowId())).collect(Collectors.toList());
for (ConvertToMBomDTO firstLevelNode : firstLevelNodes) {
firstLevelNode.setProductionFactoryCode(EBomConstant.XIAN_TAO_FACTORY_CODE_1020);
List<ConvertToMBomDTO> firstChildNodes = allChild.stream().filter(u -> u.getParentRowId().equals(firstLevelNode.getBomRowId())).collect(Collectors.toList());
for (ConvertToMBomDTO itemChild : firstChildNodes) {
itemChild.setProductionFactoryCode(EBomConstant.XIAN_TAO_FACTORY_CODE_1020);
}
}
allChild.forEach(k -> {
setDel(k, EBomConstant.XIAN_TAO_FACTORY_CODE_1020);
});
}
public void convertMBom(){
handlerBom();
buildMBom();
}
private void buildMBom() {
BomNewMbomParentEntity mBomParent = buildMBomParent(EBomConstant.XIAN_TAO_FACTORY_CODE_1020);
//当10120 bom 内容为空时不创建31 的Mbom
List<ConvertToMBomDTO> bomContent1020 = allChildTreeList_1020.stream().filter(u -> u.getDelIs().equals(0) && u.getVirtualPartType().equals(0)).collect(Collectors.toList());
if (CollUtil.isEmpty(bomContent1020)) {
return;
}
this.mBomParentResult.add(mBomParent);
List<ConvertToMBomDTO> nodes1020 = allChildTreeList_1020.stream().filter(u -> u.getDelIs().equals(0)).collect(Collectors.toList());
buildChildFor(EBomConstant.XIAN_TAO_FACTORY_CODE_1020, nodes1020, mBomParent.getRowId());
}
private void handlerBom() {
List<ConvertToMBomDTO> childBomTree = ConvertToMbomUtil.toTree(parent.getRowId(), allChild, ConvertToMBomDTO::getParentRowId, ConvertToMBomDTO::getBomRowId);
//虚拟包名称加仙桃
initFac1020Info(childBomTree);
for (ConvertToMBomDTO item : childBomTree) {
ConvertToMBomDTO directDeliveryPackage = item.getChildNodes().stream().filter(u -> VirtualPackageTypeEnum.DIRECT_DELIVERY_PACKAGE.equalsValue(u.getVirtualPartType())).collect(Collectors.toList()).get(0);
VUtils.isTure(Objects.isNull(directDeliveryPackage)).throwMessage("发货包下,没有直发包");
recursionHandlerChild1020(item, directDeliveryPackage);
}
//处理制作包无下级的情况
handEmptyMakePackage(childBomTree);
}
private void recursionHandlerChild1020(ConvertToMBomDTO item, ConvertToMBomDTO directDeliveryPackage) {
item.setRelParentRowId(item.getParentRowId());
setDel(item, EBomConstant.XIAN_TAO_FACTORY_CODE_1020);
//非31下的直发包
if (!item.getParentRowId().equals(parent.getRowId())) {
ConvertToMBomDTO parentNode = getParent(item.getParentRowId(), EBomConstant.XIAN_TAO_FACTORY_CODE_1020);
if (VirtualPackageTypeEnum.DIRECT_DELIVERY_PACKAGE.equalsValue(parentNode.getVirtualPartType()) && parentNode.getRowId() != directDeliveryPackage.getRowId()) {
handlerDirectDeliveryPackage(item, EBomConstant.XIAN_TAO_FACTORY_CODE_1020, directDeliveryPackage);
} else {
handlerMaterial(item, EBomConstant.XIAN_TAO_FACTORY_CODE_1020);
}
}
this.allChildTreeList_1020.add(item);
for (ConvertToMBomDTO itemChild : item.getChildNodes()) {
recursionHandlerChild1020(itemChild, directDeliveryPackage);
}
}
/**
* 处理直发包下的物料
* 所有直发包归到31下的直发包
*/
private void handlerDirectDeliveryPackage(ConvertToMBomDTO childItem, String facCode, ConvertToMBomDTO directDeliveryPackage) {
if (!childItem.getParentRowId().equals(parent.getRowId())) {
ConvertToMBomDTO relParent = getParent(childItem.getParentRowId(), facCode);
while (Objects.nonNull(relParent) && !VirtualPackageTypeEnum.MAKING_PACKAGE.equalsValue(relParent.getVirtualPartType())) {
childItem.setNum(NumberUtil.mul(childItem.getNum(), relParent.getNum()));
relParent = getParent(relParent.getParentRowId(), facCode);
}
childItem.setRelParentRowId(directDeliveryPackage.getBomRowId());
}
}
private void initFac1020Info(List<ConvertToMBomDTO> childBomTree) {
for (ConvertToMBomDTO item : childBomTree) {
item.setMaterialName(item.getMaterialName() + EBomConstant.XIAN_TAO_FACTORY_Name_1020);
item.setProductionFactoryCode(EBomConstant.XIAN_TAO_FACTORY_CODE_1020);
item.setProductionFactoryCodeInputType(ProductionFactoryCodeInputTypeEnum.DEFAULT.getValue());
for (ConvertToMBomDTO itemChild : item.getChildNodes()) {
itemChild.setMaterialName(itemChild.getMaterialName() + EBomConstant.XIAN_TAO_FACTORY_Name_1020);
itemChild.setProductionFactoryCode(EBomConstant.XIAN_TAO_FACTORY_CODE_1020);
itemChild.setProductionFactoryCodeInputType(ProductionFactoryCodeInputTypeEnum.DEFAULT.getValue());
}
}
}
/**
* 处理一般材料(提层)
*
* @param childItem
* @param facCode
*/
private void handlerMaterial(ConvertToMBomDTO childItem, String facCode) {
if (!childItem.getParentRowId().equals(parent.getRowId())) {
ConvertToMBomDTO relParent = getParent(childItem.getParentRowId(), facCode);
while (Objects.nonNull(relParent) && relParent.getDelIs().equals(1)) {
childItem.setNum(NumberUtil.mul(childItem.getNum(), relParent.getNum()));
relParent = getParent(relParent.getParentRowId(), facCode);
}
childItem.setRelParentRowId(relParent.getBomRowId());
}
}
/**
* 处理制作下为空的虚拟包
* 当制作下子级为空时--删除该发货制作和直发
*
* @param
*/
private void handEmptyMakePackage(List<ConvertToMBomDTO> childBomTree) {
// List<ConvertToMBomDTO> childBomTree = ConvertToMbomUtil.toTree(parent.getRowId(), allChildTreeList_1020, ConvertToMBomDTO::getRelParentRowId, ConvertToMBomDTO::getBomRowId);
for (ConvertToMBomDTO item : childBomTree) {
if (VirtualPackageTypeEnum.DELIVERY_PACKAGE.equalsValue(item.getVirtualPartType())) {
List<ConvertToMBomDTO> makeChild = item.getChildNodes().stream().filter(u -> VirtualPackageTypeEnum.MAKING_PACKAGE.equalsValue(u.getVirtualPartType())).collect(Collectors.toList());
List<ConvertToMBomDTO> zhifaChild = item.getChildNodes().stream().filter(u -> VirtualPackageTypeEnum.DIRECT_DELIVERY_PACKAGE.equalsValue(u.getVirtualPartType())).collect(Collectors.toList());
if ((CollUtil.isEmpty(makeChild) || CollUtil.isEmpty(makeChild.get(0).getChildNodes().stream().filter(u -> u.getDelIs().equals(0)).collect(Collectors.toList()))) &&
(CollUtil.isEmpty(zhifaChild) || CollUtil.isEmpty(zhifaChild.get(0).getChildNodes().stream().filter(u -> u.getDelIs().equals(0)).collect(Collectors.toList())))) {
item.setRelParentRowId(-1L);
}
}
}
}
}

View File

@ -0,0 +1,125 @@
package com.nflg.product.bomnew.service.domain.PBom;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.extra.spring.SpringUtil;
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.google.common.collect.ImmutableMap;
import com.nflg.product.base.core.conmon.util.SessionUtil;
import com.nflg.product.bomnew.constant.EBomConstant;
import com.nflg.product.bomnew.constant.MBomConstantEnum;
import com.nflg.product.bomnew.pojo.entity.BomNewMbomDetailEntity;
import com.nflg.product.bomnew.pojo.entity.BomNewMbomParentEntity;
import com.nflg.product.bomnew.pojo.entity.BomNewPbomParentEntity;
import com.nflg.product.bomnew.service.BomNewMbomDetailService;
import com.nflg.product.bomnew.service.BomNewMbomParentService;
import com.nflg.product.bomnew.util.VersionUtil;
import lombok.Getter;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
public class ConvertToMBomBase {
protected BomNewPbomParentEntity parent;
protected List<ConvertToMBomDTO> allChild;
@Getter
protected List<BomNewMbomParentEntity> mBomParentResult = new ArrayList<>();
@Getter
protected List<BomNewMbomDetailEntity> mBomDetailResult = new ArrayList<>();
protected void buildChildFor(String facCode, List<ConvertToMBomDTO> allChild, Long bomRowId) {
List<ConvertToMBomDTO> childBomTree = ConvertToMbomUtil.toTree(parent.getRowId(), allChild, ConvertToMBomDTO::getRelParentRowId, ConvertToMBomDTO::getBomRowId);
for (ConvertToMBomDTO item : childBomTree) {
buildMBomChildDo(facCode, item, 0L, bomRowId);
}
}
protected void buildMBomChildDo(String facCode, ConvertToMBomDTO item, Long parentRowId, Long bomRowId) {
if (item.getDelIs().equals(0)) {
parentRowId = buildChildDo(facCode, item, bomRowId, parentRowId);
}
for (ConvertToMBomDTO itemChild : item.getChildNodes()) {
buildMBomChildDo(facCode, itemChild, parentRowId, bomRowId);
}
}
protected Long buildChildDo(String facCode, ConvertToMBomDTO dto, Long bomRowId, Long parentRowId) {
BomNewMbomDetailEntity child = new BomNewMbomDetailEntity();
BeanUtil.copyProperties(dto, child);
child.setRowId(IdWorker.getId());
child.setBomRowId(bomRowId);
// child.setFacCode(dto.getProductionFactoryCode());
child.setFacCode(facCode);
child.setParentRowId(parentRowId);
child.setCreatedBy(SessionUtil.getUserCode());
child.setCreatedTime(LocalDateTime.now());
child.setModifyTime(LocalDateTime.now());
child.setSourceRowId(dto.getRowId());
this.mBomDetailResult.add(child);
return child.getRowId();
}
protected BomNewMbomParentEntity buildMBomParent(String facCode) {
BomNewMbomParentEntity mBomParent = new BomNewMbomParentEntity();
BeanUtil.copyProperties(parent, mBomParent);
BomNewMbomParentEntity oldParent = SpringUtil.getBean(BomNewMbomParentService.class).lambdaQuery().eq(BomNewMbomParentEntity::getMaterialNo, parent.getMaterialNo())
.eq(BomNewMbomParentEntity::getLastVersionIs, 1).eq(BomNewMbomParentEntity::getFacCode, facCode).one();
if (Objects.nonNull(oldParent)) {
if (MBomConstantEnum.MBomStatusEnum.PUB_SAP.equalsValue(oldParent.getStatus())) {
mBomParent.setCurrentVersion(VersionUtil.getNextVersion(oldParent.getCurrentVersion()));
oldParent.setLastVersionIs(0);
this.mBomParentResult.add(oldParent);
} else {
SpringUtil.getBean(BomNewMbomDetailService.class).getBaseMapper().deleteByMap(ImmutableMap.of("bom_row_id", oldParent.getRowId()));
SpringUtil.getBean(BomNewMbomParentService.class).getBaseMapper().deleteById(oldParent.getRowId());
mBomParent.setCurrentVersion(oldParent.getCurrentVersion());
}
} else {
mBomParent.setCurrentVersion(VersionUtil.getNextVersion(""));
}
mBomParent.setRowId(IdWorker.getId());
mBomParent.setFacCode(facCode);
mBomParent.setCreatedBy(SessionUtil.getUserCode());
mBomParent.setCreatedTime(LocalDateTime.now());
mBomParent.setModifyTime(LocalDateTime.now());
mBomParent.setSourceRowId(parent.getRowId());
mBomParent.setLastVersionIs(1);
mBomParent.setStatus(MBomConstantEnum.MBomStatusEnum.UNPUB_SAP.getValue());
return mBomParent;
}
protected void setDel(ConvertToMBomDTO item, String facCode) {
if (!item.getProductionFactoryCode().equals(facCode)) {
item.setDelIs(1);
}
}
/**
* 获取父级
*
* @param parentRowId
* @param facCode
* @return
*/
protected ConvertToMBomDTO getParent(Long parentRowId, String facCode) {
if (parentRowId <= 0) return null;
return allChild.stream().filter(u -> parentRowId.equals(u.getBomRowId())).collect(Collectors.toList()).get(0);
}
}

View File

@ -136,6 +136,8 @@ public class TechnologyPackageParamBuilder {
newBom.setDeptName(SessionUtil.getDepartName());
newBom.setCreatedBy(SessionUtil.getUserCode());
newBom.setCreatedTime(LocalDateTime.now());
newBom.setTechnologyUserCode(SessionUtil.getUserCode());
newBom.setTechnologyUserName(SessionUtil.getUserName());
newBom.setSourceRowId(0L);
if(Objects.nonNull(oldBom)){
oldBom.setLastVersionIs(0);