fix(接口测试首页): 修复删除场景报告,影响到首页历史总执行次数的缺陷 #1005966
【【接口测试】删除场景报告,影响到首页历史总执行次数】https://www.tapd.cn/55049933/bugtrace/bugs/view?bug_id=1155049933001005966
This commit is contained in:
parent
26a3010b3e
commit
5782702372
|
@ -252,7 +252,7 @@ public class APITestController {
|
|||
apiCountResult.setThisWeekAddedCount(dateCountByCreateInThisWeek);
|
||||
long executedInThisWeekCountNumber = apiScenarioReportService.countByProjectIdAndCreateInThisWeek(projectId);
|
||||
apiCountResult.setThisWeekExecutedCount(executedInThisWeekCountNumber);
|
||||
long executedCountNumber = apiScenarioReportService.countByProjectID(projectId);
|
||||
long executedCountNumber = apiAutomationService.countExecuteTimesByProjectID(projectId);
|
||||
apiCountResult.setExecutedCount(executedCountNumber);
|
||||
|
||||
//未执行、未通过、已通过
|
||||
|
|
|
@ -33,6 +33,7 @@ import io.metersphere.commons.constants.*;
|
|||
import io.metersphere.commons.exception.MSException;
|
||||
import io.metersphere.commons.utils.*;
|
||||
import io.metersphere.controller.request.ScheduleRequest;
|
||||
import io.metersphere.dto.ApiReportCountDTO;
|
||||
import io.metersphere.dto.BaseSystemConfigDTO;
|
||||
import io.metersphere.i18n.Translator;
|
||||
import io.metersphere.job.sechedule.ApiScenarioTestJob;
|
||||
|
@ -2472,4 +2473,30 @@ public class ApiAutomationService {
|
|||
}
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
public void initExecuteTimes() {
|
||||
List<String> apiScenarioIds = extApiScenarioMapper.selectIdsByExecuteTimeIsNull();
|
||||
Map<String,Long> scenarioIdMap = new HashMap<>();
|
||||
List<ApiReportCountDTO> reportCount = apiScenarioReportService.countByApiScenarioId();
|
||||
for (ApiReportCountDTO dto : reportCount) {
|
||||
scenarioIdMap.put(dto.getId(),dto.getCountNum());
|
||||
}
|
||||
for (String id:apiScenarioIds) {
|
||||
int count = 0;
|
||||
if(scenarioIdMap.containsKey(id)){
|
||||
Long countNum = scenarioIdMap.get(id);
|
||||
if(countNum != null){
|
||||
count = countNum.intValue();
|
||||
}
|
||||
}
|
||||
ApiScenarioWithBLOBs apiScenario = new ApiScenarioWithBLOBs();
|
||||
apiScenario.setId(id);
|
||||
apiScenario.setExecuteTimes(count);
|
||||
apiScenarioMapper.updateByPrimaryKeySelective(apiScenario);
|
||||
}
|
||||
}
|
||||
|
||||
public long countExecuteTimesByProjectID(String projectId) {
|
||||
return extApiScenarioMapper.countExeciteTimesByProjectID(projectId);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -168,7 +168,7 @@ public class ApiDefinitionExecResultService {
|
|||
* @param result
|
||||
* @param type
|
||||
*/
|
||||
public void saveApiResultByScheduleTask(TestResult result, String testPlanReportId, String type, String trigeMode) {
|
||||
public void saveApiResultByScheduleTask(TestResult result, String testPlanReportId, String type) {
|
||||
testPlanLog.info("TestPlanReportId[" + testPlanReportId + "] APICASE OVER.");
|
||||
String saveResultType = type;
|
||||
if (StringUtils.equalsAny(saveResultType, ApiRunMode.SCHEDULE_API_PLAN.name(), ApiRunMode.JENKINS_API_PLAN.name())) {
|
||||
|
|
|
@ -29,6 +29,7 @@ import io.metersphere.commons.constants.TestPlanApiExecuteStatus;
|
|||
import io.metersphere.commons.constants.TriggerMode;
|
||||
import io.metersphere.commons.exception.MSException;
|
||||
import io.metersphere.commons.utils.*;
|
||||
import io.metersphere.dto.ApiReportCountDTO;
|
||||
import io.metersphere.i18n.Translator;
|
||||
import io.metersphere.log.utils.ReflexObjectUtil;
|
||||
import io.metersphere.log.vo.DetailColumn;
|
||||
|
@ -246,6 +247,25 @@ public class ApiScenarioReportService {
|
|||
testPlanApiScenario.setUpdateTime(report.getCreateTime());
|
||||
report.setTestPlanScenarioId(testPlanApiScenario.getId());
|
||||
testPlanApiScenarioMapper.updateByPrimaryKeySelective(testPlanApiScenario);
|
||||
|
||||
// 更新场景状态
|
||||
ApiScenario scenario = apiScenarioMapper.selectByPrimaryKey(testPlanApiScenario.getApiScenarioId());
|
||||
if (scenario != null) {
|
||||
if (scenarioResult.getError() > 0) {
|
||||
scenario.setLastResult("Fail");
|
||||
} else {
|
||||
scenario.setLastResult("Success");
|
||||
}
|
||||
scenario.setPassRate(passRate);
|
||||
scenario.setReportId(report.getId());
|
||||
int executeTimes = 0;
|
||||
if(scenario.getExecuteTimes() != null){
|
||||
executeTimes = scenario.getExecuteTimes().intValue();
|
||||
}
|
||||
scenario.setExecuteTimes(executeTimes+1);
|
||||
|
||||
apiScenarioMapper.updateByPrimaryKey(scenario);
|
||||
}
|
||||
}
|
||||
returnReport = report;
|
||||
reportIds.add(report.getId());
|
||||
|
@ -301,6 +321,7 @@ public class ApiScenarioReportService {
|
|||
report.setTestPlanScenarioId(planScenarioId);
|
||||
apiScenarioReportMapper.updateByPrimaryKeySelective(report);
|
||||
|
||||
|
||||
if (scenarioResult.getError() > 0) {
|
||||
scenarioAndErrorMap.put(testPlanApiScenario.getApiScenarioId(), TestPlanApiExecuteStatus.FAILD.name());
|
||||
testPlanApiScenario.setLastResult(ScenarioStatus.Fail.name());
|
||||
|
@ -327,6 +348,25 @@ public class ApiScenarioReportService {
|
|||
scenarioIdList.add(testPlanApiScenario.getApiScenarioId());
|
||||
scenarioNames.append(report.getName()).append(",");
|
||||
|
||||
// 更新场景状态
|
||||
ApiScenario scenario = apiScenarioMapper.selectByPrimaryKey(testPlanApiScenario.getApiScenarioId());
|
||||
if (scenario != null) {
|
||||
if (scenarioResult.getError() > 0) {
|
||||
scenario.setLastResult("Fail");
|
||||
} else {
|
||||
scenario.setLastResult("Success");
|
||||
}
|
||||
scenario.setPassRate(passRate);
|
||||
scenario.setReportId(report.getId());
|
||||
int executeTimes = 0;
|
||||
if(scenario.getExecuteTimes() != null){
|
||||
executeTimes = scenario.getExecuteTimes().intValue();
|
||||
}
|
||||
scenario.setExecuteTimes(executeTimes+1);
|
||||
|
||||
apiScenarioMapper.updateByPrimaryKey(scenario);
|
||||
}
|
||||
|
||||
lastReport = report;
|
||||
reportIds.add(report.getId());
|
||||
}
|
||||
|
@ -516,6 +556,12 @@ public class ApiScenarioReportService {
|
|||
String passRate = new DecimalFormat("0%").format((float) item.getSuccess() / (item.getSuccess() + item.getError()));
|
||||
scenario.setPassRate(passRate);
|
||||
scenario.setReportId(report.getId());
|
||||
int executeTimes = 0;
|
||||
if(scenario.getExecuteTimes() != null){
|
||||
executeTimes = scenario.getExecuteTimes().intValue();
|
||||
}
|
||||
scenario.setExecuteTimes(executeTimes+1);
|
||||
|
||||
apiScenarioMapper.updateByPrimaryKey(scenario);
|
||||
}
|
||||
lastReport = report;
|
||||
|
@ -709,4 +755,8 @@ public class ApiScenarioReportService {
|
|||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public List<ApiReportCountDTO> countByApiScenarioId() {
|
||||
return extApiScenarioReportMapper.countByApiScenarioId();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -90,10 +90,8 @@ public class TestResultService {
|
|||
//测试计划用例,定时,jenkins
|
||||
} else if (StringUtils.equalsAny(runMode, ApiRunMode.API_PLAN.name(), ApiRunMode.SCHEDULE_API_PLAN.name(), ApiRunMode.JENKINS_API_PLAN.name())) {
|
||||
//测试计划定时任务-接口执行逻辑的话,需要同步测试计划的报告数据
|
||||
if (StringUtils.equals(runMode, ApiRunMode.SCHEDULE_API_PLAN.name())) {
|
||||
apiDefinitionExecResultService.saveApiResultByScheduleTask(testResult, debugReportId, ApiRunMode.SCHEDULE_API_PLAN.name(), ReportTriggerMode.SCHEDULE.name());
|
||||
} else if (StringUtils.equals(runMode, ApiRunMode.JENKINS_API_PLAN.name())) {
|
||||
apiDefinitionExecResultService.saveApiResultByScheduleTask(testResult, debugReportId, ApiRunMode.JENKINS_API_PLAN.name(), ReportTriggerMode.API.name());
|
||||
if (StringUtils.equalsAny(runMode, ApiRunMode.SCHEDULE_API_PLAN.name(), ApiRunMode.JENKINS_API_PLAN.name())) {
|
||||
apiDefinitionExecResultService.saveApiResultByScheduleTask(testResult, debugReportId, runMode);
|
||||
} else {
|
||||
apiDefinitionExecResultService.saveApiResult(testResult, ApiRunMode.API_PLAN.name(), TriggerMode.MANUAL.name());
|
||||
}
|
||||
|
|
|
@ -68,4 +68,8 @@ public interface ExtApiScenarioMapper {
|
|||
List<ApiScenarioWithBLOBs> selectByNoReferenceId();
|
||||
|
||||
void checkOriginalStatusByIds(@Param("ids")List<String> ids);
|
||||
|
||||
List<String> selectIdsByExecuteTimeIsNull();
|
||||
|
||||
long countExeciteTimesByProjectID(String projectId);
|
||||
}
|
||||
|
|
|
@ -442,6 +442,12 @@
|
|||
WHERE id = #{0}
|
||||
</select>
|
||||
|
||||
<select id="selectIdsByExecuteTimeIsNull" resultType="java.lang.String">
|
||||
select id
|
||||
from api_scenario
|
||||
WHERE execute_times is null OR execute_times = 0
|
||||
</select>
|
||||
|
||||
<select id="selectNameByIdIn" resultType="java.lang.String">
|
||||
select name
|
||||
from api_scenario
|
||||
|
@ -450,6 +456,12 @@
|
|||
#{v}
|
||||
</foreach>
|
||||
</select>
|
||||
|
||||
<select id="countExeciteTimesByProjectID" resultType="java.lang.Long">
|
||||
SELECT SUM(execute_times) FROM api_scenario
|
||||
WHERE project_id = #{0}
|
||||
</select>
|
||||
|
||||
<sql id="queryWhereConditionReview">
|
||||
<where>
|
||||
<if test="request.combine != null">
|
||||
|
|
|
@ -4,6 +4,7 @@ import io.metersphere.api.dto.QueryAPIReportRequest;
|
|||
import io.metersphere.api.dto.automation.APIScenarioReportResult;
|
||||
import io.metersphere.api.dto.datacount.ApiDataCountResult;
|
||||
import io.metersphere.base.domain.ApiScenarioReport;
|
||||
import io.metersphere.dto.ApiReportCountDTO;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
@ -26,4 +27,6 @@ public interface ExtApiScenarioReportMapper {
|
|||
ApiScenarioReport selectPreviousReportByScenarioId(@Param("scenarioId") String scenarioId, @Param("nowId") String nowId);
|
||||
|
||||
List<String> idList(@Param("request") QueryAPIReportRequest request);
|
||||
|
||||
List<ApiReportCountDTO> countByApiScenarioId();
|
||||
}
|
|
@ -279,4 +279,10 @@
|
|||
WHERE execute_type in ("Completed","Debug") and scenario_id=#{scenarioId} and id != #{nowId} ORDER BY create_time desc LIMIT 5,1
|
||||
</select>
|
||||
|
||||
<select id="countByApiScenarioId" resultType="io.metersphere.dto.ApiReportCountDTO">
|
||||
SELECT scenario_id AS id,count(id) AS countNum
|
||||
FROM api_scenario_report
|
||||
WHERE scenario_id is not null GROUP BY scenario_id;
|
||||
</select>
|
||||
|
||||
</mapper>
|
|
@ -0,0 +1,12 @@
|
|||
package io.metersphere.dto;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
public class ApiReportCountDTO {
|
||||
|
||||
private String id;
|
||||
private long countNum;
|
||||
}
|
|
@ -56,10 +56,17 @@ public class AppStartListener implements ApplicationListener<ApplicationReadyEve
|
|||
|
||||
initPythonEnv();
|
||||
|
||||
projectService.initMockTcpService();
|
||||
try {
|
||||
//检查状态为开启的TCP-Mock服务端口
|
||||
projectService.initMockTcpService();
|
||||
}catch (Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
|
||||
initOperate(apiAutomationService::checkApiScenarioUseUrl, "init.scenario.url");
|
||||
initOperate(apiAutomationService::checkApiScenarioReferenceId, "init.scenario.referenceId");
|
||||
initOperate(apiAutomationService::initExecuteTimes, "init.scenario.executeTimes");
|
||||
initOperate(issuesService::syncThirdPartyIssues, "init.issue");
|
||||
initOperate(issuesService::issuesCount, "init.issueCount");
|
||||
initOperate(performanceTestService::initScenarioLoadTest, "init.scenario.load.test");
|
||||
|
|
Loading…
Reference in New Issue