<?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.ruoyi.ems.mapper.OpEnergyStrategyStepLogMapper">

    <resultMap type="com.ruoyi.ems.domain.OpEnergyStrategyStepLog" id="StepLogResult">
        <result property="id" column="id"/>
        <result property="execId" column="exec_id"/>
        <result property="strategyCode" column="strategy_code"/>
        <result property="stepCode" column="step_code"/>
        <result property="stepName" column="step_name"/>
        <result property="stepIndex" column="step_index"/>
        <result property="execStatus" column="exec_status"/>
        <result property="startTime" column="start_time"/>
        <result property="endTime" column="end_time"/>
        <result property="duration" column="duration"/>
        <result property="inputParam" column="input_param"/>
        <result property="outputResult" column="output_result"/>
        <result property="errorMessage" column="error_message"/>
        <result property="retryCount" column="retry_count"/>
        <result property="createTime" column="create_time"/>
    </resultMap>

    <sql id="selectStepLogVo">
        select
            id, exec_id, strategy_code, step_code, step_name, step_index,
            exec_status, start_time, end_time, duration, input_param,
            output_result, error_message, retry_count, create_time
        from adm_op_energy_strategy_step_log
    </sql>

    <select id="selectStepLogList" parameterType="com.ruoyi.ems.domain.OpEnergyStrategyStepLog" resultMap="StepLogResult">
        <include refid="selectStepLogVo"/>
        <where>
            <if test="execId != null and execId != ''">
                and exec_id = #{execId}
            </if>
            <if test="strategyCode != null and strategyCode != ''">
                and strategy_code = #{strategyCode}
            </if>
            <if test="stepCode != null and stepCode != ''">
                and step_code = #{stepCode}
            </if>
            <if test="execStatus != null">
                and exec_status = #{execStatus}
            </if>
        </where>
        order by step_index asc
    </select>

    <select id="selectByExecId" parameterType="String" resultMap="StepLogResult">
        <include refid="selectStepLogVo"/>
        where exec_id = #{execId}
        order by step_index asc
    </select>

    <insert id="insertStepLog" parameterType="com.ruoyi.ems.domain.OpEnergyStrategyStepLog" useGeneratedKeys="true" keyProperty="id">
        insert into adm_op_energy_strategy_step_log
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="execId != null and execId != ''">exec_id,</if>
            <if test="strategyCode != null and strategyCode != ''">strategy_code,</if>
            <if test="stepCode != null and stepCode != ''">step_code,</if>
            <if test="stepName != null and stepName != ''">step_name,</if>
            <if test="stepIndex != null">step_index,</if>
            <if test="execStatus != null">exec_status,</if>
            <if test="startTime != null">start_time,</if>
            <if test="endTime != null">end_time,</if>
            <if test="duration != null">duration,</if>
            <if test="inputParam != null">input_param,</if>
            <if test="outputResult != null">output_result,</if>
            <if test="errorMessage != null">error_message,</if>
            <if test="retryCount != null">retry_count,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="execId != null and execId != ''">#{execId},</if>
            <if test="strategyCode != null and strategyCode != ''">#{strategyCode},</if>
            <if test="stepCode != null and stepCode != ''">#{stepCode},</if>
            <if test="stepName != null and stepName != ''">#{stepName},</if>
            <if test="stepIndex != null">#{stepIndex},</if>
            <if test="execStatus != null">#{execStatus},</if>
            <if test="startTime != null">#{startTime},</if>
            <if test="endTime != null">#{endTime},</if>
            <if test="duration != null">#{duration},</if>
            <if test="inputParam != null">#{inputParam},</if>
            <if test="outputResult != null">#{outputResult},</if>
            <if test="errorMessage != null">#{errorMessage},</if>
            <if test="retryCount != null">#{retryCount},</if>
        </trim>
    </insert>

    <update id="updateStepLog" parameterType="com.ruoyi.ems.domain.OpEnergyStrategyStepLog">
        update adm_op_energy_strategy_step_log
        <trim prefix="SET" suffixOverrides=",">
            <if test="execStatus != null">exec_status = #{execStatus},</if>
            <if test="endTime != null">end_time = #{endTime},</if>
            <if test="duration != null">duration = #{duration},</if>
            <if test="outputResult != null">output_result = #{outputResult},</if>
            <if test="errorMessage != null">error_message = #{errorMessage},</if>
            <if test="retryCount != null">retry_count = #{retryCount},</if>
        </trim>
        where id = #{id}
    </update>

    <insert id="insertStepLogBatch" parameterType="java.util.List">
        insert into adm_op_energy_strategy_step_log
        (exec_id, strategy_code, step_code, step_name, step_index, exec_status,
        start_time, end_time, duration, input_param, output_result, error_message, retry_count)
        values
        <foreach collection="list" item="item" separator=",">
            (#{item.execId}, #{item.strategyCode}, #{item.stepCode}, #{item.stepName},
            #{item.stepIndex}, #{item.execStatus}, #{item.startTime}, #{item.endTime},
            #{item.duration}, #{item.inputParam}, #{item.outputResult},
            #{item.errorMessage}, #{item.retryCount})
        </foreach>
    </insert>
</mapper>