<?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.UserLikeMusicMapper">
    
    <resultMap type="UserLikeMusic" id="UserLikeMusicResult">
        <result property="id"    column="id"    />
        <result property="musicId"    column="music_id"    />
        <result property="userId"    column="user_id"    />
    </resultMap>

    <sql id="selectUserLikeMusicVo">
        select id, music_id, user_id from user_like_music
    </sql>

    <select id="selectUserLikeMusicList" parameterType="UserLikeMusic" resultMap="UserLikeMusicResult">
        <include refid="selectUserLikeMusicVo"/>
        <where>  
            <if test="musicId != null "> and music_id = #{musicId}</if>
            <if test="userId != null "> and user_id = #{userId}</if>
        </where>
    </select>
    
    <select id="selectUserLikeMusicById" parameterType="String" resultMap="UserLikeMusicResult">
        <include refid="selectUserLikeMusicVo"/>
        where id = #{id}
    </select>

    <insert id="insertUserLikeMusic" parameterType="UserLikeMusic" useGeneratedKeys="true" keyProperty="id">
        insert into user_like_music
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="musicId != null">music_id,</if>
            <if test="userId != null">user_id,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="musicId != null">#{musicId},</if>
            <if test="userId != null">#{userId},</if>
         </trim>
    </insert>

    <update id="updateUserLikeMusic" parameterType="UserLikeMusic">
        update user_like_music
        <trim prefix="SET" suffixOverrides=",">
            <if test="musicId != null">music_id = #{musicId},</if>
            <if test="userId != null">user_id = #{userId},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteUserLikeMusicById" parameterType="String">
        delete from user_like_music where id = #{id}
    </delete>

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

    <select id="selectUserLikeMusicAndUserId" resultType="com.ruoyi.common.core.domain.entity.UserLikeMusic">
        SELECT user_id as userId,music_id as musicId FROM  user_like_music where user_id=#{userId} and music_id=#{musicId}
    </select>
</mapper>