|
@@ -2,7 +2,6 @@ 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;
|
|
@@ -27,7 +26,7 @@ public class PushMessage implements Serializable {
|
|
|
|
|
|
private String title;
|
|
|
private String content;
|
|
|
- private List<String> toList;
|
|
|
+ private List<String> toList = new ArrayList<>();
|
|
|
//the count of try again. Increase 1 for each failure, maximum times 100
|
|
|
private int tryCount = 0;
|
|
|
|
|
@@ -39,6 +38,11 @@ public class PushMessage implements Serializable {
|
|
|
this.content = content;
|
|
|
}
|
|
|
|
|
|
+ public PushMessage add(String to){
|
|
|
+ this.toList.add(to);
|
|
|
+ return this;
|
|
|
+ }
|
|
|
+
|
|
|
private static PushMessage create(String title, String content) {
|
|
|
return new PushMessage(title, content);
|
|
|
}
|
|
@@ -503,10 +507,16 @@ public class PushMessage implements Serializable {
|
|
|
return create("发布新闻", title);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 检查推送列表总数是否需要拆分,信鸽推送一次最多1000
|
|
|
+ */
|
|
|
public boolean needSplit() {
|
|
|
- return toList != null && toList.size() > ValuePool.PUSH_MAX_SIZE;
|
|
|
+ return Objects.nonNull(toList) && toList.size() > ValuePool.PUSH_MAX_SIZE;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 拆分推送设备列表
|
|
|
+ */
|
|
|
public List<ArrayList<String>> doSplit(final int length) {
|
|
|
List<ArrayList<String>> splits = new ArrayList<>();
|
|
|
int size = toList.size();
|
|
@@ -524,7 +534,7 @@ public class PushMessage implements Serializable {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 同时推送到指定的android和ios设备token
|
|
|
+ * 同时推送到多个设备token
|
|
|
*/
|
|
|
public boolean sendTokenOnPlatform(JmsMessagingTemplate jmsMessagingTemplate, List<PushUserInfo> pushUserInfos) {
|
|
|
try {
|
|
@@ -534,13 +544,11 @@ public class PushMessage implements Serializable {
|
|
|
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 (pushUserInfo.available()) {
|
|
|
+ if (pushUserInfo.isAndroid()) {
|
|
|
+ toAndroid.add(pushUserInfo.getDeviceFlag());
|
|
|
+ } else if (pushUserInfo.isIos()) {
|
|
|
+ toIos.add(pushUserInfo.getDeviceFlag());
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -568,15 +576,13 @@ public class PushMessage implements Serializable {
|
|
|
if (Objects.isNull(pushUserInfo)) {
|
|
|
return false;
|
|
|
}
|
|
|
- Integer deviceModel = pushUserInfo.getDeviceModel();
|
|
|
- String deviceFlag = pushUserInfo.getDeviceFlag();
|
|
|
- if(Objects.isNull(deviceModel) || StrUtil.isBlank(deviceFlag)){
|
|
|
+ if(!pushUserInfo.available()){
|
|
|
return false;
|
|
|
}
|
|
|
- this.setToList(Arrays.asList(deviceFlag));
|
|
|
- if (1 == deviceModel) {
|
|
|
+ this.add(pushUserInfo.getDeviceFlag());
|
|
|
+ if (pushUserInfo.isAndroid()) {
|
|
|
jmsMessagingTemplate.send(ValuePool.PUSH_QUEUE_ANDROID_TOKEN, new GenericMessage<>(this));
|
|
|
- } else if (2 == deviceModel) {
|
|
|
+ } else if (pushUserInfo.isIos()) {
|
|
|
jmsMessagingTemplate.send(ValuePool.PUSH_QUEUE_IOS_TOKEN, new GenericMessage<>(this));
|
|
|
} else {
|
|
|
return false;
|