ImGroupMapper.xml 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  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. <!--
  4. 这个文件是自动生成的。
  5. 不要修改此文件。所有改动将在下次重新自动生成时丢失。
  6. -->
  7. <mapper namespace="com.ym.mec.biz.dal.dao.ImGroupDao">
  8. <resultMap type="com.ym.mec.biz.dal.entity.ImGroup" id="ImGroup">
  9. <result column="id_" property="id" />
  10. <result column="name_" property="name" />
  11. <result column="introduce_" property="introduce" />
  12. <result column="member_num_" property="memberNum" />
  13. <result column="memo_" property="memo" />
  14. <result column="tags_" property="tags" />
  15. <result column="img_" property="img" />
  16. <result column="type_" property="type" />
  17. <result column="group_type_" property="groupType" />
  18. <result column="create_time_" property="createTime" />
  19. <result column="update_time_" property="updateTime" />
  20. <result column="tenant_id_" property="tenantId"/>
  21. </resultMap>
  22. <resultMap type="com.ym.mec.biz.dal.dto.ImGroupMemberDto" id="ImGroupMemberDto">
  23. <result column="id_" property="id" />
  24. <result column="im_group_id_" property="imGroupId" />
  25. <result column="user_id_" property="userId" />
  26. <result column="nickname_" property="nickname" />
  27. <result column="is_admin_" property="isAdmin" />
  28. <result column="role_type_" property="roleType" />
  29. <result column="create_time_" property="createTime" />
  30. <result column="update_time_" property="updateTime" />
  31. <result column="member_rank_setting_id_" property="memberRankSettingId" />
  32. <result column="subject_name_" property="subjectName" />
  33. <result column="subject_id_" property="subjectId" />
  34. <result column="username_" property="user.username" />
  35. <result column="avatar_" property="user.avatar" />
  36. <result column="phone_" property="user.phone" />
  37. <result column="group_nickname_" property="groupNickname" />
  38. </resultMap>
  39. <!-- 根据主键查询一条记录 -->
  40. <select id="get" resultMap="ImGroup" >
  41. SELECT * FROM im_group WHERE id_ = #{id}
  42. </select>
  43. <select id="getLocked" resultMap="ImGroup" >
  44. SELECT * FROM im_group WHERE id_ = #{id} for update
  45. </select>
  46. <!-- 全查询 -->
  47. <select id="findAll" resultMap="ImGroup">
  48. SELECT * FROM im_group where tenant_id_ = #{tenantId} ORDER BY id_
  49. </select>
  50. <!-- 向数据库增加一条记录 -->
  51. <insert id="insert" parameterType="com.ym.mec.biz.dal.entity.ImGroup" useGeneratedKeys="true" keyColumn="id" keyProperty="id">
  52. INSERT INTO im_group (id_,name_,introduce_,member_num_,memo_,tags_,img_,type_,create_time_,update_time_,tenant_id_,group_type_,school_id_)
  53. VALUES(#{id},#{name},#{introduce},#{memberNum},#{memo},#{tags},#{img},#{type},#{createTime},#{updateTime},#{tenantId},#{groupType},#{schoolId})
  54. </insert>
  55. <!-- 根据主键查询一条记录 -->
  56. <update id="update" parameterType="com.ym.mec.biz.dal.entity.ImGroup">
  57. UPDATE im_group <set>
  58. <if test="groupType != null">
  59. group_type_ = #{groupType},
  60. </if>
  61. <if test="memberNum != null">
  62. member_num_ = member_num_ + #{memberNum},
  63. </if>
  64. <if test="tags != null">
  65. tags_ = #{tags},
  66. </if>
  67. <if test="introduce != null">
  68. introduce_ = #{introduce},
  69. </if>
  70. <if test="updateTime != null">
  71. update_time_ = #{updateTime},
  72. </if>
  73. <if test="memo != null">
  74. memo_ = #{memo},
  75. </if>
  76. <if test="name != null">
  77. name_ = #{name},
  78. </if>
  79. <if test="img != null">
  80. img_ = #{img},
  81. </if>
  82. <if test="type != null">
  83. type_ = #{type},
  84. </if>
  85. </set> WHERE id_ = #{id} and tenant_id_ = #{tenantId}
  86. </update>
  87. <update id="updateNickname">
  88. UPDATE im_group_member SET nickname_ = #{nickName} WHERE user_id_ = #{userId}
  89. </update>
  90. <update id="updateUserFriendNickname">
  91. UPDATE im_user_friend SET friend_nickname_ = #{nickName} WHERE friend_id_ = #{userId};
  92. </update>
  93. <update id="updateMemberNum">
  94. UPDATE im_group ig
  95. LEFT JOIN (SELECT COUNT(id_) num_,im_group_id_ FROM im_group_member GROUP BY im_group_id_) igm ON ig.id_ = igm.im_group_id_
  96. SET member_num_ = igm.num_
  97. WHERE ig.id_ = igm.im_group_id_
  98. </update>
  99. <!-- 根据主键删除一条记录 -->
  100. <delete id="delete" >
  101. DELETE FROM im_group WHERE id_ = #{id}
  102. </delete>
  103. <sql id="queryPageSql">
  104. <where>
  105. <if test="userId != null">
  106. AND igm.user_id_ = #{userId}
  107. </if>
  108. <if test="search != null and search != ''">
  109. AND (ig.name_ like concat('%',#{search},'%') or ig.memo_ like concat('%',#{search},'%'))
  110. </if>
  111. <if test="ignoreIds != null and ignoreIds != ''">
  112. AND NOT FIND_IN_SET(ig.id_,#{ignoreIds})
  113. </if>
  114. <if test="targetIds != null and targetIds != ''">
  115. AND FIND_IN_SET(ig.id_,#{targetIds})
  116. </if>
  117. <if test="groupType != null">
  118. AND ig.group_type_ = #{groupType}
  119. </if>
  120. </where>
  121. </sql>
  122. <!-- 分页查询 -->
  123. <select id="queryPage" resultMap="ImGroup" parameterType="map">
  124. SELECT ig.* FROM im_group ig
  125. LEFT JOIN im_group_member igm ON igm.im_group_id_ = ig.id_
  126. <include refid="queryPageSql" />
  127. GROUP BY ig.id_
  128. ORDER BY id_
  129. <include refid="global.limit"/>
  130. </select>
  131. <!-- 查询当前表的总记录数 -->
  132. <select id="queryCount" resultType="int">
  133. SELECT COUNT(DISTINCT ig.id_) FROM im_group ig
  134. LEFT JOIN im_group_member igm ON igm.im_group_id_ = ig.id_
  135. <include refid="queryPageSql" />
  136. </select>
  137. <select id="queryByUserId" resultMap="ImGroup" parameterType="map">
  138. SELECT ig.* FROM im_group_member igm
  139. LEFT JOIN im_group ig ON igm.im_group_id_ = ig.id_
  140. where 1 =1
  141. <if test="userId != null">
  142. AND igm.user_id_ = #{userId}
  143. </if>
  144. <if test="search != null and search != ''">
  145. AND (ig.name_ like concat('%',#{search},'%') or ig.tags_ like concat('%',#{search},'%'))
  146. </if>
  147. <if test="groupType != null and groupType != ''">
  148. AND ig.group_type_ = #{groupType}
  149. </if>
  150. </select>
  151. <select id="queryMemberById" resultMap="ImGroupMemberDto">
  152. SELECT igm.*
  153. , u.avatar_
  154. , CASE WHEN find_in_set('STUDENT',u.user_type_) THEN u.username_ ELSE u.real_name_ END username_
  155. , IFNULL(NULLIF(u.username_, ''), u.real_name_) AS group_nickname_
  156. , u.real_name_
  157. , st.member_rank_setting_id_,s.name_ subject_name_,st.subject_id_list_ subject_id_
  158. FROM im_group_member igm
  159. LEFT JOIN sys_user u ON igm.user_id_ = u.id_
  160. LEFT JOIN student st ON st.user_id_ = u.id_
  161. LEFT JOIN `subject` s ON s.id_ = st.subject_id_list_
  162. WHERE igm.im_group_id_ = #{imGroupId}
  163. <if test="search != null and search != ''">
  164. AND (u.username_ like concat('%',#{search},'%') or u.real_name_ like concat('%',#{search},'%'))
  165. </if>
  166. </select>
  167. <select id="queryMember" resultMap="ImGroupMemberDto" parameterType="map">
  168. SELECT igm.*,u.avatar_,CASE WHEN find_in_set('STUDENT',u.user_type_) THEN u.username_ ELSE u.real_name_ END username_
  169. FROM im_group_member igm left join sys_user u on igm.user_id_ = u.id_
  170. WHERE igm.user_id_ = #{userId}
  171. <if test="imGroupId != null and imGroupId != ''">
  172. AND igm.im_group_id_ = #{imGroupId}
  173. </if>
  174. <if test="imGroupId == null or imGroupId == ''">
  175. LIMIT 1
  176. </if>
  177. </select>
  178. <resultMap id="NameDto" type="com.ym.mec.biz.dal.dto.NameDto">
  179. <result property="id" column="id_" />
  180. <result property="name" column="name_" />
  181. <result property="type" column="type_"/>
  182. </resultMap>
  183. <select id="queryNameByIds" resultMap="NameDto">
  184. select id_,name_,3 type_ from im_group where FIND_IN_SET(id_,#{ids})
  185. </select>
  186. <select id="queryByUserIdV2" resultMap="ImGroup">
  187. SELECT ig.* FROM im_group_member igm
  188. LEFT JOIN im_group ig ON igm.im_group_id_ = ig.id_
  189. left join class_group cg on cg.id_ = ig.id_
  190. left join music_group mg on mg.id_ = cg.music_group_id_
  191. where 1 =1 and ig.group_type_ in ('NORMAL','MIX')
  192. <if test="userId != null">
  193. AND igm.user_id_ = #{userId}
  194. </if>
  195. <if test="search != null and search != ''">
  196. AND (ig.name_ like concat('%',#{search},'%') or ig.tags_ like concat('%',#{search},'%'))
  197. </if>
  198. <if test="groupType != null and groupType != ''">
  199. AND ig.group_type_ = #{groupType}
  200. </if>
  201. <if test="musicGroupId != null and musicGroupId != ''">
  202. and mg.id_ = #{musicGroupId}
  203. </if>
  204. <if test="classType != null and classType != ''">
  205. AND cg.type_ = #{classType}
  206. </if>
  207. </select>
  208. <select id="queryMemberByIdV2" resultMap="ImGroupMemberDto">
  209. SELECT igm.*,u.avatar_,CASE WHEN find_in_set('STUDENT',u.user_type_) THEN u.username_ ELSE u.real_name_ END username_,
  210. st.member_rank_setting_id_,s.name_ subject_name_,st.subject_id_list_ subject_id_
  211. FROM im_group_member igm
  212. LEFT JOIN sys_user u ON igm.user_id_ = u.id_
  213. LEFT JOIN student st ON st.user_id_ = u.id_
  214. LEFT JOIN `subject` s ON s.id_ = st.subject_id_list_
  215. WHERE igm.im_group_id_ = #{imGroupId} and st.user_id_ is not null
  216. <if test="search != null">
  217. and (u.real_name_ like concat('%',#{search},'%'))
  218. </if>
  219. <if test="subjectId != null">
  220. and st.subject_id_list_ = #{subjectId}
  221. </if>
  222. <if test="vipFlag != null">
  223. <if test="vipFlag">
  224. and st.member_rank_setting_id_ is not null
  225. </if>
  226. <if test="vipFlag == false">
  227. and st.member_rank_setting_id_ is null
  228. </if>
  229. </if>
  230. </select>
  231. <select id="queryBySchoolId" resultMap="ImGroup">
  232. SELECT ig.* FROM im_group ig where school_id_ = #{schoolId} limit 1
  233. </select>
  234. <select id="getByIds" resultMap="ImGroup">
  235. select ig.* FROM im_group ig where ig.id_ in
  236. <foreach collection="musicGroupIds" separator="," item="item" open="(" close=")">
  237. #{item}
  238. </foreach>
  239. </select>
  240. <update id="addMemberNum">
  241. update im_group set member_num_ = member_num_ + #{num} where id_ in
  242. <foreach collection="imGroupIds" close=")" item="item" open="(" separator=",">
  243. #{item}
  244. </foreach>
  245. </update>
  246. <update id="updateMember">
  247. update im_group set member_num_ = #{num} where id_ = #{imGroupId}
  248. </update>
  249. <select id="getByUserId" resultMap="ImGroup">
  250. SELECT ig.* FROM im_group_member igm
  251. LEFT JOIN im_group ig ON igm.im_group_id_ = ig.id_
  252. where 1 =1
  253. <if test="param.userId != null">
  254. AND igm.user_id_ = #{param.userId}
  255. </if>
  256. <if test="param.keyword != null and param.keyword != ''">
  257. AND (ig.name_ like concat('%',#{param.keyword},'%') or ig.tags_ like concat('%',#{param.keyword},'%'))
  258. </if>
  259. <if test="param.musicGroupId != null and param.musicGroupId != ''">
  260. and ig.id_ = #{param.musicGroupId}
  261. </if>
  262. <if test="param.groupType != null">
  263. and ig.group_type_ = #{param.groupType.code}
  264. </if>
  265. </select>
  266. </mapper>