ImGroupMapper.xml 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  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. </resultMap>
  38. <!-- 根据主键查询一条记录 -->
  39. <select id="get" resultMap="ImGroup" >
  40. SELECT * FROM im_group WHERE id_ = #{id}
  41. </select>
  42. <select id="getLocked" resultMap="ImGroup" >
  43. SELECT * FROM im_group WHERE id_ = #{id} for update
  44. </select>
  45. <!-- 全查询 -->
  46. <select id="findAll" resultMap="ImGroup">
  47. SELECT * FROM im_group where tenant_id_ = #{tenantId} ORDER BY id_
  48. </select>
  49. <!-- 向数据库增加一条记录 -->
  50. <insert id="insert" parameterType="com.ym.mec.biz.dal.entity.ImGroup" useGeneratedKeys="true" keyColumn="id" keyProperty="id">
  51. INSERT INTO im_group (id_,name_,introduce_,member_num_,memo_,tags_,img_,type_,create_time_,update_time_,tenant_id_,group_type_)
  52. VALUES(#{id},#{name},#{introduce},#{memberNum},#{memo},#{tags},#{img},#{type},#{createTime},#{updateTime},#{tenantId},#{groupType})
  53. </insert>
  54. <!-- 根据主键查询一条记录 -->
  55. <update id="update" parameterType="com.ym.mec.biz.dal.entity.ImGroup">
  56. UPDATE im_group <set>
  57. <if test="groupType != null">
  58. group_type_ = #{groupType},
  59. </if>
  60. <if test="memberNum != null">
  61. member_num_ = member_num_ + #{memberNum},
  62. </if>
  63. <if test="tags != null">
  64. tags_ = #{tags},
  65. </if>
  66. <if test="introduce != null">
  67. introduce_ = #{introduce},
  68. </if>
  69. <if test="updateTime != null">
  70. update_time_ = #{updateTime},
  71. </if>
  72. <if test="memo != null">
  73. memo_ = #{memo},
  74. </if>
  75. <if test="name != null">
  76. name_ = #{name},
  77. </if>
  78. <if test="img != null">
  79. img_ = #{img},
  80. </if>
  81. <if test="type != null">
  82. type_ = #{type},
  83. </if>
  84. </set> WHERE id_ = #{id} and tenant_id_ = #{tenantId}
  85. </update>
  86. <update id="updateNickname">
  87. UPDATE im_group_member SET nickname_ = #{nickName} WHERE user_id_ = #{userId}
  88. </update>
  89. <update id="updateUserFriendNickname">
  90. UPDATE im_user_friend SET friend_nickname_ = #{nickName} WHERE friend_id_ = #{userId};
  91. </update>
  92. <update id="updateMemberNum">
  93. UPDATE im_group ig
  94. 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_
  95. SET member_num_ = igm.num_
  96. WHERE ig.id_ = igm.im_group_id_
  97. </update>
  98. <!-- 根据主键删除一条记录 -->
  99. <delete id="delete" >
  100. DELETE FROM im_group WHERE id_ = #{id}
  101. </delete>
  102. <sql id="queryPageSql">
  103. <where>
  104. <if test="userId != null">
  105. AND igm.user_id_ = #{userId}
  106. </if>
  107. <if test="search != null and search != ''">
  108. AND (ig.name_ like concat('%',#{search},'%') or ig.memo_ like concat('%',#{search},'%'))
  109. </if>
  110. <if test="ignoreIds != null and ignoreIds != ''">
  111. AND NOT FIND_IN_SET(ig.id_,#{ignoreIds})
  112. </if>
  113. <if test="targetIds != null and targetIds != ''">
  114. AND FIND_IN_SET(ig.id_,#{targetIds})
  115. </if>
  116. <if test="groupType != null">
  117. AND ig.group_type_ = #{groupType}
  118. </if>
  119. </where>
  120. </sql>
  121. <!-- 分页查询 -->
  122. <select id="queryPage" resultMap="ImGroup" parameterType="map">
  123. SELECT ig.* FROM im_group ig
  124. LEFT JOIN im_group_member igm ON igm.im_group_id_ = ig.id_
  125. <include refid="queryPageSql" />
  126. GROUP BY ig.id_
  127. ORDER BY id_
  128. <include refid="global.limit"/>
  129. </select>
  130. <!-- 查询当前表的总记录数 -->
  131. <select id="queryCount" resultType="int">
  132. SELECT COUNT(DISTINCT ig.id_) FROM im_group ig
  133. LEFT JOIN im_group_member igm ON igm.im_group_id_ = ig.id_
  134. <include refid="queryPageSql" />
  135. </select>
  136. <select id="queryByUserId" resultMap="ImGroup" parameterType="map">
  137. SELECT ig.* FROM im_group_member igm
  138. LEFT JOIN im_group ig ON igm.im_group_id_ = ig.id_
  139. where 1 =1
  140. <if test="userId != null">
  141. AND igm.user_id_ = #{userId}
  142. </if>
  143. <if test="search != null and search != ''">
  144. AND (ig.name_ like concat('%',#{search},'%') or ig.tags_ like concat('%',#{search},'%'))
  145. </if>
  146. <if test="groupType != null and groupType != ''">
  147. AND ig.group_type_ = #{groupType}
  148. </if>
  149. </select>
  150. <select id="queryMemberById" resultMap="ImGroupMemberDto">
  151. SELECT igm.*,u.avatar_,CASE WHEN find_in_set('STUDENT',u.user_type_) THEN u.username_ ELSE u.real_name_ END username_,
  152. st.member_rank_setting_id_,s.name_ subject_name_,st.subject_id_list_ subject_id_
  153. FROM im_group_member igm
  154. LEFT JOIN sys_user u ON igm.user_id_ = u.id_
  155. LEFT JOIN student st ON st.user_id_ = u.id_
  156. LEFT JOIN `subject` s ON s.id_ = st.subject_id_list_
  157. WHERE igm.im_group_id_ = #{imGroupId}
  158. </select>
  159. <select id="queryMember" resultMap="ImGroupMemberDto" parameterType="map">
  160. SELECT igm.*,u.avatar_,CASE WHEN find_in_set('STUDENT',u.user_type_) THEN u.username_ ELSE u.real_name_ END username_
  161. FROM im_group_member igm left join sys_user u on igm.user_id_ = u.id_
  162. WHERE igm.user_id_ = #{userId}
  163. <if test="imGroupId != null and imGroupId != ''">
  164. AND igm.im_group_id_ = #{imGroupId}
  165. </if>
  166. <if test="imGroupId == null or imGroupId == ''">
  167. LIMIT 1
  168. </if>
  169. </select>
  170. <resultMap id="NameDto" type="com.ym.mec.biz.dal.dto.NameDto">
  171. <result property="id" column="id_" />
  172. <result property="name" column="name_" />
  173. <result property="type" column="type_"/>
  174. </resultMap>
  175. <select id="queryNameByIds" resultMap="NameDto">
  176. select id_,name_,3 type_ from im_group where FIND_IN_SET(id_,#{ids})
  177. </select>
  178. <select id="queryByUserIdV2" resultMap="ImGroup">
  179. SELECT ig.* FROM im_group_member igm
  180. LEFT JOIN im_group ig ON igm.im_group_id_ = ig.id_
  181. left join class_group cg on cg.id_ = ig.id_
  182. left join music_group mg on mg.id_ = cg.music_group_id_
  183. where 1 =1
  184. <if test="userId != null">
  185. AND igm.user_id_ = #{userId}
  186. </if>
  187. <if test="search != null and search != ''">
  188. AND (ig.name_ like concat('%',#{search},'%') or ig.tags_ like concat('%',#{search},'%'))
  189. </if>
  190. <if test="groupType != null and groupType != ''">
  191. AND ig.group_type_ = #{groupType}
  192. </if>
  193. <if test="musicGroupId != null and musicGroupId != ''">
  194. and mg.id_ = #{musicGroupId}
  195. </if>
  196. <if test="classType != null and classType != ''">
  197. AND cg.type_ = #{classType}
  198. </if>
  199. </select>
  200. </mapper>