<?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.tofly.xrtygis.mapper.DmaandobserMapper">

    <resultMap id="dmaandobserMap" type="com.tofly.xrtygis.entity.Dmaandobser">
        <id property="id" column="ID"/>
        <result property="dmaId" column="DMA_ID"/>
        <result property="tableId" column="TABLE_ID"/>
        <result property="isout" column="ISOUT"/>
        <result property="createUser" column="CREATE_USER"/>
        <result property="createTime" column="CREATE_TIME"/>
        <association property="tableName" column="TABLE_ID" select="getTableName"/>
        <association property="lgtd" column="TABLE_ID" select="getX"/>
        <association property="lttd" column="TABLE_ID" select="getY"/>
        <association property="createUserName" column="CREATE_USER"
                     select="com.tofly.xrtygis.mapper.IFileMapper.getUserName"></association>
        <association property="tableName" column="TABLE_ID"
                     select="getTableName"></association>
        <association property="isoutName" column="ISOUT"
                     select="getIsoutName"></association>
    </resultMap>

    <select id="getTableName" resultType="string">
        select t2.NAME tableName
        from TF_YWPN_DMATABLE_W t1 left join TF_DEVICE_ARCHIVE_MANAGE t2
        on t1.device_Id = t2.id
        where t1.id = #{tableId}
    </select>
    <select id="getIsoutName" resultType="string">
        SELECT decode(#{isout},'0','入口','1','出口') as isoutName FROM dual
    </select>
    <select id="getX" resultType="java.lang.Double">
        select t2.LONGITUDE lgtd
        from TF_YWPN_DMATABLE_W t1 left join TF_DEVICE_ARCHIVE_MANAGE t2
                                             on t1.device_Id = t2.id
        where t1.id = #{tableId}
    </select>
    <select id="getY" resultType="java.lang.Double">
        select t2.LATITUDE lttd
        from TF_YWPN_DMATABLE_W t1 left join TF_DEVICE_ARCHIVE_MANAGE t2
                                             on t1.device_Id = t2.id
        where t1.id = #{tableId}
    </select>
    <insert id="insertBatch">
        insert into TF_YWPN_DMAANDOBSER_W (ID, DMA_ID , TABLE_ID , ISOUT , CREATE_USER , CREATE_TIME)
        <foreach collection="list" item="l" separator="union all">
            select
            #{l.id},
            #{l.dmaId},
            #{l.tableId},
            #{l.isout},
            #{l.createUser},
            #{l.createTime}
            from dual
        </foreach>
    </insert>


</mapper>
