From 57b0682db6a010bec436d75a78dc9d705acdda02 Mon Sep 17 00:00:00 2001 From: yinq <1345442242@qq.com> Date: Sun, 8 Oct 2023 18:06:21 +0800 Subject: [PATCH] =?UTF-8?q?change=20-=20=E7=94=9F=E4=BA=A7BOM=E7=A5=96?= =?UTF-8?q?=E7=BA=A7=E5=88=97=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/BaseBomInfoController.java | 9 ++++ .../aucma/production/domain/BaseBomInfo.java | 16 +------ .../production/mapper/BaseBomInfoMapper.java | 24 +++++++++++ .../service/impl/BaseBomInfoServiceImpl.java | 43 +++++++++++++++++++ .../mapper/production/BaseBomInfoMapper.xml | 32 +++++++++++--- 5 files changed, 104 insertions(+), 20 deletions(-) diff --git a/aucma-production/src/main/java/com/aucma/production/controller/BaseBomInfoController.java b/aucma-production/src/main/java/com/aucma/production/controller/BaseBomInfoController.java index d94943f..d85287e 100644 --- a/aucma-production/src/main/java/com/aucma/production/controller/BaseBomInfoController.java +++ b/aucma-production/src/main/java/com/aucma/production/controller/BaseBomInfoController.java @@ -46,6 +46,15 @@ public class BaseBomInfoController extends BaseController { return getDataTable(list); } + /** + * 查询生产子BOM树状列表 + */ + @GetMapping("/treeList" ) + public AjaxResult treeList(BaseBomInfo baseBomInfo) { + List list = baseBomInfoService.selectBaseBomInfoList(baseBomInfo); + return success(list); + } + /** * 导出生产BOM列表 */ diff --git a/aucma-production/src/main/java/com/aucma/production/domain/BaseBomInfo.java b/aucma-production/src/main/java/com/aucma/production/domain/BaseBomInfo.java index 8afab60..c860458 100644 --- a/aucma-production/src/main/java/com/aucma/production/domain/BaseBomInfo.java +++ b/aucma-production/src/main/java/com/aucma/production/domain/BaseBomInfo.java @@ -2,11 +2,11 @@ package com.aucma.production.domain; import java.util.Date; +import com.aucma.common.core.domain.model.TreeStringEntity; import com.fasterxml.jackson.annotation.JsonFormat; import org.apache.commons.lang3.builder.ToStringBuilder; import org.apache.commons.lang3.builder.ToStringStyle; import com.aucma.common.annotation.Excel; -import com.aucma.common.core.domain.BaseEntity; /** * 生产BOM对象 base_bominfo @@ -14,7 +14,7 @@ import com.aucma.common.core.domain.BaseEntity; * @author Yinq * @date 2023-09-28 */ -public class BaseBomInfo extends BaseEntity { +public class BaseBomInfo extends TreeStringEntity { private static final long serialVersionUID = 1L; /** @@ -102,11 +102,6 @@ public class BaseBomInfo extends BaseEntity { @Excel(name = "更新时间", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss") private Date updatedTime; - /** - * 工单编号 - */ - @Excel(name = "工单编号") - private String orderCode; public void setObjId(Long objId) { this.objId = objId; @@ -220,13 +215,7 @@ public class BaseBomInfo extends BaseEntity { return updatedTime; } - public void setOrderCode(String orderCode) { - this.orderCode = orderCode; - } - public String getOrderCode() { - return orderCode; - } @Override public String toString() { @@ -245,7 +234,6 @@ public class BaseBomInfo extends BaseEntity { .append("createdTime", getCreatedTime()) .append("updatedBy", getUpdatedBy()) .append("updatedTime", getUpdatedTime()) - .append("orderCode", getOrderCode()) .toString(); } } diff --git a/aucma-production/src/main/java/com/aucma/production/mapper/BaseBomInfoMapper.java b/aucma-production/src/main/java/com/aucma/production/mapper/BaseBomInfoMapper.java index 59f6425..49fd5ea 100644 --- a/aucma-production/src/main/java/com/aucma/production/mapper/BaseBomInfoMapper.java +++ b/aucma-production/src/main/java/com/aucma/production/mapper/BaseBomInfoMapper.java @@ -2,6 +2,7 @@ package com.aucma.production.mapper; import java.util.List; import com.aucma.production.domain.BaseBomInfo; +import org.apache.ibatis.annotations.Param; /** * 生产BOMMapper接口 @@ -19,6 +20,14 @@ public interface BaseBomInfoMapper */ public BaseBomInfo selectBaseBomInfoByObjId(Long objId); + /** + * 根据BOM编号查询生产BOM + * + * @param materialCode 生产BOM主键 + * @return 生产BOM + */ + public BaseBomInfo selectBaseBomInfoByMaterialCode(@Param("materialCode") String materialCode); + /** * 查询生产BOM列表 * @@ -58,4 +67,19 @@ public interface BaseBomInfoMapper * @return 结果 */ public int deleteBaseBomInfoByObjIds(Long[] objIds); + + /** + * 根据ID查询所有子Bom + * @param materialCode + * @return + */ + List selectChildrenBomById(String materialCode); + + /** + * 修改子元素关系 + * + * @param children 子元素 + * @return 结果 + */ + void updateBomChildren(@Param("depts") List children); } diff --git a/aucma-production/src/main/java/com/aucma/production/service/impl/BaseBomInfoServiceImpl.java b/aucma-production/src/main/java/com/aucma/production/service/impl/BaseBomInfoServiceImpl.java index aab9d5c..2a97b66 100644 --- a/aucma-production/src/main/java/com/aucma/production/service/impl/BaseBomInfoServiceImpl.java +++ b/aucma-production/src/main/java/com/aucma/production/service/impl/BaseBomInfoServiceImpl.java @@ -1,6 +1,9 @@ package com.aucma.production.service.impl; import java.util.List; + +import com.aucma.common.core.domain.entity.SysDept; +import com.aucma.common.utils.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import com.aucma.production.mapper.BaseBomInfoMapper; @@ -52,6 +55,12 @@ public class BaseBomInfoServiceImpl implements IBaseBomInfoService @Override public int insertBaseBomInfo(BaseBomInfo baseBomInfo) { + BaseBomInfo info = baseBomInfoMapper.selectBaseBomInfoByMaterialCode(baseBomInfo.getParentId()); + if (StringUtils.isNull(info)){ + baseBomInfo.setAncestors(baseBomInfo.getMaterialCode()); + }else { + baseBomInfo.setAncestors(info.getAncestors() + "," + baseBomInfo.getMaterialCode()); + } return baseBomInfoMapper.insertBaseBomInfo(baseBomInfo); } @@ -64,9 +73,43 @@ public class BaseBomInfoServiceImpl implements IBaseBomInfoService @Override public int updateBaseBomInfo(BaseBomInfo baseBomInfo) { + String parentId = baseBomInfo.getParentId(); + if (StringUtils.isNull(parentId)){ + baseBomInfo.setAncestors(baseBomInfo.getMaterialCode()); + }else { + BaseBomInfo newParentBomInfo = baseBomInfoMapper.selectBaseBomInfoByMaterialCode(parentId); + BaseBomInfo oldBomInfo = baseBomInfoMapper.selectBaseBomInfoByMaterialCode(baseBomInfo.getMaterialCode()); + if (StringUtils.isNotNull(newParentBomInfo) && StringUtils.isNotNull(oldBomInfo)) + { + String newAncestors = newParentBomInfo.getAncestors() + "," + baseBomInfo.getMaterialCode(); + String oldAncestors = oldBomInfo.getAncestors(); + baseBomInfo.setAncestors(newAncestors); + updateBomChildren(baseBomInfo.getMaterialCode(), newAncestors, oldAncestors); + } + } return baseBomInfoMapper.updateBaseBomInfo(baseBomInfo); } + /** + * 修改子元素关系 + * + * @param materialCode 被修改的部门ID + * @param newAncestors 新的父ID集合 + * @param oldAncestors 旧的父ID集合 + */ + private void updateBomChildren(String materialCode, String newAncestors, String oldAncestors) { + List children = baseBomInfoMapper.selectChildrenBomById(materialCode); + for (BaseBomInfo child : children) + { + child.setAncestors(child.getAncestors().replaceFirst(oldAncestors, newAncestors)); + } + if (children.size() > 0) + { + baseBomInfoMapper.updateBomChildren(children); + } + + } + /** * 批量删除生产BOM * diff --git a/aucma-production/src/main/resources/mapper/production/BaseBomInfoMapper.xml b/aucma-production/src/main/resources/mapper/production/BaseBomInfoMapper.xml index 155ce10..0c2a257 100644 --- a/aucma-production/src/main/resources/mapper/production/BaseBomInfoMapper.xml +++ b/aucma-production/src/main/resources/mapper/production/BaseBomInfoMapper.xml @@ -19,11 +19,12 @@ - + - select obj_id, bom_code, material_code, material_name, material_type, standard_amount, parent_id, plant_code, product_line_code, is_flag, created_by, created_time, updated_by, updated_time, order_code from base_bominfo + select obj_id, bom_code, material_code, material_name, material_type, standard_amount, parent_id, + plant_code, product_line_code, is_flag, created_by, created_time, updated_by, updated_time, ancestors from base_bominfo @@ -50,6 +51,13 @@ where obj_id = #{objId} + + @@ -71,7 +79,7 @@ created_time, updated_by, updated_time, - order_code, + ancestors, #{objId}, @@ -88,7 +96,7 @@ #{createdTime}, #{updatedBy}, #{updatedTime}, - #{orderCode}, + #{ancestors}, @@ -108,10 +116,22 @@ created_time = #{createdTime}, updated_by = #{updatedBy}, updated_time = #{updatedTime}, - order_code = #{orderCode}, + ancestors = #{ancestors}, where obj_id = #{objId} + + update base_bominfo set ancestors = + + when #{item.materialCode} then #{item.ancestors} + + where material_code in + + #{item.materialCode} + + delete from base_bominfo where obj_id = #{objId}