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) {
|
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) {
|
if (responseCode == 0) {
|
||||||
operationLogService.batchAdd(userLogService.getBatchAddLogs(userCreateDTO.getUserInfoList(), operator, requestPath));
|
operationLogService.batchAdd(userLogService.getBatchAddLogs(userCreateDTO.getUserInfoList(), operator, requestPath));
|
||||||
} else {
|
} else {
|
||||||
|
@ -225,7 +225,7 @@ public class SimpleUserService {
|
||||||
this.checkProcessUserAndThrowException(request.getSelectIds(), operatorId, operatorName, Translator.get("user.not.disable"));
|
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) {
|
if (responseCode == 0) {
|
||||||
TableBatchProcessResponse response = new TableBatchProcessResponse();
|
TableBatchProcessResponse response = new TableBatchProcessResponse();
|
||||||
|
@ -319,12 +319,13 @@ public class SimpleUserService {
|
||||||
this.checkUserInDb(userIdList);
|
this.checkUserInDb(userIdList);
|
||||||
//检查是否含有Admin
|
//检查是否含有Admin
|
||||||
this.checkProcessUserAndThrowException(userIdList, operatorId, operatorName, Translator.get("user.not.delete"));
|
this.checkProcessUserAndThrowException(userIdList, operatorId, operatorName, Translator.get("user.not.delete"));
|
||||||
|
//开始删除
|
||||||
UserExample userExample = new UserExample();
|
UserExample userExample = new UserExample();
|
||||||
userExample.createCriteria().andIdIn(userIdList);
|
userExample.createCriteria().andIdIn(userIdList);
|
||||||
//更新删除标志位
|
|
||||||
TableBatchProcessResponse response = new TableBatchProcessResponse();
|
TableBatchProcessResponse response = new TableBatchProcessResponse();
|
||||||
response.setTotalCount(userIdList.size());
|
response.setTotalCount(userIdList.size());
|
||||||
response.setSuccessCount(this.deleteUserByList(userIdList, operatorId));
|
response.setSuccessCount(
|
||||||
|
Objects.requireNonNull(CommonBeanFactory.getBean(UserXpackService.class)).GWHowToDeleteUser(userIdList, operatorId));
|
||||||
//删除用户角色关系
|
//删除用户角色关系
|
||||||
userRoleRelationService.deleteByUserIdList(userIdList);
|
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) {
|
public List<User> getUserList(String keyword) {
|
||||||
return extUserMapper.selectUserList(keyword);
|
return extUserMapper.selectUserList(keyword);
|
||||||
}
|
}
|
||||||
|
@ -521,7 +505,7 @@ public class SimpleUserService {
|
||||||
this.add(userInvite.getEmail());
|
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) {
|
if (responseCode == 0) {
|
||||||
//删除本次邀请记录
|
//删除本次邀请记录
|
||||||
userInviteService.deleteInviteById(userInvite.getId());
|
userInviteService.deleteInviteById(userInvite.getId());
|
||||||
|
|
|
@ -11,9 +11,11 @@ import java.util.List;
|
||||||
*/
|
*/
|
||||||
public interface UserXpackService {
|
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 {
|
public class TestPlanBatchEditRequest extends TestPlanBatchProcessRequest {
|
||||||
|
|
||||||
@Schema(description = "是否追加")
|
@Schema(description = "是否追加")
|
||||||
private boolean append;
|
private boolean append = true;
|
||||||
|
|
||||||
@Schema(description = "标签")
|
@Schema(description = "标签")
|
||||||
private List<String> tags;
|
private List<String> tags;
|
||||||
|
|
|
@ -762,16 +762,22 @@ public class TestPlanService extends TestPlanBaseUtilsService {
|
||||||
testPlan.setStatus(testPlanFinalStatus);
|
testPlan.setStatus(testPlanFinalStatus);
|
||||||
testPlanMapper.updateByPrimaryKeySelective(testPlan);
|
testPlanMapper.updateByPrimaryKeySelective(testPlan);
|
||||||
|
|
||||||
List<TestPlan> childPlan = this.selectNotArchivedChildren(testPlanId);
|
testPlan = testPlanMapper.selectByPrimaryKey(testPlanId);
|
||||||
if (CollectionUtils.isNotEmpty(childPlan)) {
|
|
||||||
TestPlan updateGroupPlan = new TestPlan();
|
if (!StringUtils.equalsIgnoreCase(testPlan.getGroupId(), TestPlanConstants.TEST_PLAN_DEFAULT_GROUP_ID)) {
|
||||||
updateGroupPlan.setId(testPlanId);
|
//该测试计划是测试计划组内的子计划, 要同步计算测试计划组的状态
|
||||||
if (childPlan.stream().allMatch(item -> StringUtils.equals(item.getStatus(), TestPlanConstants.TEST_PLAN_STATUS_COMPLETED))) {
|
|
||||||
testPlan.setStatus(TestPlanConstants.TEST_PLAN_STATUS_COMPLETED);
|
List<TestPlan> childPlan = this.selectNotArchivedChildren(testPlan.getGroupId());
|
||||||
} else {
|
if (CollectionUtils.isNotEmpty(childPlan)) {
|
||||||
testPlan.setStatus(TestPlanConstants.TEST_PLAN_STATUS_UNDERWAY);
|
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
|
@Service
|
||||||
public class TestPlanStatisticsService {
|
public class TestPlanStatisticsService {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private TestPlanMapper testPlanMapper;
|
||||||
@Resource
|
@Resource
|
||||||
private TestPlanConfigMapper testPlanConfigMapper;
|
private TestPlanConfigMapper testPlanConfigMapper;
|
||||||
@Resource
|
@Resource
|
||||||
|
@ -74,12 +76,17 @@ public class TestPlanStatisticsService {
|
||||||
* @param planIds 计划ID集合
|
* @param planIds 计划ID集合
|
||||||
*/
|
*/
|
||||||
public List<TestPlanStatisticsResponse> calculateRate(List<String> planIds) {
|
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<>();
|
List<TestPlanStatisticsResponse> planStatisticsResponses = new ArrayList<>();
|
||||||
/*
|
/*
|
||||||
* 1. 查询计划下的用例数据集合
|
* 1. 查询计划下的用例数据集合
|
||||||
* 2. 根据执行结果统计(结果小数保留两位)
|
* 2. 根据执行结果统计(结果小数保留两位)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// 计划的更多配置
|
// 计划的更多配置
|
||||||
TestPlanConfigExample example = new TestPlanConfigExample();
|
TestPlanConfigExample example = new TestPlanConfigExample();
|
||||||
example.createCriteria().andTestPlanIdIn(planIds);
|
example.createCriteria().andTestPlanIdIn(planIds);
|
||||||
|
@ -99,32 +106,36 @@ public class TestPlanStatisticsService {
|
||||||
planIds.forEach(planId -> {
|
planIds.forEach(planId -> {
|
||||||
TestPlanStatisticsResponse statisticsResponse = new TestPlanStatisticsResponse();
|
TestPlanStatisticsResponse statisticsResponse = new TestPlanStatisticsResponse();
|
||||||
statisticsResponse.setId(planId);
|
statisticsResponse.setId(planId);
|
||||||
statisticsResponse.setPassThreshold(planConfigMap.get(planId).getPassThreshold());
|
|
||||||
// 功能用例分组统计开始 (为空时, 默认为未执行)
|
// 测试计划组没有测试计划配置。同理,也不用参与用例等数据的计算
|
||||||
List<TestPlanFunctionalCase> functionalCases = planFunctionalCaseMap.get(planId);
|
if (planConfigMap.containsKey(planId)) {
|
||||||
statisticsResponse.setFunctionalCaseCount(CollectionUtils.isNotEmpty(functionalCases) ? functionalCases.size() : 0);
|
statisticsResponse.setPassThreshold(planConfigMap.get(planId).getPassThreshold());
|
||||||
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<TestPlanFunctionalCase> functionalCases = planFunctionalCaseMap.get(planId);
|
||||||
// 接口用例分组统计开始 (为空时, 默认为未执行)
|
statisticsResponse.setFunctionalCaseCount(CollectionUtils.isNotEmpty(functionalCases) ? functionalCases.size() : 0);
|
||||||
List<TestPlanApiCase> apiCases = planApiCaseMap.get(planId);
|
Map<String, Long> functionalCaseResultCountMap = CollectionUtils.isEmpty(functionalCases) ? new HashMap<>(16) : functionalCases.stream().collect(
|
||||||
statisticsResponse.setApiCaseCount(CollectionUtils.isNotEmpty(apiCases) ? apiCases.size() : 0);
|
Collectors.groupingBy(functionalCase -> Optional.ofNullable(functionalCase.getLastExecResult()).orElse(ExecStatus.PENDING.name()), Collectors.counting()));
|
||||||
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<TestPlanApiCase> apiCases = planApiCaseMap.get(planId);
|
||||||
// 接口场景用例分组统计开始 (为空时, 默认为未执行)
|
statisticsResponse.setApiCaseCount(CollectionUtils.isNotEmpty(apiCases) ? apiCases.size() : 0);
|
||||||
List<TestPlanApiScenario> apiScenarios = planApiScenarioMap.get(planId);
|
Map<String, Long> apiCaseResultCountMap = CollectionUtils.isEmpty(apiCases) ? new HashMap<>(16) : apiCases.stream().collect(
|
||||||
statisticsResponse.setApiScenarioCount(CollectionUtils.isNotEmpty(apiScenarios) ? apiScenarios.size() : 0);
|
Collectors.groupingBy(apiCase -> Optional.ofNullable(apiCase.getLastExecResult()).orElse(ExecStatus.PENDING.name()), Collectors.counting()));
|
||||||
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()));
|
List<TestPlanApiScenario> apiScenarios = planApiScenarioMap.get(planId);
|
||||||
// 用例数据汇总
|
statisticsResponse.setApiScenarioCount(CollectionUtils.isNotEmpty(apiScenarios) ? apiScenarios.size() : 0);
|
||||||
statisticsResponse.setSuccessCount(countCaseMap(functionalCaseResultCountMap, apiCaseResultCountMap, apiScenarioResultCountMap, ExecStatus.SUCCESS.name()));
|
Map<String, Long> apiScenarioResultCountMap = CollectionUtils.isEmpty(apiScenarios) ? new HashMap<>(16) : apiScenarios.stream().collect(
|
||||||
statisticsResponse.setErrorCount(countCaseMap(functionalCaseResultCountMap, apiCaseResultCountMap, apiScenarioResultCountMap, ExecStatus.ERROR.name()));
|
Collectors.groupingBy(apiScenario -> Optional.ofNullable(apiScenario.getLastExecResult()).orElse(ExecStatus.PENDING.name()), Collectors.counting()));
|
||||||
statisticsResponse.setFakeErrorCount(countCaseMap(functionalCaseResultCountMap, apiCaseResultCountMap, apiScenarioResultCountMap, ExecStatus.FAKE_ERROR.name()));
|
// 用例数据汇总
|
||||||
statisticsResponse.setBlockCount(countCaseMap(functionalCaseResultCountMap, apiCaseResultCountMap, apiScenarioResultCountMap, ExecStatus.BLOCKED.name()));
|
statisticsResponse.setSuccessCount(countCaseMap(functionalCaseResultCountMap, apiCaseResultCountMap, apiScenarioResultCountMap, ExecStatus.SUCCESS.name()));
|
||||||
statisticsResponse.setPendingCount(countCaseMap(functionalCaseResultCountMap, apiCaseResultCountMap, apiScenarioResultCountMap, ExecStatus.PENDING.name()));
|
statisticsResponse.setErrorCount(countCaseMap(functionalCaseResultCountMap, apiCaseResultCountMap, apiScenarioResultCountMap, ExecStatus.ERROR.name()));
|
||||||
statisticsResponse.setCaseTotal(statisticsResponse.getFunctionalCaseCount() + statisticsResponse.getApiCaseCount() + statisticsResponse.getApiScenarioCount());
|
statisticsResponse.setFakeErrorCount(countCaseMap(functionalCaseResultCountMap, apiCaseResultCountMap, apiScenarioResultCountMap, ExecStatus.FAKE_ERROR.name()));
|
||||||
// 通过率 {通过用例数/总用例数} && 执行进度 {非未执行的用例数/总用例数}
|
statisticsResponse.setBlockCount(countCaseMap(functionalCaseResultCountMap, apiCaseResultCountMap, apiScenarioResultCountMap, ExecStatus.BLOCKED.name()));
|
||||||
statisticsResponse.setPassRate(RateCalculateUtils.divWithPrecision(statisticsResponse.getSuccessCount(), statisticsResponse.getCaseTotal(), 2));
|
statisticsResponse.setPendingCount(countCaseMap(functionalCaseResultCountMap, apiCaseResultCountMap, apiScenarioResultCountMap, ExecStatus.PENDING.name()));
|
||||||
statisticsResponse.setExecuteRate(RateCalculateUtils.divWithPrecision(statisticsResponse.getCaseTotal() - statisticsResponse.getPendingCount(), statisticsResponse.getCaseTotal(), 2));
|
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);
|
planStatisticsResponses.add(statisticsResponse);
|
||||||
|
|
||||||
//定时任务
|
//定时任务
|
||||||
|
|
|
@ -1370,7 +1370,7 @@ public class TestPlanTests extends BaseTest {
|
||||||
this.requestPostAndReturn(URL_POST_TEST_PLAN_STATISTICS, List.of(groupTestPlanId7))
|
this.requestPostAndReturn(URL_POST_TEST_PLAN_STATISTICS, List.of(groupTestPlanId7))
|
||||||
.getResponse().getContentAsString(), ResultHolder.class).getData()),
|
.getResponse().getContentAsString(), ResultHolder.class).getData()),
|
||||||
TestPlanStatisticsResponse.class);
|
TestPlanStatisticsResponse.class);
|
||||||
Assertions.assertTrue(statisticsResponses.size() == 1);
|
Assertions.assertTrue(statisticsResponses.size() > 1);
|
||||||
Assertions.assertTrue(statisticsResponses.getFirst().getNextTriggerTime() > 0);
|
Assertions.assertTrue(statisticsResponses.getFirst().getNextTriggerTime() > 0);
|
||||||
Assertions.assertTrue(statisticsResponses.getFirst().getScheduleConfig().isEnable());
|
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))
|
this.requestPostAndReturn(URL_POST_TEST_PLAN_STATISTICS, List.of(groupTestPlanId7))
|
||||||
.getResponse().getContentAsString(), ResultHolder.class).getData()),
|
.getResponse().getContentAsString(), ResultHolder.class).getData()),
|
||||||
TestPlanStatisticsResponse.class);
|
TestPlanStatisticsResponse.class);
|
||||||
Assertions.assertTrue(statisticsResponses.size() == 1);
|
Assertions.assertTrue(statisticsResponses.size() > 1);
|
||||||
Assertions.assertTrue(statisticsResponses.getFirst().getNextTriggerTime() == null);
|
Assertions.assertTrue(statisticsResponses.getFirst().getNextTriggerTime() == null);
|
||||||
Assertions.assertFalse(statisticsResponses.getFirst().getScheduleConfig().isEnable());
|
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))
|
this.requestPostAndReturn(URL_POST_TEST_PLAN_STATISTICS, List.of(groupTestPlanId7))
|
||||||
.getResponse().getContentAsString(), ResultHolder.class).getData()),
|
.getResponse().getContentAsString(), ResultHolder.class).getData()),
|
||||||
TestPlanStatisticsResponse.class);
|
TestPlanStatisticsResponse.class);
|
||||||
Assertions.assertTrue(statisticsResponses.size() == 1);
|
Assertions.assertTrue(statisticsResponses.size() > 1);
|
||||||
Assertions.assertTrue(statisticsResponses.getFirst().getNextTriggerTime() == null);
|
Assertions.assertTrue(statisticsResponses.getFirst().getNextTriggerTime() == null);
|
||||||
Assertions.assertTrue(statisticsResponses.getFirst().getScheduleConfig() == null);
|
Assertions.assertTrue(statisticsResponses.getFirst().getScheduleConfig() == null);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue