Merge branch 'feature/DM/nflg-bom' of http://112.74.186.154:3000/nflj/nflg_project into feature/DM/nflg-bom

This commit is contained in:
jing's 2023-12-17 23:39:46 +08:00
commit a33ff76c24
7 changed files with 189 additions and 31 deletions

View File

@ -64,7 +64,7 @@ public class EbomApi extends BaseApi {
@PostMapping("workDetailsListByPage")
@ApiOperation("Ebom-工作明细列表")
public ResultVO<Page<TreeNode<BomNewEbomParentVO>>> workDetailsListByPage(@RequestBody BomNewEbomParentQuery query) {
public ResultVO<Page<BomNewEbomParentVO>> workDetailsListByPage(@RequestBody BomNewEbomParentQuery query) {
return ResultVO.success(bomNewEbomParentService.workDetailsListByPage(query));
}
@ -104,6 +104,17 @@ public class EbomApi extends BaseApi {
return ResultVO.success(true);
}
@PostMapping("convertToPBom")
@ApiOperation("转PBom")
public ResultVO<Boolean> convertToPBom(@RequestBody VirtualPackageParamDto paramDto) {
VUtils.isTure(CollUtil.isEmpty(paramDto.getVirtualPackageValue())).throwMessage("请选择要生成的虚拟包");
bomNewEbomParentService.generateVirtualPackage(paramDto);
VUtils.isTure(true).throwMessage("请选择30开头的或200401类型的物料");
return ResultVO.success(true);
}
@PostMapping("exportBom")

View File

@ -53,5 +53,5 @@ public interface BomNewEbomParentMapper extends BaseMapper<BomNewEbomParentEntit
List<BomNewEbomParentVO> getParentForMaterialNoSeach(@Param("materialNoList") List<String> materialNoList);
List<BomNewEbomParentVO> getChildForMaterialNoSeach(@Param("materialNoList") List<String> materialNoList);
List<BomNewEbomParentVO> getChildForMaterialNoSeach(@Param("materialNoList") List<String> materialNoList,@Param("materialNo") String materialNo);
}

View File

@ -8,6 +8,8 @@ import lombok.experimental.Accessors;
import java.io.Serializable;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.Collections;
import java.util.List;
/**
* t_bom_new_ebom_parent
@ -271,5 +273,7 @@ public class BomNewEbomParentVO extends BaseMaterialVO implements Serializable {
@ApiModelProperty(value = "修改时间")
private LocalDateTime modifyTime;
private List<BomNewEbomParentVO> childNodes = Collections.emptyList();
private static final long serialVersionUID = 1L;
}

View File

@ -79,9 +79,9 @@ public class BomNewEbomParentService extends ServiceImpl<BomNewEbomParentMapper,
* @param query
* @return
*/
public Page<TreeNode<BomNewEbomParentVO>> workDetailsListByPage(BomNewEbomParentQuery query) {
public Page<BomNewEbomParentVO> workDetailsListByPage(BomNewEbomParentQuery query) {
Page<TreeNode<BomNewEbomParentVO>> returnResult = new Page<>();
Page<BomNewEbomParentVO>returnResult = new Page<>();
//物料编码搜索或图号搜索
if(StrUtil.isNotBlank(query.getMaterialNo()) || StrUtil.isNotBlank(query.getDrawingNo())) {
String materialNo=query.getMaterialNo();
@ -95,24 +95,24 @@ public class BomNewEbomParentService extends ServiceImpl<BomNewEbomParentMapper,
List<String> parentMaterialByMaterialNo = getParentMaterialByMaterialNo(materialNo, !userRoleService.technician());
if(CollUtil.isNotEmpty(parentMaterialByMaterialNo)) {
List<BomNewEbomParentVO> parents = this.getBaseMapper().getParentForMaterialNoSeach(parentMaterialByMaterialNo);
List<BomNewEbomParentVO> childs = this.getBaseMapper().getChildForMaterialNoSeach(parentMaterialByMaterialNo);
List<BomNewEbomParentVO> childs = this.getBaseMapper().getChildForMaterialNoSeach(parentMaterialByMaterialNo, materialNo);
returnResult = handSeachToTree(parents, childs);
}
}
}else {
Page<BomNewEbomParentVO> result = this.getBaseMapper().getEBomListPage(new Page<>(query.getPage(), query.getPageSize()), query, userRoleService.getUserJob(), SessionUtil.getUserCode());
materialMainService.intiMaterialInfo(result.getRecords());
Page<TreeNode<BomNewEbomParentVO>> resutlData = new Page<>();
BeanUtil.copyProperties(result, resutlData);
resutlData.setRecords(handNodeToTree(result.getRecords()));
returnResult= resutlData;
returnResult=result;
// materialMainService.intiMaterialInfo(result.getRecords());
// Page<TreeNode<BomNewEbomParentVO>> resutlData = new Page<>();
// BeanUtil.copyProperties(result, resutlData);
// //resutlData.setRecords(handNodeToTree(result.getRecords()));
// returnResult= resutlData;
}
return returnResult;
}
private Page<TreeNode<BomNewEbomParentVO>> handSeachToTree(List<BomNewEbomParentVO> parents, List<BomNewEbomParentVO> childs){
Page<TreeNode<BomNewEbomParentVO>> resutlData = new Page<>();
private Page<BomNewEbomParentVO> handSeachToTree(List<BomNewEbomParentVO> parents, List<BomNewEbomParentVO> childs){
Page<BomNewEbomParentVO> resutlData = new Page<>();
Set<String> parentSet = parents.stream().map(u -> u.getMaterialNo()).collect(Collectors.toSet());
Set<String> childSet = childs.stream().map(u -> u.getMaterialNo()).collect(Collectors.toSet());
Set<String> difference = Sets.difference(parentSet, childSet);
@ -124,23 +124,24 @@ public class BomNewEbomParentService extends ServiceImpl<BomNewEbomParentMapper,
List<BomNewEbomParentVO> all=new ArrayList<>();
all.addAll(parents);
all.addAll(childs);
List<TreeNode<BomNewEbomParentVO>> result=new ArrayList<>();
List<BomNewEbomParentVO> result=new ArrayList<>();
for (BomNewEbomParentVO vo : resultParents) {
result.addAll( TreeUtils.toTree(vo.getRowId(), all, BomNewEbomParentVO::getParentRowId, BomNewEbomParentVO::getBomRowId));
vo.setParentRowId(0L);
result.addAll( CTreeUtils.toTree(0L, all, BomNewEbomParentVO::getParentRowId, BomNewEbomParentVO::getBomRowId));
}
resutlData.setRecords(result);
return resutlData;
}
private List<TreeNode<BomNewEbomParentVO>> handNodeToTree(List<BomNewEbomParentVO> list){
List<TreeNode<BomNewEbomParentVO>> result=new ArrayList<>();
for (BomNewEbomParentVO vo : list) {
TreeNode<BomNewEbomParentVO> treeData= new TreeNode<>();
treeData.setData(vo);
result.add(treeData);
}
return result;
}
// private List<BomNewEbomParentVO> handNodeToTree(List<BomNewEbomParentVO> list){
// List<TreeNode<BomNewEbomParentVO>> result=new ArrayList<>();
// for (BomNewEbomParentVO vo : list) {
// TreeNode<BomNewEbomParentVO> treeData= new TreeNode<>();
// treeData.setData(vo);
// result.add(treeData);
// }
// return result;
// }
/**

View File

@ -0,0 +1,16 @@
package com.nflg.product.bomnew.util;
import lombok.Data;
import org.apache.poi.ss.formula.functions.T;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
public class CTreeNode<T> {
private List<T> childNodes = Collections.emptyList();
}

View File

@ -0,0 +1,125 @@
package com.nflg.product.bomnew.util;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil;
import com.nflg.product.bomnew.pojo.vo.BomNewEbomParentVO;
import javax.validation.constraints.NotNull;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;
/**
*
* @author 大米
* @date 2023/11/18 16:19
*/
public class CTreeUtils {
/**
*
*
* @param dataList 数据
* @param keyFun id
* @param parentKeyFun 父级id
* @param rootKey 顶层的 id 比如部门树的顶层id是0
*/
public static <T, K> List<BomNewEbomParentVO> toTree(K rootKey,
Collection<T> dataList,
@NotNull Function<T, K> parentKeyFun,
@NotNull Function<T, K> keyFun) {
return toFilterTree(rootKey, dataList, parentKeyFun, keyFun, null);
}
/**
*
*
* @param rootKey 顶层的 id 比如部门树的顶层id是0
* @param dataList 数据列
* @param parentKeyFun 取父级id的方法引用
* @param keyFun 取子级id的方法引用
* @param filterNoDataFun 存在这种场景选人的时候某个子部门以及父部门下没有下挂任何人员那么这两个部门直接隐藏避免对用户造成干扰
* 这个参数表示部门实体类人员字段的方法引用
*/
public static <T, K, D> List<BomNewEbomParentVO> toFilterTree(K rootKey,
Collection<T> dataList,
@NotNull Function<T, K> parentKeyFun,
@NotNull Function<T, K> keyFun,
Function<T, D> filterNoDataFun) {
if (CollUtil.isEmpty(dataList)) {
return Collections.emptyList();
}
// 根据父节点对列表进行分组
Map<K, List<T>> groupParentKeyMap = dataList.stream().filter(t -> parentKeyFun.apply(t) != null).collect(Collectors.groupingBy(parentKeyFun));
List<T> rootNodes;
if (rootKey == null) {
rootNodes = dataList.stream().filter(t -> parentKeyFun.apply(t) == null).collect(Collectors.toList());
} else {
rootNodes = groupParentKeyMap.getOrDefault(rootKey, Collections.emptyList());
}
return handlerChildTree(rootNodes, groupParentKeyMap, keyFun, filterNoDataFun);
}
/**
* 列表转树
*/
private static <T, K, D> List<BomNewEbomParentVO> handlerChildTree(Collection<T> rootNodes, Map<K, List<T>> groupParentKeyMap,
Function<T, K> keyFun, Function<T, D> filterNoDataFun) {
if (CollUtil.isEmpty(rootNodes)) {
return Collections.emptyList();
}
List<BomNewEbomParentVO> nodes = new ArrayList<>();
for (T t : rootNodes) {
List<T> childNodesData = groupParentKeyMap.getOrDefault(keyFun.apply(t), Collections.emptyList());
BomNewEbomParentVO node =new BomNewEbomParentVO();
BeanUtil.copyProperties(t,node);
List<BomNewEbomParentVO> treeNodes = handlerChildTree(childNodesData, groupParentKeyMap, keyFun, filterNoDataFun);
if (filterNoDataFun != null && CollUtil.isEmpty(treeNodes)) {
if (skipNoDataNode(filterNoDataFun, t)) {
continue;
}
}
nodes.add(node);
node.setChildNodes(treeNodes);
}
return nodes;
}
/**
* 判断是否为空数据如果没有数据则隐藏
*/
@SuppressWarnings("rawtypes")
private static <T, D> boolean skipNoDataNode(Function<T, D> filterNoDataFun, T t) {
D filterData = filterNoDataFun.apply(t);
if (filterData == null) {
return true;
}
if (filterData instanceof Collection) {
Collection filterDataList = (Collection) filterData;
return CollUtil.isEmpty(filterDataList);
}
return false;
}
/**
* 树转list
*/
public static <T> List<T> toList(List<TreeNode<T>> treeNodeList) {
List<T> resultList = new ArrayList<>();
for (TreeNode<T> treeNode : treeNodeList) {
if (treeNode == null || treeNode.getData() == null) {
continue;
}
resultList.add(treeNode.getData());
if (CollUtil.isNotEmpty(treeNode.getChildNodes())) {
resultList.addAll(toList(treeNode.getChildNodes()));
}
}
return resultList;
}
}

View File

@ -105,15 +105,16 @@
</select>
<!--物料编码搜索-子级-->
<select id="getChildForMaterialNoSeach" resultType="com.nflg.product.bomnew.pojo.vo.BomNewEbomParentVO">
select if(c.status=4,99,c.status) as status ,c.current_version c.created_by as bomCreatedBy ,c.devise_name,c.devise_user_code,c.dept_name ,
c.source, c.row_id as bomRowId, c.row_id as childBomRowId, b.*
from t_bom_new_ebom_parent a
join t_bom_new_ebom_child b on a.row_id =b.parent_row_id
left join t_bom_new_ebom_parent c on b.material_no=c.material_no and c.last_version_is=1
where a.last_version_is=1 and a.material_no in
select if(c.status=4,99,c.status) as status ,c.current_version , c.created_by as bomCreatedBy
,c.devise_name,c.devise_user_code,c.dept_name ,
c.source, c.row_id as bomRowId, c.row_id as childBomRowId, b.*
from t_bom_new_ebom_parent a
join t_bom_new_ebom_child b on a.row_id =b.parent_row_id
left join t_bom_new_ebom_parent c on b.material_no=c.material_no and c.last_version_is=1
where a.last_version_is=1 and ( b.material_no in
<foreach collection="materialNoList" item="item" open="(" separator="," close=")">
#{item}
</foreach>
</foreach> or b.material_no=#{materialNo})
</select>
<!--BOM-正式工作表-->