refactor(工作台): 优化测试计划概览卡片接口访问时间
This commit is contained in:
parent
c4aae7b891
commit
b53ee23e25
|
@ -121,7 +121,7 @@ public class DashboardService {
|
||||||
@Resource
|
@Resource
|
||||||
private TestPlanMapper testPlanMapper;
|
private TestPlanMapper testPlanMapper;
|
||||||
@Resource
|
@Resource
|
||||||
private UserMapper userMapper;
|
private ExtUserMapper extUserMapper;
|
||||||
@Resource
|
@Resource
|
||||||
private BugCommonService bugCommonService;
|
private BugCommonService bugCommonService;
|
||||||
@Resource
|
@Resource
|
||||||
|
@ -163,6 +163,8 @@ public class DashboardService {
|
||||||
public static final String FUNCTIONAL_CASE_MODULE = "caseManagement";
|
public static final String FUNCTIONAL_CASE_MODULE = "caseManagement";
|
||||||
public static final String BUG_MODULE = "bugManagement";
|
public static final String BUG_MODULE = "bugManagement";
|
||||||
|
|
||||||
|
public static final String NONE = "NONE";
|
||||||
|
|
||||||
|
|
||||||
public OverViewCountDTO createByMeCount(DashboardFrontPageRequest request, String userId) {
|
public OverViewCountDTO createByMeCount(DashboardFrontPageRequest request, String userId) {
|
||||||
OverViewCountDTO map = getNoProjectData(request);
|
OverViewCountDTO map = getNoProjectData(request);
|
||||||
|
@ -804,62 +806,33 @@ public class DashboardService {
|
||||||
// 计划-缺陷的关联数据
|
// 计划-缺陷的关联数据
|
||||||
List<TestPlanBugPageResponse> planBugs = extTestPlanBugMapper.selectBugCountByPlanId(planId);
|
List<TestPlanBugPageResponse> planBugs = extTestPlanBugMapper.selectBugCountByPlanId(planId);
|
||||||
//获取卡片数据
|
//获取卡片数据
|
||||||
boolean addDefaultUser = false;
|
|
||||||
buildCountMap(statisticsResponse, planBugs, overViewCountDTO);
|
buildCountMap(statisticsResponse, planBugs, overViewCountDTO);
|
||||||
List<TestPlanFunctionalCase> caseUserNullList = planFunctionalCases.stream().filter(t -> StringUtils.isBlank(t.getExecuteUser())).toList();
|
Map<String, List<TestPlanFunctionalCase>> caseUserMap = planFunctionalCases.stream().collect(Collectors.groupingBy(t -> StringUtils.isEmpty(t.getExecuteUser()) ? NONE : t.getExecuteUser()));
|
||||||
Map<String, List<TestPlanFunctionalCase>> caseUserMap = planFunctionalCases.stream().filter(t -> StringUtils.isNotBlank(t.getExecuteUser())).collect(Collectors.groupingBy(TestPlanFunctionalCase::getExecuteUser));
|
Map<String, List<TestPlanApiCase>> apiCaseUserMap = planApiCases.stream().collect(Collectors.groupingBy(t -> StringUtils.isEmpty(t.getExecuteUser()) ? NONE : t.getExecuteUser()));
|
||||||
if (CollectionUtils.isNotEmpty(caseUserNullList)) {
|
Map<String, List<TestPlanApiScenario>> apiScenarioUserMap = planApiScenarios.stream().collect(Collectors.groupingBy(t -> StringUtils.isEmpty(t.getExecuteUser()) ? NONE : t.getExecuteUser()));
|
||||||
addDefaultUser = true;
|
|
||||||
caseUserMap.put("NONE", caseUserNullList);
|
|
||||||
}
|
|
||||||
List<TestPlanApiCase> apiCaseUserNullList = planApiCases.stream().filter(t -> StringUtils.isBlank(t.getExecuteUser())).toList();
|
|
||||||
Map<String, List<TestPlanApiCase>> apiCaseUserMap = planApiCases.stream().filter(t -> StringUtils.isNotBlank(t.getExecuteUser())).collect(Collectors.groupingBy(TestPlanApiCase::getExecuteUser));
|
|
||||||
if (CollectionUtils.isNotEmpty(apiCaseUserNullList)) {
|
|
||||||
addDefaultUser = true;
|
|
||||||
apiCaseUserMap.put("NONE", apiCaseUserNullList);
|
|
||||||
}
|
|
||||||
List<TestPlanApiScenario> apiScenarioNullList = planApiScenarios.stream().filter(t -> StringUtils.isBlank(t.getExecuteUser())).toList();
|
|
||||||
Map<String, List<TestPlanApiScenario>> apiScenarioUserMap = planApiScenarios.stream().filter(t -> StringUtils.isNotBlank(t.getExecuteUser())).collect(Collectors.groupingBy(TestPlanApiScenario::getExecuteUser));
|
|
||||||
if (CollectionUtils.isNotEmpty(apiScenarioNullList)) {
|
|
||||||
addDefaultUser = true;
|
|
||||||
apiScenarioUserMap.put("NONE", apiScenarioNullList);
|
|
||||||
}
|
|
||||||
Map<String, List<TestPlanBugPageResponse>> bugUserMap = planBugs.stream().collect(Collectors.groupingBy(TestPlanBugPageResponse::getCreateUser));
|
Map<String, List<TestPlanBugPageResponse>> bugUserMap = planBugs.stream().collect(Collectors.groupingBy(TestPlanBugPageResponse::getCreateUser));
|
||||||
List<User> users = getUsers(caseUserMap, apiCaseUserMap, apiScenarioUserMap, bugUserMap);
|
|
||||||
Map<String, String> userNameMap = users.stream().collect(Collectors.toMap(User::getId, User::getName));
|
|
||||||
int totalCount = planFunctionalCases.size() + planApiCases.size() + planApiScenarios.size() + planBugs.size();
|
int totalCount = planFunctionalCases.size() + planApiCases.size() + planApiScenarios.size() + planBugs.size();
|
||||||
List<String> nameList = new ArrayList<>();
|
List<User> users = getUsers(caseUserMap, apiCaseUserMap, apiScenarioUserMap, bugUserMap, totalCount);
|
||||||
if (CollectionUtils.isEmpty(users)) {
|
List<String> nameList =users.stream().map(User::getName).toList();
|
||||||
if (totalCount > 0) {
|
|
||||||
nameList = List.of(Translator.get("plan_executor"));
|
|
||||||
userNameMap.put("NONE", Translator.get("plan_executor"));
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (addDefaultUser) {
|
|
||||||
userNameMap.put("NONE", Translator.get("plan_executor"));
|
|
||||||
}
|
|
||||||
nameList = userNameMap.values().stream().toList();
|
|
||||||
}
|
|
||||||
overViewCountDTO.setXAxis(nameList);
|
overViewCountDTO.setXAxis(nameList);
|
||||||
|
|
||||||
//获取柱状图数据
|
//获取柱状图数据
|
||||||
List<NameArrayDTO> nameArrayDTOList = getNameArrayDTOS(projectId, userNameMap, caseUserMap, apiCaseUserMap, apiScenarioUserMap, bugUserMap);
|
List<NameArrayDTO> nameArrayDTOList = getNameArrayDTOS(projectId, users, caseUserMap, apiCaseUserMap, apiScenarioUserMap, bugUserMap);
|
||||||
overViewCountDTO.setProjectCountList(nameArrayDTOList);
|
overViewCountDTO.setProjectCountList(nameArrayDTOList);
|
||||||
return overViewCountDTO;
|
return overViewCountDTO;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private List<NameArrayDTO> getNameArrayDTOS(String projectId, Map<String, String> userNameMap, Map<String, List<TestPlanFunctionalCase>> caseUserMap, Map<String, List<TestPlanApiCase>> apiCaseUserMap, Map<String, List<TestPlanApiScenario>> apiScenarioUserMap, Map<String, List<TestPlanBugPageResponse>> bugUserMap) {
|
private List<NameArrayDTO> getNameArrayDTOS(String projectId, List<User> users, Map<String, List<TestPlanFunctionalCase>> caseUserMap, Map<String, List<TestPlanApiCase>> apiCaseUserMap, Map<String, List<TestPlanApiScenario>> apiScenarioUserMap, Map<String, List<TestPlanBugPageResponse>> bugUserMap) {
|
||||||
List<Integer> totalCaseCount = new ArrayList<>();
|
List<Integer> totalCaseCount = new ArrayList<>();
|
||||||
List<Integer> finishCaseCount = new ArrayList<>();
|
List<Integer> finishCaseCount = new ArrayList<>();
|
||||||
List<Integer> createBugCount = new ArrayList<>();
|
List<Integer> createBugCount = new ArrayList<>();
|
||||||
List<Integer> closeBugCount = new ArrayList<>();
|
List<Integer> closeBugCount = new ArrayList<>();
|
||||||
|
|
||||||
String platformName = projectApplicationService.getPlatformName(projectId);
|
String platformName = projectApplicationService.getPlatformName(projectId);
|
||||||
List<SelectOption> headerStatusOption = getStatusOption(projectId, platformName);
|
List<String> statusList = getBugEndStatus(projectId, platformName);
|
||||||
List<String> statusList = headerStatusOption.stream().map(SelectOption::getValue).toList();
|
users.forEach(user -> {
|
||||||
userNameMap.forEach((userId, name) -> {
|
String userId = user.getId();
|
||||||
int count = 0;
|
int count = 0;
|
||||||
int finishCount = 0;
|
int finishCount = 0;
|
||||||
List<TestPlanFunctionalCase> testPlanFunctionalCases = caseUserMap.get(userId);
|
List<TestPlanFunctionalCase> testPlanFunctionalCases = caseUserMap.get(userId);
|
||||||
|
@ -917,20 +890,40 @@ public class DashboardService {
|
||||||
return nameArrayDTOList;
|
return nameArrayDTOList;
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<User> getUsers(Map<String, List<TestPlanFunctionalCase>> caseUserMap, Map<String, List<TestPlanApiCase>> apiCaseUserMap, Map<String, List<TestPlanApiScenario>> apiScenarioUserMap, Map<String, List<TestPlanBugPageResponse>> bugUserMap) {
|
private List<User> getUsers(Map<String, List<TestPlanFunctionalCase>> caseUserMap, Map<String, List<TestPlanApiCase>> apiCaseUserMap, Map<String, List<TestPlanApiScenario>> apiScenarioUserMap, Map<String, List<TestPlanBugPageResponse>> bugUserMap, int totalCount) {
|
||||||
Set<String> userSet = new HashSet<>();
|
Set<String> caseUserIds = caseUserMap.keySet();
|
||||||
userSet.addAll(caseUserMap.keySet());
|
boolean addDefaultUser = caseUserIds.contains(NONE);
|
||||||
userSet.addAll(apiCaseUserMap.keySet());
|
Set<String> userSet = new HashSet<>(caseUserIds);
|
||||||
userSet.addAll(apiScenarioUserMap.keySet());
|
Set<String> apiCaseIds = apiCaseUserMap.keySet();
|
||||||
userSet.addAll(bugUserMap.keySet());
|
userSet.addAll(apiCaseIds);
|
||||||
if (CollectionUtils.isEmpty(userSet)) {
|
if (apiCaseIds.contains(NONE)) {
|
||||||
return new ArrayList<>();
|
addDefaultUser = true;
|
||||||
}
|
}
|
||||||
UserExample userExample = new UserExample();
|
Set<String> apiScenarioIds = apiScenarioUserMap.keySet();
|
||||||
userExample.createCriteria().andIdIn(new ArrayList<>(userSet));
|
userSet.addAll(apiScenarioIds);
|
||||||
userExample.createCriteria().andEnableEqualTo(true);
|
if (apiScenarioIds.contains(NONE)) {
|
||||||
userExample.createCriteria().andDeletedEqualTo(false);
|
addDefaultUser = true;
|
||||||
return userMapper.selectByExample(userExample);
|
}
|
||||||
|
userSet.addAll(bugUserMap.keySet());
|
||||||
|
List<User> users = new ArrayList<>();
|
||||||
|
if (CollectionUtils.isEmpty(userSet)) {
|
||||||
|
if (totalCount>0) {
|
||||||
|
addDefaultUser(users);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
users = extUserMapper.selectSimpleUser(userSet);
|
||||||
|
if (addDefaultUser) {
|
||||||
|
addDefaultUser(users);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return users;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void addDefaultUser(List<User> users) {
|
||||||
|
User user = new User();
|
||||||
|
user.setId(NONE);
|
||||||
|
user.setName(Translator.get("plan_executor"));
|
||||||
|
users.add(user);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void buildCountMap(TestPlanStatisticsResponse planCount, List<TestPlanBugPageResponse> planBugs, OverViewCountDTO overViewCountDTO) {
|
private void buildCountMap(TestPlanStatisticsResponse planCount, List<TestPlanBugPageResponse> planBugs, OverViewCountDTO overViewCountDTO) {
|
||||||
|
@ -1797,7 +1790,7 @@ public class DashboardService {
|
||||||
List<CascadeChildrenDTO> cascadeDTOList = new ArrayList<>();
|
List<CascadeChildrenDTO> cascadeDTOList = new ArrayList<>();
|
||||||
List<TestPlanAndGroupInfoDTO> groupAndPlanInfo = extTestPlanMapper.getGroupAndPlanInfo(projectId);
|
List<TestPlanAndGroupInfoDTO> groupAndPlanInfo = extTestPlanMapper.getGroupAndPlanInfo(projectId);
|
||||||
TestPlanExample testPlanExample = new TestPlanExample();
|
TestPlanExample testPlanExample = new TestPlanExample();
|
||||||
testPlanExample.createCriteria().andProjectIdEqualTo(projectId).andTypeEqualTo(TestPlanConstants.TEST_PLAN_TYPE_PLAN).andGroupIdEqualTo("NONE");
|
testPlanExample.createCriteria().andProjectIdEqualTo(projectId).andTypeEqualTo(TestPlanConstants.TEST_PLAN_TYPE_PLAN).andGroupIdEqualTo(NONE);
|
||||||
testPlanExample.setOrderByClause(" create_time DESC ");
|
testPlanExample.setOrderByClause(" create_time DESC ");
|
||||||
List<TestPlan> testPlans = testPlanMapper.selectByExample(testPlanExample);
|
List<TestPlan> testPlans = testPlanMapper.selectByExample(testPlanExample);
|
||||||
Map<String, List<TestPlanAndGroupInfoDTO>> groupMap = groupAndPlanInfo.stream().sorted(Comparator.comparing(TestPlanAndGroupInfoDTO::getGroupCreateTime).reversed()).collect(Collectors.groupingBy(TestPlanAndGroupInfoDTO::getGroupId));
|
Map<String, List<TestPlanAndGroupInfoDTO>> groupMap = groupAndPlanInfo.stream().sorted(Comparator.comparing(TestPlanAndGroupInfoDTO::getGroupCreateTime).reversed()).collect(Collectors.groupingBy(TestPlanAndGroupInfoDTO::getGroupId));
|
||||||
|
|
|
@ -7,6 +7,7 @@ import io.metersphere.system.dto.user.UserExtendDTO;
|
||||||
import org.apache.ibatis.annotations.Param;
|
import org.apache.ibatis.annotations.Param;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
public interface ExtUserMapper {
|
public interface ExtUserMapper {
|
||||||
|
|
||||||
|
@ -50,4 +51,12 @@ public interface ExtUserMapper {
|
||||||
void updateInstalled();
|
void updateInstalled();
|
||||||
|
|
||||||
List<UserExtendDTO> getMemberList(@Param("request") MemberRequest request);
|
List<UserExtendDTO> getMemberList(@Param("request") MemberRequest request);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据用户ID查询有效用户id,名称集合
|
||||||
|
*
|
||||||
|
* @param ids 用户ID集合
|
||||||
|
* @return 用户列表
|
||||||
|
*/
|
||||||
|
List<User> selectSimpleUser(@Param("ids") Set<String> ids);
|
||||||
}
|
}
|
||||||
|
|
|
@ -119,5 +119,13 @@
|
||||||
</if>
|
</if>
|
||||||
group by u.id
|
group by u.id
|
||||||
</select>
|
</select>
|
||||||
|
<select id="selectSimpleUser" resultType="io.metersphere.system.domain.User">
|
||||||
|
select id,
|
||||||
|
`name` from user
|
||||||
|
where deleted = 0 and enable = 1 and id in
|
||||||
|
<foreach collection="ids" item="id" open="(" separator="," close=")">
|
||||||
|
#{id}
|
||||||
|
</foreach>
|
||||||
|
</select>
|
||||||
|
|
||||||
</mapper>
|
</mapper>
|
Loading…
Reference in New Issue