ImGroupMapper.xml 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339
  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. <result column="import_flag_" property="importFlag"/>
  22. </resultMap>
  23. <resultMap type="com.ym.mec.biz.dal.dto.ImGroupMemberDto" id="ImGroupMemberDto">
  24. <result column="id_" property="id" />
  25. <result column="im_group_id_" property="imGroupId" />
  26. <result column="user_id_" property="userId" />
  27. <result column="nickname_" property="nickname" />
  28. <result column="is_admin_" property="isAdmin" />
  29. <result column="role_type_" property="roleType" />
  30. <result column="create_time_" property="createTime" />
  31. <result column="update_time_" property="updateTime" />
  32. <result column="member_rank_setting_id_" property="memberRankSettingId" />
  33. <result column="subject_name_" property="subjectName" />
  34. <result column="subject_id_" property="subjectId" />
  35. <result column="username_" property="user.username" />
  36. <result column="avatar_" property="user.avatar" />
  37. <result column="phone_" property="user.phone" />
  38. <result column="real_name_" property="user.realName" />
  39. <result column="user_type_" property="user.userType" />
  40. <result column="group_nickname_" property="groupNickname" />
  41. </resultMap>
  42. <!-- 根据主键查询一条记录 -->
  43. <select id="get" resultMap="ImGroup" >
  44. SELECT * FROM im_group WHERE id_ = #{id}
  45. </select>
  46. <select id="getLocked" resultMap="ImGroup" >
  47. SELECT * FROM im_group WHERE id_ = #{id} for update
  48. </select>
  49. <!-- 全查询 -->
  50. <select id="findAll" resultMap="ImGroup">
  51. SELECT * FROM im_group where tenant_id_ = #{tenantId} ORDER BY id_
  52. </select>
  53. <!-- 向数据库增加一条记录 -->
  54. <insert id="insert" parameterType="com.ym.mec.biz.dal.entity.ImGroup" useGeneratedKeys="true" keyColumn="id" keyProperty="id">
  55. INSERT INTO im_group (id_,name_,introduce_,member_num_,memo_,tags_,img_,type_,create_time_,update_time_,tenant_id_,group_type_,school_id_)
  56. VALUES(#{id},#{name},#{introduce},#{memberNum},#{memo},#{tags},#{img},#{type},#{createTime},#{updateTime},#{tenantId},#{groupType},#{schoolId})
  57. </insert>
  58. <!-- 根据主键查询一条记录 -->
  59. <update id="update" parameterType="com.ym.mec.biz.dal.entity.ImGroup">
  60. UPDATE im_group <set>
  61. <if test="groupType != null">
  62. group_type_ = #{groupType},
  63. </if>
  64. <if test="memberNum != null">
  65. member_num_ = member_num_ + #{memberNum},
  66. </if>
  67. <if test="tags != null">
  68. tags_ = #{tags},
  69. </if>
  70. <if test="introduce != null">
  71. introduce_ = #{introduce},
  72. </if>
  73. <if test="updateTime != null">
  74. update_time_ = #{updateTime},
  75. </if>
  76. <if test="memo != null">
  77. memo_ = #{memo},
  78. </if>
  79. <if test="name != null">
  80. name_ = #{name},
  81. </if>
  82. <if test="img != null">
  83. img_ = #{img},
  84. </if>
  85. <if test="type != null">
  86. type_ = #{type},
  87. </if>
  88. </set> WHERE id_ = #{id} and tenant_id_ = #{tenantId}
  89. </update>
  90. <update id="updateNickname">
  91. UPDATE im_group_member SET nickname_ = #{nickName} WHERE user_id_ = #{userId}
  92. </update>
  93. <update id="updateUserFriendNickname">
  94. UPDATE im_user_friend SET friend_nickname_ = #{nickName} WHERE friend_id_ = #{userId};
  95. </update>
  96. <update id="updateMemberNum">
  97. UPDATE im_group ig
  98. 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_
  99. SET member_num_ = igm.num_
  100. WHERE ig.id_ = igm.im_group_id_
  101. </update>
  102. <!-- 根据主键删除一条记录 -->
  103. <delete id="delete" >
  104. DELETE FROM im_group WHERE id_ = #{id}
  105. </delete>
  106. <sql id="queryPageSql">
  107. <where>
  108. <if test="userId != null">
  109. AND igm.user_id_ = #{userId}
  110. </if>
  111. <if test="search != null and search != ''">
  112. AND (ig.name_ like concat('%',#{search},'%') or ig.memo_ like concat('%',#{search},'%'))
  113. </if>
  114. <if test="ignoreIds != null and ignoreIds != ''">
  115. AND NOT FIND_IN_SET(ig.id_,#{ignoreIds})
  116. </if>
  117. <if test="targetIds != null and targetIds != ''">
  118. AND FIND_IN_SET(ig.id_,#{targetIds})
  119. </if>
  120. <if test="groupType != null">
  121. AND ig.group_type_ = #{groupType}
  122. </if>
  123. <if test="importFlag != null">
  124. AND ig.import_flag_ = #{importFlag}
  125. </if>
  126. </where>
  127. </sql>
  128. <!-- 分页查询 -->
  129. <select id="queryPage" resultMap="ImGroup" parameterType="map">
  130. SELECT ig.* FROM im_group ig
  131. LEFT JOIN im_group_member igm ON igm.im_group_id_ = ig.id_
  132. <include refid="queryPageSql" />
  133. GROUP BY ig.id_
  134. ORDER BY id_
  135. <include refid="global.limit"/>
  136. </select>
  137. <!-- 查询当前表的总记录数 -->
  138. <select id="queryCount" resultType="int">
  139. SELECT COUNT(DISTINCT ig.id_) FROM im_group ig
  140. LEFT JOIN im_group_member igm ON igm.im_group_id_ = ig.id_
  141. <include refid="queryPageSql" />
  142. </select>
  143. <select id="queryByUserId" resultMap="ImGroup" parameterType="map">
  144. SELECT ig.* FROM im_group_member igm
  145. LEFT JOIN im_group ig ON igm.im_group_id_ = ig.id_
  146. where 1 =1
  147. <if test="userId != null">
  148. AND igm.user_id_ = #{userId}
  149. </if>
  150. <if test="search != null and search != ''">
  151. AND (ig.name_ like concat('%',#{search},'%') or ig.tags_ like concat('%',#{search},'%'))
  152. </if>
  153. <if test="groupType != null and groupType != ''">
  154. AND ig.group_type_ = #{groupType}
  155. </if>
  156. </select>
  157. <select id="queryMemberById" resultMap="ImGroupMemberDto">
  158. SELECT igm.*
  159. , u.avatar_
  160. , CASE WHEN find_in_set('STUDENT',u.user_type_) THEN u.username_ ELSE u.real_name_ END username_
  161. , IFNULL(NULLIF(u.username_, ''), u.real_name_) AS group_nickname_
  162. , u.real_name_
  163. , u.user_type_
  164. , st.member_rank_setting_id_,s.name_ subject_name_,st.subject_id_list_ subject_id_
  165. FROM im_group_member igm
  166. LEFT JOIN sys_user u ON igm.user_id_ = u.id_
  167. LEFT JOIN student st ON st.user_id_ = u.id_
  168. LEFT JOIN `subject` s ON s.id_ = st.subject_id_list_
  169. WHERE igm.im_group_id_ = #{imGroupId}
  170. <if test="search != null and search != ''">
  171. AND (u.username_ like concat('%',#{search},'%') or u.real_name_ like concat('%',#{search},'%'))
  172. </if>
  173. </select>
  174. <select id="queryMember" resultMap="ImGroupMemberDto" parameterType="map">
  175. SELECT igm.*,u.avatar_,CASE WHEN find_in_set('STUDENT',u.user_type_) THEN u.username_ ELSE u.real_name_ END username_
  176. FROM im_group_member igm left join sys_user u on igm.user_id_ = u.id_
  177. WHERE igm.user_id_ = #{userId}
  178. <if test="imGroupId != null and imGroupId != ''">
  179. AND igm.im_group_id_ = #{imGroupId}
  180. </if>
  181. <if test="imGroupId == null or imGroupId == ''">
  182. LIMIT 1
  183. </if>
  184. </select>
  185. <resultMap id="NameDto" type="com.ym.mec.biz.dal.dto.NameDto">
  186. <result property="id" column="id_" />
  187. <result property="name" column="name_" />
  188. <result property="type" column="type_"/>
  189. </resultMap>
  190. <select id="queryNameByIds" resultMap="NameDto">
  191. select id_,name_,3 type_ from im_group where FIND_IN_SET(id_,#{ids})
  192. </select>
  193. <select id="queryByUserIdV2" resultMap="ImGroup">
  194. SELECT ig.* FROM im_group_member igm
  195. LEFT JOIN im_group ig ON igm.im_group_id_ = ig.id_
  196. left join class_group cg on cg.id_ = ig.id_
  197. left join music_group mg on mg.id_ = cg.music_group_id_
  198. where 1 =1 and ig.group_type_ in ('NORMAL','MIX')
  199. <if test="userId != null">
  200. AND igm.user_id_ = #{userId}
  201. </if>
  202. <if test="search != null and search != ''">
  203. AND (ig.name_ like concat('%',#{search},'%') or ig.tags_ like concat('%',#{search},'%'))
  204. </if>
  205. <if test="groupType != null and groupType != ''">
  206. AND ig.group_type_ = #{groupType}
  207. </if>
  208. <if test="musicGroupId != null and musicGroupId != ''">
  209. and mg.id_ = #{musicGroupId}
  210. </if>
  211. <if test="classType != null and classType != ''">
  212. AND cg.type_ = #{classType}
  213. </if>
  214. </select>
  215. <select id="queryMemberByIdV2" resultMap="ImGroupMemberDto">
  216. SELECT igm.*,u.avatar_,CASE WHEN find_in_set('STUDENT',u.user_type_) THEN u.username_ ELSE u.real_name_ END username_,
  217. st.member_rank_setting_id_,s.name_ subject_name_,st.subject_id_list_ subject_id_
  218. FROM im_group_member igm
  219. LEFT JOIN sys_user u ON igm.user_id_ = u.id_
  220. LEFT JOIN student st ON st.user_id_ = u.id_
  221. LEFT JOIN `subject` s ON s.id_ = st.subject_id_list_
  222. WHERE igm.im_group_id_ = #{imGroupId} and st.user_id_ is not null
  223. <if test="search != null">
  224. and (u.real_name_ like concat('%',#{search},'%'))
  225. </if>
  226. <if test="subjectId != null">
  227. and st.subject_id_list_ = #{subjectId}
  228. </if>
  229. <if test="vipFlag != null">
  230. <if test="vipFlag">
  231. and st.member_rank_setting_id_ is not null
  232. </if>
  233. <if test="vipFlag == false">
  234. and st.member_rank_setting_id_ is null
  235. </if>
  236. </if>
  237. </select>
  238. <select id="queryBySchoolId" resultMap="ImGroup">
  239. SELECT ig.* FROM im_group ig where school_id_ = #{schoolId} limit 1
  240. </select>
  241. <select id="getByIds" resultMap="ImGroup">
  242. select ig.* FROM im_group ig where ig.id_ in
  243. <foreach collection="musicGroupIds" separator="," item="item" open="(" close=")">
  244. #{item}
  245. </foreach>
  246. </select>
  247. <update id="addMemberNum">
  248. update im_group set member_num_ = member_num_ + #{num} where id_ in
  249. <foreach collection="imGroupIds" close=")" item="item" open="(" separator=",">
  250. #{item}
  251. </foreach>
  252. </update>
  253. <update id="updateMember">
  254. update im_group set member_num_ = #{num} where id_ = #{imGroupId}
  255. </update>
  256. <select id="getByUserId" resultMap="ImGroup">
  257. SELECT distinct ig.* FROM im_group_member igm
  258. LEFT JOIN im_group ig ON igm.im_group_id_ = ig.id_
  259. left join class_group cg on ig.id_ = cg.id_
  260. where 1 =1
  261. <if test="param.userId != null">
  262. AND igm.user_id_ = #{param.userId}
  263. </if>
  264. <if test="param.keyword != null and param.keyword != ''">
  265. AND (ig.name_ like concat('%',#{param.keyword},'%') or ig.tags_ like concat('%',#{param.keyword},'%'))
  266. </if>
  267. <if test="param.musicGroupId != null and param.musicGroupId != ''">
  268. and cg.music_group_id_ = #{param.musicGroupId}
  269. </if>
  270. <if test="param.groupType != null">
  271. and ig.group_type_ = #{param.groupType}
  272. </if>
  273. </select>
  274. <select id="queryInfoCount" resultType="java.lang.Integer">
  275. SELECT COUNT(*) FROM im_history_message
  276. </select>
  277. <select id="selectAll" resultType="com.ym.mec.biz.dal.entity.ImHistoryMessage">
  278. select msgUID_ AS msgUID,
  279. fromUserId_ AS fromUserId,
  280. targetId_ AS targetId,
  281. targetType_ AS targetType,
  282. GroupId_ AS groupId,
  283. busChannel_ AS busChannel,
  284. classname_ AS classname,
  285. content_ AS content,
  286. extraContent_ AS extraContent,
  287. dateTime_ AS dateTime,
  288. source_ AS source,
  289. isDiscard_ AS isDiscard,
  290. isSensitiveWord_ AS isSensitiveWord,
  291. isForbidden_ AS isForbidden,
  292. isNotForward_ AS isNotForward,
  293. groupUserIds_ AS groupUserIds,
  294. appId_ AS appId
  295. from im_history_message
  296. limit #{result},#{size}
  297. </select>
  298. <update id="updateSchoolRoleType">
  299. update im_group_member set role_type_ = #{userType.msg} ,type_ = #{userType.name} where user_id_ = #{userId}
  300. </update>
  301. <update id="updateImportStatusSuccess">
  302. update im_group set import_flag_ = 1
  303. where id_ = #{id}
  304. </update>
  305. <update id="updateStatus">
  306. update im_history_message set status_ = 1
  307. where msgUID in <foreach collection="info" open="(" close=")" separator="," item="info">
  308. #{info.msgUID}
  309. </foreach>
  310. </update>
  311. </mapper>