<?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.shzg.project.worn.mapper.MqttSensorCommandMapper">
    
    <resultMap type="MqttSensorCommand" id="MqttSensorCommandResult">
        <result property="id"    column="id"    />
        <result property="deviceId"    column="device_id"    />
        <result property="topic"    column="topic"    />
        <result property="command"    column="command"    />
        <result property="payload"    column="payload"    />
        <result property="status"    column="status"    />
        <result property="sendTime"    column="send_time"    />
        <result property="remark"    column="remark"    />
        <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="isDelete"    column="is_delete"    />
    </resultMap>

    <sql id="selectMqttSensorCommandVo">
        select id, device_id, topic, command, payload, status, send_time, remark, create_by, create_time, update_by, update_time, is_delete from mqtt_sensor_command
    </sql>

    <select id="selectMqttSensorCommandList" parameterType="MqttSensorCommand" resultMap="MqttSensorCommandResult">
        <include refid="selectMqttSensorCommandVo"/>
        <where>  
            <if test="deviceId != null "> and device_id = #{deviceId}</if>
            <if test="topic != null  and topic != ''"> and topic = #{topic}</if>
            <if test="command != null  and command != ''"> and command = #{command}</if>
            <if test="payload != null  and payload != ''"> and payload = #{payload}</if>
            <if test="status != null  and status != ''"> and status = #{status}</if>
            <if test="sendTime != null "> and send_time = #{sendTime}</if>
            <if test="isDelete != null  and isDelete != ''"> and is_delete = #{isDelete}</if>
        </where>
    </select>
    
    <select id="selectMqttSensorCommandById" parameterType="Long" resultMap="MqttSensorCommandResult">
        <include refid="selectMqttSensorCommandVo"/>
        where id = #{id}
    </select>

    <insert id="insertMqttSensorCommand" parameterType="MqttSensorCommand" useGeneratedKeys="true" keyProperty="id">
        insert into mqtt_sensor_command
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="deviceId != null">device_id,</if>
            <if test="topic != null">topic,</if>
            <if test="command != null">command,</if>
            <if test="payload != null">payload,</if>
            <if test="status != null">status,</if>
            <if test="sendTime != null">send_time,</if>
            <if test="remark != null">remark,</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="isDelete != null">is_delete,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="deviceId != null">#{deviceId},</if>
            <if test="topic != null">#{topic},</if>
            <if test="command != null">#{command},</if>
            <if test="payload != null">#{payload},</if>
            <if test="status != null">#{status},</if>
            <if test="sendTime != null">#{sendTime},</if>
            <if test="remark != null">#{remark},</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="isDelete != null">#{isDelete},</if>
         </trim>
    </insert>

    <update id="updateMqttSensorCommand" parameterType="MqttSensorCommand">
        update mqtt_sensor_command
        <trim prefix="SET" suffixOverrides=",">
            <if test="deviceId != null">device_id = #{deviceId},</if>
            <if test="topic != null">topic = #{topic},</if>
            <if test="command != null">command = #{command},</if>
            <if test="payload != null">payload = #{payload},</if>
            <if test="status != null">status = #{status},</if>
            <if test="sendTime != null">send_time = #{sendTime},</if>
            <if test="remark != null">remark = #{remark},</if>
            <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="isDelete != null">is_delete = #{isDelete},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteMqttSensorCommandById" parameterType="Long">
        delete from mqtt_sensor_command where id = #{id}
    </delete>

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