From 34073ac9db26dc1c90437c4604c9219f14dd8c73 Mon Sep 17 00:00:00 2001 From: "Captain.B" Date: Mon, 23 Aug 2021 10:59:41 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E6=B5=8B=E8=AF=95=E8=AE=A1?= =?UTF-8?q?=E5=88=92=E5=8F=91=E9=80=81=E6=88=90=E5=8A=9F=E9=80=9A=E7=9F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../notice/sender/impl/LarkNoticeSender.java | 6 +++ .../track/service/TestPlanService.java | 45 +++++++++---------- .../components/notice/Notification.vue | 10 ++++- 3 files changed, 37 insertions(+), 24 deletions(-) diff --git a/backend/src/main/java/io/metersphere/notice/sender/impl/LarkNoticeSender.java b/backend/src/main/java/io/metersphere/notice/sender/impl/LarkNoticeSender.java index 0755c4e914..2b44e98258 100644 --- a/backend/src/main/java/io/metersphere/notice/sender/impl/LarkNoticeSender.java +++ b/backend/src/main/java/io/metersphere/notice/sender/impl/LarkNoticeSender.java @@ -6,6 +6,7 @@ import io.metersphere.notice.domain.UserDetail; import io.metersphere.notice.sender.AbstractNoticeSender; import io.metersphere.notice.sender.NoticeModel; import io.metersphere.notice.util.LarkClient; +import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.lang3.StringUtils; import org.springframework.stereotype.Component; @@ -26,6 +27,11 @@ public class LarkNoticeSender extends AbstractNoticeSender { .map(ud -> "" + ud.getName() + "") .collect(Collectors.toList()); + // 没有接收人不发通知 + if (CollectionUtils.isEmpty(collect)) { + return; + } + context += StringUtils.join(collect, " "); LarkClient.send(messageDetail.getWebhook(), context); } diff --git a/backend/src/main/java/io/metersphere/track/service/TestPlanService.java b/backend/src/main/java/io/metersphere/track/service/TestPlanService.java index 5f2aa41311..81150c5075 100644 --- a/backend/src/main/java/io/metersphere/track/service/TestPlanService.java +++ b/backend/src/main/java/io/metersphere/track/service/TestPlanService.java @@ -273,8 +273,7 @@ public class TestPlanService { status = "已完成"; } context.put("status", status); - User user = userMapper.selectByPrimaryKey(testPlan.getCreator()); - context.put("creator", user.getName()); + context.put("creator", testPlan.getCreator()); return context; } @@ -409,7 +408,7 @@ public class TestPlanService { testPlanWithBLOBs.setStatus(TestPlanStatus.Completed.name()); this.editTestPlan(testPlanWithBLOBs); // 发送成功通知 - sendCompletedNotice(testPlanWithBLOBs); +// sendCompletedNotice(testPlanWithBLOBs); } else if (prepareNum == 0 && passNum + failNum == statusList.size()) { // 已结束 testPlanWithBLOBs.setStatus(TestPlanStatus.Finished.name()); editTestPlan(testPlanWithBLOBs); @@ -1058,21 +1057,21 @@ public class TestPlanService { } testPlanLog.info("ReportId[" + planReportId + "] start run. TestPlanID:[" + testPlanID + "]. Execute api :" + JSONObject.toJSONString(executeApiCaseIdMap) + "; Execute scenario:" + JSONObject.toJSONString(executeScenarioCaseIdMap) + "; Execute performance:" + JSONObject.toJSONString(executePerformanceIdMap)); // testPlanReportService.updateExecuteApis(planReportId, executeApiCaseIdMap, executeScenarioCaseIdMap, executePerformanceIdMap); - TestPlanReportExecuteCatch.updateApiTestPlanExecuteInfo(planReportId,executeApiCaseIdMap,executeScenarioCaseIdMap,executePerformanceIdMap); + TestPlanReportExecuteCatch.updateApiTestPlanExecuteInfo(planReportId, executeApiCaseIdMap, executeScenarioCaseIdMap, executePerformanceIdMap); //执行接口案例任务 - this.executeApiTestCase(triggerMode,planReportId,testPlanID,apiTestCaseDataMap); + this.executeApiTestCase(triggerMode, planReportId, testPlanID, apiTestCaseDataMap); //执行场景执行任务 - this.executeScenarioCase(planReportId,testPlanID,projectID,apiRunConfig,triggerMode,userId,planScenarioIdMap); + this.executeScenarioCase(planReportId, testPlanID, projectID, apiRunConfig, triggerMode, userId, planScenarioIdMap); this.listenTaskExecuteStatus(planReportId); return testPlanReport.getId(); } private void listenTaskExecuteStatus(String planReportId) { - executorService.submit(()->{ + executorService.submit(() -> { try { Thread.sleep(30000); - while (TestPlanReportExecuteCatch.getTestPlanExecuteInfo(planReportId) != null){ + while (TestPlanReportExecuteCatch.getTestPlanExecuteInfo(planReportId) != null) { testPlanReportService.countReport(planReportId); Thread.sleep(30000); } @@ -1083,30 +1082,30 @@ public class TestPlanService { }); } - private void executeApiTestCase(String triggerMode, String planReportId,String testPlanId,Map apiTestCaseDataMap) { + private void executeApiTestCase(String triggerMode, String planReportId, String testPlanId, Map apiTestCaseDataMap) { executorService.submit(() -> { - Map executeErrorMap = new HashMap<>(); + Map executeErrorMap = new HashMap<>(); for (Map.Entry entry : apiTestCaseDataMap.entrySet()) { - ApiTestCaseWithBLOBs blobs = entry.getKey(); - try{ + ApiTestCaseWithBLOBs blobs = entry.getKey(); + try { if (StringUtils.equals(triggerMode, ReportTriggerMode.API.name())) { apiTestCaseService.run(blobs, UUID.randomUUID().toString(), planReportId, testPlanId, ApiRunMode.JENKINS_API_PLAN.name()); } else { apiTestCaseService.run(blobs, UUID.randomUUID().toString(), planReportId, testPlanId, ApiRunMode.SCHEDULE_API_PLAN.name()); } - }catch (Exception e){ - executeErrorMap.put(blobs.getId(),TestPlanApiExecuteStatus.FAILD.name()); + } catch (Exception e) { + executeErrorMap.put(blobs.getId(), TestPlanApiExecuteStatus.FAILD.name()); } } - if(!executeErrorMap.isEmpty()){ - TestPlanReportExecuteCatch.updateApiTestPlanExecuteInfo(planReportId,executeErrorMap,null,null); + if (!executeErrorMap.isEmpty()) { + TestPlanReportExecuteCatch.updateApiTestPlanExecuteInfo(planReportId, executeErrorMap, null, null); } }); } - private void executeScenarioCase(String planReportId,String testPlanID,String projectID, String apiRunConfig, String triggerMode, String userId, Map planScenarioIdMap) { - executorService.submit(()->{ + private void executeScenarioCase(String planReportId, String testPlanID, String projectID, String apiRunConfig, String triggerMode, String userId, Map planScenarioIdMap) { + executorService.submit(() -> { if (!planScenarioIdMap.isEmpty()) { SchedulePlanScenarioExecuteRequest scenarioRequest = new SchedulePlanScenarioExecuteRequest(); String senarionReportID = UUID.randomUUID().toString(); @@ -1133,10 +1132,10 @@ public class TestPlanService { try { runModeConfig = JSONObject.parseObject(apiRunConfig, RunModeConfig.class); runModeConfig.setOnSampleError(false); - }catch(Exception e){ + } catch (Exception e) { e.printStackTrace(); } - if (runModeConfig == null){ + if (runModeConfig == null) { runModeConfig = new RunModeConfig(); runModeConfig.setMode("serial"); runModeConfig.setReportType("iddReport"); @@ -1431,7 +1430,7 @@ public class TestPlanService { // 场景 List scenarioFailureCases = null; if (!CollectionUtils.isEmpty(scenarioAllCases)) { - scenarioFailureCases = scenarioAllCases.stream() + scenarioFailureCases = scenarioAllCases.stream() .filter(i -> StringUtils.isNotBlank(i.getLastResult()) && i.getLastResult().equals("Fail")) .collect(Collectors.toList()); @@ -1468,7 +1467,7 @@ public class TestPlanService { } public Boolean checkReportConfig(JSONObject config, String key) { - if (config == null) { + if (config == null) { return true; } else { JSONObject configItem = config.getJSONObject(key); @@ -1477,7 +1476,7 @@ public class TestPlanService { } public Boolean checkReportConfig(JSONObject config, String key, String subKey) { - if (config == null) { + if (config == null) { return true; } else { JSONObject configItem = config.getJSONObject(key); diff --git a/frontend/src/business/components/notice/Notification.vue b/frontend/src/business/components/notice/Notification.vue index 63b1e3346b..0a384ceeaa 100644 --- a/frontend/src/business/components/notice/Notification.vue +++ b/frontend/src/business/components/notice/Notification.vue @@ -45,6 +45,7 @@ import MsRequestResultTail from "../../components/api/definition/components/resp import MsTipButton from "@/business/components/common/components/MsTipButton"; import SystemNoticeData from "@/business/components/notice/components/SystemNoticeData"; import MentionedMeData from "@/business/components/notice/components/MentionedMeData"; +import {getOperation, getResource} from "@/business/components/notice/util"; export default { name: "MsNotification", @@ -69,6 +70,7 @@ export default { visible: false, showType: "", userList: [], + userMap: {}, websocket: Object, activeName: 'mentionedMe', pageSize: 20, @@ -95,6 +97,10 @@ export default { getUserList() { this.$get('/user/list', response => { this.userList = response.data; + this.userMap = this.userList.reduce((r, c) => { + r[c.id] = c; + return r; + }, {}); }); }, initWebSocket() { @@ -155,12 +161,14 @@ export default { if (now - d.createTime > 10 * 1000) { return; } + d.user = this.userMap[d.operator]; + let message = d.user.name + getOperation(d.operation) + getResource(d.resourceType) + ": " + d.resourceName; let title = d.type === 'MENTIONED_ME' ? '@提到我的' : '系统通知'; setTimeout(() => { this.$notify({ title: title, type: 'info', - message: d.content, + message: message, }); }); });