Browse Source

# 消息推送修改

zhongwei
haungxing 2 years ago
parent
commit
90fb77db20
  1. 2
      hzims-service/message/src/main/java/com/hnac/hzims/message/controller/MessagePushRecordController.java
  2. 10
      hzims-service/message/src/main/java/com/hnac/hzims/message/fegin/MessageClient.java
  3. 14
      hzims-service/message/src/main/java/com/hnac/hzims/message/schedule/MessagePushSchedule.java
  4. 10
      hzims-service/message/src/main/java/com/hnac/hzims/message/service/IMessagePushRecordService.java
  5. 71
      hzims-service/message/src/main/java/com/hnac/hzims/message/service/impl/MessagePushRecordServiceImpl.java
  6. 8
      hzims-service/message/src/main/java/com/hnac/hzims/message/service/impl/MessageTemplateServiceImpl.java
  7. 30
      hzims-service/message/src/main/java/com/hnac/hzims/message/wrapper/MessageTemplateWrapper.java

2
hzims-service/message/src/main/java/com/hnac/hzims/message/controller/MessagePushRecordController.java

@ -54,7 +54,7 @@ public class MessagePushRecordController extends BladeController {
@GetMapping("/send/{id}") @GetMapping("/send/{id}")
@ApiOperation("推送消息记录") @ApiOperation("推送消息记录")
@ApiOperationSupport(order = 4) @ApiOperationSupport(order = 4)
public R<Boolean> send(@PathVariable @ApiParam("消息记录ID") String id) { public R<Boolean> send(@PathVariable @ApiParam("消息记录ID") Long id) {
return R.data(messagePushRecordService.send(id)); return R.data(messagePushRecordService.send(id));
} }
} }

10
hzims-service/message/src/main/java/com/hnac/hzims/message/fegin/MessageClient.java

