|
|
@ -26,15 +26,23 @@ import com.hnac.hzims.message.vo.UnreadMessageVO; |
|
|
|
import com.hnac.hzims.message.vo.msgpushrecord.*; |
|
|
|
import com.hnac.hzims.message.vo.msgpushrecord.*; |
|
|
|
import io.minio.messages.Item; |
|
|
|
import io.minio.messages.Item; |
|
|
|
import lombok.AllArgsConstructor; |
|
|
|
import lombok.AllArgsConstructor; |
|
|
|
|
|
|
|
import lombok.RequiredArgsConstructor; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.springblade.core.log.exception.ServiceException; |
|
|
|
import org.springblade.core.log.exception.ServiceException; |
|
|
|
import org.springblade.core.mp.base.BaseServiceImpl; |
|
|
|
import org.springblade.core.mp.base.BaseServiceImpl; |
|
|
|
import com.hnac.hzims.common.utils.Condition; |
|
|
|
import com.hnac.hzims.common.utils.Condition; |
|
|
|
import org.springblade.core.mp.support.Query; |
|
|
|
import org.springblade.core.mp.support.Query; |
|
|
|
import org.springblade.core.secure.utils.AuthUtil; |
|
|
|
import org.springblade.core.secure.utils.AuthUtil; |
|
|
|
|
|
|
|
import org.springblade.core.tool.api.R; |
|
|
|
|
|
|
|
import org.springblade.core.tool.utils.BeanUtil; |
|
|
|
import org.springblade.core.tool.utils.Func; |
|
|
|
import org.springblade.core.tool.utils.Func; |
|
|
|
import org.springblade.core.tool.utils.SpringUtil; |
|
|
|
import org.springblade.core.tool.utils.SpringUtil; |
|
|
|
import org.springblade.system.cache.DictCache; |
|
|
|
import org.springblade.system.cache.DictCache; |
|
|
|
|
|
|
|
import org.springblade.system.feign.ISysClient; |
|
|
|
|
|
|
|
import org.springblade.system.user.cache.UserCache; |
|
|
|
|
|
|
|
import org.springblade.system.user.entity.User; |
|
|
|
|
|
|
|
import org.springframework.beans.factory.annotation.Value; |
|
|
|
|
|
|
|
import org.springframework.data.redis.core.RedisTemplate; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
import org.springframework.util.Assert; |
|
|
|
import org.springframework.util.Assert; |
|
|
@ -43,15 +51,20 @@ import javax.validation.Valid; |
|
|
|
import java.time.*; |
|
|
|
import java.time.*; |
|
|
|
import java.time.format.DateTimeFormatter; |
|
|
|
import java.time.format.DateTimeFormatter; |
|
|
|
import java.util.*; |
|
|
|
import java.util.*; |
|
|
|
|
|
|
|
import java.util.concurrent.FutureTask; |
|
|
|
import java.util.stream.Collectors; |
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
|
|
|
|
@Service |
|
|
|
@Service |
|
|
|
@AllArgsConstructor |
|
|
|
@RequiredArgsConstructor |
|
|
|
@Slf4j |
|
|
|
@Slf4j |
|
|
|
public class MessagePushRecordServiceImpl extends BaseServiceImpl<MessagePushRecordMapper, MessagePushRecordEntity> implements IMessagePushRecordService { |
|
|
|
public class MessagePushRecordServiceImpl extends BaseServiceImpl<MessagePushRecordMapper, MessagePushRecordEntity> implements IMessagePushRecordService { |
|
|
|
|
|
|
|
|
|
|
|
private final MprNoAurhScopeMapper noAurhScopeMapper; |
|
|
|
private final MprNoAurhScopeMapper noAurhScopeMapper; |
|
|
|
private final IMessageService smsMessageService; |
|
|
|
private final IMessageService smsMessageService; |
|
|
|
|
|
|
|
private final ISysClient sysClient; |
|
|
|
|
|
|
|
private final RedisTemplate redisTemplate; |
|
|
|
|
|
|
|
@Value("${hzims.message.redis-key.app-push}") |
|
|
|
|
|
|
|
private String appPushRedisKey; |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public List<MessagePushRecordEntity> list(MessagePushRecordEntity request) { |
|
|
|
public List<MessagePushRecordEntity> list(MessagePushRecordEntity request) { |
|
|
@ -94,14 +107,13 @@ public class MessagePushRecordServiceImpl extends BaseServiceImpl<MessagePushRec |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* @return java.lang.Boolean 推送解雇 |
|
|
|
* @return java.lang.Boolean 推送结果 |
|
|
|
* @Author hx |
|
|
|
* @Author hx |
|
|
|
* @Description 保存并推送消息 |
|
|
|
* @Description 保存并推送消息 |
|
|
|
* @Date 2023/4/12 10:23 |
|
|
|
* @Date 2023/4/12 10:23 |
|
|
|
* @Param [request] 消息记录 |
|
|
|
* @Param [request] 消息记录 |
|
|
|
**/ |
|
|
|
**/ |
|
|
|
@Override |
|
|
|
@Override |
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
|
|
|
|
public Boolean saveAndSend(MessagePushRecordEntity request) { |
|
|
|
public Boolean saveAndSend(MessagePushRecordEntity request) { |
|
|
|
LocalDateTime now = LocalDateTime.now(); |
|
|
|
LocalDateTime now = LocalDateTime.now(); |
|
|
|
request.setStatus(MessageConstants.NOT_PUSH); |
|
|
|
request.setStatus(MessageConstants.NOT_PUSH); |
|
|
@ -109,10 +121,7 @@ public class MessagePushRecordServiceImpl extends BaseServiceImpl<MessagePushRec |
|
|
|
request.setPlanTime(now); |
|
|
|
request.setPlanTime(now); |
|
|
|
request.setPushTime(now); |
|
|
|
request.setPushTime(now); |
|
|
|
// 立即推送消息
|
|
|
|
// 立即推送消息
|
|
|
|
if (this.save(request) && Func.isNotEmpty(request.getId())) { |
|
|
|
return this.sendImmediatelyMSg(request); |
|
|
|
return this.send(request.getId()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
throw new ServiceException("保存消息失败!"); |
|
|
|
|
|
|
|
} else if (MessageConstants.PLAN.equals(request.getPushType())) { |
|
|
|
} else if (MessageConstants.PLAN.equals(request.getPushType())) { |
|
|
|
return this.save(request); |
|
|
|
return this.save(request); |
|
|
|
} else { |
|
|
|
} else { |
|
|
@ -296,19 +305,131 @@ public class MessagePushRecordServiceImpl extends BaseServiceImpl<MessagePushRec |
|
|
|
public Boolean sendSmsImmediatelyMsg(MessagePushRecordEntity record) { |
|
|
|
public Boolean sendSmsImmediatelyMsg(MessagePushRecordEntity record) { |
|
|
|
// 完善推送Account
|
|
|
|
// 完善推送Account
|
|
|
|
record.setAccount(smsMessageService.getAccountByPusher(Long.parseLong(record.getPusher()),record.getType())); |
|
|
|
record.setAccount(smsMessageService.getAccountByPusher(Long.parseLong(record.getPusher()),record.getType())); |
|
|
|
if(this.save(record)) { |
|
|
|
SmsMessageServiceImpl smsService = SpringUtil.getBean(SmsMessageServiceImpl.class); |
|
|
|
if(smsMessageService.send(record)) { |
|
|
|
if(this.saveOrUpdate(record)) { |
|
|
|
this.update( |
|
|
|
R sendResult = smsService.sendSmsByRecord(record); |
|
|
|
Wrappers.<MessagePushRecordEntity>lambdaUpdate() |
|
|
|
if(sendResult.isSuccess()) { |
|
|
|
.set(MessagePushRecordEntity::getStatus,MessageConstants.PUSH_SUCCESS) |
|
|
|
record.setStatus(MessageConstants.PUSH_SUCCESS); |
|
|
|
.set(MessagePushRecordEntity::getPushTime,LocalDateTime.now()) |
|
|
|
record.setPushTime(LocalDateTime.now()); |
|
|
|
.eq(MessagePushRecordEntity::getId,record.getId()) |
|
|
|
} |
|
|
|
); |
|
|
|
else { |
|
|
|
|
|
|
|
record.setStatus(MessageConstants.PUSH_FAILED); |
|
|
|
|
|
|
|
record.setFaultResult(sendResult.getMsg()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
this.updateById(record); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return true; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* 推送APP即时消息 |
|
|
|
|
|
|
|
* @param record 消息记录 |
|
|
|
|
|
|
|
* @return 推送结果 |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
private Boolean sendAppImmediatelyMsg(MessagePushRecordEntity record) { |
|
|
|
|
|
|
|
if(this.saveOrUpdate(record)) { |
|
|
|
|
|
|
|
PushMessageServiceImpl pushService = SpringUtil.getBean(PushMessageServiceImpl.class); |
|
|
|
|
|
|
|
if(pushService.send(record)) { |
|
|
|
|
|
|
|
record.setStatus(MessageConstants.PUSH_SUCCESS); |
|
|
|
|
|
|
|
record.setPushTime(LocalDateTime.now()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else { |
|
|
|
|
|
|
|
record.setStatus(MessageConstants.PUSH_FAILED); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
this.updateById(record); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return true; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private Boolean sendWsImmediatelyMsg(MessagePushRecordEntity record) { |
|
|
|
|
|
|
|
if(this.saveOrUpdate(record)) { |
|
|
|
|
|
|
|
WebsocketServiceImpl wsService = SpringUtil.getBean(WebsocketServiceImpl.class); |
|
|
|
|
|
|
|
if(wsService.send(record)) { |
|
|
|
|
|
|
|
record.setStatus(MessageConstants.PUSH_SUCCESS); |
|
|
|
|
|
|
|
record.setPushTime(LocalDateTime.now()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else { |
|
|
|
|
|
|
|
record.setStatus(MessageConstants.PUSH_FAILED); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
this.updateById(record); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return true; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public Boolean sendImmediatelyMSg(MessagePushRecordEntity record) { |
|
|
|
|
|
|
|
Assert.isTrue(MessageConstants.IMMEDIATELY.equals(record.getPushType()),() -> { |
|
|
|
|
|
|
|
throw new ServiceException("该消息记录推送类型错误,只能为即时推送!"); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
switch(record.getType()) { |
|
|
|
|
|
|
|
case MessageConstants.APP_PUSH: |
|
|
|
|
|
|
|
return this.sendAppImmediatelyMsg(record); |
|
|
|
|
|
|
|
case MessageConstants.WX_PUSH: |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
case MessageConstants.WS_PUSH: |
|
|
|
|
|
|
|
return this.sendWsImmediatelyMsg(record); |
|
|
|
|
|
|
|
case MessageConstants.SMS_PUSH: |
|
|
|
|
|
|
|
return this.sendSmsImmediatelyMsg(record); |
|
|
|
|
|
|
|
default: |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return true; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@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()); |
|
|
|
|
|
|
|
if(this.saveBatch(pushRecords)) { |
|
|
|
|
|
|
|
// 推送消息
|
|
|
|
|
|
|
|
WebsocketServiceImpl wsMessageService = SpringUtil.getBean(WebsocketServiceImpl.class); |
|
|
|
|
|
|
|
pushRecords.forEach(record -> { |
|
|
|
|
|
|
|
if(MessageConstants.APP_PUSH.equals(record.getType())) { |
|
|
|
|
|
|
|
// APP消息存入redis中进行消费
|
|
|
|
|
|
|
|
redisTemplate.opsForList().leftPush(appPushRedisKey.concat(":").concat(record.getPusher()), record); |
|
|
|
|
|
|
|
} else if (MessageConstants.WS_PUSH.equals(record.getType())) { |
|
|
|
|
|
|
|
// WEB消息调用接口直接进行推送
|
|
|
|
|
|
|
|
if(wsMessageService.send(record)) { |
|
|
|
|
|
|
|
record.setPushTime(LocalDateTime.now()); |
|
|
|
|
|
|
|
record.setStatus(MessageConstants.PUSH_SUCCESS); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
else { |
|
|
|
|
|
|
|
record.setStatus(MessageConstants.PUSH_FAILED); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
this.updateById(record); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}); |
|
|
|
return true; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* 根据机构ID获取机构名称 |
|
|
|
|
|
|
|
* @param deptId 机构ID |
|
|
|
|
|
|
|
* @return 机构名称 |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
private String getDeptNameById(Long deptId) { |
|
|
|
|
|
|
|
return Optional.ofNullable(sysClient.getDeptName(deptId)).filter(r -> r.isSuccess()).map(R::getData).orElse(null); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* 推送成功失败统计 |
|
|
|
* 推送成功失败统计 |
|
|
@ -408,40 +529,6 @@ public class MessagePushRecordServiceImpl extends BaseServiceImpl<MessagePushRec |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public Boolean sendAppMsgByUsers(BusinessMessageDTO request, List<MessagePushRecordEntity> records) { |
|
|
|
|
|
|
|
PushMessageServiceImpl service = SpringUtil.getBean(PushMessageServiceImpl.class); |
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
boolean sendFlag = service.sendByUsers(request.getSubject(), request.getContent(), Arrays.asList(request.getUserIds().split(",")), request.getTenantId()); |
|
|
|
|
|
|
|
if (sendFlag) { |
|
|
|
|
|
|
|
return this.update(Wrappers.<MessagePushRecordEntity>lambdaUpdate() |
|
|
|
|
|
|
|
.set(MessagePushRecordEntity::getPushTime, LocalDateTime.now()) |
|
|
|
|
|
|
|
.set(MessagePushRecordEntity::getStatus, MessageConstants.PUSH_SUCCESS) |
|
|
|
|
|
|
|
.in(MessagePushRecordEntity::getId, records.stream().map(MessagePushRecordEntity::getId).collect(Collectors.toList())) |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
} catch (Exception e) { |
|
|
|
|
|
|
|
throw new ServiceException(e.getMessage()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public Boolean sendWsMsgByUsers(List<MessagePushRecordEntity> request) { |
|
|
|
|
|
|
|
WebsocketServiceImpl service = SpringUtil.getBean(WebsocketServiceImpl.class); |
|
|
|
|
|
|
|
request.forEach(record -> { |
|
|
|
|
|
|
|
boolean sendFlag = service.send(record); |
|
|
|
|
|
|
|
if (sendFlag) { |
|
|
|
|
|
|
|
this.update(Wrappers.<MessagePushRecordEntity>lambdaUpdate() |
|
|
|
|
|
|
|
.set(MessagePushRecordEntity::getPushTime, LocalDateTime.now()) |
|
|
|
|
|
|
|
.set(MessagePushRecordEntity::getStatus, MessageConstants.PUSH_SUCCESS) |
|
|
|
|
|
|
|
.in(MessagePushRecordEntity::getId, record.getId()) |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
return true; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public Boolean sendMailMsgByUsers(List<MessagePushRecordEntity> request) { |
|
|
|
public Boolean sendMailMsgByUsers(List<MessagePushRecordEntity> request) { |
|
|
|
MailMessageServiceImpl service = SpringUtil.getBean(MailMessageServiceImpl.class); |
|
|
|
MailMessageServiceImpl service = SpringUtil.getBean(MailMessageServiceImpl.class); |
|
|
|
request.forEach(record -> { |
|
|
|
request.forEach(record -> { |
|
|
|