|
|
@@ -1,15 +1,20 @@
|
|
|
package com.nb.app.assistant.service;
|
|
|
|
|
|
import cn.hutool.core.collection.CollectionUtil;
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
import com.nb.app.assistant.api.bean.DeviceAlarmBean;
|
|
|
import com.nb.app.assistant.api.feign.IAppIphoneClient;
|
|
|
import com.nb.app.assistant.dto.IphoneDeviceDTO;
|
|
|
+import com.nb.app.assistant.service.dto.IphoneDeviceTokenUserDTO;
|
|
|
import com.nb.app.assistant.utils.ApnsUtils;
|
|
|
import org.redisson.api.RSet;
|
|
|
import org.redisson.api.RedissonClient;
|
|
|
+import com.nb.web.api.feign.IDeviceAlarmClient;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.context.annotation.Lazy;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.HashSet;
|
|
|
import java.util.Set;
|
|
|
|
|
|
/**
|
|
|
@@ -23,18 +28,31 @@ public class LocalAppIphoneService implements IAppIphoneClient {
|
|
|
@Autowired
|
|
|
private RedissonClient redissonClient;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ @Lazy
|
|
|
+ private IDeviceAlarmClient deviceAlarmClient;
|
|
|
+
|
|
|
@Autowired
|
|
|
@Lazy
|
|
|
private LocalAppIphoneService self;
|
|
|
|
|
|
public void addDeviceToken(IphoneDeviceDTO source){
|
|
|
- RSet<String> tenantSet = redissonClient.getSet("ios:"+source.getTenantId());
|
|
|
- tenantSet.add(source.getDeviceToken());
|
|
|
+ RSet<IphoneDeviceTokenUserDTO> tenantSet = redissonClient.getSet("ios:"+source.getTenantId());
|
|
|
+ tenantSet.add(IphoneDeviceTokenUserDTO.of(source.getDeviceToken(),source.getUserId(),new Date()));
|
|
|
}
|
|
|
|
|
|
public void removeDeviceToken(IphoneDeviceDTO source){
|
|
|
- RSet<String> tenantSet = redissonClient.getSet("ios:"+source.getTenantId());
|
|
|
- tenantSet.remove(source.getDeviceToken());
|
|
|
+ RSet<IphoneDeviceTokenUserDTO> tenantSet = redissonClient.getSet("ios:"+source.getTenantId());
|
|
|
+ Set<IphoneDeviceTokenUserDTO> iphoneDeviceTokenUserDTOS = tenantSet.readAll();
|
|
|
+ HashSet<IphoneDeviceTokenUserDTO> removeAll = new HashSet<IphoneDeviceTokenUserDTO>();
|
|
|
+ for (IphoneDeviceTokenUserDTO deviceTokenUser : iphoneDeviceTokenUserDTOS) {
|
|
|
+ if(StrUtil.equals(source.getDeviceToken(),deviceTokenUser.getDeviceToken())){
|
|
|
+ removeAll.add(deviceTokenUser);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(CollectionUtil.isNotEmpty(removeAll)){
|
|
|
+ tenantSet.removeAll(removeAll);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@@ -43,13 +61,14 @@ public class LocalAppIphoneService implements IAppIphoneClient {
|
|
|
}
|
|
|
|
|
|
public void sendMsg(String tenantId, DeviceAlarmBean source){
|
|
|
- RSet<String> tenantSet = redissonClient.getSet("ios:"+tenantId);
|
|
|
- Set<String> deviceTokenSet = tenantSet.readAll();
|
|
|
+ RSet<IphoneDeviceTokenUserDTO> tenantSet = redissonClient.getSet("ios:"+tenantId);
|
|
|
+ Set<IphoneDeviceTokenUserDTO> deviceTokenSet = tenantSet.readAll();
|
|
|
if (CollectionUtil.isNotEmpty(deviceTokenSet)) {
|
|
|
deviceTokenSet.parallelStream()
|
|
|
- .forEach(deviceToken->{
|
|
|
+ .forEach(deviceTokenUser->{
|
|
|
try {
|
|
|
- ApnsUtils.sendMsg(deviceToken,source);
|
|
|
+ Long alarmCount = deviceAlarmClient.count(tenantId, deviceTokenUser.getOfflineTime());
|
|
|
+ ApnsUtils.sendMsg(deviceTokenUser.getDeviceToken(),source,alarmCount>99?99:alarmCount);
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
}
|