|
|
|
@ -30,6 +30,7 @@ import org.springframework.util.Assert;
|
|
|
|
|
import java.util.ArrayList; |
|
|
|
|
import java.util.Arrays; |
|
|
|
|
import java.util.List; |
|
|
|
|
import java.util.concurrent.ExecutorService; |
|
|
|
|
import java.util.concurrent.FutureTask; |
|
|
|
|
import java.util.concurrent.atomic.AtomicReference; |
|
|
|
|
|
|
|
|
@ -42,6 +43,7 @@ public class PushMessageServiceImpl implements IMessageService {
|
|
|
|
|
|
|
|
|
|
private final IPushClient pushClient; |
|
|
|
|
private final BladeLogger logger; |
|
|
|
|
private final ExecutorService appMessagePushExecutor; |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
@SaveLog(type = MessageConstants.APP_NAME) |
|
|
|
@ -87,37 +89,14 @@ public class PushMessageServiceImpl implements IMessageService {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public boolean send(MessagePushRecordEntity request) { |
|
|
|
|
PushInfoVO pushInfoVO = new PushInfoVO(); |
|
|
|
|
pushInfoVO.setTenantId(Func.isNotEmpty(AuthUtil.getTenantId()) ? AuthUtil.getTenantId() : request.getTenantId()); |
|
|
|
|
ArrayList<PlatformType> platformTypes = Lists.newArrayList(PlatformType.Android, PlatformType.IOS); |
|
|
|
|
platformTypes.forEach(platformType -> { |
|
|
|
|
PushPlatform platform = PushPlatform.newBuilder().addPlatformType(platformType).build(); |
|
|
|
|
R<PushResponse> response; |
|
|
|
|
// 安卓推送
|
|
|
|
|
if(PlatformType.Android.equals(platformType)) { |
|
|
|
|
PushAudience pushAudience = PushAudience.newBuilder().addPushAudienceType(PushAudienceType.TAG, Lists.newArrayList(request.getPusher())).build(); |
|
|
|
|
PushInfo pushInfo = new PushInfo("ops-push-android", request.getSubject(), request.getContent(), |
|
|
|
|
"", null, platform, pushAudience); |
|
|
|
|
pushInfoVO.setPushInfo(pushInfo); |
|
|
|
|
response = pushClient.tenantPush(pushInfoVO); |
|
|
|
|
} |
|
|
|
|
// IOS推送
|
|
|
|
|
else if(PlatformType.IOS.equals(platformType)) { |
|
|
|
|
PushAudience pushAudience = PushAudience.newBuilder().addPushAudienceType(PushAudienceType.TAG, Lists.newArrayList(request.getPusher())).build(); |
|
|
|
|
PushInfo pushInfo = new PushInfo("ops-push-ios", request.getSubject(), request.getContent(), |
|
|
|
|
"", null, platform, pushAudience); |
|
|
|
|
pushInfoVO.setPushInfo(pushInfo); |
|
|
|
|
response = pushClient.tenantPush(pushInfoVO); |
|
|
|
|
} else { |
|
|
|
|
response = null; |
|
|
|
|
} |
|
|
|
|
Assert.isTrue(ObjectUtil.isNotEmpty(response) && response.isSuccess(),() -> { |
|
|
|
|
logger.error("hzims-message:PushMessageServiceImpl:send", "请求参数为:"+JSON.toJSONString(pushInfoVO)+"错误信息为:"+response.getMsg()); |
|
|
|
|
throw new ServiceException(response.getMsg()); |
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
|
return true; |
|
|
|
|
public boolean send(MessagePushRecordEntity request) { |
|
|
|
|
String tenantId = Func.isNotEmpty(AuthUtil.getTenantId()) ? AuthUtil.getTenantId() : request.getTenantId(); |
|
|
|
|
try { |
|
|
|
|
return this.sendByUsers(request.getSubject(), request.getContent(), Func.toStrList(",",request.getPusher()),tenantId); |
|
|
|
|
} |
|
|
|
|
catch (Exception e) { |
|
|
|
|
throw new ServiceException(e.getMessage()); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
@ -125,7 +104,7 @@ public class PushMessageServiceImpl implements IMessageService {
|
|
|
|
|
* @param subject 消息主题 |
|
|
|
|
* @param content 消息内容 |
|
|
|
|
* @param userIds 用户ID列表 |
|
|
|
|
* @param tenantId 推送成功标识 |
|
|
|
|
* @param tenantId 租户ID |
|
|
|
|
* @return |
|
|
|
|
*/ |
|
|
|
|
public boolean sendByUsers(String subject, String content, List<String> userIds,String tenantId) throws Exception { |
|
|
|
@ -140,7 +119,7 @@ public class PushMessageServiceImpl implements IMessageService {
|
|
|
|
|
R<PushResponse> pushResult = pushClient.tenantPush(pushInfoVO); |
|
|
|
|
return pushResult.isSuccess(); |
|
|
|
|
}); |
|
|
|
|
new Thread(androidPush,"安卓推送").start(); |
|
|
|
|
appMessagePushExecutor.submit(new Thread(androidPush,"安卓推送")); |
|
|
|
|
|
|
|
|
|
// IOS推送
|
|
|
|
|
FutureTask<Boolean> iosPush = new FutureTask<>(() -> { |
|
|
|
@ -153,7 +132,7 @@ public class PushMessageServiceImpl implements IMessageService {
|
|
|
|
|
R<PushResponse> pushResult = pushClient.tenantPush(pushInfoVO); |
|
|
|
|
return pushResult.isSuccess(); |
|
|
|
|
}); |
|
|
|
|
new Thread(iosPush,"ios推送").start(); |
|
|
|
|
appMessagePushExecutor.submit(new Thread(iosPush,"ios推送")); |
|
|
|
|
|
|
|
|
|
return androidPush.get() && iosPush.get(); |
|
|
|
|
} |
|
|
|
|