|
|
@ -30,6 +30,7 @@ import org.springframework.util.Assert; |
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.Arrays; |
|
|
|
import java.util.Arrays; |
|
|
|
import java.util.List; |
|
|
|
import java.util.List; |
|
|
|
|
|
|
|
import java.util.concurrent.ExecutorService; |
|
|
|
import java.util.concurrent.FutureTask; |
|
|
|
import java.util.concurrent.FutureTask; |
|
|
|
import java.util.concurrent.atomic.AtomicReference; |
|
|
|
import java.util.concurrent.atomic.AtomicReference; |
|
|
|
|
|
|
|
|
|
|
@ -42,6 +43,7 @@ public class PushMessageServiceImpl implements IMessageService { |
|
|
|
|
|
|
|
|
|
|
|
private final IPushClient pushClient; |
|
|
|
private final IPushClient pushClient; |
|
|
|
private final BladeLogger logger; |
|
|
|
private final BladeLogger logger; |
|
|
|
|
|
|
|
private final ExecutorService appMessagePushExecutor; |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
@SaveLog(type = MessageConstants.APP_NAME) |
|
|
|
@SaveLog(type = MessageConstants.APP_NAME) |
|
|
@ -87,37 +89,14 @@ public class PushMessageServiceImpl implements IMessageService { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public boolean send(MessagePushRecordEntity request) { |
|
|
|
public boolean send(MessagePushRecordEntity request) { |
|
|
|
PushInfoVO pushInfoVO = new PushInfoVO(); |
|
|
|
String tenantId = Func.isNotEmpty(AuthUtil.getTenantId()) ? AuthUtil.getTenantId() : request.getTenantId(); |
|
|
|
pushInfoVO.setTenantId(Func.isNotEmpty(AuthUtil.getTenantId()) ? AuthUtil.getTenantId() : request.getTenantId()); |
|
|
|
try { |
|
|
|
ArrayList<PlatformType> platformTypes = Lists.newArrayList(PlatformType.Android, PlatformType.IOS); |
|
|
|
return this.sendByUsers(request.getSubject(), request.getContent(), Func.toStrList(",",request.getPusher()),tenantId); |
|
|
|
platformTypes.forEach(platformType -> { |
|
|
|
} |
|
|
|
PushPlatform platform = PushPlatform.newBuilder().addPlatformType(platformType).build(); |
|
|
|
catch (Exception e) { |
|
|
|
R<PushResponse> response; |
|
|
|
throw new ServiceException(e.getMessage()); |
|
|
|
// 安卓推送
|
|
|
|
} |
|
|
|
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; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
@ -125,7 +104,7 @@ public class PushMessageServiceImpl implements IMessageService { |
|
|
|
* @param subject 消息主题 |
|
|
|
* @param subject 消息主题 |
|
|
|
* @param content 消息内容 |
|
|
|
* @param content 消息内容 |
|
|
|
* @param userIds 用户ID列表 |
|
|
|
* @param userIds 用户ID列表 |
|
|
|
* @param tenantId 推送成功标识 |
|
|
|
* @param tenantId 租户ID |
|
|
|
* @return |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public boolean sendByUsers(String subject, String content, List<String> userIds,String tenantId) throws Exception { |
|
|
|
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); |
|
|
|
R<PushResponse> pushResult = pushClient.tenantPush(pushInfoVO); |
|
|
|
return pushResult.isSuccess(); |
|
|
|
return pushResult.isSuccess(); |
|
|
|
}); |
|
|
|
}); |
|
|
|
new Thread(androidPush,"安卓推送").start(); |
|
|
|
appMessagePushExecutor.submit(new Thread(androidPush,"安卓推送")); |
|
|
|
|
|
|
|
|
|
|
|
// IOS推送
|
|
|
|
// IOS推送
|
|
|
|
FutureTask<Boolean> iosPush = new FutureTask<>(() -> { |
|
|
|
FutureTask<Boolean> iosPush = new FutureTask<>(() -> { |
|
|
@ -153,7 +132,7 @@ public class PushMessageServiceImpl implements IMessageService { |
|
|
|
R<PushResponse> pushResult = pushClient.tenantPush(pushInfoVO); |
|
|
|
R<PushResponse> pushResult = pushClient.tenantPush(pushInfoVO); |
|
|
|
return pushResult.isSuccess(); |
|
|
|
return pushResult.isSuccess(); |
|
|
|
}); |
|
|
|
}); |
|
|
|
new Thread(iosPush,"ios推送").start(); |
|
|
|
appMessagePushExecutor.submit(new Thread(iosPush,"ios推送")); |
|
|
|
|
|
|
|
|
|
|
|
return androidPush.get() && iosPush.get(); |
|
|
|
return androidPush.get() && iosPush.get(); |
|
|
|
} |
|
|
|
} |
|
|
|