Przeglądaj źródła

微信会话内容存储获取优化

anderx 6 miesięcy temu
rodzic
commit
f63bdae294

+ 85 - 0
src/main/java/com/kede/common/dao/ChatMsgOptimizeMapper.java

@@ -0,0 +1,85 @@
+package com.kede.common.dao;
+
+import com.kede.common.model.ChatMsgOptimize;
+import org.apache.ibatis.annotations.Param;
+import org.springframework.data.domain.Pageable;
+
+import java.util.List;
+
+/**
+ * 微信会话存储优化表(只存储2天的编号防止)(ChatMsgOptimize)表数据库访问层
+ *
+ * @author makejava
+ * @since 2025-06-20 15:29:39
+ */
+public interface ChatMsgOptimizeMapper {
+
+    /**
+     * 通过ID查询单条数据
+     *
+     * @param msgid 主键
+     * @return 实例对象
+     */
+    ChatMsgOptimize selectById(String msgid);
+
+
+    /**
+     * 查询指定行数据
+     *
+     * @param chatMsgOptimize 查询条件
+     * @param pageable        分页对象
+     * @return 对象列表
+     */
+    List<ChatMsgOptimize> findChatMsgOptimizeList(ChatMsgOptimize chatMsgOptimize);
+
+    /**
+     * 统计总行数
+     *
+     * @param chatMsgOptimize 查询条件
+     * @return 总行数
+     */
+    int findChatMsgOptimizeCount(ChatMsgOptimize chatMsgOptimize);
+
+    /**
+     * 新增数据
+     *
+     * @param chatMsgOptimize 实例对象
+     * @return 影响行数
+     */
+    int insert(ChatMsgOptimize chatMsgOptimize);
+
+    /**
+     * 批量新增数据(MyBatis原生foreach方法)
+     *
+     * @param entities List<ChatMsgOptimize> 实例对象列表
+     * @return 影响行数
+     */
+    int insertBatch(@Param("entities") List<ChatMsgOptimize> entities);
+
+    /**
+     * 批量新增或按主键更新数据(MyBatis原生foreach方法)
+     *
+     * @param entities List<ChatMsgOptimize> 实例对象列表
+     * @return 影响行数
+     * @throws org.springframework.jdbc.BadSqlGrammarException 入参是空List的时候会抛SQL语句错误的异常,请自行校验入参
+     */
+    int insertOrUpdateBatch(@Param("entities") List<ChatMsgOptimize> entities);
+
+    /**
+     * 修改数据
+     *
+     * @param chatMsgOptimize 实例对象
+     * @return 影响行数
+     */
+    int update(ChatMsgOptimize chatMsgOptimize);
+
+    /**
+     * 通过主键删除数据
+     *
+     * @param msgid 主键
+     * @return 影响行数
+     */
+    int deleteById(String msgid);
+
+}
+

+ 98 - 0
src/main/java/com/kede/common/mapper/ChatMsgOptimizeMapper.xml

@@ -0,0 +1,98 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.kede.common.dao.ChatMsgOptimizeMapper">
+
+    <resultMap type="com.kede.common.model.ChatMsgOptimize" id="ChatMsgOptimizeMap">
+        <result property="msgid" column="msgid" jdbcType="VARCHAR"/>
+        <result property="msgtime" column="msgtime" jdbcType="TIMESTAMP"/>
+    </resultMap>
+
+    <sql id="ChatMsgOptimizeAllSql">
+        msgid, msgtime
+    </sql>
+
+    <!--查询单个-->
+    <select id="selectById" resultMap="ChatMsgOptimizeMap">
+        select
+        <include refid="ChatMsgOptimizeAllSql"/>
+        from chat_msg_optimize
+        where msgid = #{msgid}
+    </select>
+
+    <!--新增所有列-->
+    <insert id="insert" keyProperty="msgid" useGeneratedKeys="true">
+        insert into chat_msg_optimize(msgtime)
+        values (#{msgtime})
+    </insert>
+
+    <insert id="insertBatch">
+        insert into chat_msg_optimize(msgtime)
+        values
+        <foreach collection="entities" item="entity" separator=",">
+            (#{entity.msgtime})
+        </foreach>
+    </insert>
+
+    <insert id="insertOrUpdateBatch" keyProperty="msgid" useGeneratedKeys="true">
+        insert into chat_msg_optimize(msgtime)
+        values
+        <foreach collection="entities" item="entity" separator=",">
+            (#{entity.msgtime})
+        </foreach>
+        on duplicate key update
+        msgtime = values(msgtime)
+    </insert>
+
+    <!--通过主键修改数据-->
+    <update id="update">
+        update chat_msg_optimize
+        <set>
+            <if test="msgtime != null">
+                msgtime = #{msgtime},
+            </if>
+        </set>
+        where msgid = #{msgid}
+    </update>
+
+    <!--查询指定行数据-->
+    <select id="findChatMsgOptimizeList" resultMap="ChatMsgOptimizeMap">
+        select
+        <include refid="ChatMsgOptimizeAllSql"/>
+
+        from chat_msg_optimize
+        <where>
+            <if test="msgid != null and msgid != ''">
+                and msgid = #{msgid}
+            </if>
+            <if test="msgtime != null">
+                and msgtime = #{msgtime}
+            </if>
+        </where>
+        <if test="page_sql != null">
+            ${page_sql}
+        </if>
+    </select>
+
+    <!--统计总行数-->
+    <select id="findChatMsgOptimizeCount" resultType="java.lang.Integer">
+        select count(1)
+        from chat_msg_optimize
+        <where>
+            <if test="msgid != null and msgid != ''">
+                and msgid = #{msgid}
+            </if>
+            <if test="msgtime != null">
+                and msgtime = #{msgtime}
+            </if>
+        </where>
+    </select>
+
+    <!--通过主键删除-->
+    <delete id="deleteById">
+        delete
+        from chat_msg_optimize
+        where msgid = #{msgid}
+    </delete>
+
+</mapper>
+

+ 42 - 0
src/main/java/com/kede/common/model/ChatMsgOptimize.java

@@ -0,0 +1,42 @@
+package com.kede.common.model;
+
+import java.util.Date;
+import java.io.Serializable;
+
+
+/**
+ * 微信会话存储优化表(只存储2天的编号防止)(ChatMsgOptimize)实体类
+ *
+ * @author makejava
+ * @since 2025-06-20 15:29:39
+ */
+public class ChatMsgOptimize implements Serializable {
+    private static final long serialVersionUID = 706623454382250699L;
+    /**
+     * 会话信息编号
+     */
+    private String msgid;
+    /**
+     * 消息发送时间戳
+     */
+    private Date msgtime;
+
+
+    public String getMsgid() {
+        return msgid;
+    }
+
+    public void setMsgid(String msgid) {
+        this.msgid = msgid;
+    }
+
+    public Date getMsgtime() {
+        return msgtime;
+    }
+
+    public void setMsgtime(Date msgtime) {
+        this.msgtime = msgtime;
+    }
+
+}
+