|
|
@@ -3,6 +3,7 @@ package cn.iocoder.yudao.module.system.service.appnotify;
|
|
|
import cn.iocoder.yudao.module.system.dal.dataobject.notify.NotifyMessageDO;
|
|
|
import cn.iocoder.yudao.module.system.service.notify.NotifyMessageService;
|
|
|
import cn.iocoder.yudao.module.system.service.notify.NotifySendService;
|
|
|
+import cn.iocoder.yudao.module.system.service.user.AdminUserService;
|
|
|
import com.aliyun.auth.credentials.utils.ParameterHelper;
|
|
|
import com.aliyuncs.DefaultAcsClient;
|
|
|
import com.aliyuncs.IAcsClient;
|
|
|
@@ -17,8 +18,7 @@ import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.validation.annotation.Validated;
|
|
|
|
|
|
-import java.util.Date;
|
|
|
-import java.util.Map;
|
|
|
+import java.util.*;
|
|
|
|
|
|
/**
|
|
|
* App消息推送服务实现类(阿里云推送)
|
|
|
@@ -92,14 +92,16 @@ public class AppNotifySendServiceImpl implements AppNotifySendService {
|
|
|
private NotifySendService notifySendService;
|
|
|
@Autowired
|
|
|
private NotifyMessageService notifyMessageService;
|
|
|
+ @Autowired
|
|
|
+ private AdminUserService adminUserService;
|
|
|
|
|
|
|
|
|
@Override
|
|
|
public Long sendSingleAppNotifyToAdmin(Long userId, String templateCode, Map<String, Object> templateParams) {
|
|
|
// 1. 第一步:根据用户ID查询绑定的设备ID(需替换为业务系统实际查询逻辑)
|
|
|
// 说明:设备ID是App端集成阿里云推送SDK后上报的唯一设备标识
|
|
|
- String deviceId = getDeviceIdByUserId(userId);
|
|
|
- if (deviceId.isEmpty()) {
|
|
|
+ Set<String> deviceIds = getDeviceIdByUserId(userId);
|
|
|
+ if (deviceIds.isEmpty()) {
|
|
|
log.warn("发送单用户App通知失败:用户{}未绑定任何设备ID,无法推送", userId);
|
|
|
return null;
|
|
|
}
|
|
|
@@ -112,19 +114,19 @@ public class AppNotifySendServiceImpl implements AppNotifySendService {
|
|
|
IAcsClient client = createAcsClient();
|
|
|
|
|
|
// 4. 第四步:构建单设备推送请求(封装Android/iOS双端配置)
|
|
|
- PushRequest pushRequest = buildSingleDevicePushRequest(deviceId, "博士安全", notifyMessage.getTemplateContent());
|
|
|
// PushRequest pushRequest = buildAllDevicePushRequest("博士安全", notifyMessage.getTemplateContent());
|
|
|
-
|
|
|
- // 5. 第五步:发送推送请求,调用阿里云Push接口
|
|
|
- PushResponse response = client.getAcsResponse(pushRequest);
|
|
|
-
|
|
|
- // 6. 第六步:解析返回结果,记录日志并返回消息ID
|
|
|
- String requestId = response.getRequestId(); // 阿里云请求唯一标识(用于排查问题)
|
|
|
- String messageId = response.getMessageId(); // 推送消息唯一标识(用于查询推送状态)
|
|
|
- log.info("单用户App推送成功:userId={}, requestId={}, messageId={}", userId, requestId, messageId);
|
|
|
-
|
|
|
+ for (String deviceId : deviceIds) {
|
|
|
+ PushRequest pushRequest = buildSingleDevicePushRequest(deviceId, "博士安全", notifyMessage.getTemplateContent());
|
|
|
+ // 5. 第五步:发送推送请求,调用阿里云Push接口
|
|
|
+ PushResponse response = client.getAcsResponse(pushRequest);
|
|
|
+
|
|
|
+ // 6. 第六步:解析返回结果,记录日志并返回消息ID
|
|
|
+ String requestId = response.getRequestId(); // 阿里云请求唯一标识(用于排查问题)
|
|
|
+ String messageId = response.getMessageId(); // 推送消息唯一标识(用于查询推送状态)
|
|
|
+ log.info("单用户App推送成功:userId={}, requestId={}, messageId={}", userId, requestId, messageId);
|
|
|
+ }
|
|
|
// 注意:若messageId是字符串格式(如含字母),需调整返回类型为String
|
|
|
- return Long.parseLong(messageId);
|
|
|
+ return 1L;
|
|
|
} catch (ServerException e) {
|
|
|
// 服务端异常:阿里云接口返回错误(如AppKey无效、额度不足)
|
|
|
log.error("单用户App推送失败(阿里云服务端错误):userId={}, templateCode={}", userId, templateCode, e);
|
|
|
@@ -317,13 +319,15 @@ public class AppNotifySendServiceImpl implements AppNotifySendService {
|
|
|
* @param userId 业务系统用户ID
|
|
|
* @return 设备ID(示例返回随机生成的模拟值)
|
|
|
*/
|
|
|
- private String getDeviceIdByUserId(Long userId) {
|
|
|
+ private Set<String> getDeviceIdByUserId(Long userId) {
|
|
|
// 示例:模拟返回设备ID(实际项目中需替换为真实查询逻辑)
|
|
|
- return "f92564ccc1a84aebaf58a796091a66a2";
|
|
|
+ String deviceId = adminUserService.getUser(userId).getDeviceId();
|
|
|
+ return new TreeSet<>(new ArrayList<>(Arrays.asList(deviceId.split(","))));
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 通过站内信获取相同发送信息
|
|
|
+ *
|
|
|
* @return
|
|
|
*/
|
|
|
private NotifyMessageDO getMessageByNotify(Long userId, String templateCode, Map<String, Object> templateParams) {
|
|
|
@@ -336,5 +340,12 @@ public class AppNotifySendServiceImpl implements AppNotifySendService {
|
|
|
return notifyMessage;
|
|
|
}
|
|
|
|
|
|
+ public static void main(String[] args) {
|
|
|
+ String aa = "";
|
|
|
+ TreeSet<String> strings = new TreeSet<>(new ArrayList<>(Arrays.asList(aa.split(","))));
|
|
|
+ System.out.println(strings);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
}
|