feat: 新增parentObjId字段修正BOM父子关系

master
zangch@mesnac.com 2 weeks ago
parent cbbe49407d
commit d07d8946ce

@ -53,6 +53,14 @@ public class OrderBomInfo extends TreeStringEntity {
@Excel(name = "父物料编号")
private String parentId;
/**
* BOM
*
* BOM
* parentId
*/
private Long parentObjId;
/**
*
*/
@ -152,6 +160,14 @@ public class OrderBomInfo extends TreeStringEntity {
this.parentName = parentName;
}
public Long getParentObjId() {
return parentObjId;
}
public void setParentObjId(Long parentObjId) {
this.parentObjId = parentObjId;
}
public String getParentMaterialType() {
return parentMaterialType;
}
@ -300,6 +316,7 @@ public class OrderBomInfo extends TreeStringEntity {
.append("materialType", getMaterialType())
.append("standardAmount", getStandardAmount())
.append("parentId", getParentId())
.append("parentObjId", getParentObjId())
.append("isFlag", getIsFlag())
.append("createdBy", getCreatedBy())
.append("createdTime", getCreatedTime())

@ -2,6 +2,7 @@ package com.aucma.base.service.impl;
import java.util.List;
import com.aucma.common.exception.base.BaseException;
import com.aucma.common.utils.DateUtils;
import com.aucma.common.utils.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
@ -55,8 +56,10 @@ public class OrderBomInfoServiceImpl implements IOrderBomInfoService
@Override
public int insertOrderBomInfo(OrderBomInfo orderBomInfo)
{
// 当前业务改为手工维护父子关系,这里只维护树查询必需的祖级链,不再做任何跨模块同步。
orderBomInfo.setAncestors(buildManualAncestors(orderBomInfo.getParentId(), orderBomInfo.getMaterialCode()));
// 当前业务改为手工维护父子关系。这里先把父节点唯一定位到具体 BOM 记录,
// 避免同一物料编码出现在多个分支时,祖级链被挂到错误的父节点上。
normalizeParentNode(orderBomInfo);
orderBomInfo.setAncestors(buildManualAncestors(orderBomInfo));
orderBomInfo.setCreatedTime(DateUtils.getNowDate());
return orderBomInfoMapper.insertOrderBomInfo(orderBomInfo);
}
@ -71,7 +74,8 @@ public class OrderBomInfoServiceImpl implements IOrderBomInfoService
public int updateOrderBomInfo(OrderBomInfo orderBom)
{
OrderBomInfo oldBomInfo = orderBomInfoMapper.selectOrderBomInfoByObjId(orderBom.getObjId());
String newAncestors = buildManualAncestors(orderBom.getParentId(), orderBom.getMaterialCode());
normalizeParentNode(orderBom);
String newAncestors = buildManualAncestors(orderBom);
orderBom.setAncestors(newAncestors);
if (StringUtils.isNotNull(oldBomInfo) && StringUtils.isNotEmpty(oldBomInfo.getAncestors()))
{
@ -89,13 +93,28 @@ public class OrderBomInfoServiceImpl implements IOrderBomInfoService
* @param materialCode
* @return
*/
private String buildManualAncestors(String parentId, String materialCode)
private String buildManualAncestors(OrderBomInfo orderBomInfo)
{
String parentId = orderBomInfo.getParentId();
String materialCode = orderBomInfo.getMaterialCode();
// 根节点直接以自身编码作为祖级,便于前端按成品或顶层节点筛子树。
if (isRootNode(parentId))
{
return materialCode;
}
if (StringUtils.isNotNull(orderBomInfo.getParentObjId()) && orderBomInfo.getParentObjId() > 0L)
{
OrderBomInfo parentBomInfo = orderBomInfoMapper.selectOrderBomInfoByObjId(orderBomInfo.getParentObjId());
if (StringUtils.isNull(parentBomInfo))
{
throw new BaseException("父级BOM节点不存在无法维护当前BOM结构");
}
if (StringUtils.isNotEmpty(parentBomInfo.getAncestors()))
{
return parentBomInfo.getAncestors() + "," + materialCode;
}
return parentBomInfo.getMaterialCode() + "," + materialCode;
}
OrderBomInfo parentBomInfo = orderBomInfoMapper.selectOrderBomInfoByMaterialCode(parentId);
if (StringUtils.isNotNull(parentBomInfo) && StringUtils.isNotEmpty(parentBomInfo.getAncestors()))
{
@ -116,6 +135,34 @@ public class OrderBomInfoServiceImpl implements IOrderBomInfoService
return StringUtils.isEmpty(parentId) || "0".equals(parentId);
}
/**
*
*
* BOM parentObjId
* parentId退
*
* @param orderBomInfo BOM
*/
private void normalizeParentNode(OrderBomInfo orderBomInfo)
{
if (StringUtils.isNull(orderBomInfo.getParentObjId()) || orderBomInfo.getParentObjId() <= 0L)
{
if (isRootNode(orderBomInfo.getParentId()))
{
orderBomInfo.setParentObjId(0L);
orderBomInfo.setParentId("0");
}
return;
}
OrderBomInfo parentBomInfo = orderBomInfoMapper.selectOrderBomInfoByObjId(orderBomInfo.getParentObjId());
if (StringUtils.isNull(parentBomInfo))
{
throw new BaseException("父级BOM节点不存在无法维护当前BOM结构");
}
// 统一以父节点真实物料编码落库,兼容历史查询和列表展示。
orderBomInfo.setParentId(parentBomInfo.getMaterialCode());
}
/**
*
*

@ -12,6 +12,7 @@
<result property="materialType" column="material_type"/>
<result property="standardAmount" column="standard_amount"/>
<result property="parentId" column="parent_id"/>
<result property="parentObjId" column="parent_obj_id"/>
<result property="isFlag" column="is_flag"/>
<result property="createdBy" column="created_by"/>
<result property="createdTime" column="created_time"/>
@ -34,6 +35,7 @@
bm.MATERIAL_SUBCLASS material_type,
ob.standard_amount,
ob.parent_id,
ob.parent_obj_id,
mp.MATERIAL_NAME parentName,
mp.MATERIAL_SUBCLASS parentMaterialType,
ob.is_flag,
@ -100,6 +102,7 @@
<if test="materialType != null">material_type,</if>
<if test="standardAmount != null">standard_amount,</if>
<if test="parentId != null">parent_id,</if>
<if test="parentObjId != null">parent_obj_id,</if>
<if test="isFlag != null">is_flag,</if>
<if test="createdBy != null">created_by,</if>
<if test="createdTime != null">created_time,</if>
@ -119,6 +122,7 @@
<if test="materialType != null">#{materialType},</if>
<if test="standardAmount != null">#{standardAmount},</if>
<if test="parentId != null">#{parentId},</if>
<if test="parentObjId != null">#{parentObjId},</if>
<if test="isFlag != null">#{isFlag},</if>
<if test="createdBy != null">#{createdBy},</if>
<if test="createdTime != null">#{createdTime},</if>
@ -141,6 +145,7 @@
<if test="materialType != null">material_type = #{materialType},</if>
<if test="standardAmount != null">standard_amount = #{standardAmount},</if>
<if test="parentId != null">parent_id = #{parentId},</if>
<if test="parentObjId != null">parent_obj_id = #{parentObjId},</if>
<if test="isFlag != null">is_flag = #{isFlag},</if>
<if test="createdBy != null">created_by = #{createdBy},</if>
<if test="createdTime != null">created_time = #{createdTime},</if>

Loading…
Cancel
Save