refactor(系统设置): 优化任务sql查询

This commit is contained in:
wxg0103 2024-04-17 10:59:05 +08:00 committed by Craftsman
parent 73cf6fb06b
commit 9d2a050983
9 changed files with 30 additions and 19 deletions

View File

@ -266,7 +266,7 @@
</if> </if>
</select> </select>
<select id="getHistoryDeleted" resultType="io.metersphere.api.dto.definition.ExecuteReportDTO"> <select id="getHistoryDeleted" resultType="io.metersphere.api.dto.definition.ExecuteReportDTO">
select ar.* from api_report ar INNER JOIN api_report_step ars on ar.id = ars.report_id select distinct ar.* from api_report ar INNER JOIN api_report_step ars on ar.id = ars.report_id
<if test="ids != null and ids.size() > 0"> <if test="ids != null and ids.size() > 0">
where ar.id in where ar.id in
<foreach collection="ids" item="id" open="(" separator="," close=")"> <foreach collection="ids" item="id" open="(" separator="," close=")">

View File

@ -245,7 +245,7 @@
</if> </if>
</select> </select>
<select id="getHistoryDeleted" resultType="io.metersphere.api.dto.definition.ExecuteReportDTO"> <select id="getHistoryDeleted" resultType="io.metersphere.api.dto.definition.ExecuteReportDTO">
select asr.* from select distinct asr.* from
api_scenario_report asr inner join api_scenario_report_step ars on asr.id = ars.report_id api_scenario_report asr inner join api_scenario_report_step ars on asr.id = ars.report_id
<if test="ids != null and ids.size() > 0"> <if test="ids != null and ids.size() > 0">
where asr.id in where asr.id in

View File

@ -136,13 +136,17 @@ public class ApiTaskCenterService {
list = extApiReportMapper.taskCenterlist(request, projectIds, DateUtils.getDailyStartTime(), DateUtils.getDailyEndTime()); list = extApiReportMapper.taskCenterlist(request, projectIds, DateUtils.getDailyStartTime(), DateUtils.getDailyEndTime());
//执行历史列表 //执行历史列表
List<String> reportIds = list.stream().map(TaskCenterDTO::getId).toList(); List<String> reportIds = list.stream().map(TaskCenterDTO::getId).toList();
List<ExecuteReportDTO> historyDeletedList = extApiReportMapper.getHistoryDeleted(reportIds); if (CollectionUtils.isNotEmpty(reportIds)){
historyDeletedMap = historyDeletedList.stream().collect(Collectors.toMap(ExecuteReportDTO::getId, Function.identity())); List<ExecuteReportDTO> historyDeletedList = extApiReportMapper.getHistoryDeleted(reportIds);
historyDeletedMap = historyDeletedList.stream().collect(Collectors.toMap(ExecuteReportDTO::getId, Function.identity()));
}
} else if (request.getModuleType().equals(TaskCenterResourceType.API_SCENARIO.toString())) { } else if (request.getModuleType().equals(TaskCenterResourceType.API_SCENARIO.toString())) {
list = extApiScenarioReportMapper.taskCenterlist(request, projectIds, DateUtils.getDailyStartTime(), DateUtils.getDailyEndTime()); list = extApiScenarioReportMapper.taskCenterlist(request, projectIds, DateUtils.getDailyStartTime(), DateUtils.getDailyEndTime());
List<String> reportIds = list.stream().map(TaskCenterDTO::getId).toList(); List<String> reportIds = list.stream().map(TaskCenterDTO::getId).toList();
List<ExecuteReportDTO> historyDeletedList = extApiScenarioReportMapper.getHistoryDeleted(reportIds); if (CollectionUtils.isNotEmpty(reportIds)) {
historyDeletedMap = historyDeletedList.stream().collect(Collectors.toMap(ExecuteReportDTO::getId, Function.identity())); List<ExecuteReportDTO> historyDeletedList = extApiScenarioReportMapper.getHistoryDeleted(reportIds);
historyDeletedMap = historyDeletedList.stream().collect(Collectors.toMap(ExecuteReportDTO::getId, Function.identity()));
}
} }
processTaskCenter(list, projectList, projectIds, historyDeletedMap); processTaskCenter(list, projectList, projectIds, historyDeletedMap);
} }

