From 8e5b85d9a27f82019348406131757efd1e517958 Mon Sep 17 00:00:00 2001 From: fitzcao Date: Thu, 28 Oct 2021 15:52:40 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BC=81=E4=B8=9A=E5=BE=AE=E4=BF=A1?= =?UTF-8?q?=E9=80=9A=E7=9F=A5=E5=8A=9F=E8=83=BD=E6=94=AF=E6=8C=81=E5=8E=BB?= =?UTF-8?q?=E6=8E=89=E5=9F=9F=20#5318?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../NotifyMessageTemplateServiceImpl.kt | 23 ++++++++++++++++++- .../templates/#etc#ci#application-notify.yml | 1 + 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/backend/ci/core/notify/biz-notify/src/main/kotlin/com/tencent/devops/notify/service/NotifyMessageTemplateServiceImpl.kt b/src/backend/ci/core/notify/biz-notify/src/main/kotlin/com/tencent/devops/notify/service/NotifyMessageTemplateServiceImpl.kt index 5769cf0e57b..22897f6daeb 100644 --- a/src/backend/ci/core/notify/biz-notify/src/main/kotlin/com/tencent/devops/notify/service/NotifyMessageTemplateServiceImpl.kt +++ b/src/backend/ci/core/notify/biz-notify/src/main/kotlin/com/tencent/devops/notify/service/NotifyMessageTemplateServiceImpl.kt @@ -56,6 +56,7 @@ import org.jooq.DSLContext import org.jooq.impl.DSL import org.slf4j.LoggerFactory import org.springframework.beans.factory.annotation.Autowired +import org.springframework.beans.factory.annotation.Value import org.springframework.stereotype.Service import java.time.LocalDateTime @@ -73,6 +74,9 @@ class NotifyMessageTemplateServiceImpl @Autowired constructor( private val logger = LoggerFactory.getLogger(NotifyMessageTemplateServiceImpl::class.java) + @Value("\${wework.domain}") + private val userUseDomain: Boolean? = true + /** * 根据查找到的消息通知模板主体信息来获取具体信息 * @param userId @@ -729,7 +733,7 @@ class NotifyMessageTemplateServiceImpl @Autowired constructor( ) { val wechatNotifyMessage = WeworkNotifyMessageWithOperation() wechatNotifyMessage.sender = sender - wechatNotifyMessage.addAllReceivers(sendNotifyMessageTemplateRequest.receivers) + wechatNotifyMessage.addAllReceivers(findWeworkUser(sendNotifyMessageTemplateRequest.receivers)) wechatNotifyMessage.body = body wechatNotifyMessage.priority = EnumNotifyPriority.parse(commonNotifyMessageTemplate.priority.toString()) wechatNotifyMessage.source = EnumNotifySource.parse(commonNotifyMessageTemplate.source.toInt()) @@ -745,4 +749,21 @@ class NotifyMessageTemplateServiceImpl @Autowired constructor( } return content1 } + + // #5318 为解决使用蓝鲸用户中心生成了带域名的用户名无法与企业微信账号对齐问题 + private fun findWeworkUser(userSet: Set): Set { + if (userUseDomain!!) { + val weworkUserSet = mutableSetOf() + userSet.forEach { + // 若用户名包含域,取域前的用户名. + if (it.contains("@")) { + weworkUserSet.add(it.substringBefore("@")) + } else { + weworkUserSet.add(it) + } + } + return weworkUserSet + } + return userSet + } } diff --git a/support-files/templates/#etc#ci#application-notify.yml b/support-files/templates/#etc#ci#application-notify.yml index ceb49c3b333..89bdaefe558 100644 --- a/support-files/templates/#etc#ci#application-notify.yml +++ b/support-files/templates/#etc#ci#application-notify.yml @@ -22,3 +22,4 @@ wework: enableDuplicateCheck: # 表示是否开启重复消息检查,0表示否,1表示是,默认0 duplicateCheckInterval: # 表示是否重复消息检查的时间间隔,默认1800s,最大不超过4小时 enableIdTrans: # 表示是否开启id转译,0表示否,1表示是,默认0。仅第三方应用需要用到,企业自建应用可以忽略。 + domain: true # 表示是否需要关注用户名内的@, true会将包含@的域信息剔除。 用于解决蓝鲸内用户名携带域的场景