diff --git a/hzims-service-api/message-api/src/main/java/com/hnac/hzims/message/MessageConstants.java b/hzims-service-api/message-api/src/main/java/com/hnac/hzims/message/MessageConstants.java index b0a2aae..f8d51ff 100644 --- a/hzims-service-api/message-api/src/main/java/com/hnac/hzims/message/MessageConstants.java +++ b/hzims-service-api/message-api/src/main/java/com/hnac/hzims/message/MessageConstants.java @@ -73,4 +73,12 @@ public class MessageConstants { public final static Integer CONFIRM = 3; /**====================================推送状态====================================**/ + /**====================================推送类型====================================**/ + /**即时推送**/ + public final static String IMMEDIATELY = "0"; + /**计划推送**/ + public final static String PLAN = "1"; + + /**====================================推送类型====================================**/ + } diff --git a/hzims-service-api/message-api/src/main/java/com/hnac/hzims/message/dto/MessagePushRecordDto.java b/hzims-service-api/message-api/src/main/java/com/hnac/hzims/message/dto/MessagePushRecordDto.java new file mode 100644 index 0000000..c064174 --- /dev/null +++ b/hzims-service-api/message-api/src/main/java/com/hnac/hzims/message/dto/MessagePushRecordDto.java @@ -0,0 +1,25 @@ +package com.hnac.hzims.message.dto; + +import com.hnac.hzims.message.entity.MessagePushRecordEntity; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import javax.validation.constraints.NotNull; +import java.io.Serializable; +import java.util.List; + +/** + * @ClassName MessagePushRecordDto + * @description: + * @author: hx + * @create: 2023-04-12 11:11 + * @Version 4.0 + **/ +@Data +public class MessagePushRecordDto extends MessagePushRecordEntity implements Serializable { + + @ApiModelProperty("多种消息类型推送使用字段") + @NotNull + private List types; + +} diff --git a/hzims-service-api/message-api/src/main/java/com/hnac/hzims/message/entity/MessagePushRecordEntity.java b/hzims-service-api/message-api/src/main/java/com/hnac/hzims/message/entity/MessagePushRecordEntity.java index d39dde7..39bd263 100644 --- a/hzims-service-api/message-api/src/main/java/com/hnac/hzims/message/entity/MessagePushRecordEntity.java +++ b/hzims-service-api/message-api/src/main/java/com/hnac/hzims/message/entity/MessagePushRecordEntity.java @@ -14,6 +14,7 @@ import org.springblade.core.mp.support.SqlCondition; import org.springblade.core.tool.utils.DateUtil; import org.springframework.format.annotation.DateTimeFormat; +import javax.validation.constraints.NotNull; import java.time.LocalDate; import java.time.LocalDateTime; @@ -23,12 +24,21 @@ import java.time.LocalDateTime; @EqualsAndHashCode public class MessagePushRecordEntity extends MessageTemplateEntity { - @ApiModelProperty("站点编码") + @ApiModelProperty("机构ID") @QueryField(condition = SqlCondition.EQUAL) - private String stationCode; + @NotNull + private Long deptId; - @ApiModelProperty("站点名称") - private String stationName; + @ApiModelProperty("机构名称") + private String deptName; + + @ApiModelProperty("推送类型,0:即时推送,1:计划推送") + @QueryField(condition = SqlCondition.EQUAL) + @NotNull + private String pushType; + + @ApiModelProperty("消息ID") + private Long messageId; @ApiModelProperty("业务任务ID") @QueryField(condition = SqlCondition.EQUAL) @@ -44,9 +54,11 @@ public class MessagePushRecordEntity extends MessageTemplateEntity { @ApiModelProperty(value = "推送人") @QueryField(condition = SqlCondition.LIKE) + @NotNull private String pusher; @ApiModelProperty(value = "推送账号:手机号,邮箱") + @NotNull private String account; @ApiModelProperty(value = "推送人名称") diff --git a/hzims-service-api/message-api/src/main/java/com/hnac/hzims/message/entity/config/MessageTemplateEntity.java b/hzims-service-api/message-api/src/main/java/com/hnac/hzims/message/entity/config/MessageTemplateEntity.java index 93f5930..93e182f 100644 --- a/hzims-service-api/message-api/src/main/java/com/hnac/hzims/message/entity/config/MessageTemplateEntity.java +++ b/hzims-service-api/message-api/src/main/java/com/hnac/hzims/message/entity/config/MessageTemplateEntity.java @@ -20,7 +20,6 @@ import java.io.Serializable; public class MessageTemplateEntity extends TenantEntity implements Serializable { @ApiModelProperty(value = "消息类型") - @NotNull(message = "消息类型不能为空") @QueryField(condition = SqlCondition.EQUAL) private String type; 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 1faa7cd..a140ed3 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 @@ -1,6 +1,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.PushDto; import com.hnac.hzims.message.dto.SmsPushDto; import com.hnac.hzims.message.entity.MessagePushRecordEntity; @@ -29,5 +30,5 @@ public interface IMessageClient { R sendSmsMessage(SmsPushDto pushDto); @PostMapping(SEND_MESSAGE) - R sendMessage(@RequestBody MessagePushRecordEntity request); + R sendMessage(@RequestBody MessagePushRecordDto 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 0c6058a..1aef9cb 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,5 +1,6 @@ package com.hnac.hzims.message.fegin; +import com.hnac.hzims.message.dto.MessagePushRecordDto; import com.hnac.hzims.message.dto.PushDto; import com.hnac.hzims.message.dto.SmsPushDto; import com.hnac.hzims.message.entity.MessagePushRecordEntity; @@ -18,7 +19,7 @@ public class MessageClientFallback implements IMessageClient { } @Override - public R sendMessage(MessagePushRecordEntity request) { + public R sendMessage(MessagePushRecordDto 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 3a04b61..6c3894f 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 @@ -1,7 +1,9 @@ package com.hnac.hzims.message.fegin; 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.PushDto; import com.hnac.hzims.message.dto.SmsPushDto; import com.hnac.hzims.message.entity.MessagePushRecordEntity; @@ -12,11 +14,14 @@ import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springblade.core.boot.ctrl.BladeController; import org.springblade.core.tool.api.R; +import org.springblade.core.tool.utils.BeanUtil; import org.springblade.core.tool.utils.SpringUtil; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RestController; +import javax.validation.Valid; + /** * @author hx */ @@ -36,8 +41,16 @@ public class MessageClient extends BladeController implements IMessageClient{ @Override @PostMapping(SEND_MESSAGE) - public R sendMessage(@RequestBody MessagePushRecordEntity request) { - return R.status(recordService.saveAndSend(request)); + public R sendMessage(@RequestBody @Valid MessagePushRecordDto request) { + long messageId = IdWorker.getId(); + // 可能存在多种推送类型 + request.getTypes().forEach(type -> { + MessagePushRecordEntity entity = BeanUtil.copy(request,MessagePushRecordEntity.class); + entity.setType(type); + entity.setMessageId(messageId); + recordService.saveAndSend(entity); + }); + return R.success("推送成功!"); } } 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 30565d2..34efb6e 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 @@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; +import com.baomidou.mybatisplus.core.toolkit.IdWorker; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.hnac.hzims.common.utils.DateUtil; import com.hnac.hzims.message.MessageConstants; @@ -81,6 +82,7 @@ public class MessagePushSchedule { MessagePushRecordEntity request = records.get(0); // 完善推送内容 request.setContent(this.getPushContent(type,records)); + request.setMessageId(IdWorker.getId()); Boolean flag = service.send(request); if(!flag) { return; diff --git a/hzims-service/message/src/main/java/com/hnac/hzims/message/service/impl/MessagePushRecordServiceImpl.java b/hzims-service/message/src/main/java/com/hnac/hzims/message/service/impl/MessagePushRecordServiceImpl.java index 0e5c4f1..4455f42 100644 --- a/hzims-service/message/src/main/java/com/hnac/hzims/message/service/impl/MessagePushRecordServiceImpl.java +++ b/hzims-service/message/src/main/java/com/hnac/hzims/message/service/impl/MessagePushRecordServiceImpl.java @@ -7,6 +7,7 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.core.toolkit.IdWorker; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.hnac.hzims.common.utils.CacheUtil; import com.hnac.hzims.message.MessageConstants; @@ -31,6 +32,7 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.util.Assert; +import javax.validation.Valid; import java.time.LocalDateTime; import java.time.YearMonth; import java.time.format.DateTimeFormatter; @@ -85,14 +87,23 @@ public class MessagePushRecordServiceImpl extends BaseServiceImpl 机构ID +alter table hzims_message_push_record change `STATION_CODE` `DEPT_ID` bigint(20) DEFAULT NULL comment '机构ID'; +-- 站点名称字段 -> 机构名称 +alter table hzims_message_push_record change `STATION_NAME` `DEPT_NAME` VARCHAR(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL comment '机构ID'; + +-- 消息推送类型字典 +INSERT INTO `bladex`.`blade_dict` (`id`, `parent_id`, `code`, `dict_key`, `dict_value`, `sort`, `remark`, `is_sealed`, `is_deleted`, `dict_type`, `app_id`, `app_code`) VALUES (1645998325178130433, 0, 'pushType', '-1', '推送类型', 6, '', 0, 0, 0, -1, 'message'); +INSERT INTO `bladex`.`blade_dict` (`id`, `parent_id`, `code`, `dict_key`, `dict_value`, `sort`, `remark`, `is_sealed`, `is_deleted`, `dict_type`, `app_id`, `app_code`) VALUES (1645998429171703809, 1645998325178130433, 'pushType', '0', '即时推送', 1, '', 0, 0, 0, -1, 'message'); +INSERT INTO `bladex`.`blade_dict` (`id`, `parent_id`, `code`, `dict_key`, `dict_value`, `sort`, `remark`, `is_sealed`, `is_deleted`, `dict_type`, `app_id`, `app_code`) VALUES (1645998773519867906, 1645998325178130433, 'pushType', '1', '计划推送', 2, '', 0, 0, 0, -1, 'message'); + + diff --git a/hzims-service/message/src/main/resources/db/1.0.1.sql b/hzims-service/message/src/main/resources/db/1.0.1.sql new file mode 100644 index 0000000..308434e --- /dev/null +++ b/hzims-service/message/src/main/resources/db/1.0.1.sql @@ -0,0 +1,4 @@ +-- 添加消息ID +alter table hzims_message_push_record add COLUMN `MESSAGE_ID` bigint(20) DEFAULT NULL comment '消息ID'; +-- 添加消息推送类型 +alter table hzims_message_push_record add COLUMN `PUSH_TYPE` VARCHAR(2) DEFAULT NULL comment '推送类型,0:即时推送,1:计划推送'; \ No newline at end of file