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. , t1.num as musicSheetCount
  46. ,t2.num as albumFavoriteCount
  47. from music_album t
  48. left join (select count(1) as num,amr.album_id_
  49. from album_music_relate amr
  50. join music_sheet ms on amr.music_sheet_id_ = ms.id_
  51. left join sys_user su on su.id_ = ms.user_id_
  52. where ms.del_flag_ = 0 and ms.state_ = 1 and ms.audit_status_ = 'PASS' and su.del_flag_ = 0
  53. group by amr.album_id_) t1 on t1.album_id_ = t.id_
  54. left join (select count(1) as num,af.album_id_ from album_favorite af
  55. left join sys_user su on af.user_id_ = su.id_
  56. where su.del_flag_ = 0 group by af.album_id_
  57. ) t2 on t2.album_id_ = t.id_
  58. <where>
  59. t.del_flag_ = 0
  60. <if test="query.idAndName != null and query.idAndName != ''">
  61. and (t.id_ like concat('%',#{query.idAndName},'%') or
  62. t.album_name_ like concat('%',#{query.idAndName},'%'))
  63. </if>
  64. <if test="query.albumTagIdList != null and query.albumTagIdList.size() != 0">
  65. and
  66. <foreach collection="query.albumTagIdList" open="(" close=")" separator="or" item="item">
  67. find_in_set(#{item},t.album_tag_)
  68. </foreach>
  69. </if>
  70. <if test="query.subjectIdList != null and query.subjectIdList.size() != 0">
  71. and
  72. <foreach collection="query.subjectIdList" open="(" close=")" separator="or" item="item">
  73. find_in_set(#{item},t.subject_id_)
  74. </foreach>
  75. </if>
  76. <if test="query.albumStatus != null">
  77. and t.album_status_ = #{query.albumStatus}
  78. </if>
  79. <if test="query.auditVersion != null">
  80. and t.audit_version_ = #{query.auditVersion}
  81. </if>
  82. </where>
  83. order by t.sort_number_ desc,
  84. <if test="query.sortBy != null">
  85. <choose>
  86. <when test="query.sortBy == 1">
  87. t2.num desc
  88. </when>
  89. </choose>
  90. </if>
  91. <if test="query.sortBy == null">
  92. t.id_ desc
  93. </if>
  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="query.idAndName != null and query.idAndName != ''">
  109. and (t.id_ like concat('%',#{query.idAndName},'%') or
  110. t.album_name_ like concat('%',#{query.idAndName},'%'))
  111. </if>
  112. <if test="query.albumTagIdList != null and query.albumTagIdList.size() != 0">
  113. and
  114. <foreach collection="query.albumTagIdList" open="(" close=")" separator="or" item="item">
  115. find_in_set(#{item},t.album_tag_)
  116. </foreach>
  117. </if>
  118. <if test="query.subjectIdList != null and query.subjectIdList.size() != 0">
  119. and
  120. <foreach collection="query.subjectIdList" open="(" close=")" separator="or" item="item">
  121. find_in_set(#{item},t.subject_id_)
  122. </foreach>
  123. </if>
  124. <if test="query.auditVersion != null">
  125. and t.audit_version_ = #{query.auditVersion}
  126. </if>
  127. <if test="query.albumStatus != null">
  128. and t.album_status_ = #{query.albumStatus}
  129. </if>
  130. </where>
  131. order by af2.favorite_time_ desc
  132. </select>
  133. <select id="selectFavoriteNumAndMusicNum" resultType="com.yonge.cooleshow.biz.dal.vo.MusicAlbumVo">
  134. select
  135. t1.num as musicSheetCount
  136. ,t2.num as albumFavoriteCount
  137. from music_album t
  138. left join (select count(1) as num,amr.album_id_
  139. from album_music_relate amr
  140. join music_sheet ms on amr.music_sheet_id_ = ms.id_
  141. left join sys_user su on su.id_ = ms.user_id_
  142. where ms.del_flag_ = 0 and ms.state_ = 1 and ms.audit_status_ = 'PASS' and su.del_flag_ = 0
  143. group by amr.album_id_) t1 on t1.album_id_ = t.id_
  144. left join (select count(1) as num,af.album_id_ from album_favorite af
  145. left join sys_user su on af.user_id_ = su.id_
  146. where su.del_flag_ = 0 group by af.album_id_
  147. ) t2 on t2.album_id_ = t.id_
  148. <where>
  149. t.del_flag_ = 0
  150. <if test="records != null and records.size() != 0">
  151. and t.id_ in
  152. <foreach collection="records" item="item" open="(" close=")" separator=",">
  153. #{item.id}
  154. </foreach>
  155. </if>
  156. </where>
  157. order by
  158. <if test="records != null and records.size() != 0">
  159. field(t.id_,
  160. <foreach collection="records" item="item" open="" close=")" separator=",">
  161. #{item.id}
  162. </foreach>
  163. </if>
  164. </select>
  165. <select id="selectMusicAlbumById" resultType="com.yonge.cooleshow.biz.dal.vo.MusicAlbumVo">
  166. select <include refid="Base_Column_List"/>
  167. ,(select group_concat(mt.name_) from music_tag mt
  168. where find_in_set(mt.id_,t.album_tag_) and mt.del_flag_ = 0 and mt.state_ = 1) as musicTagNames
  169. ,(select group_concat(s.name_) from subject s
  170. where find_in_set(s.id_,t.subject_id_) and s.del_flag_ = 0 ) as subjectNames
  171. , t1.num as musicSheetCount
  172. ,t2.num as albumFavoriteCount
  173. from music_album t
  174. left join (select count(1) as num,amr.album_id_
  175. 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. group by amr.album_id_) t1 on t1.album_id_ = t.id_
  180. left join (select count(1) as num,af.album_id_ from album_favorite af
  181. left join sys_user su on af.user_id_ = su.id_
  182. where su.del_flag_ = 0 group by af.album_id_
  183. ) t2 on t2.album_id_ = t.id_
  184. where t.id_ = #{musicAlbumId}
  185. </select>
  186. <select id="selectStudentPage" resultType="com.yonge.cooleshow.biz.dal.vo.MusicAlbumVo">
  187. select <include refid="Base_Column_List"/>
  188. ,(select group_concat(mt.name_) from music_tag mt
  189. where find_in_set(mt.id_,t.album_tag_) and mt.del_flag_ = 0 and mt.state_ = 1) as musicTagNames
  190. ,(select group_concat(s.name_) from subject s
  191. where find_in_set(s.id_,t.subject_id_) and s.del_flag_ = 0 ) as subjectNames
  192. ,if( t1.num>0,t1.num,0) as musicSheetCount
  193. ,if(t2.num >0,t2.num,0) as albumFavoriteCount
  194. from music_album t
  195. left join (select count(1) as num,amr.album_id_
  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. group by amr.album_id_) t1 on t1.album_id_ = t.id_
  201. left join (select count(1) as num,af.album_id_ from album_favorite af
  202. left join sys_user su on af.user_id_ = su.id_
  203. where su.del_flag_ = 0 group by af.album_id_
  204. ) t2 on t2.album_id_ = t.id_
  205. <where>
  206. t.del_flag_ = 0
  207. <if test="query.idAndName != null and query.idAndName != ''">
  208. and (t.id_ like concat('%',#{query.idAndName},'%') or
  209. t.album_name_ like concat('%',#{query.idAndName},'%'))
  210. </if>
  211. <if test="query.albumTagIdList != null and query.albumTagIdList.size() != 0">
  212. and
  213. <foreach collection="query.albumTagIdList" open="(" close=")" separator="or" item="item">
  214. find_in_set(#{item},t.album_tag_)
  215. </foreach>
  216. </if>
  217. <if test="query.subjectIdList != null and query.subjectIdList.size() != 0">
  218. and
  219. <foreach collection="query.subjectIdList" open="(" close=")" separator="or" item="item">
  220. find_in_set(#{item},t.subject_id_)
  221. </foreach>
  222. </if>
  223. <if test="query.albumStatus != null">
  224. and t.album_status_ = #{query.albumStatus}
  225. </if>
  226. <if test="query.auditVersion != null">
  227. and t.audit_version_ = #{query.auditVersion}
  228. </if>
  229. </where>
  230. order by t.sort_number_ desc,
  231. <if test="query.sortBy != null">
  232. <choose>
  233. <when test="query.sortBy == 1">
  234. t2.num desc
  235. </when>
  236. </choose>
  237. </if>
  238. <if test="query.sortBy == null">
  239. t.id_ desc
  240. </if>
  241. </select>
  242. </mapper>