<?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.cmvr.aima.mapper.AimaTestLogMapper">
    <resultMap type="AimaTestLog" id="AimaTestLogResult">
        <result property="id" column="id"/><result property="createBy" column="create_by"/><result property="createTime" column="create_time"/>
        <result property="updateBy" column="update_by"/><result property="updateTime" column="update_time"/><result property="remark" column="remark"/>
        <result property="taskInstanceId" column="task_instance_id"/><result property="taskId" column="task_id"/><result property="taskName" column="task_name"/>
        <result property="testCaseId" column="test_case_id"/><result property="caseName" column="case_name"/><result property="logLevel" column="log_level"/>
        <result property="logType" column="log_type"/><result property="logContent" column="log_content"/><result property="logTime" column="log_time"/>
        <result property="executionStep" column="execution_step"/><result property="actualResult" column="actual_result"/><result property="testStatus" column="test_status"/>
        <result property="screenshotUrl" column="screenshot_url"/><result property="videoUrl" column="video_url"/><result property="errorStack" column="error_stack"/>
        <result property="durationMs" column="duration_ms"/>
        <result property="progress" column="progress"/>
        <result property="status" column="status"/>
    </resultMap>

    <sql id="selectAimaTestLogVo">
        select id, create_by, create_time, update_by, update_time, remark, task_instance_id, task_id, task_name, test_case_id, case_name, log_level, log_type, log_content, log_time, execution_step, actual_result, test_status, screenshot_url, video_url, error_stack, duration_ms,progress,status from aima_test_log
    </sql>

    <select id="selectAimaTestLogList" parameterType="AimaTestLog" resultMap="AimaTestLogResult">
        <include refid="selectAimaTestLogVo"/>
        <where>
            <if test="taskInstanceId != null and taskInstanceId != ''"> and task_instance_id = #{taskInstanceId}</if>
            <if test="taskId != null and taskId != ''"> and task_id = #{taskId}</if>
            <if test="testCaseId != null and testCaseId != ''"> and test_case_id = #{testCaseId}</if>
            <if test="logLevel != null and logLevel != ''"> and log_level = #{logLevel}</if>
            <if test="testStatus != null and testStatus != ''"> and test_status = #{testStatus}</if>
        </where>
        order by log_time
    </select>

    <select id="selectAimaTestLogById" parameterType="String" resultMap="AimaTestLogResult">
        <include refid="selectAimaTestLogVo"/> where id = #{id}
    </select>

    <insert id="insertAimaTestLog" parameterType="AimaTestLog">
        insert into aima_test_log <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if><if test="createBy != null">create_by,</if><if test="createTime != null">create_time,</if>
            <if test="updateBy != null">update_by,</if><if test="updateTime != null">update_time,</if><if test="remark != null">remark,</if>
            <if test="taskInstanceId != null">task_instance_id,</if><if test="taskId != null">task_id,</if><if test="taskName != null">task_name,</if>
            <if test="testCaseId != null">test_case_id,</if><if test="caseName != null">case_name,</if><if test="logLevel != null">log_level,</if>
            <if test="logType != null">log_type,</if><if test="logContent != null">log_content,</if><if test="logTime != null">log_time,</if>
            <if test="executionStep != null">execution_step,</if><if test="actualResult != null">actual_result,</if><if test="testStatus != null">test_status,</if>
            <if test="screenshotUrl != null">screenshot_url,</if><if test="videoUrl != null">video_url,</if><if test="errorStack != null">error_stack,</if>
            <if test="durationMs != null">duration_ms,</if>
            <if test="progress != null">progress,</if>
            <if test="status != null">status,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if><if test="createBy != null">#{createBy},</if><if test="createTime != null">#{createTime},</if>
            <if test="updateBy != null">#{updateBy},</if><if test="updateTime != null">#{updateTime},</if><if test="remark != null">#{remark},</if>
            <if test="taskInstanceId != null">#{taskInstanceId},</if><if test="taskId != null">#{taskId},</if><if test="taskName != null">#{taskName},</if>
            <if test="testCaseId != null">#{testCaseId},</if><if test="caseName != null">#{caseName},</if><if test="logLevel != null">#{logLevel},</if>
            <if test="logType != null">#{logType},</if><if test="logContent != null">#{logContent},</if><if test="logTime != null">#{logTime},</if>
            <if test="executionStep != null">#{executionStep},</if><if test="actualResult != null">#{actualResult},</if><if test="testStatus != null">#{testStatus},</if>
            <if test="screenshotUrl != null">#{screenshotUrl},</if><if test="videoUrl != null">#{videoUrl},</if><if test="errorStack != null">#{errorStack},</if>
            <if test="durationMs != null">#{durationMs},</if>
            <if test="progress != null">#{progress},</if>
            <if test="status != null">#{status},</if>
        </trim>
    </insert>

    <update id="updateAimaTestLog" parameterType="AimaTestLog">
        update aima_test_log <trim prefix="SET" suffixOverrides=",">
            <if test="createBy != null">create_by = #{createBy},</if><if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if><if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="remark != null">remark = #{remark},</if><if test="taskInstanceId != null">task_instance_id = #{taskInstanceId},</if>
            <if test="taskId != null">task_id = #{taskId},</if><if test="taskName != null">task_name = #{taskName},</if>
            <if test="testCaseId != null">test_case_id = #{testCaseId},</if><if test="caseName != null">case_name = #{caseName},</if>
            <if test="logLevel != null">log_level = #{logLevel},</if><if test="logType != null">log_type = #{logType},</if>
            <if test="logContent != null">   log_content  = #{logContent},</if><if test="logTime != null">log_time = #{logTime},</if>
            <if test="executionStep != null">execution_step = #{executionStep},</if><if test="actualResult != null">actual_result = #{actualResult},</if>
            <if test="testStatus != null">test_status = #{testStatus},</if><if test="screenshotUrl != null">screenshot_url = #{screenshotUrl},</if>
            <if test="videoUrl != null">video_url = #{videoUrl},</if><if test="errorStack != null">error_stack = #{errorStack},</if>
            <if test="durationMs != null">duration_ms = #{durationMs},</if>
            <if test="progress != null">progress = #{progress},</if>
            <if test="status != null">status = #{status},</if>
        </trim> where id = #{id}
    </update>

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