diff --git a/detection/src/main/java/com/njcn/gather/device/service/impl/PqStandardDevServiceImpl.java b/detection/src/main/java/com/njcn/gather/device/service/impl/PqStandardDevServiceImpl.java index f08c79f6..359e1684 100644 --- a/detection/src/main/java/com/njcn/gather/device/service/impl/PqStandardDevServiceImpl.java +++ b/detection/src/main/java/com/njcn/gather/device/service/impl/PqStandardDevServiceImpl.java @@ -309,40 +309,44 @@ public class PqStandardDevServiceImpl extends ServiceImpl canBindingList() { + List excludeStandardDevIds = new ArrayList<>(); // 获取所有已绑定的标准设备 List boundList = adPlanStandardDevService.list(); - // 获取对应检测计划 - List planIds = boundList.stream().map(AdPlanStandardDev::getPlanId).collect(Collectors.toList()); - IAdPlanService adPlanService = SpringUtil.getBean(IAdPlanService.class); - List planList = adPlanService.listByIds(planIds); - // 区分主计划和子计划 - List mainPlanList = planList.stream().filter(plan -> plan.getFatherPlanId() == null).collect(Collectors.toList()); - List subPlanList = planList.stream().filter(plan -> plan.getFatherPlanId() != null).collect(Collectors.toList()); - List excludePlanIds = new ArrayList<>(); - List excludeStandardDevIds = new ArrayList<>(); - // 主计划直接排除 - if (CollectionUtil.isNotEmpty(mainPlanList)) { - List excludeMainPlanIds = mainPlanList.stream().filter(plan -> plan.getTestState() != 2).map(plan -> plan.getId()).collect(Collectors.toList()); - excludePlanIds.addAll(excludeMainPlanIds); - } - // 子计划需要判断其主计划, 如果主计划未完成则排除 - if (CollectionUtil.isNotEmpty(subPlanList)) { - List fatherPlanIds = subPlanList.stream().map(plan -> plan.getFatherPlanId()).collect(Collectors.toList()); - List fatherPlanList = adPlanService.listByIds(fatherPlanIds); - List excludeFatherPlanIds = fatherPlanList.stream() - .filter(plan -> plan.getTestState() != 2) - .map(plan -> plan.getId()).collect(Collectors.toList()); - List excludeSubPlanIds = subPlanList.stream() - .filter(plan -> excludeFatherPlanIds.contains(plan.getFatherPlanId())) - .map(plan -> plan.getId()).collect(Collectors.toList()); - excludePlanIds.addAll(excludeSubPlanIds); - } - if (CollectionUtil.isNotEmpty(excludePlanIds)) { - List 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 planIds = boundList.stream().map(AdPlanStandardDev::getPlanId).collect(Collectors.toList()); + IAdPlanService adPlanService = SpringUtil.getBean(IAdPlanService.class); + List planList = adPlanService.listByIds(planIds); + // 区分主计划和子计划 + List mainPlanList = planList.stream().filter(plan -> plan.getFatherPlanId() == null).collect(Collectors.toList()); + List subPlanList = planList.stream().filter(plan -> plan.getFatherPlanId() != null).collect(Collectors.toList()); + List excludePlanIds = new ArrayList<>(); + + // 主计划直接排除 + if (CollectionUtil.isNotEmpty(mainPlanList)) { + List excludeMainPlanIds = mainPlanList.stream().filter(plan -> plan.getTestState() != 2).map(plan -> plan.getId()).collect(Collectors.toList()); + excludePlanIds.addAll(excludeMainPlanIds); + } + // 子计划需要判断其主计划, 如果主计划未完成则排除 + if (CollectionUtil.isNotEmpty(subPlanList)) { + List fatherPlanIds = subPlanList.stream().map(plan -> plan.getFatherPlanId()).collect(Collectors.toList()); + List fatherPlanList = adPlanService.listByIds(fatherPlanIds); + List excludeFatherPlanIds = fatherPlanList.stream() + .filter(plan -> plan.getTestState() != 2) + .map(plan -> plan.getId()).collect(Collectors.toList()); + List excludeSubPlanIds = subPlanList.stream() + .filter(plan -> excludeFatherPlanIds.contains(plan.getFatherPlanId())) + .map(plan -> plan.getId()).collect(Collectors.toList()); + excludePlanIds.addAll(excludeSubPlanIds); + } + if (CollectionUtil.isNotEmpty(excludePlanIds)) { + List 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)