ChatMsgUserMapper.xml 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  3. <mapper namespace="com.kede.common.dao.ChatMsgUserMapper">
  4. <resultMap type="com.kede.common.model.ChatMsgUser" id="ChatMsgUserMap">
  5. <result property="id" column="id" jdbcType="INTEGER"/>
  6. <result property="userId" column="user_id" jdbcType="VARCHAR"/>
  7. <result property="name" column="name" jdbcType="VARCHAR"/>
  8. <result property="type" column="type" jdbcType="INTEGER"/>
  9. <result property="createTime" column="create_time" jdbcType="TIMESTAMP"/>
  10. </resultMap>
  11. <sql id="ChatMsgUserAllSql">
  12. id, user_id, name, type, create_time
  13. </sql>
  14. <!--查询单个-->
  15. <select id="selectById" resultMap="ChatMsgUserMap">
  16. select
  17. <include refid="ChatMsgUserAllSql"/>
  18. from chat_msg_user
  19. where id = #{id}
  20. </select>
  21. <!--新增所有列-->
  22. <insert id="insert" keyProperty="id" useGeneratedKeys="true">
  23. insert into chat_msg_user(user_id, name, type, create_time)
  24. values (#{userId}, #{name}, #{type}, #{createTime})
  25. </insert>
  26. <insert id="insertBatch">
  27. insert into chat_msg_user(user_id, name, type, create_time)
  28. values
  29. <foreach collection="entities" item="entity" separator=",">
  30. (#{entity.userId}, #{entity.name}, #{entity.type}, #{entity.createTime})
  31. </foreach>
  32. </insert>
  33. <insert id="insertOrUpdateBatch" keyProperty="id" useGeneratedKeys="true">
  34. insert into chat_msg_user(user_id, name, type, create_time)
  35. values
  36. <foreach collection="entities" item="entity" separator=",">
  37. (#{entity.userId}, #{entity.name}, #{entity.type}, #{entity.createTime})
  38. </foreach>
  39. on duplicate key update
  40. user_id = values(user_id),
  41. name = values(name),
  42. type = values(type),
  43. create_time = values(create_time)
  44. </insert>
  45. <!--通过主键修改数据-->
  46. <update id="update">
  47. update chat_msg_user
  48. <set>
  49. <if test="userId != null and userId != ''">
  50. user_id = #{userId},
  51. </if>
  52. <if test="name != null and name != ''">
  53. name = #{name},
  54. </if>
  55. <if test="type != null">
  56. type = #{type},
  57. </if>
  58. <if test="createTime != null">
  59. create_time = #{createTime},
  60. </if>
  61. </set>
  62. where id = #{id}
  63. </update>
  64. <!--查询指定行数据-->
  65. <select id="findChatMsgUserList" resultMap="ChatMsgUserMap">
  66. select
  67. <include refid="ChatMsgUserAllSql"/>
  68. from chat_msg_user
  69. <where>
  70. <if test="id != null">
  71. and id = #{id}
  72. </if>
  73. <if test="userId != null and userId != ''">
  74. and user_id = #{userId}
  75. </if>
  76. <if test="name != null and name != ''">
  77. and name = #{name}
  78. </if>
  79. <if test="type != null">
  80. and type = #{type}
  81. </if>
  82. <if test="createTime != null">
  83. and create_time = #{createTime}
  84. </if>
  85. </where>
  86. <if test="page_sql != null">
  87. ${page_sql}
  88. </if>
  89. </select>
  90. <!--统计总行数-->
  91. <select id="findChatMsgUserCount" resultType="java.lang.Integer">
  92. select count(1)
  93. from chat_msg_user
  94. <where>
  95. <if test="id != null">
  96. and id = #{id}
  97. </if>
  98. <if test="userId != null and userId != ''">
  99. and user_id = #{userId}
  100. </if>
  101. <if test="name != null and name != ''">
  102. and name = #{name}
  103. </if>
  104. <if test="type != null">
  105. and type = #{type}
  106. </if>
  107. <if test="createTime != null">
  108. and create_time = #{createTime}
  109. </if>
  110. </where>
  111. </select>
  112. <!--通过主键删除-->
  113. <delete id="deleteById">
  114. delete
  115. from chat_msg_user
  116. where id = #{id}
  117. </delete>
  118. <delete id="deleteByUserId">
  119. delete
  120. from chat_msg_user
  121. where chat_msg_user.user_id = #{id}
  122. </delete>
  123. <select id="selectByUserId" resultMap="ChatMsgUserMap">
  124. select
  125. <include refid="ChatMsgUserAllSql"/>
  126. from chat_msg_user
  127. where user_id = #{id}
  128. </select>
  129. <select id="getUserList" resultMap="ChatMsgUserMap">
  130. select
  131. <include refid="ChatMsgUserAllSql"/>
  132. from chat_msg_user
  133. <where>
  134. <if test="type != null">
  135. and type = #{type}
  136. </if>
  137. <if test="provinceType != null">
  138. and province_type = #{provinceType}
  139. </if>
  140. </where>
  141. </select>
  142. <select id="selectMyIdByUser" resultMap="ChatMsgUserMap">
  143. select x.user_id,b.name
  144. from (select tolist user_id
  145. from chat_msg
  146. where from_id = #{userId} and type=0
  147. <if test="startTime != null and startTime != ''">
  148. and msgtime between #{startTime} and #{endTime}
  149. </if>
  150. union
  151. select from_id user_id
  152. from chat_msg
  153. where find_in_set(#{userId},tolist) and type=0
  154. <if test="startTime != null and startTime != ''">
  155. and msgtime between #{startTime} and #{endTime}
  156. </if>
  157. )x left join chat_msg_user b on x.user_id=b.user_id
  158. </select>
  159. <select id="selectMyIdByRoom" resultType="com.kede.common.model.ChatMsgUser">
  160. select x.roomid userId,b.name
  161. from (select roomid
  162. from chat_msg
  163. where from_id = #{userId} and type=1
  164. <if test="startTime != null and startTime != ''">
  165. and msgtime between #{startTime} and #{endTime}
  166. </if>
  167. union
  168. select roomid
  169. from chat_msg
  170. where find_in_set(#{userId},tolist) and type=1
  171. <if test="startTime != null and startTime != ''">
  172. and msgtime between #{startTime} and #{endTime}
  173. </if>
  174. )x left join chat_msg_user b on x.roomid=b.user_id
  175. </select>
  176. </mapper>