From c9d04bc519b73f7fc4841c34e2f15fca9db7aad2 Mon Sep 17 00:00:00 2001
From: xiangpei <xiangpei@timesnew.cn>
Date: 星期五, 31 五月 2024 14:08:30 +0800
Subject: [PATCH] 重构:service、mapper plus化,xml删除多余sql

---
 src/main/resources/mapper/MessageMapper.xml |  203 ++++++++++----------------------------------------
 1 files changed, 40 insertions(+), 163 deletions(-)

diff --git a/src/main/resources/mapper/MessageMapper.xml b/src/main/resources/mapper/MessageMapper.xml
index 886798f..e702a09 100644
--- a/src/main/resources/mapper/MessageMapper.xml
+++ b/src/main/resources/mapper/MessageMapper.xml
@@ -1,172 +1,49 @@
 <?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.ycl.jxkg.mapper.MessageMapper">
-  <resultMap id="BaseResultMap" type="com.ycl.jxkg.domain.Message">
-    <id column="id" jdbcType="INTEGER" property="id" />
-    <result column="title" jdbcType="VARCHAR" property="title" />
-    <result column="content" jdbcType="VARCHAR" property="content" />
-    <result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
-    <result column="send_user_id" jdbcType="INTEGER" property="sendUserId" />
-    <result column="send_user_name" jdbcType="VARCHAR" property="sendUserName" />
-    <result column="send_real_name" jdbcType="VARCHAR" property="sendRealName" />
-    <result column="receive_user_count" jdbcType="INTEGER" property="receiveUserCount" />
-    <result column="read_count" jdbcType="INTEGER" property="readCount" />
-  </resultMap>
-  <sql id="Base_Column_List">
-    id, title, content, create_time, send_user_id, send_user_name, send_real_name, receive_user_count,
+    <resultMap id="BaseResultMap" type="com.ycl.jxkg.domain.Message">
+        <id column="id" jdbcType="INTEGER" property="id"/>
+        <result column="title" jdbcType="VARCHAR" property="title"/>
+        <result column="content" jdbcType="VARCHAR" property="content"/>
+        <result column="create_time" jdbcType="TIMESTAMP" property="createTime"/>
+        <result column="send_user_id" jdbcType="INTEGER" property="sendUserId"/>
+        <result column="send_user_name" jdbcType="VARCHAR" property="sendUserName"/>
+        <result column="send_real_name" jdbcType="VARCHAR" property="sendRealName"/>
+        <result column="receive_user_count" jdbcType="INTEGER" property="receiveUserCount"/>
+        <result column="read_count" jdbcType="INTEGER" property="readCount"/>
+    </resultMap>
+    <sql id="Base_Column_List">
+        id
+        , title, content, create_time, send_user_id, send_user_name, send_real_name, receive_user_count,
     read_count
