refactor(接口测试): 接口测试发送脚本通知增加报错日志

This commit is contained in:
wxg0103 2023-05-22 17:11:52 +08:00 committed by fit2-zhao
parent 260c2dca4c
commit 412c2270fc
2 changed files with 66 additions and 38 deletions

View File

@ -1348,10 +1348,11 @@ public class ApiTestCaseService {
String requestTarget, String requestTarget,
String sendUser) { String sendUser) {
ProjectApplication scriptEnable = baseProjectApplicationService try {
.getProjectApplication(projectId, ProjectApplicationType.API_REVIEW_TEST_SCRIPT.name()); ProjectApplication scriptEnable = baseProjectApplicationService
.getProjectApplication(projectId, ProjectApplicationType.API_REVIEW_TEST_SCRIPT.name());
if (BooleanUtils.toBoolean(scriptEnable.getTypeValue())) { if (BooleanUtils.toBoolean(scriptEnable.getTypeValue())) {
List<String> org = ElementUtil.scriptList(requestOrg); List<String> org = ElementUtil.scriptList(requestOrg);
List<String> target = ElementUtil.scriptList(requestTarget); List<String> target = ElementUtil.scriptList(requestTarget);
boolean isSend = ElementUtil.isSend(org, target); boolean isSend = ElementUtil.isSend(org, target);
@ -1362,20 +1363,23 @@ public class ApiTestCaseService {
sendUser = reviewer.getTypeValue(); sendUser = reviewer.getTypeValue();
} }
if (baseProjectService.isProjectMember(projectId, sendUser)) { if (baseProjectService.isProjectMember(projectId, sendUser)) {
Notification notification = new Notification(); Notification notification = new Notification();
notification.setTitle(title); notification.setTitle(title);
notification.setOperator(reviewer.getTypeValue()); notification.setOperator(reviewer.getTypeValue());
notification.setOperation(NoticeConstants.Event.REVIEW); notification.setOperation(NoticeConstants.Event.REVIEW);
notification.setResourceId(id); notification.setResourceId(id);
notification.setResourceName(name); notification.setResourceName(name);
notification.setResourceType(resourceType); notification.setResourceType(resourceType);
notification.setType(NotificationConstants.Type.SYSTEM_NOTICE.name()); notification.setType(NotificationConstants.Type.SYSTEM_NOTICE.name());
notification.setStatus(NotificationConstants.Status.UNREAD.name()); notification.setStatus(NotificationConstants.Status.UNREAD.name());
notification.setCreateTime(System.currentTimeMillis()); notification.setCreateTime(System.currentTimeMillis());
notification.setReceiver(sendUser); notification.setReceiver(sendUser);
notificationService.sendAnnouncement(notification); notificationService.sendAnnouncement(notification);
}
} }
} }
} catch (Exception e) {
LogUtil.error("发送通知失败", e);
} }
} }

View File

