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

    <resultMap type="TestTaskResult" id="TestTaskResultResult">
        <result property="id"    column="id"    />
        <result property="taskId"    column="task_id"    />
        <result property="triggerTime"    column="trigger_time"    />
        <result property="startTime"    column="start_time"    />
        <result property="triggerType"    column="trigger_type"    />
        <result property="environment"    column="environment"    />
        <result property="status"    column="status"    />
        <result property="sendStatus"    column="send_status"    />
        <result property="costTime"    column="cost_time"    />
        <result property="caseCount"    column="case_count"    />
        <result property="caseStepCount"    column="case_step_count"    />
        <result property="resultDesc"    column="result_desc"    />
        <result property="createTime"    column="create_time"    />
    </resultMap>

    <sql id="selectTestTaskResultVo">
        select id, task_id, trigger_time, start_time, trigger_type, environment, status, send_status, cost_time, case_count, case_step_count, result_desc, create_time from test_task_result
    </sql>

    <select id="selectTestTaskResultList" parameterType="TestTaskResult" resultMap="TestTaskResultResult">
        <include refid="selectTestTaskResultVo"/>
        <where>
            <if test="taskId != null "> and task_id = #{taskId}</if>
            <if test="triggerTime != null "> and trigger_time = #{triggerTime}</if>
            <if test="startTime != null "> and start_time = #{startTime}</if>
            <if test="triggerType != null "> and trigger_type = #{triggerType}</if>
            <if test="environment != null  and environment != ''"> and environment = #{environment}</if>
            <if test="status != null "> and status = #{status}</if>
            <if test="sendStatus != null "> and send_status = #{sendStatus}</if>
            <if test="costTime != null "> and cost_time = #{costTime}</if>
            <if test="caseCount != null "> and case_count = #{caseCount}</if>
            <if test="caseStepCount != null "> and case_step_count = #{caseStepCount}</if>
            <if test="resultDesc != null  and resultDesc != ''"> and result_desc = #{resultDesc}</if>
        </where>
        order by create_time desc
    </select>

    <select id="selectTestTaskResultById" parameterType="Long" resultMap="TestTaskResultResult">
        <include refid="selectTestTaskResultVo"/>
        where id = #{id}
    </select>

    <insert id="insertTestTaskResult" parameterType="TestTaskResult" useGeneratedKeys="true" keyProperty="id">
        insert into test_task_result
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="taskId != null">task_id,</if>
            <if test="triggerTime != null">trigger_time,</if>
            <if test="startTime != null">start_time,</if>
            <if test="triggerType != null">trigger_type,</if>
            <if test="environment != null">environment,</if>
            <if test="status != null">status,</if>
            <if test="sendStatus != null">send_status,</if>
            <if test="costTime != null">cost_time,</if>
            <if test="caseCount != null">case_count,</if>
            <if test="caseStepCount != null">case_step_count,</if>
            <if test="resultDesc != null">result_desc,</if>
            <if test="createTime != null">create_time,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="taskId != null">#{taskId},</if>
            <if test="triggerTime != null">#{triggerTime},</if>
            <if test="startTime != null">#{startTime},</if>
            <if test="triggerType != null">#{triggerType},</if>
            <if test="environment != null">#{environment},</if>
            <if test="status != null">#{status},</if>
            <if test="sendStatus != null">#{sendStatus},</if>
            <if test="costTime != null">#{costTime},</if>
            <if test="caseCount != null">#{caseCount},</if>
            <if test="caseStepCount != null">#{caseStepCount},</if>
            <if test="resultDesc != null">#{resultDesc},</if>
            <if test="createTime != null">#{createTime},</if>
         </trim>
    </insert>

    <update id="updateTestTaskResult" parameterType="TestTaskResult">
        update test_task_result
        <trim prefix="SET" suffixOverrides=",">
            <if test="taskId != null">task_id = #{taskId},</if>
            <if test="triggerTime != null">trigger_time = #{triggerTime},</if>
            <if test="startTime != null">start_time = #{startTime},</if>
            <if test="triggerType != null">trigger_type = #{triggerType},</if>
            <if test="environment != null">environment = #{environment},</if>
            <if test="status != null">status = #{status},</if>
            <if test="sendStatus != null">send_status = #{sendStatus},</if>
            <if test="costTime != null">cost_time = #{costTime},</if>
            <if test="caseCount != null">case_count = #{caseCount},</if>
            <if test="caseStepCount != null">case_step_count = #{caseStepCount},</if>
            <if test="resultDesc != null">result_desc = #{resultDesc},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteTestTaskResultById" parameterType="Long">
        delete from test_task_result where id = #{id}
    </delete>

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