MusicAlbumMapper.xml 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348
  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="virtual_number_" property="virtualNumber" />
  17. <result column="audit_version_" jdbcType="TINYINT" property="auditVersion"/>
  18. <result column="create_time_" jdbcType="TIMESTAMP" property="createTime"/>
  19. <result column="create_by_" jdbcType="BIGINT" property="createBy"/>
  20. <result column="update_time_" jdbcType="TIMESTAMP" property="updateTime"/>
  21. <result column="update_by_" jdbcType="BIGINT" property="updateBy"/>
  22. <result column="album_type_" jdbcType="BIGINT" property="albumType"/>
  23. </resultMap>
  24. <sql id="Base_Column_List">
  25. t.id_,
  26. t.album_name_,
  27. t.album_desc_,
  28. t.album_tag_,
  29. t.subject_id_,
  30. t.album_cover_url_,
  31. t.album_status_,
  32. t.sort_number_,
  33. t.hot_flag_,
  34. t.top_flag_,
  35. t.virtual_number_,
  36. t.create_time_,
  37. t.audit_version_,
  38. t.create_by_,
  39. t.album_price_,
  40. t.payment_type_,
  41. t.update_time_,
  42. t.update_by_,
  43. t.album_type_
  44. </sql>
  45. <select id="selectPage" resultType="com.yonge.cooleshow.biz.dal.vo.MusicAlbumVo">
  46. select <include refid="Base_Column_List"/>
  47. ,(select group_concat(mt.name_) from music_tag mt
  48. where find_in_set(mt.id_,t.album_tag_) and mt.del_flag_ = 0 and mt.state_ = 1) as musicTagNames
  49. ,(select group_concat(s.name_) from subject s
  50. where find_in_set(s.id_,t.subject_id_) and s.del_flag_ = 0 ) as subjectNames
  51. ,(select count(1) as num
  52. from album_music_relate amr
  53. join music_sheet ms on amr.music_sheet_id_ = ms.id_
  54. where ms.del_flag_ = 0 and ms.state_ = 1 and ms.audit_status_ = 'PASS'
  55. and amr.album_id_ = t.id_) as musicSheetCount
  56. ,t2.num as albumFavoriteCount
  57. <if test="query.userId != null">
  58. ,(select count(1) from album_favorite af where af.album_id_ = t.id_ and af.user_id_ = #{query.userId}) as favorite
  59. </if>
  60. from music_album t
  61. left join (select count(1) as num,af.album_id_ from album_favorite af
  62. group by af.album_id_
  63. ) t2 on t2.album_id_ = t.id_
  64. <where>
  65. t.del_flag_ = 0
  66. <if test="query.idAndName != null and query.idAndName != ''">
  67. and (t.id_ like concat('%',#{query.idAndName},'%') or
  68. t.album_name_ like concat('%',#{query.idAndName},'%'))
  69. </if>
  70. <if test="query.albumTagIdList != null and query.albumTagIdList.size() != 0">
  71. and
  72. <foreach collection="query.albumTagIdList" open="(" close=")" separator="or" item="item">
  73. find_in_set(#{item},t.album_tag_)
  74. </foreach>
  75. </if>
  76. <if test="query.subjectIdList != null and query.subjectIdList.size() != 0">
  77. and (
  78. <foreach collection="query.subjectIdList" open="(" close=")" separator="or" item="item">
  79. find_in_set(#{item},t.subject_id_)
  80. </foreach>
  81. or t.subject_id_ is null or t.subject_id_ = ''
  82. )
  83. </if>
  84. <if test="query.albumStatus != null">
  85. and t.album_status_ = #{query.albumStatus}
  86. </if>
  87. <if test="query.auditVersion != null">
  88. and t.audit_version_ = #{query.auditVersion}
  89. </if>
  90. <if test="query.paymentType != null">
  91. and t.payment_type_ = #{query.paymentType}
  92. </if>
  93. </where>
  94. order by t.sort_number_ desc
  95. <if test="query.sortBy != null">
  96. <choose>
  97. <when test="query.sortBy == 1">
  98. ,t2.num desc
  99. </when>
  100. </choose>
  101. </if>
  102. ,t.id_ desc
  103. </select>
  104. <select id="selectFavoritePage" resultType="com.yonge.cooleshow.biz.dal.vo.MusicAlbumVo">
  105. select distinct <include refid="Base_Column_List"/>
  106. ,(select group_concat(mt.name_) from music_tag mt
  107. where find_in_set(mt.id_,t.album_tag_) and mt.del_flag_ = 0 and mt.state_ = 1) as musicTagNames
  108. ,(select group_concat(s.name_) from subject s
  109. where find_in_set(s.id_,t.subject_id_) and s.del_flag_ = 0 ) as subjectNames
  110. from music_album t
  111. <if test="query.albumFavorite != null">
  112. left join album_favorite af2 on af2.album_id_ = t.id_
  113. </if>
  114. <if test="query.albumPurchased != null">
  115. JOIN music_sheet_purchase_record t2 ON (t.id_ = t2.music_sheet_id_)
  116. </if>
  117. <where>
  118. <if test="query.albumFavorite != null">
  119. t.del_flag_ = 0
  120. <if test="query.studentId != null">
  121. and af2.user_id_ = #{query.studentId}
  122. </if>
  123. <if test="clientType != null">
  124. AND af2.client_type_ = #{clientType}
  125. </if>
  126. </if>
  127. <if test="query.albumPurchased != null">
  128. <if test="query.clientType != null">
  129. AND t2.client_type_ = #{query.clientType}
  130. </if>
  131. <if test="query.orderStatus != null">
  132. AND t2.order_status_ = #{query.orderStatus}
  133. </if>
  134. <if test="query.purchaseType != null">
  135. AND t2.purchase_type_ = #{query.purchaseType}
  136. </if>
  137. <if test="query.courseGift != null">
  138. AND t2.course_music_album_id_ <choose><when test="query.courseGift == 0"> = </when><otherwise> > </otherwise> </choose> 0
  139. </if>
  140. <if test="query.studentId != null">
  141. AND t2.student_id_ = #{query.studentId}
  142. </if>
  143. </if>
  144. <if test="query.idAndName != null and query.idAndName != ''">
  145. and (t.id_ like concat('%',#{query.idAndName},'%') or
  146. t.album_name_ like concat('%',#{query.idAndName},'%'))
  147. </if>
  148. <if test="query.albumTagIdList != null and query.albumTagIdList.size() != 0">
  149. and
  150. <foreach collection="query.albumTagIdList" open="(" close=")" separator="or" item="item">
  151. find_in_set(#{item},t.album_tag_)
  152. </foreach>
  153. </if>
  154. <if test="query.subjectIdList != null and query.subjectIdList.size() != 0">
  155. and (
  156. <foreach collection="query.subjectIdList" open="(" close=")" separator="or" item="item">
  157. find_in_set(#{item},t.subject_id_)
  158. </foreach>
  159. or t.subject_id_ is null or t.subject_id_ = ''
  160. )
  161. </if>
  162. <if test="query.auditVersion != null">
  163. and t.audit_version_ = #{query.auditVersion}
  164. </if>
  165. <if test="query.albumStatus != null">
  166. and t.album_status_ = #{query.albumStatus}
  167. </if>
  168. </where>
  169. <if test="query.albumFavorite != null">
  170. order by af2.favorite_time_ desc
  171. </if>
  172. </select>
  173. <select id="selectFavoriteNumAndMusicNum" resultType="com.yonge.cooleshow.biz.dal.vo.MusicAlbumVo">
  174. select
  175. t.id_ as id,
  176. ifnull(t1.num,0) as musicSheetCount
  177. ,ifnull(t2.num,0) as albumFavoriteCount
  178. from music_album t
  179. left join (select count(1) as num,amr.album_id_
  180. from album_music_relate amr
  181. join music_sheet ms on amr.music_sheet_id_ = ms.id_
  182. where ms.del_flag_ = 0 and ms.state_ = 1 and ms.audit_status_ = 'PASS'
  183. group by amr.album_id_) t1 on t1.album_id_ = t.id_
  184. left join (select count(1) as num,af.album_id_ from album_favorite af
  185. group by af.album_id_
  186. ) t2 on t2.album_id_ = t.id_
  187. <where>
  188. t.del_flag_ = 0
  189. <if test="records != null and records.size() != 0">
  190. and t.id_ in
  191. <foreach collection="records" item="item" open="(" close=")" separator=",">
  192. #{item.id}
  193. </foreach>
  194. </if>
  195. </where>
  196. order by
  197. <if test="records != null and records.size() != 0">
  198. field(t.id_,
  199. <foreach collection="records" item="item" open="" close=")" separator=",">
  200. #{item.id}
  201. </foreach>
  202. </if>
  203. </select>
  204. <select id="selectMusicAlbumById" resultType="com.yonge.cooleshow.biz.dal.vo.MusicAlbumVo">
  205. select <include refid="Base_Column_List"/>
  206. ,(select group_concat(mt.name_) from music_tag mt
  207. where find_in_set(mt.id_,t.album_tag_) and mt.del_flag_ = 0 and mt.state_ = 1) as musicTagNames
  208. ,(select group_concat(s.name_) from subject s
  209. where find_in_set(s.id_,t.subject_id_) and s.del_flag_ = 0 ) as subjectNames
  210. , (
  211. select count(1) as num from album_music_relate amr
  212. join music_sheet ms on amr.music_sheet_id_ = ms.id_
  213. where ms.del_flag_ = 0 and ms.state_ = 1 and ms.audit_status_ = 'PASS'
  214. and amr.album_id_ = t.id_
  215. ) as musicSheetCount
  216. ,(
  217. select count(1) as num from album_favorite af
  218. where af.album_id_ = t.id_
  219. ) as albumFavoriteCount
  220. from music_album t
  221. where t.id_ = #{musicAlbumId}
  222. </select>
  223. <select id="selectStudentPage" resultType="com.yonge.cooleshow.biz.dal.vo.MusicAlbumVo">
  224. select <include refid="Base_Column_List"/>
  225. ,(select group_concat(mt.name_) from music_tag mt
  226. where find_in_set(mt.id_,t.album_tag_) and mt.del_flag_ = 0 and mt.state_ = 1) as musicTagNames
  227. ,(select group_concat(s.name_) from subject s
  228. where find_in_set(s.id_,t.subject_id_) and s.del_flag_ = 0 ) as subjectNames
  229. ,(select count(1) as num
  230. from album_music_relate amr
  231. join music_sheet ms on amr.music_sheet_id_ = ms.id_
  232. where ms.del_flag_ = 0 and ms.state_ = 1 and ms.audit_status_ = 'PASS'
  233. and amr.album_id_ = t.id_) as musicSheetCount
  234. ,if(t2.num >0,t2.num,0) as albumFavoriteCount
  235. from music_album t
  236. <if test="query.musicId != null">
  237. JOIN album_music_relate t1 ON (t.id_ = t1.album_id_ AND t1.music_sheet_id_ = #{query.musicId})
  238. </if>
  239. left join (select count(1) as num,af.album_id_ from album_favorite af
  240. group by af.album_id_
  241. ) t2 on t2.album_id_ = t.id_
  242. <if test="clientType != null and query.userId != null">
  243. left join music_sheet_purchase_record t3 on t3.music_sheet_id_ = t.id_ and t3.client_type_ = #{clientType} and t3.student_id_ = #{query.userId}
  244. </if>
  245. <where>
  246. t.del_flag_ = 0
  247. <if test="query.idAndName != null and query.idAndName != ''">
  248. and (t.id_ like concat('%',#{query.idAndName},'%') or
  249. t.album_name_ like concat('%',#{query.idAndName},'%'))
  250. </if>
  251. <if test="query.albumTagIdList != null and query.albumTagIdList.size() != 0">
  252. and
  253. <foreach collection="query.albumTagIdList" open="(" close=")" separator="or" item="item">
  254. find_in_set(#{item},t.album_tag_)
  255. </foreach>
  256. </if>
  257. <if test="query.subjectIdList != null and query.subjectIdList.size() != 0">
  258. and (
  259. <foreach collection="query.subjectIdList" open="(" close=")" separator="or" item="item">
  260. find_in_set(#{item},t.subject_id_)
  261. </foreach>
  262. or t.subject_id_ is null or t.subject_id_ = ''
  263. )
  264. </if>
  265. <if test="query.albumStatus != null">
  266. and t.album_status_ = #{query.albumStatus}
  267. </if>
  268. <if test="query.auditVersion != null">
  269. and t.audit_version_ = #{query.auditVersion}
  270. </if>
  271. </where>
  272. order by
  273. <if test="clientType != null and query.userId != null">
  274. field(t3.id_,null,t3.id_) desc,
  275. </if>
  276. t.sort_number_ desc
  277. <if test="query.sortBy != null">
  278. <choose>
  279. <when test="query.sortBy == 1">
  280. ,t2.num desc
  281. </when>
  282. </choose>
  283. </if>
  284. ,t.id_ desc
  285. </select>
  286. <!--专辑曲目付费方式统计-->
  287. <select id="selectAlbumMusicSheetStatInfo"
  288. resultType="com.yonge.cooleshow.biz.dal.wrapper.StatGroupWrapper">
  289. SELECT t1.album_id_ AS id, COUNT(t1.id_) AS total
  290. FROM album_music_relate t1 JOIN music_sheet t2 ON (t1.music_sheet_id_ = t2.id_)
  291. <where>
  292. <if test="albumId != null">
  293. AND t1.album_id_ = #{albumId}
  294. </if>
  295. <if test="paymentType != null">
  296. AND t2.payment_type_ = #{paymentType}
  297. </if>
  298. </where>
  299. GROUP BY t1.album_id_
  300. </select>
  301. <!--专辑曲目付费方式统计-->
  302. <select id="selectStudentOrderPage" resultType="com.yonge.cooleshow.biz.dal.vo.StudentMusicAlbumOrderVo">
  303. select distinct mspr.music_sheet_id_ as musicAlbumId
  304. ,ms.album_name_ as musicAlbumName
  305. ,ms.album_cover_url_ as titleImg
  306. ,(select group_concat(mt.name_) from music_tag mt
  307. where find_in_set(mt.id_,ms.album_tag_) and mt.del_flag_ = 0 and mt.state_ = 1) as TagNames
  308. ,mspr.purchase_price_ as purchasePrice
  309. ,mspr.order_no_ as orderNo
  310. ,mspr.purchase_time_ as purchaseTime
  311. from music_sheet_purchase_record mspr
  312. left join music_album ms on mspr.music_sheet_id_ = ms.id_
  313. <where>
  314. mspr.order_status_ = 'PAID' and mspr.purchase_type_ = 'ALBUM'
  315. <if test="param.idAndName != null and param.idAndName != ''">
  316. and (ms.id_ like concat('%',#{param.idAndName} ,'%')
  317. or ms.album_name_ like concat('%',#{param.idAndName},'%'))
  318. </if>
  319. <if test="param.studentId != null">
  320. and mspr.student_id_ = #{param.studentId}
  321. </if>
  322. <if test="param.orderNo != null and param.orderNo != ''">
  323. and mspr.order_no_ = #{param.orderNo}
  324. </if>
  325. <if test="param.musicTagList != null and param.musicTagList.size() != 0">
  326. and
  327. <foreach collection="param.musicTagList" separator="or" item="item" open="(" close=")" >
  328. find_in_set(#{item},ms.album_tag_)
  329. </foreach>
  330. </if>
  331. <if test="param.startTime != null">
  332. and mspr.purchase_time_ &gt; #{param.startTime}
  333. </if>
  334. <if test="param.endTime != null">
  335. and mspr.purchase_time_ &lt; #{param.endTime}
  336. </if>
  337. </where>
  338. order by mspr.id_ desc
  339. </select>
  340. </mapper>