<?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.test.test.mapper.TestPlanDefectMapper">

    <resultMap type="TestPlanDefect" id="TestPlanDefectResult">
        <result property="id"    column="id"    />
        <result property="planId"    column="plan_id"    />
        <result property="defectId"    column="defect_id"    />
        <result property="type"    column="type"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateTime"    column="update_time"    />
        <result property="version"    column="version"    />
        <result property="delFlag"    column="del_flag"    />
    </resultMap>

    <sql id="selectTestPlanDefectVo">
        select id, plan_id, defect_id, type, create_time, update_time, version, del_flag from test_plan_defect
    </sql>

    <select id="selectTestPlanDefectList" parameterType="TestPlanDefect" resultMap="TestPlanDefectResult">
        <include refid="selectTestPlanDefectVo"/>
        <where>
            <if test="planId != null  and planId != ''"> and plan_id = #{planId}</if>
            <if test="defectId != null  and defectId != ''"> and defect_id = #{defectId}</if>
            <if test="type != null  and type != ''"> and type = #{type}</if>
            <if test="version != null  and version != ''"> and version = #{version}</if>
        </where>
    </select>

    <select id="selectTestPlanDefectById" parameterType="Long" resultMap="TestPlanDefectResult">
        <include refid="selectTestPlanDefectVo"/>
        where id = #{id}
    </select>

    <insert id="insertTestPlanDefect" parameterType="TestPlanDefect">
        insert into test_plan_defect
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="planId != null and planId != ''">plan_id,</if>
            <if test="defectId != null and defectId != ''">defect_id,</if>
            <if test="type != null and type != ''">type,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="version != null">version,</if>
            <if test="delFlag != null and delFlag != ''">del_flag,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="planId != null and planId != ''">#{planId},</if>
            <if test="defectId != null and defectId != ''">#{defectId},</if>
            <if test="type != null and type != ''">#{type},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="version != null">#{version},</if>
            <if test="delFlag != null and delFlag != ''">#{delFlag},</if>
         </trim>
    </insert>

    <update id="updateTestPlanDefect" parameterType="TestPlanDefect">
        update test_plan_defect
        <trim prefix="SET" suffixOverrides=",">
            <if test="planId != null and planId != ''">plan_id = #{planId},</if>
            <if test="defectId != null and defectId != ''">defect_id = #{defectId},</if>
            <if test="type != null and type != ''">type = #{type},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="version != null">version = #{version},</if>
            <if test="delFlag != null and delFlag != ''">del_flag = #{delFlag},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteTestPlanDefectById" parameterType="Long">
        delete from test_plan_defect where id = #{id}
    </delete>

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