<?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.IotDeviceSetMapper">
    
    <resultMap type="IotDeviceSet" id="IotDeviceSetResult">
        <result property="deviceSetId"    column="device_set_id"    />
        <result property="deviceId"    column="device_id"    />
        <result property="deviceNum"    column="device_num"    />
        <result property="isAlarm"    column="is_alarm"    />
        <result property="isRadar"    column="is_radar"    />
        <result property="isHost"    column="is_host"    />
        <result property="isReset"    column="is_reset"    />
        <result property="isAp"    column="is_ap"    />
        <result property="isWifiOffline"    column="is_wifi_offline"    />
        <result property="isOpenCertifi"    column="is_open_certifi"    />
        <result property="isSmartConfig"    column="is_smart_config"    />
        <result property="isRfControl"    column="is_rf_control"    />
        <result property="isRfLearn"    column="is_rf_learn"    />
        <result property="isRfClear"    column="is_rf_clear"    />
        <result property="rfOneFunc"    column="rf_one_func"    />
        <result property="rfTwoFunc"    column="rf_two_func"    />
        <result property="rfThreeFunc"    column="rf_three_func"    />
        <result property="rfFourFunc"    column="rf_four_func"    />
        <result property="ownerId"    column="owner_id"    />
        <result property="networkAddress"    column="network_address"    />
        <result property="networkIp"    column="network_ip"    />
        <result property="radarInterval"    column="radar_interval"    />
        <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="remark"    column="remark"    />
    </resultMap>

    <sql id="selectIotDeviceSetVo">
        select device_set_id, device_id, device_num, is_alarm, is_radar, is_host, is_reset, is_ap, is_wifi_offline, is_open_certifi, is_smart_config, is_rf_control, is_rf_learn, is_rf_clear, rf_one_func, rf_two_func, rf_three_func, rf_four_func, owner_id, network_address, network_ip,radar_interval, create_by, create_time, update_by, update_time, remark from iot_device_set
    </sql>

    <select id="selectIotDeviceSetList" parameterType="IotDeviceSet" resultMap="IotDeviceSetResult">
        <include refid="selectIotDeviceSetVo"/>
        <where>
            del_flag= '0'
            <if test="deviceId != null "> and device_id = #{deviceId}</if>
            <if test="deviceNum != null  and deviceNum != ''"> and device_num like concat('%', #{deviceNum}, '%')</if>
            <if test="isAlarm != null "> and is_alarm = #{isAlarm}</if>
            <if test="isRadar != null "> and is_radar = #{isRadar}</if>
            <if test="isHost != null "> and is_host = #{isHost}</if>
            <if test="isRfControl != null "> and is_rf_control = #{isRfControl}</if>
            <if test="ownerId != null  and ownerId != ''"> and owner_id like concat('%', #{ownerId}, '%')</if>
            <if test="networkAddress != null  and networkAddress != ''"> and network_address like concat('%', #{networkAddress}, '%')</if>
            <if test="params.beginCreateTime != null and params.beginCreateTime != '' and params.endCreateTime != null and params.endCreateTime != ''"> and create_time between #{params.beginCreateTime} and #{params.endCreateTime}</if>
        </where>
        order by create_time desc
    </select>
    
    <select id="selectIotDeviceSetById" parameterType="Long" resultMap="IotDeviceSetResult">
        <include refid="selectIotDeviceSetVo"/>
        where device_set_id = #{deviceSetId}
    </select>

    <select id="selectIotDeviceSetByDeviceId" parameterType="Long" resultMap="IotDeviceSetResult">
        <include refid="selectIotDeviceSetVo"/>
        where device_id = #{devicetId}
        order by create_time desc
        limit 1
    </select>
        
    <insert id="insertIotDeviceSet" parameterType="IotDeviceSet">
        insert into iot_device_set
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="deviceSetId != null">device_set_id,</if>
            <if test="deviceId != null">device_id,</if>
            <if test="deviceNum != null and deviceNum != ''">device_num,</if>
            <if test="isAlarm != null">is_alarm,</if>
            <if test="isRadar != null">is_radar,</if>
            <if test="isHost != null">is_host,</if>
            <if test="isReset != null">is_reset,</if>
            <if test="isAp != null">is_ap,</if>
            <if test="isWifiOffline != null">is_wifi_offline,</if>
            <if test="isOpenCertifi != null">is_open_certifi,</if>
            <if test="isSmartConfig != null">is_smart_config,</if>
            <if test="isRfControl != null">is_rf_control,</if>
            <if test="isRfLearn != null">is_rf_learn,</if>
            <if test="isRfClear != null">is_rf_clear,</if>
            <if test="rfOneFunc != null">rf_one_func,</if>
            <if test="rfTwoFunc != null">rf_two_func,</if>
            <if test="rfThreeFunc != null">rf_three_func,</if>
            <if test="rfFourFunc != null">rf_four_func,</if>
            <if test="ownerId != null">owner_id,</if>
            <if test="networkAddress != null">network_address,</if>
            <if test="networkIp != null">network_ip,</if>
            <if test="radarInterval != null">radar_interval,</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="remark != null">remark,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="deviceSetId != null">#{deviceSetId},</if>
            <if test="deviceId != null">#{deviceId},</if>
            <if test="deviceNum != null and deviceNum != ''">#{deviceNum},</if>
            <if test="isAlarm != null">#{isAlarm},</if>
            <if test="isRadar != null">#{isRadar},</if>
            <if test="isHost != null">#{isHost},</if>
            <if test="isReset != null">#{isReset},</if>
            <if test="isAp != null">#{isAp},</if>
            <if test="isWifiOffline != null">#{isWifiOffline},</if>
            <if test="isOpenCertifi != null">#{isOpenCertifi},</if>
            <if test="isSmartConfig != null">#{isSmartConfig},</if>
            <if test="isRfControl != null">#{isRfControl},</if>
            <if test="isRfLearn != null">#{isRfLearn},</if>
            <if test="isRfClear != null">#{isRfClear},</if>
            <if test="rfOneFunc != null">#{rfOneFunc},</if>
            <if test="rfTwoFunc != null">#{rfTwoFunc},</if>
            <if test="rfThreeFunc != null">#{rfThreeFunc},</if>
            <if test="rfFourFunc != null">#{rfFourFunc},</if>
            <if test="ownerId != null">#{ownerId},</if>
            <if test="networkAddress != null">#{networkAddress},</if>
            <if test="networkIp != null">#{networkIp},</if>
            <if test="radarInterval != null">#{radarInterval},</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="remark != null">#{remark},</if>
         </trim>
    </insert>

    <update id="updateIotDeviceSet" parameterType="IotDeviceSet">
        update iot_device_set
        <trim prefix="SET" suffixOverrides=",">
            <if test="deviceId != null">device_id = #{deviceId},</if>
            <if test="deviceNum != null and deviceNum != ''">device_num = #{deviceNum},</if>
            <if test="isAlarm != null">is_alarm = #{isAlarm},</if>
            <if test="isRadar != null">is_radar = #{isRadar},</if>
            <if test="isHost != null">is_host = #{isHost},</if>
            <if test="isReset != null">is_reset = #{isReset},</if>
            <if test="isAp != null">is_ap = #{isAp},</if>
            <if test="isWifiOffline != null">is_wifi_offline = #{isWifiOffline},</if>
            <if test="isOpenCertifi != null">is_open_certifi = #{isOpenCertifi},</if>
            <if test="isSmartConfig != null">is_smart_config = #{isSmartConfig},</if>
            <if test="isRfControl != null">is_rf_control = #{isRfControl},</if>
            <if test="isRfLearn != null">is_rf_learn = #{isRfLearn},</if>
            <if test="isRfClear != null">is_rf_clear = #{isRfClear},</if>
            <if test="rfOneFunc != null">rf_one_func = #{rfOneFunc},</if>
            <if test="rfTwoFunc != null">rf_two_func = #{rfTwoFunc},</if>
            <if test="rfThreeFunc != null">rf_three_func = #{rfThreeFunc},</if>
            <if test="rfFourFunc != null">rf_four_func = #{rfFourFunc},</if>
            <if test="ownerId != null">owner_id = #{ownerId},</if>
            <if test="networkAddress != null">network_address = #{networkAddress},</if>
            <if test="networkIp != null">network_ip = #{networkIp},</if>
            <if test="radarInterval != null">radar_interval = #{radarInterval},</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="remark != null">remark = #{remark},</if>
        </trim>
        where device_set_id = #{deviceSetId}
    </update>

    <delete id="deleteIotDeviceSetById" parameterType="Long">
        update iot_device_set set del_flag= '2' where device_set_id = #{deviceSetId}
    </delete>

    <delete id="deleteIotDeviceSetByIds" parameterType="String">
        update iot_device_set set del_flag= '2' where device_set_id in
        <foreach item="deviceSetId" collection="array" open="(" separator="," close=")">
            #{deviceSetId}
        </foreach>
    </delete>
</mapper>