refactor: 重构统计SQL书写位置

将统计SQL书写位置挪至由{table}Mapper挪至Ext{table}Mapper
This commit is contained in:
song.tianyang 2020-12-17 18:47:52 +08:00
parent ac11493d77
commit 5539df37b9
21 changed files with 149 additions and 131 deletions

View File

@ -220,11 +220,11 @@ public class APIReportService {
if(firstTime==null || lastTime == null){ if(firstTime==null || lastTime == null){
return 0; return 0;
}else { }else {
return apiTestReportMapper.countByProjectIDAndCreateInThisWeek(workspaceID,group,firstTime.getTime(),lastTime.getTime()); return extApiTestReportMapper.countByProjectIDAndCreateInThisWeek(workspaceID,group,firstTime.getTime(),lastTime.getTime());
} }
} }
public long countByWorkspaceIdAndGroup(String workspaceID, String group) { public long countByWorkspaceIdAndGroup(String workspaceID, String group) {
return apiTestReportMapper.countByWorkspaceIdAndGroup(workspaceID,group); return extApiTestReportMapper.countByWorkspaceIdAndGroup(workspaceID,group);
} }
} }

View File

@ -357,7 +357,7 @@ public class ApiAutomationService {
} }
public long countScenarioByProjectID(String projectId) { public long countScenarioByProjectID(String projectId) {
return apiScenarioMapper.countByProjectID(projectId); return extApiScenarioMapper.countByProjectID(projectId);
} }
public long countScenarioByProjectIDAndCreatInThisWeek(String projectId) { public long countScenarioByProjectIDAndCreatInThisWeek(String projectId) {
@ -369,7 +369,7 @@ public class ApiAutomationService {
if(firstTime==null || lastTime == null){ if(firstTime==null || lastTime == null){
return 0; return 0;
}else { }else {
return apiScenarioMapper.countByProjectIDAndCreatInThisWeek(projectId,firstTime.getTime(),lastTime.getTime()); return extApiScenarioMapper.countByProjectIDAndCreatInThisWeek(projectId,firstTime.getTime(),lastTime.getTime());
} }
} }
} }

View File

@ -49,12 +49,12 @@ public class ApiDefinitionExecResultService {
if(firstTime==null || lastTime == null){ if(firstTime==null || lastTime == null){
return 0; return 0;
}else { }else {
return apiDefinitionExecResultMapper.countByProjectIDAndCreateInThisWeek(projectId,firstTime.getTime(),lastTime.getTime()); return extApiDefinitionExecResultMapper.countByProjectIDAndCreateInThisWeek(projectId,firstTime.getTime(),lastTime.getTime());
} }
} }
public long countByTestCaseIDInProject(String projectId) { public long countByTestCaseIDInProject(String projectId) {
return apiDefinitionExecResultMapper.countByTestCaseIDInProject(projectId); return extApiDefinitionExecResultMapper.countByTestCaseIDInProject(projectId);
} }
@ -72,7 +72,7 @@ public class ApiDefinitionExecResultService {
if(startTime==null){ if(startTime==null){
return new ArrayList<>(0); return new ArrayList<>(0);
}else { }else {
return apiDefinitionExecResultMapper.findFaliureCaseInfoByProjectIDAndExecuteTimeAndLimitNumber(projectId,startTime.getTime(),limitNumber); return extApiDefinitionExecResultMapper.findFaliureCaseInfoByProjectIDAndExecuteTimeAndLimitNumber(projectId,startTime.getTime(),limitNumber);
} }
} }
} }

View File

