This commit is contained in:
chenjianxing 2021-02-02 19:23:16 +08:00
commit 08cab71e00
4 changed files with 44 additions and 0 deletions

View File

@ -459,6 +459,8 @@ public class ApiAutomationService {
ids = this.getAllScenarioIdsByFontedSelect( ids = this.getAllScenarioIdsByFontedSelect(
request.getModuleIds(), request.getName(), request.getProjectId(), request.getFilters(), request.getUnSelectIds()); request.getModuleIds(), request.getName(), request.getProjectId(), request.getFilters(), request.getUnSelectIds());
} }
//检查是否有正在执行中的情景
this.checkScenarioIsRunnng(ids);
List<ApiScenarioWithBLOBs> apiScenarios = extApiScenarioMapper.selectIds(ids); List<ApiScenarioWithBLOBs> apiScenarios = extApiScenarioMapper.selectIds(ids);
String runMode = ApiRunMode.SCENARIO.name(); String runMode = ApiRunMode.SCENARIO.name();
@ -475,6 +477,15 @@ public class ApiAutomationService {
return request.getId(); return request.getId();
} }
public void checkScenarioIsRunnng(List<String> ids) {
List<ApiScenarioReport> lastReportStatusByIds = apiReportService.selectLastReportByIds(ids);
for (ApiScenarioReport report : lastReportStatusByIds) {
if(StringUtils.equals(report.getStatus(),APITestStatus.Running.name())){
MSException.throwException(report.getName()+" Is Running!");
}
}
}
/** /**
* 获取前台查询条件查询的所有(未经分页筛选)数据ID * 获取前台查询条件查询的所有(未经分页筛选)数据ID
* *

View File

@ -415,4 +415,12 @@ public class ApiScenarioReportService {
public List<ApiDataCountResult> countByProjectIdGroupByExecuteResult(String projectId) { public List<ApiDataCountResult> countByProjectIdGroupByExecuteResult(String projectId) {
return extApiScenarioReportMapper.countByProjectIdGroupByExecuteResult(projectId); return extApiScenarioReportMapper.countByProjectIdGroupByExecuteResult(projectId);
} }
public List<ApiScenarioReport> selectLastReportByIds(List<String> ids) {
if(!ids.isEmpty()){
return extApiScenarioReportMapper.selectLastReportByIds(ids);
}else {
return new ArrayList<>(0);
}
}
} }

View File

@ -3,6 +3,7 @@ package io.metersphere.base.mapper.ext;
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 io.metersphere.api.dto.datacount.ApiDataCountResult; import io.metersphere.api.dto.datacount.ApiDataCountResult;
import io.metersphere.base.domain.ApiScenarioReport;
import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select; import org.apache.ibatis.annotations.Select;
@ -20,4 +21,6 @@ public interface ExtApiScenarioReportMapper {
long countByProjectIdAndCreateAndByScheduleInThisWeek(@Param("projectId") String projectId, @Param("firstDayTimestamp") long firstDayTimestamp, @Param("lastDayTimestamp") long lastDayTimestamp); long countByProjectIdAndCreateAndByScheduleInThisWeek(@Param("projectId") String projectId, @Param("firstDayTimestamp") long firstDayTimestamp, @Param("lastDayTimestamp") long lastDayTimestamp);
List<ApiDataCountResult> countByProjectIdGroupByExecuteResult(String projectId); List<ApiDataCountResult> countByProjectIdGroupByExecuteResult(String projectId);
List<ApiScenarioReport> selectLastReportByIds(@Param("scenarioIdList") List<String> ids);
} }

View File

@ -194,4 +194,26 @@
WHERE acr.project_id = #{projectId} AND ar.trigger_mode = 'SCHEDULE' WHERE acr.project_id = #{projectId} AND ar.trigger_mode = 'SCHEDULE'
GROUP BY groupField; GROUP BY groupField;
</select> </select>
<select id="selectLastReportByIds" resultType="io.metersphere.base.domain.ApiScenarioReport">
SELECT report.* FROM api_scenario_report report
INNER JOIN (
SELECT a.id,a.createTime,a.scenario_id FROM
(
SELECT id AS id,create_time AS createTime, scenario_id AS scenario_id FROM api_scenario_report
WHERE scenario_id in
<foreach collection="scenarioIdList" item="value" separator="," open="(" close=")">
#{value}
</foreach>
UNION
SELECT report.id AS id,report.create_time AS createTime,planScenario.api_scenario_id AS scenario_id FROM api_scenario_report report
INNER JOIN test_plan_api_scenario planScenario ON report.scenario_id = planScenario.id
WHERE planScenario.api_scenario_id in
<foreach collection="scenarioIdList" item="value" separator="," open="(" close=")">
#{value}
</foreach>
ORDER BY createTime DESC
) a GROUP BY a.scenario_id
) orderData ON orderData.id = report.id;
</select>
</mapper> </mapper>