<?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.ruoyi.system.mapper.MusicInfoMapper">
    
    <resultMap type="MusicInfo" id="MusicInfoResult">
        <result property="id"    column="id"    />
        <result property="musicId"    column="music_id"    />
        <result property="name"    column="name"    />
        <result property="author"    column="author"    />
        <result property="vip"    column="vip"    />
        <result property="shelf"    column="shelf"    />
        <result property="imgAddr"    column="img_addr"    />
        <result property="musicAddr"    column="music_addr"    />
        <result property="musicType"    column="music_type"    />
        <result property="creator"    column="creator"    />
        <result property="modify"    column="modify"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateTime"    column="update_time"    />
        <result property="isDel"    column="is_del"    />
        <result property="label"    column="label"    />
    </resultMap>

    <sql id="selectMusicInfoVo">
        select id, music_id, name, author, vip, shelf, img_addr, music_addr, music_type, creator, modify, create_time, update_time, is_del, label from music_info
    </sql>

    <select id="selectMusicInfoList" parameterType="MusicInfo" resultMap="MusicInfoResult">
        <include refid="selectMusicInfoVo"/>
        <where>  
            <if test="musicId != null "> and music_id = #{musicId}</if>
            <if test="name != null  and name != ''"> and name like concat('%', #{name}, '%')</if>
            <if test="author != null  and author != ''"> and author = #{author}</if>
            <if test="vip != null "> and vip = #{vip}</if>
            <if test="shelf != null "> and shelf = #{shelf}</if>
            <if test="imgAddr != null  and imgAddr != ''"> and img_addr = #{imgAddr}</if>
            <if test="musicAddr != null  and musicAddr != ''"> and music_addr = #{musicAddr}</if>
            <if test="musicType != null  and musicType != ''"> and music_type = #{musicType}</if>
            <if test="creator != null  and creator != ''"> and creator = #{creator}</if>
            <if test="modify != null  and modify != ''"> and modify = #{modify}</if>
            <if test="isDel != null "> and is_del = #{isDel}</if>
            <if test="label != null  and label != ''"> and label = #{label}</if>
        </where>
    </select>
    
    <select id="selectMusicInfoById" parameterType="String" resultMap="MusicInfoResult">
        <include refid="selectMusicInfoVo"/>
        where id = #{id}
    </select>

    <insert id="insertMusicInfo" parameterType="MusicInfo" useGeneratedKeys="true" keyProperty="id">
        insert into music_info
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="musicId != null">music_id,</if>
            <if test="name != null">name,</if>
            <if test="author != null">author,</if>
            <if test="vip != null">vip,</if>
            <if test="shelf != null">shelf,</if>
            <if test="imgAddr != null">img_addr,</if>
            <if test="musicAddr != null">music_addr,</if>
            <if test="musicType != null">music_type,</if>
            <if test="creator != null">creator,</if>
            <if test="modify != null">modify,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="isDel != null">is_del,</if>
            <if test="label != null">label,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="musicId != null">#{musicId},</if>
            <if test="name != null">#{name},</if>
            <if test="author != null">#{author},</if>
            <if test="vip != null">#{vip},</if>
            <if test="shelf != null">#{shelf},</if>
            <if test="imgAddr != null">#{imgAddr},</if>
            <if test="musicAddr != null">#{musicAddr},</if>
            <if test="musicType != null">#{musicType},</if>
            <if test="creator != null">#{creator},</if>
            <if test="modify != null">#{modify},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="isDel != null">#{isDel},</if>
            <if test="label != null">#{label},</if>
         </trim>
    </insert>

    <update id="updateMusicInfo" parameterType="MusicInfo">
        update music_info
        <trim prefix="SET" suffixOverrides=",">
            <if test="musicId != null">music_id = #{musicId},</if>
            <if test="name != null">name = #{name},</if>
            <if test="author != null">author = #{author},</if>
            <if test="vip != null">vip = #{vip},</if>
            <if test="shelf != null">shelf = #{shelf},</if>
            <if test="imgAddr != null">img_addr = #{imgAddr},</if>
            <if test="musicAddr != null">music_addr = #{musicAddr},</if>
            <if test="musicType != null">music_type = #{musicType},</if>
            <if test="creator != null">creator = #{creator},</if>
            <if test="modify != null">modify = #{modify},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="isDel != null">is_del = #{isDel},</if>
            <if test="label != null">label = #{label},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteMusicInfoById" parameterType="String">
        delete from music_info where id = #{id}
    </delete>

    <delete id="deleteMusicInfoByIds" parameterType="String">
        delete from music_info where id in 
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>

    <select id="selectByCate" resultType="com.ruoyi.common.core.domain.entity.MusicInfo">
        
    </select>

    <select id="selectMusicInfoByCid" resultMap="MusicInfoResult">
        SELECT m.* FROM music_category mc left JOIN music_info m on mc.music_id = m.music_id WHERE mc.category_id = #{categoryId} and m.shelf=1 and m.is_del=0
    </select>
</mapper>