diff --git a/backend/src/main/java/io/metersphere/track/service/TestPlanService.java b/backend/src/main/java/io/metersphere/track/service/TestPlanService.java index 8616cbf2b7..e3acb02d65 100644 --- a/backend/src/main/java/io/metersphere/track/service/TestPlanService.java +++ b/backend/src/main/java/io/metersphere/track/service/TestPlanService.java @@ -545,6 +545,8 @@ public class TestPlanService { public void testPlanRelevance(PlanCaseRelevanceRequest request) { LinkedHashMap userMap; + TestPlan testPlan = testPlanMapper.selectByPrimaryKey(request.getPlanId()); + boolean isSelectAll = request.getRequest() != null && request.getRequest().isSelectAll(); if (isSelectAll) { List maintainerMap = extTestCaseMapper.getMaintainerMap(request.getRequest()); @@ -558,6 +560,11 @@ public class TestPlanService { .collect(LinkedHashMap::new, (m, v) -> m.put(v.getId(), v.getMaintainer()), LinkedHashMap::putAll); } + Set projectMemberSet = userService.getProjectMemberOption(testPlan.getProjectId()) + .stream() + .map(User::getId) + .collect(Collectors.toSet()); + SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH); TestPlanTestCaseMapper batchMapper = sqlSession.getMapper(TestPlanTestCaseMapper.class); @@ -580,7 +587,10 @@ public class TestPlanService { TestPlanTestCaseWithBLOBs testPlanTestCase = new TestPlanTestCaseWithBLOBs(); testPlanTestCase.setId(UUID.randomUUID().toString()); testPlanTestCase.setCreateUser(SessionUtils.getUserId()); - String maintainer = Optional.ofNullable(userMap.get(caseId)).orElse(SessionUtils.getUserId()); + String maintainer = userMap.get(caseId); + if (StringUtils.isBlank(maintainer) || !projectMemberSet.contains(maintainer)) { + maintainer = SessionUtils.getUserId(); + } testPlanTestCase.setExecutor(maintainer); testPlanTestCase.setCaseId(caseId); testPlanTestCase.setCreateTime(System.currentTimeMillis()); @@ -597,7 +607,6 @@ public class TestPlanService { caseTestRelevance(request, testCaseIds); - TestPlan testPlan = testPlanMapper.selectByPrimaryKey(request.getPlanId()); if (StringUtils.equals(testPlan.getStatus(), TestPlanStatus.Prepare.name()) || StringUtils.equals(testPlan.getStatus(), TestPlanStatus.Completed.name())) { testPlan.setStatus(TestPlanStatus.Underway.name());