<?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.zehong.system.mapper.TYehuaqiDeviceMapper">
    
    <resultMap type="TYehuaqiDevice" id="TYehuaqiDeviceResult">
        <result property="detectorId"    column="detector_id"    />
        <result property="enterpriseId"    column="enterprise_id"    />
        <result property="userId"    column="user_id"    />
        <result property="deviceId"    column="device_id"    />
        <result property="siteStationId"    column="site_station_id"    />
        <result property="detectorName"    column="detector_name"    />
        <result property="detectorCode"    column="detector_code"    />
        <result property="detectorAddr"    column="detector_addr"    />
        <result property="detectorType"    column="detector_type"    />
        <result property="medium"    column="medium"    />
        <result property="longitude"    column="longitude"    />
        <result property="latitude"    column="latitude"    />
        <result property="iotNo"    column="iot_no"    />
        <result property="linkman"    column="linkman"    />
        <result property="phone"    column="phone"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateTime"    column="update_time"    />
        <result property="alarmTime"    column="alarm_time"    />
        <result property="detectorStatus"    column="detector_status"    />
        <result property="isDel"    column="is_del"    />
        <result property="remarks"    column="remarks"    />
    </resultMap>

    <sql id="selectTYehuaqiDeviceVo">
        select detector_id, enterprise_id, user_id, device_id, site_station_id, detector_name, detector_code, detector_addr, detector_type, medium, longitude, latitude, iot_no, linkman, phone, create_time, update_time, alarm_time, detector_status, is_del, remarks from t_yehuaqi_device
    </sql>

    <select id="selectTYehuaqiDeviceList" parameterType="TYehuaqiDevice" resultMap="TYehuaqiDeviceResult">
        <include refid="selectTYehuaqiDeviceVo"/>
        <where>  
            <if test="enterpriseId != null "> and enterprise_id = #{enterpriseId}</if>
            <if test="userId != null "> and user_id = #{userId}</if>
            <if test="deviceId != null "> and device_id = #{deviceId}</if>
            <if test="siteStationId != null "> and site_station_id = #{siteStationId}</if>
            <if test="detectorName != null  and detectorName != ''"> and detector_name like concat('%', #{detectorName}, '%')</if>
            <if test="detectorCode != null  and detectorCode != ''"> and detector_code = #{detectorCode}</if>
            <if test="detectorAddr != null  and detectorAddr != ''"> and detector_addr = #{detectorAddr}</if>
            <if test="detectorType != null  and detectorType != ''"> and detector_type = #{detectorType}</if>
            <if test="medium != null  and medium != ''"> and medium = #{medium}</if>
            <if test="longitude != null "> and longitude = #{longitude}</if>
            <if test="latitude != null "> and latitude = #{latitude}</if>
            <if test="iotNo != null  and iotNo != ''"> and iot_no = #{iotNo}</if>
            <if test="linkman != null  and linkman != ''"> and linkman = #{linkman}</if>
            <if test="phone != null  and phone != ''"> and phone = #{phone}</if>
            <if test="alarmTime != null  and alarmTime != ''"> and alarm_time = #{alarmTime}</if>
            <if test="detectorStatus != null  and detectorStatus != ''"> and detector_status = #{detectorStatus}</if>
            <if test="isDel != null  and isDel != ''"> and is_del = #{isDel}</if>
            <if test="remarks != null  and remarks != ''"> and remarks = #{remarks}</if>
        </where>
    </select>
    
    <select id="selectTYehuaqiDeviceById" parameterType="Long" resultMap="TYehuaqiDeviceResult">
        <include refid="selectTYehuaqiDeviceVo"/>
        where detector_id = #{detectorId}
    </select>
        
    <insert id="insertTYehuaqiDevice" parameterType="TYehuaqiDevice" useGeneratedKeys="true" keyProperty="detectorId">
        insert into t_yehuaqi_device
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="enterpriseId != null">enterprise_id,</if>
            <if test="userId != null">user_id,</if>
            <if test="deviceId != null">device_id,</if>
            <if test="siteStationId != null">site_station_id,</if>
            <if test="detectorName != null">detector_name,</if>
            <if test="detectorCode != null">detector_code,</if>
            <if test="detectorAddr != null">detector_addr,</if>
            <if test="detectorType != null">detector_type,</if>
            <if test="medium != null">medium,</if>
            <if test="longitude != null">longitude,</if>
            <if test="latitude != null">latitude,</if>
            <if test="iotNo != null">iot_no,</if>
            <if test="linkman != null">linkman,</if>
            <if test="phone != null">phone,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="alarmTime != null">alarm_time,</if>
            <if test="detectorStatus != null">detector_status,</if>
            <if test="isDel != null">is_del,</if>
            <if test="remarks != null">remarks,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="enterpriseId != null">#{enterpriseId},</if>
            <if test="userId != null">#{userId},</if>
            <if test="deviceId != null">#{deviceId},</if>
            <if test="siteStationId != null">#{siteStationId},</if>
            <if test="detectorName != null">#{detectorName},</if>
            <if test="detectorCode != null">#{detectorCode},</if>
            <if test="detectorAddr != null">#{detectorAddr},</if>
            <if test="detectorType != null">#{detectorType},</if>
            <if test="medium != null">#{medium},</if>
            <if test="longitude != null">#{longitude},</if>
            <if test="latitude != null">#{latitude},</if>
            <if test="iotNo != null">#{iotNo},</if>
            <if test="linkman != null">#{linkman},</if>
            <if test="phone != null">#{phone},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="alarmTime != null">#{alarmTime},</if>
            <if test="detectorStatus != null">#{detectorStatus},</if>
            <if test="isDel != null">#{isDel},</if>
            <if test="remarks != null">#{remarks},</if>
         </trim>
    </insert>

    <update id="updateTYehuaqiDevice" parameterType="TYehuaqiDevice">
        update t_yehuaqi_device
        <trim prefix="SET" suffixOverrides=",">
            <if test="enterpriseId != null">enterprise_id = #{enterpriseId},</if>
            <if test="userId != null">user_id = #{userId},</if>
            <if test="deviceId != null">device_id = #{deviceId},</if>
            <if test="siteStationId != null">site_station_id = #{siteStationId},</if>
            <if test="detectorName != null">detector_name = #{detectorName},</if>
            <if test="detectorCode != null">detector_code = #{detectorCode},</if>
            <if test="detectorAddr != null">detector_addr = #{detectorAddr},</if>
            <if test="detectorType != null">detector_type = #{detectorType},</if>
            <if test="medium != null">medium = #{medium},</if>
            <if test="longitude != null">longitude = #{longitude},</if>
            <if test="latitude != null">latitude = #{latitude},</if>
            <if test="iotNo != null">iot_no = #{iotNo},</if>
            <if test="linkman != null">linkman = #{linkman},</if>
            <if test="phone != null">phone = #{phone},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="alarmTime != null">alarm_time = #{alarmTime},</if>
            <if test="detectorStatus != null">detector_status = #{detectorStatus},</if>
            <if test="isDel != null">is_del = #{isDel},</if>
            <if test="remarks != null">remarks = #{remarks},</if>
        </trim>
        where detector_id = #{detectorId}
    </update>

    <delete id="deleteTYehuaqiDeviceById" parameterType="Long">
        delete from t_yehuaqi_device where detector_id = #{detectorId}
    </delete>

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