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

    <resultMap id="tfDeviceArchiveManageMap" type="com.tofly.xrtygis.entity.TfDeviceArchiveManage">
        <id property="id" column="ID"/>
        <result property="waterId" column="WATER_ID"/>
        <result property="code" column="CODE"/>
        <result property="name" column="NAME"/>
        <result property="type" column="TYPE"/>
        <result property="makeDate" column="MAKE_DATE"/>
        <result property="deviceType" column="DEVICE_TYPE"/>
        <result property="manufacturer" column="MANUFACTURER"/>
        <result property="modelSpecification" column="MODEL_SPECIFICATION"/>
        <result property="status" column="STATUS"/>
        <result property="address" column="ADDRESS"/>
        <result property="longitude" column="LONGITUDE"/>
        <result property="latitude" column="LATITUDE"/>
        <result property="leader" column="LEADER"/>
        <result property="phone" column="PHONE"/>
        <result property="describe" column="DESCRIBE"/>
        <result property="createUser" column="CREATE_USER"/>
        <result property="createTime" column="CREATE_TIME"/>
        <result property="viewJson" column="VIEW_JSON"/>
        <result property="bore" column="BORE"/>
        <result property="pressureDeviceId" column="PRESSURE_DEVICE_ID"/>
        <association property="createUserName" column="CREATE_USER"
                     select="com.tofly.xrtygis.mapper.IFileMapper.getUserName"/>
        <association property="waterName" column="WATER_ID"
                     select="com.tofly.xrtygis.mapper.TfWaterInfoMapper.getWaterName"/>
        <association property="typeName" column="TYPE"
                     select="getTypeName"/>
        <association property="statusName" column="STATUS"
                     select="getStatusName"/>
        <association property="deviceTypeName" column="DEVICE_TYPE" select="getDeviceTypeName"/>
        <association property="leaderName" column="LEADER" select="com.tofly.xrtygis.mapper.IFileMapper.getUserName"/>
    </resultMap>

    <select id="getDeviceName" resultType="string">
        select NAME
        from TF_DEVICE_ARCHIVE_MANAGE
        where ID = #{id}
    </select>

    <select id="getTypeName" resultType="string">
        SELECT decode(#{type}, '0', '未定义', '1', '水厂', '2', '管网', '3', '泵站', '4', '泵组', '5', '污水厂') as typeName
        FROM dual
    </select>

    <select id="getStatusName" resultType="string">
        SELECT CNAME
        FROM TF_YWPN_SYSCHILDCODE_D
        WHERE PCID = 53005
          AND CCODE = #{status}
    </select>

    <select id="getDeviceTypeName" resultType="string">
        SELECT CNAME
        FROM TF_YWPN_SYSCHILDCODE_D
        WHERE PCID = 53400
          AND CCODE = #{deviceType}
    </select>

    <select id="getIdList" resultType="long">
        SELECT ID
        FROM TF_DEVICE_ARCHIVE_MANAGE
        WHERE
            1=1
        <if test="deviceName != null and deviceName.trim() != ''">
            AND NAME LIKE '%' || #{deviceName} || '%'
        </if>
        <if test="stationIdList != null">
            AND WATER_ID IN
            <foreach item="item" index="index" collection="stationIdList" separator="," open="(" close=")">
                #{item}
            </foreach>
        </if>
        <if test="pipeStationType != null and pipeStationType.trim() != ''">
            AND TYPE = #{pipeStationType}
        </if>
    </select>

    <select id="getDeviceTypeReport" resultType="Map">
        select count(1) as total, t2.cname as name, t2.ccode as code
        from TF_DEVICE_ARCHIVE_MANAGE t1
                 inner join TF_YWPN_SYSCHILDCODE_D t2
                            on t1.device_type = t2.ccode
        where t2.pcid = 53400
        group by t2.cname, t2.ccode
        order by t2.ccode

    </select>
    
    
</mapper>
