From 1c4f4e0fecb24d93164aff59a8e4e9d3ae07f64b Mon Sep 17 00:00:00 2001 From: Jianguo-Genius Date: Thu, 13 Jun 2024 15:10:01 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E6=B5=8B=E8=AF=95=E8=AE=A1=E5=88=92):=20?= =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=B5=8B=E8=AF=95=E8=AE=A1=E5=88=92=E7=BB=9F?= =?UTF-8?q?=E8=AE=A1=E6=8E=A5=E5=8F=A3=E6=B2=A1=E6=9F=A5=E8=AF=A2=E5=AD=90?= =?UTF-8?q?=E8=AE=A1=E5=88=92=E7=9A=84=E7=BC=BA=E9=99=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../system/service/SimpleUserService.java | 28 ++------ .../system/service/UserXpackService.java | 8 ++- .../dto/request/TestPlanBatchEditRequest.java | 2 +- .../plan/service/TestPlanService.java | 24 ++++--- .../service/TestPlanStatisticsService.java | 65 +++++++++++-------- .../plan/controller/TestPlanTests.java | 6 +- 6 files changed, 68 insertions(+), 65 deletions(-) diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/service/SimpleUserService.java b/backend/services/system-setting/src/main/java/io/metersphere/system/service/SimpleUserService.java index 1c2bfa5012..d7624768a6 100644 --- a/backend/services/system-setting/src/main/java/io/metersphere/system/service/SimpleUserService.java +++ b/backend/services/system-setting/src/main/java/io/metersphere/system/service/SimpleUserService.java @@ -129,7 +129,7 @@ public class SimpleUserService { } private List saveUserAndRole(UserBatchCreateRequest userCreateDTO, String source, String operator, String requestPath) { - int responseCode = Objects.requireNonNull(CommonBeanFactory.getBean(UserXpackService.class)).guessWhatHowToAddUser(userCreateDTO, source, operator); + int responseCode = Objects.requireNonNull(CommonBeanFactory.getBean(UserXpackService.class)).GWHowToAddUser(userCreateDTO, source, operator); if (responseCode == 0) { operationLogService.batchAdd(userLogService.getBatchAddLogs(userCreateDTO.getUserInfoList(), operator, requestPath)); } else { @@ -225,7 +225,7 @@ public class SimpleUserService { this.checkProcessUserAndThrowException(request.getSelectIds(), operatorId, operatorName, Translator.get("user.not.disable")); } - int responseCode = Objects.requireNonNull(CommonBeanFactory.getBean(UserXpackService.class)).guessWhatHowToChangeUser(request.getSelectIds(), request.isEnable(), operatorName); + int responseCode = Objects.requireNonNull(CommonBeanFactory.getBean(UserXpackService.class)).GWHowToChangeUser(request.getSelectIds(), request.isEnable(), operatorName); if (responseCode == 0) { TableBatchProcessResponse response = new TableBatchProcessResponse(); @@ -319,12 +319,13 @@ public class SimpleUserService { this.checkUserInDb(userIdList); //检查是否含有Admin this.checkProcessUserAndThrowException(userIdList, operatorId, operatorName, Translator.get("user.not.delete")); + //开始删除 UserExample userExample = new UserExample(); userExample.createCriteria().andIdIn(userIdList); - //更新删除标志位 TableBatchProcessResponse response = new TableBatchProcessResponse(); response.setTotalCount(userIdList.size()); - response.setSuccessCount(this.deleteUserByList(userIdList, operatorId)); + response.setSuccessCount( + Objects.requireNonNull(CommonBeanFactory.getBean(UserXpackService.class)).GWHowToDeleteUser(userIdList, operatorId)); //删除用户角色关系 userRoleRelationService.deleteByUserIdList(userIdList); //批量踢出用户 @@ -350,23 +351,6 @@ public class SimpleUserService { } } - private int deleteUserByList(List updateUserList, String operator) { - SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH); - BaseUserMapper batchDeleteMapper = sqlSession.getMapper(BaseUserMapper.class); - int insertIndex = 0; - long deleteTime = System.currentTimeMillis(); - for (String userId : updateUserList) { - batchDeleteMapper.deleteUser(userId, operator, deleteTime); - insertIndex++; - if (insertIndex % 50 == 0) { - sqlSession.flushStatements(); - } - } - sqlSession.flushStatements(); - SqlSessionUtils.closeSqlSession(sqlSession, sqlSessionFactory); - return insertIndex; - } - public List getUserList(String keyword) { return extUserMapper.selectUserList(keyword); } @@ -521,7 +505,7 @@ public class SimpleUserService { this.add(userInvite.getEmail()); }}); - int responseCode = Objects.requireNonNull(CommonBeanFactory.getBean(UserXpackService.class)).guessWhatHowToAddUser(request, userInvite); + int responseCode = Objects.requireNonNull(CommonBeanFactory.getBean(UserXpackService.class)).GWHowToAddUser(request, userInvite); if (responseCode == 0) { //删除本次邀请记录 userInviteService.deleteInviteById(userInvite.getId()); diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/service/UserXpackService.java b/backend/services/system-setting/src/main/java/io/metersphere/system/service/UserXpackService.java index d927aa2299..678c97f576 100644 --- a/backend/services/system-setting/src/main/java/io/metersphere/system/service/UserXpackService.java +++ b/backend/services/system-setting/src/main/java/io/metersphere/system/service/UserXpackService.java @@ -11,9 +11,11 @@ import java.util.List; */ public interface UserXpackService { - int guessWhatHowToAddUser(UserBatchCreateRequest userCreateDTO, String source, String operator); + int GWHowToAddUser(UserBatchCreateRequest userCreateDTO, String source, String operator); - int guessWhatHowToAddUser(UserRegisterRequest registerRequest, UserInvite userInvite) throws Exception; + int GWHowToAddUser(UserRegisterRequest registerRequest, UserInvite userInvite) throws Exception; - int guessWhatHowToChangeUser(List userIds, boolean enable, String operator); + int GWHowToChangeUser(List userIds, boolean enable, String operator); + + int GWHowToDeleteUser(List userIdList, String operator); } diff --git a/backend/services/test-plan/src/main/java/io/metersphere/plan/dto/request/TestPlanBatchEditRequest.java b/backend/services/test-plan/src/main/java/io/metersphere/plan/dto/request/TestPlanBatchEditRequest.java index a1e2dd45a8..44ec6b306f 100644 --- a/backend/services/test-plan/src/main/java/io/metersphere/plan/dto/request/TestPlanBatchEditRequest.java +++ b/backend/services/test-plan/src/main/java/io/metersphere/plan/dto/request/TestPlanBatchEditRequest.java @@ -12,7 +12,7 @@ import java.util.List; public class TestPlanBatchEditRequest extends TestPlanBatchProcessRequest { @Schema(description = "是否追加") - private boolean append; + private boolean append = true; @Schema(description = "标签") private List tags; diff --git a/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanService.java b/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanService.java index 276e5902ed..452f0e1cda 100644 --- a/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanService.java +++ b/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanService.java @@ -762,16 +762,22 @@ public class TestPlanService extends TestPlanBaseUtilsService { testPlan.setStatus(testPlanFinalStatus); testPlanMapper.updateByPrimaryKeySelective(testPlan); - List childPlan = this.selectNotArchivedChildren(testPlanId); - if (CollectionUtils.isNotEmpty(childPlan)) { - TestPlan updateGroupPlan = new TestPlan(); - updateGroupPlan.setId(testPlanId); - if (childPlan.stream().allMatch(item -> StringUtils.equals(item.getStatus(), TestPlanConstants.TEST_PLAN_STATUS_COMPLETED))) { - testPlan.setStatus(TestPlanConstants.TEST_PLAN_STATUS_COMPLETED); - } else { - testPlan.setStatus(TestPlanConstants.TEST_PLAN_STATUS_UNDERWAY); + testPlan = testPlanMapper.selectByPrimaryKey(testPlanId); + + if (!StringUtils.equalsIgnoreCase(testPlan.getGroupId(), TestPlanConstants.TEST_PLAN_DEFAULT_GROUP_ID)) { + //该测试计划是测试计划组内的子计划, 要同步计算测试计划组的状态 + + List childPlan = this.selectNotArchivedChildren(testPlan.getGroupId()); + if (CollectionUtils.isNotEmpty(childPlan)) { + TestPlan updateGroupPlan = new TestPlan(); + updateGroupPlan.setId(testPlan.getGroupId()); + if (childPlan.stream().allMatch(item -> StringUtils.equals(item.getStatus(), TestPlanConstants.TEST_PLAN_STATUS_COMPLETED))) { + updateGroupPlan.setStatus(TestPlanConstants.TEST_PLAN_STATUS_COMPLETED); + } else { + updateGroupPlan.setStatus(TestPlanConstants.TEST_PLAN_STATUS_UNDERWAY); + } + testPlanMapper.updateByPrimaryKeySelective(updateGroupPlan); } - testPlanMapper.updateByPrimaryKeySelective(testPlan); } } diff --git a/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanStatisticsService.java b/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanStatisticsService.java index e1776fee15..99dbd332f6 100644 --- a/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanStatisticsService.java +++ b/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanStatisticsService.java @@ -26,6 +26,8 @@ import java.util.stream.Collectors; @Service public class TestPlanStatisticsService { + @Resource + private TestPlanMapper testPlanMapper; @Resource private TestPlanConfigMapper testPlanConfigMapper; @Resource @@ -74,12 +76,17 @@ public class TestPlanStatisticsService { * @param planIds 计划ID集合 */ public List calculateRate(List planIds) { + // 查出子计划 + TestPlanExample testPlanExample = new TestPlanExample(); + testPlanExample.createCriteria().andGroupIdIn(planIds); + List childrenPlan = testPlanMapper.selectByExample(testPlanExample); + childrenPlan.forEach(item -> planIds.add(item.getId())); + List planStatisticsResponses = new ArrayList<>(); /* * 1. 查询计划下的用例数据集合 * 2. 根据执行结果统计(结果小数保留两位) */ - // 计划的更多配置 TestPlanConfigExample example = new TestPlanConfigExample(); example.createCriteria().andTestPlanIdIn(planIds); @@ -99,32 +106,36 @@ public class TestPlanStatisticsService { planIds.forEach(planId -> { TestPlanStatisticsResponse statisticsResponse = new TestPlanStatisticsResponse(); statisticsResponse.setId(planId); - statisticsResponse.setPassThreshold(planConfigMap.get(planId).getPassThreshold()); - // 功能用例分组统计开始 (为空时, 默认为未执行) - List functionalCases = planFunctionalCaseMap.get(planId); - statisticsResponse.setFunctionalCaseCount(CollectionUtils.isNotEmpty(functionalCases) ? functionalCases.size() : 0); - Map functionalCaseResultCountMap = CollectionUtils.isEmpty(functionalCases) ? new HashMap<>(16) : functionalCases.stream().collect( - Collectors.groupingBy(functionalCase -> Optional.ofNullable(functionalCase.getLastExecResult()).orElse(ExecStatus.PENDING.name()), Collectors.counting())); - // 接口用例分组统计开始 (为空时, 默认为未执行) - List apiCases = planApiCaseMap.get(planId); - statisticsResponse.setApiCaseCount(CollectionUtils.isNotEmpty(apiCases) ? apiCases.size() : 0); - Map apiCaseResultCountMap = CollectionUtils.isEmpty(apiCases) ? new HashMap<>(16) : apiCases.stream().collect( - Collectors.groupingBy(apiCase -> Optional.ofNullable(apiCase.getLastExecResult()).orElse(ExecStatus.PENDING.name()), Collectors.counting())); - // 接口场景用例分组统计开始 (为空时, 默认为未执行) - List apiScenarios = planApiScenarioMap.get(planId); - statisticsResponse.setApiScenarioCount(CollectionUtils.isNotEmpty(apiScenarios) ? apiScenarios.size() : 0); - Map apiScenarioResultCountMap = CollectionUtils.isEmpty(apiScenarios) ? new HashMap<>(16) : apiScenarios.stream().collect( - Collectors.groupingBy(apiScenario -> Optional.ofNullable(apiScenario.getLastExecResult()).orElse(ExecStatus.PENDING.name()), Collectors.counting())); - // 用例数据汇总 - statisticsResponse.setSuccessCount(countCaseMap(functionalCaseResultCountMap, apiCaseResultCountMap, apiScenarioResultCountMap, ExecStatus.SUCCESS.name())); - statisticsResponse.setErrorCount(countCaseMap(functionalCaseResultCountMap, apiCaseResultCountMap, apiScenarioResultCountMap, ExecStatus.ERROR.name())); - statisticsResponse.setFakeErrorCount(countCaseMap(functionalCaseResultCountMap, apiCaseResultCountMap, apiScenarioResultCountMap, ExecStatus.FAKE_ERROR.name())); - statisticsResponse.setBlockCount(countCaseMap(functionalCaseResultCountMap, apiCaseResultCountMap, apiScenarioResultCountMap, ExecStatus.BLOCKED.name())); - statisticsResponse.setPendingCount(countCaseMap(functionalCaseResultCountMap, apiCaseResultCountMap, apiScenarioResultCountMap, ExecStatus.PENDING.name())); - statisticsResponse.setCaseTotal(statisticsResponse.getFunctionalCaseCount() + statisticsResponse.getApiCaseCount() + statisticsResponse.getApiScenarioCount()); - // 通过率 {通过用例数/总用例数} && 执行进度 {非未执行的用例数/总用例数} - statisticsResponse.setPassRate(RateCalculateUtils.divWithPrecision(statisticsResponse.getSuccessCount(), statisticsResponse.getCaseTotal(), 2)); - statisticsResponse.setExecuteRate(RateCalculateUtils.divWithPrecision(statisticsResponse.getCaseTotal() - statisticsResponse.getPendingCount(), statisticsResponse.getCaseTotal(), 2)); + + // 测试计划组没有测试计划配置。同理,也不用参与用例等数据的计算 + if (planConfigMap.containsKey(planId)) { + statisticsResponse.setPassThreshold(planConfigMap.get(planId).getPassThreshold()); + // 功能用例分组统计开始 (为空时, 默认为未执行) + List functionalCases = planFunctionalCaseMap.get(planId); + statisticsResponse.setFunctionalCaseCount(CollectionUtils.isNotEmpty(functionalCases) ? functionalCases.size() : 0); + Map functionalCaseResultCountMap = CollectionUtils.isEmpty(functionalCases) ? new HashMap<>(16) : functionalCases.stream().collect( + Collectors.groupingBy(functionalCase -> Optional.ofNullable(functionalCase.getLastExecResult()).orElse(ExecStatus.PENDING.name()), Collectors.counting())); + // 接口用例分组统计开始 (为空时, 默认为未执行) + List apiCases = planApiCaseMap.get(planId); + statisticsResponse.setApiCaseCount(CollectionUtils.isNotEmpty(apiCases) ? apiCases.size() : 0); + Map apiCaseResultCountMap = CollectionUtils.isEmpty(apiCases) ? new HashMap<>(16) : apiCases.stream().collect( + Collectors.groupingBy(apiCase -> Optional.ofNullable(apiCase.getLastExecResult()).orElse(ExecStatus.PENDING.name()), Collectors.counting())); + // 接口场景用例分组统计开始 (为空时, 默认为未执行) + List apiScenarios = planApiScenarioMap.get(planId); + statisticsResponse.setApiScenarioCount(CollectionUtils.isNotEmpty(apiScenarios) ? apiScenarios.size() : 0); + Map apiScenarioResultCountMap = CollectionUtils.isEmpty(apiScenarios) ? new HashMap<>(16) : apiScenarios.stream().collect( + Collectors.groupingBy(apiScenario -> Optional.ofNullable(apiScenario.getLastExecResult()).orElse(ExecStatus.PENDING.name()), Collectors.counting())); + // 用例数据汇总 + statisticsResponse.setSuccessCount(countCaseMap(functionalCaseResultCountMap, apiCaseResultCountMap, apiScenarioResultCountMap, ExecStatus.SUCCESS.name())); + statisticsResponse.setErrorCount(countCaseMap(functionalCaseResultCountMap, apiCaseResultCountMap, apiScenarioResultCountMap, ExecStatus.ERROR.name())); + statisticsResponse.setFakeErrorCount(countCaseMap(functionalCaseResultCountMap, apiCaseResultCountMap, apiScenarioResultCountMap, ExecStatus.FAKE_ERROR.name())); + statisticsResponse.setBlockCount(countCaseMap(functionalCaseResultCountMap, apiCaseResultCountMap, apiScenarioResultCountMap, ExecStatus.BLOCKED.name())); + statisticsResponse.setPendingCount(countCaseMap(functionalCaseResultCountMap, apiCaseResultCountMap, apiScenarioResultCountMap, ExecStatus.PENDING.name())); + statisticsResponse.setCaseTotal(statisticsResponse.getFunctionalCaseCount() + statisticsResponse.getApiCaseCount() + statisticsResponse.getApiScenarioCount()); + // 通过率 {通过用例数/总用例数} && 执行进度 {非未执行的用例数/总用例数} + statisticsResponse.setPassRate(RateCalculateUtils.divWithPrecision(statisticsResponse.getSuccessCount(), statisticsResponse.getCaseTotal(), 2)); + statisticsResponse.setExecuteRate(RateCalculateUtils.divWithPrecision(statisticsResponse.getCaseTotal() - statisticsResponse.getPendingCount(), statisticsResponse.getCaseTotal(), 2)); + } planStatisticsResponses.add(statisticsResponse); //定时任务 diff --git a/backend/services/test-plan/src/test/java/io/metersphere/plan/controller/TestPlanTests.java b/backend/services/test-plan/src/test/java/io/metersphere/plan/controller/TestPlanTests.java index 3965fef15d..42a10a00c1 100644 --- a/backend/services/test-plan/src/test/java/io/metersphere/plan/controller/TestPlanTests.java +++ b/backend/services/test-plan/src/test/java/io/metersphere/plan/controller/TestPlanTests.java @@ -1370,7 +1370,7 @@ public class TestPlanTests extends BaseTest { this.requestPostAndReturn(URL_POST_TEST_PLAN_STATISTICS, List.of(groupTestPlanId7)) .getResponse().getContentAsString(), ResultHolder.class).getData()), TestPlanStatisticsResponse.class); - Assertions.assertTrue(statisticsResponses.size() == 1); + Assertions.assertTrue(statisticsResponses.size() > 1); Assertions.assertTrue(statisticsResponses.getFirst().getNextTriggerTime() > 0); Assertions.assertTrue(statisticsResponses.getFirst().getScheduleConfig().isEnable()); @@ -1395,7 +1395,7 @@ public class TestPlanTests extends BaseTest { this.requestPostAndReturn(URL_POST_TEST_PLAN_STATISTICS, List.of(groupTestPlanId7)) .getResponse().getContentAsString(), ResultHolder.class).getData()), TestPlanStatisticsResponse.class); - Assertions.assertTrue(statisticsResponses.size() == 1); + Assertions.assertTrue(statisticsResponses.size() > 1); Assertions.assertTrue(statisticsResponses.getFirst().getNextTriggerTime() == null); Assertions.assertFalse(statisticsResponses.getFirst().getScheduleConfig().isEnable()); @@ -1474,7 +1474,7 @@ public class TestPlanTests extends BaseTest { this.requestPostAndReturn(URL_POST_TEST_PLAN_STATISTICS, List.of(groupTestPlanId7)) .getResponse().getContentAsString(), ResultHolder.class).getData()), TestPlanStatisticsResponse.class); - Assertions.assertTrue(statisticsResponses.size() == 1); + Assertions.assertTrue(statisticsResponses.size() > 1); Assertions.assertTrue(statisticsResponses.getFirst().getNextTriggerTime() == null); Assertions.assertTrue(statisticsResponses.getFirst().getScheduleConfig() == null); }