diff --git a/detection/src/main/java/com/njcn/gather/device/controller/PqStandardDevController.java b/detection/src/main/java/com/njcn/gather/device/controller/PqStandardDevController.java index 3f9689e1..bda395ea 100644 --- a/detection/src/main/java/com/njcn/gather/device/controller/PqStandardDevController.java +++ b/detection/src/main/java/com/njcn/gather/device/controller/PqStandardDevController.java @@ -160,5 +160,17 @@ public class PqStandardDevController extends BaseController { return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, pqDevVOList, methodDescribe); } + + + @OperateInfo(info = LogEnum.BUSINESS_COMMON) + @GetMapping("/canBindingList") + @ApiOperation("查询可绑定的标准设备") + public HttpResult> canBindingList() { + String methodDescribe = getMethodDescribe("canBindingList"); + LogUtil.njcnDebug(log, "{},查询可绑定的标准设备", methodDescribe); + List result = pqStandardDevService.canBindingList(); + + return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe); + } } diff --git a/detection/src/main/java/com/njcn/gather/device/service/IPqStandardDevService.java b/detection/src/main/java/com/njcn/gather/device/service/IPqStandardDevService.java index 73b1a29d..8161be92 100644 --- a/detection/src/main/java/com/njcn/gather/device/service/IPqStandardDevService.java +++ b/detection/src/main/java/com/njcn/gather/device/service/IPqStandardDevService.java @@ -91,4 +91,12 @@ public interface IPqStandardDevService extends IService { * @return */ List listStandardDevPreDetection(List ids); + + + /** + * 查询可绑定的标准设备列表 + * + * @return + */ + List canBindingList(); } 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 845a3004..f08c79f6 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 @@ -8,6 +8,7 @@ import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.collection.CollectionUtil; import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.StrUtil; +import cn.hutool.extra.spring.SpringUtil; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; @@ -23,6 +24,10 @@ import com.njcn.gather.device.pojo.vo.PqStandardDevExcel; import com.njcn.gather.device.pojo.vo.PreDetection; import com.njcn.gather.device.service.IPqStandardDevService; import com.njcn.gather.plan.mapper.AdPlanStandardDevMapper; +import com.njcn.gather.plan.pojo.po.AdPlan; +import com.njcn.gather.plan.pojo.po.AdPlanStandardDev; +import com.njcn.gather.plan.service.IAdPlanService; +import com.njcn.gather.plan.service.IAdPlanStandardDevService; import com.njcn.gather.pojo.enums.DetectionResponseEnum; import com.njcn.gather.system.dictionary.pojo.po.DictData; import com.njcn.gather.system.dictionary.pojo.po.DictType; @@ -58,6 +63,7 @@ public class PqStandardDevServiceImpl extends ServiceImpl listPqStandardDevs(PqStandardDevParam.QueryParam queryParam) { @@ -300,4 +306,46 @@ public class PqStandardDevServiceImpl extends ServiceImpl canBindingList() { + // 获取所有已绑定的标准设备 + 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()); + } + return this.lambdaQuery() + .eq(PqStandardDev::getState, DataStateEnum.ENABLE.getCode()) + .notIn(CollectionUtil.isNotEmpty(excludeStandardDevIds), PqStandardDev::getId, excludeStandardDevIds) + .list(); + } }