Skip to content

Commit

Permalink
Merge pull request #5431 from fitzcao/issues_5318
Browse files Browse the repository at this point in the history
feat: 企业微信通知功能支持去掉域 #5318
  • Loading branch information
irwinsun authored Oct 28, 2021
2 parents a6e7590 + 8e5b85d commit d91b375
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down Expand Up @@ -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())
Expand All @@ -745,4 +749,21 @@ class NotifyMessageTemplateServiceImpl @Autowired constructor(
}
return content1
}

// #5318 为解决使用蓝鲸用户中心生成了带域名的用户名无法与企业微信账号对齐问题
private fun findWeworkUser(userSet: Set<String>): Set<String> {
if (userUseDomain!!) {
val weworkUserSet = mutableSetOf<String>()
userSet.forEach {
// 若用户名包含域,取域前的用户名.
if (it.contains("@")) {
weworkUserSet.add(it.substringBefore("@"))
} else {
weworkUserSet.add(it)
}
}
return weworkUserSet
}
return userSet
}
}
1 change: 1 addition & 0 deletions support-files/templates/#etc#ci#application-notify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,4 @@ wework:
enableDuplicateCheck: # 表示是否开启重复消息检查,0表示否,1表示是,默认0
duplicateCheckInterval: # 表示是否重复消息检查的时间间隔,默认1800s,最大不超过4小时
enableIdTrans: # 表示是否开启id转译,0表示否,1表示是,默认0。仅第三方应用需要用到,企业自建应用可以忽略。
domain: true # 表示是否需要关注用户名内的@, true会将包含@的域信息剔除。 用于解决蓝鲸内用户名携带域的场景

0 comments on commit d91b375

Please sign in to comment.