<?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.bonus.material.iot.mapper.IotMachineMapper">
    <resultMap type="com.bonus.material.iot.domain.IotMachine" id="IotMachineResult">
        <result property="id"    column="id"    />
        <result property="iotType"    column="iot_type"    />
        <result property="iotCode"    column="iot_code"    />
        <result property="iotStatus"    column="iot_status"    />
        <result property="qrCode"    column="qr_code"    />
        <result property="bindStatus"    column="bind_status"    />
        <result property="delFlag"    column="del_flag"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
    </resultMap>

    <sql id="selectIotMachineVo">
        select id, iot_type, iot_code, iot_status, qr_code, bind_status, del_flag, create_by, create_time, update_by, update_time from iot_machine
    </sql>

    <select id="selectIotMachineList" parameterType="com.bonus.material.iot.domain.IotMachine" resultMap="IotMachineResult">
        <include refid="selectIotMachineVo"/>
        <where>  
            <if test="iotType != null  and iotType != ''"> and iot_type = #{iotType}</if>
            <if test="iotCode != null  and iotCode != ''"> and iot_code = #{iotCode}</if>
            <if test="iotStatus != null "> and iot_status = #{iotStatus}</if>
            <if test="qrCode != null  and qrCode != ''"> and qr_code = #{qrCode}</if>
            <if test="bindStatus != null "> and bind_status = #{bindStatus}</if>
        </where>
    </select>
    
    <select id="selectIotMachineById" parameterType="Long" resultMap="IotMachineResult">
        <include refid="selectIotMachineVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertIotMachine" parameterType="com.bonus.material.iot.domain.IotMachine" useGeneratedKeys="true" keyProperty="id">
        insert into iot_machine
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="iotType != null">iot_type,</if>
            <if test="iotCode != null">iot_code,</if>
            <if test="iotStatus != null">iot_status,</if>
            <if test="qrCode != null">qr_code,</if>
            <if test="bindStatus != null">bind_status,</if>
            <if test="delFlag != null">del_flag,</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>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="iotType != null">#{iotType},</if>
            <if test="iotCode != null">#{iotCode},</if>
            <if test="iotStatus != null">#{iotStatus},</if>
            <if test="qrCode != null">#{qrCode},</if>
            <if test="bindStatus != null">#{bindStatus},</if>
            <if test="delFlag != null">#{delFlag},</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>
         </trim>
    </insert>

    <update id="updateIotMachine" parameterType="com.bonus.material.iot.domain.IotMachine">
        update iot_machine
        <trim prefix="SET" suffixOverrides=",">
            <if test="iotType != null">iot_type = #{iotType},</if>
            <if test="iotCode != null">iot_code = #{iotCode},</if>
            <if test="iotStatus != null">iot_status = #{iotStatus},</if>
            <if test="qrCode != null">qr_code = #{qrCode},</if>
            <if test="bindStatus != null">bind_status = #{bindStatus},</if>
            <if test="delFlag != null">del_flag = #{delFlag},</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>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteIotMachineById" parameterType="Long">
        delete from iot_machine where id = #{id}
    </delete>

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