MusicAlbumMapper.xml 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
  3. "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  4. <mapper namespace="com.yonge.cooleshow.biz.dal.dao.MusicAlbumDao">
  5. <resultMap id="BaseResultMap" type="com.yonge.cooleshow.biz.dal.entity.MusicAlbum">
  6. <id column="id_" jdbcType="BIGINT" property="id"/>
  7. <result column="album_name_" jdbcType="VARCHAR" property="albumName"/>
  8. <result column="album_desc_" jdbcType="VARCHAR" property="albumDesc"/>
  9. <result column="album_tag_" jdbcType="VARCHAR" property="albumTag"/>
  10. <result column="subject_id_" jdbcType="VARCHAR" property="subjectId"/>
  11. <result column="album_cover_url_" jdbcType="VARCHAR" property="albumCoverUrl"/>
  12. <result column="album_status_" jdbcType="TINYINT" property="albumStatus"/>
  13. <result column="sort_number_" jdbcType="INTEGER" property="sortNumber"/>
  14. <result column="hot_flag_" jdbcType="TINYINT" property="hotFlag"/>
  15. <result column="top_flag_" jdbcType="TINYINT" property="topFlag"/>
  16. <result column="audit_version_" jdbcType="TINYINT" property="auditVersion"/>
  17. <result column="create_time_" jdbcType="TIMESTAMP" property="createTime"/>
  18. <result column="create_by_" jdbcType="BIGINT" property="createBy"/>
  19. <result column="update_time_" jdbcType="TIMESTAMP" property="updateTime"/>
  20. <result column="update_by_" jdbcType="BIGINT" property="updateBy"/>
  21. </resultMap>
  22. <sql id="Base_Column_List">
  23. t.id_,
  24. t.album_name_,
  25. t.album_desc_,
  26. t.album_tag_,
  27. t.subject_id_,
  28. t.album_cover_url_,
  29. t.album_status_,
  30. t.sort_number_,
  31. t.hot_flag_,
  32. t.top_flag_,
  33. t.create_time_,
  34. t.audit_version_,
  35. t.create_by_,
  36. t.update_time_,
  37. t.update_by_
  38. </sql>
  39. <select id="selectPage" resultType="com.yonge.cooleshow.biz.dal.vo.MusicAlbumVo">
  40. select <include refid="Base_Column_List"/>
  41. ,(select group_concat(mt.name_) from music_tag mt
  42. where find_in_set(mt.id_,t.album_tag_) and mt.del_flag_ = 0 and mt.state_ = 1) as musicTagNames
  43. ,(select group_concat(s.name_) from subject s
  44. where find_in_set(s.id_,t.subject_id_) and s.del_flag_ = 0 ) as subjectNames
  45. ,(select count(1) as num
  46. from album_music_relate amr
  47. join music_sheet ms on amr.music_sheet_id_ = ms.id_
  48. left join sys_user su on su.id_ = ms.user_id_
  49. where ms.del_flag_ = 0 and ms.state_ = 1 and ms.audit_status_ = 'PASS' and su.del_flag_ = 0
  50. and amr.album_id_ = t.id_) as musicSheetCount
  51. ,t2.num as albumFavoriteCount
  52. <if test="query.userId != null">
  53. ,(select count(1) from album_favorite af where af.album_id_ = t.id_ and af.user_id_ = #{query.userId}) as favorite
  54. </if>
  55. from music_album t
  56. left join (select count(1) as num,af.album_id_ from album_favorite af
  57. left join sys_user su on af.user_id_ = su.id_
  58. where su.del_flag_ = 0 group by af.album_id_
  59. ) t2 on t2.album_id_ = t.id_
  60. <where>
  61. t.del_flag_ = 0
  62. <if test="query.idAndName != null and query.idAndName != ''">
  63. and (t.id_ like concat('%',#{query.idAndName},'%') or
  64. t.album_name_ like concat('%',#{query.idAndName},'%'))
  65. </if>
  66. <if test="query.albumTagIdList != null and query.albumTagIdList.size() != 0">
  67. and
  68. <foreach collection="query.albumTagIdList" open="(" close=")" separator="or" item="item">
  69. find_in_set(#{item},t.album_tag_)
  70. </foreach>
  71. </if>
  72. <if test="query.subjectIdList != null and query.subjectIdList.size() != 0">
  73. and
  74. <foreach collection="query.subjectIdList" open="(" close=")" separator="or" item="item">
  75. find_in_set(#{item},t.subject_id_)
  76. </foreach>
  77. </if>
  78. <if test="query.albumStatus != null">
  79. and t.album_status_ = #{query.albumStatus}
  80. </if>
  81. <if test="query.auditVersion != null">
  82. and t.audit_version_ = #{query.auditVersion}
  83. </if>
  84. </where>
  85. order by t.sort_number_ desc
  86. <if test="query.sortBy != null">
  87. <choose>
  88. <when test="query.sortBy == 1">
  89. ,t2.num desc
  90. </when>
  91. </choose>
  92. </if>
  93. ,t.id_ desc
  94. </select>
  95. <select id="selectFavoritePage" resultType="com.yonge.cooleshow.biz.dal.vo.MusicAlbumVo">
  96. select <include refid="Base_Column_List"/>
  97. ,(select group_concat(mt.name_) from music_tag mt
  98. where find_in_set(mt.id_,t.album_tag_) and mt.del_flag_ = 0 and mt.state_ = 1) as musicTagNames
  99. ,(select group_concat(s.name_) from subject s
  100. where find_in_set(s.id_,t.subject_id_) and s.del_flag_ = 0 ) as subjectNames
  101. from music_album t
  102. left join album_favorite af2 on af2.album_id_ = t.id_
  103. <where>
  104. t.del_flag_ = 0
  105. <if test="query.studentId != null">
  106. and af2.user_id_ = #{query.studentId}
  107. </if>
  108. <if test="clientType != null">
  109. AND af2.client_type_ = #{clientType}
  110. </if>
  111. <if test="query.idAndName != null and query.idAndName != ''">
  112. and (t.id_ like concat('%',#{query.idAndName},'%') or
  113. t.album_name_ like concat('%',#{query.idAndName},'%'))
  114. </if>
  115. <if test="query.albumTagIdList != null and query.albumTagIdList.size() != 0">
  116. and
  117. <foreach collection="query.albumTagIdList" open="(" close=")" separator="or" item="item">
  118. find_in_set(#{item},t.album_tag_)
  119. </foreach>
  120. </if>
  121. <if test="query.subjectIdList != null and query.subjectIdList.size() != 0">
  122. and
  123. <foreach collection="query.subjectIdList" open="(" close=")" separator="or" item="item">
  124. find_in_set(#{item},t.subject_id_)
  125. </foreach>
  126. </if>
  127. <if test="query.auditVersion != null">
  128. and t.audit_version_ = #{query.auditVersion}
  129. </if>
  130. <if test="query.albumStatus != null">
  131. and t.album_status_ = #{query.albumStatus}
  132. </if>
  133. </where>
  134. order by af2.favorite_time_ desc
  135. </select>
  136. <select id="selectFavoriteNumAndMusicNum" resultType="com.yonge.cooleshow.biz.dal.vo.MusicAlbumVo">
  137. select
  138. t1.num as musicSheetCount
  139. ,t2.num as albumFavoriteCount
  140. from music_album t
  141. left join (select count(1) as num,amr.album_id_
  142. from album_music_relate amr
  143. join music_sheet ms on amr.music_sheet_id_ = ms.id_
  144. left join sys_user su on su.id_ = ms.user_id_
  145. where ms.del_flag_ = 0 and ms.state_ = 1 and ms.audit_status_ = 'PASS' and su.del_flag_ = 0
  146. group by amr.album_id_) t1 on t1.album_id_ = t.id_
  147. left join (select count(1) as num,af.album_id_ from album_favorite af
  148. left join sys_user su on af.user_id_ = su.id_
  149. where su.del_flag_ = 0 group by af.album_id_
  150. ) t2 on t2.album_id_ = t.id_
  151. <where>
  152. t.del_flag_ = 0
  153. <if test="records != null and records.size() != 0">
  154. and t.id_ in
  155. <foreach collection="records" item="item" open="(" close=")" separator=",">
  156. #{item.id}
  157. </foreach>
  158. </if>
  159. </where>
  160. order by
  161. <if test="records != null and records.size() != 0">
  162. field(t.id_,
  163. <foreach collection="records" item="item" open="" close=")" separator=",">
  164. #{item.id}
  165. </foreach>
  166. </if>
  167. </select>
  168. <select id="selectMusicAlbumById" resultType="com.yonge.cooleshow.biz.dal.vo.MusicAlbumVo">
  169. select <include refid="Base_Column_List"/>
  170. ,(select group_concat(mt.name_) from music_tag mt
  171. where find_in_set(mt.id_,t.album_tag_) and mt.del_flag_ = 0 and mt.state_ = 1) as musicTagNames
  172. ,(select group_concat(s.name_) from subject s
  173. where find_in_set(s.id_,t.subject_id_) and s.del_flag_ = 0 ) as subjectNames
  174. , (
  175. select count(1) as num from album_music_relate amr
  176. join music_sheet ms on amr.music_sheet_id_ = ms.id_
  177. left join sys_user su on su.id_ = ms.user_id_
  178. where ms.del_flag_ = 0 and ms.state_ = 1 and ms.audit_status_ = 'PASS' and su.del_flag_ = 0
  179. and amr.album_id_ = t.id_
  180. ) as musicSheetCount
  181. ,(
  182. select count(1) as num from album_favorite af
  183. left join sys_user su on af.user_id_ = su.id_
  184. where su.del_flag_ = 0 and af.album_id_ = t.id_
  185. ) as albumFavoriteCount
  186. from music_album t
  187. where t.id_ = #{musicAlbumId}
  188. </select>
  189. <select id="selectStudentPage" resultType="com.yonge.cooleshow.biz.dal.vo.MusicAlbumVo">
  190. select <include refid="Base_Column_List"/>
  191. ,(select group_concat(mt.name_) from music_tag mt
  192. where find_in_set(mt.id_,t.album_tag_) and mt.del_flag_ = 0 and mt.state_ = 1) as musicTagNames
  193. ,(select group_concat(s.name_) from subject s
  194. where find_in_set(s.id_,t.subject_id_) and s.del_flag_ = 0 ) as subjectNames
  195. ,(select count(1) as num
  196. from album_music_relate amr
  197. join music_sheet ms on amr.music_sheet_id_ = ms.id_
  198. left join sys_user su on su.id_ = ms.user_id_
  199. where ms.del_flag_ = 0 and ms.state_ = 1 and ms.audit_status_ = 'PASS' and su.del_flag_ = 0
  200. and amr.album_id_ = t.id_) as musicSheetCount
  201. ,if(t2.num >0,t2.num,0) as albumFavoriteCount
  202. from music_album t
  203. left join (select count(1) as num,af.album_id_ from album_favorite af
  204. left join sys_user su on (af.user_id_ = su.id_ <if test="clientType != null"> AND af.client_type_ = #{clientType} </if>)
  205. where su.del_flag_ = 0 group by af.album_id_
  206. ) t2 on t2.album_id_ = t.id_
  207. <where>
  208. t.del_flag_ = 0
  209. <if test="query.idAndName != null and query.idAndName != ''">
  210. and (t.id_ like concat('%',#{query.idAndName},'%') or
  211. t.album_name_ like concat('%',#{query.idAndName},'%'))
  212. </if>
  213. <if test="query.albumTagIdList != null and query.albumTagIdList.size() != 0">
  214. and
  215. <foreach collection="query.albumTagIdList" open="(" close=")" separator="or" item="item">
  216. find_in_set(#{item},t.album_tag_)
  217. </foreach>
  218. </if>
  219. <if test="query.subjectIdList != null and query.subjectIdList.size() != 0">
  220. and
  221. <foreach collection="query.subjectIdList" open="(" close=")" separator="or" item="item">
  222. find_in_set(#{item},t.subject_id_)
  223. </foreach>
  224. </if>
  225. <if test="query.albumStatus != null">
  226. and t.album_status_ = #{query.albumStatus}
  227. </if>
  228. <if test="query.auditVersion != null">
  229. and t.audit_version_ = #{query.auditVersion}
  230. </if>
  231. </where>
  232. order by t.sort_number_ desc
  233. <if test="query.sortBy != null">
  234. <choose>
  235. <when test="query.sortBy == 1">
  236. ,t2.num desc
  237. </when>
  238. </choose>
  239. </if>
  240. ,t.id_ desc
  241. </select>
  242. </mapper>