fix(测试计划): 修改测试计划统计接口没查询子计划的缺陷
This commit is contained in:
parent
52b046cd71
commit
1c4f4e0fec
|
@ -129,7 +129,7 @@ public class SimpleUserService {
|
|||
}
|
||||
|
||||
private List<UserCreateInfo> 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<String> 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<User> 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());
|
||||
|
|
|
@ -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<String> userIds, boolean enable, String operator);
|
||||
int GWHowToChangeUser(List<String> userIds, boolean enable, String operator);
|
||||
|
||||
int GWHowToDeleteUser(List<String> userIdList, String operator);
|
||||
}
|
||||
|
|
|
@ -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<String> tags;
|
||||
|
|
|
@ -762,16 +762,22 @@ public class TestPlanService extends TestPlanBaseUtilsService {
|
|||
testPlan.setStatus(testPlanFinalStatus);
|
||||
testPlanMapper.updateByPrimaryKeySelective(testPlan);
|
||||
|
||||
List<TestPlan> 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<TestPlan> 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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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<TestPlanStatisticsResponse> calculateRate(List<String> planIds) {
|
||||
// 查出子计划
|
||||
TestPlanExample testPlanExample = new TestPlanExample();
|
||||
testPlanExample.createCriteria().andGroupIdIn(planIds);
|
||||
List<TestPlan> childrenPlan = testPlanMapper.selectByExample(testPlanExample);
|
||||
childrenPlan.forEach(item -> planIds.add(item.getId()));
|
||||
|
||||
List<TestPlanStatisticsResponse> 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<TestPlanFunctionalCase> functionalCases = planFunctionalCaseMap.get(planId);
|
||||
statisticsResponse.setFunctionalCaseCount(CollectionUtils.isNotEmpty(functionalCases) ? functionalCases.size() : 0);
|
||||
Map<String, Long> functionalCaseResultCountMap = CollectionUtils.isEmpty(functionalCases) ? new HashMap<>(16) : functionalCases.stream().collect(
|
||||
Collectors.groupingBy(functionalCase -> Optional.ofNullable(functionalCase.getLastExecResult()).orElse(ExecStatus.PENDING.name()), Collectors.counting()));
|
||||
// 接口用例分组统计开始 (为空时, 默认为未执行)
|
||||
List<TestPlanApiCase> apiCases = planApiCaseMap.get(planId);
|
||||
statisticsResponse.setApiCaseCount(CollectionUtils.isNotEmpty(apiCases) ? apiCases.size() : 0);
|
||||
Map<String, Long> apiCaseResultCountMap = CollectionUtils.isEmpty(apiCases) ? new HashMap<>(16) : apiCases.stream().collect(
|
||||
Collectors.groupingBy(apiCase -> Optional.ofNullable(apiCase.getLastExecResult()).orElse(ExecStatus.PENDING.name()), Collectors.counting()));
|
||||
// 接口场景用例分组统计开始 (为空时, 默认为未执行)
|
||||
List<TestPlanApiScenario> apiScenarios = planApiScenarioMap.get(planId);
|
||||
statisticsResponse.setApiScenarioCount(CollectionUtils.isNotEmpty(apiScenarios) ? apiScenarios.size() : 0);
|
||||
Map<String, Long> 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<TestPlanFunctionalCase> functionalCases = planFunctionalCaseMap.get(planId);
|
||||
statisticsResponse.setFunctionalCaseCount(CollectionUtils.isNotEmpty(functionalCases) ? functionalCases.size() : 0);
|
||||
Map<String, Long> functionalCaseResultCountMap = CollectionUtils.isEmpty(functionalCases) ? new HashMap<>(16) : functionalCases.stream().collect(
|
||||
Collectors.groupingBy(functionalCase -> Optional.ofNullable(functionalCase.getLastExecResult()).orElse(ExecStatus.PENDING.name()), Collectors.counting()));
|
||||
// 接口用例分组统计开始 (为空时, 默认为未执行)
|
||||
List<TestPlanApiCase> apiCases = planApiCaseMap.get(planId);
|
||||
statisticsResponse.setApiCaseCount(CollectionUtils.isNotEmpty(apiCases) ? apiCases.size() : 0);
|
||||
Map<String, Long> apiCaseResultCountMap = CollectionUtils.isEmpty(apiCases) ? new HashMap<>(16) : apiCases.stream().collect(
|
||||
Collectors.groupingBy(apiCase -> Optional.ofNullable(apiCase.getLastExecResult()).orElse(ExecStatus.PENDING.name()), Collectors.counting()));
|
||||
// 接口场景用例分组统计开始 (为空时, 默认为未执行)
|
||||
List<TestPlanApiScenario> apiScenarios = planApiScenarioMap.get(planId);
|
||||
statisticsResponse.setApiScenarioCount(CollectionUtils.isNotEmpty(apiScenarios) ? apiScenarios.size() : 0);
|
||||
Map<String, Long> 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);
|
||||
|
||||
//定时任务
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue