Commit bd5a21ea by zhangjw

1:新增USER_DEVICE_PUSH_TOKEN 保存用户对应的Push信息 减少每次发送查询token

parent bedaafbd
......@@ -24,8 +24,6 @@ public class UserSocketInfo extends BaseSocketInfo {
private Set<Long> sessionList;
private DeviceTokenParam deviceTokenParam;
private Map<Long, Long> staffIds = new HashMap<>();
public Long getStaffId(Long merchantId) {
......
package com.ym.im.handler;
import com.ym.im.entity.DeviceTokenParam;
import com.ym.im.entity.StaffSocketInfo;
import com.ym.im.entity.UserSocketInfo;
import org.springframework.stereotype.Component;
......@@ -25,6 +26,11 @@ public class ChannelGroupHandler {
*/
public final Map<Long, Map<Long, StaffSocketInfo>> STAFF_GROUP = new ConcurrentHashMap<>();
/**
* 用户推送tokenGroup
*/
public final Map<Long, DeviceTokenParam> USER_DEVICE_PUSH_TOKEN = new ConcurrentHashMap<>();
/**
* 新增商户 客服
......
......@@ -181,11 +181,9 @@ public class StaffSingleChatServiceImpl implements ChatService {
*/
@SneakyThrows
private void pushNotifications(Long userId) {
final UserSocketInfo userSocketInfo = channelGroup.USER_GROUP.get(userId);
if (userSocketInfo != null) {
final DeviceTokenParam deviceTokenParam = userSocketInfo.getDeviceTokenParam();
final DeviceTokenParam deviceTokenParam = channelGroup.USER_DEVICE_PUSH_TOKEN.get(userId);
pushFactory.getService(deviceTokenParam.getDeviceType()).unicast(deviceTokenParam.getDeviceToken());
}
}
......
......@@ -76,8 +76,8 @@ public class UserSingleChatServiceImpl implements ChatService {
Map<String, String> headers = new HashMap<>();
headers.put("token", token);
final AppUser appUser = JsonUtils.json2Obj(HttpClientUtils.doGet(USER_INFO_URL, null, headers), AppUser.class);//获取deviceToken
userSocketInfo.setDeviceTokenParam(new DeviceTokenParam().setDeviceToken(appUser.getDeviceToken()).setDeviceType(appUser.getDeviceType()));
channelGroup.USER_GROUP.put(userId, userSocketInfo);
channelGroup.USER_DEVICE_PUSH_TOKEN.put(userId, new DeviceTokenParam().setDeviceToken(appUser.getDeviceToken()).setDeviceType(appUser.getDeviceType()));
this.restoreBindingRelationship(userId); //恢复历史绑定关系
this.broadcastUserOnline(userId); //通知客服 用户上线
log.info("用户: " + userId + " 上线");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment