|
@@ -2,6 +2,7 @@ package cn.com.ty.lift.common.model;
|
|
|
|
|
|
import cn.com.ty.lift.common.utils.ValuePool;
|
|
|
import cn.hutool.core.collection.IterUtil;
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
import lombok.Data;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.jms.core.JmsMessagingTemplate;
|
|
@@ -10,11 +11,7 @@ import org.springframework.messaging.support.GenericMessage;
|
|
|
import java.io.Serializable;
|
|
|
import java.time.LocalDate;
|
|
|
import java.time.LocalDateTime;
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
-import java.util.Objects;
|
|
|
-import java.util.stream.Collectors;
|
|
|
+import java.util.*;
|
|
|
|
|
|
/**
|
|
|
* 推送消息
|
|
@@ -537,21 +534,25 @@ public class PushMessage implements Serializable {
|
|
|
if(IterUtil.isEmpty(pushUserInfos)){
|
|
|
return false;
|
|
|
}
|
|
|
- Map<Integer, List<PushUserInfo>> collect = pushUserInfos.stream().collect(Collectors.groupingBy(PushUserInfo::getDeviceModel));
|
|
|
- List<PushUserInfo> pushAndroids = collect.get(1);
|
|
|
- List<PushUserInfo> pushIos = collect.get(2);
|
|
|
- if(IterUtil.isNotEmpty(pushAndroids)){
|
|
|
- List<String> toAndroid = pushAndroids.stream().map(PushUserInfo::getDeviceFlag).filter(Objects::nonNull).distinct().collect(Collectors.toList());
|
|
|
- if (IterUtil.isNotEmpty(toAndroid)) {
|
|
|
- this.setToList(toAndroid);
|
|
|
- jmsMessagingTemplate.send(ValuePool.QUEUE_ANDROID_TOKEN, new GenericMessage<>(this));
|
|
|
- }
|
|
|
- }else if (IterUtil.isNotEmpty(pushIos)) {
|
|
|
- List<String> toIos = pushIos.stream().map(PushUserInfo::getDeviceFlag).filter(Objects::nonNull).distinct().collect(Collectors.toList());
|
|
|
- if(IterUtil.isNotEmpty(toIos)){
|
|
|
- this.setToList(toIos);
|
|
|
- jmsMessagingTemplate.send(ValuePool.QUEUE_IOS_TOKEN, new GenericMessage<>(this));
|
|
|
+ Set<String> toAndroid = new HashSet<>();
|
|
|
+ Set<String> toIos = new HashSet<>();
|
|
|
+ for (PushUserInfo pushUserInfo : pushUserInfos) {
|
|
|
+ Integer deviceModel = pushUserInfo.getDeviceModel();
|
|
|
+ String deviceFlag = pushUserInfo.getDeviceFlag();
|
|
|
+ if (Objects.nonNull(deviceModel) && StrUtil.isNotBlank(deviceFlag)) {
|
|
|
+ if (1 == deviceModel) {
|
|
|
+ toAndroid.add(deviceFlag);
|
|
|
+ } else if (2 == deviceModel) {
|
|
|
+ toIos.add(deviceFlag);
|
|
|
+ }
|
|
|
}
|
|
|
+ }
|
|
|
+ if (IterUtil.isNotEmpty(toAndroid)) {
|
|
|
+ this.setToList(new ArrayList<>(toAndroid));
|
|
|
+ jmsMessagingTemplate.send(ValuePool.QUEUE_ANDROID_TOKEN, new GenericMessage<>(this));
|
|
|
+ } else if (IterUtil.isNotEmpty(toIos)) {
|
|
|
+ this.setToList(new ArrayList<>(toIos));
|
|
|
+ jmsMessagingTemplate.send(ValuePool.QUEUE_IOS_TOKEN, new GenericMessage<>(this));
|
|
|
} else {
|
|
|
return false;
|
|
|
}
|
|
@@ -577,44 +578,4 @@ public class PushMessage implements Serializable {
|
|
|
return false;
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- /**
|
|
|
- * 只推送到android平台的指定设备token
|
|
|
- *
|
|
|
- * @param jmsMessagingTemplate jms
|
|
|
- * @param toList 推到安卓平台的设备token
|
|
|
- */
|
|
|
- public boolean sendTokenOnAndroid(JmsMessagingTemplate jmsMessagingTemplate, List<String> toList) {
|
|
|
- try {
|
|
|
- if (IterUtil.isEmpty(toList)) {
|
|
|
- return false;
|
|
|
- }
|
|
|
- this.setToList(toList.stream().filter(Objects::nonNull).distinct().collect(Collectors.toList()));
|
|
|
- jmsMessagingTemplate.send(ValuePool.QUEUE_ANDROID_TOKEN, new GenericMessage<>(this));
|
|
|
- return true;
|
|
|
- } catch (Exception e) {
|
|
|
- log.error("Failed to Send pushMessage to ANDROID_TOKEN Message Queue: ", e);
|
|
|
- return false;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 只推送到ios的指定设备token
|
|
|
- * @param jmsMessagingTemplate
|
|
|
- * @param toList ios设备token
|
|
|
- * @return
|
|
|
- */
|
|
|
- public boolean sendTokenOnIos(JmsMessagingTemplate jmsMessagingTemplate, List<String> toList) {
|
|
|
- try {
|
|
|
- if (IterUtil.isEmpty(toList)) {
|
|
|
- return false;
|
|
|
- }
|
|
|
- this.setToList(toList.stream().filter(Objects::nonNull).distinct().collect(Collectors.toList()));
|
|
|
- jmsMessagingTemplate.send(ValuePool.QUEUE_IOS_TOKEN, new GenericMessage<>(this));
|
|
|
- return true;
|
|
|
- } catch (Exception e) {
|
|
|
- log.error("Failed to Send pushMessage to IOS_TOKEN Message Queue: ", e);
|
|
|
- return false;
|
|
|
- }
|
|
|
- }
|
|
|
}
|