From b9ef0e384fac996b209761ea4f9a8f39ea308545 Mon Sep 17 00:00:00 2001 From: CaptainB Date: Mon, 21 Nov 2022 15:05:51 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E6=B6=88=E6=81=AF=E9=80=9A=E7=9F=A5):=20?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=88=9B=E5=BB=BA=E7=BC=BA=E9=99=B7=E4=B8=8D?= =?UTF-8?q?=E8=83=BD=E9=80=9A=E7=9F=A5=E5=A4=84=E7=90=86=E4=BA=BA=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --bug=1019950 --user=刘瑞斌 [消息通知]github#19855消息通知中缺陷通知里面新建缺陷只能通知创建人,不能通知处理人 https://www.tapd.cn/55049933/s/1299369 Closes #19855 --- .../notice/sender/AbstractNoticeSender.java | 57 +++++++++++++------ 1 file changed, 39 insertions(+), 18 deletions(-) diff --git a/framework/sdk-parent/sdk/src/main/java/io/metersphere/notice/sender/AbstractNoticeSender.java b/framework/sdk-parent/sdk/src/main/java/io/metersphere/notice/sender/AbstractNoticeSender.java index d77e77b977..fbb6933ea1 100644 --- a/framework/sdk-parent/sdk/src/main/java/io/metersphere/notice/sender/AbstractNoticeSender.java +++ b/framework/sdk-parent/sdk/src/main/java/io/metersphere/notice/sender/AbstractNoticeSender.java @@ -1,5 +1,7 @@ package io.metersphere.notice.sender; +import com.fasterxml.jackson.core.type.TypeReference; +import io.metersphere.base.domain.CustomField; import io.metersphere.base.domain.TestCaseReview; import io.metersphere.base.domain.User; import io.metersphere.base.mapper.UserMapper; @@ -13,7 +15,9 @@ import io.metersphere.commons.utils.LogUtil; import io.metersphere.notice.domain.MessageDetail; import io.metersphere.notice.domain.Receiver; import io.metersphere.notice.domain.UserDetail; +import io.metersphere.service.BaseCustomFieldService; import io.metersphere.service.MicroService; +import org.apache.commons.beanutils.BeanMap; import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.time.DateFormatUtils; @@ -33,27 +37,12 @@ public abstract class AbstractNoticeSender implements NoticeSender { private MicroService microService; @Resource private UserMapper userMapper; + @Resource + private BaseCustomFieldService baseCustomFieldService; protected String getContext(MessageDetail messageDetail, NoticeModel noticeModel) { // 如果有自定义字段 - if (noticeModel.getParamMap().containsKey("customFields")) { - try { - String customFields = (String) noticeModel.getParamMap().get("customFields"); - List array = JSON.parseArray(customFields); - if (CollectionUtils.isNotEmpty(array)) { - for (Object o : array) { - Map obj = JSON.parseObject(o.toString(), Map.class); - String name = (String) obj.get("name"); - Object value = obj.get("value"); - noticeModel.getParamMap().put(name, value); // 处理人 - if (StringUtils.equals((String) obj.get("name"), "处理人")) { - noticeModel.getParamMap().put("processor", value); // 处理人 - } - } - } - } catch (Exception e) { - } - } + handleCustomFields(noticeModel); // 处理 userIds 中包含的特殊值 noticeModel.setReceivers(getRealUserIds(messageDetail, noticeModel, messageDetail.getEvent())); @@ -93,6 +82,38 @@ public abstract class AbstractNoticeSender implements NoticeSender { return getContent(context, noticeModel.getParamMap()); } + private void handleCustomFields(NoticeModel noticeModel) { + if (!noticeModel.getParamMap().containsKey("fields")) { + return; + } + try { + Object customFields = noticeModel.getParamMap().get("fields"); + List fields; + if (customFields instanceof String) { + fields = JSON.parseArray((String) customFields, Object.class); + } else { + fields = (List) customFields; + } + if (CollectionUtils.isNotEmpty(fields)) { + for (Object o : fields) { + Map jsonObject = new BeanMap(o); + String id = (String) jsonObject.get("id"); + CustomField customField = baseCustomFieldService.get(id); + Object value = jsonObject.get("value"); + if (value instanceof String && StringUtils.isNotEmpty((String) value)) { + String v = StringUtils.unwrap((String) value, "\""); + noticeModel.getParamMap().put(customField.getName(), v); // 处理人 + if (StringUtils.equals(customField.getName(), "处理人")) { + noticeModel.getParamMap().put("processor", v); // 处理人 + } + } + } + } + } catch (Exception e) { + LogUtil.error(e); + } + } + protected String getContent(String template, Map context) { // 处理 null context.forEach((k, v) -> {