<?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.watermeter.mapper.WatermeterMapper">

    <resultMap id="watermeterMap" type="com.tofly.watermeter.entity.Watermeter">
        <id property="id" column="ID"/>
        <result property="sid" column="SID"/>
        <result property="rfid" column="RFID"/>
        <result property="metertype" column="METERTYPE"/>
        <result property="distno" column="DISTNO"/>
        <result property="diameter" column="DIAMETER"/>
        <result property="manufacturer" column="MANUFACTURER"/>
        <result property="areano" column="AREANO"/>
        <result property="x" column="X"/>
        <result property="y" column="Y"/>
        <result property="groundz" column="GROUNDZ"/>
        <result property="district" column="DISTRICT"/>
        <result property="laneway" column="LANEWAY"/>
        <result property="address" column="ADDRESS"/>
        <result property="surveyunit" column="SURVEYUNIT"/>
        <result property="ownerunit" column="OWNERUNIT"/>
        <result property="maintainedunit" column="MAINTAINEDUNIT"/>
        <result property="surveydate" column="SURVEYDATE"/>
        <result property="indate" column="INDATE"/>
        <result property="installdate" column="INSTALLDATE"/>
        <result property="createUser" column="CREATE_USER"/>
        <result property="createTime" column="CREATE_TIME"/>
        <result property="remark" column="REMARK"/>
        <result property="fileIds" column="FILE_IDS"/>
        <result property="sbbh" column="SBBH"/>
        <result property="yhbh" column="YHBH"/>
        <result property="yhxm" column="YHXM"/>
        <result property="yhdz" column="YHDZ"/>
        <result property="status" column="STATUS"/>
        <association property="cbpq" column="CBPQ"
                     select="com.tofly.watermeter.mapper.QfcbcbbbmMapper.getCbpqName"/>
        <association property="createUserName" column="CREATE_USER"
                     select="com.tofly.baseapi.mapper.ToflyCodeCommonMapper.getUserName"/>
    </resultMap>

    <select id="getWaterInfo" resultType="map">
        select r.SID,
               r.X,
               r.Y,
               r.GROUNDZ,
               r.ADDRESS,
               r.SURVEYUNIT,
               r.OWNERUNIT,
               r.SURVEYDATE,
               r.REMARK,
               r.FILE_IDS,
               decode(r.ISSUM, '0', '否', '1', '是')                                          is_sum,
               q.YHBH,
               q.YHXM,
               q.YHDZ,
               q.LXDH,
               q.SBCJ,
               (select CNAME from TF_YWPN_SYSCHILDCODE_D where PCID = 2 and CCODE = to_char(q.SBCJ)) sbcjName,
               (select CNAME from TF_YWPN_SYSCHILDCODE_D where PCID = 1 and CCODE = to_char(q.SBKJ)) sbkjName,
               (select CNAME from TF_YWPN_SYSCHILDCODE_D where PCID = 3 and CCODE = to_char(q.SBLX)) sblxName,
               q.SBKJ,
               q.SBLX,
               q.CBPQ,
               c.QYMC,
               q.SBBH,
               r.VILLAGE
        from TF_YWPN_WATERREP_W r
                 left join TF_YWPN_WATERMETER_W w on r.ID = w.REP_ID
                 left join TF_YWPN_QFKHJBXX_W q on w.YHBH = q.YHBH
                 left join TF_YWPN_CBQYBM_W c on q.CBPQ = c.QYBM
        where r.SID = #{sid}
    </select>

</mapper>
