<?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.CategoryInfoMapper">

    <resultMap type="CategoryInfo" id="CategoryInfoResult">
        <result property="id"    column="id"    />
        <result property="categoryId"    column="category_id"    />
        <result property="name"    column="name"    />
        <result property="isDel"    column="is_del"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateTime"    column="update_time"    />
        <result property="creator"    column="creator"    />
        <result property="modify"    column="modify"    />
    </resultMap>

    <sql id="selectCategoryInfoVo">
        select id, category_id, name, is_del, create_time, update_time, creator, modify from category_info
    </sql>

    <select id="selectCategoryInfoList" parameterType="CategoryInfo" resultMap="CategoryInfoResult">
        <include refid="selectCategoryInfoVo"/>
        <where>
            <if test="categoryId != null "> and category_id = #{categoryId}</if>
            <if test="name != null  and name != ''"> and name like concat('%', #{name}, '%')</if>
            <if test="isDel != null "> and is_del = #{isDel}</if>
            <if test="creator != null  and creator != ''"> and creator = #{creator}</if>
            <if test="modify != null  and modify != ''"> and modify = #{modify}</if>
        </where>
    </select>

    <select id="selectCategoryInfoById" parameterType="String" resultMap="CategoryInfoResult">
        <include refid="selectCategoryInfoVo"/>
        where id = #{id}
    </select>

    <insert id="insertCategoryInfo" parameterType="CategoryInfo" useGeneratedKeys="true" keyProperty="id">
        insert into category_info
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="categoryId != null">category_id,</if>
            <if test="name != null">name,</if>
            <if test="isDel != null">is_del,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="creator != null">creator,</if>
            <if test="modify != null">modify,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="categoryId != null">#{categoryId},</if>
            <if test="name != null">#{name},</if>
            <if test="isDel != null">#{isDel},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="creator != null">#{creator},</if>
            <if test="modify != null">#{modify},</if>
         </trim>
    </insert>

    <update id="updateCategoryInfo" parameterType="CategoryInfo">
        update category_info
        <trim prefix="SET" suffixOverrides=",">
            <if test="categoryId != null">category_id = #{categoryId},</if>
            <if test="name != null">name = #{name},</if>
            <if test="isDel != null">is_del = #{isDel},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="creator != null">creator = #{creator},</if>
            <if test="modify != null">modify = #{modify},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteCategoryInfoById" parameterType="String">
        delete from category_info where id = #{id}
    </delete>

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

    <select id="selectCategoryList" resultMap="CategoryInfoResult">
        <include refid="selectCategoryInfoVo" /> where is_del = 0
    </select>

    <insert id="bindMusic">
        insert into music_category(music_id,category_id) values
        <foreach item="id" collection="ids" separator=",">
            (#{id},#{categoryId})
        </foreach>

    </insert>

</mapper>
