<?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.custom.mapper.AreaSubTableMapper">

    <select id="getArea" resultType="map">
        select distinct cbpq, cbpqmc
        from TF_YWPN_DMAUSERTABLE_W
        where CBPQ is not null
        order by CBPQMC
    </select>

    <select id="getCopybook" resultType="map">
        select distinct cbb, cbbmc
        from TF_YWPN_DMAUSERTABLE_W
        where CBB is not null
          and cbpq = #{cbpqbm}
        order by cbbmc
    </select>

    <select id="getSubTable" resultType="map">
        select
        YHBH,
        YHXM,
        YHDZ,
        SBBH,
        (select CBPQ_MC from TF_YWPN_DMACISCBPQ_W where CBPQ_BM = CBPQ)CBPQMC,
        (select CBB_MC from TF_YWPN_DMACISCBB_W where CBB_BM = CBB) CBBMC,
        (select CNAME from TF_YWPN_SYSCHILDCODE_D where PCID = 2 and CCODE = SBCJ) SBCJMC,
        (select CNAME from TF_YWPN_SYSCHILDCODE_D where PCID = 3 and CCODE = SBLX) SBLXMC,
        DAY_WATER,
        decode(YHZT,'0','申请','1','正式','2','报停','3','销户','4','作废') zt
        from TF_YWPN_DMAUSERTABLE_W
        <where>
            <if test="cbb != null">
                and CBB = #{cbb}
            </if>
            <if test="dto != null">
                and yhbh || yhxm || yhdz || sbbh like '%' || #{dto} || '%'
            </if>
        </where>
        order by YHBH
    </select>

    <select id="exportSubTable" resultType="map">
        select YHBH,
        YHXM,
        YHDZ,
        SBBH,
        (select CBPQ_MC from TF_YWPN_DMACISCBPQ_W where CBPQ_BM = CBPQ)CBPQMC,
        (select CBB_MC from TF_YWPN_DMACISCBB_W where CBB_BM = CBB) CBBMC,
        (select CNAME from TF_YWPN_SYSCHILDCODE_D where PCID = 2 and CCODE = SBCJ) SBCJMC,
        (select CNAME from TF_YWPN_SYSCHILDCODE_D where PCID = 3 and CCODE = SBLX) SBLXMC,
        CBPQMC,
        CBBMC,
        SBCJMC,
        SBLXMC,
        DAY_WATER,
        decode(YHZT,'0','申请','1','正式','2','报停','3','销户','4','作废') zt
        from TF_YWPN_DMAUSERTABLE_W
        <where>
            <if test="cbb != null">
                and CBB = #{cbb}
            </if>
            <if test="dto != null">
                and yhbh || yhxm || yhdz || sbbh like '%' || #{dto} || '%'
            </if>
        </where>
        order by YHBH
    </select>

    <select id="getUseWater" resultType="map">
        select id, yhbh, cwyf, ysl, csrq
        from TF_YWPN_DMAUSERWATER_W
        where yhbh like '%' || #{khbh} || '%'
        <if test="start != null and end != null">
            and csrq between #{start} and #{end}
        </if>
        order by csrq desc
    </select>
</mapper>