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会将包含@的域信息剔除。 用于解决蓝鲸内用户名携带域的场景