123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248 |
- <?xml version="1.0" encoding="UTF-8"?>
- <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
- "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
- <mapper namespace="com.yonge.cooleshow.biz.dal.dao.MusicAlbumDao">
- <resultMap id="BaseResultMap" type="com.yonge.cooleshow.biz.dal.entity.MusicAlbum">
- <id column="id_" jdbcType="BIGINT" property="id"/>
- <result column="album_name_" jdbcType="VARCHAR" property="albumName"/>
- <result column="album_desc_" jdbcType="VARCHAR" property="albumDesc"/>
- <result column="album_tag_" jdbcType="VARCHAR" property="albumTag"/>
- <result column="subject_id_" jdbcType="VARCHAR" property="subjectId"/>
- <result column="album_cover_url_" jdbcType="VARCHAR" property="albumCoverUrl"/>
- <result column="album_status_" jdbcType="TINYINT" property="albumStatus"/>
- <result column="sort_number_" jdbcType="INTEGER" property="sortNumber"/>
- <result column="hot_flag_" jdbcType="TINYINT" property="hotFlag"/>
- <result column="top_flag_" jdbcType="TINYINT" property="topFlag"/>
- <result column="audit_version_" jdbcType="TINYINT" property="auditVersion"/>
- <result column="create_time_" jdbcType="TIMESTAMP" property="createTime"/>
- <result column="create_by_" jdbcType="BIGINT" property="createBy"/>
- <result column="update_time_" jdbcType="TIMESTAMP" property="updateTime"/>
- <result column="update_by_" jdbcType="BIGINT" property="updateBy"/>
- </resultMap>
- <sql id="Base_Column_List">
- t.id_,
- t.album_name_,
- t.album_desc_,
- t.album_tag_,
- t.subject_id_,
- t.album_cover_url_,
- t.album_status_,
- t.sort_number_,
- t.hot_flag_,
- t.top_flag_,
- t.create_time_,
- t.audit_version_,
- t.create_by_,
- t.update_time_,
- t.update_by_
- </sql>
- <select id="selectPage" resultType="com.yonge.cooleshow.biz.dal.vo.MusicAlbumVo">
- select <include refid="Base_Column_List"/>
- ,(select group_concat(mt.name_) from music_tag mt
- where find_in_set(mt.id_,t.album_tag_) and mt.del_flag_ = 0 and mt.state_ = 1) as musicTagNames
- ,(select group_concat(s.name_) from subject s
- where find_in_set(s.id_,t.subject_id_) and s.del_flag_ = 0 ) as subjectNames
- ,(select count(1) as num
- from album_music_relate amr
- join music_sheet ms on amr.music_sheet_id_ = ms.id_
- left join sys_user su on su.id_ = ms.user_id_
- where ms.del_flag_ = 0 and ms.state_ = 1 and ms.audit_status_ = 'PASS' and su.del_flag_ = 0
- and amr.album_id_ = t.id_) as musicSheetCount
- ,t2.num as albumFavoriteCount
- <if test="query.userId != null">
- ,(select count(1) from album_favorite af where af.album_id_ = t.id_ and af.user_id_ = #{query.userId}) as favorite
- </if>
- from music_album t
- left join (select count(1) as num,af.album_id_ from album_favorite af
- left join sys_user su on af.user_id_ = su.id_
- where su.del_flag_ = 0 group by af.album_id_
- ) t2 on t2.album_id_ = t.id_
- <where>
- t.del_flag_ = 0
- <if test="query.idAndName != null and query.idAndName != ''">
- and (t.id_ like concat('%',#{query.idAndName},'%') or
- t.album_name_ like concat('%',#{query.idAndName},'%'))
- </if>
- <if test="query.albumTagIdList != null and query.albumTagIdList.size() != 0">
- and
- <foreach collection="query.albumTagIdList" open="(" close=")" separator="or" item="item">
- find_in_set(#{item},t.album_tag_)
- </foreach>
- </if>
- <if test="query.subjectIdList != null and query.subjectIdList.size() != 0">
- and
- <foreach collection="query.subjectIdList" open="(" close=")" separator="or" item="item">
- find_in_set(#{item},t.subject_id_)
- </foreach>
- </if>
- <if test="query.albumStatus != null">
- and t.album_status_ = #{query.albumStatus}
- </if>
- <if test="query.auditVersion != null">
- and t.audit_version_ = #{query.auditVersion}
- </if>
- </where>
- order by t.sort_number_ desc
- <if test="query.sortBy != null">
- <choose>
- <when test="query.sortBy == 1">
- ,t2.num desc
- </when>
- </choose>
- </if>
- ,t.id_ desc
- </select>
- <select id="selectFavoritePage" resultType="com.yonge.cooleshow.biz.dal.vo.MusicAlbumVo">
- select <include refid="Base_Column_List"/>
- ,(select group_concat(mt.name_) from music_tag mt
- where find_in_set(mt.id_,t.album_tag_) and mt.del_flag_ = 0 and mt.state_ = 1) as musicTagNames
- ,(select group_concat(s.name_) from subject s
- where find_in_set(s.id_,t.subject_id_) and s.del_flag_ = 0 ) as subjectNames
- from music_album t
- left join album_favorite af2 on af2.album_id_ = t.id_
- <where>
- t.del_flag_ = 0
- <if test="query.studentId != null">
- and af2.user_id_ = #{query.studentId}
- </if>
- <if test="clientType != null">
- AND af2.client_type_ = #{clientType}
- </if>
- <if test="query.idAndName != null and query.idAndName != ''">
- and (t.id_ like concat('%',#{query.idAndName},'%') or
- t.album_name_ like concat('%',#{query.idAndName},'%'))
- </if>
- <if test="query.albumTagIdList != null and query.albumTagIdList.size() != 0">
- and
- <foreach collection="query.albumTagIdList" open="(" close=")" separator="or" item="item">
- find_in_set(#{item},t.album_tag_)
- </foreach>
- </if>
- <if test="query.subjectIdList != null and query.subjectIdList.size() != 0">
- and
- <foreach collection="query.subjectIdList" open="(" close=")" separator="or" item="item">
- find_in_set(#{item},t.subject_id_)
- </foreach>
- </if>
- <if test="query.auditVersion != null">
- and t.audit_version_ = #{query.auditVersion}
- </if>
- <if test="query.albumStatus != null">
- and t.album_status_ = #{query.albumStatus}
- </if>
- </where>
- order by af2.favorite_time_ desc
- </select>
- <select id="selectFavoriteNumAndMusicNum" resultType="com.yonge.cooleshow.biz.dal.vo.MusicAlbumVo">
- select
- t1.num as musicSheetCount
- ,t2.num as albumFavoriteCount
- from music_album t
- left join (select count(1) as num,amr.album_id_
- from album_music_relate amr
- join music_sheet ms on amr.music_sheet_id_ = ms.id_
- left join sys_user su on su.id_ = ms.user_id_
- where ms.del_flag_ = 0 and ms.state_ = 1 and ms.audit_status_ = 'PASS' and su.del_flag_ = 0
- group by amr.album_id_) t1 on t1.album_id_ = t.id_
- left join (select count(1) as num,af.album_id_ from album_favorite af
- left join sys_user su on af.user_id_ = su.id_
- where su.del_flag_ = 0 group by af.album_id_
- ) t2 on t2.album_id_ = t.id_
- <where>
- t.del_flag_ = 0
- <if test="records != null and records.size() != 0">
- and t.id_ in
- <foreach collection="records" item="item" open="(" close=")" separator=",">
- #{item.id}
- </foreach>
- </if>
- </where>
- order by
- <if test="records != null and records.size() != 0">
- field(t.id_,
- <foreach collection="records" item="item" open="" close=")" separator=",">
- #{item.id}
- </foreach>
- </if>
- </select>
- <select id="selectMusicAlbumById" resultType="com.yonge.cooleshow.biz.dal.vo.MusicAlbumVo">
- select <include refid="Base_Column_List"/>
- ,(select group_concat(mt.name_) from music_tag mt
- where find_in_set(mt.id_,t.album_tag_) and mt.del_flag_ = 0 and mt.state_ = 1) as musicTagNames
- ,(select group_concat(s.name_) from subject s
- where find_in_set(s.id_,t.subject_id_) and s.del_flag_ = 0 ) as subjectNames
- , (
- select count(1) as num from album_music_relate amr
- join music_sheet ms on amr.music_sheet_id_ = ms.id_
- left join sys_user su on su.id_ = ms.user_id_
- where ms.del_flag_ = 0 and ms.state_ = 1 and ms.audit_status_ = 'PASS' and su.del_flag_ = 0
- and amr.album_id_ = t.id_
- ) as musicSheetCount
- ,(
- select count(1) as num from album_favorite af
- left join sys_user su on af.user_id_ = su.id_
- where su.del_flag_ = 0 and af.album_id_ = t.id_
- ) as albumFavoriteCount
- from music_album t
- where t.id_ = #{musicAlbumId}
- </select>
- <select id="selectStudentPage" resultType="com.yonge.cooleshow.biz.dal.vo.MusicAlbumVo">
- select <include refid="Base_Column_List"/>
- ,(select group_concat(mt.name_) from music_tag mt
- where find_in_set(mt.id_,t.album_tag_) and mt.del_flag_ = 0 and mt.state_ = 1) as musicTagNames
- ,(select group_concat(s.name_) from subject s
- where find_in_set(s.id_,t.subject_id_) and s.del_flag_ = 0 ) as subjectNames
- ,(select count(1) as num
- from album_music_relate amr
- join music_sheet ms on amr.music_sheet_id_ = ms.id_
- left join sys_user su on su.id_ = ms.user_id_
- where ms.del_flag_ = 0 and ms.state_ = 1 and ms.audit_status_ = 'PASS' and su.del_flag_ = 0
- and amr.album_id_ = t.id_) as musicSheetCount
- ,if(t2.num >0,t2.num,0) as albumFavoriteCount
- from music_album t
- left join (select count(1) as num,af.album_id_ from album_favorite af
- left join sys_user su on (af.user_id_ = su.id_ <if test="clientType != null"> AND af.client_type_ = #{clientType} </if>)
- where su.del_flag_ = 0 group by af.album_id_
- ) t2 on t2.album_id_ = t.id_
- <where>
- t.del_flag_ = 0
- <if test="query.idAndName != null and query.idAndName != ''">
- and (t.id_ like concat('%',#{query.idAndName},'%') or
- t.album_name_ like concat('%',#{query.idAndName},'%'))
- </if>
- <if test="query.albumTagIdList != null and query.albumTagIdList.size() != 0">
- and
- <foreach collection="query.albumTagIdList" open="(" close=")" separator="or" item="item">
- find_in_set(#{item},t.album_tag_)
- </foreach>
- </if>
- <if test="query.subjectIdList != null and query.subjectIdList.size() != 0">
- and
- <foreach collection="query.subjectIdList" open="(" close=")" separator="or" item="item">
- find_in_set(#{item},t.subject_id_)
- </foreach>
- </if>
- <if test="query.albumStatus != null">
- and t.album_status_ = #{query.albumStatus}
- </if>
- <if test="query.auditVersion != null">
- and t.audit_version_ = #{query.auditVersion}
- </if>
- </where>
- order by t.sort_number_ desc
- <if test="query.sortBy != null">
- <choose>
- <when test="query.sortBy == 1">
- ,t2.num desc
- </when>
- </choose>
- </if>
- ,t.id_ desc
- </select>
- </mapper>
|