|
|
|
@ -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<BaseStructureBomVo> queryList(BaseStructureBomBo bo) {
|
|
|
|
|
MPJLambdaWrapper<BaseStructureBom> lqw = buildQueryWrapper(bo);
|
|
|
|
|
return baseMapper.selectVoList(lqw);
|
|
|
|
|
// MPJLambdaWrapper<BaseStructureBom> lqw = buildQueryWrapper(bo);
|
|
|
|
|
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) {
|
|
|
|
|
Map<String, Object> params = bo.getParams();
|
|
|
|
|
MPJLambdaWrapper<BaseStructureBom> 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<Tree<Long>> selectStructureBomTreeList(BaseStructureBomBo bo) {
|
|
|
|
|
public List<TreeSelect> selectStructureBomTreeList(BaseStructureBomBo bo) {
|
|
|
|
|
// bo.setStatus(UserConstants.DEPT_NORMAL);
|
|
|
|
|
MPJLambdaWrapper<BaseStructureBom> lqw = buildQueryWrapper(bo);
|
|
|
|
|
List<BaseStructureBomVo> structureBomVos = baseMapper.selectVoList(lqw);
|
|
|
|
|
// MPJLambdaWrapper<BaseStructureBom> lqw = buildQueryWrapper(bo);
|
|
|
|
|
List<BaseStructureBomVo> structureBomVos = baseMapper.selectStructureBomJoinMaterialTypeList(bo);
|
|
|
|
|
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 下拉树结构列表
|
|
|
|
|
*/
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* *//**
|
|
|
|
|
* 构建前端所需要下拉树结构(此方法有bug,只能按parentid排序才能组成一颗树)
|
|
|
|
|
*
|
|
|
|
|
* @param structureBomVos 物料结构bom列表
|
|
|
|
|
* @return 下拉树结构列表
|
|
|
|
|
*//*
|
|
|
|
|
@Override
|
|
|
|
|
public List<Tree<Long>> buildStructureBomTreeSelect(List<BaseStructureBomVo> structureBomVos) {
|
|
|
|
|
if (CollUtil.isEmpty(structureBomVos)) {
|
|
|
|
@ -184,7 +316,7 @@ public class BaseStructureBomServiceImpl implements IBaseStructureBomService {
|
|
|
|
|
.setParentId(structureBom.getParentId())
|
|
|
|
|
.setName(structureBom.getMaterialTypeName())
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|