<?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.RecommendInfoMapper">
    
    <resultMap type="RecommendInfo" id="RecommendInfoResult">
        <result property="id"    column="id"    />
        <result property="name"    column="name"    />
        <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="desc"    column="desc"    />
    </resultMap>

    <sql id="selectRecommendInfoVo">
        select id, name, creator, modify, create_time, update_time, is_del, `desc` from recommend_info
    </sql>

    <select id="selectRecommendInfoList" parameterType="RecommendInfo" resultMap="RecommendInfoResult">
        <include refid="selectRecommendInfoVo"/>
        <where>  
            <if test="name != null  and name != ''"> and name like concat('%', #{name}, '%')</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="desc != null  and desc != ''"> and `desc` = #{desc}</if>
        </where>
    </select>
    
    <select id="selectRecommendInfoById" parameterType="Long" resultMap="RecommendInfoResult">
        <include refid="selectRecommendInfoVo"/>
        where id = #{id}
    </select>

    <insert id="insertRecommendInfo" parameterType="RecommendInfo">
        insert into recommend_info
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="name != null">name,</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="desc != null">desc,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="name != null">#{name},</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="desc != null">#{desc},</if>
         </trim>
    </insert>

    <update id="updateRecommendInfo" parameterType="RecommendInfo">
        update recommend_info
        <trim prefix="SET" suffixOverrides=",">
            <if test="name != null">name = #{name},</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="desc != null">desc = #{desc},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteRecommendInfoById" parameterType="Long">
        delete from recommend_info where id = #{id}
    </delete>

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

    <insert id="bindMusic">
        insert into music_recommend(recommend_id,music_id) values
        <foreach item="id" collection="musicIds" separator=",">
            (#{reId},#{id})
        </foreach>
    </insert>

    <select id="selectMusicRecommend" resultMap="RecommendInfoResult">
        SELECT ri.* FROM music_recommend mr LEFT JOIN recommend_info ri on mr.recommend_id = ri.id and ri.is_del=0
    </select>
</mapper>