fix(接口测试): 修复用例执行完成后推送消息异常

--bug=1010424 --user=赵勇 case选择资源池执行日志报错 https://www.tapd.cn/55049933/s/1106452
This commit is contained in:
fit2-zhao 2022-02-21 11:28:57 +08:00 committed by fit2-zhao
parent 69da455dd5
commit ad1650a8bc
2 changed files with 17 additions and 7 deletions

View File

@ -61,6 +61,8 @@ public class ApiDefinitionExecResultService {
private ApiTestCaseService apiTestCaseService;
@Resource
private UserMapper userMapper;
@Resource
private ProjectMapper projectMapper;
public void saveApiResult(List<RequestResult> requestResults, ResultDTO dto) {
LoggerUtil.info("接收到API/CASE执行结果【 " + requestResults.size() + "");
@ -98,9 +100,14 @@ public class ApiDefinitionExecResultService {
event = NoticeConstants.Event.EXECUTE_FAILED;
status = "失败";
}
User user = userMapper.selectByPrimaryKey(result.getUserId());
User user = null;
if (SessionUtils.getUser() != null && StringUtils.equals(SessionUtils.getUser().getId(), result.getUserId())) {
user = SessionUtils.getUser();
} else {
user = userMapper.selectByPrimaryKey(result.getUserId());
}
Map paramMap = new HashMap<>(beanMap);
paramMap.put("operator", user != null ? user.getName() : SessionUtils.getUser().getName());
paramMap.put("operator", user != null ? user.getName() : result.getUserId());
paramMap.put("status", result.getStatus());
String context = "${operator}执行接口用例" + status + ": ${name}";
NoticeModel noticeModel = NoticeModel.builder()
@ -114,13 +121,16 @@ public class ApiDefinitionExecResultService {
.build();
String taskType = NoticeConstants.TaskType.API_DEFINITION_TASK;
if (StringUtils.equals(ReportTriggerMode.API.name(), result.getTriggerMode())) {
noticeSendService.send(ReportTriggerMode.API.name(), taskType, noticeModel);
} else {
if (SessionUtils.getUser() != null
&& StringUtils.equals(SessionUtils.getCurrentProjectId(), apiTestCaseWithBLOBs.getProjectId())
&& StringUtils.isNotEmpty(SessionUtils.getCurrentWorkspaceId())) {
noticeSendService.send(taskType, noticeModel);
} else {
Project project = projectMapper.selectByPrimaryKey(apiTestCaseWithBLOBs.getProjectId());
noticeSendService.send(project, taskType, noticeModel);
}
} catch (Exception e) {
LogUtil.error(e);
LogUtil.error("消息发送失败:" + e.getMessage());
}
}

View File

@ -134,7 +134,7 @@ public class NoticeService {
public List<MessageDetail> searchMessageByTypeBySend(String type, String projectId) {
try {
String workspaceId = "";
if (null == SessionUtils.getUser()) {
if (null == SessionUtils.getCurrentWorkspaceId()) {
Project project = projectMapper.selectByPrimaryKey(projectId);
workspaceId = project.getWorkspaceId();
} else {