<?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.MusicCollectMapper">
    
    <resultMap type="MusicCollect" id="MusicCollectResult">
        <result property="id"    column="id"    />
        <result property="musicId"    column="music_id"    />
        <result property="collectId"    column="collect_id"    />
    </resultMap>

    <sql id="selectMusicCollectVo">
        select id, music_id, collect_id from music_collect
    </sql>

    <select id="selectMusicCollectList" parameterType="MusicCollect" resultMap="MusicCollectResult">
        <include refid="selectMusicCollectVo"/>
        <where>  
            <if test="musicId != null "> and music_id = #{musicId}</if>
            <if test="collectId != null "> and collect_id = #{collectId}</if>
        </where>
    </select>
    
    <select id="selectMusicCollectById" parameterType="String" resultMap="MusicCollectResult">
        <include refid="selectMusicCollectVo"/>
        where id = #{id}
    </select>

    <insert id="insertMusicCollect" parameterType="MusicCollect" useGeneratedKeys="true" keyProperty="id">
        insert into music_collect
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="musicId != null">music_id,</if>
            <if test="collectId != null">collect_id,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="musicId != null">#{musicId},</if>
            <if test="collectId != null">#{collectId},</if>
         </trim>
    </insert>

    <update id="updateMusicCollect" parameterType="MusicCollect">
        update music_collect
        <trim prefix="SET" suffixOverrides=",">
            <if test="musicId != null">music_id = #{musicId},</if>
            <if test="collectId != null">collect_id = #{collectId},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteMusicCollectById" parameterType="String">
        delete from music_collect where id = #{id}
    </delete>

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

    <delete id="delBindMusic">
        delete from music_collect where collect_id=#{collectId} and music_id in
            <foreach collection="musicIds" item="musicId" open="(" close=")" separator=",">
                #{musicId}
            </foreach>
    </delete>

    <select id="selectCollectIdAndMusicId" resultMap="MusicCollectResult">
        SELECT * FROM  music_collect where music_id=#{musicId} and collect_id=#{collectId}
    </select>
</mapper>