From 0c5b9cca2271e7d477db533b0a302fe2b80e8bf5 Mon Sep 17 00:00:00 2001 From: xs Date: Tue, 25 Feb 2025 19:26:10 +0800 Subject: [PATCH] =?UTF-8?q?1.2.1=20=E7=94=9F=E4=BA=A7bom=E7=BB=93=E6=9E=84?= =?UTF-8?q?=E6=A0=91=E5=90=8E=E7=AB=AF=E5=8A=9F=E8=83=BD=E5=AE=8C=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BaseStructureBomController.java | 31 +++- .../mes/domain/bo/BaseStructureBomBo.java | 5 +- .../mes/domain/vo/BaseStructureBomVo.java | 6 +- .../org/dromara/mes/domain/vo/TreeSelect.java | 81 +++++++++ .../mes/mapper/BaseStructureBomMapper.java | 16 +- .../mes/service/IBaseStructureBomService.java | 16 +- .../impl/BaseStructureBomServiceImpl.java | 170 ++++++++++++++++-- .../mapper/mes/BaseStructureBomMapper.xml | 48 +++++ 8 files changed, 342 insertions(+), 31 deletions(-) create mode 100644 ruoyi-modules/hwmom-mes/src/main/java/org/dromara/mes/domain/vo/TreeSelect.java 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 4d95e093..0b7a8da2 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 @@ -7,6 +7,13 @@ import lombok.RequiredArgsConstructor; import jakarta.servlet.http.HttpServletResponse; import jakarta.validation.constraints.*; import cn.dev33.satoken.annotation.SaCheckPermission; +import org.dromara.common.mybatis.core.page.TableDataInfo; +import org.dromara.mes.domain.bo.BaseClassTeamInfoBo; +import org.dromara.mes.domain.bo.BaseMaterialTypeBo; +import org.dromara.mes.domain.vo.BaseClassTeamInfoVo; +import org.dromara.mes.domain.vo.BaseMaterialTypeVo; +import org.dromara.mes.domain.vo.TreeSelect; +import org.dromara.mes.service.IBaseMaterialTypeService; import org.springframework.web.bind.annotation.*; import org.springframework.validation.annotation.Validated; import org.dromara.common.idempotent.annotation.RepeatSubmit; @@ -36,6 +43,7 @@ import org.dromara.mes.service.IBaseStructureBomService; public class BaseStructureBomController extends BaseController { private final IBaseStructureBomService baseStructureBomService; + private final IBaseMaterialTypeService baseMaterialTypeService; /** * 查询结构BOM信息列表 @@ -123,8 +131,29 @@ public class BaseStructureBomController extends BaseController { */ @SaCheckPermission("mes:baseStructureBom:list") @GetMapping("/structureBomTree") - public R>> structureBomTree(BaseStructureBomBo structureBomBo) { + public R> structureBomTree(BaseStructureBomBo structureBomBo) { return R.ok(baseStructureBomService.selectStructureBomTreeList(structureBomBo)); } + + /** + * 查询物料类型结构树信息列表 + */ + @SaCheckPermission("mes:baseStructureBom:list") + @GetMapping("/pageList") + public TableDataInfo pageList(BaseStructureBomBo bo, PageQuery pageQuery) { + return baseStructureBomService.queryPageList(bo,pageQuery); + } + + + /** + * 查询物料类型信息列表 + */ + @SaCheckPermission("mes:baseStructureBom:list") + @GetMapping("/getMaterialTypeList") + public R> list(BaseMaterialTypeBo bo) { + List list = baseMaterialTypeService.queryList(bo); + return R.ok(list); + } + } diff --git a/ruoyi-modules/hwmom-mes/src/main/java/org/dromara/mes/domain/bo/BaseStructureBomBo.java b/ruoyi-modules/hwmom-mes/src/main/java/org/dromara/mes/domain/bo/BaseStructureBomBo.java index 6f7b3abb..b68df526 100644 --- a/ruoyi-modules/hwmom-mes/src/main/java/org/dromara/mes/domain/bo/BaseStructureBomBo.java +++ b/ruoyi-modules/hwmom-mes/src/main/java/org/dromara/mes/domain/bo/BaseStructureBomBo.java @@ -28,12 +28,13 @@ public class BaseStructureBomBo extends BaseEntity { /** * 父级物料类型ID */ + @NotNull(message = "父物料类型ID不能为空", groups = { AddGroup.class, EditGroup.class }) private Long parentId; /** * 物料类型ID */ - @NotBlank(message = "物料类型ID不能为空", groups = { AddGroup.class, EditGroup.class }) + @NotNull(message = "物料类型ID不能为空", groups = { AddGroup.class, EditGroup.class }) private Long materialTypeId; /** @@ -77,4 +78,6 @@ public class BaseStructureBomBo extends BaseEntity { private String remark; + private String materialTypeCode;//join查询字段 + } 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 0cb8862b..98de3123 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 @@ -10,8 +10,9 @@ import lombok.Data; import java.io.Serial; import java.io.Serializable; +import java.util.ArrayList; import java.util.Date; - +import java.util.List; /** @@ -132,5 +133,8 @@ public class BaseStructureBomVo implements Serializable { @ExcelProperty(value = "更新时间") private Date updateTime; + /** 子部门 */ + private List children = new ArrayList(); + private String materialTypeCode;//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 new file mode 100644 index 00000000..458f8a14 --- /dev/null +++ b/ruoyi-modules/hwmom-mes/src/main/java/org/dromara/mes/domain/vo/TreeSelect.java @@ -0,0 +1,81 @@ +package org.dromara.mes.domain.vo; + +import com.fasterxml.jackson.annotation.JsonInclude; + +import java.io.Serializable; +import java.util.List; +import java.util.stream.Collectors; + +/** + * Treeselect树结构实体类 + * + * @author ruoyi + */ +public class TreeSelect implements Serializable +{ + private static final long serialVersionUID = 1L; + + /** 节点ID */ + private Long id; + + /** 父级节点ID */ + private Long parentId; + + /** 节点名称 */ + private String label; + + /** 子节点 */ + @JsonInclude(JsonInclude.Include.NON_EMPTY) + private List children; + + public TreeSelect() + { + + } + + 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() + { + return id; + } + + public void setId(Long id) + { + this.id = id; + } + + public Long getParentId() { + return parentId; + } + + public void setParentId(Long parentId) { + this.parentId = parentId; + } + + public String getLabel() + { + return label; + } + + public void setLabel(String label) + { + this.label = label; + } + + public List getChildren() + { + return children; + } + + public void setChildren(List children) + { + this.children = children; + } +} diff --git a/ruoyi-modules/hwmom-mes/src/main/java/org/dromara/mes/mapper/BaseStructureBomMapper.java b/ruoyi-modules/hwmom-mes/src/main/java/org/dromara/mes/mapper/BaseStructureBomMapper.java index cedb4a14..21338331 100644 --- a/ruoyi-modules/hwmom-mes/src/main/java/org/dromara/mes/mapper/BaseStructureBomMapper.java +++ b/ruoyi-modules/hwmom-mes/src/main/java/org/dromara/mes/mapper/BaseStructureBomMapper.java @@ -6,6 +6,7 @@ import org.apache.ibatis.annotations.Param; import org.dromara.common.mybatis.annotation.DataColumn; import org.dromara.common.mybatis.annotation.DataPermission; import org.dromara.mes.domain.BaseStructureBom; +import org.dromara.mes.domain.bo.BaseStructureBomBo; import org.dromara.mes.domain.vo.BaseStructureBomVo; import org.dromara.common.mybatis.core.mapper.BaseMapperPlus; @@ -20,14 +21,15 @@ import java.util.List; public interface BaseStructureBomMapper extends BaseMapperPlus { /** - * 查询bom结构管理数据 + * 查询物料信息结构bom结构管理数据,join materialtype * - * @param queryWrapper 查询条件 - * @return 部门信息集合 + * @param baseStructureBomBo 查询条件 + * @return 物料信息bom结构信息集合 */ - @DataPermission({ - @DataColumn(key = "deptName", value = "dept_id") - }) - List selectStructureBomList(@Param(Constants.WRAPPER) Wrapper queryWrapper); +// @DataPermission({ +// @DataColumn(key = "deptName", value = "dept_id") +// }) + List selectStructureBomJoinMaterialTypeList(BaseStructureBomBo baseStructureBomBo); + } diff --git a/ruoyi-modules/hwmom-mes/src/main/java/org/dromara/mes/service/IBaseStructureBomService.java b/ruoyi-modules/hwmom-mes/src/main/java/org/dromara/mes/service/IBaseStructureBomService.java index e23b29b7..0c189c3d 100644 --- a/ruoyi-modules/hwmom-mes/src/main/java/org/dromara/mes/service/IBaseStructureBomService.java +++ b/ruoyi-modules/hwmom-mes/src/main/java/org/dromara/mes/service/IBaseStructureBomService.java @@ -1,9 +1,12 @@ package org.dromara.mes.service; import cn.hutool.core.lang.tree.Tree; +import org.dromara.common.mybatis.core.page.PageQuery; +import org.dromara.common.mybatis.core.page.TableDataInfo; import org.dromara.mes.domain.BaseStructureBom; import org.dromara.mes.domain.vo.BaseStructureBomVo; import org.dromara.mes.domain.bo.BaseStructureBomBo; +import org.dromara.mes.domain.vo.TreeSelect; import java.util.Collection; import java.util.List; @@ -33,6 +36,15 @@ public interface IBaseStructureBomService { */ List queryList(BaseStructureBomBo bo); + /** + * 分页查询物料类型结构bom信息列表 + * + * @param bo 查询条件 + * @param pageQuery 分页参数 + * @return 物料结构bom信息分页列表 + */ + public TableDataInfo queryPageList(BaseStructureBomBo bo, PageQuery pageQuery); + /** * 新增结构BOM信息 * @@ -65,7 +77,7 @@ public interface IBaseStructureBomService { * @param bo 物料结构树信息 * @return 物料结构树信息集合 */ - public List> selectStructureBomTreeList(BaseStructureBomBo bo); + public List selectStructureBomTreeList(BaseStructureBomBo bo); /** * 构建前端所需要下拉树结构 @@ -73,5 +85,5 @@ public interface IBaseStructureBomService { * @param structureBomVos 物料结构bom列表 * @return 下拉树结构列表 */ - public List> buildStructureBomTreeSelect(List structureBomVos); +// public List> buildStructureBomTreeSelect(List structureBomVos); } diff --git a/ruoyi-modules/hwmom-mes/src/main/java/org/dromara/mes/service/impl/BaseStructureBomServiceImpl.java b/ruoyi-modules/hwmom-mes/src/main/java/org/dromara/mes/service/impl/BaseStructureBomServiceImpl.java index 994e80ba..04e507c8 100644 --- a/ruoyi-modules/hwmom-mes/src/main/java/org/dromara/mes/service/impl/BaseStructureBomServiceImpl.java +++ b/ruoyi-modules/hwmom-mes/src/main/java/org/dromara/mes/service/impl/BaseStructureBomServiceImpl.java @@ -2,7 +2,9 @@ package org.dromara.mes.service.impl; import cn.hutool.core.collection.CollUtil; import cn.hutool.core.lang.tree.Tree; +import com.alibaba.csp.sentinel.util.StringUtil; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import org.apache.commons.lang3.ObjectUtils; import org.dromara.common.core.constant.UserConstants; import org.dromara.common.core.exception.ServiceException; @@ -13,6 +15,12 @@ import com.github.yulichang.wrapper.MPJLambdaWrapper; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import lombok.RequiredArgsConstructor; import org.dromara.common.core.utils.TreeBuildUtils; +import org.dromara.common.mybatis.core.page.PageQuery; +import org.dromara.common.mybatis.core.page.TableDataInfo; +import org.dromara.mes.domain.BaseClassTeamInfo; +import org.dromara.mes.domain.bo.BaseClassTeamInfoBo; +import org.dromara.mes.domain.vo.BaseClassTeamInfoVo; +import org.dromara.mes.domain.vo.TreeSelect; import org.springframework.stereotype.Service; import org.dromara.mes.domain.bo.BaseStructureBomBo; import org.dromara.mes.domain.vo.BaseStructureBomVo; @@ -20,9 +28,8 @@ import org.dromara.mes.domain.BaseStructureBom; import org.dromara.mes.mapper.BaseStructureBomMapper; import org.dromara.mes.service.IBaseStructureBomService; -import java.util.List; -import java.util.Map; -import java.util.Collection; +import java.util.*; +import java.util.stream.Collectors; /** * 结构BOM信息Service业务层处理 @@ -56,10 +63,28 @@ public class BaseStructureBomServiceImpl implements IBaseStructureBomService { */ @Override public List queryList(BaseStructureBomBo bo) { - MPJLambdaWrapper lqw = buildQueryWrapper(bo); - return baseMapper.selectVoList(lqw); +// MPJLambdaWrapper lqw = buildQueryWrapper(bo); + return baseMapper.selectStructureBomJoinMaterialTypeList(bo); } + /** + * 分页查询物料类型结构bom信息列表 + * + * @param bo 查询条件 + * @param pageQuery 分页参数 + * @return 物料结构bom信息分页列表 + */ + @Override + public TableDataInfo queryPageList(BaseStructureBomBo bo, PageQuery pageQuery) { +/* LambdaQueryWrapper lqw = buildQueryWrapper(bo); + Page result = baseMapper.selectVoPage(pageQuery.build(), lqw); + return TableDataInfo.build(result);*/ + MPJLambdaWrapper lqw = buildQueryWrapper(bo); + Page result = baseMapper.selectVoPage(pageQuery.build(), lqw); + return TableDataInfo.build(result); + } + + private MPJLambdaWrapper buildQueryWrapper(BaseStructureBomBo bo) { Map params = bo.getParams(); MPJLambdaWrapper lqw = JoinWrappers.lambda(BaseStructureBom.class) @@ -90,14 +115,14 @@ public class BaseStructureBomServiceImpl implements IBaseStructureBomService { validEntityBeforeSave(add); //获取父节点信息 - BaseStructureBomVo query = baseMapper.selectVoById(bo.getParentId()); - if (ObjectUtils.isNotEmpty(query)) { - //若父节点不为空,则将父节点的ancestors拼接父节点id拼接成ancestors - add.setAncestors(query.getAncestors() + "," + bo.getParentId()); - }else{ - //若父节点为空,则ancestors仅有父节点id - add.setAncestors(bo.getParentId().toString()); - } +// BaseStructureBomVo query = baseMapper.selectVoById(bo.getParentId()); +// if (ObjectUtils.isNotEmpty(query)) { +// //若父节点不为空,则将父节点的ancestors拼接父节点id拼接成ancestors +// add.setAncestors(query.getAncestors() + "," + bo.getParentId()); +// }else{ +// //若父节点为空,则ancestors仅有父节点id +// add.setAncestors(bo.getParentId().toString()); +// } boolean flag = baseMapper.insert(add) > 0; if (flag) { @@ -123,7 +148,23 @@ public class BaseStructureBomServiceImpl implements IBaseStructureBomService { * 保存前的数据校验 */ private void validEntityBeforeSave(BaseStructureBom entity){ - //TODO 做一些数据校验,如唯一约束 + if(entity.getMaterialTypeId().equals(entity.getParentId())){ + throw new ServiceException("物料类型不能与子级物料类型相同"); + } + BaseStructureBom query = new BaseStructureBom();//同一个物料类型同一个父级,别重复添加 + query.setParentId(entity.getParentId()); + query.setMaterialTypeId(entity.getMaterialTypeId()); + if (baseMapper.selectCount(Wrappers.lambdaQuery(query)) > 0) { + throw new ServiceException("此物料类型下已经有此子级物料类型"); + } + + BaseStructureBom reverseQuery = new BaseStructureBom();//同一个物料类型同一个父级,反过来父级物料类型是物料类型的子级 + reverseQuery.setParentId(entity.getMaterialTypeId()); + reverseQuery.setMaterialTypeId(entity.getParentId()); + if (baseMapper.selectCount(Wrappers.lambdaQuery(reverseQuery)) > 0) { + throw new ServiceException("已经存在此物料类型的父级物料类型是此子级物料类型"); + } + } /** @@ -160,20 +201,111 @@ public class BaseStructureBomServiceImpl implements IBaseStructureBomService { * @return 物料结构树信息集合 */ @Override - public List> selectStructureBomTreeList(BaseStructureBomBo bo) { + public List selectStructureBomTreeList(BaseStructureBomBo bo) { // bo.setStatus(UserConstants.DEPT_NORMAL); - MPJLambdaWrapper lqw = buildQueryWrapper(bo); - List structureBomVos = baseMapper.selectVoList(lqw); +// MPJLambdaWrapper lqw = buildQueryWrapper(bo); + List structureBomVos = baseMapper.selectStructureBomJoinMaterialTypeList(bo); return buildStructureBomTreeSelect(structureBomVos); } + /** + * 构建前端所需要树结构 + * + * @param structureBomVos 部门列表 + * @return 树结构列表 + */ + private List buildStructureBomTree(List structureBomVos) + { + List returnList = new ArrayList(); + List tempList = structureBomVos.stream().map(BaseStructureBomVo::getMaterialTypeId).collect(Collectors.toList()); + for (BaseStructureBomVo structureBomVo : structureBomVos) + { + if(structureBomVo.getMaterialTypeId().equals(-1L) && StringUtil.isBlank(structureBomVo.getMaterialTypeName())){ + structureBomVo.setMaterialTypeName("BOM结构"); + } + // 如果是顶级节点, 遍历该父节点的所有子节点 + if (!tempList.contains(structureBomVo.getParentId())) + { + recursionFn(structureBomVos, structureBomVo); + returnList.add(structureBomVo); + } + } + if (returnList.isEmpty()) + { + returnList = structureBomVos; + } + return returnList; + } + /** * 构建前端所需要下拉树结构 * - * @param structureBomVos 物料结构bom列表 + * @param baseStructureBomVos 生产bom结构树列表 * @return 下拉树结构列表 */ + private List buildStructureBomTreeSelect(List baseStructureBomVos) + { + List structureBomTrees = buildStructureBomTree(baseStructureBomVos); + return structureBomTrees.stream().map(TreeSelect::new).collect(Collectors.toList()); + } + + + /** + * 递归列表 + */ + private void recursionFn(List list, BaseStructureBomVo t) + { + // 得到子节点列表 + List childList = getChildList(list, t); + t.setChildren(childList); + for (BaseStructureBomVo tChild : childList) + { + if (hasChild(list, tChild)) + { + recursionFn(list, tChild); + } + } + } + + /** + * 得到子节点列表 + */ + private List getChildList(List list, BaseStructureBomVo t) + { + List tlist = new ArrayList(); + Iterator it = list.iterator(); + while (it.hasNext()) + { + BaseStructureBomVo n = (BaseStructureBomVo) it.next(); + if (StringUtils.isNotNull(n.getParentId()) && n.getParentId().longValue() == t.getMaterialTypeId().longValue()) + { + tlist.add(n); + } + } + return tlist; + } + + /** + * 判断是否有子节点 + */ + private boolean hasChild(List list, BaseStructureBomVo t) + { + return getChildList(list, t).size() > 0 ? true : false; + } + + + + + + + +/* *//** + * 构建前端所需要下拉树结构(此方法有bug,只能按parentid排序才能组成一颗树) + * + * @param structureBomVos 物料结构bom列表 + * @return 下拉树结构列表 + *//* @Override public List> buildStructureBomTreeSelect(List structureBomVos) { if (CollUtil.isEmpty(structureBomVos)) { @@ -184,7 +316,7 @@ public class BaseStructureBomServiceImpl implements IBaseStructureBomService { .setParentId(structureBom.getParentId()) .setName(structureBom.getMaterialTypeName()) ); - } + }*/ } diff --git a/ruoyi-modules/hwmom-mes/src/main/resources/mapper/mes/BaseStructureBomMapper.xml b/ruoyi-modules/hwmom-mes/src/main/resources/mapper/mes/BaseStructureBomMapper.xml index a8c008f0..e27c3a8b 100644 --- a/ruoyi-modules/hwmom-mes/src/main/resources/mapper/mes/BaseStructureBomMapper.xml +++ b/ruoyi-modules/hwmom-mes/src/main/resources/mapper/mes/BaseStructureBomMapper.xml @@ -4,4 +4,52 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> + + + + + + + + + + + + + + + + + + + + + + + + + +