UPDATE: 优化可选标准设备接口

This commit is contained in:
贾同学
2025-09-04 15:59:03 +08:00
parent b09438e29d
commit 7c18d0038a

View File

@@ -309,40 +309,44 @@ public class PqStandardDevServiceImpl extends ServiceImpl<PqStandardDevMapper, P
@Override
public List<PqStandardDev> canBindingList() {
List<String> excludeStandardDevIds = new ArrayList<>();
// 获取所有已绑定的标准设备
List<AdPlanStandardDev> boundList = adPlanStandardDevService.list();
// 获取对应检测计划
List<String> planIds = boundList.stream().map(AdPlanStandardDev::getPlanId).collect(Collectors.toList());
IAdPlanService adPlanService = SpringUtil.getBean(IAdPlanService.class);
List<AdPlan> planList = adPlanService.listByIds(planIds);
// 区分主计划和子计划
List<AdPlan> mainPlanList = planList.stream().filter(plan -> plan.getFatherPlanId() == null).collect(Collectors.toList());
List<AdPlan> subPlanList = planList.stream().filter(plan -> plan.getFatherPlanId() != null).collect(Collectors.toList());
List<String> excludePlanIds = new ArrayList<>();
List<String> excludeStandardDevIds = new ArrayList<>();
// 主计划直接排除
if (CollectionUtil.isNotEmpty(mainPlanList)) {
List<String> excludeMainPlanIds = mainPlanList.stream().filter(plan -> plan.getTestState() != 2).map(plan -> plan.getId()).collect(Collectors.toList());
excludePlanIds.addAll(excludeMainPlanIds);
}
// 子计划需要判断其主计划, 如果主计划未完成则排除
if (CollectionUtil.isNotEmpty(subPlanList)) {
List<String> fatherPlanIds = subPlanList.stream().map(plan -> plan.getFatherPlanId()).collect(Collectors.toList());
List<AdPlan> fatherPlanList = adPlanService.listByIds(fatherPlanIds);
List<String> excludeFatherPlanIds = fatherPlanList.stream()
.filter(plan -> plan.getTestState() != 2)
.map(plan -> plan.getId()).collect(Collectors.toList());
List<String> excludeSubPlanIds = subPlanList.stream()
.filter(plan -> excludeFatherPlanIds.contains(plan.getFatherPlanId()))
.map(plan -> plan.getId()).collect(Collectors.toList());
excludePlanIds.addAll(excludeSubPlanIds);
}
if (CollectionUtil.isNotEmpty(excludePlanIds)) {
List<AdPlanStandardDev> excludeBoundList = boundList.stream()
.filter(bound -> excludePlanIds.contains(bound.getPlanId()))
.collect(Collectors.toList());
excludeStandardDevIds = excludeBoundList.stream().map(AdPlanStandardDev::getStandardDevId).collect(Collectors.toList());
if (CollectionUtil.isNotEmpty(boundList)) {
// 获取对应检测计划
List<String> planIds = boundList.stream().map(AdPlanStandardDev::getPlanId).collect(Collectors.toList());
IAdPlanService adPlanService = SpringUtil.getBean(IAdPlanService.class);
List<AdPlan> planList = adPlanService.listByIds(planIds);
// 区分主计划和子计划
List<AdPlan> mainPlanList = planList.stream().filter(plan -> plan.getFatherPlanId() == null).collect(Collectors.toList());
List<AdPlan> subPlanList = planList.stream().filter(plan -> plan.getFatherPlanId() != null).collect(Collectors.toList());
List<String> excludePlanIds = new ArrayList<>();
// 主计划直接排除
if (CollectionUtil.isNotEmpty(mainPlanList)) {
List<String> excludeMainPlanIds = mainPlanList.stream().filter(plan -> plan.getTestState() != 2).map(plan -> plan.getId()).collect(Collectors.toList());
excludePlanIds.addAll(excludeMainPlanIds);
}
// 子计划需要判断其主计划, 如果主计划未完成则排除
if (CollectionUtil.isNotEmpty(subPlanList)) {
List<String> fatherPlanIds = subPlanList.stream().map(plan -> plan.getFatherPlanId()).collect(Collectors.toList());
List<AdPlan> fatherPlanList = adPlanService.listByIds(fatherPlanIds);
List<String> excludeFatherPlanIds = fatherPlanList.stream()
.filter(plan -> plan.getTestState() != 2)
.map(plan -> plan.getId()).collect(Collectors.toList());
List<String> excludeSubPlanIds = subPlanList.stream()
.filter(plan -> excludeFatherPlanIds.contains(plan.getFatherPlanId()))
.map(plan -> plan.getId()).collect(Collectors.toList());
excludePlanIds.addAll(excludeSubPlanIds);
}
if (CollectionUtil.isNotEmpty(excludePlanIds)) {
List<AdPlanStandardDev> excludeBoundList = boundList.stream()
.filter(bound -> excludePlanIds.contains(bound.getPlanId()))
.collect(Collectors.toList());
excludeStandardDevIds = excludeBoundList.stream().map(AdPlanStandardDev::getStandardDevId).collect(Collectors.toList());
}
}
return this.lambdaQuery()
.eq(PqStandardDev::getState, DataStateEnum.ENABLE.getCode())
.notIn(CollectionUtil.isNotEmpty(excludeStandardDevIds), PqStandardDev::getId, excludeStandardDevIds)