diff --git a/hzims-service-api/message-api/src/main/java/com/hnac/hzims/message/dto/BusinessMessageDTO.java b/hzims-service-api/message-api/src/main/java/com/hnac/hzims/message/dto/BusinessMessageDTO.java index 17e566b..ba52449 100644 --- a/hzims-service-api/message-api/src/main/java/com/hnac/hzims/message/dto/BusinessMessageDTO.java +++ b/hzims-service-api/message-api/src/main/java/com/hnac/hzims/message/dto/BusinessMessageDTO.java @@ -66,4 +66,7 @@ public class BusinessMessageDTO implements Serializable { @ApiModelProperty(value = "租户ID") private String tenantId; + + @ApiModelProperty(value = "APP推送是否紧急") + private boolean isEmergent = false; } diff --git a/hzims-service/message/src/main/java/com/hnac/hzims/message/service/impl/MessagePushRecordServiceImpl.java b/hzims-service/message/src/main/java/com/hnac/hzims/message/service/impl/MessagePushRecordServiceImpl.java index 34048a1..ad2b1dd 100644 --- a/hzims-service/message/src/main/java/com/hnac/hzims/message/service/impl/MessagePushRecordServiceImpl.java +++ b/hzims-service/message/src/main/java/com/hnac/hzims/message/service/impl/MessagePushRecordServiceImpl.java @@ -11,6 +11,7 @@ import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; import com.baomidou.mybatisplus.core.toolkit.IdWorker; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.google.common.collect.Lists; +import com.hnac.hzims.common.constant.CommonConstant; import com.hnac.hzims.common.utils.CacheUtil; import com.hnac.hzims.message.MessageConstants; import com.hnac.hzims.message.config.MessageFactory; @@ -24,6 +25,8 @@ import com.hnac.hzims.message.service.IMessagePushRecordService; import com.hnac.hzims.message.service.IMessageService; import com.hnac.hzims.message.vo.UnreadMessageVO; import com.hnac.hzims.message.vo.msgpushrecord.*; +import com.hnac.hzinfo.core.push.model.PushResponse; +import com.xxl.job.core.log.XxlJobLogger; import io.minio.messages.Item; import lombok.AllArgsConstructor; import lombok.RequiredArgsConstructor; @@ -324,17 +327,39 @@ public class MessagePushRecordServiceImpl extends BaseServiceImpl pushers = Lists.newArrayList(record.getPusher().toString()); + R androidPush = pushService.sendAndroidMsg(record.getSubject(), record.getContent(), pushers, CommonConstant.TENANT_ID); + R iosPush = pushService.sendIOSMsg(record.getSubject(), record.getContent(), pushers, CommonConstant.TENANT_ID); + String faultResult = ""; + if(!androidPush.isSuccess()) { + record.setStatus(MessageConstants.PUSH_FAILED); + faultResult += "ANDROID消息推送失败,推送结果为:"+androidPush.getMsg()+";"; + } + if(!iosPush.isSuccess()) { + record.setStatus(MessageConstants.PUSH_FAILED); + faultResult += "IOS消息推送失败,推送结果为:"+androidPush.getMsg()+";"; + } + else { + record.setStatus(MessageConstants.PUSH_SUCCESS); + } + record.setFaultResult(faultResult); + this.updateById(record); } else { - record.setStatus(MessageConstants.PUSH_FAILED); + if(pushService.send(record)) { + record.setStatus(MessageConstants.PUSH_SUCCESS); + record.setPushTime(LocalDateTime.now()); + } + else { + record.setStatus(MessageConstants.PUSH_FAILED); + } } this.updateById(record); } @@ -364,7 +389,7 @@ public class MessagePushRecordServiceImpl extends BaseServiceImpl pushRecords = Func.toLongList(request.getUserIds()).stream().flatMap(userId -> { - long messageId = IdWorker.getId(); - return Lists.newArrayList(MessageConstants.APP_PUSH, MessageConstants.WS_PUSH).stream().map(messageType -> { - MessagePushRecordEntity record = BeanUtil.copy(request, MessagePushRecordEntity.class); - record.setDeptName(Func.isNotEmpty(record.getDeptName()) ? record.getDeptName() : this.getDeptNameById(record.getDeptId())); - record.setMessageId(messageId); - record.setPusher(userId.toString()); - record.setPusherName(Optional.ofNullable(UserCache.getUser(userId)).map(User::getName).orElse(null)); - record.setPushType(MessageConstants.IMMEDIATELY); - record.setAccount(userId.toString()); - record.setPlanTime(LocalDateTime.now()); - record.setType(messageType); - record.setCreateDept(record.getDeptId()); - record.setStatus(MessageConstants.NOT_PUSH); - return record; - }); - }).collect(Collectors.toList()); + List pushRecords = this.convert(request); if(this.saveBatch(pushRecords)) { // 推送消息 WebsocketServiceImpl wsMessageService = SpringUtil.getBean(WebsocketServiceImpl.class); pushRecords.forEach(record -> { if(MessageConstants.APP_PUSH.equals(record.getType())) { // APP消息存入redis中进行消费 + this.sendAppImmediatelyMsg(record,request.isEmergent()); redisTemplate.opsForList().leftPush(appPushRedisKey.concat(":").concat(record.getPusher()), record); } else if (MessageConstants.WS_PUSH.equals(record.getType())) { // WEB消息调用接口直接进行推送 @@ -415,13 +425,32 @@ public class MessagePushRecordServiceImpl extends BaseServiceImpl convert(BusinessMessageDTO request) { + return Func.toLongList(request.getUserIds()).stream().flatMap(userId -> { + long messageId = IdWorker.getId(); + return Lists.newArrayList(MessageConstants.APP_PUSH, MessageConstants.WS_PUSH).stream().map(messageType -> { + MessagePushRecordEntity record = BeanUtil.copy(request, MessagePushRecordEntity.class); + record.setDeptName(Func.isNotEmpty(record.getDeptName()) ? record.getDeptName() : this.getDeptNameById(record.getDeptId())); + record.setMessageId(messageId); + record.setPusher(userId.toString()); + record.setPusherName(Optional.ofNullable(UserCache.getUser(userId)).map(User::getName).orElse(null)); + record.setPushType(MessageConstants.IMMEDIATELY); + record.setAccount(userId.toString()); + record.setPlanTime(LocalDateTime.now()); + record.setType(messageType); + record.setCreateDept(record.getDeptId()); + record.setStatus(MessageConstants.NOT_PUSH); + return record; + }); + }).collect(Collectors.toList()); + } + /** * 根据机构ID获取机构名称 * @param deptId 机构ID diff --git a/hzims-service/message/src/main/java/com/hnac/hzims/message/service/impl/PushMessageServiceImpl.java b/hzims-service/message/src/main/java/com/hnac/hzims/message/service/impl/PushMessageServiceImpl.java index 79ee3ed..4d7a943 100644 --- a/hzims-service/message/src/main/java/com/hnac/hzims/message/service/impl/PushMessageServiceImpl.java +++ b/hzims-service/message/src/main/java/com/hnac/hzims/message/service/impl/PushMessageServiceImpl.java @@ -102,25 +102,7 @@ public class PushMessageServiceImpl implements IMessageService { return Func.isNotEmpty(pushResult); } - /** - * 发送APP消息(多人) - * @param subject 消息主题 - * @param content 消息内容 - * @param userIds 用户ID列表 - * @param tenantId 租户ID - * @return - */ -// public boolean sendByUsers(String subject, String content, List userIds,String tenantId) throws Exception { -// // 安卓推送 -// FutureTask androidPush = new FutureTask<>(() -> this.sendAndroidMsg(subject,content,userIds,tenantId)); -// appMessagePushExecutor.submit(new Thread(androidPush,"安卓推送")); -// -// // IOS推送 -// FutureTask iosPush = new FutureTask<>(() -> this.sendIOSMsg(subject,content,userIds,tenantId)); -// appMessagePushExecutor.submit(new Thread(iosPush,"ios推送")); -// -// return androidPush.get() && iosPush.get(); -// } + /** * 发送APP安卓消息