<?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.yanzhu.exam.questions.mapper.ExamTypeMapper">
    
    <resultMap type="com.yanzhu.exam.questions.domain.ExamType" id="ExamTypeResult">
        <result property="typeId"    column="type_id"    />
        <result property="parentId"    column="parent_id"    />
        <result property="typeCode"    column="type_code"    />
        <result property="typeName"    column="type_name"    />
        <result property="orderId"    column="order_id"    />
        <result property="status"    column="status"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
    </resultMap>

    <sql id="selectExamTypeVo">
        select type_id, parent_id, type_code, type_name, order_id, status, create_by, create_time from exam_type
    </sql>

    <select id="selectExamTypeList" parameterType="com.yanzhu.exam.questions.domain.ExamType" resultMap="ExamTypeResult">
        <include refid="selectExamTypeVo"/>
        <where>  
            <if test="typeName != null  and typeName != ''"> and type_name like '%' || #{typeName} || '%'</if>
        </where>
    </select>
    
    <select id="selectExamTypeById" parameterType="Long" resultMap="ExamTypeResult">
        <include refid="selectExamTypeVo"/>
        where type_id = #{typeId}
    </select>
        
    <insert id="insertExamType" parameterType="com.yanzhu.exam.questions.domain.ExamType" >
        insert into exam_type
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="parentId != null">parent_id,</if>
            <if test="typeCode != null">type_code,</if>
            <if test="typeName != null and typeName != ''">type_name,</if>
            <if test="orderId != null">order_id,</if>
            status,
            <if test="createBy != null">create_by,</if>
            create_time,
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="parentId != null">#{parentId},</if>
            <if test="typeCode != null">#{typeCode},</if>
            <if test="typeName != null and typeName != ''">#{typeName},</if>
            <if test="orderId != null">#{orderId},</if>
            0,
            <if test="createBy != null">#{createBy},</if>
            now(),
         </trim>
    </insert>

    <update id="updateExamType" parameterType="com.yanzhu.exam.questions.domain.ExamType">
        update exam_type
        <trim prefix="SET" suffixOverrides=",">
            <if test="parentId != null">parent_id = #{parentId},</if>
            <if test="typeCode != null">type_code = #{typeCode},</if>
            <if test="typeName != null and typeName != ''">type_name = #{typeName},</if>
            <if test="orderId != null">order_id = #{orderId},</if>
            <if test="status != null">status = #{status},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
        </trim>
        where type_id = #{typeId}
    </update>

    <delete id="deleteExamTypeById" parameterType="Long">
        delete from exam_type where type_id = #{typeId}
    </delete>

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