发布Mbom

This commit is contained in:
大米 2024-01-05 18:14:11 +08:00
parent 07db8a3e1d
commit 66990bd395
15 changed files with 733 additions and 11 deletions

View File

@ -172,7 +172,7 @@ public class PBomApi extends BaseApi {
@GetMapping("convertToMBom")
@ApiOperation("发布MBom")
public ResultVO<Boolean> convertToMBom(@RequestParam("bomRowId") Long bomRowId) {
public ResultVO<Boolean> convertToMBom(@RequestParam("bomRowId") Long bomRowId) throws ExecutionException, InterruptedException {
BomNewPbomParentEntity parent = bomNewPbomParentService.getById(bomRowId);
VUtils.isTure(!parent.getMaterialNo().startsWith("31")).throwMessage("只有31开头的物料才可以发布");
VUtils.isTure(!PBomStatusEnum.PUBLISH.equalsValue(parent.getStatus())).throwMessage("只有已发布的BOM才能生成MBom");

View File

@ -19,4 +19,6 @@ public class EBomConstant {
//仙桃分厂代码
public static final String XIAN_TAO_FACTORY_CODE_1020="1020";
public static final String XIAN_TAO_FACTORY_Name_1020="仙桃";
}

View File

@ -25,6 +25,10 @@ public class TechnologyPackageParam {
@ApiModelProperty("工艺包物料编码")
private String technologyPackageMaterialNo;
@ApiModelProperty("项目类别")
@NotNull(message = "项目类别不能为空")
private String projectType;
@ApiModelProperty("工艺包类型rowId(创建工艺包时用)")
private Long technologyPackageTypeRowId;

View File

@ -202,6 +202,10 @@ public class BomNewEbomChildEntity implements Serializable {
@ApiModelProperty(value = "备注")
private String remark;
@TableField(value = "virtual_part_type")
@ApiModelProperty(value = "0-非虚拟包 1-发货包 2-制作包 4-直发包 8-发货前装配包")
private Integer virtualPartType;
private static final long serialVersionUID = -14147430944632372L;
}

View File

@ -216,6 +216,13 @@ public class BomNewPbomChildEntity implements Serializable {
@ApiModelProperty(value = "来源行-父项物料编码")
private String sourceParentMaterialNo;
/**
* 0-非虚拟包 1-发货包 2-制作包 4-直发包 8-发货前装配包
*/
@TableField(value = "virtual_part_type")
@ApiModelProperty(value = "0-非虚拟包 1-发货包 2-制作包 4-直发包 8-发货前装配包")
private Integer virtualPartType;
private static final long serialVersionUID = -76633783850936076L;
}

View File

@ -308,6 +308,9 @@ public class BomNewEbomParentVO extends BaseMaterialVO implements Serializable {
@ApiModelProperty("是否虚拟件")
private Integer virtualPartIs;
@ApiModelProperty("0-非虚拟包 1-发货包 2-制作包 4-直发包 8-发货前装配包")
private Integer virtualPartType;
private List<BomNewEbomParentVO> childNodes = Collections.emptyList();
private static final long serialVersionUID = 1L;

View File

@ -246,6 +246,9 @@ public class BomNewPbomParentVO extends BaseMaterialVO implements Serializable {
@ApiModelProperty("是否虚拟件 0-否 1-是")
private Integer virtualPartIs;
@ApiModelProperty("虚拟件类型 0-非虚拟包 1-发货包 2-制作包 4-直发包 8-发货前装配包")
private Integer virtualPartType;
@ApiModelProperty("子级")
List<BomNewPbomParentVO> childNodes;

View File

@ -16,6 +16,7 @@ import com.nflg.product.bomnew.pojo.entity.*;
import com.nflg.product.bomnew.pojo.query.BomNewPbomParentQuery;
import com.nflg.product.bomnew.pojo.vo.*;
import com.nflg.product.bomnew.service.domain.PBom.BomCopy;
import com.nflg.product.bomnew.service.domain.PBom.ConvertToMBom;
import com.nflg.product.bomnew.service.domain.PBom.PBomDetailTask;
import com.nflg.product.bomnew.service.domain.PBom.TechnologyPackageParamBuilder;
import com.nflg.product.bomnew.util.*;
@ -67,6 +68,11 @@ public class BomNewPbomParentService extends ServiceImpl<BomNewPbomParentMapper,
@Qualifier(value = "getPBomDetailPool")
private ForkJoinPool bomDetailPool;
@Resource
private BomNewMbomParentService mBomParentService;
@Resource
private BomNewMbomDetailService mBomDetailService;
/**
* pbom-工作列表
*
@ -424,9 +430,19 @@ public class BomNewPbomParentService extends ServiceImpl<BomNewPbomParentMapper,
/**
* 发布MBOM
*/
public Boolean convertToMBom(Long bomRowId){
@Transactional(rollbackFor = Exception.class)
public Boolean convertToMBom(Long bomRowId) throws ExecutionException, InterruptedException {
BomNewPbomParentEntity rootParent = this.getById(bomRowId);
List<BomNewPbomParentVO> allChild = getAllBom(bomRowId, 0);
ConvertToMBom convertToMBom=new ConvertToMBom(rootParent ,allChild);
convertToMBom.convertToMBom();
if(CollUtil.isNotEmpty(convertToMBom.getMBomParentResult())){
mBomParentService.saveOrUpdateBatch(convertToMBom.getMBomParentResult());
}
if(CollUtil.isNotEmpty(convertToMBom.getMBomDetailResult())){
mBomDetailService.saveOrUpdateBatch(convertToMBom.getMBomDetailResult());
}
return true;
}

View File

@ -114,6 +114,7 @@ public abstract class VirtualPackageBase {
childEntity.setNum(new BigDecimal(1));
childEntity.setEditStatus(EbomEditStatusEnum.HANDLER_CREATED.getValue());
childEntity.setSource(EBomSourceEnum.FROM_MDM.getValue());
childEntity.setVirtualPartType(virtualPackageTypeEnum.getValue());
this.childResult.add(childEntity);
return childEntity;
}

View File

@ -1,17 +1,293 @@
package com.nflg.product.bomnew.service.domain.PBom;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.convert.Convert;
import cn.hutool.core.util.EnumUtil;
import cn.hutool.core.util.NumberUtil;
import cn.hutool.extra.spring.SpringUtil;
import com.alibaba.excel.enums.BooleanEnum;
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.google.common.collect.ImmutableList;
import com.nflg.product.base.core.conmon.util.SessionUtil;
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.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.BomNewMbomParentService;
import com.nflg.product.bomnew.service.BomNewPbomParentService;
import com.nflg.product.bomnew.util.CTreePBomUtils;
import com.nflg.product.bomnew.util.VUtils;
import com.nflg.product.bomnew.util.VersionUtil;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
/**
* PBOM转MBOM
*/
public class ConvertToMBom {
@ApiModelProperty("BOM版本行id")
private Long bomRowId;
private BomNewPbomParentEntity parent;
public ConvertToMBom(Long inBomRowId){
this.bomRowId=inBomRowId;
private List<ConvertToMBomDTO> allChild_1020;
private List<ConvertToMBomDTO> allChild_1010;
@Getter
List<BomNewMbomParentEntity> mBomParentResult = new ArrayList<>();
@Getter
List<BomNewMbomDetailEntity> mBomDetailResult = new ArrayList<>();
public ConvertToMBom(BomNewPbomParentEntity inRootParent, List<BomNewPbomParentVO> inAllChild) {
this.parent = inRootParent;
this.allChild_1010 = Convert.toList(ConvertToMBomDTO.class, inAllChild);
Collections.copy(allChild_1010, allChild_1020);
}
/**
* 转换MBom
*/
public void convertToMBom() {
handler1010();
handler1020();
buildMBom(EBomConstant.MAIN_FACTORY_CODE_1010);
buildMBom(EBomConstant.XIAN_TAO_FACTORY_CODE_1020);
}
/**
* 构建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)) {
mBomParent.setCurrentVersion(VersionUtil.getNextVersion(oldParent.getCurrentVersion()));
oldParent.setLastVersionIs(0);
this.mBomParentResult.add(oldParent);
} else {
mBomParent.setCurrentVersion(VersionUtil.getNextVersion(""));
}
mBomParent.setRowId(IdWorker.getId());
mBomParent.setFacCode(facCode);
mBomParent.setCreatedBy(SessionUtil.getUserCode());
mBomParent.setCreatedTime(LocalDateTime.now());
mBomParent.setModifyTime(LocalDateTime.now());
this.mBomParentResult.add(mBomParent);
buildChild(EBomConstant.MAIN_FACTORY_CODE_1010.equals(facCode)? allChild_1010:allChild_1020,mBomParent.getRowId());
}
/**
* 构建子级
*
* @param allChild
*/
private void buildChild(List<ConvertToMBomDTO> allChild, Long bomRowId) {
List<ConvertToMBomDTO> childBomTree = ConvertToMbomUtil.toTree(parent.getRowId(), allChild_1010, ConvertToMBomDTO::getRelParentRowId, ConvertToMBomDTO::getBomRowId);
List<ConvertToMBomDTO> parentChildren;
Long parentRowId = 0L;
for (ConvertToMBomDTO item : childBomTree) {
//构建子级
if (item.getDelIs().equals(0)) {
parentRowId = buildChildDo(item, bomRowId, 0L);
}
parentChildren = item.getChildNodes();
while (CollUtil.isNotEmpty(parentChildren)) {
for (ConvertToMBomDTO itemChild : parentChildren) {
if (item.getDelIs().equals(0)) {
parentRowId = buildChildDo(itemChild, bomRowId, parentRowId);
}
parentChildren = itemChild.getChildNodes();
}
}
}
}
/**
* 处理制作下为空的虚拟包
* 当制作下子级为空时--删除该发货制作和直发
* @param allChildTree
*/
private void handEmptyMakePackage(List<ConvertToMBomDTO> allChildTree){
List<ConvertToMBomDTO> childBomTree = ConvertToMbomUtil.toTree(parent.getRowId(), allChild_1020, ConvertToMBomDTO::getRelParentRowId, ConvertToMBomDTO::getBomRowId);
for (ConvertToMBomDTO item : allChildTree) {
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(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.setParentRowId(parentRowId);
child.setCreatedBy(SessionUtil.getUserCode());
child.setCreatedTime(LocalDateTime.now());
child.setModifyTime(LocalDateTime.now());
this.mBomDetailResult.add(child);
return child.getRowId();
}
private void handler1010() {
List<ConvertToMBomDTO> childBomTree = ConvertToMbomUtil.toTree(parent.getRowId(), allChild_1010, ConvertToMBomDTO::getParentRowId, ConvertToMBomDTO::getBomRowId);
List<ConvertToMBomDTO> parentChildren;
for (ConvertToMBomDTO item : childBomTree) {
//默认
item.setRelParentRowId(item.getParentRowId());
setDel(item, EBomConstant.MAIN_FACTORY_CODE_1010);
parentChildren = item.getChildNodes();
while (CollUtil.isNotEmpty(parentChildren)) {
for (ConvertToMBomDTO childItem : parentChildren) {
//默认
childItem.setRelParentRowId(childItem.getParentRowId());
setDel(childItem, EBomConstant.MAIN_FACTORY_CODE_1010);
handlerMaterial(childItem, EBomConstant.MAIN_FACTORY_CODE_1010);
parentChildren = childItem.getChildNodes();
}
}
}
}
/**
* 处理1020
*/
private void handler1020() {
List<ConvertToMBomDTO> childBomTree = ConvertToMbomUtil.toTree(parent.getRowId(), allChild_1020, ConvertToMBomDTO::getParentRowId, ConvertToMBomDTO::getBomRowId);
//虚拟包名称加仙桃
initFac1020Info(childBomTree);
List<ConvertToMBomDTO> parentChildren;
//31下直发包
ConvertToMBomDTO directDeliveryPackage;
ConvertToMBomDTO parentNode = Convert.convert(ConvertToMBomDTO.class, parent);
for (ConvertToMBomDTO item : childBomTree) {
//默认
item.setRelParentRowId(item.getParentRowId());
setDel(item, EBomConstant.XIAN_TAO_FACTORY_CODE_1020);
parentChildren = item.getChildNodes();
directDeliveryPackage = item.getChildNodes().stream().filter(u -> VirtualPackageTypeEnum.DIRECT_DELIVERY_PACKAGE.equalsValue(u.getVirtualPartType())).collect(Collectors.toList()).get(0);
VUtils.isTure(Objects.isNull(directDeliveryPackage)).throwMessage("发货包下,没有直发包");
while (CollUtil.isNotEmpty(parentChildren)) {
parentNode = item;
for (ConvertToMBomDTO childItem : parentChildren) {
//默认
childItem.setRelParentRowId(childItem.getParentRowId());
setDel(childItem, EBomConstant.XIAN_TAO_FACTORY_CODE_1020);
//非31下的直发包
if (VirtualPackageTypeEnum.DIRECT_DELIVERY_PACKAGE.equalsValue(parentNode.getVirtualPartType()) && parentNode.getRowId() != directDeliveryPackage.getRowId()) {
handlerDirectDeliveryPackage(childItem, EBomConstant.XIAN_TAO_FACTORY_CODE_1020, directDeliveryPackage);
} else {
handlerMaterial(childItem, EBomConstant.XIAN_TAO_FACTORY_CODE_1020);
}
parentChildren = childItem.getChildNodes();
parentNode = childItem;
}
}
}
//处理制作包无下级的情况
handEmptyMakePackage(childBomTree);
}
/**
* 处理直发包下的物料
* 所有直发包归到31下的直发包
*/
private void handlerDirectDeliveryPackage(ConvertToMBomDTO childItem, String facCode, ConvertToMBomDTO directDeliveryPackage) {
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) {
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,278 @@
package com.nflg.product.bomnew.service.domain.PBom;
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.nflg.product.bomnew.pojo.vo.BaseMaterialVO;
import com.nflg.product.bomnew.pojo.vo.BomNewPbomParentVO;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.List;
/**
* pbom转mbom
*/
@Data
public class ConvertToMBomDTO extends BaseMaterialVO implements Serializable {
/**
* 主键行ID-雪花
*/
@ApiModelProperty(value = "主键行ID-雪花")
private Long rowId=0L;
@ApiModelProperty("Bom行ID")
private Long bomRowId=0L;
@ApiModelProperty("父级行id")
private Long parentRowId=0L;
/**
* 批号-来自plm-临时
*/
@ApiModelProperty(value = "批号-来自plm-临时")
private String batchNo;
/**
* 工厂编码
*/
@ApiModelProperty(value = "工厂编码")
private String facCode;
/**
* 排序号
*/
@ApiModelProperty(value = "排序号")
private String orderNumber;
/**
* 单重
*/
@ApiModelProperty(value = "单重")
private BigDecimal unitWeight;
/**
* 总重
*/
@ApiModelProperty(value = "总重")
private BigDecimal totalWeight;
/**
* 版本号
*/
@ApiModelProperty(value = "版本号")
private String currentVersion;
/**
* 数量
*/
@ApiModelProperty(value = "数量")
private BigDecimal num;
/**
* 是否跟节点 0- 1-
*/
@ApiModelProperty(value = "是否跟节点 0-否 1-是")
private Integer rootIs;
/**
* 是否应该有BOM 0- 1-
*/
@ApiModelProperty(value = "是否应该有BOM 0-否 1-是")
private Integer shouldBomExist;
/**
* 超级物料 0- 1-
*/
@ApiModelProperty(value = "超级物料 0-否 1-是")
private Integer superMaterialStatus;
/**
* 是否有BOM: 0- 1-
*/
@ApiModelProperty(value = "是否有BOM: 0-否 1-是")
private Integer bomExist;
/**
* 是否最新版0- 1-
*/
@ApiModelProperty(value = "是否最新版0-否 1-是")
private Integer lastVersionIs;
/**
* 1=待处理2=暂存 3=已处理
*/
@ApiModelProperty(value = "1=待处理、2=暂存 3=已处理")
private Integer editStatus;
/**
* BOM状态1=待发布 2=待分配工厂 3=已分配工厂 4=已发布
*/
@ApiModelProperty(value = "BOM状态1=待发布 2=待分配工厂 3=已分配工厂 4=已发布")
private Integer status;
/**
* 是否用户跟节点 0- 1-
*/
@ApiModelProperty(value = "是否用户跟节点 0-否 1-是")
private Integer userRootIs;
/**
* 是否虚拟包 0- 1-
*/
@ApiModelProperty(value = "是否虚拟包 0-否 1-是")
private Integer virtualPackageIs;
/**
* 来源行ID(EBOM中的行ID)
*/
@ApiModelProperty(value = "来源行ID(EBOM中的行ID)")
private Long sourceRowId;
/**
* 设计人员编码
*/
@ApiModelProperty(value = "设计人员编码")
private String deviseUserCode;
/**
* 设计人员名称
*/
@ApiModelProperty(value = "设计人员名称")
private String deviseName;
/**
* 创建人编码
*/
@ApiModelProperty(value = "创建人编码")
private String createdBy;
/**
* 创建时间
*/
@ApiModelProperty(value = "创建时间")
private LocalDateTime createdTime;
/**
* 创建人员所属岗位 0-设计人员 1-工艺人员 2-其他
*/
@ApiModelProperty(value = "创建人员所属岗位 0-设计人员 1-工艺人员 2-其他")
private Integer createdJob;
/**
* 发布时间
*/
@ApiModelProperty(value = "发布时间")
private LocalDateTime releaseTime;
/**
* 发布人
*/
@ApiModelProperty(value = "发布人")
private String releaseUserName;
/**
* 版本过期时间=下个版本的创建时间
*/
@ApiModelProperty(value = "版本过期时间=下个版本的创建时间")
private LocalDateTime expireEndTime;
/**
* 备注
*/
@ApiModelProperty(value = "备注")
private String remark;
/**
* 设计维护部门名称
*/
@ApiModelProperty(value = "设计维护部门名称")
private String deptName;
/**
* bom树的高度
*/
@ApiModelProperty(value = "bom树的高度")
private Integer levelNum;
/**
* 升版说明
*/
@ApiModelProperty(value = "升版说明")
private String changeDesc;
/**
* 通知单号
*/
@ApiModelProperty(value = "通知单号")
private String noticeNums;
/**
* 订单号
*/
@ApiModelProperty(value = "订单号")
private String orderNo;
/**
* 修改时间
*/
@ApiModelProperty(value = "修改时间")
private LocalDateTime modifyTime;
@ApiModelProperty("生产工厂")
private String productionFactoryCode;
@ApiModelProperty("生产工厂设置方式 0-默认 1-规则匹配 2-手工")
private Integer productionFactoryCodeInputType;
@ApiModelProperty("是否虚拟件 0-否 1-是")
private Integer virtualPartIs;
@ApiModelProperty("虚拟件类型 0-非虚拟包 1-发货包 2-制作包 4-直发包 8-发货前装配包")
private Integer virtualPartType;
@ApiModelProperty("是否删除")
public Integer delIs=0;
@ApiModelProperty("提层后的父级行Id")
private Long relParentRowId;
@ApiModelProperty("转到MbOM后的RowId")
private Long mBomChildRowId= IdWorker.getId();
@ApiModelProperty("转到mBOM后的父级Id")
private Long mBomParentRowId=0L;
@ApiModelProperty("子级")
List<ConvertToMBomDTO> childNodes;
@Override
public Object clone() {
try {
ConvertToMBomDTO obj = (ConvertToMBomDTO) super.clone();
return obj;
} catch (CloneNotSupportedException e) {
e.printStackTrace();
return null;
}
}
}

View File

@ -0,0 +1,126 @@
package com.nflg.product.bomnew.service.domain.PBom;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil;
import com.nflg.product.bomnew.util.TreeNode;
import javax.validation.constraints.NotNull;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;
/**
*
* @author 大米
* @date 2023/11/18 16:19
*/
public class ConvertToMbomUtil {
/**
*
*
* @param dataList 数据
* @param keyFun id
* @param parentKeyFun 父级id
* @param rootKey 顶层的 id 比如部门树的顶层id是0
*/
public static <T, K> List<ConvertToMBomDTO> toTree(K rootKey,
Collection<T> dataList,
@NotNull Function<T, K> parentKeyFun,
@NotNull Function<T, K> keyFun) {
return toFilterTree(rootKey, dataList, parentKeyFun, keyFun, null);
}
/**
*
*
* @param rootKey 顶层的 id 比如部门树的顶层id是0
* @param dataList 数据列
* @param parentKeyFun 取父级id的方法引用
* @param keyFun 取子级id的方法引用
* @param filterNoDataFun 存在这种场景选人的时候某个子部门以及父部门下没有下挂任何人员那么这两个部门直接隐藏避免对用户造成干扰
* 这个参数表示部门实体类人员字段的方法引用
*/
public static <T, K, D> List<ConvertToMBomDTO> toFilterTree(K rootKey,
Collection<T> dataList,
@NotNull Function<T, K> parentKeyFun,
@NotNull Function<T, K> keyFun,
Function<T, D> filterNoDataFun) {
if (CollUtil.isEmpty(dataList)) {
return Collections.emptyList();
}
// 根据父节点对列表进行分组
Map<K, List<T>> groupParentKeyMap = dataList.stream().filter(t -> parentKeyFun.apply(t) != null).collect(Collectors.groupingBy(parentKeyFun));
List<T> rootNodes;
if (rootKey == null) {
rootNodes = dataList.stream().filter(t -> parentKeyFun.apply(t) == null).collect(Collectors.toList());
} else {
rootNodes = groupParentKeyMap.getOrDefault(rootKey, Collections.emptyList());
}
return handlerChildTree(rootNodes, groupParentKeyMap, keyFun, filterNoDataFun);
}
/**
* 列表转树
*/
private static <T, K, D> List<ConvertToMBomDTO> handlerChildTree(Collection<T> rootNodes, Map<K, List<T>> groupParentKeyMap,
Function<T, K> keyFun, Function<T, D> filterNoDataFun) {
if (CollUtil.isEmpty(rootNodes)) {
return Collections.emptyList();
}
List<ConvertToMBomDTO> nodes = new ArrayList<>();
for (T t : rootNodes) {
List<T> childNodesData = groupParentKeyMap.getOrDefault(keyFun.apply(t), Collections.emptyList());
ConvertToMBomDTO node =new ConvertToMBomDTO();
BeanUtil.copyProperties(t,node);
List<ConvertToMBomDTO> treeNodes = handlerChildTree(childNodesData, groupParentKeyMap, keyFun, filterNoDataFun);
if (filterNoDataFun != null && CollUtil.isEmpty(treeNodes)) {
if (skipNoDataNode(filterNoDataFun, t)) {
continue;
}
}
nodes.add(node);
node.setChildNodes(treeNodes);
}
return nodes;
}
/**
* 判断是否为空数据如果没有数据则隐藏
*/
@SuppressWarnings("rawtypes")
private static <T, D> boolean skipNoDataNode(Function<T, D> filterNoDataFun, T t) {
D filterData = filterNoDataFun.apply(t);
if (filterData == null) {
return true;
}
if (filterData instanceof Collection) {
Collection filterDataList = (Collection) filterData;
return CollUtil.isEmpty(filterDataList);
}
return false;
}
/**
* 树转list
*/
public static <T> List<T> toList(List<TreeNode<T>> treeNodeList) {
List<T> resultList = new ArrayList<>();
for (TreeNode<T> treeNode : treeNodeList) {
if (treeNode == null || treeNode.getData() == null) {
continue;
}
resultList.add(treeNode.getData());
if (CollUtil.isNotEmpty(treeNode.getChildNodes())) {
resultList.addAll(toList(treeNode.getChildNodes()));
}
}
return resultList;
}
}

View File

@ -124,7 +124,7 @@ public class TechnologyPackageParamBuilder {
newBom.setMaterialTexture(packageMaterial.getMaterialTexture());
newBom.setMaterialUnit(packageMaterial.getMaterialUnit());
newBom.setNum(new BigDecimal(1));
newBom.setProjectType("L");
newBom.setProjectType(packageMaterial.getProjectType());
newBom.setBomExist(packageParam.getLevelBelong().equals(0)?1:0);
newBom.setLastVersionIs(1);
newBom.setCurrentVersion(Objects.isNull(oldBom)? VersionUtil.getNextVersion(""):VersionUtil.getNextVersion(oldBom.getCurrentVersion()));
@ -158,7 +158,7 @@ public class TechnologyPackageParamBuilder {
child.setMaterialUnit(packageMaterial.getMaterialUnit());
child.setMaterialCategoryCode(packageMaterial.getMaterialCategoryCode());
child.setNum(new BigDecimal(1));
child.setProjectType("L");
child.setProjectType(packageParam.getProjectType());
child.setCreatedBy(SessionUtil.getUserCode());
child.setCreatedTime(LocalDateTime.now());
child.setModifyTime(LocalDateTime.now());

View File

@ -29,6 +29,7 @@
<result column="source" property="source" jdbcType="INTEGER"/>
<result column="source_row_id" property="sourceRowId" jdbcType="BIGINT"/>
<result column="remark" property="remark" jdbcType="VARCHAR"/>
<result column="virtual_part_type" property="virtualPartType" jdbcType="INTEGER"/>
</resultMap>
<sql id="Base_Column_List">
@ -36,7 +37,7 @@
row_id, parent_row_id, identity_no, order_number, drawing_no, material_no, material_name, material_desc,
material_texture, material_unit, material_category_code, unit_weight, num, total_weight, project_type,
project_type_input_type, created_by,virtual_part_is, created_time, modify_time, edit_status, exception_status, source,
source_row_id, remark
source_row_id, remark,virtual_part_type
</sql>

View File

@ -32,11 +32,12 @@
<result column="source_row_id" property="sourceRowId" jdbcType="BIGINT"/>
<result column="remark" property="remark" jdbcType="VARCHAR"/>
<result column="source_parent_material_no" property="sourceParentMaterialNo" jdbcType="VARCHAR"/>
<result column="virtual_part_type" property="virtualPartType" jdbcType="INTEGER"/>
</resultMap>
<sql id="Base_Column_List">
<!--@mbg.generated-->
row_id, parent_row_id, identity_no, fac_code, order_number, drawing_no, material_no, material_name, material_desc, material_texture, material_unit, material_category_code, unit_weight, num, total_weight, project_type, production_factory_code,production_factory_code_input_type, set_production_factory_time, super_material_status, virtual_part_is, created_by, created_time, modify_time, source_row_id, remark, source_parent_material_no </sql>
row_id, parent_row_id, identity_no, fac_code, order_number, drawing_no, material_no, material_name, material_desc, material_texture, material_unit, material_category_code, unit_weight, num, total_weight, project_type, production_factory_code,production_factory_code_input_type, set_production_factory_time, super_material_status, virtual_part_is, created_by, created_time, modify_time, source_row_id, remark, source_parent_material_no ,virtual_part_type </sql>
<delete id="delByRowId">