View File

@ -561,14 +561,17 @@ public class ApiTestCaseService extends MoveNodeService {
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss"); SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
//执行历史列表 //执行历史列表
List<String> reportIds = executeList.stream().map(ExecuteReportDTO::getId).toList(); List<String> reportIds = executeList.stream().map(ExecuteReportDTO::getId).toList();
List<ExecuteReportDTO> historyDeletedList = extApiReportMapper.getHistoryDeleted(reportIds); Map<String, ExecuteReportDTO> historyDeletedMap = new HashMap<>();
Map<String, ExecuteReportDTO> historyDeletedMap = historyDeletedList.stream().collect(Collectors.toMap(ExecuteReportDTO::getId, Function.identity())); if (CollectionUtils.isNotEmpty(reportIds)) {
List<ExecuteReportDTO> historyDeletedList = extApiReportMapper.getHistoryDeleted(reportIds);
historyDeletedMap = historyDeletedList.stream().collect(Collectors.toMap(ExecuteReportDTO::getId, Function.identity()));
}
Map<String, ExecuteReportDTO> finalHistoryDeletedMap = historyDeletedMap;
executeList.forEach(apiReport -> { executeList.forEach(apiReport -> {
apiReport.setOperationUser(userMap.get(apiReport.getCreateUser())); apiReport.setOperationUser(userMap.get(apiReport.getCreateUser()));
Date date = new Date(apiReport.getStartTime()); Date date = new Date(apiReport.getStartTime());
apiReport.setNum(sdf.format(date)); apiReport.setNum(sdf.format(date));
apiReport.setHistoryDeleted(MapUtils.isNotEmpty(historyDeletedMap) && !historyDeletedMap.containsKey(apiReport.getId())); apiReport.setHistoryDeleted(MapUtils.isNotEmpty(finalHistoryDeletedMap) && !finalHistoryDeletedMap.containsKey(apiReport.getId()));
}); });
return executeList; return executeList;
} }

View File

@ -2827,16 +2827,20 @@ public class ApiScenarioService extends MoveNodeService {
.collect(Collectors.toSet()); .collect(Collectors.toSet());
//执行历史列表 //执行历史列表
List<String> reportIds = executeList.stream().map(ExecuteReportDTO::getId).toList(); List<String> reportIds = executeList.stream().map(ExecuteReportDTO::getId).toList();
List<ExecuteReportDTO> historyDeletedList = extApiScenarioReportMapper.getHistoryDeleted(reportIds); Map<String, ExecuteReportDTO> historyDeletedMap = new HashMap<>();
Map<String, ExecuteReportDTO> historyDeletedMap = historyDeletedList.stream().collect(Collectors.toMap(ExecuteReportDTO::getId, Function.identity())); if (CollectionUtils.isNotEmpty(reportIds)) {
List<ExecuteReportDTO> historyDeletedList = extApiScenarioReportMapper.getHistoryDeleted(reportIds);
historyDeletedMap = historyDeletedList.stream().collect(Collectors.toMap(ExecuteReportDTO::getId, Function.identity()));
}
Map<String, String> userMap = userLoginService.getUserNameMap(new ArrayList<>(userSet)); Map<String, String> userMap = userLoginService.getUserNameMap(new ArrayList<>(userSet));
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss"); SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
Map<String, ExecuteReportDTO> finalHistoryDeletedMap = historyDeletedMap;
executeList.forEach(apiReport -> { executeList.forEach(apiReport -> {
apiReport.setOperationUser(userMap.get(apiReport.getCreateUser())); apiReport.setOperationUser(userMap.get(apiReport.getCreateUser()));
Date date = new Date(apiReport.getStartTime()); Date date = new Date(apiReport.getStartTime());
apiReport.setNum(sdf.format(date)); apiReport.setNum(sdf.format(date));
apiReport.setHistoryDeleted(MapUtils.isNotEmpty(historyDeletedMap) && !historyDeletedMap.containsKey(apiReport.getId())); apiReport.setHistoryDeleted(MapUtils.isNotEmpty(finalHistoryDeletedMap) && !finalHistoryDeletedMap.containsKey(apiReport.getId()));
}); });
return executeList; return executeList;
} }

