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

    <resultMap type="PerformanceTestCaseReport" id="PerformanceTestCaseReportResult">
        <result property="id"    column="id"    />
        <result property="performanceId"    column="performance_id"    />
        <result property="testCaseId"    column="test_case_id"    />
        <result property="sid"    column="sid"    />
        <result property="concurrentThreads"    column="concurrent_threads"    />
        <result property="average"    column="average"    />
        <result property="tps"    column="tps"    />
        <result property="startTime"    column="start_time"    />
        <result property="endTime"    column="end_time"    />
        <result property="costTime"    column="cost_time"    />
        <result property="triggerType"    column="trigger_type"    />
        <result property="summaryReport"    column="summary_report"    />
        <result property="errorReport"    column="error_report"    />
        <result property="applyUser"    column="apply_user"    />
        <result property="name"    column="name"    />
        <result property="status"    column="status"    />
        <result property="delFlag"    column="del_flag"    />
        <result property="createBy"    column="create_by"    />
        <result property="updateBy"    column="update_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateTime"    column="update_time"    />
    </resultMap>

    <sql id="selectPerformanceTestCaseReportVo">
        select id, performance_id, test_case_id, sid, concurrent_threads, average, tps, start_time, end_time, cost_time, trigger_type, summary_report, error_report, apply_user, status, del_flag, create_by, update_by, create_time, update_time from performance_test_case_report
    </sql>

    <select id="selectPerformanceTestCaseReportList" parameterType="PerformanceTestCaseReport" resultMap="PerformanceTestCaseReportResult">
        select a.id, a.performance_id, a.test_case_id, b.name, a.sid, a.concurrent_threads, a.average, a.tps, a.start_time, a.end_time, a.cost_time, a.trigger_type, a.status, a.create_by, a.update_by, a.create_time, a.update_time
        from performance_test_case_report a left join test_case b on a.test_case_id = b.id
        <where>
            <if test="performanceId != null "> and a.performance_id = #{performanceId}</if>
            <if test="testCaseId != null "> and a.test_case_id = #{testCaseId}</if>
            <if test="sid != null "> and a.sid = #{sid}</if>
            <if test="name != null  and name != ''"> and b.name like concat('%', #{name}, '%')</if>
            <if test="startTime != null "> and a.start_time = #{startTime}</if>
            <if test="endTime != null "> and a.end_time = #{endTime}</if>
            <if test="costTime != null "> and a.cost_time = #{costTime}</if>
            <if test="triggerType != null "> and a.trigger_type = #{triggerType}</if>
            <if test="delFlag != null  and delFlag != ''"> and a.del_flag = #{delFlag}</if>
            <if test="status != null  and status != ''"> and a.status = #{status}</if>
        </where>
    </select>

    <select id="selectPerformanceTestCaseReportById" parameterType="Long" resultMap="PerformanceTestCaseReportResult">
        <include refid="selectPerformanceTestCaseReportVo"/>
        where id = #{id}
    </select>

    <insert id="insertPerformanceTestCaseReport" parameterType="PerformanceTestCaseReport" useGeneratedKeys="true" keyProperty="id">
        insert into performance_test_case_report
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="performanceId != null">performance_id,</if>
            <if test="testCaseId != null">test_case_id,</if>
            <if test="sid != null">sid,</if>
            <if test="concurrentThreads != null">concurrent_threads,</if>
            <if test="average != null">average,</if>
            <if test="tps != null">tps,</if>
            <if test="startTime != null">start_time,</if>
            <if test="endTime != null">end_time,</if>
            <if test="costTime != null">cost_time,</if>
            <if test="triggerType != null">trigger_type,</if>
            <if test="summaryReport != null">summary_report,</if>
            <if test="errorReport != null">error_report,</if>
            <if test="applyUser != null">apply_user,</if>
            <if test="status != null">status,</if>
            <if test="delFlag != null and delFlag != ''">del_flag,</if>
            <if test="createBy != null">create_by,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateTime != null">update_time,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="performanceId != null">#{performanceId},</if>
            <if test="testCaseId != null">#{testCaseId},</if>
            <if test="sid != null">#{sid},</if>
            <if test="concurrentThreads != null">#{concurrentThreads},</if>
            <if test="average != null">#{average},</if>
            <if test="tps != null">#{tps},</if>
            <if test="startTime != null">#{startTime},</if>
            <if test="endTime != null">#{endTime},</if>
            <if test="costTime != null">#{costTime},</if>
            <if test="triggerType != null">#{triggerType},</if>
            <if test="summaryReport != null">#{summaryReport},</if>
            <if test="errorReport != null">#{errorReport},</if>
            <if test="applyUser != null">#{applyUser},</if>
            <if test="status != null">#{status},</if>
            <if test="delFlag != null and delFlag != ''">#{delFlag},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateTime != null">#{updateTime},</if>
         </trim>
    </insert>

    <update id="updatePerformanceTestCaseReport" parameterType="PerformanceTestCaseReport">
        update performance_test_case_report
        <trim prefix="SET" suffixOverrides=",">
            <if test="performanceId != null">performance_id = #{performanceId},</if>
            <if test="testCaseId != null">test_case_id = #{testCaseId},</if>
            <if test="sid != null">sid = #{sid},</if>
            <if test="concurrentThreads != null">concurrent_threads = #{concurrentThreads},</if>
            <if test="average != null">average = #{average},</if>
            <if test="tps != null">tps = #{tps},</if>
            <if test="startTime != null">start_time = #{startTime},</if>
            <if test="endTime != null">end_time = #{endTime},</if>
            <if test="costTime != null">cost_time = #{costTime},</if>
            <if test="triggerType != null">trigger_type = #{triggerType},</if>
            <if test="summaryReport != null">summary_report = #{summaryReport},</if>
            <if test="errorReport != null">error_report = #{errorReport},</if>
            <if test="applyUser != null">apply_user = #{applyUser},</if>
            <if test="status != null">status = #{status},</if>
            <if test="delFlag != null and delFlag != ''">del_flag = #{delFlag},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deletePerformanceTestCaseReportById" parameterType="Long">
        delete from performance_test_case_report where id = #{id}
    </delete>

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