<?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.abuwx.mapper.QuestionCategoryMapper">
    
    <resultMap type="QuestionCategory" id="QuestionCategoryResult">
        <result property="id"    column="id"    />
        <result property="name"    column="name"    />
        <result property="sort"    column="sort"    />
        <result property="remark"    column="remark"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateTime"    column="update_time"    />
        <result property="createBy"    column="create_by"    />
        <result property="updateBy"    column="update_by"    />
    </resultMap>

    <sql id="selectQuestionCategoryVo">
        select id, name, sort, remark, create_time, update_time, create_by, update_by from question_category
    </sql>

    <select id="selectQuestionCategoryList" parameterType="QuestionCategory" resultMap="QuestionCategoryResult">
        <include refid="selectQuestionCategoryVo"/>
        <where>  
            <if test="name != null  and name != ''"> and name like concat('%', #{name}, '%')</if>
            <if test="sort != null  and sort != ''"> and sort = #{sort}</if>
        </where>
    </select>
    
    <select id="selectQuestionCategoryById" parameterType="Long" resultMap="QuestionCategoryResult">
        <include refid="selectQuestionCategoryVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertQuestionCategory" parameterType="QuestionCategory" useGeneratedKeys="true" keyProperty="id">
        insert into question_category
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="name != null">name,</if>
            <if test="sort != null">sort,</if>
            <if test="remark != null">remark,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="createBy != null">create_by,</if>
            <if test="updateBy != null">update_by,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="name != null">#{name},</if>
            <if test="sort != null">#{sort},</if>
            <if test="remark != null">#{remark},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="updateBy != null">#{updateBy},</if>
         </trim>
    </insert>

    <update id="updateQuestionCategory" parameterType="QuestionCategory">
        update question_category
        <trim prefix="SET" suffixOverrides=",">
            <if test="name != null">name = #{name},</if>
            <if test="sort != null">sort = #{sort},</if>
            <if test="remark != null">remark = #{remark},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteQuestionCategoryById" parameterType="Long">
        delete from question_category where id = #{id}
    </delete>

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