|
|
|
@ -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<MessagePushRec
|
|
|
|
|
/** |
|
|
|
|
* 推送APP即时消息 |
|
|
|
|
* @param record 消息记录 |
|
|
|
|
* @param isEmergent 是否紧急 若紧急则直接推送 若不紧急则存入redis进行消费 |
|
|
|
|
* @return 推送结果 |
|
|
|
|
*/ |
|
|
|
|
private Boolean sendAppImmediatelyMsg(MessagePushRecordEntity record) { |
|
|
|
|
private Boolean sendAppImmediatelyMsg(MessagePushRecordEntity record, boolean isEmergent) { |
|
|
|
|
if(this.saveOrUpdate(record)) { |
|
|
|
|
PushMessageServiceImpl pushService = SpringUtil.getBean(PushMessageServiceImpl.class); |
|
|
|
|
if(pushService.send(record)) { |
|
|
|
|
record.setStatus(MessageConstants.PUSH_SUCCESS); |
|
|
|
|
record.setPushTime(LocalDateTime.now()); |
|
|
|
|
if(isEmergent) { |
|
|
|
|
ArrayList<String> pushers = Lists.newArrayList(record.getPusher().toString()); |
|
|
|
|
R<PushResponse> androidPush = pushService.sendAndroidMsg(record.getSubject(), record.getContent(), pushers, CommonConstant.TENANT_ID); |
|
|
|
|
R<PushResponse> 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<MessagePushRec
|
|
|
|
|
}); |
|
|
|
|
switch(record.getType()) { |
|
|
|
|
case MessageConstants.APP_PUSH: |
|
|
|
|
return this.sendAppImmediatelyMsg(record); |
|
|
|
|
return this.sendAppImmediatelyMsg(record,false); |
|
|
|
|
case MessageConstants.WX_PUSH: |
|
|
|
|
break; |
|
|
|
|
case MessageConstants.WS_PUSH: |
|
|
|
@ -380,29 +405,14 @@ public class MessagePushRecordServiceImpl extends BaseServiceImpl<MessagePushRec
|
|
|
|
|
@Override |
|
|
|
|
public Boolean sendAppAndWsMsgByUsers(BusinessMessageDTO request) { |
|
|
|
|
// 保存消息记录
|
|
|
|
|
List<MessagePushRecordEntity> 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<MessagePushRecordEntity> 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<MessagePushRec
|
|
|
|
|
} |
|
|
|
|
this.updateById(record); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
}); |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private List<MessagePushRecordEntity> 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 |
|
|
|
|