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

    <resultMap id="qfcbqfmxMap" type="com.tofly.watermeter.entity.Qfcbqfmx">
        <result property="yhbh" column="YHBH"/>
        <result property="cbkh" column="CBKH"/>
        <result property="cbxh" column="CBXH"/>
        <result property="yhxm" column="YHXM"/>
        <result property="yhdz" column="YHDZ"/>
        <result property="lxdh" column="LXDH"/>
        <result property="sbbh" column="SBBH"/>
        <result property="sbcj" column="SBCJ"/>
        <result property="sblx" column="SBLX"/>
        <result property="sbkj" column="SBKJ"/>
        <result property="ysxz" column="YSXZ"/>
        <result property="xzxf" column="XZXF"/>
        <result property="cbpq" column="CBPQ"/>
        <result property="cbb" column="CBB"/>
        <result property="cwrq" column="CWRQ"/>
        <result property="scds" column="SCDS"/>
        <result property="bcds" column="BCDS"/>
        <result property="bcjjl" column="BCJJL"/>
        <result property="cbbz" column="CBBZ"/>
        <result property="jfzt" column="JFZT"/>
        <result property="cbry" column="CBRY"/>
        <result property="cbrq" column="CBRQ"/>
        <result property="jhrq" column="JHRQ"/>
        <result property="xzbs" column="XZBS"/>
        <result property="fileid" column="FILEID"/>
        <result property="cbfsCode" column="CBFS_CODE"/>
        <result property="shbz" column="SHBZ"/>
        <result property="auditReason" column="AUDIT_REASON"/>
        <result property="auditUser" column="AUDIT_USER"/>
        <result property="auditCause" column="AUDIT_CAUSE"/>
        <result property="auditResult" column="AUDIT_RESULT"/>
        <result property="cbsl" column="CBSL"/>
        <result property="issyn" column="ISSYN"/>
        <result property="month1" column="MONTH1"/>
        <result property="month2" column="MONTH2"/>
        <result property="month3" column="MONTH3"/>
        <result property="bz" column="BZ"/>
        <result property="cbzq" column="CBZQ"/>
        <result property="cbyf" column="CBYF"/>
        <result property="sxjmessage" column="SXJMESSAGE"/>
        <result property="x" column="X"/>
        <result property="y" column="Y"/>
        <result property="addressState" column="ADDRESS_STATE"/>
        <association property="cbfsName" column="CBFS_CODE"
                     select="com.tofly.watermeter.mapper.BwrksbdatailMapper.getCodeById"/>
        <!--        <association property="c"-->
    </resultMap>


    <select id="getAuditResultName" resultType="string">
        select decode(#{result}, '0', '不合格', '1', '合格')
        from dual
    </select>
    <select id="getAuditName" resultType="string">
        select decode(#{shbz}, '0', '未审核', '1', '已审核')
        from dual
    </select>

    <!--(CWRQ , SCDS , BCDS , BCJJL , CBBZ , CBRY , CBRQ , JHRQ)-->
    <update id="updateReadPlan">
        <foreach collection="list" open="begin" close=";end;" item="yh" separator=";">
            update TF_YWPN_QFCBQFMX_W
            <set>
                CWRQ = #{cwrq},
                SCDS = BCDS,
                BCDS = '',
                BCJJL = '',
                CBBZ = '',
                CBRY = '',
                CBRQ = '',
                JHRQ = '',
                XZBS = '0'
            </set>
            where YHBH = #{yh}
        </foreach>
    </update>


    <update id="updateCb">
        <foreach collection="list" open="begin" close=";end;" item="l" separator=";">
            update TF_YWPN_QFCBQFMX_W
            <set>
                BCDS = #{l.bcds} ,
                SCDS = #{l.scds} ,
                CBSL = #{l.bcjjl} ,
                BCJJL = #{l.bcjjl} ,
                <if test="l.month1 != null">
                    MONTH1 = #{l.month1} ,
                </if>
                <if test="l.month2 != null">
                    MONTH2 = #{l.month2} ,
                </if>
                <if test="l.month3 != null">
                    MONTH3 = #{l.month3}
                </if>
            </set>
            where YHBH = #{l.yhbh}
        </foreach>
    </update>

    <update id="insertOrUpdate" parameterType="java.util.List">
        <if test="list != null">
            MERGE INTO TF_YWPN_QFCBQFMX_W w USING (
            <foreach collection="list" item="info" index="index" separator="union all">
                SELECT #{info.yhbh} as YHBH,
                <choose>
                    <when test="info.yhxm!= null">#{info.yhxm} as YHXM,</when>
                    <otherwise>'' as YHXM,</otherwise>
                </choose>
                <choose>
                    <when test="info.yhdz!= null">#{info.yhdz} as YHDZ,</when>
                    <otherwise>'' as YHDZ,</otherwise>
                </choose>
                <choose>
                    <when test="info.lxdh!= null">#{info.lxdh} as LXDH,</when>
                    <otherwise>'' as LXDH,</otherwise>
                </choose>
                <choose>
                    <when test="info.sbbh!= null">#{info.sbbh} as SBBH,</when>
                    <otherwise>'' as SBBH,</otherwise>
                </choose>
                <choose>
                    <when test="info.sbcj!= null">#{info.sbcj} as SBCJ,</when>
                    <otherwise>'' as SBCJ,</otherwise>
                </choose>
                <choose>
                    <when test="info.sblx!= null">#{info.sblx} as SBLX ,</when>
                    <otherwise>'' as SBLX,</otherwise>
                </choose>
                <choose>
                    <when test="info.sbkj!= null">#{info.sbkj} as SBKJ,</when>
                    <otherwise>'' as SBKJ,</otherwise>
                </choose>
                <choose>
                    <when test="info.ysxz!= null">#{info.ysxz} as YSXZ ,</when>
                    <otherwise>'' as YSXZ,</otherwise>
                </choose>
                <choose>
                    <when test="info.xzxf!= null">#{info.xzxf} as XZXF,</when>
                    <otherwise>'' as XZXF,</otherwise>
                </choose>
                <choose>
                    <when test="info.cbpq!= null">#{info.cbpq} as CBPQ,</when>
                    <otherwise>'' as CBPQ,</otherwise>
                </choose>
                <choose>
                    <when test="info.cbb!= null">#{info.cbb} as CBB,</when>
                    <otherwise>'' as CBB,</otherwise>
                </choose>
                <choose>
                    <when test="info.cwrq!= null">#{info.cwrq} as CWRQ,</when>
                    <otherwise>'' as CWRQ,</otherwise>
                </choose>
                <choose>
                    <when test="info.bcds!= null">#{info.bcds} as BCDS ,</when>
                    <otherwise>0 as BCDS,</otherwise>
                </choose>
                <choose>
                    <when test="info.jfzt!= null">#{info.jfzt} as JFZT ,</when>
                    <otherwise>'' as JFZT,</otherwise>
                </choose>

                <choose>
                    <when test="info.bcjjl!= null">#{info.bcjjl} as MONTH1,</when>
                    <otherwise>0 as MONTH1,</otherwise>
                </choose>

                <choose>
                    <when test="info.month2!= null">#{info.month2} as MONTH2,</when>
                    <otherwise>0 as MONTH2,</otherwise>
                </choose>

                <choose>
                    <when test="info.month3!= null">#{info.month3} as MONTH3,</when>
                    <otherwise>0 as MONTH3,</otherwise>
                </choose>

                <choose>
                    <when test="info.cbzq!= null">#{info.cbzq} as CBZQ</when>
                    <otherwise>'' as CBZQ</otherwise>
                </choose>
                FROM dual
            </foreach>
            ) s ON (s.YHBH = w.YHBH)
            WHEN NOT MATCHED THEN INSERT
            (YHBH,YHXM,YHDZ,LXDH,SBBH,SBCJ,SBLX,SBKJ,YSXZ,XZXF,CBPQ,CBB,CWRQ,SCDS,BCDS,BCJJL,CBBZ,JFZT,CBRY,CBRQ,JHRQ,XZBS,FILEID,CBFS_CODE,SHBZ,AUDIT_REASON,AUDIT_USER,AUDIT_CAUSE,AUDIT_RESULT,CBSL,ISSYN,MONTH1,MONTH2,MONTH3,BZ,CBZQ)
            VALUES
            (s.YHBH, s.YHXM,
            s.YHDZ,s.LXDH,s.SBBH,s.SBCJ,s.SBLX,s.SBKJ,s.YSXZ,s.XZXF,s.CBPQ,s.CBB,s.CWRQ,s.BCDS,null,null,'0',s.JFZT,null,null,null,'0',null,null,null,null,null,null,null,null,null,s.MONTH1,s.MONTH2,s.MONTH3,null,s.CBZQ)
            WHEN MATCHED THEN UPDATE
            SET
            w.YHXM=s.YHXM,w.YHDZ=s.YHDZ,w.LXDH=s.LXDH,w.SBBH=s.SBBH,w.SBCJ=s.SBCJ,w.SBLX=s.SBLX,w.SBKJ=s.SBKJ,w.YSXZ=s.YSXZ,w.XZXF=s.XZXF,w.CBPQ=s.CBPQ,w.CBB=s.CBB,w.CWRQ=s.CWRQ,w.SCDS=s.BCDS,w.BCDS=null,w.BCJJL=null,w.CBBZ='0',w.JFZT=s.JFZT,w.CBRY=null,w.CBRQ=null,w.JHRQ=null,w.XZBS='0',w.FILEID=null,w.CBFS_CODE=null,w.SHBZ=null,w.AUDIT_REASON=null,w.AUDIT_USER=null,w.AUDIT_CAUSE=null,w.AUDIT_RESULT=null,w.CBSL=null,w.ISSYN=null,w.MONTH1=s.MONTH1,w.MONTH2=s.MONTH2,w.MONTH3=s.MONTH3,w.BZ=null,w.CBZQ=s.CBZQ
        </if>
    </update>

    <!--    <select id="getReadAppPlan" resultType="map">-->
    <!--        SELECT k.YHBH , k.YHXM , k.YHDZ , DECODE(q.CBBZ, '0','未抄表','1','已抄表') ISCB, q.JHRQ ,-->
    <!--        DECODE(q.XZBS,'0' ,'未下载' ,'1' ,'已下载' ) ISDOW , q.CWRQ-->
    <!--        FROM TF_YWPN_QFKHJBXX_W k , TF_YWPN_QFCBQFMX_W q-->
    <!--        <where>-->
    <!--            <if test="search.sspq != null and search.sspq != '' ">-->
    <!--                and q.CBPQ=#{search.sspq}-->
    <!--            </if>-->
    <!--            <if test="search.cbb != null and search.cbb != '' ">-->
    <!--                and q.CBB=#{search.cbb}-->
    <!--            </if>-->
    <!--            <if test="search.cbry != null and search.cbry != '' ">-->
    <!--                and q.CBRY=#{search.cbry}-->
    <!--            </if>-->
    <!--            <if test="search.state != null and search.state != '' ">-->
    <!--                and q.CBBZ =#{search.state}-->
    <!--            </if>-->
    <!--            and q.YHBH=k.YHBH-->
    <!--        </where>-->
    <!--    </select>-->
    <resultMap id="readPcPlanMap" type="map">
        <result property="allnum" column="ALLNUM"/>
        <result property="read" column="READ"/>
        <result property="noRead" column="NOREAD"/>
        <result property="down" column="DOWN"/>
        <result property="nodown" column="NODOWN"/>
        <result property="planNum" column="planNum"/>
        <!--        <result property="jhrq" column="JHRQ"/>-->
        <result property="qydbm" column="QYDBM"/>
        <result property="qydmc" column="QYDMC"/>
        <result property="cbzq" column="CBZQ"/>
        <result property="cbry" column="CBRY"/>
        <result property="qybm" column="QYBM"/>
        <result property="isDown" column="IS_DOWN"/>
        <association property="cbryName" column="CBRY"
                     select="com.tofly.baseapi.mapper.ToflyCodeCommonMapper.getUserName"/>
        <association property="qybmName" column="QYBM" select="getQyName"/>
    </resultMap>

    <select id="getQyName" resultType="string">
        select QYMC
        from TF_YWPN_CBQYBM_W
        where QYBM = #{qybm}
    </select>


    <select id="staPlanByCbb" resultType="map">
        SELECT t.SUMREAD, t.READ, t.NOREAD, b.CBBMC , b.CBDZ
        FROM TF_YWPN_QFCBCBBBM_W b ,
        (SELECT COUNT(CBBZ) SUMREAD ,
        sum(case when CBBZ = '1' then 1 else 0 end) READ ,
        sum(case when CBBZ= '0' then 1 else 0 end ) NOREAD , CBB
        FROM TF_YWPN_QFCBQFMX_W
        <where>
            CWRQ=#{cwRq} AND CBB IN
            <foreach collection="list" item="list" separator="," close=")" open="(">
                #{list}
            </foreach>
        </where>
        GROUP BY CBB) t
        WHERE t.CBB = b.CBBBM
    </select>

    <resultMap id="appReadMap" type="com.tofly.watermeter.custom.entity.meterRead.AppRead">
        <result property="yhbh" column="YHBH"/>
        <result property="scds" column="SCDS"/>
        <result property="bcds" column="BCDS"/>
        <result property="cbsl" column="CBSL"/>
        <result property="yhxm" column="YHXM"/>
        <result property="yhdz" column="YHDZ"/>
        <result property="lxdh" column="LXDH"/>
        <result property="lxsj" column="LXSJ"/>
        <result property="isqf" column="ISQF"/>
        <result property="qfje" column="QFJE"/>
        <result property="yhzt" column="YHZT"/>
        <result property="qfzq" column="QFZQ"/>
        <result property="clientBz" column="CLIENT_BZ"/>
        <result property="clientFileIds" column="CLIENT_FILE"/>
        <result property="ysxz" column="YSXZ"/>
        <result property="xzxf" column="XZXF"/>
        <result property="sbbh" column="SBBH"/>
        <result property="cbxh" column="CBXH"/>
        <result property="rfid" column="RFID"/>
        <result property="qybm" column="QYBM"/>
        <result property="ysxzName" column="YSXZ_MC"/>
        <result property="qydbm" column="QYDBM"/>
        <result property="qybmName" column="QYMC"/>
        <result property="qydmc" column="QYDMC"/>
        <result property="cbfsCode" column="CBFS_CODE"/>
        <result property="cbbz" column="CBBZ"/>
        <result property="isupload" column="ISUPLOAD"/>
        <result property="isSave" column="ISSAVE"/>
        <result property="cbry" column="CBRY"/>
        <result property="cbryName" column="CBRY_NAME"/>
        <result property="addressState" column="ADDRESS_STATE"/>
        <result property="issyn" column="ISSYN"/>
        <result property="synName" column="SYNNAME"/>
        <result property="auditReason" column="AUDIT_REASON"/>
        <result property="bz" column="BZ"/>
        <result property="month1" column="MONTH1"/>
        <result property="month2" column="MONTH2"/>
        <result property="month3" column="MONTH3"/>
        <result property="cbrq1" column="CBRQ1"/>
        <result property="cbrq2" column="CBRQ2"/>
        <result property="cbrq3" column="CBRQ3"/>
        <result property="cbrq4" column="CBRQ4"/>
        <result property="isEstimate" column="IS_ESTIMATE"/>
        <result property="cbrq" column="CBRQ"/>
        <result property="hblx" column="HBLX"/>
        <result property="jbzd" column="JBZD"/>
        <result property="xbqd" column="XBQD"/>
        <result property="sxjSbqd" column="SXJ_SBQD"/>
        <result property="hbrq" column="HBRQ"/>
        <result property="zhye" column="ZHYE"/>
        <result property="imgUrl" column="IMG_URL"/>
        <result property="monthPlan" column="MONTH_PLAN"/>
        <result property="auditResultName" column="AUDITRESULTNAME"/>
        <result property="auditResult" column="AUDIT_RESULT"/>
        <result property="khrq" column="KHRQ"/>
        <result property="zgl" column="ZGL"/>
        <result property="diffValue" column="DIFF_VALUE"/>
        <result property="soleSign" column="SOLE_SIGN"/>
        <association property="sbcj" column="SBCJ"
                     select="com.tofly.watermeter.mapper.QfkhjbxxMapper.getCjByCode"/>
        <association property="sbkj" column="SBKJ"
                     select="com.tofly.watermeter.mapper.QfkhjbxxMapper.getKjByCode"/>
        <association property="sblx" column="SBLX"
                     select="com.tofly.watermeter.mapper.QfkhjbxxMapper.getLxByCode"/>
        <association property="cbfsName" column="CBFS_CODE"
                     select="com.tofly.watermeter.mapper.BwrksbdatailMapper.getCodeById"/>
        <association property="cbbzName" column="CBBZ"
                     select="getCbbzName"/>
        <collection property="fileInfo" column="{fileIds=FILEID,cbry=HANDLERS_ID}"
                    select="com.tofly.watermeter.mapper.QfcbqfmxMapper.getFileByIdsAndCbry"/>
        <collection property="clientFileInfo" column="CLIENT_FILE"
                    select="com.tofly.watermeter.mapper.QfcbqfmxMapper.getFileByIds"/>
    </resultMap>

    <select id="getFileByIdsAndCbry" resultType="com.tofly.watermeter.custom.entity.file.FileInfo">
        select ID , FILE_PATH , FILE_NAME from TF_YWPN_FILE_W
        <where>
            <if test="fileIds != null and fileIds != '' ">
                and ID in
                <foreach collection="fileIds.split(',')" item="id" open="(" separator="," close=")">
                    #{id}
                </foreach>
            </if>
            <if test="cbry != null and cbry != ''">
                and CREATE_USER = #{cbry}
            </if>
            <!--排除没有照片，没有抄表的情况-->
            <if test="fileIds == null or fileIds == ''">
                and ID = null
            </if>
        </where>
    </select>

    <select id="getCbbzName" resultType="string">
        select decode(#{cbbz}, '0', '未抄表', '1', '已抄表')
        from dual
    </select>
    <resultMap id="readUpdateListMap" type="com.tofly.watermeter.custom.entity.meterRead.AppRead" extends="appReadMap">
        <collection property="readupdateList" column="SOLE_SIGN"
                    select="com.tofly.watermeter.mapper.ReadupdateMapper.getReadUpdate"/>
    </resultMap>
    <select id="getOfflineByYhbh" resultMap="readUpdateListMap">
        SELECT distinct b.YHBH,
               b.SOLE_SIGN,
               b.ZGL,
               b.DIFF_VALUE,
               b.YHXM,
               b.YHDZ,
               b.LXDH,
               b.SCDS,
               b.BCDS,
               b.CBSL,
               b.SBBH,
               b.YSXZ,
               b.CBRQ,
               b.CBRY,
               b.HANDLERS_ID,
               b.CBRY_NAME,
               b.ADDRESS_STATE,
               b.ISSYN,
               DECODE(b.ISSYN, '0', '未同步', '1', '已同步')                                                         SYNNAME,
               b.AUDIT_REASON,
               b.XZXF,
               b.CBFS_CODE,
               b.MONTH1,
               b.MONTH2,
               b.MONTH3,
               b.CBRQ2,
               b.CBRQ3,
               b.CBRQ4,
               b.CBRQ1,
               b.IS_ESTIMATE,
               b.JBZD,
               b.XBQD,
               b.HBLX,
               b.HBRQ,
               b.BZ,
               b.FILEID,
               b.SBCJ                                                                                          SBCJ,
               b.SBKJ                                                                                          SBKJ,
               b.SBLX                                                                                          SBLX,
               l.SFQF                                                                                       as ISQF,
               l.QFJE,
               l.QFZQ,
               DECODE(l.YHZT, '0', '未启用', '1', '正常', '2', '报停', '3', '停水', '4', '锁定', '5', '关阀', '9', '销户') as YHZT,
               l.LXSJ,
               b.CBQY_BM                                                                                       QYBM,
               b.CBQYD_BM                                                                                      QYDBM,
               b.CBQY_MC                                                                                       QYMC,
               b.QYDMC,
               b.CBBZ,
               b.CBXH,
               b.MONTH_PLAN,
               d.RFID,
               j.YSXZ_MC,
               l.ZHYE,
               f.CLIENT_BZ,
               f.FILE_ID                                                                                    as CLIENT_FILE,
               decode(b.SHBZ, '0', '未审核', '1', '人工审核通过', '2', '转质检', '3', '转质检完成')                          as AUDITRESULTNAME,
               b.SHBZ                                                                                       as AUDIT_RESULT,
               b.SXJ_SBQD
        FROM TF_YWPN_READMETERHIS_W b
                 LEFT JOIN TF_YWPN_WATERMETER_W d ON b.YHBH = d.YHBH
                 LEFT JOIN TF_YWPN_QFMIDYSXZBM_E j ON b.YSXZ = j.YSXZ_BM
                 LEFT JOIN TF_YWPN_QFKHJBXX_W l ON b.YHBH = l.YHBH
                 LEFT JOIN TF_YWPN_YHFOREVERINFO_W f ON b.YHBH = f.YHBH
        WHERE b.SOLE_SIGN = #{soleSign}
        ORDER BY b.CBXH ASC
    </select>

    <select id="queryOfflineByYhbh" resultMap="readUpdateListMap">
        SELECT distinct b.YHBH,
                        b.YHXM,
                        b.YHDZ,
                        b.LXDH,
                        b.SCDS,
                        b.BCDS,
                        b.CBSL,
                        b.SBBH,
                        b.YSXZ,
                        b.CBRQ,
                        b.CBRY,
                        b.CBRY_NAME,
                        b.ADDRESS_STATE,
                        b.ISSYN,
                        DECODE(b.ISSYN, '0', '未同步', '1', '已同步')                                SYNNAME,
                        b.AUDIT_REASON,
                        b.XZXF,
                        b.CBFS_CODE,
                        b.MONTH1,
                        b.MONTH2,
                        b.MONTH3,
                        (case
                             when MONTH1 is not null
                                 then add_months(to_date(CBYF, 'yyyymm'), -1) end)             cbrq1,
                        (case
                             when MONTH2 is not null
                                 then add_months(to_date(CBYF, 'yyyymm'), -2) end)             cbrq2,
                        (case
                             when MONTH3 is not null
                                 then add_months(to_date(CBYF, 'yyyymm'), -3) end)             cbrq3,
                        b.CBRQ4,
                        b.IS_ESTIMATE,
                        b.JBZD,
                        b.XBQD,
                        b.HBLX,
                        b.HBRQ,
                        b.BZ,
                        b.FILEID,
                        b.SBCJ                                                                 SBCJ,
                        b.SBKJ                                                                 SBKJ,
                        b.SBLX                                                                 SBLX,
                        l.SFQF                                                              as ISQF,
                        l.QFJE,
                        l.QFZQ,
                        DECODE(l.YHZT, '0', '未启用', '1', '正常', '2', '报停', '3', '停水', '4', '锁定', '5', '关阀', '9',
                               '销户')                                                        as YHZT,
                        l.LXSJ,
                        b.CBQY_BM                                                              QYBM,
                        b.CBQYD_BM                                                             QYDBM,
                        b.CBQY_MC                                                              QYMC,
                        b.QYDMC,
                        b.CBBZ,
                        b.CBRY                                                                 HANDLERS_ID,
                        b.CBXH,
                        b.MONTH_PLAN,
                        d.RFID,
                        j.YSXZ_MC,
                        l.ZHYE,
                        f.CLIENT_BZ,
                        f.FILE_ID                                                           as CLIENT_FILE,
                        decode(b.SHBZ, '0', '未审核', '1', '人工审核通过', '2', '转质检', '3', '转质检完成') as AUDITRESULTNAME,
                        b.SHBZ                                                              as AUDIT_RESULT,
                        b.SXJ_SBQD
        FROM TF_YWPN_METERREADING_W_VIEW b
                 LEFT JOIN TF_YWPN_WATERMETER_W d ON b.YHBH = d.YHBH
                 LEFT JOIN TF_YWPN_QFMIDYSXZBM_E j ON b.YSXZ = j.YSXZ_BM
                 LEFT JOIN TF_YWPN_QFKHJBXX_W l ON b.YHBH = l.YHBH
                 LEFT JOIN TF_YWPN_YHFOREVERINFO_W f ON b.YHBH = f.YHBH
        WHERE b.YHBH = #{yhbh}
          and to_char(cbrq, 'yyyy-mm-dd hh24:mi:ss') = #{cbrq}
    </select>

    <select id="getListByYhbh" resultMap="appReadMap">
        SELECT distinct
        b.YHBH,
        b.YHXM,
        b.YHDZ,
        b.LXDH,
        b.SCDS,
        <if test="isGeneral == 1">
            (case when b.SBLX = '3' then l.SCDS end) as ZGL,
        </if>
        b.BCDS,
        b.SBBH,
        b.YSXZ,
        b.XZXF,
        b.CBFS_CODE,
        b.MONTH1,
        b.MONTH2,
        b.MONTH3,
        b.CBRQ2,
        b.CBRQ3,
        b.CBRQ1,
        b.CBRQ4,
        b.IMG_URL,
        b.IS_ESTIMATE,
        b.JBZD,
        b.XBQD,
        b.MONTH_PLAN,
        b.HBLX,
        b.HBRQ,
        b.BZ,
        b.SBCJ SBCJ, b.SBKJ SBKJ, b.SBLX SBLX ,
        l.SFQF as ISQF,
        l.QFJE,
        l.QFZQ,
        f.CLIENT_BZ,
        f.FILE_ID as CLIENT_FILE,
        l.LXSJ,
        DECODE(l.YHZT,'0','未启用','1','正常','2','报停','3','停水','4','锁定','5','关阀','9','销户') as YHZT,
        b.CBQY_BM as QYBM , b.CBQYD_BM as QYDBM ,
        b.CBQY_MC as QYMC ,
        b.QYDMC ,
        b.CBBZ , b.CBXH ,
        d.RFID ,
        j.YSXZ_MC,
        l.ZHYE,
        l.JDRQ,
        b.DIFF_VALUE,
        b.SOLE_SIGN,
        b.FILEID,
        b.CBRY,
        b.HANDLERS_ID,
        l.SBWZ sbxh
        FROM
        TF_YWPN_READMETERHIS_W b
        LEFT JOIN TF_YWPN_WATERMETER_W d ON b.YHBH = d.YHBH
        LEFT JOIN TF_YWPN_QFMIDYSXZBM_E j ON b.YSXZ = j.YSXZ_BM
        LEFT JOIN TF_YWPN_QFKHJBXX_W l ON b.YHBH = l.YHBH
        LEFT JOIN TF_YWPN_YHFOREVERINFO_W f ON b.YHBH = f.YHBH
        WHERE b.CBRY = #{cbry}
        and b.cbbz != '1'
        and b.START_DAY <![CDATA[ <= ]]> #{day}
        <if test="isGeneral != null ">
            and b.IS_GENERAL = #{isGeneral}
        </if>
        <choose>
            <when test="type != null and type != ''">
                and b.SBLX like '%' || #{type} || '%'
            </when>
            <otherwise>
                and b.SBLX = '01'
            </otherwise>
        </choose>
        <if test="zone != null and zone != ''">
            and b.CBQYD_BM in
            <foreach collection="zone.split(',')" item="z" open="(" separator="," close=")">
                #{z}
            </foreach>
        </if>
        and b.MONTH_PLAN = #{monthPlan}
        and b.PLAN_ID = #{planId}
        ORDER BY b.CBQY_BM , b.CBQYD_BM , b.CBXH
    </select>

    <select id="getOfflineInfo" resultMap="auditMap">
        SELECT YHBH,
        (select distinct sbkh from TF_YWPN_QFKHJBXX_W where yhbh = r.yhbh and ROWNUM = 1) sbkh,
        YHXM,
        YHDZ,
        SCDS,
        BCDS,
        decode(ISSYN , '0' , '未同步', '1', '已同步') ISSYN,
        SXJMESSAGE,
        SXJ_SBQD,
        TO_CHAR(CBRQ , 'yyyy-MM-dd hh24:mi:ss') cbrq,
        MONTH_PLAN,
        FILEID,
        BCJJL,
        BZ,
        CBRY_NAME,
        CBRY,
        HANDLERS_ID,
        CBQY_MC,
        CBQYD_BM,
        CBFS_CODE,
        CBBZ,
        QYDMC,
        CBSL,
        IS_ESTIMATE,
        SBKJ,
        DIFF_TIME,
        SOLE_SIGN,
        ZGL,DIFF_VALUE,YSXZ,SBBH,IS_UPDATEID
        FROM TF_YWPN_READMETERHIS_W r
        where
        MONTH_PLAN = #{cwyf}
        <if test="cbryList != null">
            and CBRY_NAME IN
            <foreach collection="cbryList" open="(" separator="," item="cbry" close=")">
                #{cbry}
            </foreach>
        </if>
        <if test="isDis != null and isDis != ''">
            and CBBZ = #{isDis}
        </if>
        <if test="cbbList != null">
            and CBQYD_BM IN
            <foreach collection="cbbList" open="(" separator="," item="cbb" close=")">
                #{cbb}
            </foreach>
        </if>
        <if test="cbpqList != null">
            and CBQY_BM IN
            <foreach collection="cbpqList" open="(" separator="," item="qymc" close=")">
                #{qymc}
            </foreach>
        </if>
        <if test="state == 0">
            AND CBBZ = '0'
        </if>
        <if test="state == 1">
            AND CBBZ = '1'
        </if>
        <if test="state == 7">
            AND CBBZ = '1' AND ISBREAK_READ = '1'
        </if>
        <if test="state == 8">
            AND CBBZ = '1' AND ISBREAK_READ is null
        </if>
        <if test="cbfsList != null">
            AND CBFS_CODE IN
            <foreach collection="cbfsList" open="(" separator="," item="cbfs" close=")">
                #{cbfs}
            </foreach>
        </if>
        <if test="isEstimate != null and isEstimate != ''">
            and IS_ESTIMATE = #{isEstimate}
        </if>
        <if test="issyn != null and issyn != ''">
            AND ISSYN = #{issyn}
        </if>
        <if test="inputContent != null and inputContent != ''">
            AND
            (
            YHBH like '%' || #{inputContent} || '%'
            or
            YHXM like '%' || #{inputContent} || '%'
            or
            YHDZ like '%' || #{inputContent} || '%'
            or
            LXDH like '%' || #{inputContent} || '%')
        </if>
        <if test="isUpdate == 1">
            AND IS_UPDATECBSL = #{isUpdate}
        </if>
        <if test="isUpdate == 0">
            AND IS_UPDATECBSL is null
        </if>
        and IS_GENERAL = #{isGeneral}
        ORDER BY CBRQ
    </select>

    <!--这个与上面的SQL是一样的，但是前端页面的抄表人员传参不好改，所以就多加一个-->
    <select id="getOfflineInfo2" resultMap="auditMap">
        SELECT YHBH,
        YHXM,
        YHDZ,
        SCDS,
        BCDS,
        decode(ISSYN , '0' , '未同步', '1', '已同步') ISSYN,
        SXJMESSAGE,
        SXJ_SBQD,
        TO_CHAR(CBRQ , 'yyyy-MM-dd hh24:mi:ss') cbrq,
        FILEID,
        BCJJL,
        BZ,
        CBRY_NAME,
        CBRY,
        HANDLERS_ID,
        CBQY_MC,
        CBQYD_BM,
        CBFS_CODE,
        CBBZ,
        QYDMC,
        CBSL,
        IS_ESTIMATE,
        DIFF_TIME,
        SOLE_SIGN,
        ZGL,DIFF_VALUE
        FROM TF_YWPN_READMETERHIS_W
        where
        MONTH_PLAN = #{cwyf}
        <if test="cbryList != null">
            and CBRY IN
            <foreach collection="cbryList" open="(" separator="," item="cbry" close=")">
                #{cbry}
            </foreach>
        </if>
        <if test="isDis != null and isDis != ''">
            and CBBZ = #{isDis}
        </if>
        <if test="cbbList != null">
            and CBQYD_BM IN
            <foreach collection="cbbList" open="(" separator="," item="cbb" close=")">
                #{cbb}
            </foreach>
        </if>
        <if test="cbpqList != null">
            and CBQY_BM IN
            <foreach collection="cbpqList" open="(" separator="," item="qymc" close=")">
                #{qymc}
            </foreach>
        </if>
        <if test="cbfsList != null">
            and CBFS_CODE IN
            <foreach collection="cbfsList" open="(" separator="," item="cbfs" close=")">
                #{cbfs}
            </foreach>
        </if>
        <if test="state == 0">
            AND CBBZ = '0'
        </if>
        <if test="state == 1">
            AND CBBZ = '1'
        </if>
        <if test="state == 7">
            AND CBBZ = '1' AND ISBREAK_READ = '1'
        </if>
        <if test="state == 8">
            AND CBBZ = '1' AND ISBREAK_READ is null
        </if>
        <if test="isEstimate != null and isEstimate != ''">
            and IS_ESTIMATE = #{isEstimate}
        </if>
        <if test="issyn != null and issyn != ''">
            AND ISSYN = #{issyn}
        </if>
        and IS_GENERAL = #{isGeneral}
        ORDER BY CBQY_MC , QYDMC , CBRQ
    </select>

    <select id="cardUpdateTwo" resultMap="auditMap">
        SELECT
        YHBH,
        (select sbkh from TF_YWPN_QFKHJBXX_W where yhbh = a.yhbh) sbkh,
        YHXM,
        YHDZ,
        SCDS,
        BCDS,
        decode(ISSYN , '0' , '未同步', '1', '已同步') ISSYN,
        SXJMESSAGE,
        SXJ_SBQD,
        TO_CHAR(CBRQ , 'yyyy-MM-dd hh24:mi:ss') cbrq,
        FILEID,
        BCJJL,
        BZ,
        CBRY_NAME,
        CBRY,
        HANDLERS_ID,
        CBQY_MC,
        CBQYD_BM,
        CBFS_CODE,
        CBBZ,
        QYDMC,
        CBSL,
        IS_ESTIMATE,
        DIFF_TIME,
        SOLE_SIGN,
        ZGL,a.DIFF_VALUE,
        IS_UPDATEID
        FROM TF_YWPN_READMETERHIS_W a
        where
        MONTH_PLAN = #{cwyf}
        <if test="cbryList != null">
            and CBRY IN
            <foreach collection="cbryList" open="(" separator="," item="cbry" close=")">
                #{cbry}
            </foreach>
        </if>
        <if test="qydbmList != null">
            and CBQYD_BM IN
            <foreach collection="qydbmList" open="(" separator="," item="qyd" close=")">
                #{qyd}
            </foreach>
        </if>
        <if test="qybmList != null">
            and CBQY_BM IN
            <foreach collection="qybmList" open="(" separator="," item="qybm" close=")">
                #{qybm}
            </foreach>
        </if>
        <if test="inputContent != null and inputContent != ''">
            AND
            (
            YHBH like '%' || #{inputContent} || '%'
            or
            YHXM like '%' || #{inputContent} || '%'
            or
            YHDZ like '%' || #{inputContent} || '%'
            or
            LXDH like '%' || #{inputContent} || '%')
        </if>
        <if test="state == 0">
            AND CBBZ = '0'
        </if>
        <if test="state == 1">
            AND CBBZ = '1'
        </if>
        <if test="state == 7">
            AND CBBZ = '1' AND IS_UPDATECBSL = '1'
        </if>
        <if test="state == 8">
            AND CBBZ = '1' AND IS_UPDATECBSL is null
        </if>
        <if test="isUpdate == 1">
            AND IS_UPDATECBSL = #{isUpdate}
        </if>
        <if test="isUpdate == 0">
            AND IS_UPDATECBSL is null
        </if>
        and IS_GENERAL = #{isGeneral}
        ORDER BY CBQY_MC , QYDMC , CBRQ
    </select>

    <select id="getOfflineInfoList" resultMap="auditMap" fetchSize="1000" databaseId="oracle">
        SELECT YHBH,
        YHXM,
        YHDZ,
        SCDS,
        BCDS,
        decode(ISSYN , '0' , '未同步', '1', '已同步') ISSYN,
        SXJMESSAGE,
        SXJ_SBQD,
        TO_CHAR(CBRQ , 'yyyy-MM-dd hh24:mi:ss') cbrqstr,
        FILEID,
        BCJJL,
        SBKJ,
        (select cname from TF_YWPN_SYSCHILDCODE_D where PCID = 1 and CCODE = SBKJ) SBKJ_NAME,
        YSXZ,
        BZ,
        CBRY_NAME,
        CBRY,
        HANDLERS_ID,
        CBQY_MC,
        CBQYD_BM,
        CBFS_CODE,
        CBBZ,
        QYDMC,
        CBSL,
        IS_ESTIMATE,
        DIFF_TIME,
        ZGL,DIFF_VALUE
        FROM TF_YWPN_READMETERHIS_W
        where
        MONTH_PLAN = #{cwyf}
        <if test="cbryList != null">
            and CBRY_NAME IN
            <foreach collection="cbryList" open="(" separator="," item="cbry" close=")">
                #{cbry}
            </foreach>
        </if>
        <if test="isDis != null and isDis != ''">
            and CBBZ = #{isDis}
        </if>
        <if test="cbbList != null">
            and CBQYD_BM IN
            <foreach collection="cbbList" open="(" separator="," item="cbb" close=")">
                #{cbb}
            </foreach>
        </if>
        <if test="cbpqList != null">
            and CBQY_BM IN
            <foreach collection="cbpqList" open="(" separator="," item="qymc" close=")">
                #{qymc}
            </foreach>
        </if>
        <if test="state == 0">
            AND CBBZ = '0'
        </if>
        <if test="state == 1">
            AND CBBZ = '1'
        </if>
        <if test="state == 7">
            AND CBBZ = '1' AND ISBREAK_READ = '1'
        </if>
        <if test="state == 8">
            AND CBBZ = '1' AND ISBREAK_READ is null
        </if>
        <if test="cbfsList != null">
            AND CBFS_CODE IN
            <foreach collection="cbfsList" open="(" separator="," item="cbfs" close=")">
                #{cbfs}
            </foreach>
        </if>
        <if test="isEstimate != null and isEstimate != ''">
            and IS_ESTIMATE = #{isEstimate}
        </if>
        <if test="issyn != null and issyn != ''">
            AND ISSYN = #{issyn}
        </if>
        <if test="inputContent != null and inputContent != ''">
            AND
            (
            YHBH like '%' || #{inputContent} || '%'
            or
            YHXM like '%' || #{inputContent} || '%'
            or
            YHDZ like '%' || #{inputContent} || '%'
            or
            LXDH like '%' || #{inputContent} || '%')
        </if>
        <if test="isUpdate == 1">
            AND IS_UPDATECBSL = #{isUpdate}
        </if>
        <if test="isUpdate == 0">
            AND IS_UPDATECBSL is null
        </if>
        and IS_GENERAL = #{isGeneral}
        ORDER BY CBRQ
    </select>

    <select id="getOfflineInfoList2" resultMap="auditMap">
        SELECT YHBH,
        YHXM,
        YHDZ,
        SCDS,
        BCDS,
        CBSL,
        SXJMESSAGE,
        decode(ISSYN , '0' , '未同步', '1', '已同步') ISSYN,
        TO_CHAR(CBRQ , 'yyyy-MM-dd hh24:mi:ss') cbrq,
        FILEID,
        BCJJL,
        BZ,
        CBRY,
        HANDLERS_ID,
        CBRY_NAME,
        CBQY_MC,
        CBQYD_BM,
        CBFS_CODE,
        CBBZ,
        QYDMC,
        DIFF_TIME,
        ZGL,DIFF_VALUE
        FROM TF_YWPN_READMETERHIS_W
        where
        MONTH_PLAN = #{cwyf}
        <if test="cbryList != null">
            and CBRY IN
            <foreach collection="cbryList" open="(" separator="," item="cbry" close=")">
                #{cbry}
            </foreach>
        </if>
        <if test="isDis != null and isDis != ''">
            and CBBZ = #{isDis}
        </if>
        <if test="cbbList != null">
            and CBQYD_BM IN
            <foreach collection="cbbList" open="(" separator="," item="cbb" close=")">
                #{cbb}
            </foreach>
        </if>
        <if test="cbpqList != null">
            and CBQY_BM IN
            <foreach collection="cbpqList" open="(" separator="," item="qymc" close=")">
                #{qymc}
            </foreach>
        </if>
        <if test="cbfsList != null">
            and CBFS_CODE IN
            <foreach collection="cbfsList" open="(" separator="," item="cbfs" close=")">
                #{cbfs}
            </foreach>
        </if>
        <if test="state == 0">
            AND CBBZ = '0'
        </if>
        <if test="state == 1">
            AND CBBZ = '1'
        </if>
        <if test="state == 7">
            AND CBBZ = '1' AND ISBREAK_READ = '1'
        </if>
        <if test="state == 8">
            AND CBBZ = '1' AND ISBREAK_READ is null
        </if>
        <if test="isEstimate != null and isEstimate != ''">
            and IS_ESTIMATE = #{isEstimate}
        </if>
        <if test="issyn != null and issyn != ''">
            AND ISSYN = #{issyn}
        </if>
        and IS_GENERAL = #{isGeneral}
        ORDER BY CBRQ
    </select>

    <select id="getKhjbxx" resultType="com.tofly.watermeter.custom.entity.meterRead.AppRead">
        SELECT q.YHBH,
        q.YHXM,
        q.YHDZ,
        q.LXDH,
        q.SBBH,
        q.SBCJ SBCJ,
        q.SBKJ SBKJ,
        q.SBLX SBLX,
        d.RFID,
        j.YSXZ_MC,
        b.CBQY_BM as QYBM , b.CBQYD_BM as QYDBM ,
        b.CBQY_MC as QYMC ,
        b.CBBZ , b.CBXH
        FROM TF_YWPN_QFKHJBXX_W q
        LEFT JOIN TF_YWPN_READMETERHIS_W b ON q.YHBH = b.YHBH
        LEFT JOIN TF_YWPN_WATERMETER_W d ON q.YHBH = d.YHBH
        LEFT JOIN TF_YWPN_QFMIDYSXZBM_E j ON q.YSXZ = j.YSXZ_BM
        WHERE q.YHBH IN
        <foreach collection="list" item="yhInfo" open="(" close=")" separator=",">
            #{yhInfo.yhbh}
        </foreach>
        <if test="isGeneral != null ">
            and b.IS_GENERAL = #{isGeneral}
        </if>
        and b.MONTH_PLAN = #{monthPlan}
        ORDER BY b.CBXH ASC
    </select>


    <resultMap id="auditMap" type="com.tofly.watermeter.custom.entity.meterRead.readstatic.AuditMap">
        <id property="yhbh" column="YHBH"/>
        <result property="sbkj" column="SBKJ"/>
        <result property="yhxm" column="YHXM"/>
        <result property="yhdz" column="YHDZ"/>
        <result property="scds" column="SCDS"/>
        <result property="bcds" column="BCDS"/>
        <result property="qydbm" column="CBQYD_BM"/>
        <result property="qymc" column="CBQY_MC"/>
        <result property="qydmc" column="QYDMC"/>
        <result property="auditReason" column="AUDIT_REASON"/>
        <result property="bz" column="BZ"/>
        <result property="sxjmessage" column="SXJMESSAGE"/>
        <result property="sxjSbqd" column="SXJ_SBQD"/>
        <result property="issyn" column="ISSYN"/>
        <result property="cbryName" column="CBRY_NAME"/>
        <result property="cbry" column="CBRY"/>
        <result property="diffTime" column="DIFF_TIME"/>
        <result property="cbsl" column="CBSL"/>
        <result property="isEstimate" column="IS_ESTIMATE"/>
        <result property="cbrqStr" column="cbrqstr"/>
        <result property="soleSign" column="SOLE_SIGN"/>
        <result property="zgl" column="ZGL"/>
        <result property="diffValue" column="DIFF_VALUE"/>
        <result property="sbbh" column="SBBH"/>
        <result property="monthPlan" column="MONTH_PLAN"/>
        <association property="ysxz" column="YSXZ"
                     select="com.tofly.watermeter.mapper.QfkhjbxxMapper.getYsxzName"/>
        <association property="diffTimeStr" column="DIFF_TIME"
                     select="getDiffTimeStr"/>
        <association property="cbbzName" column="CBBZ"
                     select="getcbbzName"/>
        <association property="cbfsName" column="CBFS_CODE"
                     select="com.tofly.watermeter.mapper.BwrksbdatailMapper.getCodeById"/>
        <association property="auditResultName" column="AUDIT_RESULT"
                     select="getAuditResultName"/>
        <association property="auditName" column="SHBZ"
                     select="getAuditName"/>
        <association property="auditUserName" column="AUDIT_USER"
                     select="com.tofly.baseapi.mapper.ToflyCodeCommonMapper.getUserName"/>
        <association property="readupdate" column="IS_UPDATEID"
                     select="com.tofly.watermeter.mapper.ReadupdateMapper.selectById"/>
        <association property="sbkjName" column="SBKJ"
                     select="com.tofly.watermeter.mapper.BwrksbdatailMapper.getCal"/>
        <collection property="fileInfo" column="{fileIds=FILEID,cbry=HANDLERS_ID}"
                    select="com.tofly.watermeter.mapper.QfcbqfmxMapper.getFileByIdsAndCbry"/>

    </resultMap>

    <select id="getDiffTimeStr" resultType="string">
        SELECT floor(#{diffTime} / 60) || '分' || MOD(#{diffTime}, 60) || '秒'
        from dual
    </select>

    <select id="getcbbzName" resultType="string">
        select decode(#{cbbz}, '0', '未抄表', '1', '已抄表')
        from dual
    </select>

    <select id="getFileByIds" resultType="com.tofly.watermeter.custom.entity.file.FileInfo">
        select ID , FILE_PATH , FILE_NAME from TF_YWPN_FILE_W where ID in
        <if test="fileIds != null and fileIds != '' ">
            <foreach collection="fileIds.split(',')" item="id" open="(" separator="," close=")">
                #{id}
            </foreach>
        </if>
    </select>

    <select id="getAuditCbData" resultMap="auditMap">
        SELECT YHBH,
               YHXM,
               YHDZ,
               SCDS,
               BCDS,
               FILEID,
               BCJJL,
               BZ,
               CBRY_NAME,
               HANDLERS_ID,
               CBQY_MC,
               CBQYD_BM,
               QYDMC,
               AUDIT_RESULT,
               AUDIT_REASON,
               CBFS_CODE
        FROM TF_YWPN_READMETERHIS_W
        where SHBZ = #{isDis}
          and CBYF = #{startTime}
          and CBRY_NAME = #{cbry}
          and QYDMC = #{cbb}
          and CBQY_MC = #{cbpq}
          and IS_GENERAL = #{isGeneral}
        ORDER BY CBRQ
    </select>

    <resultMap id="statisticsMap" type="com.tofly.watermeter.custom.entity.meterRead.ReadStatisticsDetail">
        <result property="qydmc" column="QYDMC"/>
        <result property="qydbm" column="QYDBM"/>
        <result property="allRead" column="ALLREAD"/>
        <result property="read" column="READ"/>
        <result property="noRead" column="NOREAD"/>
        <result property="readPercent" column="READPERCENT"/>
        <result property="qymc" column="QYMC"/>
        <result property="yhbh" column="YHBH"/>
        <result property="yhxm" column="YHXM"/>
        <result property="yhdz" column="YHDZ"/>
        <result property="ysxzMc" column="YSXZ_MC"/>
        <result property="jhrq" column="JHRQ"/>
        <result property="cbrq" column="CBRQ"/>
        <result property="cbStatus" column="CBSTATUS"/>
        <result property="readNum" column="READNUM"/>
        <result property="firstCb" column="FIRSTCB"/>
        <result property="lastCb" column="LASTCB"/>
        <result property="scds" column="SCDS"/>
        <result property="bcds" column="BCDS"/>
        <result property="cbsl" column="CBSL"/>
        <result property="isSyn" column="ISSYN"/>
        <result property="cbbz" column="CBBZ"/>
        <result property="shbz" column="SHBZ"/>
        <result property="sxjmessage" column="SXJMESSAGE"/>
        <association property="cbfsName" column="CBFS_CODE"
                     select="com.tofly.watermeter.mapper.BwrksbdatailMapper.getCodeById"/>
        <association property="sbkj" column="SBKJ"
                     select="com.tofly.watermeter.mapper.BwrksbdatailMapper.getCodeById"/>
        <association property="cbqyName" column="CBRY"
                     select="com.tofly.baseapi.mapper.ToflyCodeCommonMapper.getUserName"/>
    </resultMap>

    <select id="getReadQuery" resultMap="statisticsMap">
        select b.YHBH , b.YHXM , b.YHDZ , b.SCDS , nvl(b.BCDS , 0) BCDS , nvl(b.CBSL , 0 ) CBSL , c.CBRY , b.CBFS_CODE ,
        b.SXJMESSAGE ,
        decode(b.CBBZ , '0','未抄表','1','已抄表') CBBZ , decode(b.SHBZ , '0','未审核','1','已审核','','') SHBZ,
        decode(b.ISSYN , '0','未同步','1','已同步') ISSYN
        from TF_YWPN_YHBINGQY_W a LEFT JOIN TF_YWPN_QFCBQFMXLS_W b ON a.YHBH = b.YHBH
        LEFT JOIN TF_YWPN_CBQYDBM_W c ON c.QYDBM = a.QYDBM
        <where>
            <!--IS_GENERAL = #{search.isGeneral}-->
            <if test="cwyf != null and cwyf != '' ">
                AND b.CBYF = #{cwyf}
            </if>
            <if test="qybm != null and qybm != '' ">
                AND a.QYBM = #{qybm}
            </if>
            <if test="qydbm != null and qydbm != '' ">
                AND a.QYDBM = #{qydbm}
            </if>
            <if test="cb != null and cb != ''">
                AND b.CBBZ = #{cb}
            </if>
            <if test="audit != null and audit != ''">
                AND b.SHBZ = #{audit}
            </if>
            <if test="input != null and input != ''">
                AND b.YHBH || b.YHDZ || b.YHXM LIKE '%' ||#{input , jdbcType=VARCHAR} || '%'
            </if>
        </where>
        ORDER BY b.CBRQ
    </select>

    <select id="getCustomerInfo" resultType="map" databaseId="oracle">
        select SBBH,
               q.YHBH,
               YHXM,
               YHDZ,
               LXDH,
               CBPQ,
               CBB,
               X,
               Y,
               (select PQMC from TF_YWPN_QFCBCBPQ_W where PQBM = CBPQ)   cbpq_name
        from TF_YWPN_QFKHJBXX_W q
                 left join TF_YWPN_WATERMETER_W w on q.YHBH = w.YHBH
        where q.YHBH || YHXM || YHDZ like '%' || #{code} || '%'
    </select>


</mapper>
