<?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.xzzn.ems.mapper.EmsSiteMonitorPointMatchMapper">

    <select id="selectDistinctSiteIds" resultType="java.lang.String">
        select distinct site_id
        from ems_site_monitor_point_match
        where site_id is not null
          and site_id != ''
        order by site_id asc
    </select>

    <resultMap id="EmsSiteMonitorPointMatchResult" type="com.xzzn.ems.domain.EmsSiteMonitorPointMatch">
        <result property="id" column="id"/>
        <result property="siteId" column="site_id"/>
        <result property="fieldCode" column="field_code"/>
        <result property="deviceId" column="device_id"/>
        <result property="dataPoint" column="data_point"/>
        <result property="fixedDataPoint" column="fixed_data_point"/>
        <result property="useFixedDisplay" column="use_fixed_display"/>
        <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>

    <select id="selectBySiteId" resultMap="EmsSiteMonitorPointMatchResult">
        select id, site_id, field_code, device_id, data_point, fixed_data_point, use_fixed_display, create_by, create_time, update_by, update_time, remark
        from ems_site_monitor_point_match
        where site_id = #{siteId}
        order by id asc
    </select>

    <delete id="deleteBySiteId">
        delete from ems_site_monitor_point_match
        where site_id = #{siteId}
    </delete>

    <delete id="deleteBySiteIdAndDeviceId">
        delete from ems_site_monitor_point_match
        where site_id = #{siteId}
          and device_id = #{deviceId}
    </delete>

    <insert id="insertBatch">
        insert into ems_site_monitor_point_match
        (site_id, field_code, device_id, data_point, fixed_data_point, use_fixed_display, create_by, create_time, update_by, update_time)
        values
        <foreach collection="list" item="item" separator=",">
            (#{item.siteId}, #{item.fieldCode}, #{item.deviceId}, #{item.dataPoint}, #{item.fixedDataPoint}, #{item.useFixedDisplay}, #{item.createBy}, now(), #{item.updateBy}, now())
        </foreach>
    </insert>

</mapper>
