From 49dac3aa19619489c8f9b025e71fb6e5bdd7c30f Mon Sep 17 00:00:00 2001 From: haungxing <1203316822@qq.com> Date: Fri, 14 Apr 2023 14:58:10 +0800 Subject: [PATCH] =?UTF-8?q?#=20=E8=AE=A1=E5=88=92=E7=B1=BB=E5=9E=8B?= =?UTF-8?q?=E6=B6=88=E6=81=AF=E6=8E=A8=E9=80=81=E6=8E=A5=E5=8F=A3=E4=BF=AE?= =?UTF-8?q?=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hnac/hzims/message/dto/PlanMsgRecordDto.java | 58 ++++++++++++++++++++++ .../hnac/hzims/message/fegin/IMessageClient.java | 5 ++ .../hzims/message/fegin/MessageClientFallback.java | 6 +++ .../hnac/hzims/message/fegin/MessageClient.java | 40 +++++++++++++++ 4 files changed, 109 insertions(+) create mode 100644 hzims-service-api/message-api/src/main/java/com/hnac/hzims/message/dto/PlanMsgRecordDto.java diff --git a/hzims-service-api/message-api/src/main/java/com/hnac/hzims/message/dto/PlanMsgRecordDto.java b/hzims-service-api/message-api/src/main/java/com/hnac/hzims/message/dto/PlanMsgRecordDto.java new file mode 100644 index 0000000..e449437 --- /dev/null +++ b/hzims-service-api/message-api/src/main/java/com/hnac/hzims/message/dto/PlanMsgRecordDto.java @@ -0,0 +1,58 @@ +package com.hnac.hzims.message.dto; + +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.fasterxml.jackson.databind.ser.std.NullSerializer; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; + +import javax.validation.constraints.NotNull; +import java.io.Serializable; +import java.time.LocalDateTime; + +/** + * @ClassName PlanMsgRecordDto + * @description: + * @author: hx + * @create: 2023-04-14 14:15 + * @Version 4.0 + **/ +@Data +@ApiModel("计划推送消息请求对象") +@EqualsAndHashCode +public class PlanMsgRecordDto implements Serializable { + + @ApiModelProperty("机构ID") + @JsonSerialize(nullsUsing = NullSerializer.class) + @NotNull + private Long deptId; + + @ApiModelProperty("消息模板Id") + @JsonSerialize(nullsUsing = NullSerializer.class) + @NotNull + private Long templateId; + + @ApiModelProperty("业务任务Id") + @JsonSerialize(nullsUsing = NullSerializer.class) + @NotNull + private Long taskId; + + @ApiModelProperty("消息接收人") + @JsonSerialize(nullsUsing = NullSerializer.class) + @NotNull + private Long receiver; + + @ApiModelProperty("消息推送计划时间") + @NotNull + private LocalDateTime planTime; + + @ApiModelProperty("消息创建人") + @JsonSerialize(nullsUsing = NullSerializer.class) + private Long createUser; + + @ApiModelProperty("消息推送耳机") + @NotNull + private String content; + +} diff --git a/hzims-service-api/message-api/src/main/java/com/hnac/hzims/message/fegin/IMessageClient.java b/hzims-service-api/message-api/src/main/java/com/hnac/hzims/message/fegin/IMessageClient.java index b5d902d..a84e3f9 100644 --- a/hzims-service-api/message-api/src/main/java/com/hnac/hzims/message/fegin/IMessageClient.java +++ b/hzims-service-api/message-api/src/main/java/com/hnac/hzims/message/fegin/IMessageClient.java @@ -2,6 +2,7 @@ package com.hnac.hzims.message.fegin; import com.hnac.hzims.message.MessageConstants; import com.hnac.hzims.message.dto.MessagePushRecordDto; +import com.hnac.hzims.message.dto.PlanMsgRecordDto; import com.hnac.hzims.message.dto.PushDto; import com.hnac.hzims.message.dto.SmsPushDto; import com.hnac.hzims.message.entity.MessagePushRecordEntity; @@ -25,6 +26,7 @@ public interface IMessageClient { String SEND_SMS_MESSAGE = API_PREFIX + "/send-sms-message"; String SEND_MESSAGE = API_PREFIX + "/sendMessage"; String GET_TEMPLATE_BY_ID = API_PREFIX + "/getMsgTemplateById"; + String PLAN_SEND_MESSAGE = API_PREFIX + "/planSendMessage"; /** * 推送消息(短信) * @param pushDto @@ -38,4 +40,7 @@ public interface IMessageClient { @GetMapping(GET_TEMPLATE_BY_ID) R getMsgTemplateById(@RequestParam Long id); + + @PostMapping(PLAN_SEND_MESSAGE) + R planSendMessage(@RequestBody PlanMsgRecordDto request); } diff --git a/hzims-service-api/message-api/src/main/java/com/hnac/hzims/message/fegin/MessageClientFallback.java b/hzims-service-api/message-api/src/main/java/com/hnac/hzims/message/fegin/MessageClientFallback.java index 90c79f0..e03c604 100644 --- a/hzims-service-api/message-api/src/main/java/com/hnac/hzims/message/fegin/MessageClientFallback.java +++ b/hzims-service-api/message-api/src/main/java/com/hnac/hzims/message/fegin/MessageClientFallback.java @@ -1,6 +1,7 @@ package com.hnac.hzims.message.fegin; import com.hnac.hzims.message.dto.MessagePushRecordDto; +import com.hnac.hzims.message.dto.PlanMsgRecordDto; import com.hnac.hzims.message.dto.PushDto; import com.hnac.hzims.message.dto.SmsPushDto; import com.hnac.hzims.message.entity.MessagePushRecordEntity; @@ -28,4 +29,9 @@ public class MessageClientFallback implements IMessageClient { public R getMsgTemplateById(Long id) { return R.fail("获取消息模板失败!"); } + + @Override + public R planSendMessage(PlanMsgRecordDto request) { + return R.fail("调用失败!"); + } } 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 7537a48..d9ba935 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,7 @@ import com.alibaba.fastjson.JSON; import com.baomidou.mybatisplus.core.toolkit.IdWorker; import com.hnac.hzims.message.MessageConstants; import com.hnac.hzims.message.dto.MessagePushRecordDto; +import com.hnac.hzims.message.dto.PlanMsgRecordDto; import com.hnac.hzims.message.dto.PushDto; import com.hnac.hzims.message.dto.SmsPushDto; import com.hnac.hzims.message.entity.MessagePushRecordEntity; @@ -12,15 +13,24 @@ import com.hnac.hzims.message.service.IMessagePushRecordService; import com.hnac.hzims.message.service.IMessageService; import com.hnac.hzims.message.service.IMessageTemplateService; import com.hnac.hzims.message.service.impl.SmsMessageServiceImpl; +import com.xxl.job.core.log.XxlJobLogger; import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springblade.core.boot.ctrl.BladeController; +import org.springblade.core.log.exception.ServiceException; 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.ObjectUtil; import org.springblade.core.tool.utils.SpringUtil; +import org.springblade.system.user.cache.UserCache; +import org.springframework.util.Assert; import org.springframework.web.bind.annotation.*; import javax.validation.Valid; +import java.time.LocalDateTime; +import java.time.ZoneId; +import java.util.Arrays; /** * @author hx @@ -60,4 +70,34 @@ public class MessageClient extends BladeController implements IMessageClient{ return R.data(messageTemplateService.getById(id)); } + @PostMapping(PLAN_SEND_MESSAGE) + @Override + public R planSendMessage(@RequestBody @Valid PlanMsgRecordDto request) { + MessageTemplateEntity template = messageTemplateService.getById(request.getTemplateId()); + Assert.isTrue(ObjectUtil.isNotEmpty(template),() -> { + throw new ServiceException("获取消息模板失败,请检查消息模板是否删除!"); + }); + long messageId = IdWorker.getId(); + if(Func.isNotEmpty(template.getType())) { + Func.toStrList(",",template.getType()).forEach(type -> { + MessagePushRecordEntity entity = BeanUtil.copy(template,MessagePushRecordEntity.class); + entity.setType(type); + entity.setTemplateId(messageId); + entity.setDeptId(request.getDeptId()); + entity.setCreateUser(request.getCreateUser()); + entity.setCreateDept(request.getDeptId()); + entity.setPlanTime(request.getPlanTime()); + entity.setPushType(MessageConstants.PLAN); + entity.setPusher(request.getReceiver().toString()); + entity.setPusherName(UserCache.getUser(request.getReceiver()).getName()); + entity.setAccount(request.getReceiver().toString()); + entity.setContent(request.getContent()); + Assert.isTrue(recordService.saveAndSend(entity),()-> { + throw new ServiceException("消息保存失败!"); + }); + }); + } + return R.success("推送失败!"); + } + }