feat: ebom工作表精确搜索排序

This commit is contained in:
曹鹏飞 2024-04-18 09:15:43 +08:00
parent 5956c61075
commit 39ed6810eb
1 changed files with 34 additions and 33 deletions

View File

@ -2077,40 +2077,41 @@ public class BomNewEbomParentService extends ServiceImpl<BomNewEbomParentMapper,
if (StrUtil.isBlank(query.getMaterialNo()) && StrUtil.isBlank(query.getDrawingNo())) { if (StrUtil.isBlank(query.getMaterialNo()) && StrUtil.isBlank(query.getDrawingNo())) {
//列表搜索 //列表搜索
return result; return result;
} else {
//根据编号或图号搜索
//从顶级开始查找
List<BomNewEbomParentVO> roots = result.getRecords().stream()
.filter(r -> StrUtil.equals(r.getMaterialNo(), query.getMaterialNo()) || StrUtil.equals(r.getDrawingNo(), query.getDrawingNo()))
.collect(Collectors.toList());
roots.forEach(this::buildChildren);
//从子级开始查找
List<BomNewEbomParentVO> boms = this.getBaseMapper().getBom(query.getMaterialNo(), query.getDrawingNo());
boms.removeIf(c -> Objects.equals(c.getLastVersionIs(), 0));
boms.forEach(this::buildChildren);
roots.addAll(boms.stream().filter(b -> b.getRootIs() == 0 && b.getUserRootIs() == 0 && b.getRootIsForWaitReview() == 0).map(this::buildParent).flatMap(List::stream).collect(Collectors.toList()));
Map<String, List<BomNewEbomParentVO>> map = roots.stream().collect(Collectors.groupingBy(BaseMaterialVO::getMaterialNo));
List<BomNewEbomParentVO> results = new ArrayList<>();
map.forEach((k, v) -> {
if (v.size() == 1) {
results.add(v.get(0));
} else {
BomNewEbomParentVO f1 = v.get(0);
for (int i = 1; i < v.size(); i++) {
merge(f1, v.get(i));
}
results.add(f1);
}
});
Page<BomNewEbomParentVO> pageResult = new Page<>();
pageResult.setPages(1);
pageResult.setCurrent(1);
pageResult.setTotal(results.size());
pageResult.setRecords(results);
return pageResult;
} }
//根据编号或图号搜索
//从顶级开始查找
List<BomNewEbomParentVO> roots = result.getRecords().stream()
.filter(r -> StrUtil.equals(r.getMaterialNo(), query.getMaterialNo()) || StrUtil.equals(r.getDrawingNo(), query.getDrawingNo()))
.collect(Collectors.toList());
roots.forEach(this::buildChildren);
//从子级开始查找
List<BomNewEbomParentVO> boms = this.getBaseMapper().getBom(query.getMaterialNo(), query.getDrawingNo());
boms.removeIf(c -> Objects.equals(c.getLastVersionIs(), 0));
boms.forEach(this::buildChildren);
roots.addAll(boms.stream().filter(b -> b.getRootIs() == 0 && b.getUserRootIs() == 0 && b.getRootIsForWaitReview() == 0).map(this::buildParent).flatMap(List::stream).collect(Collectors.toList()));
Map<String, List<BomNewEbomParentVO>> map = roots.stream().collect(Collectors.groupingBy(BaseMaterialVO::getMaterialNo));
List<BomNewEbomParentVO> results = new ArrayList<>();
map.forEach((k, v) -> {
if (v.size() == 1) {
results.add(v.get(0));
} else {
BomNewEbomParentVO f1 = v.get(0);
for (int i = 1; i < v.size(); i++) {
merge(f1, v.get(i));
}
results.add(f1);
}
});
results.sort((r1, r2) -> r1.getBomRowId() >= r2.getBomRowId() ? r1.getBomRowId() > r2.getBomRowId() ? 1 : 0 : -1);
Page<BomNewEbomParentVO> pageResult = new Page<>();
pageResult.setPages(1);
pageResult.setCurrent(1);
pageResult.setTotal(results.size());
pageResult.setRecords(results);
return pageResult;
} }
private void merge(BomNewEbomParentVO v1, BomNewEbomParentVO v2) { private void merge(BomNewEbomParentVO v1, BomNewEbomParentVO v2) {