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

    <resultMap type="TestPlanCase" id="TestPlanCaseResult">
        <result property="id"    column="id"    />
        <result property="planId"    column="plan_id"    />
        <result property="caseId"    column="case_id"    />
        <result property="type"    column="type"    />
        <result property="executeResult"    column="execute_result"    />
        <result property="createTime"    column="create_time"    />
        <result property="createBy"    column="create_by"    />
        <result property="updateTime"    column="update_time"    />
        <result property="executeTime"    column="execute_time"    />
        <result property="executeBy"    column="execute_by"    />
        <result property="version"    column="version"    />
        <result property="delFlag"    column="del_flag"    />
        <result property="caseName"    column="name"    />
    </resultMap>

    <sql id="selectTestPlanCaseVo">
        select id, plan_id, case_id, type, execute_result, create_time, create_by, update_time, execute_time, execute_by, version, del_flag from test_plan_case
    </sql>

    <select id="selectTestPlanCaseList" parameterType="TestPlanCase" resultMap="TestPlanCaseResult">
        SELECT
        tp.id,
        tp.case_id,
        tc.name ,
        tp.execute_result,
        tp.create_by,
        tp.execute_by,
        tp.execute_time,
        tp.create_time
        FROM test_plan_case tp
        LEFT JOIN test_case tc ON tc.id = tp.case_id
        where tp.del_flag = '0'
        <if test="caseName != null  and caseName != ''"> AND tc.name LIKE concat('%', #{caseName}, '%') </if>
        <if test="caseId != null"> and case_id = #{caseId}</if>
        <if test="type != null"> and type = #{type}</if>
        <if test="planId != null"> and plan_id = #{planId}</if>
    </select>

    <select id="selectTestPlanCaseById" parameterType="Long" resultMap="TestPlanCaseResult">
        <include refid="selectTestPlanCaseVo"/>
        where id = #{id}
    </select>

    <insert id="insertTestPlanCase" parameterType="TestPlanCase">
        insert into test_plan_case
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="planId != null and planId != ''">plan_id,</if>
            <if test="caseId != null and caseId != ''">case_id,</if>
            type,
            <if test="executeResult != null">execute_result,</if>
            <if test="createTime != null">create_time,</if>
            <if test="createBy != null">create_by,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="executeTime != null">execute_time,</if>
            <if test="executeBy != null">execute_by,</if>
            <if test="version != null">version,</if>
            <if test="delFlag != null">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="caseId != null and caseId != ''">#{caseId},</if>
            #{type},
            <if test="executeResult != null">#{executeResult},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="executeTime != null">#{executeTime},</if>
            <if test="executeBy != null">#{executeBy},</if>
            <if test="version != null">#{version},</if>
            <if test="delFlag != null">#{delFlag},</if>
         </trim>
    </insert>

    <update id="updateTestPlanCase" parameterType="TestPlanCase">
        update test_plan_case
        <trim prefix="SET" suffixOverrides=",">
            <if test="planId != null and planId != ''">plan_id = #{planId},</if>
            <if test="caseId != null and caseId != ''">case_id = #{caseId},</if>
            <if test="type != null and type != ''">type = #{type},</if>
            <if test="executeResult != null">execute_result = #{executeResult},</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="executeTime != null">execute_time = #{executeTime},</if>
            <if test="executeBy != null">execute_by = #{executeBy},</if>
            <if test="version != null">version = #{version},</if>
            <if test="delFlag != null">del_flag = #{delFlag},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteTestPlanCaseById" parameterType="Long">
        delete from test_plan_case where id = #{id}
    </delete>

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