生产bom结构树后端功能完成
master
xs 4 days ago
parent 5d3fbdc652
commit 0c5b9cca22

@ -7,6 +7,13 @@ import lombok.RequiredArgsConstructor;
import jakarta.servlet.http.HttpServletResponse; import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.*; import jakarta.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission; 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.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
import org.dromara.common.idempotent.annotation.RepeatSubmit; import org.dromara.common.idempotent.annotation.RepeatSubmit;
@ -36,6 +43,7 @@ import org.dromara.mes.service.IBaseStructureBomService;
public class BaseStructureBomController extends BaseController { public class BaseStructureBomController extends BaseController {
private final IBaseStructureBomService baseStructureBomService; private final IBaseStructureBomService baseStructureBomService;
private final IBaseMaterialTypeService baseMaterialTypeService;
/** /**
* BOM * BOM
@ -123,8 +131,29 @@ public class BaseStructureBomController extends BaseController {
*/ */
@SaCheckPermission("mes:baseStructureBom:list") @SaCheckPermission("mes:baseStructureBom:list")
@GetMapping("/structureBomTree") @GetMapping("/structureBomTree")
public R<List<Tree<Long>>> structureBomTree(BaseStructureBomBo structureBomBo) { public R<List<TreeSelect>> structureBomTree(BaseStructureBomBo structureBomBo) {
return R.ok(baseStructureBomService.selectStructureBomTreeList(structureBomBo)); return R.ok(baseStructureBomService.selectStructureBomTreeList(structureBomBo));
} }
/**
*
*/
@SaCheckPermission("mes:baseStructureBom:list")
@GetMapping("/pageList")
public TableDataInfo<BaseStructureBomVo> pageList(BaseStructureBomBo bo, PageQuery pageQuery) {
return baseStructureBomService.queryPageList(bo,pageQuery);
}
/**
*
*/
@SaCheckPermission("mes:baseStructureBom:list")
@GetMapping("/getMaterialTypeList")
public R<List<BaseMaterialTypeVo>> list(BaseMaterialTypeBo bo) {
List<BaseMaterialTypeVo> list = baseMaterialTypeService.queryList(bo);
return R.ok(list);
}
} }

@ -28,12 +28,13 @@ public class BaseStructureBomBo extends BaseEntity {
/** /**
* ID * ID
*/ */
@NotNull(message = "父物料类型ID不能为空", groups = { AddGroup.class, EditGroup.class })
private Long parentId; private Long parentId;
/** /**
* ID * ID
*/ */
@NotBlank(message = "物料类型ID不能为空", groups = { AddGroup.class, EditGroup.class }) @NotNull(message = "物料类型ID不能为空", groups = { AddGroup.class, EditGroup.class })
private Long materialTypeId; private Long materialTypeId;
/** /**
@ -77,4 +78,6 @@ public class BaseStructureBomBo extends BaseEntity {
private String remark; private String remark;
private String materialTypeCode;//join查询字段
} }

@ -10,8 +10,9 @@ import lombok.Data;
import java.io.Serial; import java.io.Serial;
import java.io.Serializable; import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date; import java.util.Date;
import java.util.List;
/** /**
@ -132,5 +133,8 @@ public class BaseStructureBomVo implements Serializable {
@ExcelProperty(value = "更新时间") @ExcelProperty(value = "更新时间")
private Date updateTime; private Date updateTime;
/** 子部门 */
private List<BaseStructureBomVo> children = new ArrayList<BaseStructureBomVo>();
private String materialTypeCode;//join字段
} }

@ -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<TreeSelect> 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<TreeSelect> getChildren()
{
return children;
}
public void setChildren(List<TreeSelect> children)
{
this.children = children;
}
}

