Browse Source

# 计划类型消息推送接口修改

zhongwei
haungxing 2 years ago
parent
commit
49dac3aa19
  1. 58
      hzims-service-api/message-api/src/main/java/com/hnac/hzims/message/dto/PlanMsgRecordDto.java
  2. 5
      hzims-service-api/message-api/src/main/java/com/hnac/hzims/message/fegin/IMessageClient.java
  3. 6
      hzims-service-api/message-api/src/main/java/com/hnac/hzims/message/fegin/MessageClientFallback.java
  4. 40
      hzims-service/message/src/main/java/com/hnac/hzims/message/fegin/MessageClient.java

58
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;
}

5
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.MessageConstants;
import com.hnac.hzims.message.dto.MessagePushRecordDto; 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.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.entity.MessagePushRecordEntity;
@ -25,6 +26,7 @@ public interface IMessageClient {
String SEND_SMS_MESSAGE = API_PREFIX + "/send-sms-message"; String SEND_SMS_MESSAGE = API_PREFIX + "/send-sms-message";
String SEND_MESSAGE = API_PREFIX + "/sendMessage"; String SEND_MESSAGE = API_PREFIX + "/sendMessage";
String GET_TEMPLATE_BY_ID = API_PREFIX + "/getMsgTemplateById"; String GET_TEMPLATE_BY_ID = API_PREFIX + "/getMsgTemplateById";
String PLAN_SEND_MESSAGE = API_PREFIX + "/planSendMessage";
/** /**
* 推送消息短信 * 推送消息短信
* @param pushDto * @param pushDto
@ -38,4 +40,7 @@ public interface IMessageClient {
@GetMapping(GET_TEMPLATE_BY_ID) @GetMapping(GET_TEMPLATE_BY_ID)
R<MessageTemplateEntity> getMsgTemplateById(@RequestParam Long id); R<MessageTemplateEntity> getMsgTemplateById(@RequestParam Long id);
@PostMapping(PLAN_SEND_MESSAGE)
R<PlanMsgRecordDto> planSendMessage(@RequestBody PlanMsgRecordDto request);
} }

6
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; package com.hnac.hzims.message.fegin;
import com.hnac.hzims.message.dto.MessagePushRecordDto; 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.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.entity.MessagePushRecordEntity;
@ -28,4 +29,9 @@ public class MessageClientFallback implements IMessageClient {
public R<MessageTemplateEntity> getMsgTemplateById(Long id) { public R<MessageTemplateEntity> getMsgTemplateById(Long id) {
return R.fail("获取消息模板失败!"); return R.fail("获取消息模板失败!");
} }
@Override
public R<PlanMsgRecordDto> planSendMessage(PlanMsgRecordDto request) {
return R.fail("调用失败!");
}
} }

40
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.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.hnac.hzims.message.MessageConstants; import com.hnac.hzims.message.MessageConstants;
import com.hnac.hzims.message.dto.MessagePushRecordDto; 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.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.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.IMessageService;
import com.hnac.hzims.message.service.IMessageTemplateService; import com.hnac.hzims.message.service.IMessageTemplateService;
import com.hnac.hzims.message.service.impl.SmsMessageServiceImpl; import com.hnac.hzims.message.service.impl.SmsMessageServiceImpl;
import com.xxl.job.core.log.XxlJobLogger;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springblade.core.boot.ctrl.BladeController; 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.api.R;
import org.springblade.core.tool.utils.BeanUtil; 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.core.tool.utils.SpringUtil;
import org.springblade.system.user.cache.UserCache;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import javax.validation.Valid; import javax.validation.Valid;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.Arrays;
/** /**
* @author hx * @author hx
@ -60,4 +70,34 @@ public class MessageClient extends BladeController implements IMessageClient{
return R.data(messageTemplateService.getById(id)); return R.data(messageTemplateService.getById(id));
} }
@PostMapping(PLAN_SEND_MESSAGE)
@Override
public R<PlanMsgRecordDto> 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("推送失败!");
}
} }

Loading…
Cancel
Save