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

    <resultMap type="XysCategory" id="XysCategoryResult">
        <result property="id"    column="id"    />
        <result property="parentId"    column="parent_id"    />
        <result property="title"    column="title"    />
        <result property="coverImg"    column="cover_img"    />
        <result property="description"    column="description"    />
        <result property="createTime"    column="create_time"    />
        <result property="createBy"    column="create_by"    />
        <result property="updateTime"    column="update_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="remark"    column="remark"    />
        <result property="delFlag"    column="del_flag"    />
    </resultMap>

    <sql id="selectXysCategoryVo">
        select id, parent_id, title, cover_img, description, create_time, create_by, update_time, update_by, remark, del_flag from xys_category
    </sql>

    <select id="selectXysCategoryList" parameterType="XysCategory" resultMap="XysCategoryResult">
        <include refid="selectXysCategoryVo"/>
        <where>
            <if test="parentId != null "> and parent_id = #{parentId}</if>
            <if test="title != null  and title != ''"> and title = #{title}</if>
            <if test="coverImg != null  and coverImg != ''"> and cover_img = #{coverImg}</if>
            <if test="description != null  and description != ''"> and description = #{description}</if>
        </where>
    </select>

    <select id="selectXysCategoryById" parameterType="Long" resultMap="XysCategoryResult">
        <include refid="selectXysCategoryVo"/>
        where id = #{id}
    </select>

    <insert id="insertXysCategory" parameterType="XysCategory">
        insert into xys_category
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="parentId != null">parent_id,</if>
            <if test="title != null">title,</if>
            <if test="coverImg != null">cover_img,</if>
            <if test="description != null">description,</if>
            <if test="createTime != null">create_time,</if>
            <if test="createBy != null">create_by,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="remark != null">remark,</if>
            <if test="delFlag != null">del_flag,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="parentId != null">#{parentId},</if>
            <if test="title != null">#{title},</if>
            <if test="coverImg != null">#{coverImg},</if>
            <if test="description != null">#{description},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="remark != null">#{remark},</if>
            <if test="delFlag != null">#{delFlag},</if>
        </trim>
    </insert>

    <update id="updateXysCategory" parameterType="XysCategory">
        update xys_category
        <trim prefix="SET" suffixOverrides=",">
            <if test="parentId != null">parent_id = #{parentId},</if>
            <if test="title != null">title = #{title},</if>
            <if test="coverImg != null">cover_img = #{coverImg},</if>
            <if test="description != null">description = #{description},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="remark != null">remark = #{remark},</if>
            <if test="delFlag != null">del_flag = #{delFlag},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteXysCategoryById" parameterType="Long">
        delete from xys_category where id = #{id}
    </delete>

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