@ -6,6 +6,7 @@ import org.apache.ibatis.annotations.Param;
import org.dromara.common.mybatis.annotation.DataColumn; import org.dromara.common.mybatis.annotation.DataColumn;
import org.dromara.common.mybatis.annotation.DataPermission; import org.dromara.common.mybatis.annotation.DataPermission;
import org.dromara.mes.domain.BaseStructureBom; import org.dromara.mes.domain.BaseStructureBom;
import org.dromara.mes.domain.bo.BaseStructureBomBo;
import org.dromara.mes.domain.vo.BaseStructureBomVo; import org.dromara.mes.domain.vo.BaseStructureBomVo;
import org.dromara.common.mybatis.core.mapper.BaseMapperPlus; import org.dromara.common.mybatis.core.mapper.BaseMapperPlus;
@ -20,14 +21,15 @@ import java.util.List;
public interface BaseStructureBomMapper extends BaseMapperPlus<BaseStructureBom, BaseStructureBomVo> { public interface BaseStructureBomMapper extends BaseMapperPlus<BaseStructureBom, BaseStructureBomVo> {
/** /**
* bom * bom,join materialtype
* *
* @param queryWrapper * @param baseStructureBomBo
* @return * @return bom
*/ */
@DataPermission({ // @DataPermission({
@DataColumn(key = "deptName", value = "dept_id") // @DataColumn(key = "deptName", value = "dept_id")
}) // })
List<BaseStructureBomVo> selectStructureBomList(@Param(Constants.WRAPPER) Wrapper<BaseStructureBom> queryWrapper); List<BaseStructureBomVo> selectStructureBomJoinMaterialTypeList(BaseStructureBomBo baseStructureBomBo);
} }

@ -1,9 +1,12 @@
package org.dromara.mes.service; package org.dromara.mes.service;
import cn.hutool.core.lang.tree.Tree; 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.BaseStructureBom;
import org.dromara.mes.domain.vo.BaseStructureBomVo; import org.dromara.mes.domain.vo.BaseStructureBomVo;
import org.dromara.mes.domain.bo.BaseStructureBomBo; import org.dromara.mes.domain.bo.BaseStructureBomBo;
import org.dromara.mes.domain.vo.TreeSelect;
import java.util.Collection; import java.util.Collection;
import java.util.List; import java.util.List;
@ -33,6 +36,15 @@ public interface IBaseStructureBomService {
*/ */
List<BaseStructureBomVo> queryList(BaseStructureBomBo bo); List<BaseStructureBomVo> queryList(BaseStructureBomBo bo);
/**
* bom
*
* @param bo
* @param pageQuery
* @return bom
*/
public TableDataInfo<BaseStructureBomVo> queryPageList(BaseStructureBomBo bo, PageQuery pageQuery);
/** /**
* BOM * BOM
* *
@ -65,7 +77,7 @@ public interface IBaseStructureBomService {
* @param bo * @param bo
* @return * @return
*/ */
public List<Tree<Long>> selectStructureBomTreeList(BaseStructureBomBo bo); public List<TreeSelect> selectStructureBomTreeList(BaseStructureBomBo bo);
/** /**
* *
@ -73,5 +85,5 @@ public interface IBaseStructureBomService {
* @param structureBomVos bom * @param structureBomVos bom
* @return * @return
*/ */
public List<Tree<Long>> buildStructureBomTreeSelect(List<BaseStructureBomVo> structureBomVos); // public List<Tree<Long>> buildStructureBomTreeSelect(List<BaseStructureBomVo> structureBomVos);
} }

