MusicAlbumMapper.xml 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355
  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' and find_in_set('PLATFORM',ms.provider_type_)
  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. <if test="query.albumIds != null and query.albumIds.size() != 0">
  94. and t.id_ in
  95. <foreach collection="query.albumIds" item="item" open="(" close=")" separator=",">
  96. #{item}
  97. </foreach>
  98. </if>
  99. </where>
  100. order by t.sort_number_ desc
  101. <if test="query.sortBy != null">
  102. <choose>
  103. <when test="query.sortBy == 1">
  104. ,t2.num desc
  105. </when>
  106. </choose>
  107. </if>
  108. ,t.id_ desc
  109. </select>
  110. <select id="selectFavoritePage" resultType="com.yonge.cooleshow.biz.dal.vo.MusicAlbumVo">
  111. select distinct <include refid="Base_Column_List"/>
  112. ,(select group_concat(mt.name_) from music_tag mt
  113. where find_in_set(mt.id_,t.album_tag_) and mt.del_flag_ = 0 and mt.state_ = 1) as musicTagNames
  114. ,(select group_concat(s.name_) from subject s
  115. where find_in_set(s.id_,t.subject_id_) and s.del_flag_ = 0 ) as subjectNames
  116. from music_album t
  117. <if test="query.albumFavorite != null">
  118. left join album_favorite af2 on af2.album_id_ = t.id_
  119. </if>
  120. <if test="query.albumPurchased != null">
  121. JOIN music_sheet_purchase_record t2 ON (t.id_ = t2.music_sheet_id_)
  122. </if>
  123. <where>
  124. <if test="query.albumFavorite != null">
  125. t.del_flag_ = 0
  126. <if test="query.studentId != null">
  127. and af2.user_id_ = #{query.studentId}
  128. </if>
  129. <if test="clientType != null">
  130. AND af2.client_type_ = #{clientType}
  131. </if>
  132. </if>
  133. <if test="query.albumPurchased != null">
  134. <if test="query.clientType != null">
  135. AND t2.client_type_ = #{query.clientType}
  136. </if>
  137. <if test="query.orderStatus != null">
  138. AND t2.order_status_ = #{query.orderStatus}
  139. </if>
  140. <if test="query.purchaseType != null">
  141. AND t2.purchase_type_ = #{query.purchaseType}
  142. </if>
  143. <if test="query.courseGift != null">
  144. AND t2.course_music_album_id_ <choose><when test="query.courseGift == 0"> = </when><otherwise> > </otherwise> </choose> 0
  145. </if>
  146. <if test="query.studentId != null">
  147. AND t2.student_id_ = #{query.studentId}
  148. </if>
  149. </if>
  150. <if test="query.idAndName != null and query.idAndName != ''">
  151. and (t.id_ like concat('%',#{query.idAndName},'%') or
  152. t.album_name_ like concat('%',#{query.idAndName},'%'))
  153. </if>
  154. <if test="query.albumTagIdList != null and query.albumTagIdList.size() != 0">
  155. and
  156. <foreach collection="query.albumTagIdList" open="(" close=")" separator="or" item="item">
  157. find_in_set(#{item},t.album_tag_)
  158. </foreach>
  159. </if>
  160. <if test="query.subjectIdList != null and query.subjectIdList.size() != 0">
  161. and (
  162. <foreach collection="query.subjectIdList" open="(" close=")" separator="or" item="item">
  163. find_in_set(#{item},t.subject_id_)
  164. </foreach>
  165. or t.subject_id_ is null or t.subject_id_ = ''
  166. )
  167. </if>
  168. <if test="query.auditVersion != null">
  169. and t.audit_version_ = #{query.auditVersion}
  170. </if>
  171. <if test="query.albumStatus != null">
  172. and t.album_status_ = #{query.albumStatus}
  173. </if>
  174. </where>
  175. <if test="query.albumFavorite != null">
  176. order by af2.favorite_time_ desc
  177. </if>
  178. </select>
  179. <select id="selectFavoriteNumAndMusicNum" resultType="com.yonge.cooleshow.biz.dal.vo.MusicAlbumVo">
  180. select
  181. t.id_ as id,
  182. ifnull(t1.num,0) as musicSheetCount
  183. ,ifnull(t2.num,0) as albumFavoriteCount
  184. from music_album t
  185. left join (select count(1) as num,amr.album_id_
  186. from album_music_relate amr
  187. join music_sheet ms on amr.music_sheet_id_ = ms.id_
  188. where ms.del_flag_ = 0 and ms.state_ = 1 and ms.audit_status_ = 'PASS' and find_in_set('PLATFORM',ms.provider_type_)
  189. group by amr.album_id_) t1 on t1.album_id_ = t.id_
  190. left join (select count(1) as num,af.album_id_ from album_favorite af
  191. group by af.album_id_
  192. ) t2 on t2.album_id_ = t.id_
  193. <where>
  194. t.del_flag_ = 0
  195. <if test="records != null and records.size() != 0">
  196. and t.id_ in
  197. <foreach collection="records" item="item" open="(" close=")" separator=",">
  198. #{item.id}
  199. </foreach>
  200. </if>
  201. </where>
  202. order by
  203. <if test="records != null and records.size() != 0">
  204. field(t.id_,
  205. <foreach collection="records" item="item" open="" close=")" separator=",">
  206. #{item.id}
  207. </foreach>
  208. </if>
  209. </select>
  210. <select id="selectMusicAlbumById" resultType="com.yonge.cooleshow.biz.dal.vo.MusicAlbumVo">
  211. select <include refid="Base_Column_List"/>
  212. ,(select group_concat(mt.name_) from music_tag mt
  213. where find_in_set(mt.id_,t.album_tag_) and mt.del_flag_ = 0 and mt.state_ = 1) as musicTagNames
  214. ,(select group_concat(s.name_) from subject s
  215. where find_in_set(s.id_,t.subject_id_) and s.del_flag_ = 0 ) as subjectNames
  216. , (
  217. select count(1) as num from album_music_relate amr
  218. join music_sheet ms on amr.music_sheet_id_ = ms.id_
  219. where ms.del_flag_ = 0 and ms.state_ = 1 and ms.audit_status_ = 'PASS' and find_in_set('PLATFORM',ms.provider_type_)
  220. and amr.album_id_ = t.id_
  221. ) as musicSheetCount
  222. ,(
  223. select count(1) as num from album_favorite af
  224. where af.album_id_ = t.id_
  225. ) as albumFavoriteCount
  226. from music_album t
  227. where t.id_ = #{musicAlbumId}
  228. </select>
  229. <select id="selectStudentPage" resultType="com.yonge.cooleshow.biz.dal.vo.MusicAlbumVo">
  230. select <include refid="Base_Column_List"/>
  231. ,(select group_concat(mt.name_) from music_tag mt
  232. where find_in_set(mt.id_,t.album_tag_) and mt.del_flag_ = 0 and mt.state_ = 1) as musicTagNames
  233. ,(select group_concat(s.name_) from subject s
  234. where find_in_set(s.id_,t.subject_id_) and s.del_flag_ = 0 ) as subjectNames
  235. ,(select count(1) as num
  236. from album_music_relate amr
  237. join music_sheet ms on amr.music_sheet_id_ = ms.id_
  238. where ms.del_flag_ = 0 and ms.state_ = 1 and ms.audit_status_ = 'PASS' and find_in_set('PLATFORM',ms.provider_type_)
  239. and amr.album_id_ = t.id_) as musicSheetCount
  240. ,if(t2.num >0,t2.num,0) as albumFavoriteCount
  241. from music_album t
  242. <if test="query.musicId != null">
  243. JOIN album_music_relate t1 ON (t.id_ = t1.album_id_ AND t1.music_sheet_id_ = #{query.musicId})
  244. </if>
  245. left join (select count(1) as num,af.album_id_ from album_favorite af
  246. group by af.album_id_
  247. ) t2 on t2.album_id_ = t.id_
  248. <if test="clientType != null and query.userId != null">
  249. 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}
  250. </if>
  251. <where>
  252. t.del_flag_ = 0
  253. <if test="query.idAndName != null and query.idAndName != ''">
  254. and (t.id_ like concat('%',#{query.idAndName},'%') or
  255. t.album_name_ like concat('%',#{query.idAndName},'%'))
  256. </if>
  257. <if test="query.albumTagIdList != null and query.albumTagIdList.size() != 0">
  258. and
  259. <foreach collection="query.albumTagIdList" open="(" close=")" separator="or" item="item">
  260. find_in_set(#{item},t.album_tag_)
  261. </foreach>
  262. </if>
  263. <if test="query.subjectIdList != null and query.subjectIdList.size() != 0">
  264. and (
  265. <foreach collection="query.subjectIdList" open="(" close=")" separator="or" item="item">
  266. find_in_set(#{item},t.subject_id_)
  267. </foreach>
  268. or t.subject_id_ is null or t.subject_id_ = ''
  269. )
  270. </if>
  271. <if test="query.albumStatus != null">
  272. and t.album_status_ = #{query.albumStatus}
  273. </if>
  274. <if test="query.auditVersion != null">
  275. and t.audit_version_ = #{query.auditVersion}
  276. </if>
  277. </where>
  278. order by
  279. <if test="clientType != null and query.userId != null">
  280. field(t3.id_,null,t3.id_) desc,
  281. </if>
  282. t.sort_number_ desc
  283. <if test="query.sortBy != null">
  284. <choose>
  285. <when test="query.sortBy == 1">
  286. ,t2.num desc
  287. </when>
  288. </choose>
  289. </if>
  290. ,t.id_ desc
  291. </select>
  292. <!--专辑曲目付费方式统计-->
  293. <select id="selectAlbumMusicSheetStatInfo"
  294. resultType="com.yonge.cooleshow.biz.dal.wrapper.StatGroupWrapper">
  295. SELECT t1.album_id_ AS id, COUNT(t1.id_) AS total
  296. FROM album_music_relate t1 JOIN music_sheet t2 ON (t1.music_sheet_id_ = t2.id_)
  297. <where>
  298. <if test="albumId != null">
  299. AND t1.album_id_ = #{albumId}
  300. </if>
  301. <if test="paymentType != null">
  302. AND t2.payment_type_ = #{paymentType}
  303. and find_in_set('PLATFORM',t2.provider_type_)
  304. </if>
  305. </where>
  306. GROUP BY t1.album_id_
  307. </select>
  308. <!--专辑曲目付费方式统计-->
  309. <select id="selectStudentOrderPage" resultType="com.yonge.cooleshow.biz.dal.vo.StudentMusicAlbumOrderVo">
  310. select distinct mspr.music_sheet_id_ as musicAlbumId
  311. ,ms.album_name_ as musicAlbumName
  312. ,ms.album_cover_url_ as titleImg
  313. ,(select group_concat(mt.name_) from music_tag mt
  314. where find_in_set(mt.id_,ms.album_tag_) and mt.del_flag_ = 0 and mt.state_ = 1) as TagNames
  315. ,mspr.purchase_price_ as purchasePrice
  316. ,mspr.order_no_ as orderNo
  317. ,mspr.purchase_time_ as purchaseTime
  318. from music_sheet_purchase_record mspr
  319. left join music_album ms on mspr.music_sheet_id_ = ms.id_
  320. <where>
  321. mspr.order_status_ = 'PAID' and mspr.purchase_type_ = 'ALBUM'
  322. <if test="param.idAndName != null and param.idAndName != ''">
  323. and (ms.id_ like concat('%',#{param.idAndName} ,'%')
  324. or ms.album_name_ like concat('%',#{param.idAndName},'%'))
  325. </if>
  326. <if test="param.studentId != null">
  327. and mspr.student_id_ = #{param.studentId}
  328. </if>
  329. <if test="param.orderNo != null and param.orderNo != ''">
  330. and mspr.order_no_ = #{param.orderNo}
  331. </if>
  332. <if test="param.musicTagList != null and param.musicTagList.size() != 0">
  333. and
  334. <foreach collection="param.musicTagList" separator="or" item="item" open="(" close=")" >
  335. find_in_set(#{item},ms.album_tag_)
  336. </foreach>
  337. </if>
  338. <if test="param.startTime != null">
  339. and mspr.purchase_time_ &gt; #{param.startTime}
  340. </if>
  341. <if test="param.endTime != null">
  342. and mspr.purchase_time_ &lt; #{param.endTime}
  343. </if>
  344. </where>
  345. order by mspr.id_ desc
  346. </select>
  347. </mapper>