Browse Source

# 消息推送规则修改

zhongwei
haungxing 1 year ago
parent
commit
32bf0e1841
  1. 6
      hzims-service/message/src/main/java/com/hnac/hzims/message/config/ThreadPoolConfig.java
  2. 20
      hzims-service/message/src/main/java/com/hnac/hzims/message/controller/MessageController.java
  3. 41
      hzims-service/message/src/main/java/com/hnac/hzims/message/service/impl/PushMessageServiceImpl.java

6
hzims-service/message/src/main/java/com/hnac/hzims/message/config/ThreadPoolConfig.java

@ -18,9 +18,13 @@ public class ThreadPoolConfig {
@Bean @Bean
public ExecutorService logExecutorService() { public ExecutorService logExecutorService() {
return new ThreadPoolExecutor(1, 1, return new ThreadPoolExecutor(2, 5,
0L, TimeUnit.MILLISECONDS, 0L, TimeUnit.MILLISECONDS,
new LinkedBlockingQueue<Runnable>()); new LinkedBlockingQueue<Runnable>());
} }
@Bean
public ExecutorService appMessagePushExecutor() {
return new ThreadPoolExecutor(2, 5, 5L, TimeUnit.SECONDS,new LinkedBlockingQueue<Runnable>());
}
} }

20
hzims-service/message/src/main/java/com/hnac/hzims/message/controller/MessageController.java

@ -7,6 +7,7 @@ import com.hnac.hzims.message.dto.SmsPushDto;
import com.hnac.hzims.message.dto.WsPushDto; import com.hnac.hzims.message.dto.WsPushDto;
import com.hnac.hzims.message.fegin.IPushMsgClient; import com.hnac.hzims.message.fegin.IPushMsgClient;
import com.hnac.hzims.message.service.IMessageService; import com.hnac.hzims.message.service.IMessageService;
import com.hnac.hzims.message.service.IPushMessageService;
import com.hnac.hzims.message.service.impl.MailMessageServiceImpl; import com.hnac.hzims.message.service.impl.MailMessageServiceImpl;
import com.hnac.hzims.message.service.impl.PushMessageServiceImpl; import com.hnac.hzims.message.service.impl.PushMessageServiceImpl;
import com.hnac.hzims.message.service.impl.SmsMessageServiceImpl; import com.hnac.hzims.message.service.impl.SmsMessageServiceImpl;
@ -14,16 +15,16 @@ import com.hnac.hzims.message.service.impl.WebsocketServiceImpl;
import com.hnac.hzims.message.utils.HtmlModule; import com.hnac.hzims.message.utils.HtmlModule;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springblade.core.boot.ctrl.BladeController; import org.springblade.core.boot.ctrl.BladeController;
import org.springblade.core.tool.api.R; import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.Func;
import org.springblade.core.tool.utils.SpringUtil; import org.springblade.core.tool.utils.SpringUtil;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
import java.util.Map; import java.util.Map;
/** /**
@ -79,4 +80,15 @@ public class MessageController extends BladeController {
IMessageService messageService = SpringUtil.getBean(WebsocketServiceImpl.class); IMessageService messageService = SpringUtil.getBean(WebsocketServiceImpl.class);
return messageService.send(wsPushDto); return messageService.send(wsPushDto);
} }
@GetMapping("/sendByUsers")
@ApiOperation("发送APP消息(多人)")
@ApiOperationSupport(order=5)
public R sendByUsers(@ApiParam("消息主题") String subject,
@ApiParam("消息内容") String content,
@ApiParam("用户ID列表") String userIds,
@ApiParam("租户ID") String tenantId) throws Exception {
PushMessageServiceImpl messageService = SpringUtil.getBean(PushMessageServiceImpl.class);
return R.status(messageService.sendByUsers(subject,content, Func.toStrList(",",userIds),tenantId));
}
} }

41
hzims-service/message/src/main/java/com/hnac/hzims/message/service/impl/PushMessageServiceImpl.java

@ -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)
@ -88,36 +90,13 @@ 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();
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推送 catch (Exception e) {
else if(PlatformType.IOS.equals(platformType)) { throw new ServiceException(e.getMessage());
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();
} }

Loading…
Cancel
Save