查询正式表查询逻辑(非 bom_version_row_id)调整
This commit is contained in:
parent
1cec213f66
commit
52a26046d6
|
|
@ -4,6 +4,7 @@ import cn.hutool.core.collection.CollUtil;
|
|||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.extra.spring.SpringUtil;
|
||||
import com.nflg.product.bomnew.constant.EBomConstant;
|
||||
import com.nflg.product.bomnew.constant.EBomStatusEnum;
|
||||
import com.nflg.product.bomnew.constant.OriginalConstant;
|
||||
import com.nflg.product.bomnew.pojo.entity.BomNewEbomParentEntity;
|
||||
import com.nflg.product.bomnew.pojo.entity.BomNewEbomParentFormalEntity;
|
||||
|
|
@ -17,27 +18,27 @@ import com.nflg.product.bomnew.util.MaterialshouldBomExistUtil;
|
|||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.RecursiveTask;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.function.BinaryOperator;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
|
||||
public class EBomFormalTreeTask extends RecursiveTask<List<BomNewEbomParentFormalVO>> {
|
||||
public class EBomFormalTreeTask extends RecursiveTask<List<BomNewEbomParentVO>> {
|
||||
|
||||
private List<BomNewEbomParentFormalVO> bomDetail;
|
||||
private List<BomNewEbomParentVO> bomDetail;
|
||||
|
||||
private boolean isNewVersion;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
private int levelNum=1;
|
||||
private int levelNum=2;
|
||||
AtomicInteger orderNum = new AtomicInteger(2);
|
||||
List<BomNewEbomParentVO> result = new ArrayList<>();
|
||||
|
||||
List<BomNewEbomParentFormalVO> result = new ArrayList<>();
|
||||
|
||||
public EBomFormalTreeTask(List<BomNewEbomParentFormalVO> inBomDetail) {
|
||||
public EBomFormalTreeTask(List<BomNewEbomParentVO> inBomDetail) {
|
||||
bomDetail = inBomDetail;
|
||||
}
|
||||
|
||||
|
|
@ -49,58 +50,68 @@ public class EBomFormalTreeTask extends RecursiveTask<List<BomNewEbomParentForma
|
|||
if(CollUtil.isEmpty(bomDetail)){
|
||||
return;
|
||||
}
|
||||
for (BomNewEbomParentFormalVO vo:
|
||||
for (BomNewEbomParentVO vo:
|
||||
bomDetail ) {
|
||||
vo.setLevelNum(levelNum);
|
||||
vo.setOrderNumber(orderNum.getAndIncrement()+"");
|
||||
}
|
||||
|
||||
SpringUtil.getBean(MaterialMainService.class).intiMaterialInfo(bomDetail, EBomConstant.EBOM_IGNORED_FIELDS_INIT_MATERIAL_DEFAULT);
|
||||
// SpringUtil.getBean(MaterialMainService.class).intiMaterialInfo(bomDetail, EBomConstant.EBOM_IGNORED_FIELDS_INIT_MATERIAL_DEFAULT);
|
||||
|
||||
List<Long> bomRowIds=bomDetail.stream().filter(u -> Objects.nonNull(u.getBomRowId()) && u.getBomRowId()>0 ).map(BomNewEbomParentFormalVO::getBomRowId).collect(Collectors.toList());
|
||||
if (CollUtil.isNotEmpty(bomRowIds)) {
|
||||
List<BomNewEbomParentFormalEntity > bomlist = SpringUtil.getBean(BomNewEbomParentFormalService.class ).lambdaQuery().in(BomNewEbomParentFormalEntity::getRowId, bomRowIds).list();
|
||||
Map<Long, BomNewEbomParentFormalEntity> parentEntityMap = ListCommonUtil.listToMap(bomlist, BomNewEbomParentFormalEntity::getRowId);
|
||||
for (BomNewEbomParentFormalVO detailVO : bomDetail) {
|
||||
if (parentEntityMap.containsKey(detailVO.getBomRowId())) {
|
||||
BomNewEbomParentFormalEntity ebomParentEntity = parentEntityMap.get(detailVO.getBomRowId());
|
||||
List<String> materialNos = bomDetail.stream().filter(u -> StrUtil.isNotBlank(u.getMaterialNo()) ).map(BomNewEbomParentVO::getMaterialNo).collect(Collectors.toList());
|
||||
|
||||
if (CollUtil.isNotEmpty(materialNos)) {
|
||||
|
||||
List<BomNewEbomParentEntity> childBomlist = SpringUtil.getBean(BomNewEbomParentService.class).lambdaQuery().in(BomNewEbomParentEntity::getMaterialNo, materialNos)
|
||||
.eq(BomNewEbomParentEntity::getStatus, EBomStatusEnum.PUBLISHED.getValue()).list();
|
||||
Map<String, BomNewEbomParentEntity> stringBomNewOriginalParentEntityMap = childBomlist.parallelStream()
|
||||
.collect(Collectors.toMap(
|
||||
BomNewEbomParentEntity::getMaterialNo, // key: DrawingNo
|
||||
Function.identity(),
|
||||
BinaryOperator.maxBy(Comparator.comparing(BomNewEbomParentEntity::getCurrentVersion))
|
||||
));
|
||||
// Map<String, BomNewEbomParentEntity> stringBomNewOriginalParentEntityMap = ListCommonUtil.listToMap(childBomlist, BomNewEbomParentEntity::getMaterialNo);
|
||||
for (BomNewEbomParentVO detailVO : bomDetail) {
|
||||
if (stringBomNewOriginalParentEntityMap.containsKey(detailVO.getMaterialNo())) {
|
||||
BomNewEbomParentEntity ebomParentEntity = stringBomNewOriginalParentEntityMap.get(detailVO.getMaterialNo());
|
||||
detailVO.setChildBomRowId(ebomParentEntity.getRowId());
|
||||
// detailVO.setCreatedTime(ebomParentEntity.getCreatedTime());
|
||||
|
||||
detailVO.setBomRowId(ebomParentEntity.getRowId());
|
||||
detailVO.setSourceRowId(ebomParentEntity.getSourceRowId());
|
||||
detailVO.setCurrentVersion(ebomParentEntity.getCurrentVersion());
|
||||
detailVO.setDeviseName(ebomParentEntity.getDeviseName());
|
||||
detailVO.setDeviseUserCode(ebomParentEntity.getDeviseUserCode());
|
||||
detailVO.setDeptName(ebomParentEntity.getDeptName());
|
||||
detailVO.setDeptRowId(ebomParentEntity.getDeptRowId());
|
||||
detailVO.setDeviseName(ebomParentEntity.getDeviseName());
|
||||
detailVO.setBomExist(ebomParentEntity.getBomExist());
|
||||
|
||||
|
||||
|
||||
detailVO.setStatus(ebomParentEntity.getStatus());
|
||||
detailVO.setBatchNo(ebomParentEntity.getBatchNo());
|
||||
detailVO.setCreatedBy(ebomParentEntity.getCreatedBy());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
//无Bom
|
||||
BomNewEbomParentFormalEntity ebomParentEntity = SpringUtil.getBean(BomNewEbomParentFormalService.class).lambdaQuery().eq(BomNewEbomParentFormalEntity::getRowId, bomDetail.get(0).getParentRowId()).one();
|
||||
List<BomNewEbomParentFormalVO> noBomList = bomDetail.stream().filter(u -> Objects.isNull(u.getBomRowId() )||u.getBomRowId() == 0).collect(Collectors.toList());
|
||||
if(CollUtil.isNotEmpty(noBomList)) {
|
||||
for (BomNewEbomParentFormalVO detailVO : noBomList) {
|
||||
|
||||
// detailVO.setCreatedTime(ebomParentEntity.getCreatedTime());
|
||||
detailVO.setDeviseUserCode(ebomParentEntity.getDeviseUserCode());
|
||||
detailVO.setDeptName(ebomParentEntity.getDeptName());
|
||||
detailVO.setDeviseName(ebomParentEntity.getDeviseName());
|
||||
detailVO.setDeviseUserCode(ebomParentEntity.getDeviseUserCode());
|
||||
if (MaterialshouldBomExistUtil.checkShouldBomExist(detailVO)) {
|
||||
detailVO.setCurrentVersion(OriginalConstant.NO_BOM_VERSION);
|
||||
} else {
|
||||
detailVO.setCurrentVersion(OriginalConstant.DEFAULT_BOM_VERSION);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
// //无Bom
|
||||
// BomNewEbomParentEntity ebomParentEntity = SpringUtil.getBean(BomNewEbomParentFormalService.class).lambdaQuery().eq(BomNewEbomParentFormalEntity::getRowId, bomDetail.get(0).getParentRowId()).one();
|
||||
// List<BomNewEbomParentFormalVO> noBomList = bomDetail.stream().filter(u -> Objects.isNull(u.getBomRowId() )||u.getBomRowId() == 0).collect(Collectors.toList());
|
||||
// if(CollUtil.isNotEmpty(noBomList)) {
|
||||
// for (BomNewEbomParentFormalVO detailVO : noBomList) {
|
||||
//
|
||||
// // detailVO.setCreatedTime(ebomParentEntity.getCreatedTime());
|
||||
// detailVO.setDeviseUserCode(ebomParentEntity.getDeviseUserCode());
|
||||
// detailVO.setDeptName(ebomParentEntity.getDeptName());
|
||||
// detailVO.setDeviseName(ebomParentEntity.getDeviseName());
|
||||
// detailVO.setDeviseUserCode(ebomParentEntity.getDeviseUserCode());
|
||||
// if (MaterialshouldBomExistUtil.checkShouldBomExist(detailVO)) {
|
||||
// detailVO.setCurrentVersion(OriginalConstant.NO_BOM_VERSION);
|
||||
// } else {
|
||||
// detailVO.setCurrentVersion(OriginalConstant.DEFAULT_BOM_VERSION);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// }
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -111,7 +122,7 @@ public class EBomFormalTreeTask extends RecursiveTask<List<BomNewEbomParentForma
|
|||
* @return
|
||||
*/
|
||||
@Override
|
||||
protected List<BomNewEbomParentFormalVO > compute() {
|
||||
protected List<BomNewEbomParentVO > compute() {
|
||||
|
||||
handlerChildBomVersionDetail();
|
||||
// 最新 BOM 版本
|
||||
|
|
@ -119,11 +130,11 @@ public class EBomFormalTreeTask extends RecursiveTask<List<BomNewEbomParentForma
|
|||
|
||||
if (CollUtil.isNotEmpty(bomDetail)) {
|
||||
levelNumAdd();
|
||||
List<Long> childBowIds = bomDetail.stream().filter(u-> u.getBomRowId()!=null && u.getBomRowId() > 0).map(u->u.getBomRowId()).collect(Collectors.toList());
|
||||
List<Long> childBowIds = bomDetail.stream().filter(u-> u.getChildBomRowId()!=null && u.getChildBomRowId() > 0).map(u->u.getChildBomRowId()).collect(Collectors.toList());
|
||||
if(CollUtil.isNotEmpty(childBowIds)) {
|
||||
List<BomNewEbomParentFormalVO> bom = SpringUtil.getBean(BomNewEbomParentFormalService.class).getBaseMapper().getParentChildBatch(childBowIds);
|
||||
List<BomNewEbomParentVO> bom = SpringUtil.getBean(BomNewEbomParentService.class).getBaseMapper().getParentChildBatch(childBowIds);
|
||||
|
||||
EBomFormalTreeTask task = new EBomFormalTreeTask(bom);
|
||||
task.setLevelNum(levelNum);
|
||||
task.fork();
|
||||
bomDetail.addAll(task.join());
|
||||
return bomDetail;
|
||||
|
|
|
|||
|
|
@ -180,7 +180,7 @@ public class EBomForwardReport extends BaseForwardReport {
|
|||
bom 子级同步有bom版本号
|
||||
*/
|
||||
|
||||
void bomUpAndLowLevel( List<BomNewEbomParentVO> parent,List< BomNewEbomParentVO> parentChildList,int levelNum,AtomicInteger orderNum){
|
||||
void bomUpAndLowLevel( List<BomNewEbomParentVO> parent,List< BomNewEbomParentVO> parentChildList,List< BomNewEbomParentVO> backList,int levelNum,AtomicInteger orderNum){
|
||||
|
||||
if (CollectionUtil.isNotEmpty(parentChildList)) {
|
||||
|
||||
|
|
@ -188,7 +188,10 @@ public class EBomForwardReport extends BaseForwardReport {
|
|||
Map<Long, BomNewEbomParentVO> parentEntityMap=null;
|
||||
if(CollUtil.isNotEmpty(bomRowIds)) {
|
||||
List< BomNewEbomParentVO> bomlist = getParentList(bomRowIds);
|
||||
|
||||
if (CollUtil.isNotEmpty(backList)) {
|
||||
backList.clear();
|
||||
backList.addAll(bomlist);
|
||||
}
|
||||
parentEntityMap = ListCommonUtil.listToMap(bomlist, BomNewEbomParentVO::getRowId);
|
||||
}
|
||||
|
||||
|
|
@ -342,7 +345,7 @@ public class EBomForwardReport extends BaseForwardReport {
|
|||
//
|
||||
// }
|
||||
|
||||
bomUpAndLowLevel(ImmutableList.of(parentFormal),parentChildList,2,orderNum);
|
||||
bomUpAndLowLevel(ImmutableList.of(parentFormal),parentChildList,null,2,orderNum);
|
||||
|
||||
List<ForwardReportVO> nodeList = Convert.convert(new TypeReference<List<ForwardReportVO>>() {
|
||||
}, parentChildList);
|
||||
|
|
@ -396,14 +399,13 @@ public class EBomForwardReport extends BaseForwardReport {
|
|||
*
|
||||
* @return
|
||||
*/
|
||||
synchronized List<BomNewEbomParentFormalVO> bomDetailList(Long bomRowId) {
|
||||
List<BomNewEbomParentFormalVO> childList = SpringUtil.getBean(BomNewEbomParentFormalService.class).getParentChild(bomRowId);
|
||||
List<BomNewEbomParentVO> bomDetailList(Long bomRowId) {
|
||||
List<BomNewEbomParentVO> childList = SpringUtil.getBean(BomNewEbomParentService.class).getParentChild(bomRowId);
|
||||
if(CollUtil.isNotEmpty(childList)) {
|
||||
EBomFormalTreeTask task = new EBomFormalTreeTask(childList);
|
||||
ForkJoinPool pool = new ForkJoinPool();
|
||||
ForkJoinTask<List<BomNewEbomParentFormalVO>> submit = pool.submit(task);
|
||||
|
||||
List<BomNewEbomParentFormalVO> bomList = submit.join();
|
||||
ForkJoinTask<List<BomNewEbomParentVO>> submit = pool.submit(task);
|
||||
List<BomNewEbomParentVO> bomList = submit.join();
|
||||
initMaterialInfo(bomList);
|
||||
return bomList;
|
||||
}
|
||||
|
|
@ -411,12 +413,35 @@ public class EBomForwardReport extends BaseForwardReport {
|
|||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
List<BomNewEbomParentVO> bomDetailAndParent(BomNewEbomParentVO parentBomRow){
|
||||
|
||||
if(isNewVersion()){
|
||||
List<BomNewEbomParentVO> bomDetails= bomDetailList(parentBomRow.getRowId());
|
||||
if(CollUtil.isNotEmpty(bomDetails)){
|
||||
parentBomRow.setLevelNum(1);
|
||||
parentBomRow.setOrderNumber("1");
|
||||
bomDetails.add(0,parentBomRow);
|
||||
}
|
||||
|
||||
return bomDetails;
|
||||
}else{
|
||||
return bomDetailFormalList(parentBomRow);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 迭代查询整颗树
|
||||
|
||||
* @return
|
||||
*/
|
||||
List<BomNewEbomParentVO> bomDetailTreeList(BomNewEbomParentVO parentBomRow) {
|
||||
List<BomNewEbomParentVO> bomDetailFormalList(BomNewEbomParentVO parentBomRow) {
|
||||
|
||||
int levelNum = 1;
|
||||
AtomicInteger orderNum = new AtomicInteger(1);
|
||||
|
|
@ -434,20 +459,19 @@ public class EBomForwardReport extends BaseForwardReport {
|
|||
List<Long> rowIdList = new ArrayList<>( Arrays.asList(parentBomRow.getRowId()) );
|
||||
|
||||
List<BomNewEbomParentVO> parentVOList=new ArrayList<>(Arrays.asList(parentBomRow));
|
||||
|
||||
List<BomNewEbomParentVO> backList=new ArrayList<>();
|
||||
while (!rowIdList.isEmpty()) {
|
||||
List< BomNewEbomParentVO> parentChildList= getParentChildList(rowIdList);
|
||||
rowIdList.clear();
|
||||
if (CollUtil.isNotEmpty(parentChildList)) {
|
||||
bomUpAndLowLevel(parentVOList,parentChildList,levelNum,orderNum);
|
||||
bomUpAndLowLevel(parentVOList,parentChildList,backList,levelNum,orderNum);
|
||||
|
||||
voList.addAll(parentChildList);
|
||||
levelNum++;
|
||||
List<Long> nextBomId = parentChildList.stream().filter(u -> ObjectUtil.isNotNull(u.getBomRowId()) && u.getBomRowId() > 0)
|
||||
.map(BomNewEbomParentVO::getBomRowId).collect(Collectors.toList());
|
||||
parentVOList.clear();
|
||||
parentVOList.addAll(parentChildList.stream().filter(u -> ObjectUtil.isNotNull(u.getBomRowId()) && u.getBomRowId() > 0)
|
||||
.collect(Collectors.toList()));
|
||||
parentVOList.addAll(backList);
|
||||
|
||||
if (CollUtil.isNotEmpty(nextBomId)) {
|
||||
rowIdList.addAll(nextBomId);
|
||||
|
|
@ -491,7 +515,7 @@ public class EBomForwardReport extends BaseForwardReport {
|
|||
for (BomNewEbomParentVO parentFormal : listParent) {
|
||||
|
||||
|
||||
List<BomNewEbomParentVO> bomList = bomDetailTreeList(parentFormal);
|
||||
List<BomNewEbomParentVO> bomList = bomDetailAndParent(parentFormal);
|
||||
if(CollUtil.isEmpty(bomList)){
|
||||
continue;
|
||||
}
|
||||
|
|
@ -535,7 +559,7 @@ public class EBomForwardReport extends BaseForwardReport {
|
|||
List<ForwardReportVO> nodesList = new ArrayList<>();
|
||||
for (BomNewEbomParentVO parentFormal : listParent) {
|
||||
|
||||
List<BomNewEbomParentVO> bomList = bomDetailTreeList(parentFormal );
|
||||
List<BomNewEbomParentVO> bomList = bomDetailAndParent(parentFormal );
|
||||
if(CollUtil.isEmpty(bomList)){
|
||||
continue;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue