MusicAlbumMapper.xml 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  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. <if test="query.sortBy != null">
  84. <choose>
  85. <when test="query.sortBy == 1">
  86. order by t2.num desc
  87. </when>
  88. </choose>
  89. </if>
  90. <if test="query.sortBy == null">
  91. order by t.id_ desc
  92. </if>
  93. </select>
  94. <select id="selectFavoritePage" resultType="com.yonge.cooleshow.biz.dal.vo.MusicAlbumVo">
  95. select <include refid="Base_Column_List"/>
  96. ,(select group_concat(mt.name_) from music_tag mt
  97. where find_in_set(mt.id_,t.album_tag_) and mt.del_flag_ = 0 and mt.state_ = 1) as musicTagNames
  98. ,(select group_concat(s.name_) from subject s
  99. where find_in_set(s.id_,t.subject_id_) and s.del_flag_ = 0 ) as subjectNames
  100. from music_album t
  101. left join album_favorite af2 on af2.album_id_ = t.id_
  102. <where>
  103. t.del_flag_ = 0
  104. <if test="query.studentId != null">
  105. and af2.user_id_ = #{query.studentId}
  106. </if>
  107. <if test="query.idAndName != null and query.idAndName != ''">
  108. and (t.id_ like concat('%',#{query.idAndName},'%') or
  109. t.album_name_ like concat('%',#{query.idAndName},'%'))
  110. </if>
  111. <if test="query.albumTagIdList != null and query.albumTagIdList.size() != 0">
  112. and
  113. <foreach collection="query.albumTagIdList" open="(" close=")" separator="or" item="item">
  114. find_in_set(#{item},t.album_tag_)
  115. </foreach>
  116. </if>
  117. <if test="query.subjectIdList != null and query.subjectIdList.size() != 0">
  118. and
  119. <foreach collection="query.subjectIdList" open="(" close=")" separator="or" item="item">
  120. find_in_set(#{item},t.subject_id_)
  121. </foreach>
  122. </if>
  123. <if test="query.auditVersion != null">
  124. and t.audit_version_ = #{query.auditVersion}
  125. </if>
  126. <if test="query.albumStatus != null">
  127. and t.album_status_ = #{query.albumStatus}
  128. </if>
  129. </where>
  130. order by af2.favorite_time_ desc
  131. </select>
  132. <select id="selectFavoriteNumAndMusicNum" resultType="com.yonge.cooleshow.biz.dal.vo.MusicAlbumVo">
  133. select
  134. t1.num as musicSheetCount
  135. ,t2.num as albumFavoriteCount
  136. from music_album t
  137. left join (select count(1) as num,amr.album_id_
  138. from album_music_relate amr
  139. join music_sheet ms on amr.music_sheet_id_ = ms.id_
  140. left join sys_user su on su.id_ = ms.user_id_
  141. where ms.del_flag_ = 0 and ms.state_ = 1 and ms.audit_status_ = 'PASS' and su.del_flag_ = 0
  142. group by amr.album_id_) t1 on t1.album_id_ = t.id_
  143. left join (select count(1) as num,af.album_id_ from album_favorite af
  144. left join sys_user su on af.user_id_ = su.id_
  145. where su.del_flag_ = 0 group by af.album_id_
  146. ) t2 on t2.album_id_ = t.id_
  147. <where>
  148. t.del_flag_ = 0
  149. <if test="records != null and records.size() != 0">
  150. and t.id_ in
  151. <foreach collection="records" item="item" open="(" close=")" separator=",">
  152. #{item.id}
  153. </foreach>
  154. </if>
  155. </where>
  156. order by
  157. <if test="records != null and records.size() != 0">
  158. field(t.id_,
  159. <foreach collection="records" item="item" open="" close=")" separator=",">
  160. #{item.id}
  161. </foreach>
  162. </if>
  163. </select>
  164. <select id="selectMusicAlbumById" resultType="com.yonge.cooleshow.biz.dal.vo.MusicAlbumVo">
  165. select <include refid="Base_Column_List"/>
  166. ,(select group_concat(mt.name_) from music_tag mt
  167. where find_in_set(mt.id_,t.album_tag_) and mt.del_flag_ = 0 and mt.state_ = 1) as musicTagNames
  168. ,(select group_concat(s.name_) from subject s
  169. where find_in_set(s.id_,t.subject_id_) and s.del_flag_ = 0 ) as subjectNames
  170. , (
  171. select count(1) as num from album_music_relate amr
  172. join music_sheet ms on amr.music_sheet_id_ = ms.id_
  173. left join sys_user su on su.id_ = ms.user_id_
  174. where ms.del_flag_ = 0 and ms.state_ = 1 and ms.audit_status_ = 'PASS' and su.del_flag_ = 0
  175. and amr.album_id_ = t.id_
  176. ) as musicSheetCount
  177. ,(
  178. select count(1) as num from album_favorite af
  179. left join sys_user su on af.user_id_ = su.id_
  180. where su.del_flag_ = 0 and af.album_id_ = t.id_
  181. ) as albumFavoriteCount
  182. from music_album t
  183. where t.id_ = #{musicAlbumId}
  184. </select>
  185. <select id="selectStudentPage" resultType="com.yonge.cooleshow.biz.dal.vo.MusicAlbumVo">
  186. select <include refid="Base_Column_List"/>
  187. ,(select group_concat(mt.name_) from music_tag mt
  188. where find_in_set(mt.id_,t.album_tag_) and mt.del_flag_ = 0 and mt.state_ = 1) as musicTagNames
  189. ,(select group_concat(s.name_) from subject s
  190. where find_in_set(s.id_,t.subject_id_) and s.del_flag_ = 0 ) as subjectNames
  191. ,if( t1.num>0,t1.num,0) as musicSheetCount
  192. ,if(t2.num >0,t2.num,0) as albumFavoriteCount
  193. from music_album t
  194. left join (select count(1) as num,amr.album_id_
  195. from album_music_relate amr
  196. join music_sheet ms on amr.music_sheet_id_ = ms.id_
  197. left join sys_user su on su.id_ = ms.user_id_
  198. where ms.del_flag_ = 0 and ms.state_ = 1 and ms.audit_status_ = 'PASS' and su.del_flag_ = 0
  199. group by amr.album_id_) t1 on t1.album_id_ = t.id_
  200. left join (select count(1) as num,af.album_id_ from album_favorite af
  201. left join sys_user su on af.user_id_ = su.id_
  202. where su.del_flag_ = 0 group by af.album_id_
  203. ) t2 on t2.album_id_ = t.id_
  204. <where>
  205. t.del_flag_ = 0
  206. <if test="query.idAndName != null and query.idAndName != ''">
  207. and (t.id_ like concat('%',#{query.idAndName},'%') or
  208. t.album_name_ like concat('%',#{query.idAndName},'%'))
  209. </if>
  210. <if test="query.albumTagIdList != null and query.albumTagIdList.size() != 0">
  211. and
  212. <foreach collection="query.albumTagIdList" open="(" close=")" separator="or" item="item">
  213. find_in_set(#{item},t.album_tag_)
  214. </foreach>
  215. </if>
  216. <if test="query.subjectIdList != null and query.subjectIdList.size() != 0">
  217. and
  218. <foreach collection="query.subjectIdList" open="(" close=")" separator="or" item="item">
  219. find_in_set(#{item},t.subject_id_)
  220. </foreach>
  221. </if>
  222. <if test="query.albumStatus != null">
  223. and t.album_status_ = #{query.albumStatus}
  224. </if>
  225. <if test="query.auditVersion != null">
  226. and t.audit_version_ = #{query.auditVersion}
  227. </if>
  228. </where>
  229. <if test="query.sortBy != null">
  230. <choose>
  231. <when test="query.sortBy == 1">
  232. order by t2.num desc
  233. </when>
  234. </choose>
  235. </if>
  236. <if test="query.sortBy == null">
  237. order by t.id_ desc
  238. </if>
  239. </select>
  240. </mapper>