@ -4,6 +4,8 @@ import com.alibaba.fastjson.JSON;
import com.hnac.hzims.message.MessageConstants; import com.hnac.hzims.message.MessageConstants;
import com.hnac.hzims.message.dto.PushDto; import com.hnac.hzims.message.dto.PushDto;
import com.hnac.hzims.message.dto.SmsPushDto; import com.hnac.hzims.message.dto.SmsPushDto;
import com.hnac.hzims.message.entity.MessagePushRecordEntity;
import com.hnac.hzims.message.service.IMessagePushRecordService;
import com.hnac.hzims.message.service.IMessageService; import com.hnac.hzims.message.service.IMessageService;
import com.hnac.hzims.message.service.impl.SmsMessageServiceImpl; import com.hnac.hzims.message.service.impl.SmsMessageServiceImpl;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
@ -23,6 +25,8 @@ import org.springframework.web.bind.annotation.RestController;
@Slf4j @Slf4j
public class MessageClient extends BladeController implements IMessageClient{ public class MessageClient extends BladeController implements IMessageClient{
private final IMessagePushRecordService recordService;
@Override @Override
@PostMapping(SEND_SMS_MESSAGE) @PostMapping(SEND_SMS_MESSAGE)
public R sendSmsMessage(@RequestBody SmsPushDto pushDto) { public R sendSmsMessage(@RequestBody SmsPushDto pushDto) {
@ -30,4 +34,10 @@ public class MessageClient extends BladeController implements IMessageClient{
return messageService.send(pushDto); return messageService.send(pushDto);
} }
@Override
@PostMapping(SEND_MESSAGE)
public R<Boolean> sendMessage(@RequestBody MessagePushRecordEntity request) {
return R.status(recordService.saveAndSend(request));
}
} }

14
hzims-service/message/src/main/java/com/hnac/hzims/message/schedule/MessagePushSchedule.java

@ -17,6 +17,7 @@ import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.handler.annotation.XxlJob; import com.xxl.job.core.handler.annotation.XxlJob;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springblade.core.tool.utils.CollectionUtil;
import org.springblade.core.tool.utils.Func; import org.springblade.core.tool.utils.Func;
import org.springblade.core.tool.utils.ObjectUtil; import org.springblade.core.tool.utils.ObjectUtil;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
@ -53,10 +54,14 @@ public class MessagePushSchedule {
LocalDateTime endTime = DateUtil.plus(LocalDateTime.now(), template.getConcentratedDuration(), template.getConcentratedTimeUnit()); LocalDateTime endTime = DateUtil.plus(LocalDateTime.now(), template.getConcentratedDuration(), template.getConcentratedTimeUnit());
endTime = DateUtil.plus(endTime, template.getAdvanceDuration(), template.getAdvanceTimeUnit()); endTime = DateUtil.plus(endTime, template.getAdvanceDuration(), template.getAdvanceTimeUnit());
LambdaQueryWrapper<MessagePushRecordEntity> lqw = Wrappers.<MessagePushRecordEntity>lambdaQuery() LambdaQueryWrapper<MessagePushRecordEntity> lqw = Wrappers.<MessagePushRecordEntity>lambdaQuery()
.eq(MessagePushRecordEntity::getStatus, MessageConstants.NOT_PUSH) .eq(MessagePushRecordEntity::getStatus, MessageConstants.NOT_PUSH)
.ge(MessagePushRecordEntity::getPlanTime, now) .eq(MessagePushRecordEntity::getTemplateId,template.getId())
.le(MessagePushRecordEntity::getPlanTime, endTime); .ge(MessagePushRecordEntity::getPlanTime, now)
.le(MessagePushRecordEntity::getPlanTime, endTime);
List<MessagePushRecordEntity> list = recordService.list(lqw); List<MessagePushRecordEntity> list = recordService.list(lqw);
if(CollectionUtil.isEmpty(list) || list.size() == 0) {
return;
}
this.sendMessage(list); this.sendMessage(list);
}); });
return ReturnT.SUCCESS; return ReturnT.SUCCESS;
@ -77,6 +82,9 @@ public class MessagePushSchedule {
// 完善推送内容 // 完善推送内容
request.setContent(this.getPushContent(type,records)); request.setContent(this.getPushContent(type,records));
Boolean flag = service.send(request); Boolean flag = service.send(request);
if(!flag) {
return;
}
List<Long> ids = records.stream().map(MessagePushRecordEntity::getId).collect(Collectors.toList()); List<Long> ids = records.stream().map(MessagePushRecordEntity::getId).collect(Collectors.toList());
// 更新消息推送状态 // 更新消息推送状态
LambdaUpdateWrapper<MessagePushRecordEntity> lwq = Wrappers.<MessagePushRecordEntity>lambdaUpdate() LambdaUpdateWrapper<MessagePushRecordEntity> lwq = Wrappers.<MessagePushRecordEntity>lambdaUpdate()

10
hzims-service/message/src/main/java/com/hnac/hzims/message/service/IMessagePushRecordService.java

@ -35,7 +35,15 @@ public interface IMessagePushRecordService extends BaseService<MessagePushRecord
* @Param ids 消息记录ID * @Param ids 消息记录ID
* @return * @return
**/ **/
Boolean send(String id); Boolean send(Long id);
/** @Author hx
* @Description 保存并推送消息
* @Date 2023/4/6 20:14
* @Param request 消息推送记录
* @return
**/
Boolean saveAndSend(MessagePushRecordEntity request);
/** /**

71
hzims-service/message/src/main/java/com/hnac/hzims/message/service/impl/MessagePushRecordServiceImpl.java

@ -1,7 +1,10 @@
package com.hnac.hzims.message.service.impl; package com.hnac.hzims.message.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.hnac.hzims.message.MessageConstants;
import com.hnac.hzims.message.config.MessageFactory; import com.hnac.hzims.message.config.MessageFactory;
import com.hnac.hzims.message.entity.MessagePushRecordEntity; import com.hnac.hzims.message.entity.MessagePushRecordEntity;
import com.hnac.hzims.message.enums.PushStatEnum; import com.hnac.hzims.message.enums.PushStatEnum;
@ -11,12 +14,16 @@ import com.hnac.hzims.message.service.IMessageService;
import com.hnac.hzims.message.vo.msgpushrecord.*; import com.hnac.hzims.message.vo.msgpushrecord.*;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springblade.core.log.exception.ServiceException;
import org.springblade.core.mp.base.BaseServiceImpl; import org.springblade.core.mp.base.BaseServiceImpl;
import org.springblade.core.mp.support.Condition; import org.springblade.core.mp.support.Condition;
import org.springblade.core.mp.support.Query; import org.springblade.core.mp.support.Query;
import org.springblade.core.tool.utils.Func; import org.springblade.core.tool.utils.Func;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Assert;
import java.time.LocalDateTime;
import java.time.YearMonth; import java.time.YearMonth;
import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatter;
import java.util.ArrayList; import java.util.ArrayList;
@ -39,13 +46,50 @@ public class MessagePushRecordServiceImpl extends BaseServiceImpl<MessagePushRec
return this.page(Condition.getPage(query), this.getQueryWrapper(request)); return this.page(Condition.getPage(query), this.getQueryWrapper(request));
} }
@Override @Override
public Boolean send(String id) { public Boolean send(Long id) {
MessagePushRecordEntity record = this.getById(id); MessagePushRecordEntity record = this.getById(id);
IMessageService messageSend = MessageFactory.getMessageSend(record.getType()); IMessageService messageSend = MessageFactory.getMessageSend(record.getType());
return messageSend.send(record); Boolean result = messageSend.send(record);
} Assert.isTrue(result , ()-> {
throw new ServiceException("发送消息失败!");
});
// 更新推送状态以及推送时间
LambdaUpdateWrapper<MessagePushRecordEntity> luw = Wrappers.<MessagePushRecordEntity>lambdaUpdate()
.set(MessagePushRecordEntity::getPushTime, LocalDateTime.now())
.set(MessagePushRecordEntity::getStatus, MessageConstants.PUSH_SUCCESS)
.eq(MessagePushRecordEntity::getId, id);
return this.update(luw);
}
@Override
@Transactional(rollbackFor = Exception.class)
public Boolean saveAndSend(MessagePushRecordEntity request) {
if(Func.isEmpty(request.getPlanTime())) {
request.setPlanTime(LocalDateTime.now());
}
if(this.save(request) && Func.isNotEmpty(request.getId())) {
return this.send(request.getId());
}
return false;
}
/**
* 获取 QueryWrapper
* @param request 查询条件
* @return QueryWrapper
*/
private LambdaQueryWrapper<MessagePushRecordEntity> getQueryWrapper(MessagePushRecordEntity request) {
LambdaQueryWrapper<MessagePushRecordEntity> lambda = Condition.getQueryWrapper(request).lambda();
if(Func.isNotEmpty(request.getStartTime())) {
lambda.ge(MessagePushRecordEntity::getPushTime,request.getStartTime());
}
if(Func.isNotEmpty(request.getEndTime())) {
lambda.le(MessagePushRecordEntity::getPushTime,request.getEndTime());
}
lambda.orderByDesc(MessagePushRecordEntity::getPushTime);
return lambda;
}
/** /**
* 短信推送统计 * 短信推送统计
*/ */
@ -141,21 +185,6 @@ public class MessagePushRecordServiceImpl extends BaseServiceImpl<MessagePushRec
/** /**
* 获取 QueryWrapper
*
* @param request 查询条件
* @return QueryWrapper
*/
private LambdaQueryWrapper<MessagePushRecordEntity> getQueryWrapper(MessagePushRecordEntity request) {
LambdaQueryWrapper<MessagePushRecordEntity> lambda = Condition.getQueryWrapper(request).lambda();
if (Func.isNotEmpty(request.getStatus())) {
lambda.eq(MessagePushRecordEntity::getStatus, request.getStatus());
}
return lambda;
}
/**
* 状态 ===> 状态名称 * 状态 ===> 状态名称
* *
* @param key 状态 * @param key 状态

8
hzims-service/message/src/main/java/com/hnac/hzims/message/service/impl/MessageTemplateServiceImpl.java

@ -6,10 +6,12 @@ import com.hnac.hzims.common.utils.Condition;
import com.hnac.hzims.message.entity.config.MessageTemplateEntity; import com.hnac.hzims.message.entity.config.MessageTemplateEntity;
import com.hnac.hzims.message.mapper.MessageTemplateMapper; import com.hnac.hzims.message.mapper.MessageTemplateMapper;
import com.hnac.hzims.message.service.IMessageTemplateService; import com.hnac.hzims.message.service.IMessageTemplateService;
import com.hnac.hzims.message.wrapper.MessageTemplateWrapper;
import groovy.util.logging.Slf4j; import groovy.util.logging.Slf4j;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import org.springblade.core.mp.base.BaseServiceImpl; import org.springblade.core.mp.base.BaseServiceImpl;
import org.springblade.core.mp.support.Query; import org.springblade.core.mp.support.Query;
import org.springblade.core.tool.utils.CollectionUtil;
import org.springblade.core.tool.utils.Func; import org.springblade.core.tool.utils.Func;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@ -21,12 +23,14 @@ import java.util.List;
public class MessageTemplateServiceImpl extends BaseServiceImpl<MessageTemplateMapper, MessageTemplateEntity> implements IMessageTemplateService { public class MessageTemplateServiceImpl extends BaseServiceImpl<MessageTemplateMapper, MessageTemplateEntity> implements IMessageTemplateService {
@Override @Override
public List<MessageTemplateEntity> list(MessageTemplateEntity req) { public List<MessageTemplateEntity> list(MessageTemplateEntity req) {
return this.list(this.getQueryWrapper(req)); List<MessageTemplateEntity> record = this.list(this.getQueryWrapper(req));
return MessageTemplateWrapper.build().listVO(record);
} }
@Override @Override
public IPage<MessageTemplateEntity> listPage(MessageTemplateEntity req, Query query) { public IPage<MessageTemplateEntity> listPage(MessageTemplateEntity req, Query query) {
return this.page(Condition.getPage(query) , this.getQueryWrapper(req)); IPage<MessageTemplateEntity> page = this.page(Condition.getPage(query), this.getQueryWrapper(req));
return page.setRecords(MessageTemplateWrapper.build().listVO(page.getRecords()));
} }
/** /**

30
hzims-service/message/src/main/java/com/hnac/hzims/message/wrapper/MessageTemplateWrapper.java

@ -0,0 +1,30 @@
package com.hnac.hzims.message.wrapper;
import com.hnac.hzims.message.entity.config.MessageTemplateEntity;
import org.springblade.core.mp.support.BaseEntityWrapper;
import org.springblade.system.cache.DictCache;
import org.springblade.system.user.cache.UserCache;
import org.springblade.system.user.entity.User;
import java.util.Optional;
/**
* @ClassName MessageTemplateWrapper
* @description:
* @author: hx
* @create: 2023-04-06 17:30
* @Version 4.0
**/
public class MessageTemplateWrapper extends BaseEntityWrapper<MessageTemplateEntity,MessageTemplateEntity> {
public static MessageTemplateWrapper build() {
return new MessageTemplateWrapper();
}
@Override
public MessageTemplateEntity entityVO(MessageTemplateEntity entity) {
User user = UserCache.getUser(entity.getCreateUser());
entity.setCreatorName(Optional.ofNullable(user).map(User::getName).orElse(entity.getCreateUser().toString()));
return entity;
}
}
Loading…
Cancel
Save