<?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.microservices.pms.project.mapper.PmsProjectTestcaseTypeMapper">

    <resultMap type="PmsProjectTestcaseType" id="PmsProjectTestcaseTypeResult">
        <result property="id" column="id"/>
        <result property="name" column="name"/>
        <result property="updateTime" column="update_time"/>
        <result property="updateBy" column="update_by"/>
        <result property="createTime" column="create_time"/>
        <result property="createBy" column="create_by"/>
        <result property="delFlag" column="del_flag"/>
        <result property="isDefault" column="is_default"/>
        <result property="reservedField1" column="reserved_field_1"/>
        <result property="reservedField2" column="reserved_field_2"/>
    </resultMap>

    <sql id="selectPmsProjectTestcaseTypeVo">
        select id,
               name,
               update_time,
               update_by,
               create_time,
               create_by,
               del_flag,
               is_default,
               reserved_field_1,
               reserved_field_2
        from pms_project_testcase_type
    </sql>

    <select id="selectPmsProjectTestcaseTypeList" parameterType="PmsProjectTestcaseType"
            resultMap="PmsProjectTestcaseTypeResult">
        <include refid="selectPmsProjectTestcaseTypeVo"/>
        <where>
            <if test="name != null  and name != ''">and name like concat('%', #{name}, '%')</if>
            <if test="isDefault != null ">and is_default = #{isDefault}</if>
            <if test="reservedField1 != null  and reservedField1 != ''">and reserved_field_1 = #{reservedField1}</if>
            <if test="reservedField2 != null  and reservedField2 != ''">and reserved_field_2 = #{reservedField2}</if>
        </where>
    </select>

    <select id="selectPmsProjectTestcaseTypeById" parameterType="Long" resultMap="PmsProjectTestcaseTypeResult">
        <include refid="selectPmsProjectTestcaseTypeVo"/>
        where id = #{id}
    </select>
    <select id="selectDefaultPmsProjectTestcaseType" resultMap="PmsProjectTestcaseTypeResult">
        <include refid="selectPmsProjectTestcaseTypeVo"/>
        where is_default = 1
    </select>

    <insert id="insertPmsProjectTestcaseType" parameterType="PmsProjectTestcaseType" useGeneratedKeys="true"
            keyProperty="id">
        insert into pms_project_testcase_type
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="name != null and name != ''">name,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="createBy != null">create_by,</if>
            <if test="delFlag != null">del_flag,</if>
            <if test="isDefault != null">is_default,</if>
            <if test="reservedField1 != null">reserved_field_1,</if>
            <if test="reservedField2 != null">reserved_field_2,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="name != null and name != ''">#{name},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="delFlag != null">#{delFlag},</if>
            <if test="isDefault != null">#{isDefault},</if>
            <if test="reservedField1 != null">#{reservedField1},</if>
            <if test="reservedField2 != null">#{reservedField2},</if>
        </trim>
    </insert>

    <update id="updatePmsProjectTestcaseType" parameterType="PmsProjectTestcaseType">
        update pms_project_testcase_type
        <trim prefix="SET" suffixOverrides=",">
            <if test="name != null and name != ''">name = #{name},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="delFlag != null">del_flag = #{delFlag},</if>
            <if test="isDefault != null">is_default = #{isDefault},</if>
            <if test="reservedField1 != null">reserved_field_1 = #{reservedField1},</if>
            <if test="reservedField2 != null">reserved_field_2 = #{reservedField2},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deletePmsProjectTestcaseTypeById" parameterType="Long">
        delete
        from pms_project_testcase_type
        where id = #{id}
    </delete>

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