fix(接口测试): 修复误报状态的时候执行率错误的缺陷

--bug=1039427 --user=王孝刚 【项目任务中心】实时任务-查看用例/场景独立报告任务-请求分析-误报通过率计算错误
https://www.tapd.cn/55049933/s/1497756
This commit is contained in:
wxg0103 2024-04-15 21:05:17 +08:00 committed by Craftsman
parent a6e01dd075
commit 794008a6a3
4 changed files with 39 additions and 11 deletions

View File

@ -33,7 +33,7 @@ public class ProcessResultDTO {
private String lastScriptIdentifier; private String lastScriptIdentifier;
public void computerTotal() { public void computerTotal() {
this.total = this.pendingCount + this.errorCount + this.successCount; this.total = this.pendingCount + this.errorCount + this.successCount + this.fakeErrorCount;
} }
public void computerFakeError(long fakeErrorCount) { public void computerFakeError(long fakeErrorCount) {

View File

@ -207,7 +207,6 @@ public class ApiScenarioController {
@RequiresPermissions(PermissionConstants.PROJECT_API_SCENARIO_EXECUTE) @RequiresPermissions(PermissionConstants.PROJECT_API_SCENARIO_EXECUTE)
@Log(type = OperationLogType.UPDATE, expression = "#msClass.scheduleLog(#request.getScenarioId())", msClass = ApiScenarioLogService.class) @Log(type = OperationLogType.UPDATE, expression = "#msClass.scheduleLog(#request.getScenarioId())", msClass = ApiScenarioLogService.class)
@CheckOwner(resourceId = "#request.getScenarioId()", resourceType = "api_scenario") @CheckOwner(resourceId = "#request.getScenarioId()", resourceType = "api_scenario")
@SendNotice(taskType = NoticeConstants.TaskType.SCHEDULE_TASK, event = NoticeConstants.Event.UPDATE, target = "#targetClass.getScheduleNotice(#request)", targetClass = ApiScenarioNoticeService.class)
public String scheduleConfig(@Validated @RequestBody ApiScenarioScheduleConfigRequest request) { public String scheduleConfig(@Validated @RequestBody ApiScenarioScheduleConfigRequest request) {
apiValidateService.validateApiMenuInProject(request.getScenarioId(), ApiResource.API_SCENARIO.name()); apiValidateService.validateApiMenuInProject(request.getScenarioId(), ApiResource.API_SCENARIO.name());
return apiScenarioService.scheduleConfig(request, SessionUtils.getUserId()); return apiScenarioService.scheduleConfig(request, SessionUtils.getUserId());

View File

@ -2,7 +2,9 @@ package io.metersphere.api.service.scenario;
import io.metersphere.api.domain.ApiScenario; import io.metersphere.api.domain.ApiScenario;
import io.metersphere.api.domain.ApiScenarioExample; import io.metersphere.api.domain.ApiScenarioExample;
import io.metersphere.api.dto.scenario.*; import io.metersphere.api.dto.scenario.ApiScenarioAddRequest;
import io.metersphere.api.dto.scenario.ApiScenarioScheduleConfigRequest;
import io.metersphere.api.dto.scenario.ApiScenarioUpdateRequest;
import io.metersphere.api.job.ApiScenarioScheduleJob; import io.metersphere.api.job.ApiScenarioScheduleJob;
import io.metersphere.api.mapper.ApiScenarioMapper; import io.metersphere.api.mapper.ApiScenarioMapper;
import io.metersphere.sdk.util.BeanUtils; import io.metersphere.sdk.util.BeanUtils;
@ -11,35 +13,59 @@ import io.metersphere.system.domain.Schedule;
import io.metersphere.system.domain.ScheduleExample; import io.metersphere.system.domain.ScheduleExample;
import io.metersphere.system.dto.sdk.ApiScenarioMessageDTO; import io.metersphere.system.dto.sdk.ApiScenarioMessageDTO;
import io.metersphere.system.mapper.ScheduleMapper; import io.metersphere.system.mapper.ScheduleMapper;
import io.metersphere.system.notice.NoticeModel;
import io.metersphere.system.notice.constants.NoticeConstants;
import io.metersphere.system.notice.utils.MessageTemplateUtils;
import io.metersphere.system.service.NoticeSendService;
import jakarta.annotation.Resource; import jakarta.annotation.Resource;
import org.apache.commons.beanutils.BeanMap;
import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.BooleanUtils;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map;
@Service @Service
public class ApiScenarioNoticeService { public class ApiScenarioNoticeService {
@Resource
private ApiScenarioService apiScenarioService;
@Resource @Resource
private ApiScenarioMapper apiScenarioMapper; private ApiScenarioMapper apiScenarioMapper;
@Resource @Resource
private ScheduleMapper scheduleMapper; private ScheduleMapper scheduleMapper;
@Resource
private NoticeSendService noticeSendService;
public Schedule getScheduleNotice(ApiScenarioScheduleConfigRequest request) { public void sendScheduleNotice(ApiScenarioScheduleConfigRequest request, String userId) {
ScheduleExample example = new ScheduleExample(); ScheduleExample example = new ScheduleExample();
example.createCriteria().andResourceIdEqualTo(request.getScenarioId()).andJobEqualTo(ApiScenarioScheduleJob.class.getName()); example.createCriteria().andResourceIdEqualTo(request.getScenarioId()).andJobEqualTo(ApiScenarioScheduleJob.class.getName());
List<Schedule> schedules = scheduleMapper.selectByExample(example); List<Schedule> schedules = scheduleMapper.selectByExample(example);
return CollectionUtils.isEmpty(schedules) ? null : schedules.get(0); Map<String, String> defaultTemplateMap = MessageTemplateUtils.getDefaultTemplateMap();
String event = NoticeConstants.Event.OPEN;
if (BooleanUtils.isFalse(request.isEnable())) {
event = NoticeConstants.Event.CLOSE;
}
if (CollectionUtils.isNotEmpty(schedules)) {
BeanMap beanMap = new BeanMap(schedules.getFirst());
Map paramMap = new HashMap<>(beanMap);
String template = defaultTemplateMap.get(NoticeConstants.TaskType.SCHEDULE_TASK + "_" + event);
Map<String, String> defaultSubjectMap = MessageTemplateUtils.getDefaultTemplateSubjectMap();
String subject = defaultSubjectMap.get(NoticeConstants.TaskType.SCHEDULE_TASK + "_" + event);
NoticeModel noticeModel = NoticeModel.builder()
.operator(userId)
.context(template)
.subject(subject)
.paramMap(paramMap)
.event(event)
.excludeSelf(true)
.build();
noticeSendService.send(NoticeConstants.TaskType.SCHEDULE_TASK, noticeModel);
}
} }
public List<ApiScenario> getBatchOptionScenarios(ApiScenarioBatchRequest request) {
List<String> ids = apiScenarioService.doSelectIds(request, false);
return handleBatchNotice(ids);
}
private List<ApiScenario> handleBatchNotice(List<String> ids) { private List<ApiScenario> handleBatchNotice(List<String> ids) {
List<ApiScenario> dtoList = new ArrayList<>(); List<ApiScenario> dtoList = new ArrayList<>();

View File

@ -188,6 +188,8 @@ public class ApiScenarioService extends MoveNodeService {
private ApiScenarioReportService apiScenarioReportService; private ApiScenarioReportService apiScenarioReportService;
@Resource @Resource
private ApiScenarioReportMapper apiScenarioReportMapper; private ApiScenarioReportMapper apiScenarioReportMapper;
@Resource
private ApiScenarioNoticeService apiScenarioNoticeService;
public static final String PRIORITY = "Priority"; public static final String PRIORITY = "Priority";
public static final String STATUS = "Status"; public static final String STATUS = "Status";
@ -2667,6 +2669,7 @@ public class ApiScenarioService extends MoveNodeService {
.resourceType(ScheduleResourceType.API_SCENARIO.name()) .resourceType(ScheduleResourceType.API_SCENARIO.name())
.config(JSON.toJSONString(scheduleRequest.getConfig())) .config(JSON.toJSONString(scheduleRequest.getConfig()))
.build(); .build();
apiScenarioNoticeService.sendScheduleNotice(scheduleRequest, operator);
return scheduleService.scheduleConfig( return scheduleService.scheduleConfig(
scheduleConfig, scheduleConfig,