数据库实体类以及数据测试

This commit is contained in:
xiaowang
2026-02-10 21:59:41 +08:00
parent 784232eb50
commit da7a7b9889
6 changed files with 443 additions and 0 deletions
@@ -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;
}
}
@@ -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;
}
}
@@ -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<Message> {
@Select("SELECT * FROM message WHERE topic = #{topic} AND deleted = 0 ORDER BY create_time DESC LIMIT #{limit}")
List<Message> 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<Message> 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<Message> 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<Message> selectPage(Page<Message> page);
@Select("SELECT * FROM message WHERE topic = #{topic} AND deleted = 0 ORDER BY create_time DESC")
IPage<Message> selectPageByTopic(Page<Message> 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<Message> 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<Message> searchByContent(@Param("keyword") String keyword, @Param("limit") int limit);
}
@@ -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<PushLog> {
@Select("SELECT * FROM push_log WHERE source_system = #{sourceSystem} ORDER BY create_time DESC LIMIT #{limit}")
List<PushLog> 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<PushLog> 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<PushLog> 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<PushLog> 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<PushLog> 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<PushLog> selectPage(Page<PushLog> page);
@Select("SELECT * FROM push_log WHERE source_system = #{sourceSystem} ORDER BY create_time DESC")
IPage<PushLog> selectPageBySourceSystem(Page<PushLog> page, @Param("sourceSystem") String sourceSystem);
@Select("SELECT * FROM push_log WHERE create_time >= #{startTime} AND create_time <= #{endTime} ORDER BY create_time DESC")
List<PushLog> 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<PushLog> searchByContent(@Param("keyword") String keyword, @Param("limit") int limit);
}
@@ -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<PushTemplate> {
@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<PushTemplate> selectByChannelType(@Param("channelType") String channelType);
@Select("SELECT * FROM push_template WHERE is_enable = 1 ORDER BY create_time DESC")
List<PushTemplate> selectEnabledTemplates();
@Select("SELECT * FROM push_template WHERE channel_type = #{channelType} AND is_enable = 1 ORDER BY create_time DESC")
List<PushTemplate> 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<PushTemplate> selectPage(Page<PushTemplate> page);
@Select("SELECT * FROM push_template WHERE channel_type = #{channelType} ORDER BY create_time DESC")
IPage<PushTemplate> selectPageByChannelType(Page<PushTemplate> page, @Param("channelType") String channelType);
@Select("SELECT * FROM push_template WHERE template_name LIKE CONCAT('%', #{keyword}, '%') OR description LIKE CONCAT('%', #{keyword}, '%')")
List<PushTemplate> searchByKeyword(@Param("keyword") String keyword);
}