From 162cb3560b8a98abd6f91635ff453241bdb3cdda Mon Sep 17 00:00:00 2001 From: guoyuqi Date: Mon, 24 Oct 2022 16:41:09 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E9=A1=B9=E7=9B=AE=E8=AE=BE=E7=BD=AE):=20?= =?UTF-8?q?=E6=96=B0=E5=A2=9E=E6=B6=88=E6=81=AF=E9=80=9A=E7=9F=A5=E7=B1=BB?= =?UTF-8?q?=E5=9E=8B-mock?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit https://www.tapd.cn/55049933/prong/stories/view/1155049933001009922 --user=郭雨琦 --- .../controller/mock/MockConfigController.java | 2 + .../service/MockConfigService.java | 50 +++++++++-- .../src/business/definition/ApiDefinition.vue | 49 ++++++++++- .../frontend/src/components/notice/util.js | 2 + .../frontend/src/i18n/lang/en-US.js | 3 + .../frontend/src/i18n/lang/zh-CN.js | 3 + .../frontend/src/i18n/lang/zh-TW.js | 3 + .../commons/constants/NoticeConstants.java | 4 + .../AfterReturningNoticeSendService.java | 3 + .../api/ApiDefinitionNotification.vue | 86 +++++++++++++++++++ 10 files changed, 199 insertions(+), 6 deletions(-) diff --git a/api-test/backend/src/main/java/io/metersphere/controller/mock/MockConfigController.java b/api-test/backend/src/main/java/io/metersphere/controller/mock/MockConfigController.java index 6a85023020..4a6048bcc9 100644 --- a/api-test/backend/src/main/java/io/metersphere/controller/mock/MockConfigController.java +++ b/api-test/backend/src/main/java/io/metersphere/controller/mock/MockConfigController.java @@ -8,8 +8,10 @@ import io.metersphere.api.dto.mock.config.MockConfigRequest; import io.metersphere.api.dto.mock.config.MockExpectConfigRequest; import io.metersphere.api.dto.mock.config.response.MockConfigResponse; import io.metersphere.api.dto.mock.config.response.MockExpectConfigResponse; +import io.metersphere.commons.constants.NoticeConstants; import io.metersphere.commons.utils.mock.MockApiUtils; import io.metersphere.commons.utils.mock.MockTestDataUtil; +import io.metersphere.notice.annotation.SendNotice; import io.metersphere.service.definition.ApiDefinitionService; import io.metersphere.service.MockConfigService; import io.metersphere.base.domain.ApiDefinitionWithBLOBs; diff --git a/api-test/backend/src/main/java/io/metersphere/service/MockConfigService.java b/api-test/backend/src/main/java/io/metersphere/service/MockConfigService.java index bf83c736fe..bb78c0170d 100644 --- a/api-test/backend/src/main/java/io/metersphere/service/MockConfigService.java +++ b/api-test/backend/src/main/java/io/metersphere/service/MockConfigService.java @@ -13,11 +13,9 @@ import io.metersphere.api.parse.api.ApiDefinitionImport; import io.metersphere.api.parse.scenario.TcpTreeTableDataParser; import io.metersphere.api.tcp.TCPPool; import io.metersphere.base.domain.*; -import io.metersphere.base.mapper.MockConfigMapper; -import io.metersphere.base.mapper.MockExpectConfigMapper; -import io.metersphere.base.mapper.ProjectApplicationMapper; -import io.metersphere.base.mapper.ProjectMapper; +import io.metersphere.base.mapper.*; import io.metersphere.base.mapper.ext.ExtMockExpectConfigMapper; +import io.metersphere.commons.constants.NoticeConstants; import io.metersphere.commons.constants.ProjectApplicationType; import io.metersphere.commons.constants.PropertyConstant; import io.metersphere.commons.exception.MSException; @@ -26,6 +24,8 @@ import io.metersphere.commons.utils.mock.MockApiUtils; import io.metersphere.dto.ProjectConfig; import io.metersphere.environment.service.BaseEnvironmentService; import io.metersphere.i18n.Translator; +import io.metersphere.notice.sender.NoticeModel; +import io.metersphere.notice.service.NoticeSendService; import io.metersphere.service.definition.ApiDefinitionService; import io.metersphere.service.ext.ExtProjectApplicationService; import org.apache.commons.collections.CollectionUtils; @@ -75,6 +75,14 @@ public class MockConfigService { private String tcpMockPorts; @Resource private BaseEnvironmentService baseEnvironmentService; + @Resource + private NoticeSendService noticeSendService; + + @Resource + private ApiDefinitionMapper apiDefinitionMapper; + + @Resource + private ProjectVersionMapper projectVersionMapper; public List selectMockExpectConfigByApiId(String apiId) { return extMockExpectConfigMapper.selectByApiId(apiId); @@ -169,6 +177,33 @@ public class MockConfigService { return returnRsp; } + public void sendMockNotice(MockExpectConfigWithBLOBs mockExpectConfigWithBLOBs, String defaultContext, String event) { + String context = SessionUtils.getUserId().concat(defaultContext).concat(":").concat(mockExpectConfigWithBLOBs.getName()); + Map paramMap = new HashMap<>(); + MockConfig mockConfig = mockConfigMapper.selectByPrimaryKey(mockExpectConfigWithBLOBs.getMockConfigId()); + getParamMap(paramMap, SessionUtils.getUserId(), mockExpectConfigWithBLOBs, mockConfig); + NoticeModel noticeModel = NoticeModel.builder().operator(SessionUtils.getUserId()).context(context).testId(mockExpectConfigWithBLOBs.getId()).subject("接口定义通知").paramMap(paramMap).excludeSelf(true).event(event).build(); + noticeSendService.send(NoticeConstants.TaskType.API_DEFINITION_TASK, noticeModel); + } + + private void getParamMap(Map paramMap, String userId, MockExpectConfigWithBLOBs mockExpectConfigWithBLOBs, MockConfig mockConfig) { + paramMap.put("operator", userId); + paramMap.put("id", mockExpectConfigWithBLOBs.getId()); + paramMap.put("name", mockExpectConfigWithBLOBs.getName()); + paramMap.put("createUser", mockExpectConfigWithBLOBs.getCreateUserId()); + if (mockConfig != null) { + ApiDefinitionWithBLOBs apiDefinitionWithBLOBs = apiDefinitionMapper.selectByPrimaryKey(mockConfig.getApiId()); + if (apiDefinitionWithBLOBs != null) { + paramMap.put("projectId", apiDefinitionWithBLOBs.getProjectId()); + paramMap.put("apiDefinitionId", apiDefinitionWithBLOBs.getId()); + ProjectVersion projectVersion = projectVersionMapper.selectByPrimaryKey(apiDefinitionWithBLOBs.getVersionId()); + paramMap.put("version", projectVersion.getName()); + } + + } + + } + public MockExpectConfig updateMockExpectConfigStatus(MockExpectConfigRequest request) { if (StringUtils.isNotEmpty(request.getId()) && StringUtils.isNotEmpty(request.getStatus())) { MockExpectConfigWithBLOBs model = new MockExpectConfigWithBLOBs(); @@ -177,6 +212,7 @@ public class MockConfigService { model.setUpdateTime(timeStmp); model.setStatus(request.getStatus()); mockExpectConfigMapper.updateByPrimaryKeySelective(model); + sendMockNotice(model, "更新了mock", NoticeConstants.Event.MOCK_UPDATE); return model; } else { return null; @@ -219,14 +255,17 @@ public class MockConfigService { model.setCreateUserId(SessionUtils.getUserId()); model.setStatus("true"); mockExpectConfigMapper.insert(model); + sendMockNotice(model, "新建了mock", NoticeConstants.Event.MOCK_CREATE); } else { mockExpectConfigMapper.updateByPrimaryKeySelective(model); + model = mockExpectConfigMapper.selectByPrimaryKey(model.getId()); + sendMockNotice(model, "更新了mock", NoticeConstants.Event.MOCK_UPDATE); } if (StringUtils.isNotEmpty(request.getCopyId())) { FileUtils.copyBdyFile(request.getCopyId(), model.getId()); } FileUtils.createBodyFiles(model.getId(), bodyFiles); - return model; + return mockExpectConfigMapper.selectByPrimaryKey(model.getId()); } private String getMockExpectId(String mockConfigId) { @@ -637,6 +676,7 @@ public class MockConfigService { public void deleteMockExpectConfig(String id) { MockExpectConfigWithBLOBs mockBlobs = mockExpectConfigMapper.selectByPrimaryKey(id); if (mockBlobs != null) { + sendMockNotice(mockBlobs, "删除了mock", NoticeConstants.Event.MOCK_DELETE); this.deleteMockExpectFiles(mockBlobs); mockExpectConfigMapper.deleteByPrimaryKey(id); } diff --git a/api-test/frontend/src/business/definition/ApiDefinition.vue b/api-test/frontend/src/business/definition/ApiDefinition.vue index 20c9dffb3d..ac4c27a626 100644 --- a/api-test/frontend/src/business/definition/ApiDefinition.vue +++ b/api-test/frontend/src/business/definition/ApiDefinition.vue @@ -244,7 +244,10 @@ - +