-  </sql>
-  <select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
-    select
-    <include refid="Base_Column_List" />
-    from t_message
-    where id = #{id,jdbcType=INTEGER}
-  </select>
-  <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
-    delete from t_message
-    where id = #{id,jdbcType=INTEGER}
-  </delete>
-  <insert id="insert" parameterType="com.ycl.jxkg.domain.Message" useGeneratedKeys="true" keyProperty="id">
-    insert into t_message (id, title, content,
-      create_time, send_user_id, send_user_name,
-      send_real_name, receive_user_count, read_count
-      )
-    values (#{id,jdbcType=INTEGER}, #{title,jdbcType=VARCHAR}, #{content,jdbcType=VARCHAR},
-      #{createTime,jdbcType=TIMESTAMP}, #{sendUserId,jdbcType=INTEGER}, #{sendUserName,jdbcType=VARCHAR},
-      #{sendRealName,jdbcType=VARCHAR}, #{receiveUserCount,jdbcType=INTEGER}, #{readCount,jdbcType=INTEGER}
-      )
-  </insert>
-  <insert id="insertSelective" parameterType="com.ycl.jxkg.domain.Message" useGeneratedKeys="true" keyProperty="id">
-    insert into t_message
-    <trim prefix="(" suffix=")" suffixOverrides=",">
-      <if test="id != null">
-        id,
-      </if>
-      <if test="title != null">
-        title,
-      </if>
-      <if test="content != null">
-        content,
-      </if>
-      <if test="createTime != null">
-        create_time,
-      </if>
-      <if test="sendUserId != null">
-        send_user_id,
-      </if>
-      <if test="sendUserName != null">
-        send_user_name,
-      </if>
-      <if test="sendRealName != null">
-        send_real_name,
-      </if>
-      <if test="receiveUserCount != null">
-        receive_user_count,
-      </if>
-      <if test="readCount != null">
-        read_count,
-      </if>
-    </trim>
-    <trim prefix="values (" suffix=")" suffixOverrides=",">
-      <if test="id != null">
-        #{id,jdbcType=INTEGER},
-      </if>
-      <if test="title != null">
-        #{title,jdbcType=VARCHAR},
-      </if>
-      <if test="content != null">
-        #{content,jdbcType=VARCHAR},
-      </if>
-      <if test="createTime != null">
-        #{createTime,jdbcType=TIMESTAMP},
-      </if>
-      <if test="sendUserId != null">
-        #{sendUserId,jdbcType=INTEGER},
-      </if>
-      <if test="sendUserName != null">
-        #{sendUserName,jdbcType=VARCHAR},
-      </if>
-      <if test="sendRealName != null">
-        #{sendRealName,jdbcType=VARCHAR},
-      </if>
-      <if test="receiveUserCount != null">
-        #{receiveUserCount,jdbcType=INTEGER},
-      </if>
-      <if test="readCount != null">
-        #{readCount,jdbcType=INTEGER},
-      </if>
-    </trim>
-  </insert>
-  <update id="updateByPrimaryKeySelective" parameterType="com.ycl.jxkg.domain.Message">
-    update t_message
-    <set>
-      <if test="title != null">
-        title = #{title,jdbcType=VARCHAR},
-      </if>
-      <if test="content != null">
-        content = #{content,jdbcType=VARCHAR},
-      </if>
-      <if test="createTime != null">
-        create_time = #{createTime,jdbcType=TIMESTAMP},
-      </if>
-      <if test="sendUserId != null">
-        send_user_id = #{sendUserId,jdbcType=INTEGER},
-      </if>
-      <if test="sendUserName != null">
-        send_user_name = #{sendUserName,jdbcType=VARCHAR},
-      </if>
-      <if test="sendRealName != null">
-        send_real_name = #{sendRealName,jdbcType=VARCHAR},
-      </if>
-      <if test="receiveUserCount != null">
-        receive_user_count = #{receiveUserCount,jdbcType=INTEGER},
-      </if>
-      <if test="readCount != null">
-        read_count = #{readCount,jdbcType=INTEGER},
-      </if>
-    </set>
-    where id = #{id,jdbcType=INTEGER}
-  </update>
-  <update id="updateByPrimaryKey" parameterType="com.ycl.jxkg.domain.Message">
-    update t_message
-    set title = #{title,jdbcType=VARCHAR},
-      content = #{content,jdbcType=VARCHAR},
-      create_time = #{createTime,jdbcType=TIMESTAMP},
-      send_user_id = #{sendUserId,jdbcType=INTEGER},
-      send_user_name = #{sendUserName,jdbcType=VARCHAR},
-      send_real_name = #{sendRealName,jdbcType=VARCHAR},
-      receive_user_count = #{receiveUserCount,jdbcType=INTEGER},
-      read_count = #{readCount,jdbcType=INTEGER}
-    where id = #{id,jdbcType=INTEGER}
-  </update>
+    </sql>
 
+    <select id="page" resultMap="BaseResultMap" parameterType="com.ycl.jxkg.vo.admin.message.MessagePageRequestVO">
+        select
+        <include refid="Base_Column_List"/>
+        from t_message
+        <where>
+            <if test="sendUserName != null">
+                and send_user_name like concat('%',#{sendUserName},'%')
+            </if>
+        </where>
+    </select>
 
+    <select id="selectByIds" resultMap="BaseResultMap">
+        select
+        <include refid="Base_Column_List"/>
+        from t_message
+        where id in
+        <foreach item="id" collection="list" open="(" separator="," close=")">
+            #{id}
+        </foreach>
+    </select>
 
-
-  <select id="page" resultMap="BaseResultMap" parameterType="com.ycl.jxkg.vo.admin.message.MessagePageRequestVO">
-    select
-    <include refid="Base_Column_List" />
-    from t_message
-    <where>
-         <if test="sendUserName != null">
-           and send_user_name  like concat('%',#{sendUserName},'%')
-         </if>
-    </where>
-  </select>
-
-  <select id="selectByIds" resultMap="BaseResultMap">
-    select
-    <include refid="Base_Column_List" />
-    from t_message
-    where  id  in
-    <foreach item="id" collection="list" open="(" separator=","  close=")">
-      #{id}
-    </foreach>
-  </select>
-
-  <update id="readAdd" parameterType="java.lang.Integer">
-      UPDATE t_message SET read_count = read_count + 1
-      WHERE id= #{id} and read_count = (SELECT m.read_count from ( SELECT read_count FROM t_message WHERE id = #{id} ) m)
-  </update>
+    <update id="readAdd" parameterType="java.lang.Integer">
+        UPDATE t_message
+        SET read_count = read_count + 1
+        WHERE id = #{id}
+          and read_count = (SELECT m.read_count from (SELECT read_count FROM t_message WHERE id = #{id}) m)
+    </update>
 
 </mapper>

--
Gitblit v1.8.0