ChatMsgUserMapper.xml 6.8 KB

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