<?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.fastbee.iot.mapper.SimulateLogMapper">

    <resultMap type="com.fastbee.iot.domain.SimulateLog" id="SimulateLogResult">
        <result property="logId"    column="log_id"    />
        <result property="sendData"    column="send_data"    />
        <result property="callbackData"    column="callback_data"    />
        <result property="deviceId"    column="device_id"    />
        <result property="deviceName"    column="device_name"    />
        <result property="serialNumber"    column="serial_number"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="remark"    column="remark"    />
    </resultMap>

    <sql id="selectSimulateLogVo">
        select log_id, send_data, callback_data, device_id, device_name, serial_number, create_by, create_time, remark from iot_simulate_log
    </sql>

    <select id="selectSimulateLogList" parameterType="com.fastbee.iot.domain.SimulateLog" resultMap="SimulateLogResult">
        <include refid="selectSimulateLogVo"/>
        <where>
            <if test="sendData != null  and sendData != ''"> and send_data = #{sendData}</if>
            <if test="callbackData != null  and callbackData != ''"> and callback_data = #{callbackData}</if>
            <if test="deviceId != null "> and device_id = #{deviceId}</if>
            <if test="deviceName != null  and deviceName != ''"> and device_name like concat('%', #{deviceName}, '%')</if>
            <if test="serialNumber != null  and serialNumber != ''"> and serial_number = #{serialNumber}</if>
        </where>
        order by create_time desc
    </select>

    <select id="selectSimulateLogByLogId" parameterType="Long" resultMap="SimulateLogResult">
        <include refid="selectSimulateLogVo"/>
        where log_id = #{logId}
    </select>

    <insert id="insertSimulateLog" parameterType="com.fastbee.iot.domain.SimulateLog" useGeneratedKeys="true" keyProperty="logId">
        insert into iot_simulate_log
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="sendData != null">send_data,</if>
            <if test="callbackData != null">callback_data,</if>
            <if test="deviceId != null">device_id,</if>
            <if test="deviceName != null">device_name,</if>
            <if test="serialNumber != null and serialNumber != ''">serial_number,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="remark != null">remark,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="sendData != null">#{sendData},</if>
            <if test="callbackData != null">#{callbackData},</if>
            <if test="deviceId != null">#{deviceId},</if>
            <if test="deviceName != null">#{deviceName},</if>
            <if test="serialNumber != null and serialNumber != ''">#{serialNumber},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="remark != null">#{remark},</if>
        </trim>
    </insert>

    <update id="updateSimulateLog" parameterType="com.fastbee.iot.domain.SimulateLog">
        update iot_simulate_log
        <trim prefix="SET" suffixOverrides=",">
            <if test="sendData != null">send_data = #{sendData},</if>
            <if test="callbackData != null">callback_data = #{callbackData},</if>
            <if test="deviceId != null">device_id = #{deviceId},</if>
            <if test="deviceName != null">device_name = #{deviceName},</if>
            <if test="serialNumber != null and serialNumber != ''">serial_number = #{serialNumber},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="remark != null">remark = #{remark},</if>
        </trim>
        where log_id = #{logId}
    </update>

    <delete id="deleteSimulateLogByLogId" parameterType="Long">
        delete from iot_simulate_log where log_id = #{logId}
    </delete>

    <delete id="deleteSimulateLogBySerialNumber" parameterType="String">
        delete from iot_simulate_log where serial_number = #{serialNumber}
    </delete>

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