From 7d6528e4d9c3210e01bc046267f87612000fe3c1 Mon Sep 17 00:00:00 2001 From: xs Date: Thu, 27 Feb 2025 18:59:05 +0800 Subject: [PATCH] =?UTF-8?q?1.2.2=20=E7=94=9F=E4=BA=A7bom=E6=9C=8D=E5=8A=A1?= =?UTF-8?q?=E7=AB=AF=E5=AE=8C=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BaseStructureBomController.java | 2 +- .../controller/ProdMaterialBomController.java | 26 ++ .../dromara/mes/domain/ProdMaterialBom.java | 8 +- .../mes/domain/bo/ProdMaterialBomBo.java | 13 +- .../mes/domain/vo/BaseStructureBomVo.java | 2 +- .../mes/domain/vo/ProdMaterialBomVo.java | 19 +- .../org/dromara/mes/domain/vo/TreeSelect.java | 104 ++++++-- .../mes/mapper/ProdMaterialBomMapper.java | 26 ++ .../mes/service/IProdMaterialBomService.java | 17 ++ .../impl/ProdMaterialBomServiceImpl.java | 252 +++++++++++------- .../service/impl/ProdPlanInfoServiceImpl.java | 1 + .../mapper/mes/ProdMaterialBomMapper.xml | 60 +++++ 12 files changed, 404 insertions(+), 126 deletions(-) diff --git a/ruoyi-modules/hwmom-mes/src/main/java/org/dromara/mes/controller/BaseStructureBomController.java b/ruoyi-modules/hwmom-mes/src/main/java/org/dromara/mes/controller/BaseStructureBomController.java index 0b7a8da2..32330ea6 100644 --- a/ruoyi-modules/hwmom-mes/src/main/java/org/dromara/mes/controller/BaseStructureBomController.java +++ b/ruoyi-modules/hwmom-mes/src/main/java/org/dromara/mes/controller/BaseStructureBomController.java @@ -127,7 +127,7 @@ public class BaseStructureBomController extends BaseController { /** - * 获取部门树列表 + * 获取物料类型结构树列表 */ @SaCheckPermission("mes:baseStructureBom:list") @GetMapping("/structureBomTree") diff --git a/ruoyi-modules/hwmom-mes/src/main/java/org/dromara/mes/controller/ProdMaterialBomController.java b/ruoyi-modules/hwmom-mes/src/main/java/org/dromara/mes/controller/ProdMaterialBomController.java index e3776c15..e86d51b3 100644 --- a/ruoyi-modules/hwmom-mes/src/main/java/org/dromara/mes/controller/ProdMaterialBomController.java +++ b/ruoyi-modules/hwmom-mes/src/main/java/org/dromara/mes/controller/ProdMaterialBomController.java @@ -6,6 +6,8 @@ import lombok.RequiredArgsConstructor; import jakarta.servlet.http.HttpServletResponse; import jakarta.validation.constraints.*; import cn.dev33.satoken.annotation.SaCheckPermission; +import org.dromara.mes.domain.bo.BaseStructureBomBo; +import org.dromara.mes.domain.vo.TreeSelect; import org.springframework.web.bind.annotation.*; import org.springframework.validation.annotation.Validated; import org.dromara.common.idempotent.annotation.RepeatSubmit; @@ -124,4 +126,28 @@ public class ProdMaterialBomController extends BaseController { //不是单纯的批量新增,是新增BOM对话框(参考结构BOM批量新增物料BOM) return toAjax(prodMaterialBomService.insertBatchByBoList(boList)); } + + + + + + /** + * 获取生产bom结构树列表 + */ + @SaCheckPermission("mes:materialBom:list") + @GetMapping("/materialBomTree") + public R> materialBomTree(ProdMaterialBomBo prodMaterialBomBo) { + return R.ok(prodMaterialBomService.selectMaterialBomTreeList(prodMaterialBomBo)); + } + + /** + * 查询物料BOM信息列表 + */ + @SaCheckPermission("mes:materialBom:list") + @GetMapping("/joinStructureList") + public R> joinStructureList(ProdMaterialBomBo bo) { + List list = prodMaterialBomService.queryJoinStructureList(bo); + return R.ok(list); + } + } diff --git a/ruoyi-modules/hwmom-mes/src/main/java/org/dromara/mes/domain/ProdMaterialBom.java b/ruoyi-modules/hwmom-mes/src/main/java/org/dromara/mes/domain/ProdMaterialBom.java index b0414007..8275b9f3 100644 --- a/ruoyi-modules/hwmom-mes/src/main/java/org/dromara/mes/domain/ProdMaterialBom.java +++ b/ruoyi-modules/hwmom-mes/src/main/java/org/dromara/mes/domain/ProdMaterialBom.java @@ -6,6 +6,7 @@ import lombok.Data; import lombok.EqualsAndHashCode; import java.io.Serial; +import java.math.BigDecimal; /** * 物料BOM信息对象 prod_material_bom @@ -42,6 +43,11 @@ public class ProdMaterialBom extends TenantEntity { */ private String materialName; + /** + * 物料类型ID + */ + private Long materialTypeId; + /** * bom说明 */ @@ -60,7 +66,7 @@ public class ProdMaterialBom extends TenantEntity { /** * 标准数量 */ - private Long standardAmount; + private BigDecimal standardAmount; /** * 顶级标识(1是 0否) diff --git a/ruoyi-modules/hwmom-mes/src/main/java/org/dromara/mes/domain/bo/ProdMaterialBomBo.java b/ruoyi-modules/hwmom-mes/src/main/java/org/dromara/mes/domain/bo/ProdMaterialBomBo.java index 7ea4526d..2a7bb606 100644 --- a/ruoyi-modules/hwmom-mes/src/main/java/org/dromara/mes/domain/bo/ProdMaterialBomBo.java +++ b/ruoyi-modules/hwmom-mes/src/main/java/org/dromara/mes/domain/bo/ProdMaterialBomBo.java @@ -9,6 +9,8 @@ import lombok.Data; import lombok.EqualsAndHashCode; import jakarta.validation.constraints.*; +import java.math.BigDecimal; + /** * 物料BOM信息业务对象 prod_material_bom * @@ -41,6 +43,11 @@ public class ProdMaterialBomBo extends BaseEntity { */ private String materialName; + /** + * 物料类型ID + */ + private Long materialTypeId; + /** * bom说明 */ @@ -59,7 +66,7 @@ public class ProdMaterialBomBo extends BaseEntity { /** * 标准数量 */ - private Long standardAmount; + private BigDecimal standardAmount; /** * 顶级标识(1是 0否) @@ -101,5 +108,9 @@ public class ProdMaterialBomBo extends BaseEntity { */ private String remark; + private String materialTypeCode;//join查询字段 + + private String materialTypeName;//join查询字段 + private Long bomStructureParentId;//结构树的parentId } diff --git a/ruoyi-modules/hwmom-mes/src/main/java/org/dromara/mes/domain/vo/BaseStructureBomVo.java b/ruoyi-modules/hwmom-mes/src/main/java/org/dromara/mes/domain/vo/BaseStructureBomVo.java index 98de3123..a6b37084 100644 --- a/ruoyi-modules/hwmom-mes/src/main/java/org/dromara/mes/domain/vo/BaseStructureBomVo.java +++ b/ruoyi-modules/hwmom-mes/src/main/java/org/dromara/mes/domain/vo/BaseStructureBomVo.java @@ -133,7 +133,7 @@ public class BaseStructureBomVo implements Serializable { @ExcelProperty(value = "更新时间") private Date updateTime; - /** 子部门 */ + /** 子物料类型结构bom */ private List children = new ArrayList(); private String materialTypeCode;//join字段 diff --git a/ruoyi-modules/hwmom-mes/src/main/java/org/dromara/mes/domain/vo/ProdMaterialBomVo.java b/ruoyi-modules/hwmom-mes/src/main/java/org/dromara/mes/domain/vo/ProdMaterialBomVo.java index 0e6cbd36..0438846e 100644 --- a/ruoyi-modules/hwmom-mes/src/main/java/org/dromara/mes/domain/vo/ProdMaterialBomVo.java +++ b/ruoyi-modules/hwmom-mes/src/main/java/org/dromara/mes/domain/vo/ProdMaterialBomVo.java @@ -7,11 +7,14 @@ import org.dromara.common.excel.annotation.ExcelDictFormat; import org.dromara.common.excel.convert.ExcelDictConvert; import io.github.linpeilie.annotations.AutoMapper; import lombok.Data; +import org.dromara.mes.domain.bo.ProdMaterialBomBo; import java.io.Serial; import java.io.Serializable; +import java.math.BigDecimal; +import java.util.ArrayList; import java.util.Date; - +import java.util.List; /** @@ -50,6 +53,11 @@ public class ProdMaterialBomVo implements Serializable { @ExcelProperty(value = "物料名称") private String materialName; + /** + * 物料类型ID + */ + private Long materialTypeId; + /** * bom说明 */ @@ -69,7 +77,7 @@ public class ProdMaterialBomVo implements Serializable { * 标准数量 */ @ExcelProperty(value = "标准数量") - private Long standardAmount; + private BigDecimal standardAmount; /** * 顶级标识(1是 0否) @@ -154,4 +162,11 @@ public class ProdMaterialBomVo implements Serializable { private Date updateTime; + /** 子物料类型结构bom */ + private List children = new ArrayList(); + + private String materialTypeCode;//join字段 + + private String materialTypeName;//join字段 + } diff --git a/ruoyi-modules/hwmom-mes/src/main/java/org/dromara/mes/domain/vo/TreeSelect.java b/ruoyi-modules/hwmom-mes/src/main/java/org/dromara/mes/domain/vo/TreeSelect.java index 458f8a14..6abc7341 100644 --- a/ruoyi-modules/hwmom-mes/src/main/java/org/dromara/mes/domain/vo/TreeSelect.java +++ b/ruoyi-modules/hwmom-mes/src/main/java/org/dromara/mes/domain/vo/TreeSelect.java @@ -1,5 +1,6 @@ package org.dromara.mes.domain.vo; +import com.alibaba.excel.util.StringUtils; import com.fasterxml.jackson.annotation.JsonInclude; import java.io.Serializable; @@ -11,43 +12,74 @@ import java.util.stream.Collectors; * * @author ruoyi */ -public class TreeSelect implements Serializable -{ +public class TreeSelect implements Serializable { private static final long serialVersionUID = 1L; - /** 节点ID */ + /** + * 节点ID + */ private Long id; - /** 父级节点ID */ + /** + * 父级节点ID + */ private Long parentId; - /** 节点名称 */ + /** + * 节点名称 + */ private String label; - /** 子节点 */ + /** + * 子节点 + */ @JsonInclude(JsonInclude.Include.NON_EMPTY) private List children; - public TreeSelect() - { + + private String materialName; + /** + * 物料类型ID + */ + private Long materialTypeId; + + private String materialTypeName; + + private String materialBomVersion; + + + public TreeSelect() { } - public TreeSelect(BaseStructureBomVo baseStructureBomVo) - { + public TreeSelect(BaseStructureBomVo baseStructureBomVo) { this.id = baseStructureBomVo.getMaterialTypeId(); this.label = baseStructureBomVo.getMaterialTypeName(); this.parentId = baseStructureBomVo.getParentId(); this.children = baseStructureBomVo.getChildren().stream().map(TreeSelect::new).collect(Collectors.toList()); } - public Long getId() - { + public TreeSelect(ProdMaterialBomVo prodMaterialBomVo) { + this.id = prodMaterialBomVo.getMaterialBomId(); + if (prodMaterialBomVo.getParentId() == null) { + this.label = prodMaterialBomVo.getMaterialName(); + } else { + this.label = "[" + prodMaterialBomVo.getMaterialBomVersion() + "][" + prodMaterialBomVo.getMaterialTypeName() + "]" + + prodMaterialBomVo.getMaterialName(); + } + this.parentId = prodMaterialBomVo.getParentId(); + this.children = prodMaterialBomVo.getChildren().stream().map(TreeSelect::new).collect(Collectors.toList()); + this.materialName = prodMaterialBomVo.getMaterialName(); + this.materialTypeId = prodMaterialBomVo.getMaterialTypeId(); + this.materialTypeName = prodMaterialBomVo.getMaterialTypeName(); + this.materialBomVersion = prodMaterialBomVo.getMaterialBomVersion(); + } + + public Long getId() { return id; } - public void setId(Long id) - { + public void setId(Long id) { this.id = id; } @@ -59,23 +91,51 @@ public class TreeSelect implements Serializable this.parentId = parentId; } - public String getLabel() - { + public String getLabel() { return label; } - public void setLabel(String label) - { + public void setLabel(String label) { this.label = label; } - public List getChildren() - { + public List getChildren() { return children; } - public void setChildren(List children) - { + public void setChildren(List children) { this.children = children; } + + public String getMaterialName() { + return materialName; + } + + public void setMaterialName(String materialName) { + this.materialName = materialName; + } + + public Long getMaterialTypeId() { + return materialTypeId; + } + + public void setMaterialTypeId(Long materialTypeId) { + this.materialTypeId = materialTypeId; + } + + public String getMaterialTypeName() { + return materialTypeName; + } + + public void setMaterialTypeName(String materialTypeName) { + this.materialTypeName = materialTypeName; + } + + public String getMaterialBomVersion() { + return materialBomVersion; + } + + public void setMaterialBomVersion(String materialBomVersion) { + this.materialBomVersion = materialBomVersion; + } } diff --git a/ruoyi-modules/hwmom-mes/src/main/java/org/dromara/mes/mapper/ProdMaterialBomMapper.java b/ruoyi-modules/hwmom-mes/src/main/java/org/dromara/mes/mapper/ProdMaterialBomMapper.java index 21432eb8..a5348a26 100644 --- a/ruoyi-modules/hwmom-mes/src/main/java/org/dromara/mes/mapper/ProdMaterialBomMapper.java +++ b/ruoyi-modules/hwmom-mes/src/main/java/org/dromara/mes/mapper/ProdMaterialBomMapper.java @@ -1,9 +1,12 @@ package org.dromara.mes.mapper; import org.dromara.mes.domain.ProdMaterialBom; +import org.dromara.mes.domain.bo.ProdMaterialBomBo; import org.dromara.mes.domain.vo.ProdMaterialBomVo; import org.dromara.common.mybatis.core.mapper.BaseMapperPlus; +import java.util.List; + /** * 物料BOM信息Mapper接口 * @@ -12,4 +15,27 @@ import org.dromara.common.mybatis.core.mapper.BaseMapperPlus; */ public interface ProdMaterialBomMapper extends BaseMapperPlus { + /** + * 查询生产bom数据,join material和materialtype + * + * @param podMaterialBomBo 查询条件 + * @return 生产bom信息集合 + */ +// @DataPermission({ +// @DataColumn(key = "deptName", value = "dept_id") +// }) + List selectMaterialBomJoinList(ProdMaterialBomBo podMaterialBomBo); + + + /** + * 查询生产bom数据,join material、materialtype和bomstructure + * + * @param podMaterialBomBo 查询条件 + * @return 生产bom信息集合 + */ +// @DataPermission({ +// @DataColumn(key = "deptName", value = "dept_id") +// }) + List selectMaterialBomJoinStructureList(ProdMaterialBomBo podMaterialBomBo); + } diff --git a/ruoyi-modules/hwmom-mes/src/main/java/org/dromara/mes/service/IProdMaterialBomService.java b/ruoyi-modules/hwmom-mes/src/main/java/org/dromara/mes/service/IProdMaterialBomService.java index 95d9157f..6c62fdb8 100644 --- a/ruoyi-modules/hwmom-mes/src/main/java/org/dromara/mes/service/IProdMaterialBomService.java +++ b/ruoyi-modules/hwmom-mes/src/main/java/org/dromara/mes/service/IProdMaterialBomService.java @@ -3,6 +3,7 @@ package org.dromara.mes.service; import org.dromara.mes.domain.ProdMaterialBom; import org.dromara.mes.domain.vo.ProdMaterialBomVo; import org.dromara.mes.domain.bo.ProdMaterialBomBo; +import org.dromara.mes.domain.vo.TreeSelect; import java.util.Collection; import java.util.List; @@ -63,4 +64,20 @@ public interface IProdMaterialBomService { * @return 如果所有节点都成功插入,返回true;否则抛出异常。 */ Boolean insertBatchByBoList(List boList); + + /** + * 查询符合条件的物料BOM信息列表,join materialtype,material,structurebom + * + * @param bo 查询条件 + * @return 物料BOM信息列表 + */ + public List queryJoinStructureList(ProdMaterialBomBo bo); + + /** + * 查询生产bom信息 + * + * @param bo 生产bom信息 + * @return 生产bom信息集合 + */ + public List selectMaterialBomTreeList(ProdMaterialBomBo bo); } diff --git a/ruoyi-modules/hwmom-mes/src/main/java/org/dromara/mes/service/impl/ProdMaterialBomServiceImpl.java b/ruoyi-modules/hwmom-mes/src/main/java/org/dromara/mes/service/impl/ProdMaterialBomServiceImpl.java index 6767f87f..853a4371 100644 --- a/ruoyi-modules/hwmom-mes/src/main/java/org/dromara/mes/service/impl/ProdMaterialBomServiceImpl.java +++ b/ruoyi-modules/hwmom-mes/src/main/java/org/dromara/mes/service/impl/ProdMaterialBomServiceImpl.java @@ -1,10 +1,15 @@ package org.dromara.mes.service.impl; +import com.alibaba.csp.sentinel.util.StringUtil; +import com.baomidou.mybatisplus.core.toolkit.Wrappers; import org.dromara.common.core.utils.MapstructUtils; import org.dromara.common.core.utils.StringUtils; import com.github.yulichang.toolkit.JoinWrappers; import com.github.yulichang.wrapper.MPJLambdaWrapper; import lombok.RequiredArgsConstructor; +import org.dromara.mes.domain.BaseStructureBom; +import org.dromara.mes.domain.vo.BaseStructureBomVo; +import org.dromara.mes.domain.vo.TreeSelect; import org.springframework.stereotype.Service; import org.dromara.mes.domain.bo.ProdMaterialBomBo; import org.dromara.mes.domain.vo.ProdMaterialBomVo; @@ -12,12 +17,8 @@ import org.dromara.mes.domain.ProdMaterialBom; import org.dromara.mes.mapper.ProdMaterialBomMapper; import org.dromara.mes.service.IProdMaterialBomService; -import java.util.List; -import java.util.Map; -import java.util.Collection; +import java.util.*; import java.util.stream.Collectors; -import java.util.ArrayList; -import java.util.HashMap; import org.springframework.transaction.annotation.Transactional; import cn.hutool.core.collection.CollUtil; @@ -43,7 +44,7 @@ public class ProdMaterialBomServiceImpl implements IProdMaterialBomService { * @return 物料BOM信息 */ @Override - public ProdMaterialBomVo queryById(Long materialBomId){ + public ProdMaterialBomVo queryById(Long materialBomId) { return baseMapper.selectVoById(materialBomId); } @@ -63,23 +64,23 @@ public class ProdMaterialBomServiceImpl implements IProdMaterialBomService { private MPJLambdaWrapper buildQueryWrapper(ProdMaterialBomBo bo) { Map params = bo.getParams(); MPJLambdaWrapper lqw = JoinWrappers.lambda(ProdMaterialBom.class) - .selectAll(ProdMaterialBom.class) - .eq(bo.getMaterialBomId() != null, ProdMaterialBom::getMaterialBomId, bo.getMaterialBomId()) - .eq(bo.getParentId() != null, ProdMaterialBom::getParentId, bo.getParentId()) - .eq(bo.getMaterialId() != null, ProdMaterialBom::getMaterialId, bo.getMaterialId()) - .like(StringUtils.isNotBlank(bo.getMaterialName()), ProdMaterialBom::getMaterialName, bo.getMaterialName()) - .like(StringUtils.isNotBlank(bo.getMaterialBomDesc()), ProdMaterialBom::getMaterialBomDesc, bo.getMaterialBomDesc()) - .like(StringUtils.isNotBlank(bo.getMaterialBomVersion()), ProdMaterialBom::getMaterialBomVersion, bo.getMaterialBomVersion()) - .like(StringUtils.isNotBlank(bo.getAncestors()), ProdMaterialBom::getAncestors, bo.getAncestors()) - .eq(bo.getStandardAmount() != null, ProdMaterialBom::getStandardAmount, bo.getStandardAmount()) - .eq(bo.getTopFlag() != null, ProdMaterialBom::getTopFlag, bo.getTopFlag()) - .eq(StringUtils.isNotBlank(bo.getCheckType()), ProdMaterialBom::getCheckType, bo.getCheckType()) - .eq(bo.getProjectId() != null, ProdMaterialBom::getProjectId, bo.getProjectId()) - .eq(bo.getAssembleTime() != null, ProdMaterialBom::getAssembleTime, bo.getAssembleTime()) - .eq(StringUtils.isNotBlank(bo.getMaterialClassfication()), ProdMaterialBom::getMaterialClassfication, bo.getMaterialClassfication()) - .eq(StringUtils.isNotBlank(bo.getAttachId()), ProdMaterialBom::getAttachId, bo.getAttachId()) - .eq(StringUtils.isNotBlank(bo.getActiveFlag()), ProdMaterialBom::getActiveFlag, bo.getActiveFlag()) - .orderByAsc(ProdMaterialBom::getCreateTime); + .selectAll(ProdMaterialBom.class) + .eq(bo.getMaterialBomId() != null, ProdMaterialBom::getMaterialBomId, bo.getMaterialBomId()) + .eq(bo.getParentId() != null, ProdMaterialBom::getParentId, bo.getParentId()) + .eq(bo.getMaterialId() != null, ProdMaterialBom::getMaterialId, bo.getMaterialId()) + .like(StringUtils.isNotBlank(bo.getMaterialName()), ProdMaterialBom::getMaterialName, bo.getMaterialName()) + .like(StringUtils.isNotBlank(bo.getMaterialBomDesc()), ProdMaterialBom::getMaterialBomDesc, bo.getMaterialBomDesc()) + .like(StringUtils.isNotBlank(bo.getMaterialBomVersion()), ProdMaterialBom::getMaterialBomVersion, bo.getMaterialBomVersion()) + .like(StringUtils.isNotBlank(bo.getAncestors()), ProdMaterialBom::getAncestors, bo.getAncestors()) + .eq(bo.getStandardAmount() != null, ProdMaterialBom::getStandardAmount, bo.getStandardAmount()) + .eq(bo.getTopFlag() != null, ProdMaterialBom::getTopFlag, bo.getTopFlag()) + .eq(StringUtils.isNotBlank(bo.getCheckType()), ProdMaterialBom::getCheckType, bo.getCheckType()) + .eq(bo.getProjectId() != null, ProdMaterialBom::getProjectId, bo.getProjectId()) + .eq(bo.getAssembleTime() != null, ProdMaterialBom::getAssembleTime, bo.getAssembleTime()) + .eq(StringUtils.isNotBlank(bo.getMaterialClassfication()), ProdMaterialBom::getMaterialClassfication, bo.getMaterialClassfication()) + .eq(StringUtils.isNotBlank(bo.getAttachId()), ProdMaterialBom::getAttachId, bo.getAttachId()) + .eq(StringUtils.isNotBlank(bo.getActiveFlag()), ProdMaterialBom::getActiveFlag, bo.getActiveFlag()) + .orderByAsc(ProdMaterialBom::getCreateTime); return lqw; } @@ -115,11 +116,6 @@ public class ProdMaterialBomServiceImpl implements IProdMaterialBomService { */ @Override public Boolean updateByBo(ProdMaterialBomBo bo) { - isTopFlag(bo); - ProdMaterialBomVo info = baseMapper.selectVoById(bo.getParentId()); - if (StringUtils.isNotNull(info)) { - bo.setAncestors(info.getAncestors() + "," + bo.getParentId()); - } ProdMaterialBom update = MapstructUtils.convert(bo, ProdMaterialBom.class); validEntityBeforeSave(update); return baseMapper.updateById(update) > 0; @@ -128,7 +124,7 @@ public class ProdMaterialBomServiceImpl implements IProdMaterialBomService { /** * 保存前的数据校验 */ - private void validEntityBeforeSave(ProdMaterialBom entity){ + private void validEntityBeforeSave(ProdMaterialBom entity) { //TODO 做一些数据校验,如唯一约束 } @@ -141,8 +137,15 @@ public class ProdMaterialBomServiceImpl implements IProdMaterialBomService { */ @Override public Boolean deleteWithValidByIds(Collection ids, Boolean isValid) { - if(isValid){ - //TODO 做一些业务上的校验,判断是否需要校验 + if (isValid) { + ids.forEach(materialBomId -> { + //判断是否有子级物料 + ProdMaterialBom query = new ProdMaterialBom(); + query.setParentId(materialBomId); + if (baseMapper.selectCount(Wrappers.lambdaQuery(query)) > 0) { + throw new ServiceException("生产BOM编号为[" + materialBomId + "]有子级物料,不能删除"); + } + }); } return baseMapper.deleteByIds(ids) > 0; } @@ -163,9 +166,9 @@ public class ProdMaterialBomServiceImpl implements IProdMaterialBomService { } - /** * 根据结构BOM批量插入物料清单BOM。 + * * @param boList 需要插入的物料清单BOM列表。 * @return 如果所有节点都成功插入,返回true;否则抛出异常。 */ @@ -175,76 +178,129 @@ public class ProdMaterialBomServiceImpl implements IProdMaterialBomService { if (CollUtil.isEmpty(boList)) { return false; } - - try { - // 按层级分组(根据parentId分组) - Map> levelMap = new HashMap<>(); - // 1. 首先找出所有顶级节点 - List topNodes = boList.stream() - .filter(bo -> bo.getParentId() == null || bo.getParentId() == 0) - .collect(Collectors.toList()); - // 2. 其他节点按parentId分组 - Map> childrenMap = boList.stream() - .filter(bo -> bo.getParentId() != null && bo.getParentId() != 0) - .collect(Collectors.groupingBy(bo -> Math.abs(bo.getParentId()))); - // 存储临时ID到实际ID的映射 - Map idMapping = new HashMap<>(); - // 3. 优先处理顶级节点,设置基础数据并插入 - for (ProdMaterialBomBo topNode : topNodes) { - Long tempId = Math.abs(topNode.getMaterialBomId()); - topNode.setMaterialBomId(null); // 清除临时ID - topNode.setParentId(0L); // 确保顶级节点parentId为0 - topNode.setAncestors("0"); // 顶级节点的ancestors为"0" - topNode.setTopFlag(1L); // 设置顶级节点的topFlag为1 - // 插入顶级节点 - ProdMaterialBom add = MapstructUtils.convert(topNode, ProdMaterialBom.class); - if (baseMapper.insert(add) <= 0) { - throw new ServiceException("插入顶级节点失败"); - } - // 记录映射关系 - idMapping.put(tempId, add.getMaterialBomId()); - } - // 4. 处理子节点,直到所有节点都处理完 - while (!childrenMap.isEmpty()) { - // 找出当前可以处理的节点(父节点已经在idMapping中的节点) - List processableParentIds = new ArrayList<>(childrenMap.keySet()); - boolean processed = false;// 标记本轮是否有节点被处理 - for (Long parentTempId : processableParentIds) { - // 检查父节点是否已处理 - if (idMapping.containsKey(parentTempId)) { - List children = childrenMap.remove(parentTempId); - // 处理同一父节点的所有子节点 - for (ProdMaterialBomBo child : children) { - Long childTempId = Math.abs(child.getMaterialBomId()); - // 设置实际的父节点ID - child.setMaterialBomId(null);// 清除临时ID - child.setTopFlag(0L); // 设置非顶级节点的topFlag为0 - Long actualParentId = idMapping.get(parentTempId); - child.setParentId(actualParentId); - // 设置祖级列表 - ProdMaterialBom parent = baseMapper.selectById(actualParentId); - child.setAncestors(parent.getAncestors() + "," + actualParentId); - - // 插入子节点 - ProdMaterialBom add = MapstructUtils.convert(child, ProdMaterialBom.class); - if (baseMapper.insert(add) <= 0) { - throw new ServiceException("插入子节点失败"); - } - - // 记录映射关系 - idMapping.put(childTempId, add.getMaterialBomId()); - } - processed = true; + //获取materialbomid不为空的更新,获取materialbomid为空materialid不为空的保存 + for (ProdMaterialBomBo prodMaterialBomBo : boList) { + if (prodMaterialBomBo.getMaterialBomId() == null) { + if (prodMaterialBomBo.getMaterialId() != null) { + if (!insertByBo(prodMaterialBomBo)) { + throw new ServiceException("保存失败"); } } - // 如果一轮循环没有处理任何节点,说明数据有问题 - if (!processed && !childrenMap.isEmpty()) { - throw new ServiceException("存在无法处理的节点,可能是父节点丢失"); + + } else { + if (!updateByBo(prodMaterialBomBo)) { + throw new ServiceException("保存失败"); } } - return true; - } catch (Exception e) { - throw new ServiceException("批量插入失败: " + e.getMessage()); } + + return true; + + } + + + /** + * 查询符合条件的物料BOM信息列表,join materialtype,material,structurebom + * + * @param bo 查询条件 + * @return 物料BOM信息列表 + */ + @Override + public List queryJoinStructureList(ProdMaterialBomBo bo) { + return baseMapper.selectMaterialBomJoinStructureList(bo); + } + + + /** + * 查询生产bom信息 + * + * @param bo 生产bom信息 + * @return 生产bom信息集合 + */ + @Override + public List selectMaterialBomTreeList(ProdMaterialBomBo bo) { + List prodMaterialBomVos = baseMapper.selectMaterialBomJoinList(bo); + return buildMaterialBomTreeSelect(prodMaterialBomVos); } + + + /** + * 构建前端所需要树结构 + * + * @param prodMaterialBomVos 部门列表 + * @return 树结构列表 + */ + private List buildMaterialBomTree(List prodMaterialBomVos) { + List returnList = new ArrayList(); + ProdMaterialBomVo topProdMaterialBomVo = new ProdMaterialBomVo(); + topProdMaterialBomVo.setMaterialBomId(0L); + topProdMaterialBomVo.setMaterialName("生产BOM"); + topProdMaterialBomVo.setMaterialTypeId(-1L); + prodMaterialBomVos.add(topProdMaterialBomVo); + + List tempList = prodMaterialBomVos.stream().map(ProdMaterialBomVo::getMaterialBomId).collect(Collectors.toList()); + for (ProdMaterialBomVo prodMaterialBomVo : prodMaterialBomVos) { + // 如果是顶级节点, 遍历该父节点的所有子节点 + if (!tempList.contains(prodMaterialBomVo.getParentId())) { + recursionFn(prodMaterialBomVos, prodMaterialBomVo); + returnList.add(prodMaterialBomVo); + } + } + if (returnList.isEmpty()) { + returnList = prodMaterialBomVos; + } + return returnList; + } + + /** + * 构建前端所需要下拉树结构 + * + * @param prodMaterialBomVos 生产bom结构树列表 + * @return 下拉树结构列表 + */ + private List buildMaterialBomTreeSelect(List prodMaterialBomVos) { + List materialBomTrees = buildMaterialBomTree(prodMaterialBomVos); + return materialBomTrees.stream().map(TreeSelect::new).collect(Collectors.toList()); + } + + + /** + * 递归列表 + */ + private void recursionFn(List list, ProdMaterialBomVo t) { + // 得到子节点列表 + List childList = getChildList(list, t); + t.setChildren(childList); + for (ProdMaterialBomVo tChild : childList) { + if (hasChild(list, tChild)) { + recursionFn(list, tChild); + } + } + } + + /** + * 得到子节点列表 + */ + private List getChildList(List list, ProdMaterialBomVo t) { + List tlist = new ArrayList(); + Iterator it = list.iterator(); + while (it.hasNext()) { + ProdMaterialBomVo n = (ProdMaterialBomVo) it.next(); + if(StringUtils.isNotBlank(t.getMaterialBomVersion())){ + n.setMaterialBomVersion(t.getMaterialBomVersion()); + } + if (StringUtils.isNotNull(n.getParentId()) && n.getParentId().longValue() == t.getMaterialBomId().longValue()) { + tlist.add(n); + } + } + return tlist; + } + + /** + * 判断是否有子节点 + */ + private boolean hasChild(List list, ProdMaterialBomVo t) { + return getChildList(list, t).size() > 0 ? true : false; + } + } diff --git a/ruoyi-modules/hwmom-mes/src/main/java/org/dromara/mes/service/impl/ProdPlanInfoServiceImpl.java b/ruoyi-modules/hwmom-mes/src/main/java/org/dromara/mes/service/impl/ProdPlanInfoServiceImpl.java index 2af080d6..fbcc5fe8 100644 --- a/ruoyi-modules/hwmom-mes/src/main/java/org/dromara/mes/service/impl/ProdPlanInfoServiceImpl.java +++ b/ruoyi-modules/hwmom-mes/src/main/java/org/dromara/mes/service/impl/ProdPlanInfoServiceImpl.java @@ -131,6 +131,7 @@ public class ProdPlanInfoServiceImpl implements IProdPlanInfoService { bo.setPlanCode(getDispatchCode()); } ProdPlanInfo add = MapstructUtils.convert(bo, ProdPlanInfo.class); + add.setDispatchAmount(add.getPlanAmount()); validEntityBeforeSave(add); String tableName = getPlanInfoTableName(bo.getWorkshopId()); boolean flag = dynamicBaseSqlMapper.dynamicInsert(tableName, DatabaseConstants.TABLE_NAME_PROD_PLAN_INFO_PREFIX, add) > 0; diff --git a/ruoyi-modules/hwmom-mes/src/main/resources/mapper/mes/ProdMaterialBomMapper.xml b/ruoyi-modules/hwmom-mes/src/main/resources/mapper/mes/ProdMaterialBomMapper.xml index 7b825cf3..0820cfc7 100644 --- a/ruoyi-modules/hwmom-mes/src/main/resources/mapper/mes/ProdMaterialBomMapper.xml +++ b/ruoyi-modules/hwmom-mes/src/main/resources/mapper/mes/ProdMaterialBomMapper.xml @@ -4,4 +4,64 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> + + + + + + + +