@ -2,7 +2,9 @@ package org.dromara.mes.service.impl;
import cn.hutool.core.collection.CollUtil; import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.lang.tree.Tree; 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.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.commons.lang3.ObjectUtils; import org.apache.commons.lang3.ObjectUtils;
import org.dromara.common.core.constant.UserConstants; import org.dromara.common.core.constant.UserConstants;
import org.dromara.common.core.exception.ServiceException; 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 com.baomidou.mybatisplus.core.toolkit.Wrappers;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import org.dromara.common.core.utils.TreeBuildUtils; 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.springframework.stereotype.Service;
import org.dromara.mes.domain.bo.BaseStructureBomBo; import org.dromara.mes.domain.bo.BaseStructureBomBo;
import org.dromara.mes.domain.vo.BaseStructureBomVo; 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.mapper.BaseStructureBomMapper;
import org.dromara.mes.service.IBaseStructureBomService; import org.dromara.mes.service.IBaseStructureBomService;
import java.util.List; import java.util.*;
import java.util.Map; import java.util.stream.Collectors;
import java.util.Collection;
/** /**
* BOMService * BOMService
@ -56,10 +63,28 @@ public class BaseStructureBomServiceImpl implements IBaseStructureBomService {
*/ */
@Override @Override
public List<BaseStructureBomVo> queryList(BaseStructureBomBo bo) { public List<BaseStructureBomVo> queryList(BaseStructureBomBo bo) {
MPJLambdaWrapper<BaseStructureBom> lqw = buildQueryWrapper(bo); // MPJLambdaWrapper<BaseStructureBom> lqw = buildQueryWrapper(bo);
return baseMapper.selectVoList(lqw); return baseMapper.selectStructureBomJoinMaterialTypeList(bo);
} }
/**
* bom
*
* @param bo
* @param pageQuery
* @return bom
*/
@Override
public TableDataInfo<BaseStructureBomVo> queryPageList(BaseStructureBomBo bo, PageQuery pageQuery) {
/* LambdaQueryWrapper<BaseClassTeamInfo> lqw = buildQueryWrapper(bo);
Page<BaseClassTeamInfoVo> result = baseMapper.selectVoPage(pageQuery.build(), lqw);
return TableDataInfo.build(result);*/
MPJLambdaWrapper<BaseStructureBom> lqw = buildQueryWrapper(bo);
Page<BaseStructureBomVo> result = baseMapper.selectVoPage(pageQuery.build(), lqw);
return TableDataInfo.build(result);
}
private MPJLambdaWrapper<BaseStructureBom> buildQueryWrapper(BaseStructureBomBo bo) { private MPJLambdaWrapper<BaseStructureBom> buildQueryWrapper(BaseStructureBomBo bo) {
Map<String, Object> params = bo.getParams(); Map<String, Object> params = bo.getParams();
MPJLambdaWrapper<BaseStructureBom> lqw = JoinWrappers.lambda(BaseStructureBom.class) MPJLambdaWrapper<BaseStructureBom> lqw = JoinWrappers.lambda(BaseStructureBom.class)
@ -90,14 +115,14 @@ public class BaseStructureBomServiceImpl implements IBaseStructureBomService {
validEntityBeforeSave(add); validEntityBeforeSave(add);
//获取父节点信息 //获取父节点信息
BaseStructureBomVo query = baseMapper.selectVoById(bo.getParentId()); // BaseStructureBomVo query = baseMapper.selectVoById(bo.getParentId());
if (ObjectUtils.isNotEmpty(query)) { // if (ObjectUtils.isNotEmpty(query)) {
//若父节点不为空则将父节点的ancestors拼接父节点id拼接成ancestors // //若父节点不为空则将父节点的ancestors拼接父节点id拼接成ancestors
add.setAncestors(query.getAncestors() + "," + bo.getParentId()); // add.setAncestors(query.getAncestors() + "," + bo.getParentId());
}else{ // }else{
//若父节点为空则ancestors仅有父节点id // //若父节点为空则ancestors仅有父节点id
add.setAncestors(bo.getParentId().toString()); // add.setAncestors(bo.getParentId().toString());
} // }
boolean flag = baseMapper.insert(add) > 0; boolean flag = baseMapper.insert(add) > 0;
if (flag) { if (flag) {
@ -123,7 +148,23 @@ public class BaseStructureBomServiceImpl implements IBaseStructureBomService {
* *
*/ */
private void validEntityBeforeSave(BaseStructureBom entity){ 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 * @return
*/ */
@Override @Override
public List<Tree<Long>> selectStructureBomTreeList(BaseStructureBomBo bo) { public List<TreeSelect> selectStructureBomTreeList(BaseStructureBomBo bo) {
// bo.setStatus(UserConstants.DEPT_NORMAL); // bo.setStatus(UserConstants.DEPT_NORMAL);
MPJLambdaWrapper<BaseStructureBom> lqw = buildQueryWrapper(bo); // MPJLambdaWrapper<BaseStructureBom> lqw = buildQueryWrapper(bo);
List<BaseStructureBomVo> structureBomVos = baseMapper.selectVoList(lqw); List<BaseStructureBomVo> structureBomVos = baseMapper.selectStructureBomJoinMaterialTypeList(bo);
return buildStructureBomTreeSelect(structureBomVos); return buildStructureBomTreeSelect(structureBomVos);
} }
/**
*
*
* @param structureBomVos
* @return
*/
private List<BaseStructureBomVo> buildStructureBomTree(List<BaseStructureBomVo> structureBomVos)
{
List<BaseStructureBomVo> returnList = new ArrayList<BaseStructureBomVo>();
List<Long> 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 * @return
*/ */
private List<TreeSelect> buildStructureBomTreeSelect(List<BaseStructureBomVo> baseStructureBomVos)
{
List<BaseStructureBomVo> structureBomTrees = buildStructureBomTree(baseStructureBomVos);
return structureBomTrees.stream().map(TreeSelect::new).collect(Collectors.toList());
}
/**
*
*/
private void recursionFn(List<BaseStructureBomVo> list, BaseStructureBomVo t)
{
// 得到子节点列表
List<BaseStructureBomVo> childList = getChildList(list, t);
t.setChildren(childList);
for (BaseStructureBomVo tChild : childList)
{
if (hasChild(list, tChild))
{
recursionFn(list, tChild);
}
}
}
/**
*
*/
private List<BaseStructureBomVo> getChildList(List<BaseStructureBomVo> list, BaseStructureBomVo t)
{
List<BaseStructureBomVo> tlist = new ArrayList<BaseStructureBomVo>();
Iterator<BaseStructureBomVo> 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<BaseStructureBomVo> list, BaseStructureBomVo t)
{
return getChildList(list, t).size() > 0 ? true : false;
}
/* *//**
* bugparentid
*
* @param structureBomVos bom
* @return
*//*
@Override @Override
public List<Tree<Long>> buildStructureBomTreeSelect(List<BaseStructureBomVo> structureBomVos) { public List<Tree<Long>> buildStructureBomTreeSelect(List<BaseStructureBomVo> structureBomVos) {
if (CollUtil.isEmpty(structureBomVos)) { if (CollUtil.isEmpty(structureBomVos)) {
@ -184,7 +316,7 @@ public class BaseStructureBomServiceImpl implements IBaseStructureBomService {
.setParentId(structureBom.getParentId()) .setParentId(structureBom.getParentId())
.setName(structureBom.getMaterialTypeName()) .setName(structureBom.getMaterialTypeName())
); );
} }*/
} }

@ -4,4 +4,52 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd"> "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="org.dromara.mes.mapper.BaseStructureBomMapper"> <mapper namespace="org.dromara.mes.mapper.BaseStructureBomMapper">
<resultMap type="BaseStructureBom" id="BaseStructureBomResult">
<result property="structureBomId" column="structure_bom_id"/>
<result property="tenantId" column="tenant_id"/>
<result property="parentId" column="parent_id"/>
<result property="materialTypeId" column="material_type_id"/>
<result property="materialTypeName" column="material_type_name"/>
<result property="structureBomDesc" column="structure_bom_desc"/>
<result property="structureBomVersion" column="structure_bom_version"/>
<result property="ancestors" column="ancestors"/>
<result property="level" column="level"/>
<result property="topFlag" column="top_flag"/>
<result property="activeFlag" column="active_flag"/>
<result property="remark" column="remark"/>
<result property="createDept" column="create_dept"/>
<result property="createBy" column="create_by"/>
<result property="createTime" column="create_time"/>
<result property="updateBy" column="update_by"/>
<result property="updateTime" column="update_time"/>
<result property="materialTypeCode" column="material_type_code"/>
</resultMap>
<select id="selectStructureBomJoinMaterialTypeList" parameterType="BaseStructureBomBo" resultType="BaseStructureBomVo">
select
bsb.structure_bom_id,
bsb.material_type_id,
bsb.parent_id,
bsb.create_time,
bsb.update_time,
bmt.matrial_type_code as material_type_code,
bmt.matrial_type_name as material_type_name
from base_structure_bom bsb
left join base_material_type bmt on bsb.material_type_id = bmt.matrial_type_id
<where>
<if test="materialTypeCode != null and materialTypeCode != ''">and bmt.matrial_type_code like concat('%', #{materialTypeCode},
'%')
</if>
<if test="materialTypeName != null and materialTypeName != ''">and bmt.matrial_type_name like concat('%', #{materialTypeName},
'%')
</if>
<if test="parentId != null ">and bsb.parent_id = #{parentId}</if>
</where>
order by bsb.structure_bom_id desc
</select>
</mapper> </mapper>

Loading…
Cancel
Save