MusicAlbumMapper.xml 14 KB

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