<?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.system.mapper.GatewayOperationLogMapper">

    <resultMap type="GatewayOperationLog" id="GatewayOperationLogResult">
        <result property="id"    column="id"    />
        <result property="gatewayId"    column="gateway_id"    />
        <result property="operationCommand"    column="operation_command"    />
        <result property="sendParams"    column="send_params"    />
        <result property="executionResponse"    column="execution_response"    />
        <result property="executionResult"    column="execution_result"    />
        <result property="operationTime"    column="operation_time"    />
    </resultMap>

    <sql id="selectGatewayOperationLogVo">
        select id, gateway_id, operation_command, send_params, execution_response, execution_result, operation_time from gateway_operation_log
    </sql>

    <select id="selectGatewayOperationLogList" parameterType="GatewayOperationLog" resultMap="GatewayOperationLogResult">
        <include refid="selectGatewayOperationLogVo"/>
        <where>
            <if test="gatewayId != null  and gatewayId != ''">and gateway_id = #{gatewayId}</if>
            <if test="operationCommand != null  and operationCommand != ''">and operation_command =
                #{operationCommand}
            </if>
            <if test="sendParams != null  and sendParams != ''">and send_params = #{sendParams}</if>
            <if test="executionResponse != null  and executionResponse != ''">and execution_response =
                #{executionResponse}
            </if>
            <if test="executionResult != null  and executionResult != ''">and execution_result = #{executionResult}</if>
            <if test="operationTime != null ">and operation_time = #{operationTime}</if>
        </where>
        order by operation_time desc
    </select>

    <select id="selectGatewayOperationLogById" parameterType="Long" resultMap="GatewayOperationLogResult">
        <include refid="selectGatewayOperationLogVo"/>
        where id = #{id}
    </select>

    <insert id="insertGatewayOperationLog" parameterType="GatewayOperationLog" useGeneratedKeys="true" keyProperty="id">
        insert into gateway_operation_log
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="gatewayId != null and gatewayId != ''">gateway_id,</if>
            <if test="operationCommand != null and operationCommand != ''">operation_command,</if>
            <if test="sendParams != null">send_params,</if>
            <if test="executionResponse != null">execution_response,</if>
            <if test="executionResult != null">execution_result,</if>
            <if test="operationTime != null">operation_time,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="gatewayId != null and gatewayId != ''">#{gatewayId},</if>
            <if test="operationCommand != null and operationCommand != ''">#{operationCommand},</if>
            <if test="sendParams != null">#{sendParams},</if>
            <if test="executionResponse != null">#{executionResponse},</if>
            <if test="executionResult != null">#{executionResult},</if>
            <if test="operationTime != null">#{operationTime},</if>
         </trim>
    </insert>

    <update id="updateGatewayOperationLog" parameterType="GatewayOperationLog">
        update gateway_operation_log
        <trim prefix="SET" suffixOverrides=",">
            <if test="gatewayId != null and gatewayId != ''">gateway_id = #{gatewayId},</if>
            <if test="operationCommand != null and operationCommand != ''">operation_command = #{operationCommand},</if>
            <if test="sendParams != null">send_params = #{sendParams},</if>
            <if test="executionResponse != null">execution_response = #{executionResponse},</if>
            <if test="executionResult != null">execution_result = #{executionResult},</if>
            <if test="operationTime != null">operation_time = #{operationTime},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteGatewayOperationLogById" parameterType="Long">
        delete from gateway_operation_log where id = #{id}
    </delete>

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