diff --git a/hzims-service/message/src/main/java/com/hnac/hzims/message/controller/MessagePushRecordController.java b/hzims-service/message/src/main/java/com/hnac/hzims/message/controller/MessagePushRecordController.java index ff38d71..a1f3fa8 100644 --- a/hzims-service/message/src/main/java/com/hnac/hzims/message/controller/MessagePushRecordController.java +++ b/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}") @ApiOperation("推送消息记录") @ApiOperationSupport(order = 4) - public R send(@PathVariable @ApiParam("消息记录ID") String id) { + public R send(@PathVariable @ApiParam("消息记录ID") Long id) { return R.data(messagePushRecordService.send(id)); } } diff --git a/hzims-service/message/src/main/java/com/hnac/hzims/message/fegin/MessageClient.java b/hzims-service/message/src/main/java/com/hnac/hzims/message/fegin/MessageClient.java index 352e2f9..3a04b61 100644 --- a/hzims-service/message/src/main/java/com/hnac/hzims/message/fegin/MessageClient.java +++ b/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.dto.PushDto; 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.impl.SmsMessageServiceImpl; import lombok.AllArgsConstructor; @@ -23,6 +25,8 @@ import org.springframework.web.bind.annotation.RestController; @Slf4j public class MessageClient extends BladeController implements IMessageClient{ + private final IMessagePushRecordService recordService; + @Override @PostMapping(SEND_SMS_MESSAGE) public R sendSmsMessage(@RequestBody SmsPushDto pushDto) { @@ -30,4 +34,10 @@ public class MessageClient extends BladeController implements IMessageClient{ return messageService.send(pushDto); } + @Override + @PostMapping(SEND_MESSAGE) + public R sendMessage(@RequestBody MessagePushRecordEntity request) { + return R.status(recordService.saveAndSend(request)); + } + } diff --git a/hzims-service/message/src/main/java/com/hnac/hzims/message/schedule/MessagePushSchedule.java b/hzims-service/message/src/main/java/com/hnac/hzims/message/schedule/MessagePushSchedule.java index 797bec7..30565d2 100644 --- a/hzims-service/message/src/main/java/com/hnac/hzims/message/schedule/MessagePushSchedule.java +++ b/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 lombok.AllArgsConstructor; 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.ObjectUtil; import org.springframework.stereotype.Component; @@ -53,10 +54,14 @@ public class MessagePushSchedule { LocalDateTime endTime = DateUtil.plus(LocalDateTime.now(), template.getConcentratedDuration(), template.getConcentratedTimeUnit()); endTime = DateUtil.plus(endTime, template.getAdvanceDuration(), template.getAdvanceTimeUnit()); LambdaQueryWrapper lqw = Wrappers.lambdaQuery() - .eq(MessagePushRecordEntity::getStatus, MessageConstants.NOT_PUSH) - .ge(MessagePushRecordEntity::getPlanTime, now) - .le(MessagePushRecordEntity::getPlanTime, endTime); + .eq(MessagePushRecordEntity::getStatus, MessageConstants.NOT_PUSH) + .eq(MessagePushRecordEntity::getTemplateId,template.getId()) + .ge(MessagePushRecordEntity::getPlanTime, now) + .le(MessagePushRecordEntity::getPlanTime, endTime); List list = recordService.list(lqw); + if(CollectionUtil.isEmpty(list) || list.size() == 0) { + return; + } this.sendMessage(list); }); return ReturnT.SUCCESS; @@ -77,6 +82,9 @@ public class MessagePushSchedule { // 完善推送内容 request.setContent(this.getPushContent(type,records)); Boolean flag = service.send(request); + if(!flag) { + return; + } List ids = records.stream().map(MessagePushRecordEntity::getId).collect(Collectors.toList()); // 更新消息推送状态 LambdaUpdateWrapper lwq = Wrappers.lambdaUpdate() diff --git a/hzims-service/message/src/main/java/com/hnac/hzims/message/service/IMessagePushRecordService.java b/hzims-service/message/src/main/java/com/hnac/hzims/message/service/IMessagePushRecordService.java index 1b7f1d4..001cc23 100644 --- a/hzims-service/message/src/main/java/com/hnac/hzims/message/service/IMessagePushRecordService.java +++ b/hzims-service/message/src/main/java/com/hnac/hzims/message/service/IMessagePushRecordService.java @@ -35,7 +35,15 @@ public interface IMessagePushRecordService extends BaseService { + throw new ServiceException("发送消息失败!"); + }); + // 更新推送状态以及推送时间 + LambdaUpdateWrapper luw = Wrappers.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 getQueryWrapper(MessagePushRecordEntity request) { + LambdaQueryWrapper 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 getQueryWrapper(MessagePushRecordEntity request) { - LambdaQueryWrapper lambda = Condition.getQueryWrapper(request).lambda(); - if (Func.isNotEmpty(request.getStatus())) { - lambda.eq(MessagePushRecordEntity::getStatus, request.getStatus()); - } - return lambda; - } - - - /** * 状态 ===> 状态名称 * * @param key 状态 diff --git a/hzims-service/message/src/main/java/com/hnac/hzims/message/service/impl/MessageTemplateServiceImpl.java b/hzims-service/message/src/main/java/com/hnac/hzims/message/service/impl/MessageTemplateServiceImpl.java index a446c39..2012749 100644 --- a/hzims-service/message/src/main/java/com/hnac/hzims/message/service/impl/MessageTemplateServiceImpl.java +++ b/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.mapper.MessageTemplateMapper; import com.hnac.hzims.message.service.IMessageTemplateService; +import com.hnac.hzims.message.wrapper.MessageTemplateWrapper; import groovy.util.logging.Slf4j; import lombok.AllArgsConstructor; import org.springblade.core.mp.base.BaseServiceImpl; import org.springblade.core.mp.support.Query; +import org.springblade.core.tool.utils.CollectionUtil; import org.springblade.core.tool.utils.Func; import org.springframework.stereotype.Service; @@ -21,12 +23,14 @@ import java.util.List; public class MessageTemplateServiceImpl extends BaseServiceImpl implements IMessageTemplateService { @Override public List list(MessageTemplateEntity req) { - return this.list(this.getQueryWrapper(req)); + List record = this.list(this.getQueryWrapper(req)); + return MessageTemplateWrapper.build().listVO(record); } @Override public IPage listPage(MessageTemplateEntity req, Query query) { - return this.page(Condition.getPage(query) , this.getQueryWrapper(req)); + IPage page = this.page(Condition.getPage(query), this.getQueryWrapper(req)); + return page.setRecords(MessageTemplateWrapper.build().listVO(page.getRecords())); } /** diff --git a/hzims-service/message/src/main/java/com/hnac/hzims/message/wrapper/MessageTemplateWrapper.java b/hzims-service/message/src/main/java/com/hnac/hzims/message/wrapper/MessageTemplateWrapper.java new file mode 100644 index 0000000..31ba882 --- /dev/null +++ b/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 { + + 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; + } +}