View File

@ -88,7 +88,7 @@
<MsButton <MsButton
:disabled=" :disabled="
record.historyDeleted || record.historyDeleted ||
hasAnyPermission(['PROJECT_API_DEFINITION_CASE:READ+EXECUTE', 'PROJECT_API_REPORT:READ']) !hasAnyPermission(['PROJECT_API_DEFINITION_CASE:READ+EXECUTE', 'PROJECT_API_REPORT:READ'])
" "
class="!mr-0" class="!mr-0"
@click="showResult(record, rowIndex)" @click="showResult(record, rowIndex)"
@ -100,7 +100,7 @@
<MsButton <MsButton
:disabled=" :disabled="
record.historyDeleted || record.historyDeleted ||
hasAnyPermission(['PROJECT_API_DEFINITION_CASE:READ+EXECUTE', 'PROJECT_API_REPORT:READ']) !hasAnyPermission(['PROJECT_API_DEFINITION_CASE:READ+EXECUTE', 'PROJECT_API_REPORT:READ'])
" "
class="!mr-0" class="!mr-0"
@click="showResult(record, rowIndex)" @click="showResult(record, rowIndex)"

View File

@ -80,7 +80,7 @@
<MsButton <MsButton
:disabled=" :disabled="
record.historyDeleted || record.historyDeleted ||
hasAnyPermission(['PROJECT_API_SCENARIO:READ+EXECUTE', 'PROJECT_API_REPORT:READ']) !hasAnyPermission(['PROJECT_API_SCENARIO:READ+EXECUTE', 'PROJECT_API_REPORT:READ'])
" "
class="!mr-0" class="!mr-0"
@click="showResult(record)" @click="showResult(record)"
@ -92,7 +92,7 @@
<MsButton <MsButton
:disabled=" :disabled="
record.historyDeleted || record.historyDeleted ||
hasAnyPermission(['PROJECT_API_SCENARIO:READ+EXECUTE', 'PROJECT_API_REPORT:READ']) !hasAnyPermission(['PROJECT_API_SCENARIO:READ+EXECUTE', 'PROJECT_API_REPORT:READ'])
" "
class="!mr-0" class="!mr-0"
@click="showResult(record)" @click="showResult(record)"

View File

@ -61,5 +61,5 @@ export default {
'project.taskCenter.disableSuccess': 'Disable successfully', 'project.taskCenter.disableSuccess': 'Disable successfully',
'project.taskCenter.filterPlaceholderText': 'Please select a project', 'project.taskCenter.filterPlaceholderText': 'Please select a project',
'project.taskCenter.filterOrgPlaceholderText': 'Please select an organization', 'project.taskCenter.filterOrgPlaceholderText': 'Please select an organization',
'project.executionHistory.cleared': 'Execution history has been cleared', 'project.executionHistory.cleared': 'Execution result has been cleared',
}; };

View File

@ -59,5 +59,5 @@ export default {
'project.taskCenter.disableSuccess': '关闭成功', 'project.taskCenter.disableSuccess': '关闭成功',
'project.taskCenter.filterProPlaceholderText': '请选择所属项目', 'project.taskCenter.filterProPlaceholderText': '请选择所属项目',
'project.taskCenter.filterOrgPlaceholderText': '请选择所属组织', 'project.taskCenter.filterOrgPlaceholderText': '请选择所属组织',
'project.executionHistory.cleared': '执行历史被清理', 'project.executionHistory.cleared': '执行结果被清理',
}; };