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

    <resultMap type="TestCaseResult" id="TestCaseResultResult">
        <result property="id"    column="id"    />
        <result property="caseId"    column="case_id"    />
        <result property="stepId"    column="step_id"    />
        <result property="requestHeader"    column="request_header"    />
        <result property="requestBody"    column="request_body"    />
        <result property="responseHeader"    column="response_header"    />
        <result property="responseBody"    column="response_body"    />
        <result property="sqlResult"    column="sql_result"    />
        <result property="pollingCount"    column="polling_count"    />
        <result property="loopCount"    column="loop_count"    />
        <result property="assignment"    column="assignment"    />
        <result property="assertion"    column="assertion"    />
        <result property="useTime"    column="use_time"    />
        <result property="executeTime"    column="execute_time"    />
        <result property="status"    column="status"    />
        <result property="caseSid" column="case_sid"/>
    </resultMap>

    <sql id="selectTestCaseResultVo">
        select id, case_id, case_sid, step_id, request_header, request_body, response_header, response_body, sql_result, polling_count, loop_count, assignment, assertion, use_time, execute_time, status from test_case_result
    </sql>

    <sql id="selectMinTestCaseResultVo">
        select id, case_id, case_sid, step_id, polling_count, loop_count, use_time, execute_time, status from test_case_result
    </sql>

    <select id="selectTestCaseResultList" parameterType="TestCaseResult" resultMap="TestCaseResultResult">
        <include refid="selectTestCaseResultVo"/>
        <where>
            <if test="caseId != null "> and case_id = #{caseId}</if>
            <if test="stepId != null "> and step_id = #{stepId}</if>
            <if test="requestHeader != null  and requestHeader != ''"> and request_header = #{requestHeader}</if>
            <if test="requestBody != null  and requestBody != ''"> and request_body = #{requestBody}</if>
            <if test="responseHeader != null  and responseHeader != ''"> and response_header = #{responseHeader}</if>
            <if test="responseBody != null  and responseBody != ''"> and response_body = #{responseBody}</if>
            <if test="sqlResult != null  and sqlResult != ''"> and sql_result = #{sqlResult}</if>
            <if test="pollingCount != null "> and polling_count = #{pollingCount}</if>
            <if test="loopCount != null "> and loop_count = #{loopCount}</if>
            <if test="assignment != null  and assignment != ''"> and assignment = #{assignment}</if>
            <if test="assertion != null  and assertion != ''"> and assertion = #{assertion}</if>
            <if test="useTime != null "> and use_time = #{useTime}</if>
            <if test="executeTime != null "> and execute_time = #{executeTime}</if>
            <if test="status != null  and status != ''"> and status = #{status}</if>
            <if test="caseSid != null">and case_sid = #{caseSid}</if>
        </where>
    </select>

    <select id="selectMinTestCaseResultList" parameterType="TestCaseResult" resultMap="TestCaseResultResult">
        <include refid="selectMinTestCaseResultVo"/>
        <where>
            <if test="caseId != null "> and case_id = #{caseId}</if>
            <if test="stepId != null "> and step_id = #{stepId}</if>
            <if test="useTime != null "> and use_time = #{useTime}</if>
            <if test="executeTime != null "> and execute_time = #{executeTime}</if>
            <if test="status != null  and status != ''"> and status = #{status}</if>
            <if test="caseSid != null">and case_sid = #{caseSid}</if>
        </where>
        order by execute_time desc
    </select>

    <select id="selectTestCaseResultById" parameterType="Long" resultMap="TestCaseResultResult">
        <include refid="selectTestCaseResultVo"/>
        where id = #{id}
    </select>

    <insert id="insertTestCaseResult" parameterType="TestCaseResult" useGeneratedKeys="true" keyProperty="id">
        insert into test_case_result
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="caseId != null">case_id,</if>
            <if test="stepId != null">step_id,</if>
            <if test="requestHeader != null">request_header,</if>
            <if test="requestBody != null">request_body,</if>
            <if test="responseHeader != null">response_header,</if>
            <if test="responseBody != null">response_body,</if>
            <if test="sqlResult != null">sql_result,</if>
            <if test="pollingCount != null">polling_count,</if>
            <if test="loopCount != null">loop_count,</if>
            <if test="assignment != null">assignment,</if>
            <if test="assertion != null">assertion,</if>
            <if test="useTime != null">use_time,</if>
            <if test="executeTime != null">execute_time,</if>
            <if test="status != null">status,</if>
            <if test="caseSid != null">case_sid,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="caseId != null">#{caseId},</if>
            <if test="stepId != null">#{stepId},</if>
            <if test="requestHeader != null">#{requestHeader},</if>
            <if test="requestBody != null">#{requestBody},</if>
            <if test="responseHeader != null">#{responseHeader},</if>
            <if test="responseBody != null">#{responseBody},</if>
            <if test="sqlResult != null">#{sqlResult},</if>
            <if test="pollingCount != null">#{pollingCount},</if>
            <if test="loopCount != null">#{loopCount},</if>
            <if test="assignment != null">#{assignment},</if>
            <if test="assertion != null">#{assertion},</if>
            <if test="useTime != null">#{useTime},</if>
            <if test="executeTime != null">#{executeTime},</if>
            <if test="status != null">#{status},</if>
            <if test="caseSid != null">#{caseSid},</if>
        </trim>
    </insert>

    <update id="updateTestCaseResult" parameterType="TestCaseResult">
        update test_case_result
        <trim prefix="SET" suffixOverrides=",">
            <if test="caseId != null">case_id = #{caseId},</if>
            <if test="stepId != null">step_id = #{stepId},</if>
            <if test="requestHeader != null">request_header = #{requestHeader},</if>
            <if test="requestBody != null">request_body = #{requestBody},</if>
            <if test="responseHeader != null">response_header = #{responseHeader},</if>
            <if test="responseBody != null">response_body = #{responseBody},</if>
            <if test="sqlResult != null">sql_result = #{sqlResult},</if>
            <if test="pollingCount != null">polling_count = #{pollingCount},</if>
            <if test="loopCount != null">loop_count = #{loopCount},</if>
            <if test="assignment != null">assignment = #{assignment},</if>
            <if test="assertion != null">assertion = #{assertion},</if>
            <if test="useTime != null">use_time = #{useTime},</if>
            <if test="executeTime != null">execute_time = #{executeTime},</if>
            <if test="status != null">status = #{status},</if>
            <if test="caseSid != null">case_sid = #{caseSid},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteTestCaseResultById" parameterType="Long">
        delete from test_case_result where id = #{id}
    </delete>

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