<?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.IotMachineBindMapper">
    <resultMap type="com.bonus.material.iot.domain.IotMachineBind" id="IotMachineBindResult">
        <result property="id"    column="id"    />
        <result property="iotId"    column="iot_id"    />
        <result property="typeId"    column="type_id"    />
        <result property="maCode"    column="ma_code"    />
        <result property="binder"    column="binder"    />
        <result property="bindTime"    column="bind_time"    />
        <result property="unbinder"    column="unbinder"    />
        <result property="unbindTime"    column="unbind_time"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateTime"    column="update_time"    />
    </resultMap>

    <sql id="selectIotMachineBindVo">
        select id, iot_id, type_id, ma_code, binder, bind_time, unbinder, unbind_time, create_time, update_time from iot_machine_bind
    </sql>

    <select id="selectIotMachineBindList" parameterType="com.bonus.material.iot.domain.IotMachineBind" resultMap="IotMachineBindResult">
        <include refid="selectIotMachineBindVo"/>
        <where>  
            <if test="iotId != null "> and iot_id = #{iotId}</if>
            <if test="typeId != null "> and type_id = #{typeId}</if>
            <if test="maCode != null  and maCode != ''"> and ma_code = #{maCode}</if>
            <if test="binder != null  and binder != ''"> and binder = #{binder}</if>
            <if test="bindTime != null "> and bind_time = #{bindTime}</if>
            <if test="unbinder != null  and unbinder != ''"> and unbinder = #{unbinder}</if>
            <if test="unbindTime != null "> and unbind_time = #{unbindTime}</if>
        </where>
    </select>
    
    <select id="selectIotMachineBindById" parameterType="Long" resultMap="IotMachineBindResult">
        <include refid="selectIotMachineBindVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertIotMachineBind" parameterType="com.bonus.material.iot.domain.IotMachineBind" useGeneratedKeys="true" keyProperty="id">
        insert into iot_machine_bind
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="iotId != null">iot_id,</if>
            <if test="typeId != null">type_id,</if>
            <if test="maCode != null and maCode != ''">ma_code,</if>
            <if test="binder != null">binder,</if>
            <if test="bindTime != null">bind_time,</if>
            <if test="unbinder != null">unbinder,</if>
            <if test="unbindTime != null">unbind_time,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateTime != null">update_time,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="iotId != null">#{iotId},</if>
            <if test="typeId != null">#{typeId},</if>
            <if test="maCode != null and maCode != ''">#{maCode},</if>
            <if test="binder != null">#{binder},</if>
            <if test="bindTime != null">#{bindTime},</if>
            <if test="unbinder != null">#{unbinder},</if>
            <if test="unbindTime != null">#{unbindTime},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateTime != null">#{updateTime},</if>
         </trim>
    </insert>

    <update id="updateIotMachineBind" parameterType="com.bonus.material.iot.domain.IotMachineBind">
        update iot_machine_bind
        <trim prefix="SET" suffixOverrides=",">
            <if test="iotId != null">iot_id = #{iotId},</if>
            <if test="typeId != null">type_id = #{typeId},</if>
            <if test="maCode != null and maCode != ''">ma_code = #{maCode},</if>
            <if test="binder != null">binder = #{binder},</if>
            <if test="bindTime != null">bind_time = #{bindTime},</if>
            <if test="unbinder != null">unbinder = #{unbinder},</if>
            <if test="unbindTime != null">unbind_time = #{unbindTime},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteIotMachineBindById" parameterType="Long">
        delete from iot_machine_bind where id = #{id}
    </delete>

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