|
|
@@ -1,6 +1,8 @@
|
|
|
package com.etotem.cfc.service.notification;
|
|
|
|
|
|
import com.etotem.cfc.dto.NotificationMessage;
|
|
|
+import com.etotem.cfc.entity.User;
|
|
|
+import com.etotem.cfc.mapper.UserMapper;
|
|
|
import com.etotem.cfc.service.WechatWaitMsgService;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
@@ -13,6 +15,9 @@ import javax.annotation.Resource;
|
|
|
* <p>
|
|
|
* 复用 WechatWaitMsgService 向微信待办接口推送;URL/token 见
|
|
|
* etotem.webhook.wait-msg.*(缺省内联默认值),msgLabel 经 sys_config 可配。
|
|
|
+ * <p>
|
|
|
+ * 定向推送:若接收用户配置了手机号,则以手机号作为 msgLabel(按人定向),
|
|
|
+ * 否则回退全局 msgLabel(sys_config → yml 默认值)。
|
|
|
*/
|
|
|
@Component
|
|
|
public class WebhookNotificationChannel implements NotificationChannel {
|
|
|
@@ -22,6 +27,9 @@ public class WebhookNotificationChannel implements NotificationChannel {
|
|
|
@Resource
|
|
|
private WechatWaitMsgService wechatWaitMsgService;
|
|
|
|
|
|
+ @Resource
|
|
|
+ private UserMapper userMapper;
|
|
|
+
|
|
|
@Override
|
|
|
public String getChannelType() {
|
|
|
return "wechat";
|
|
|
@@ -34,9 +42,27 @@ public class WebhookNotificationChannel implements NotificationChannel {
|
|
|
|
|
|
@Override
|
|
|
public void send(NotificationMessage message) {
|
|
|
- boolean ok = wechatWaitMsgService.sendWaitMsg(message.getContent());
|
|
|
+ // 优先用接收人手机号作为 msgLabel(按用户定向推送);无手机号则用全局默认
|
|
|
+ String label = resolveUserPhone(message.getUserId());
|
|
|
+ boolean ok = wechatWaitMsgService.sendWaitMsg(message.getContent(), label);
|
|
|
if (!ok) {
|
|
|
- log.warn("微信待办推送失败: userId={}, title={}", message.getUserId(), message.getTitle());
|
|
|
+ log.warn("微信待办推送失败: userId={}, title={}, label={}", message.getUserId(), message.getTitle(), label);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /** 查询接收用户手机号作为定向 msgLabel;失败或无手机号返回 null(走全局默认) */
|
|
|
+ private String resolveUserPhone(Long userId) {
|
|
|
+ if (userId == null) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ User u = userMapper.selectById(userId);
|
|
|
+ if (u != null && u.getPhone() != null && !u.getPhone().trim().isEmpty()) {
|
|
|
+ return u.getPhone().trim();
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.warn("查询用户手机号失败 userId={}, error={}", userId, e.getMessage());
|
|
|
}
|
|
|
+ return null;
|
|
|
}
|
|
|
}
|