@ -389,7 +389,7 @@ public class ApiDefinitionService {
* @return * @return
*/ */
public List<ApiDataCountResult> countProtocolByProjectID(String projectId) { public List<ApiDataCountResult> countProtocolByProjectID(String projectId) {
return apiDefinitionMapper.countProtocolByProjectID(projectId); return extApiDefinitionMapper.countProtocolByProjectID(projectId);
} }
/** /**
@ -406,7 +406,7 @@ public class ApiDefinitionService {
if(firstTime==null || lastTime == null){ if(firstTime==null || lastTime == null){
return 0; return 0;
}else { }else {
return apiDefinitionMapper.countByProjectIDAndCreateInThisWeek(projectId,firstTime.getTime(),lastTime.getTime()); return extApiDefinitionMapper.countByProjectIDAndCreateInThisWeek(projectId,firstTime.getTime(),lastTime.getTime());
} }
} }
} }

View File

@ -209,7 +209,7 @@ public class ApiScenarioReportService {
} }
public long countByProjectID(String projectId) { public long countByProjectID(String projectId) {
return apiScenarioReportMapper.countByProjectID(projectId); return extApiScenarioReportMapper.countByProjectID(projectId);
} }
public long countByProjectIDAndCreateInThisWeek(String projectId) { public long countByProjectIDAndCreateInThisWeek(String projectId) {
@ -221,7 +221,7 @@ public class ApiScenarioReportService {
if(firstTime==null || lastTime == null){ if(firstTime==null || lastTime == null){
return 0; return 0;
}else { }else {
return apiScenarioReportMapper.countByProjectIDAndCreateInThisWeek(projectId,firstTime.getTime(),lastTime.getTime()); return extApiScenarioReportMapper.countByProjectIDAndCreateInThisWeek(projectId,firstTime.getTime(),lastTime.getTime());
} }
} }
} }

View File

@ -249,7 +249,7 @@ public class ApiTestCaseService {
} }
public List<ApiDataCountResult> countProtocolByProjectID(String projectId) { public List<ApiDataCountResult> countProtocolByProjectID(String projectId) {
return apiTestCaseMapper.countProtocolByProjectID(projectId); return extApiTestCaseMapper.countProtocolByProjectID(projectId);
} }
public long countByProjectIDAndCreateInThisWeek(String projectId) { public long countByProjectIDAndCreateInThisWeek(String projectId) {
@ -261,7 +261,7 @@ public class ApiTestCaseService {
if(firstTime==null || lastTime == null){ if(firstTime==null || lastTime == null){
return 0; return 0;
}else { }else {
return apiTestCaseMapper.countByProjectIDAndCreateInThisWeek(projectId,firstTime.getTime(),lastTime.getTime()); return extApiTestCaseMapper.countByProjectIDAndCreateInThisWeek(projectId,firstTime.getTime(),lastTime.getTime());
} }
} }

View File

@ -37,41 +37,4 @@ public interface ApiDefinitionExecResultMapper {
int updateByPrimaryKey(ApiDefinitionExecResult record); int updateByPrimaryKey(ApiDefinitionExecResult record);
@Select({
"SELECT count(id) AS countNumber FROM api_definition_exec_result ",
"WHERE resource_id IN ( ",
"SELECT testCase.id FROM api_test_case testCase ",
"WHERE testCase.project_id = #{projectId}) ",
"and start_time BETWEEN #{firstDayTimestamp} AND #{lastDayTimestamp} "
})
long countByProjectIDAndCreateInThisWeek(@Param("projectId") String projectId, @Param("firstDayTimestamp") long firstDayTimestamp, @Param("lastDayTimestamp") long lastDayTimestamp);
@Select({
"SELECT count(id) AS countNumber FROM api_definition_exec_result ",
"WHERE resource_id IN ( ",
"SELECT testCase.id FROM api_test_case testCase ",
"WHERE testCase.project_id = #{projectId}) ",
})
long countByTestCaseIDInProject(String projectId);
// AS testPlan FROM ( SELECT apiCase.id AS testCaseID,apiCase.`name` AS testCaseNa' at line 1
@Select({
"SELECT testCase.testCaseName AS caseName,testCase.testPlanName AS testPlan ,caseErrorCountData.dataCountNumber AS failureTimes FROM ( ",
"SELECT apiCase.id AS testCaseID,apiCase.`name` AS testCaseName,group_concat(testPlan.`name`) AS testPlanName FROM api_test_case apiCase ",
"LEFT JOIN test_plan testPlan ON testPlan.api_ids like concat('%\"',apiCase.id,'\"%') ",
"GROUP BY apiCase.id ",
"ORDER BY apiCase.create_time DESC ",
")testCase ",
"INNER JOIN ( ",
"SELECT resource_id AS testCaseID,COUNT(id) AS dataCountNumber,start_time AS executeTime FROM api_definition_exec_result ",
"WHERE resource_id IN ( ",
"SELECT id FROM api_test_case WHERE project_id = #{projectId} ",
") and `status` = 'error' GROUP BY resource_id ",
") caseErrorCountData ON caseErrorCountData.testCaseID =testCase.testCaseID ",
"WHERE caseErrorCountData.executeTime >= #{startTimestamp} ",
"ORDER BY caseErrorCountData.dataCountNumber DESC ",
"limit #{limitNumber} "
})
List<ExecutedCaseInfoResult> findFaliureCaseInfoByProjectIDAndExecuteTimeAndLimitNumber(@Param("projectId") String projectId, @Param("startTimestamp") long startTimestamp, @Param("limitNumber") int limitNumber);
} }

View File

@ -39,13 +39,4 @@ public interface ApiDefinitionMapper {
int updateByPrimaryKey(ApiDefinition record); int updateByPrimaryKey(ApiDefinition record);
@Select("SELECT protocol AS groupField,count(id) AS countNumber FROM api_definition WHERE project_id = #{0} GROUP BY protocol;")
List<ApiDataCountResult> countProtocolByProjectID(String projectId);
@Select({
"SELECT count(id) AS countNumber FROM api_definition ",
"WHERE project_id = #{projectId} ",
"AND create_time BETWEEN #{firstDayTimestamp} AND #{lastDayTimestamp} "
})
long countByProjectIDAndCreateInThisWeek(@Param("projectId") String projectId, @Param("firstDayTimestamp") long firstDayTimestamp, @Param("lastDayTimestamp") long lastDayTimestamp);
} }

View File

@ -35,13 +35,4 @@ public interface ApiScenarioMapper {
int updateByPrimaryKey(ApiScenario record); int updateByPrimaryKey(ApiScenario record);
@Select("SELECT COUNT(id) AS countNumber FROM api_scenario WHERE project_id = #{0} ")
long countByProjectID(String projectId);
@Select({
"SELECT count(id) AS countNumber FROM api_scenario ",
"WHERE project_id = #{projectId} ",
"AND create_time BETWEEN #{firstDayTimestamp} AND #{lastDayTimestamp} "
})
long countByProjectIDAndCreatInThisWeek(@Param("projectId") String projectId, @Param("firstDayTimestamp") long firstDayTimestamp, @Param("lastDayTimestamp") long lastDayTimestamp);
} }

View File

@ -29,13 +29,4 @@ public interface ApiScenarioReportMapper {
int updateByPrimaryKey(ApiScenarioReport record); int updateByPrimaryKey(ApiScenarioReport record);
@Select("SELECT count(id) AS countNumber FROM api_scenario_report WHERE project_id = #{0} ")
long countByProjectID(String projectId);
@Select({
"SELECT count(id) AS countNumber FROM api_scenario_report ",
"WHERE project_id = #{projectId} ",
"AND create_time BETWEEN #{firstDayTimestamp} AND #{lastDayTimestamp} "
})
long countByProjectIDAndCreateInThisWeek(@Param("projectId") String projectId, @Param("firstDayTimestamp") long firstDayTimestamp, @Param("lastDayTimestamp") long lastDayTimestamp);
} }

View File

@ -38,19 +38,4 @@ public interface ApiTestCaseMapper {
int updateByPrimaryKey(ApiTestCase record); int updateByPrimaryKey(ApiTestCase record);
@Select({
"SELECT apiDef.protocol AS groupField,COUNT(testCase.id) AS countNumber FROM api_test_case testCase ",
"INNER JOIN api_definition apiDef ON testCase.api_definition_id = apiDef.id ",
"WHERE testCase.project_id = #{0} ",
"GROUP BY apiDef.protocol "
})
List<ApiDataCountResult> countProtocolByProjectID(String projectId);
@Select({
"SELECT count(testCase.id) AS countNumber FROM api_test_case testCase ",
"INNER JOIN api_definition apiDef ON testCase.api_definition_id = apiDef.id ",
"WHERE testCase.project_id = #{projectId} ",
"AND testCase.create_time BETWEEN #{firstDayTimestamp} AND #{lastDayTimestamp} "
})
long countByProjectIDAndCreateInThisWeek(@Param("projectId") String projectId, @Param("firstDayTimestamp") long firstDayTimestamp, @Param("lastDayTimestamp") long lastDayTimestamp);
} }

View File

@ -29,20 +29,4 @@ public interface ApiTestReportMapper {
int updateByPrimaryKey(ApiTestReport record); int updateByPrimaryKey(ApiTestReport record);
@Select({
"SELECT COUNT(testReportDetail.report_id) AS countNumber FROM api_test_report_detail testReportDetail ",
"INNER JOIN `schedule` sch ON sch.resource_id = testReportDetail.test_id ",
"INNER JOIN api_test_report testReport ON testReportDetail.report_id = testReport.id ",
"WHERE workspace_id = #{workspaceID} AND `group` = #{group} ",
})
long countByWorkspaceIdAndGroup(@Param("workspaceID") String workspaceID, @Param("group")String group);
@Select({
"SELECT COUNT(testReportDetail.report_id) AS countNumber FROM api_test_report_detail testReportDetail ",
"INNER JOIN `schedule` sch ON sch.resource_id = testReportDetail.test_id ",
"INNER JOIN api_test_report testReport ON testReportDetail.report_id = testReport.id ",
"WHERE workspace_id = #{workspaceID} AND `group` = #{group} ",
"AND testReport.create_time BETWEEN #{startTime} and #{endTime} ",
})
long countByProjectIDAndCreateInThisWeek(@Param("workspaceID") String workspaceID, @Param("group")String group, @Param("startTime") long startTime, @Param("endTime")long endTime);
} }

View File

@ -38,24 +38,4 @@ public interface ScheduleMapper {
int updateByPrimaryKey(Schedule record); int updateByPrimaryKey(Schedule record);
@Select("SELECT COUNT(id) AS countNumber FROM `schedule` WHERE `workspace_id` = #{workspaceId} AND `group` = #{group} ")
long countTaskByWorkspaceIdAndGroup(@Param("workspaceId") String workspaceId,@Param("group") String group);
@Select({
"SELECT COUNT(id) AS countNumber FROM `schedule` ",
"WHERE workspace_id = #{workspaceId} ",
"AND `group` = #{group} ",
"AND create_time BETWEEN #{startTime} and #{endTime}; "
})
long countTaskByWorkspaceIdAndGroupAndCreateTimeRange(@Param("workspaceId")String workspaceId,@Param("group") String group, @Param("startTime") long startTime, @Param("endTime") long endTime);
@Select({
"SELECT apiTest.`name` AS scenario,sch.id AS taskID,sch.`value` AS rule,sch.`enable` AS `taskStatus`,u.`name` AS creator,sch.update_time AS updateTime ",
"FROM api_test apiTest ",
"INNER JOIN `schedule` sch ON apiTest.id = sch.resource_id ",
"INNER JOIN `user` u ON u.id = sch.user_id ",
"WHERE sch.`enable` = true AND sch.workspace_id = #{0,jdbcType=VARCHAR}"
})
List<TaskInfoResult> findRunningTaskInfoByWorkspaceID(String workspaceID);
} }

View File

@ -1,6 +1,11 @@
package io.metersphere.base.mapper.ext; package io.metersphere.base.mapper.ext;
import io.metersphere.api.dto.dataCount.ExecutedCaseInfoResult;
import io.metersphere.base.domain.ApiDefinitionExecResult; import io.metersphere.base.domain.ApiDefinitionExecResult;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import java.util.List;
public interface ExtApiDefinitionExecResultMapper { public interface ExtApiDefinitionExecResultMapper {
@ -8,4 +13,40 @@ public interface ExtApiDefinitionExecResultMapper {
ApiDefinitionExecResult selectMaxResultByResourceId(String resourceId); ApiDefinitionExecResult selectMaxResultByResourceId(String resourceId);
@Select({
"SELECT count(id) AS countNumber FROM api_definition_exec_result ",
"WHERE resource_id IN ( ",
"SELECT testCase.id FROM api_test_case testCase ",
"WHERE testCase.project_id = #{projectId}) ",
"and start_time BETWEEN #{firstDayTimestamp} AND #{lastDayTimestamp} "
})
long countByProjectIDAndCreateInThisWeek(@Param("projectId") String projectId, @Param("firstDayTimestamp") long firstDayTimestamp, @Param("lastDayTimestamp") long lastDayTimestamp);
@Select({
"SELECT count(id) AS countNumber FROM api_definition_exec_result ",
"WHERE resource_id IN ( ",
"SELECT testCase.id FROM api_test_case testCase ",
"WHERE testCase.project_id = #{projectId}) ",
})
long countByTestCaseIDInProject(String projectId);
@Select({
"SELECT testCase.testCaseName AS caseName,testCase.testPlanName AS testPlan ,caseErrorCountData.dataCountNumber AS failureTimes FROM ( ",
"SELECT apiCase.id AS testCaseID,apiCase.`name` AS testCaseName,group_concat(testPlan.`name`) AS testPlanName FROM api_test_case apiCase ",
"LEFT JOIN test_plan testPlan ON testPlan.api_ids like concat('%\"',apiCase.id,'\"%') ",
"GROUP BY apiCase.id ",
"ORDER BY apiCase.create_time DESC ",
")testCase ",
"INNER JOIN ( ",
"SELECT resource_id AS testCaseID,COUNT(id) AS dataCountNumber,start_time AS executeTime FROM api_definition_exec_result ",
"WHERE resource_id IN ( ",
"SELECT id FROM api_test_case WHERE project_id = #{projectId} ",
") and `status` = 'error' GROUP BY resource_id ",
") caseErrorCountData ON caseErrorCountData.testCaseID =testCase.testCaseID ",
"WHERE caseErrorCountData.executeTime >= #{startTimestamp} ",
"ORDER BY caseErrorCountData.dataCountNumber DESC ",
"limit #{limitNumber} "
})
List<ExecutedCaseInfoResult> findFaliureCaseInfoByProjectIDAndExecuteTimeAndLimitNumber(@Param("projectId") String projectId, @Param("startTimestamp") long startTimestamp, @Param("limitNumber") int limitNumber);
} }

View File

@ -1,9 +1,11 @@
package io.metersphere.base.mapper.ext; package io.metersphere.base.mapper.ext;
import io.metersphere.api.dto.dataCount.ApiDataCountResult;
import io.metersphere.api.dto.definition.ApiComputeResult; import io.metersphere.api.dto.definition.ApiComputeResult;
import io.metersphere.api.dto.definition.ApiDefinitionRequest; import io.metersphere.api.dto.definition.ApiDefinitionRequest;
import io.metersphere.api.dto.definition.ApiDefinitionResult; import io.metersphere.api.dto.definition.ApiDefinitionResult;
import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import java.util.List; import java.util.List;
@ -17,4 +19,13 @@ public interface ExtApiDefinitionMapper {
int reduction(@Param("ids") List<String> ids); int reduction(@Param("ids") List<String> ids);
@Select("SELECT protocol AS groupField,count(id) AS countNumber FROM api_definition WHERE project_id = #{0} GROUP BY protocol;")
List<ApiDataCountResult> countProtocolByProjectID(String projectId);
@Select({
"SELECT count(id) AS countNumber FROM api_definition ",
"WHERE project_id = #{projectId} ",
"AND create_time BETWEEN #{firstDayTimestamp} AND #{lastDayTimestamp} "
})
long countByProjectIDAndCreateInThisWeek(@Param("projectId") String projectId, @Param("firstDayTimestamp") long firstDayTimestamp, @Param("lastDayTimestamp") long lastDayTimestamp);
} }

View File

@ -4,6 +4,7 @@ import io.metersphere.api.dto.automation.ApiScenarioDTO;
import io.metersphere.api.dto.automation.ApiScenarioRequest; import io.metersphere.api.dto.automation.ApiScenarioRequest;
import io.metersphere.base.domain.ApiScenario; import io.metersphere.base.domain.ApiScenario;
import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import java.util.List; import java.util.List;
@ -19,4 +20,14 @@ public interface ExtApiScenarioMapper {
int removeToGc(@Param("ids") List<String> ids); int removeToGc(@Param("ids") List<String> ids);
int reduction(@Param("ids") List<String> ids); int reduction(@Param("ids") List<String> ids);
@Select("SELECT COUNT(id) AS countNumber FROM api_scenario WHERE project_id = #{0} ")
long countByProjectID(String projectId);
@Select({
"SELECT count(id) AS countNumber FROM api_scenario ",
"WHERE project_id = #{projectId} ",
"AND create_time BETWEEN #{firstDayTimestamp} AND #{lastDayTimestamp} "
})
long countByProjectIDAndCreatInThisWeek(@Param("projectId") String projectId, @Param("firstDayTimestamp") long firstDayTimestamp, @Param("lastDayTimestamp") long lastDayTimestamp);
} }

View File

@ -4,6 +4,7 @@ import io.metersphere.api.dto.APIReportResult;
import io.metersphere.api.dto.QueryAPIReportRequest; import io.metersphere.api.dto.QueryAPIReportRequest;
import io.metersphere.api.dto.automation.APIScenarioReportResult; import io.metersphere.api.dto.automation.APIScenarioReportResult;
import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import java.util.List; import java.util.List;
@ -12,4 +13,14 @@ public interface ExtApiScenarioReportMapper {
APIReportResult get(@Param("reportId") String reportId); APIReportResult get(@Param("reportId") String reportId);
@Select("SELECT count(id) AS countNumber FROM api_scenario_report WHERE project_id = #{0} ")
long countByProjectID(String projectId);
@Select({
"SELECT count(id) AS countNumber FROM api_scenario_report ",
"WHERE project_id = #{projectId} ",
"AND create_time BETWEEN #{firstDayTimestamp} AND #{lastDayTimestamp} "
})
long countByProjectIDAndCreateInThisWeek(@Param("projectId") String projectId, @Param("firstDayTimestamp") long firstDayTimestamp, @Param("lastDayTimestamp") long lastDayTimestamp);
} }

View File

@ -1,10 +1,12 @@
package io.metersphere.base.mapper.ext; package io.metersphere.base.mapper.ext;
import io.metersphere.api.dto.dataCount.ApiDataCountResult;
import io.metersphere.api.dto.definition.ApiTestCaseDTO; import io.metersphere.api.dto.definition.ApiTestCaseDTO;
import io.metersphere.api.dto.definition.ApiTestCaseRequest; import io.metersphere.api.dto.definition.ApiTestCaseRequest;
import io.metersphere.api.dto.definition.ApiTestCaseResult; import io.metersphere.api.dto.definition.ApiTestCaseResult;
import io.metersphere.base.domain.ApiTestCase; import io.metersphere.base.domain.ApiTestCase;
import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import java.util.List; import java.util.List;
@ -12,4 +14,20 @@ public interface ExtApiTestCaseMapper {
List<ApiTestCaseResult> list(@Param("request") ApiTestCaseRequest request); List<ApiTestCaseResult> list(@Param("request") ApiTestCaseRequest request);
List<ApiTestCaseDTO> listSimple(@Param("request") ApiTestCaseRequest request); List<ApiTestCaseDTO> listSimple(@Param("request") ApiTestCaseRequest request);
@Select({
"SELECT apiDef.protocol AS groupField,COUNT(testCase.id) AS countNumber FROM api_test_case testCase ",
"INNER JOIN api_definition apiDef ON testCase.api_definition_id = apiDef.id ",
"WHERE testCase.project_id = #{0} ",
"GROUP BY apiDef.protocol "
})
List<ApiDataCountResult> countProtocolByProjectID(String projectId);
@Select({
"SELECT count(testCase.id) AS countNumber FROM api_test_case testCase ",
"INNER JOIN api_definition apiDef ON testCase.api_definition_id = apiDef.id ",
"WHERE testCase.project_id = #{projectId} ",
"AND testCase.create_time BETWEEN #{firstDayTimestamp} AND #{lastDayTimestamp} "
})
long countByProjectIDAndCreateInThisWeek(@Param("projectId") String projectId, @Param("firstDayTimestamp") long firstDayTimestamp, @Param("lastDayTimestamp") long lastDayTimestamp);
} }

View File

@ -5,6 +5,7 @@ import io.metersphere.api.dto.QueryAPIReportRequest;
import io.metersphere.dto.ApiReportDTO; import io.metersphere.dto.ApiReportDTO;
import io.metersphere.dto.DashboardTestDTO; import io.metersphere.dto.DashboardTestDTO;
import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import java.util.List; import java.util.List;
@ -18,4 +19,21 @@ public interface ExtApiTestReportMapper {
List<DashboardTestDTO> selectDashboardTests(@Param("workspaceId") String workspaceId, @Param("startTimestamp") long startTimestamp); List<DashboardTestDTO> selectDashboardTests(@Param("workspaceId") String workspaceId, @Param("startTimestamp") long startTimestamp);
@Select({
"SELECT COUNT(testReportDetail.report_id) AS countNumber FROM api_test_report_detail testReportDetail ",
"INNER JOIN `schedule` sch ON sch.resource_id = testReportDetail.test_id ",
"INNER JOIN api_test_report testReport ON testReportDetail.report_id = testReport.id ",
"WHERE workspace_id = #{workspaceID} AND `group` = #{group} ",
})
long countByWorkspaceIdAndGroup(@Param("workspaceID") String workspaceID, @Param("group")String group);
@Select({
"SELECT COUNT(testReportDetail.report_id) AS countNumber FROM api_test_report_detail testReportDetail ",
"INNER JOIN `schedule` sch ON sch.resource_id = testReportDetail.test_id ",
"INNER JOIN api_test_report testReport ON testReportDetail.report_id = testReport.id ",
"WHERE workspace_id = #{workspaceID} AND `group` = #{group} ",
"AND testReport.create_time BETWEEN #{startTime} and #{endTime} ",
})
long countByProjectIDAndCreateInThisWeek(@Param("workspaceID") String workspaceID, @Param("group")String group, @Param("startTime") long startTime, @Param("endTime")long endTime);
} }

View File

@ -1,11 +1,34 @@
package io.metersphere.base.mapper.ext; package io.metersphere.base.mapper.ext;
import io.metersphere.api.dto.dataCount.response.TaskInfoResult;
import io.metersphere.controller.request.QueryScheduleRequest; import io.metersphere.controller.request.QueryScheduleRequest;
import io.metersphere.dto.ScheduleDao; import io.metersphere.dto.ScheduleDao;
import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import java.util.List; import java.util.List;
public interface ExtScheduleMapper { public interface ExtScheduleMapper {
List<ScheduleDao> list(@Param("request") QueryScheduleRequest request); List<ScheduleDao> list(@Param("request") QueryScheduleRequest request);
@Select("SELECT COUNT(id) AS countNumber FROM `schedule` WHERE `workspace_id` = #{workspaceId} AND `group` = #{group} ")
long countTaskByWorkspaceIdAndGroup(@Param("workspaceId") String workspaceId,@Param("group") String group);
@Select({
"SELECT COUNT(id) AS countNumber FROM `schedule` ",
"WHERE workspace_id = #{workspaceId} ",
"AND `group` = #{group} ",
"AND create_time BETWEEN #{startTime} and #{endTime}; "
})
long countTaskByWorkspaceIdAndGroupAndCreateTimeRange(@Param("workspaceId")String workspaceId,@Param("group") String group, @Param("startTime") long startTime, @Param("endTime") long endTime);
@Select({
"SELECT apiTest.`name` AS scenario,sch.id AS taskID,sch.`value` AS rule,sch.`enable` AS `taskStatus`,u.`name` AS creator,sch.update_time AS updateTime ",
"FROM api_test apiTest ",
"INNER JOIN `schedule` sch ON apiTest.id = sch.resource_id ",
"INNER JOIN `user` u ON u.id = sch.user_id ",
"WHERE sch.`enable` = true AND sch.workspace_id = #{0,jdbcType=VARCHAR}"
})
List<TaskInfoResult> findRunningTaskInfoByWorkspaceID(String workspaceID);
} }

View File

@ -167,7 +167,7 @@ public class ScheduleService {
} }
public long countTaskByWorkspaceIdAndGroup(String workspaceId,String group) { public long countTaskByWorkspaceIdAndGroup(String workspaceId,String group) {
return scheduleMapper.countTaskByWorkspaceIdAndGroup(workspaceId,group); return extScheduleMapper.countTaskByWorkspaceIdAndGroup(workspaceId,group);
} }
public long countTaskByWorkspaceIdAndGroupInThisWeek(String workspaceID, String group) { public long countTaskByWorkspaceIdAndGroupInThisWeek(String workspaceID, String group) {
@ -179,12 +179,12 @@ public class ScheduleService {
if(firstTime==null || lastTime == null){ if(firstTime==null || lastTime == null){
return 0; return 0;
}else { }else {
return scheduleMapper.countTaskByWorkspaceIdAndGroupAndCreateTimeRange(workspaceID,group,firstTime.getTime(),lastTime.getTime()); return extScheduleMapper.countTaskByWorkspaceIdAndGroupAndCreateTimeRange(workspaceID,group,firstTime.getTime(),lastTime.getTime());
} }
} }
public List<TaskInfoResult> findRunningTaskInfoByWorkspaceID(String workspaceID) { public List<TaskInfoResult> findRunningTaskInfoByWorkspaceID(String workspaceID) {
List<TaskInfoResult> runningTaskInfoList = scheduleMapper.findRunningTaskInfoByWorkspaceID(workspaceID); List<TaskInfoResult> runningTaskInfoList = extScheduleMapper.findRunningTaskInfoByWorkspaceID(workspaceID);
return runningTaskInfoList; return runningTaskInfoList;
} }
} }