MusicAlbumMapper.xml 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  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.album_price_,
  37. t.payment_type_,
  38. t.update_time_,
  39. t.update_by_
  40. </sql>
  41. <select id="selectPage" resultType="com.yonge.cooleshow.biz.dal.vo.MusicAlbumVo">
  42. select <include refid="Base_Column_List"/>
  43. ,(select group_concat(mt.name_) from music_tag mt
  44. where find_in_set(mt.id_,t.album_tag_) and mt.del_flag_ = 0 and mt.state_ = 1) as musicTagNames
  45. ,(select group_concat(s.name_) from subject s
  46. where find_in_set(s.id_,t.subject_id_) and s.del_flag_ = 0 ) as subjectNames
  47. ,(select count(1) as num
  48. from album_music_relate amr
  49. join music_sheet ms on amr.music_sheet_id_ = ms.id_
  50. left join sys_user su on su.id_ = ms.user_id_
  51. where ms.del_flag_ = 0 and ms.state_ = 1 and ms.audit_status_ = 'PASS' and su.del_flag_ = 0
  52. and amr.album_id_ = t.id_) as musicSheetCount
  53. ,t2.num as albumFavoriteCount
  54. <if test="query.userId != null">
  55. ,(select count(1) from album_favorite af where af.album_id_ = t.id_ and af.user_id_ = #{query.userId}) as favorite
  56. </if>
  57. from music_album t
  58. left join (select count(1) as num,af.album_id_ from album_favorite af
  59. left join sys_user su on af.user_id_ = su.id_
  60. where su.del_flag_ = 0 group by af.album_id_
  61. ) t2 on t2.album_id_ = t.id_
  62. <where>
  63. t.del_flag_ = 0
  64. <if test="query.idAndName != null and query.idAndName != ''">
  65. and (t.id_ like concat('%',#{query.idAndName},'%') or
  66. t.album_name_ like concat('%',#{query.idAndName},'%'))
  67. </if>
  68. <if test="query.albumTagIdList != null and query.albumTagIdList.size() != 0">
  69. and
  70. <foreach collection="query.albumTagIdList" open="(" close=")" separator="or" item="item">
  71. find_in_set(#{item},t.album_tag_)
  72. </foreach>
  73. </if>
  74. <if test="query.subjectIdList != null and query.subjectIdList.size() != 0">
  75. and
  76. <foreach collection="query.subjectIdList" open="(" close=")" separator="or" item="item">
  77. find_in_set(#{item},t.subject_id_)
  78. </foreach>
  79. </if>
  80. <if test="query.albumStatus != null">
  81. and t.album_status_ = #{query.albumStatus}
  82. </if>
  83. <if test="query.auditVersion != null">
  84. and t.audit_version_ = #{query.auditVersion}
  85. </if>
  86. </where>
  87. order by t.sort_number_ desc
  88. <if test="query.sortBy != null">
  89. <choose>
  90. <when test="query.sortBy == 1">
  91. ,t2.num desc
  92. </when>
  93. </choose>
  94. </if>
  95. ,t.id_ desc
  96. </select>
  97. <select id="selectFavoritePage" resultType="com.yonge.cooleshow.biz.dal.vo.MusicAlbumVo">
  98. select <include refid="Base_Column_List"/>
  99. ,(select group_concat(mt.name_) from music_tag mt
  100. where find_in_set(mt.id_,t.album_tag_) and mt.del_flag_ = 0 and mt.state_ = 1) as musicTagNames
  101. ,(select group_concat(s.name_) from subject s
  102. where find_in_set(s.id_,t.subject_id_) and s.del_flag_ = 0 ) as subjectNames
  103. from music_album t
  104. <if test="query.albumFavorite != null">
  105. left join album_favorite af2 on af2.album_id_ = t.id_
  106. </if>
  107. <if test="query.albumPurchased != null">
  108. JOIN music_sheet_purchase_record t2 ON (t.id_ = t2.music_sheet_id_)
  109. </if>
  110. <where>
  111. <if test="query.albumFavorite != null">
  112. t.del_flag_ = 0
  113. <if test="query.studentId != null">
  114. and af2.user_id_ = #{query.studentId}
  115. </if>
  116. <if test="clientType != null">
  117. AND af2.client_type_ = #{clientType}
  118. </if>
  119. </if>
  120. <if test="query.albumPurchased != null">
  121. <if test="query.clientType != null">
  122. AND t2.client_type_ = #{query.clientType}
  123. </if>
  124. <if test="query.orderStatus != null">
  125. AND t2.order_status_ #{query.orderStatus}
  126. </if>
  127. <if test="query.purchaseType != null">
  128. AND t2.purchase_type_ = #{query.purchaseType}
  129. </if>
  130. <if test="query.studentId != null">
  131. AND t2.student_id_ = #{query.studentId}
  132. </if>
  133. </if>
  134. <if test="query.idAndName != null and query.idAndName != ''">
  135. and (t.id_ like concat('%',#{query.idAndName},'%') or
  136. t.album_name_ like concat('%',#{query.idAndName},'%'))
  137. </if>
  138. <if test="query.albumTagIdList != null and query.albumTagIdList.size() != 0">
  139. and
  140. <foreach collection="query.albumTagIdList" open="(" close=")" separator="or" item="item">
  141. find_in_set(#{item},t.album_tag_)
  142. </foreach>
  143. </if>
  144. <if test="query.subjectIdList != null and query.subjectIdList.size() != 0">
  145. and
  146. <foreach collection="query.subjectIdList" open="(" close=")" separator="or" item="item">
  147. find_in_set(#{item},t.subject_id_)
  148. </foreach>
  149. </if>
  150. <if test="query.auditVersion != null">
  151. and t.audit_version_ = #{query.auditVersion}
  152. </if>
  153. <if test="query.albumStatus != null">
  154. and t.album_status_ = #{query.albumStatus}
  155. </if>
  156. </where>
  157. <if test="query.albumFavorite != null">
  158. order by af2.favorite_time_ desc
  159. </if>
  160. </select>
  161. <select id="selectFavoriteNumAndMusicNum" resultType="com.yonge.cooleshow.biz.dal.vo.MusicAlbumVo">
  162. select
  163. t1.num as musicSheetCount
  164. ,t2.num as albumFavoriteCount
  165. from music_album t
  166. left join (select count(1) as num,amr.album_id_
  167. from album_music_relate amr
  168. join music_sheet ms on amr.music_sheet_id_ = ms.id_
  169. left join sys_user su on su.id_ = ms.user_id_
  170. where ms.del_flag_ = 0 and ms.state_ = 1 and ms.audit_status_ = 'PASS' and su.del_flag_ = 0
  171. group by amr.album_id_) t1 on t1.album_id_ = t.id_
  172. left join (select count(1) as num,af.album_id_ from album_favorite af
  173. left join sys_user su on af.user_id_ = su.id_
  174. where su.del_flag_ = 0 group by af.album_id_
  175. ) t2 on t2.album_id_ = t.id_
  176. <where>
  177. t.del_flag_ = 0
  178. <if test="records != null and records.size() != 0">
  179. and t.id_ in
  180. <foreach collection="records" item="item" open="(" close=")" separator=",">
  181. #{item.id}
  182. </foreach>
  183. </if>
  184. </where>
  185. order by
  186. <if test="records != null and records.size() != 0">
  187. field(t.id_,
  188. <foreach collection="records" item="item" open="" close=")" separator=",">
  189. #{item.id}
  190. </foreach>
  191. </if>
  192. </select>
  193. <select id="selectMusicAlbumById" resultType="com.yonge.cooleshow.biz.dal.vo.MusicAlbumVo">
  194. select <include refid="Base_Column_List"/>
  195. ,(select group_concat(mt.name_) from music_tag mt
  196. where find_in_set(mt.id_,t.album_tag_) and mt.del_flag_ = 0 and mt.state_ = 1) as musicTagNames
  197. ,(select group_concat(s.name_) from subject s
  198. where find_in_set(s.id_,t.subject_id_) and s.del_flag_ = 0 ) as subjectNames
  199. , (
  200. select count(1) as num from album_music_relate amr
  201. join music_sheet ms on amr.music_sheet_id_ = ms.id_
  202. left join sys_user su on su.id_ = ms.user_id_
  203. where ms.del_flag_ = 0 and ms.state_ = 1 and ms.audit_status_ = 'PASS' and su.del_flag_ = 0
  204. and amr.album_id_ = t.id_
  205. ) as musicSheetCount
  206. ,(
  207. select count(1) as num from album_favorite af
  208. left join sys_user su on af.user_id_ = su.id_
  209. where su.del_flag_ = 0 and af.album_id_ = t.id_
  210. ) as albumFavoriteCount
  211. from music_album t
  212. where t.id_ = #{musicAlbumId}
  213. </select>
  214. <select id="selectStudentPage" resultType="com.yonge.cooleshow.biz.dal.vo.MusicAlbumVo">
  215. select <include refid="Base_Column_List"/>
  216. ,(select group_concat(mt.name_) from music_tag mt
  217. where find_in_set(mt.id_,t.album_tag_) and mt.del_flag_ = 0 and mt.state_ = 1) as musicTagNames
  218. ,(select group_concat(s.name_) from subject s
  219. where find_in_set(s.id_,t.subject_id_) and s.del_flag_ = 0 ) as subjectNames
  220. ,(select count(1) as num
  221. from album_music_relate amr
  222. join music_sheet ms on amr.music_sheet_id_ = ms.id_
  223. left join sys_user su on su.id_ = ms.user_id_
  224. where ms.del_flag_ = 0 and ms.state_ = 1 and ms.audit_status_ = 'PASS' and su.del_flag_ = 0
  225. and amr.album_id_ = t.id_) as musicSheetCount
  226. ,if(t2.num >0,t2.num,0) as albumFavoriteCount
  227. from music_album t
  228. <if test="query.musicId != null">
  229. JOIN album_music_relate t1 ON (t.id_ = t1.album_id_ AND t1.music_sheet_id_ = #{query.musicId})
  230. </if>
  231. left join (select count(1) as num,af.album_id_ from album_favorite af
  232. left join sys_user su on (af.user_id_ = su.id_ <if test="clientType != null"> AND af.client_type_ = #{clientType} </if>)
  233. where su.del_flag_ = 0 group by af.album_id_
  234. ) t2 on t2.album_id_ = t.id_
  235. <where>
  236. t.del_flag_ = 0
  237. <if test="query.idAndName != null and query.idAndName != ''">
  238. and (t.id_ like concat('%',#{query.idAndName},'%') or
  239. t.album_name_ like concat('%',#{query.idAndName},'%'))
  240. </if>
  241. <if test="query.albumTagIdList != null and query.albumTagIdList.size() != 0">
  242. and
  243. <foreach collection="query.albumTagIdList" open="(" close=")" separator="or" item="item">
  244. find_in_set(#{item},t.album_tag_)
  245. </foreach>
  246. </if>
  247. <if test="query.subjectIdList != null and query.subjectIdList.size() != 0">
  248. and
  249. <foreach collection="query.subjectIdList" open="(" close=")" separator="or" item="item">
  250. find_in_set(#{item},t.subject_id_)
  251. </foreach>
  252. </if>
  253. <if test="query.albumStatus != null">
  254. and t.album_status_ = #{query.albumStatus}
  255. </if>
  256. <if test="query.auditVersion != null">
  257. and t.audit_version_ = #{query.auditVersion}
  258. </if>
  259. </where>
  260. order by t.sort_number_ desc
  261. <if test="query.sortBy != null">
  262. <choose>
  263. <when test="query.sortBy == 1">
  264. ,t2.num desc
  265. </when>
  266. </choose>
  267. </if>
  268. ,t.id_ desc
  269. </select>
  270. <!--专辑曲目付费方式统计-->
  271. <select id="selectAlbumMusicSheetStatInfo"
  272. resultType="com.yonge.cooleshow.biz.dal.wrapper.StatGroupWrapper">
  273. SELECT t1.album_id_ AS id, COUNT(t1.id_) AS total
  274. FROM album_music_relate t1 JOIN music_sheet t2 ON (t1.music_sheet_id_ = t2.id_)
  275. <where>
  276. <if test="albumId != null">
  277. AND t1.album_id_ = #{albumId}
  278. </if>
  279. <if test="paymentType != null">
  280. AND t2.payment_type_ = #{paymentType}
  281. </if>
  282. </where>
  283. GROUP BY t1.album_id_
  284. </select>
  285. <!--专辑曲目付费方式统计-->
  286. </mapper>