@ -85,6 +85,8 @@ public class BaseEnvironmentService extends NodeTreeService<ApiModuleDTO> {
private BaseProjectApplicationService baseProjectApplicationService; private BaseProjectApplicationService baseProjectApplicationService;
@Resource @Resource
private NotificationService notificationService; private NotificationService notificationService;
@Resource
private UserGroupMapper userGroupMapper;
public static final String MOCK_EVN_NAME = "Mock环境"; public static final String MOCK_EVN_NAME = "Mock环境";
@ -505,14 +507,32 @@ public class BaseEnvironmentService extends NodeTreeService<ApiModuleDTO> {
ApiTestEnvironmentWithBLOBs envOrg = apiTestEnvironmentMapper.selectByPrimaryKey(apiTestEnvironment.getId()); ApiTestEnvironmentWithBLOBs envOrg = apiTestEnvironmentMapper.selectByPrimaryKey(apiTestEnvironment.getId());
apiTestEnvironmentMapper.updateByPrimaryKeyWithBLOBs(apiTestEnvironment); apiTestEnvironmentMapper.updateByPrimaryKeyWithBLOBs(apiTestEnvironment);
checkAndSendReviewMessage(apiTestEnvironment.getId(), if (StringUtils.isBlank(apiTestEnvironment.getCreateUser())) {
apiTestEnvironment.getName(), UserGroupExample example = new UserGroupExample();
apiTestEnvironment.getProjectId(), example.createCriteria().andSourceIdEqualTo(apiTestEnvironment.getProjectId()).andGroupIdEqualTo("project_admin");
NoticeConstants.TaskType.ENV_TASK, List<UserGroup> userGroups = userGroupMapper.selectByExample(example);
envOrg.getConfig(), if (CollectionUtils.isNotEmpty(userGroups)) {
apiTestEnvironment.getConfig(), userGroups.forEach(userGroup -> {
apiTestEnvironment.getCreateUser() checkAndSendReviewMessage(apiTestEnvironment.getId(),
); apiTestEnvironment.getName(),
apiTestEnvironment.getProjectId(),
NoticeConstants.TaskType.ENV_TASK,
envOrg.getConfig(),
apiTestEnvironment.getConfig(),
userGroup.getUserId()
);
});
}
} else {
checkAndSendReviewMessage(apiTestEnvironment.getId(),
apiTestEnvironment.getName(),
apiTestEnvironment.getProjectId(),
NoticeConstants.TaskType.ENV_TASK,
envOrg.getConfig(),
apiTestEnvironment.getConfig(),
apiTestEnvironment.getCreateUser()
);
}
} }
@ -1019,10 +1039,11 @@ public class BaseEnvironmentService extends NodeTreeService<ApiModuleDTO> {
String requestOrg, String requestOrg,
String requestTarget, String requestTarget,
String sendUser) { String sendUser) {
ProjectApplication scriptEnable = baseProjectApplicationService try {
.getProjectApplication(projectId, ProjectApplicationType.API_REVIEW_TEST_SCRIPT.name()); ProjectApplication scriptEnable = baseProjectApplicationService
.getProjectApplication(projectId, ProjectApplicationType.API_REVIEW_TEST_SCRIPT.name());
if (BooleanUtils.toBoolean(scriptEnable.getTypeValue())) { if (BooleanUtils.toBoolean(scriptEnable.getTypeValue())) {
List<String> org = scriptList(requestOrg); List<String> org = scriptList(requestOrg);
List<String> target = scriptList(requestTarget); List<String> target = scriptList(requestTarget);
@ -1035,20 +1056,23 @@ public class BaseEnvironmentService extends NodeTreeService<ApiModuleDTO> {
sendUser = reviewer.getTypeValue(); sendUser = reviewer.getTypeValue();
} }
if (baseProjectService.isProjectMember(projectId, sendUser)) { if (baseProjectService.isProjectMember(projectId, sendUser)) {
Notification notification = new Notification(); Notification notification = new Notification();
notification.setTitle("环境设置"); notification.setTitle("环境设置");
notification.setOperator(reviewer.getTypeValue()); notification.setOperator(reviewer.getTypeValue());
notification.setOperation(NoticeConstants.Event.REVIEW); notification.setOperation(NoticeConstants.Event.REVIEW);
notification.setResourceId(id); notification.setResourceId(id);
notification.setResourceName(name); notification.setResourceName(name);
notification.setResourceType(resourceType); notification.setResourceType(resourceType);
notification.setType(NotificationConstants.Type.SYSTEM_NOTICE.name()); notification.setType(NotificationConstants.Type.SYSTEM_NOTICE.name());
notification.setStatus(NotificationConstants.Status.UNREAD.name()); notification.setStatus(NotificationConstants.Status.UNREAD.name());
notification.setCreateTime(System.currentTimeMillis()); notification.setCreateTime(System.currentTimeMillis());
notification.setReceiver(sendUser); notification.setReceiver(sendUser);
notificationService.sendAnnouncement(notification); notificationService.sendAnnouncement(notification);
}
} }
} }
} catch (Exception e) {
LogUtil.error("发送通知失败", e);
} }
} }