From 412c2270fcb4ae9c5f2fbbb879af79bb606a6c1f Mon Sep 17 00:00:00 2001 From: wxg0103 <727495428@qq.com> Date: Mon, 22 May 2023 17:11:52 +0800 Subject: [PATCH] =?UTF-8?q?refactor(=E6=8E=A5=E5=8F=A3=E6=B5=8B=E8=AF=95):?= =?UTF-8?q?=20=E6=8E=A5=E5=8F=A3=E6=B5=8B=E8=AF=95=E5=8F=91=E9=80=81?= =?UTF-8?q?=E8=84=9A=E6=9C=AC=E9=80=9A=E7=9F=A5=E5=A2=9E=E5=8A=A0=E6=8A=A5?= =?UTF-8?q?=E9=94=99=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../definition/ApiTestCaseService.java | 34 +++++---- .../service/BaseEnvironmentService.java | 70 +++++++++++++------ 2 files changed, 66 insertions(+), 38 deletions(-) diff --git a/api-test/backend/src/main/java/io/metersphere/service/definition/ApiTestCaseService.java b/api-test/backend/src/main/java/io/metersphere/service/definition/ApiTestCaseService.java index d64c802023..cb2c062605 100644 --- a/api-test/backend/src/main/java/io/metersphere/service/definition/ApiTestCaseService.java +++ b/api-test/backend/src/main/java/io/metersphere/service/definition/ApiTestCaseService.java @@ -1348,10 +1348,11 @@ public class ApiTestCaseService { String requestTarget, String sendUser) { - ProjectApplication scriptEnable = baseProjectApplicationService - .getProjectApplication(projectId, ProjectApplicationType.API_REVIEW_TEST_SCRIPT.name()); + try { + ProjectApplication scriptEnable = baseProjectApplicationService + .getProjectApplication(projectId, ProjectApplicationType.API_REVIEW_TEST_SCRIPT.name()); - if (BooleanUtils.toBoolean(scriptEnable.getTypeValue())) { + if (BooleanUtils.toBoolean(scriptEnable.getTypeValue())) { List org = ElementUtil.scriptList(requestOrg); List target = ElementUtil.scriptList(requestTarget); boolean isSend = ElementUtil.isSend(org, target); @@ -1362,20 +1363,23 @@ public class ApiTestCaseService { sendUser = reviewer.getTypeValue(); } if (baseProjectService.isProjectMember(projectId, sendUser)) { - Notification notification = new Notification(); - notification.setTitle(title); - notification.setOperator(reviewer.getTypeValue()); - notification.setOperation(NoticeConstants.Event.REVIEW); - notification.setResourceId(id); - notification.setResourceName(name); - notification.setResourceType(resourceType); - notification.setType(NotificationConstants.Type.SYSTEM_NOTICE.name()); - notification.setStatus(NotificationConstants.Status.UNREAD.name()); - notification.setCreateTime(System.currentTimeMillis()); - notification.setReceiver(sendUser); - notificationService.sendAnnouncement(notification); + Notification notification = new Notification(); + notification.setTitle(title); + notification.setOperator(reviewer.getTypeValue()); + notification.setOperation(NoticeConstants.Event.REVIEW); + notification.setResourceId(id); + notification.setResourceName(name); + notification.setResourceType(resourceType); + notification.setType(NotificationConstants.Type.SYSTEM_NOTICE.name()); + notification.setStatus(NotificationConstants.Status.UNREAD.name()); + notification.setCreateTime(System.currentTimeMillis()); + notification.setReceiver(sendUser); + notificationService.sendAnnouncement(notification); + } } } + } catch (Exception e) { + LogUtil.error("发送通知失败", e); } } diff --git a/framework/sdk-parent/sdk/src/main/java/io/metersphere/environment/service/BaseEnvironmentService.java b/framework/sdk-parent/sdk/src/main/java/io/metersphere/environment/service/BaseEnvironmentService.java index b62fb3446f..5e34fc02f2 100644 --- a/framework/sdk-parent/sdk/src/main/java/io/metersphere/environment/service/BaseEnvironmentService.java +++ b/framework/sdk-parent/sdk/src/main/java/io/metersphere/environment/service/BaseEnvironmentService.java @@ -85,6 +85,8 @@ public class BaseEnvironmentService extends NodeTreeService { private BaseProjectApplicationService baseProjectApplicationService; @Resource private NotificationService notificationService; + @Resource + private UserGroupMapper userGroupMapper; public static final String MOCK_EVN_NAME = "Mock环境"; @@ -505,14 +507,32 @@ public class BaseEnvironmentService extends NodeTreeService { ApiTestEnvironmentWithBLOBs envOrg = apiTestEnvironmentMapper.selectByPrimaryKey(apiTestEnvironment.getId()); apiTestEnvironmentMapper.updateByPrimaryKeyWithBLOBs(apiTestEnvironment); - checkAndSendReviewMessage(apiTestEnvironment.getId(), - apiTestEnvironment.getName(), - apiTestEnvironment.getProjectId(), - NoticeConstants.TaskType.ENV_TASK, - envOrg.getConfig(), - apiTestEnvironment.getConfig(), - apiTestEnvironment.getCreateUser() - ); + if (StringUtils.isBlank(apiTestEnvironment.getCreateUser())) { + UserGroupExample example = new UserGroupExample(); + example.createCriteria().andSourceIdEqualTo(apiTestEnvironment.getProjectId()).andGroupIdEqualTo("project_admin"); + List userGroups = userGroupMapper.selectByExample(example); + if (CollectionUtils.isNotEmpty(userGroups)) { + userGroups.forEach(userGroup -> { + 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 { String requestOrg, String requestTarget, String sendUser) { - ProjectApplication scriptEnable = baseProjectApplicationService - .getProjectApplication(projectId, ProjectApplicationType.API_REVIEW_TEST_SCRIPT.name()); + try { + ProjectApplication scriptEnable = baseProjectApplicationService + .getProjectApplication(projectId, ProjectApplicationType.API_REVIEW_TEST_SCRIPT.name()); - if (BooleanUtils.toBoolean(scriptEnable.getTypeValue())) { + if (BooleanUtils.toBoolean(scriptEnable.getTypeValue())) { List org = scriptList(requestOrg); List target = scriptList(requestTarget); @@ -1035,20 +1056,23 @@ public class BaseEnvironmentService extends NodeTreeService { sendUser = reviewer.getTypeValue(); } if (baseProjectService.isProjectMember(projectId, sendUser)) { - Notification notification = new Notification(); - notification.setTitle("环境设置"); - notification.setOperator(reviewer.getTypeValue()); - notification.setOperation(NoticeConstants.Event.REVIEW); - notification.setResourceId(id); - notification.setResourceName(name); - notification.setResourceType(resourceType); - notification.setType(NotificationConstants.Type.SYSTEM_NOTICE.name()); - notification.setStatus(NotificationConstants.Status.UNREAD.name()); - notification.setCreateTime(System.currentTimeMillis()); - notification.setReceiver(sendUser); - notificationService.sendAnnouncement(notification); + Notification notification = new Notification(); + notification.setTitle("环境设置"); + notification.setOperator(reviewer.getTypeValue()); + notification.setOperation(NoticeConstants.Event.REVIEW); + notification.setResourceId(id); + notification.setResourceName(name); + notification.setResourceType(resourceType); + notification.setType(NotificationConstants.Type.SYSTEM_NOTICE.name()); + notification.setStatus(NotificationConstants.Status.UNREAD.name()); + notification.setCreateTime(System.currentTimeMillis()); + notification.setReceiver(sendUser); + notificationService.sendAnnouncement(notification); + } } } + } catch (Exception e) { + LogUtil.error("发送通知失败", e); } }