diff --git a/MessageHub/src/main/java/com/xiaowang/messagehub/entity/PushLog.java b/MessageHub/src/main/java/com/xiaowang/messagehub/entity/PushLog.java new file mode 100644 index 00000000..de178018 --- /dev/null +++ b/MessageHub/src/main/java/com/xiaowang/messagehub/entity/PushLog.java @@ -0,0 +1,161 @@ +package com.xiaowang.messagehub.entity; + +import com.baomidou.mybatisplus.annotation.*; +import java.time.LocalDateTime; + +@TableName("push_log") +public class PushLog { + @TableId(value = "id", type = IdType.INPUT) + private String id; + + @TableField("source_system") + private String sourceSystem; + + @TableField("unique_id") + private String uniqueId; + + @TableField("receiver") + private String receiver; + + @TableField("channel_type") + private String channelType; + + @TableField("msg_type") + private String msgType; + + @TableField("template_code") + private String templateCode; + + @TableField("template_params") + private String templateParams; + + @TableField("final_content") + private String finalContent; + + @TableField("status") + private Integer status; + + @TableField("retry_count") + private Integer retryCount; + + @TableField("fail_reason") + private String failReason; + + @TableField("send_time") + private LocalDateTime sendTime; + + @TableField(value = "create_time", fill = FieldFill.INSERT) + private LocalDateTime createTime; + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getSourceSystem() { + return sourceSystem; + } + + public void setSourceSystem(String sourceSystem) { + this.sourceSystem = sourceSystem; + } + + public String getUniqueId() { + return uniqueId; + } + + public void setUniqueId(String uniqueId) { + this.uniqueId = uniqueId; + } + + public String getReceiver() { + return receiver; + } + + public void setReceiver(String receiver) { + this.receiver = receiver; + } + + public String getChannelType() { + return channelType; + } + + public void setChannelType(String channelType) { + this.channelType = channelType; + } + + public String getMsgType() { + return msgType; + } + + public void setMsgType(String msgType) { + this.msgType = msgType; + } + + public String getTemplateCode() { + return templateCode; + } + + public void setTemplateCode(String templateCode) { + this.templateCode = templateCode; + } + + public String getTemplateParams() { + return templateParams; + } + + public void setTemplateParams(String templateParams) { + this.templateParams = templateParams; + } + + public String getFinalContent() { + return finalContent; + } + + public void setFinalContent(String finalContent) { + this.finalContent = finalContent; + } + + public Integer getStatus() { + return status; + } + + public void setStatus(Integer status) { + this.status = status; + } + + public Integer getRetryCount() { + return retryCount; + } + + public void setRetryCount(Integer retryCount) { + this.retryCount = retryCount; + } + + public String getFailReason() { + return failReason; + } + + public void setFailReason(String failReason) { + this.failReason = failReason; + } + + public LocalDateTime getSendTime() { + return sendTime; + } + + public void setSendTime(LocalDateTime sendTime) { + this.sendTime = sendTime; + } + + public LocalDateTime getCreateTime() { + return createTime; + } + + public void setCreateTime(LocalDateTime createTime) { + this.createTime = createTime; + } +} diff --git a/MessageHub/src/main/java/com/xiaowang/messagehub/entity/PushTemplate.java b/MessageHub/src/main/java/com/xiaowang/messagehub/entity/PushTemplate.java new file mode 100644 index 00000000..f5ed6e1c --- /dev/null +++ b/MessageHub/src/main/java/com/xiaowang/messagehub/entity/PushTemplate.java @@ -0,0 +1,139 @@ +package com.xiaowang.messagehub.entity; + +import com.baomidou.mybatisplus.annotation.*; +import java.time.LocalDateTime; + +@TableName("push_template") +public class PushTemplate { + @TableId(value = "id", type = IdType.AUTO) + private Long id; + + @TableField("template_code") + private String templateCode; + + @TableField("template_name") + private String templateName; + + @TableField("channel_type") + private String channelType; + + @TableField("msg_type") + private Integer msgType; + + @TableField("external_id") + private String externalId; + + @TableField("content_pattern") + private String contentPattern; + + @TableField("msg_category") + private Integer msgCategory; + + @TableField("is_enable") + private Integer isEnable; + + @TableField("description") + private String description; + + @TableField(value = "create_time", fill = FieldFill.INSERT) + private LocalDateTime createTime; + + @TableField(value = "update_time", fill = FieldFill.INSERT_UPDATE) + private LocalDateTime updateTime; + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getTemplateCode() { + return templateCode; + } + + public void setTemplateCode(String templateCode) { + this.templateCode = templateCode; + } + + public String getTemplateName() { + return templateName; + } + + public void setTemplateName(String templateName) { + this.templateName = templateName; + } + + public String getChannelType() { + return channelType; + } + + public void setChannelType(String channelType) { + this.channelType = channelType; + } + + public Integer getMsgType() { + return msgType; + } + + public void setMsgType(Integer msgType) { + this.msgType = msgType; + } + + public String getExternalId() { + return externalId; + } + + public void setExternalId(String externalId) { + this.externalId = externalId; + } + + public String getContentPattern() { + return contentPattern; + } + + public void setContentPattern(String contentPattern) { + this.contentPattern = contentPattern; + } + + public Integer getMsgCategory() { + return msgCategory; + } + + public void setMsgCategory(Integer msgCategory) { + this.msgCategory = msgCategory; + } + + public Integer getIsEnable() { + return isEnable; + } + + public void setIsEnable(Integer isEnable) { + this.isEnable = isEnable; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public LocalDateTime getCreateTime() { + return createTime; + } + + public void setCreateTime(LocalDateTime createTime) { + this.createTime = createTime; + } + + public LocalDateTime getUpdateTime() { + return updateTime; + } + + public void setUpdateTime(LocalDateTime updateTime) { + this.updateTime = updateTime; + } +} diff --git a/MessageHub/src/main/java/com/xiaowang/messagehub/mapper/MessageMapper.java b/MessageHub/src/main/java/com/xiaowang/messagehub/mapper/MessageMapper.java index 4477eefa..5d740ac9 100644 --- a/MessageHub/src/main/java/com/xiaowang/messagehub/mapper/MessageMapper.java +++ b/MessageHub/src/main/java/com/xiaowang/messagehub/mapper/MessageMapper.java @@ -1,10 +1,48 @@ package com.xiaowang.messagehub.mapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.xiaowang.messagehub.entity.Message; import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; +import org.apache.ibatis.annotations.Select; +import org.apache.ibatis.annotations.Update; + +import java.time.LocalDateTime; +import java.util.List; @Mapper public interface MessageMapper extends BaseMapper { + + @Select("SELECT * FROM message WHERE topic = #{topic} AND deleted = 0 ORDER BY create_time DESC LIMIT #{limit}") + List selectByTopicWithLimit(@Param("topic") String topic, @Param("limit") int limit); + + @Select("SELECT * FROM message WHERE status = #{status} AND deleted = 0 ORDER BY create_time DESC LIMIT #{limit}") + List selectByStatusWithLimit(@Param("status") Integer status, @Param("limit") int limit); + + @Select("SELECT * FROM message WHERE topic = #{topic} AND status = #{status} AND deleted = 0 ORDER BY create_time DESC") + List selectByTopicAndStatus(@Param("topic") String topic, @Param("status") Integer status); + + @Update("UPDATE message SET status = #{status}, update_time = #{updateTime} WHERE id IN (${ids}) AND deleted = 0") + int batchUpdateStatus(@Param("ids") String ids, @Param("status") Integer status, @Param("updateTime") LocalDateTime updateTime); + + @Select("SELECT COUNT(*) FROM message WHERE topic = #{topic} AND deleted = 0") + long countByTopic(@Param("topic") String topic); + + @Select("SELECT COUNT(*) FROM message WHERE status = #{status} AND deleted = 0") + long countByStatus(@Param("status") Integer status); + + @Select("SELECT * FROM message WHERE deleted = 0 ORDER BY create_time DESC") + IPage selectPage(Page page); + + @Select("SELECT * FROM message WHERE topic = #{topic} AND deleted = 0 ORDER BY create_time DESC") + IPage selectPageByTopic(Page page, @Param("topic") String topic); + + @Select("SELECT * FROM message WHERE create_time >= #{startTime} AND create_time <= #{endTime} AND deleted = 0 ORDER BY create_time DESC") + List selectByTimeRange(@Param("startTime") LocalDateTime startTime, @Param("endTime") LocalDateTime endTime); + + @Select("SELECT * FROM message WHERE content LIKE CONCAT('%', #{keyword}, '%') AND deleted = 0 ORDER BY create_time DESC LIMIT #{limit}") + List searchByContent(@Param("keyword") String keyword, @Param("limit") int limit); } diff --git a/MessageHub/src/main/java/com/xiaowang/messagehub/mapper/PushLogMapper.java b/MessageHub/src/main/java/com/xiaowang/messagehub/mapper/PushLogMapper.java new file mode 100644 index 00000000..94a5d155 --- /dev/null +++ b/MessageHub/src/main/java/com/xiaowang/messagehub/mapper/PushLogMapper.java @@ -0,0 +1,59 @@ +package com.xiaowang.messagehub.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.xiaowang.messagehub.entity.PushLog; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; +import org.apache.ibatis.annotations.Select; +import org.apache.ibatis.annotations.Update; + +import java.time.LocalDateTime; +import java.util.List; + +@Mapper +public interface PushLogMapper extends BaseMapper { + + @Select("SELECT * FROM push_log WHERE source_system = #{sourceSystem} ORDER BY create_time DESC LIMIT #{limit}") + List selectBySourceSystemWithLimit(@Param("sourceSystem") String sourceSystem, @Param("limit") int limit); + + @Select("SELECT * FROM push_log WHERE receiver = #{receiver} ORDER BY create_time DESC LIMIT #{limit}") + List selectByReceiverWithLimit(@Param("receiver") String receiver, @Param("limit") int limit); + + @Select("SELECT * FROM push_log WHERE channel_type = #{channelType} ORDER BY create_time DESC LIMIT #{limit}") + List selectByChannelTypeWithLimit(@Param("channelType") String channelType, @Param("limit") int limit); + + @Select("SELECT * FROM push_log WHERE status = #{status} ORDER BY create_time DESC LIMIT #{limit}") + List selectByStatusWithLimit(@Param("status") Integer status, @Param("limit") int limit); + + @Select("SELECT * FROM push_log WHERE source_system = #{sourceSystem} AND status = #{status} ORDER BY create_time DESC") + List selectBySourceSystemAndStatus(@Param("sourceSystem") String sourceSystem, @Param("status") Integer status); + + @Select("SELECT * FROM push_log WHERE unique_id = #{uniqueId}") + PushLog selectByUniqueId(@Param("uniqueId") String uniqueId); + + @Update("UPDATE push_log SET status = #{status}, retry_count = retry_count + 1, fail_reason = #{failReason} WHERE id = #{id}") + int updateRetryStatus(@Param("id") String id, @Param("status") Integer status, @Param("failReason") String failReason); + + @Update("UPDATE push_log SET send_time = #{sendTime} WHERE id = #{id}") + int updateSendTime(@Param("id") String id, @Param("sendTime") LocalDateTime sendTime); + + @Select("SELECT COUNT(*) FROM push_log WHERE source_system = #{sourceSystem}") + long countBySourceSystem(@Param("sourceSystem") String sourceSystem); + + @Select("SELECT COUNT(*) FROM push_log WHERE status = #{status}") + long countByStatus(@Param("status") Integer status); + + @Select("SELECT * FROM push_log ORDER BY create_time DESC") + IPage selectPage(Page page); + + @Select("SELECT * FROM push_log WHERE source_system = #{sourceSystem} ORDER BY create_time DESC") + IPage selectPageBySourceSystem(Page page, @Param("sourceSystem") String sourceSystem); + + @Select("SELECT * FROM push_log WHERE create_time >= #{startTime} AND create_time <= #{endTime} ORDER BY create_time DESC") + List selectByTimeRange(@Param("startTime") LocalDateTime startTime, @Param("endTime") LocalDateTime endTime); + + @Select("SELECT * FROM push_log WHERE final_content LIKE CONCAT('%', #{keyword}, '%') ORDER BY create_time DESC LIMIT #{limit}") + List searchByContent(@Param("keyword") String keyword, @Param("limit") int limit); +} diff --git a/MessageHub/src/main/java/com/xiaowang/messagehub/mapper/PushTemplateMapper.java b/MessageHub/src/main/java/com/xiaowang/messagehub/mapper/PushTemplateMapper.java new file mode 100644 index 00000000..59106d05 --- /dev/null +++ b/MessageHub/src/main/java/com/xiaowang/messagehub/mapper/PushTemplateMapper.java @@ -0,0 +1,46 @@ +package com.xiaowang.messagehub.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.xiaowang.messagehub.entity.PushTemplate; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; +import org.apache.ibatis.annotations.Select; +import org.apache.ibatis.annotations.Update; + +import java.util.List; + +@Mapper +public interface PushTemplateMapper extends BaseMapper { + + @Select("SELECT * FROM push_template WHERE template_code = #{templateCode}") + PushTemplate selectByTemplateCode(@Param("templateCode") String templateCode); + + @Select("SELECT * FROM push_template WHERE channel_type = #{channelType} ORDER BY create_time DESC") + List selectByChannelType(@Param("channelType") String channelType); + + @Select("SELECT * FROM push_template WHERE is_enable = 1 ORDER BY create_time DESC") + List selectEnabledTemplates(); + + @Select("SELECT * FROM push_template WHERE channel_type = #{channelType} AND is_enable = 1 ORDER BY create_time DESC") + List selectEnabledByChannelType(@Param("channelType") String channelType); + + @Update("UPDATE push_template SET is_enable = #{isEnable} WHERE id = #{id}") + int updateEnableStatus(@Param("id") Long id, @Param("isEnable") Integer isEnable); + + @Select("SELECT COUNT(*) FROM push_template WHERE channel_type = #{channelType}") + long countByChannelType(@Param("channelType") String channelType); + + @Select("SELECT COUNT(*) FROM push_template WHERE is_enable = 1") + long countEnabledTemplates(); + + @Select("SELECT * FROM push_template ORDER BY create_time DESC") + IPage selectPage(Page page); + + @Select("SELECT * FROM push_template WHERE channel_type = #{channelType} ORDER BY create_time DESC") + IPage selectPageByChannelType(Page page, @Param("channelType") String channelType); + + @Select("SELECT * FROM push_template WHERE template_name LIKE CONCAT('%', #{keyword}, '%') OR description LIKE CONCAT('%', #{keyword}, '%')") + List searchByKeyword(@Param("keyword") String keyword); +} diff --git a/MessageHub/src/main/resources/files/消息推送系统需求设计文档.docx b/MessageHub/src/main/resources/files/消息推送系统需求设计文档.docx new file mode 100644 index 00000000..802c6961 Binary files /dev/null and b/MessageHub/src/main/resources/files/消息推送系统需求设计文档.docx differ