<?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.NoiseLoggerInfoMapper">

    <resultMap id="noiseLoggerInfoMap" type="com.tofly.xrtygis.entity.NoiseLoggerInfo">
        <id property="id" column="ID"/>
        <result property="mobileNumber" column="MOBILE_NUMBER"/>
        <result property="channelName" column="CHANNEL_NAME"/>
        <result property="monitoringState" column="MONITORING_STATE"/>
        <result property="disposeState" column="DISPOSE_STATE"/>
        <result property="lastValueDate" column="LAST_VALUE_DATE"/>
        <result property="synchronisedTime" column="SYNCHRONISED_TIME"/>
        <result property="numberCode" column="NUMBER_CODE"/>
        <result property="fileId" column="FILE_ID"/>
        <result property="gdinfoId" column="GDINFO_ID"/>
        <result property="listenNum" column="LISTEN_NUM"/>
        <association property="monitoringStateName" column="MONITORING_STATE" select="getMonitoringStateName"/>
        <association property="disposeStateName" column="DISPOSE_STATE" select="getDisposeStateName"/>
        <association property="filePath" column="FILE_ID" select="getFileIdsList"/>
    </resultMap>

    <select id="getMaxLastValueDateVo" resultType="com.tofly.xrtygis.entity.NoiseLoggerInfo">
        select ID,MOBILE_NUMBER as mobileNumber,LAST_VALUE_DATE as lastValueDate
        from
             (select ID,MOBILE_NUMBER, LAST_VALUE_DATE
             from TF_NOISE_LOGGER_INFO_D
             WHERE MOBILE_NUMBER = #{mobileNumber}
             order by LAST_VALUE_DATE desc)
        where rownum=1
    </select>

    <!--查询得到某个表的最大ID-->
    <select id="selectMaxId" resultType="long">
        select nvl(max(id), 0) + 1
        from #{tableName}
    </select>
    <select id="getFileIdsList" resultType="string" >
        select FILE_PATH as filePath
        from TF_YWPN_FILE_W
        <if test="fileIds != null and fileIds != ''  ">where id in
            <foreach item="nodeCodestr" collection="fileIds.split(',')" open="(" separator="," close=")">
                #{nodeCodestr}
            </foreach>
        </if>
        <if test="fileIdsOne == null ">
            where id = ''
        </if>

    </select>
    <select id="getMonitoringStateName" resultType="string">
        SELECT CNAME
        FROM
            TF_YWPN_SYSCHILDCODE_D
        WHERE
            PCID =53200
          AND
            CCODE = #{monitoringState}
    </select>
    <select id="getDisposeStateName" resultType="string">
        SELECT CNAME
        FROM
            TF_YWPN_SYSCHILDCODE_D
        WHERE
            PCID =53300
          AND
            CCODE = #{monitoringState}
    </select>

    <select id="getNoises" resultType="string">
        SELECT wm_concat(ID)
        FROM TF_NOISE_LOGGER_INFO_D
        WHERE GDINFO_ID = #{id}
    </select>
</mapper>
