原始BOM搜索+虚拟包加单位
This commit is contained in:
parent
b81a9e6cf2
commit
c20932ff1f
|
|
@ -95,13 +95,16 @@ public class OriginalBomApi extends BaseApi {
|
|||
|
||||
@PostMapping("pullFromCad")
|
||||
@ApiOperation("从CAD获取BOM数据") //去除参数 @RequestBody OriginalBomFromPlmQuery dto
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public ResultVO<Boolean> pullFromPlm() {
|
||||
|
||||
originalParentService.pullFromPlm(SessionUtil.getUserCode());
|
||||
|
||||
originalParentService.computeLevelNumAndRootState();
|
||||
|
||||
//更新物料使用
|
||||
originalParentService.getBaseMapper().upOriginalMaterialUse();
|
||||
|
||||
return ResultVO.success(true);
|
||||
}
|
||||
|
||||
|
|
@ -110,6 +113,9 @@ public class OriginalBomApi extends BaseApi {
|
|||
public ResultVO<Boolean> del(@RequestParam("bomRowId") Long bomRowId) throws ExecutionException, InterruptedException {
|
||||
originalParentService.del(bomRowId);
|
||||
originalParentService.computeLevelNumAndRootState();
|
||||
|
||||
//更新物料使用
|
||||
originalParentService.getBaseMapper().upOriginalMaterialUse();
|
||||
return ResultVO.success(true);
|
||||
}
|
||||
|
||||
|
|
@ -165,7 +171,8 @@ public class OriginalBomApi extends BaseApi {
|
|||
//计算层级
|
||||
originalParentService.computeLevelNumAndRootState();
|
||||
|
||||
|
||||
//更新物料使用
|
||||
originalParentService.getBaseMapper().upOriginalMaterialUse();
|
||||
return ResultVO.success(true);
|
||||
}
|
||||
|
||||
|
|
@ -209,14 +216,14 @@ public class OriginalBomApi extends BaseApi {
|
|||
|
||||
@ApiOperation("导出-bom异常物料")
|
||||
@PostMapping("downLoadErrorMaterial")
|
||||
public void downLoadErrorMaterial(HttpServletResponse response){
|
||||
public void downLoadErrorMaterial(HttpServletResponse response) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ApiOperation("test匹配")
|
||||
@PostMapping("testpiPEI")
|
||||
public ResultVO<String> test(@RequestParam("mname") String mname , @RequestParam("textrue")String textrue){
|
||||
public ResultVO<String> test(@RequestParam("mname") String mname, @RequestParam("textrue") String textrue) {
|
||||
MaterialMateCache mateCache = new MaterialMateCache();
|
||||
MaterialMateVO materialMate = mateCache.findMaterialByNameOrmaterialTexture(mname, textrue);
|
||||
return ResultVO.success(materialMate.getMaterialNo());
|
||||
|
|
@ -224,6 +231,4 @@ public class OriginalBomApi extends BaseApi {
|
|||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,15 @@
|
|||
package com.nflg.product.bomnew.mapper.master;
|
||||
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.nflg.product.bomnew.pojo.entity.BomNewOriginalMaterialUseEntity;
|
||||
|
||||
/**
|
||||
* t_bom_new_original_material_use 表数据库访问层
|
||||
* 该物料使用在了哪些零部件上
|
||||
*
|
||||
* @author makejava
|
||||
* @since 2024-01-23 10:22:42
|
||||
*/
|
||||
public interface BomNewOriginalMaterialUseMapper extends BaseMapper<BomNewOriginalMaterialUseEntity> {
|
||||
}
|
||||
|
|
@ -42,4 +42,18 @@ public interface BomNewOriginalParentMapper extends BaseMapper<BomNewOriginalPar
|
|||
|
||||
void updateRootState_2();
|
||||
void updateRootState_3();
|
||||
|
||||
/**
|
||||
* 更新物料使用
|
||||
*/
|
||||
void upOriginalMaterialUse();
|
||||
|
||||
List<String> getDrawingNoByMaterialNos(@Param("materialNos") List<String> materialNos);
|
||||
|
||||
List<BomOriginalListVO> getParentForDrawingNoSeach(@Param("drawingNos") List<String> drawingNos ,@Param("state") Integer state);
|
||||
|
||||
List<BomOriginalListVO> getChildForDrawingNoSeach(@Param("drawingNos") List<String> drawingNos);
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,55 @@
|
|||
package com.nflg.product.bomnew.pojo.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.*;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import java.io.Serializable;
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.LocalDate;
|
||||
|
||||
/**
|
||||
* t_bom_new_original_material_use
|
||||
* 该物料使用在了哪些零部件上
|
||||
*
|
||||
* @author makejava
|
||||
* @since 2024-01-23 10:22:42
|
||||
*/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
@ApiModel(value="com-nflg-product-bomnew-pojo-new-entity-BomNewOriginalMaterialUseEntity")
|
||||
@TableName(value = "t_bom_new_original_material_use")
|
||||
public class BomNewOriginalMaterialUseEntity implements Serializable {
|
||||
|
||||
/**
|
||||
* 主键-雪花ID
|
||||
*/
|
||||
@TableId(value = "row_id", type = IdType.ASSIGN_ID)
|
||||
@ApiModelProperty(value = "主键-雪花ID")
|
||||
private Long rowId;
|
||||
|
||||
/**
|
||||
* drawing_no
|
||||
*/
|
||||
@TableField(value = "drawing_no")
|
||||
@ApiModelProperty(value = "drawing_no")
|
||||
private String drawingNo;
|
||||
|
||||
/**
|
||||
* 父级图号-多个用逗号隔开(单层最新版)
|
||||
*/
|
||||
@TableField(value = "parent_drawing_nos")
|
||||
@ApiModelProperty(value = "父级图号-多个用逗号隔开(单层最新版)")
|
||||
private String parentDrawingNos;
|
||||
|
||||
/**
|
||||
* 父级创建用户-多个用逗号隔开(单层最新版)
|
||||
*/
|
||||
@TableField(value = "parent_create_user")
|
||||
@ApiModelProperty(value = "父级创建用户-多个用逗号隔开(单层最新版)")
|
||||
private String parentCreateUser;
|
||||
|
||||
private static final long serialVersionUID = 914525080365661039L;
|
||||
|
||||
}
|
||||
|
|
@ -7,6 +7,8 @@ import lombok.Data;
|
|||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 原始BOM-列表
|
||||
|
|
@ -179,6 +181,8 @@ public class BomOriginalListVO extends BaseMaterialVO {
|
|||
@ApiModelProperty("转换后Ebom行ID")
|
||||
private Long eBomRowId=0L;
|
||||
|
||||
private List<BomOriginalListVO> childNodes = Collections.emptyList();
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,19 @@
|
|||
package com.nflg.product.bomnew.service;
|
||||
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.nflg.product.bomnew.mapper.master.BomNewOriginalMaterialUseMapper;
|
||||
import com.nflg.product.bomnew.pojo.entity.BomNewOriginalMaterialUseEntity;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* t_bom_new_original_material_use 表服务实现类
|
||||
* 该物料使用在了哪些零部件上
|
||||
*
|
||||
* @author makejava
|
||||
* @since 2024-01-23 10:22:42
|
||||
*/
|
||||
@Service
|
||||
public class BomNewOriginalMaterialUseService extends ServiceImpl<BomNewOriginalMaterialUseMapper, BomNewOriginalMaterialUseEntity> {
|
||||
|
||||
}
|
||||
|
|
@ -8,20 +8,17 @@ import cn.hutool.core.util.StrUtil;
|
|||
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.google.common.collect.Sets;
|
||||
import com.nflg.product.base.core.config.SpringContextUtils;
|
||||
import com.nflg.product.base.core.conmon.util.SessionUtil;
|
||||
import com.nflg.product.base.core.exception.NflgBusinessException;
|
||||
import com.nflg.product.bomnew.constant.OriginalConstant;
|
||||
import com.nflg.product.bomnew.constant.OriginalEditStatusEnum;
|
||||
import com.nflg.product.bomnew.constant.OriginalSourceEnum;
|
||||
import com.nflg.product.bomnew.constant.OriginalStatusEnum;
|
||||
import com.nflg.product.bomnew.constant.*;
|
||||
import com.nflg.product.bomnew.mapper.master.BomNewOriginalParentMapper;
|
||||
import com.nflg.product.bomnew.pojo.dto.BomNewOriginalExcelDTO;
|
||||
import com.nflg.product.bomnew.pojo.dto.OriginalSaveBomDTO;
|
||||
import com.nflg.product.bomnew.pojo.entity.BomNewOriginalChildEntity;
|
||||
import com.nflg.product.bomnew.pojo.entity.BomNewOriginalParentEntity;
|
||||
import com.nflg.product.bomnew.pojo.entity.BomOriginalCadParentEntity;
|
||||
import com.nflg.product.bomnew.pojo.entity.*;
|
||||
import com.nflg.product.bomnew.pojo.query.OriginalBomQuery;
|
||||
import com.nflg.product.bomnew.pojo.vo.BomNewEbomParentVO;
|
||||
import com.nflg.product.bomnew.pojo.vo.BomOriginalListVO;
|
||||
import com.nflg.product.bomnew.pojo.vo.BomOriginalPlmBomVO;
|
||||
import com.nflg.product.bomnew.service.domain.EBom.CheckEBomException;
|
||||
|
|
@ -82,6 +79,60 @@ public class BomNewOriginalParentService extends ServiceImpl<BomNewOriginalParen
|
|||
@Resource
|
||||
BomNewOriginalParentService parentService;
|
||||
|
||||
@Resource
|
||||
BomNewOriginalMaterialUseService originalMaterialUseService;
|
||||
|
||||
|
||||
|
||||
|
||||
public Set<String> getParentDrawingNoByMaterialNo(List<String> drawingNos) {
|
||||
List<BomNewOriginalMaterialUseEntity> draringEnts = originalMaterialUseService.lambdaQuery().in(BomNewOriginalMaterialUseEntity::getDrawingNo, drawingNos).list();
|
||||
List<String[]> draringNosList = draringEnts.stream().map(u -> StrUtil.split(u.getParentDrawingNos(), ",") ).collect(Collectors.toList());
|
||||
List<String> draringNos = draringNosList.stream().flatMap(Arrays::stream).collect(Collectors.toList());
|
||||
Set<String> result = new HashSet<>();
|
||||
if (CollUtil.isNotEmpty(draringNos)) {
|
||||
Set<String> relSkuNo = Sets.newHashSet(draringNos);
|
||||
while (CollUtil.isNotEmpty(relSkuNo)) {
|
||||
List<BomNewOriginalMaterialUseEntity> relSkuList = originalMaterialUseService.lambdaQuery().in(BomNewOriginalMaterialUseEntity::getDrawingNo, relSkuNo).list();
|
||||
result.addAll(relSkuNo);
|
||||
relSkuNo.clear();
|
||||
Set<String> finalRelSkuNo = relSkuNo;
|
||||
relSkuList.forEach(k -> {
|
||||
if (StrUtil.isNotBlank(k.getParentDrawingNos())) {
|
||||
finalRelSkuNo.addAll(Sets.newHashSet(StrUtil.split(k.getParentDrawingNos(), ",")));
|
||||
}
|
||||
});
|
||||
relSkuNo = finalRelSkuNo;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private Page<BomOriginalListVO> handSeachToTree(List<BomOriginalListVO> parents, List<BomOriginalListVO> childs) {
|
||||
Page<BomOriginalListVO> resutlData = new Page<>();
|
||||
Set<String> parentSet = parents.stream().map(u -> u.getDrawingNo()).collect(Collectors.toSet());
|
||||
Set<String> childSet = childs.stream().map(u -> u.getDrawingNo()).collect(Collectors.toSet());
|
||||
Set<String> difference = Sets.difference(parentSet, childSet);
|
||||
List<BomOriginalListVO> resultParents = parents.stream().filter(u -> difference.contains(u.getDrawingNo())).collect(Collectors.toList());
|
||||
resutlData.setTotal(difference.size());
|
||||
resutlData.setSize(difference.size());
|
||||
resutlData.setPages(1);
|
||||
resutlData.setCurrent(1L);
|
||||
List<BomOriginalListVO> all = new ArrayList<>();
|
||||
// all.addAll(resultParents);
|
||||
all.addAll(childs);
|
||||
List<BomOriginalListVO> result = new ArrayList<>();
|
||||
for (BomOriginalListVO vo : resultParents) {
|
||||
vo.setParentRowId(0L);
|
||||
List<BomOriginalListVO> da = new ArrayList<>();
|
||||
da.addAll(childs);
|
||||
da.add(vo);
|
||||
result.addAll(OriginalCTreeUtils.toTree(0L, da, BomOriginalListVO::getParentRowId, BomOriginalListVO::getBomRowId));
|
||||
}
|
||||
resutlData.setRecords(result);
|
||||
return resutlData;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取原始BOM列表
|
||||
*
|
||||
|
|
@ -89,13 +140,41 @@ public class BomNewOriginalParentService extends ServiceImpl<BomNewOriginalParen
|
|||
* @return 原始BOM列表
|
||||
*/
|
||||
public Page<BomOriginalListVO> getOriginalBomListPage(OriginalBomQuery query) {
|
||||
Page<BomOriginalListVO> result = this.getBaseMapper().getOriginalBomListPage(new Page<>(query.getPage(), query.getPageSize()), query, SessionUtil.getUserCode());
|
||||
Page<BomOriginalListVO> result=null;
|
||||
//物料编码搜索或图号搜索
|
||||
if (CollUtil.isNotEmpty(query.getMaterialNos()) || CollUtil.isNotEmpty(query.getDrawingNos())) {
|
||||
List<String> queryDrawingNos= new ArrayList<>();
|
||||
queryDrawingNos.addAll(query.getDrawingNos());
|
||||
if (CollUtil.isNotEmpty(query.getMaterialNos())) {
|
||||
List<String> drawingNos = this.getBaseMapper().getDrawingNoByMaterialNos(query.getMaterialNos());
|
||||
if (CollUtil.isNotEmpty(drawingNos)) {
|
||||
queryDrawingNos.addAll(drawingNos);
|
||||
}
|
||||
}
|
||||
if (CollUtil.isNotEmpty(queryDrawingNos)) {
|
||||
List<String> parentDrawingNos = getParentDrawingNoByMaterialNo(queryDrawingNos).stream().collect(Collectors.toList());
|
||||
parentDrawingNos.addAll(queryDrawingNos);
|
||||
if (CollUtil.isNotEmpty(parentDrawingNos)) {
|
||||
List<BomOriginalListVO> parents = this.getBaseMapper().getParentForDrawingNoSeach(parentDrawingNos, query.getStatus());
|
||||
List<BomOriginalListVO> childs = this.getBaseMapper().getChildForDrawingNoSeach(parentDrawingNos);
|
||||
List<BomOriginalListVO> data = new ArrayList<>();
|
||||
data.addAll(parents);
|
||||
data.addAll(childs);
|
||||
materialMainService.intiMaterialInfo(data, EBomConstant.EBOM_IGNORED_FIELDS_INIT_MATERIAL_DEFAULT);
|
||||
result = handSeachToTree(parents, childs);
|
||||
}
|
||||
}
|
||||
}else {
|
||||
|
||||
materialMainService.intiMaterialInfo(result.getRecords());
|
||||
result = this.getBaseMapper().getOriginalBomListPage(new Page<>(query.getPage(), query.getPageSize()), query, SessionUtil.getUserCode());
|
||||
materialMainService.intiMaterialInfo(result.getRecords());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 编辑时-暂存
|
||||
*
|
||||
|
|
@ -189,7 +268,7 @@ public class BomNewOriginalParentService extends ServiceImpl<BomNewOriginalParen
|
|||
//child.setStatus(OriginalStatusEnum.UN_CONVERT.getValue());
|
||||
// child.setEditStatus(OriginalEditStatusEnum.HANDLER_CREATED.getValue());
|
||||
}
|
||||
}catch (Exception e){
|
||||
} catch (Exception e) {
|
||||
e.getMessage();
|
||||
}
|
||||
|
||||
|
|
@ -214,17 +293,16 @@ public class BomNewOriginalParentService extends ServiceImpl<BomNewOriginalParen
|
|||
|
||||
/**
|
||||
* 退回
|
||||
*
|
||||
*/
|
||||
public void revertBom(List<Long> sourceIds){
|
||||
public void revertBom(List<Long> sourceIds) {
|
||||
|
||||
if(CollectionUtil.isEmpty(sourceIds)){
|
||||
return;
|
||||
}
|
||||
if (CollectionUtil.isEmpty(sourceIds)) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.getBaseMapper().updateRevertBom(OriginalStatusEnum.UN_CONVERT.getValue(),
|
||||
OriginalEditStatusEnum.HANDLER_CREATED.getValue(),
|
||||
sourceIds);
|
||||
this.getBaseMapper().updateRevertBom(OriginalStatusEnum.UN_CONVERT.getValue(),
|
||||
OriginalEditStatusEnum.HANDLER_CREATED.getValue(),
|
||||
sourceIds);
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -259,7 +337,7 @@ public class BomNewOriginalParentService extends ServiceImpl<BomNewOriginalParen
|
|||
|
||||
if (CollUtil.isNotEmpty(list)) {
|
||||
for (BomNewOriginalParentEntity bom : list) {
|
||||
// bom.setRootIs(1);
|
||||
// bom.setRootIs(1);
|
||||
List<BomOriginalListVO> bomDetail = this.getBaseMapper().getParentChild(bom.getRowId());
|
||||
OriginalBomDetailTask detailTask = new OriginalBomDetailTask(bomDetail);
|
||||
detailTask.setLevelNum(1);
|
||||
|
|
@ -360,17 +438,19 @@ public class BomNewOriginalParentService extends ServiceImpl<BomNewOriginalParen
|
|||
public Boolean convertToEBom(List<Long> bomRowIds) throws ExecutionException, InterruptedException {
|
||||
List<BomNewOriginalParentEntity> bomNewOriginalParentEntities = this.getBaseMapper().selectBatchIds(bomRowIds);
|
||||
|
||||
List<BomNewOriginalParentEntity> convertedBom = bomNewOriginalParentEntities.stream().filter(u -> OriginalStatusEnum.OVER_CONVERT.equalsValue(u.getStatus())).collect(Collectors.toList());
|
||||
//List<BomNewOriginalParentEntity> convertedBom = bomNewOriginalParentEntities.stream().filter(u -> OriginalStatusEnum.OVER_CONVERT.equalsValue(u.getStatus())).collect(Collectors.toList());
|
||||
// VUtils.isTure(CollUtil.isNotEmpty(convertedBom)).throwMessage("所选BOM中存在已转换的BOM");
|
||||
//检查:有子级的物料编码不能为空
|
||||
|
||||
|
||||
//开始转换
|
||||
for (BomNewOriginalParentEntity parent : bomNewOriginalParentEntities) {
|
||||
|
||||
Long ebomRowId= IdWorker.getId();
|
||||
convertToEBomDo(parent,ebomRowId);
|
||||
Long ebomRowId = IdWorker.getId();
|
||||
convertToEBomDo(parent, ebomRowId);
|
||||
|
||||
//更新并保存异常信息
|
||||
ebomParentService.checkAndSaveEBomException( ebomRowId);
|
||||
ebomParentService.checkAndSaveEBomException(ebomRowId);
|
||||
|
||||
}
|
||||
return true;
|
||||
|
|
@ -383,10 +463,14 @@ public class BomNewOriginalParentService extends ServiceImpl<BomNewOriginalParen
|
|||
* @param parent
|
||||
*/
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void convertToEBomDo(BomNewOriginalParentEntity parent , Long eBomRowId) throws ExecutionException, InterruptedException {
|
||||
public void convertToEBomDo(BomNewOriginalParentEntity parent, Long eBomRowId) throws ExecutionException, InterruptedException {
|
||||
//获取整颗树的BOM
|
||||
List<BomOriginalListVO> bomAllChildList = this.getBomTree(parent.getRowId());
|
||||
|
||||
//检查-有子级的物料,编码不能为空
|
||||
List<String> noMaterialDrawing = bomAllChildList.stream().filter(u -> u.getBomRowId() > 0 && StrUtil.isBlank(u.getMaterialNo())).map(u -> u.getDrawingNo()).collect(Collectors.toList());
|
||||
VUtils.isTure(CollUtil.isNotEmpty(noMaterialDrawing)).throwMessage(StrUtil.join(",", noMaterialDrawing)+" 请维护物料编码");
|
||||
|
||||
BomOriginalListVO parentVO = Convert.convert(BomOriginalListVO.class, parent);
|
||||
parentVO.setEBomRowId(eBomRowId);
|
||||
OriginalBomToEBomConvert convert = new OriginalBomToEBomConvert(parentVO, bomAllChildList);
|
||||
|
|
@ -435,7 +519,7 @@ public class BomNewOriginalParentService extends ServiceImpl<BomNewOriginalParen
|
|||
data.setUuid(uuid);
|
||||
}
|
||||
List<BomNewOriginalExcelDTO> noMaterialNoList = excelContext.stream().filter(u -> StrUtil.isBlank(u.getMaterialNo())).collect(Collectors.toList());
|
||||
materialMainService.initMaterialForDrawdingNo(noMaterialNoList,BomNewOriginalExcelDTO::getChartNo,BomNewOriginalExcelDTO::setMaterialNo,BomNewOriginalExcelDTO::setMaterialName);
|
||||
materialMainService.initMaterialForDrawdingNo(noMaterialNoList, BomNewOriginalExcelDTO::getChartNo, BomNewOriginalExcelDTO::setMaterialNo, BomNewOriginalExcelDTO::setMaterialName);
|
||||
|
||||
//转换
|
||||
for (BomNewOriginalExcelDTO data : excelContext) {
|
||||
|
|
|
|||
|
|
@ -185,6 +185,7 @@ public class MaterialService {
|
|||
ma.setMaterialClass(0);
|
||||
ma.setProcessState(0);
|
||||
ma.setApplyUserCode(SessionUtil.getRealName());
|
||||
ma.setMaterialUnit("PC");
|
||||
resultList.add(ma);
|
||||
|
||||
AddMaterialMainDTO ent=new AddMaterialMainDTO();
|
||||
|
|
|
|||
|
|
@ -0,0 +1,126 @@
|
|||
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 com.nflg.product.bomnew.pojo.vo.BomOriginalListVO;
|
||||
|
||||
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 OriginalCTreeUtils {
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @param dataList 数据
|
||||
* @param keyFun id
|
||||
* @param parentKeyFun 父级id
|
||||
* @param rootKey 顶层的 id 值 ,比如部门树的顶层id是0
|
||||
*/
|
||||
public static <T, K> List<BomOriginalListVO> 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<BomOriginalListVO> 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<BomOriginalListVO> 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<BomOriginalListVO> nodes = new ArrayList<>();
|
||||
for (T t : rootNodes) {
|
||||
List<T> childNodesData = groupParentKeyMap.getOrDefault(keyFun.apply(t), Collections.emptyList());
|
||||
BomOriginalListVO node =new BomOriginalListVO();
|
||||
BeanUtil.copyProperties(t,node);
|
||||
|
||||
List<BomOriginalListVO> 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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.nflg.product.bomnew.mapper.master.BomNewOriginalMaterialUseMapper">
|
||||
|
||||
<resultMap id="BaseResultMap" type="com.nflg.product.bomnew.pojo.entity.BomNewOriginalMaterialUseEntity">
|
||||
<!--@mbg.generated-->
|
||||
<!--@Table t_bom_new_original_material_use -->
|
||||
<id column="row_id" property="rowId" jdbcType="BIGINT"/>
|
||||
<result column="drawing_no" property="drawingNo" jdbcType="VARCHAR"/>
|
||||
<result column="parent_drawing_nos" property="parentDrawingNos" jdbcType="VARCHAR"/>
|
||||
<result column="parent_create_user" property="parentCreateUser" jdbcType="VARCHAR"/>
|
||||
</resultMap>
|
||||
|
||||
<sql id="Base_Column_List">
|
||||
<!--@mbg.generated-->
|
||||
row_id, drawing_no, parent_drawing_nos, parent_create_user </sql>
|
||||
|
||||
</mapper>
|
||||
|
|
@ -45,24 +45,24 @@
|
|||
<sql id="whr">
|
||||
<if test="query.status!= null">
|
||||
<if test="query.status==2">
|
||||
and status=2
|
||||
and status=2
|
||||
|
||||
<if test="query.startDate==null or query.startDate==''">
|
||||
and convert_to_ebom_time> DATE_ADD(now(), INTERVAL -3 DAY)
|
||||
</if>
|
||||
<if test="query.startDate==null or query.startDate==''">
|
||||
and convert_to_ebom_time> DATE_ADD(now(), INTERVAL -3 DAY)
|
||||
</if>
|
||||
</if>
|
||||
<if test="query.status==1">
|
||||
and status=1
|
||||
</if>
|
||||
</if>
|
||||
<if test="query.drawingNos!=null and query.drawingNos.size()>0">
|
||||
and drawing_no in
|
||||
and drawing_no in
|
||||
<foreach collection="query.drawingNos" item="drawingNo" open="(" separator="," close=")">
|
||||
#{drawingNo}
|
||||
</foreach>
|
||||
</if>
|
||||
<if test="query.materialNos!=null and query.materialNos.size()>0">
|
||||
and material_no in
|
||||
and material_no in
|
||||
<foreach collection="query.materialNos" item="materialNo" open="(" separator="," close=")">
|
||||
#{materialNo}
|
||||
</foreach>
|
||||
|
|
@ -76,7 +76,7 @@
|
|||
<select id="getOriginalBomListPage" resultType="com.nflg.product.bomnew.pojo.vo.BomOriginalListVO">
|
||||
select * , 0 as parentRowId , row_id as bomRowId
|
||||
from t_bom_new_original_parent
|
||||
where (root_is | user_root_is=1 )
|
||||
where (root_is | user_root_is=1 )
|
||||
<include refid="whr"/>
|
||||
order by user_root_is desc , created_time desc
|
||||
</select>
|
||||
|
|
@ -96,29 +96,27 @@
|
|||
<foreach collection="rowIds" item="rowId" open="(" separator="," close=")">
|
||||
#{rowId}
|
||||
</foreach>
|
||||
|
||||
</select>
|
||||
|
||||
<delete id="delBatch">
|
||||
delete from t_bom_new_original_parent where row_id in
|
||||
<foreach collection="rowIds" item="rowId" open="(" separator="," close=")">
|
||||
#{rowId}
|
||||
</foreach>;
|
||||
delete from t_bom_new_original_child where parent_row_id in
|
||||
<foreach collection="rowIds" item="rowId" open="(" separator="," close=")">
|
||||
#{rowId}
|
||||
</foreach>;
|
||||
delete from t_bom_new_original_parent where row_id in
|
||||
<foreach collection="rowIds" item="rowId" open="(" separator="," close=")">
|
||||
#{rowId}
|
||||
</foreach>;
|
||||
delete from t_bom_new_original_child where parent_row_id in
|
||||
<foreach collection="rowIds" item="rowId" open="(" separator="," close=")">
|
||||
#{rowId}
|
||||
</foreach>;
|
||||
</delete>
|
||||
|
||||
<update id="updateRevertBom">
|
||||
|
||||
update t_bom_new_original_parent set status = #{status},edit_status=#{editStatus} where
|
||||
update t_bom_new_original_parent set status = #{status},edit_status=#{editStatus} where
|
||||
row_id in
|
||||
<foreach collection="rowIds" item="rowId" open="(" separator="," close=")">
|
||||
#{rowId}
|
||||
</foreach>;
|
||||
|
||||
update t_bom_new_original_child set status = #{status},edit_status=#{editStatus} where
|
||||
update t_bom_new_original_child set status = #{status},edit_status=#{editStatus} where
|
||||
parent_row_id in
|
||||
<foreach collection="rowIds" item="rowId" open="(" separator="," close=")">
|
||||
#{rowId}
|
||||
|
|
@ -126,12 +124,9 @@
|
|||
</update>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<update id="updateBomState">
|
||||
update t_bom_new_original_parent set status = #{status},edit_status=#{editStatus}, convert_to_ebom_time=now() where
|
||||
update t_bom_new_original_parent set status = #{status},edit_status=#{editStatus}, convert_to_ebom_time=now()
|
||||
where
|
||||
row_id in
|
||||
<foreach collection="rowIds" item="rowId" open="(" separator="," close=")">
|
||||
#{rowId}
|
||||
|
|
@ -145,26 +140,86 @@
|
|||
</update>
|
||||
|
||||
<update id="updateRootState_1">
|
||||
|
||||
update t_bom_new_original_parent set root_is=0,user_root_is=0 where last_version_is=1
|
||||
|
||||
update t_bom_new_original_parent
|
||||
set root_is=0,
|
||||
user_root_is=0
|
||||
where last_version_is = 1
|
||||
</update>
|
||||
<update id="updateRootState_2">
|
||||
update t_bom_new_original_parent a join (
|
||||
select a.row_id from t_bom_new_original_parent a
|
||||
update t_bom_new_original_parent a join (
|
||||
select a.row_id from t_bom_new_original_parent a
|
||||
left join t_bom_new_original_child b
|
||||
on a.drawing_no=b.drawing_no
|
||||
where a.last_version_is=1 and b.row_id is null ) t on a.row_id=t.row_id set a.root_is=1
|
||||
where a.last_version_is=1 and b.row_id is null ) t
|
||||
on a.row_id=t.row_id set a.root_is=1
|
||||
</update>
|
||||
|
||||
<update id="updateRootState_3">
|
||||
update t_bom_new_original_parent a join (
|
||||
select a.row_id from t_bom_new_original_parent a
|
||||
update t_bom_new_original_parent a join (
|
||||
select a.row_id from t_bom_new_original_parent a
|
||||
left join t_bom_new_original_child b
|
||||
on a.drawing_no=b.drawing_no and a.created_by=b.created_by
|
||||
where a.last_version_is=1 and b.row_id is null ) t on a.row_id=t.row_id set a.user_root_is=1
|
||||
on a.drawing_no=b.drawing_no and a.created_by=b.created_by
|
||||
where a.last_version_is=1 and b.row_id is null ) t
|
||||
on a.row_id=t.row_id set a.user_root_is=1
|
||||
</update>
|
||||
|
||||
<insert id="upOriginalMaterialUse">
|
||||
SET @@global.group_concat_max_len=804800;
|
||||
truncate table t_bom_new_original_material_use;
|
||||
INSERT INTO `t_bom_new_original_material_use` (`row_id`, `drawing_no`, `parent_drawing_nos`)
|
||||
|
||||
select min(b.row_id) rowId, b.drawing_no, GROUP_CONCAt(distinct a.drawing_no) as value_list
|
||||
from t_bom_new_original_parent a
|
||||
join t_bom_new_original_child b on a.row_id = b.parent_row_id and a.last_version_is = 1
|
||||
group by b.drawing_no;
|
||||
</insert>
|
||||
|
||||
|
||||
<!--获取编码获取图号-->
|
||||
<select id="getDrawingNoByMaterialNos" resultType="java.lang.String">
|
||||
select drawing_no from t_bom_new_original_child where material_no in
|
||||
<foreach collection="materialNos" item="materialNo" open="(" separator="," close=")">
|
||||
#{materialNo}
|
||||
</foreach>
|
||||
union all
|
||||
select drawing_no from t_bom_new_original_parent where material_no in
|
||||
<foreach collection="materialNos" item="materialNo" open="(" separator="," close=")">
|
||||
#{materialNo}
|
||||
</foreach>
|
||||
</select>
|
||||
|
||||
|
||||
<!--物料编码搜索-父级-->
|
||||
<select id="getParentForDrawingNoSeach" resultType="com.nflg.product.bomnew.pojo.vo.BomOriginalListVO">
|
||||
SELECT created_by as bomCreatedBy , row_id as bomRowId, row_id as childBomRowId, a.*
|
||||
FROM t_bom_new_original_parent a where 1=1
|
||||
<if test="state==1">
|
||||
and a.last_version_is=1 and status=1
|
||||
</if>
|
||||
<if test="state==2">
|
||||
and current_version in ( select current_version from t_bom_new_original_parent where status >1 and drawing_no in
|
||||
<foreach collection="drawingNos" item="item" open="(" separator="," close=")">
|
||||
#{item}
|
||||
</foreach>
|
||||
)
|
||||
</if>
|
||||
and drawing_no in
|
||||
<foreach collection="drawingNos" item="item" open="(" separator="," close=")">
|
||||
#{item}
|
||||
</foreach>
|
||||
</select>
|
||||
<!--物料编码搜索-子级-->
|
||||
<select id="getChildForDrawingNoSeach" resultType="com.nflg.product.bomnew.pojo.vo.BomOriginalListVO">
|
||||
select if(c.status=2,3,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_original_parent a
|
||||
join t_bom_new_original_child b on a.row_id =b.parent_row_id
|
||||
left join t_bom_new_original_parent c on b.drawing_no=c.drawing_no and c.last_version_is=1
|
||||
where a.last_version_is=1 and b.drawing_no in
|
||||
<foreach collection="drawingNos" item="item" open="(" separator="," close=")">
|
||||
#{item}
|
||||
</foreach>
|
||||
|
||||
</select>
|
||||
</mapper>
|
||||
|
|
|
|||
Loading…
Reference in New Issue