From 0e2ce21192a6eef68ae015e2dadb239d56818ecd Mon Sep 17 00:00:00 2001 From: fit2-zhao Date: Tue, 10 Jan 2023 13:18:04 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E6=8E=A5=E5=8F=A3=E6=B5=8B=E8=AF=95):=20?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=B6=88=E6=81=AF=E9=80=9A=E7=9F=A5=E4=BA=BA?= =?UTF-8?q?=E9=94=99=E8=AF=AF=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --bug=1021753 --user=赵勇 【项目设置】站内消息通知用户名显示错误 https://www.tapd.cn/55049933/s/1324990 --- .../commons/constants/CommonConstants.java | 3 ++ .../ApiDefinitionExecResultService.java | 40 +++++++++++-------- 2 files changed, 27 insertions(+), 16 deletions(-) diff --git a/api-test/backend/src/main/java/io/metersphere/commons/constants/CommonConstants.java b/api-test/backend/src/main/java/io/metersphere/commons/constants/CommonConstants.java index ecdfecd3b0..c7b65fb0e1 100644 --- a/api-test/backend/src/main/java/io/metersphere/commons/constants/CommonConstants.java +++ b/api-test/backend/src/main/java/io/metersphere/commons/constants/CommonConstants.java @@ -11,4 +11,7 @@ public class CommonConstants { public static final String USER_ID = "userId"; public static final String METHODS_KEY = "methods"; public static final String CASE = "CASE"; + public static final String USER = "user"; + public static final String USER_NAME = "userName"; + } diff --git a/api-test/backend/src/main/java/io/metersphere/service/definition/ApiDefinitionExecResultService.java b/api-test/backend/src/main/java/io/metersphere/service/definition/ApiDefinitionExecResultService.java index b79adefa28..ad44293ca5 100644 --- a/api-test/backend/src/main/java/io/metersphere/service/definition/ApiDefinitionExecResultService.java +++ b/api-test/backend/src/main/java/io/metersphere/service/definition/ApiDefinitionExecResultService.java @@ -95,18 +95,7 @@ public class ApiDefinitionExecResultService { if (result != null) { result.setResourceId(dto.getTestId()); apiExecutionInfoService.insertExecutionInfo(result); - User user = null; - if (MapUtils.isNotEmpty(dto.getExtendedParameters())) { - if (dto.getExtendedParameters().containsKey(CommonConstants.USER_ID) && dto.getExtendedParameters().containsKey("userName")) { - user = new User() {{ - this.setId(dto.getExtendedParameters().get(CommonConstants.USER_ID).toString()); - this.setName(dto.getExtendedParameters().get("userName").toString()); - }}; - result.setUserId(user.getId()); - } else if (dto.getExtendedParameters().containsKey(CommonConstants.USER_ID)) { - result.setUserId(dto.getExtendedParameters().get(CommonConstants.USER_ID).toString()); - } - } + User user = getUser(dto, result); //如果是测试计划用例,更新接口用例的上次执行结果 TestPlanApiCase testPlanApiCase = testPlanApiCaseMapper.selectByPrimaryKey(dto.getTestId()); if (testPlanApiCase != null) { @@ -147,10 +136,12 @@ public class ApiDefinitionExecResultService { // 批量更新关联关系状态 batchEditStatus(dto.getRunMode(), result.getStatus(), result.getId(), dto.getTestId(), planApiCaseMapper, batchApiTestCaseMapper); } - if (result != null && !StringUtils.startsWithAny(dto.getRunMode(), "SCHEDULE")) { - User user = null; - if (MapUtils.isNotEmpty(dto.getExtendedParameters()) && dto.getExtendedParameters().containsKey("user") && dto.getExtendedParameters().get("user") instanceof User) { - user = (User) dto.getExtendedParameters().get("user"); + if (result != null && !StringUtils.startsWithAny(dto.getRunMode(), NoticeConstants.Mode.SCHEDULE)) { + User user = getUser(dto, result); + if (MapUtils.isNotEmpty(dto.getExtendedParameters()) + && dto.getExtendedParameters().containsKey(CommonConstants.USER) + && dto.getExtendedParameters().get(CommonConstants.USER) instanceof User) { + user = (User) dto.getExtendedParameters().get(CommonConstants.USER); } // 发送通知 result.setResourceId(dto.getTestId()); @@ -166,6 +157,23 @@ public class ApiDefinitionExecResultService { } } + private User getUser(ResultDTO dto, ApiDefinitionExecResult result) { + User user = null; + if (MapUtils.isNotEmpty(dto.getExtendedParameters())) { + if (dto.getExtendedParameters().containsKey(CommonConstants.USER_ID) + && dto.getExtendedParameters().containsKey(CommonConstants.USER_NAME)) { + user = new User() {{ + this.setId(dto.getExtendedParameters().get(CommonConstants.USER_ID).toString()); + this.setName(dto.getExtendedParameters().get(CommonConstants.USER_NAME).toString()); + }}; + result.setUserId(user.getId()); + } else if (dto.getExtendedParameters().containsKey(CommonConstants.USER_ID)) { + result.setUserId(dto.getExtendedParameters().get(CommonConstants.USER_ID).toString()); + } + } + return user; + } + private void sendNotice(ApiDefinitionExecResult result, User user) { try { String resourceId = result.getResourceId();