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

    <resultMap id="qfkhjbxxMap" type="com.tofly.watermeter.entity.Qfkhjbxx">
        <result property="userId" column="USER_ID"/>
        <result property="accountId" column="ACCOUNT_ID"/>
        <result property="yhbh" column="YHBH"/>
        <result property="yhxm" column="YHXM"/>
        <result property="yhdz" column="YHDZ"/>
        <result property="lxdh" column="LXDH"/>
        <result property="lxry" column="LXRY"/>
        <result property="lxsj" column="LXSJ"/>
        <result property="yyqy" column="YYQY"/>
        <result property="cbpq" column="CBPQ"/>
        <result property="cbb" column="CBB"/>
        <result property="yhzt" column="YHZT"/>
        <result property="jfzh" column="JFZH"/>
        <result property="zhzt" column="ZHZT"/>
        <result property="zhye" column="ZHYE"/>
        <result property="gsht" column="GSHT"/>
        <result property="ysxz" column="YSXZ"/>
        <result property="xzxf" column="XZXF"/>
        <result property="sbyt" column="SBYT"/>
        <result property="sfjt" column="SFJT"/>
        <result property="sfjl" column="SFJL"/>
        <result property="sfjf" column="SFJF"/>
        <result property="zbry" column="ZBRY"/>
        <result property="sbbw" column="SBBW"/>
        <result property="sfYsdh" column="SF_YSDH"/>
        <result property="cbzq" column="CBZQ"/>
        <result property="yjfr" column="YJFR"/>
        <result property="xzlx" column="XZLX"/>
        <result property="sfDwyh" column="SF_DWYH"/>
        <result property="sfKzzs" column="SF_KZZS"/>
        <result property="khrq" column="KHRQ"/>
        <result property="sfTsyh" column="SF_TSYH"/>
        <result property="tsdw" column="TSDW"/>
        <result property="gsHtzt" column="GS_HTZT"/>
        <result property="sbbh" column="SBBH"/>
        <result property="sbcj" column="SBCJ"/>
        <result property="sblx" column="SBLX"/>
        <result property="sbdd" column="SBDD"/>
        <result property="sbkj" column="SBKJ"/>
        <result property="azfs" column="AZFS"/>
        <result property="azrq" column="AZRQ"/>
        <result property="zhHbrq" column="ZH_HBRQ"/>
        <result property="jdrq" column="JDRQ"/>
        <result property="zhXgrq" column="ZH_XGRQ"/>
        <result property="yhbs" column="YHBS"/>
        <result property="bcZjrq" column="BC_ZJRQ"/>
        <result property="xcZjrq" column="XC_ZJRQ"/>
        <result property="cbpqName" column="QYMC"/>
        <result property="cbbName" column="QYDMC"/>
        <result property="village" column="VILLAGE"/>
        <result property="issum" column="ISSUM"/>
        <result property="rfid" column="RFID"/>
        <result property="scds" column="SCDS"/>
        <result property="sfqf" column="SFQF"/>
        <result property="qfje" column="QFJE"/>
        <result property="qfzq" column="QFZQ"/>
        <result property="clientBz" column="CLIENT_BZ"/>
        <result property="qymc" column="QYMC"/>
        <result property="qydmc" column="QYDMC"/>
        <result property="month1" column="MONTH1"/>
        <result property="month2" column="MONTH2"/>
        <result property="month3" column="MONTH3"/>
        <result property="yearonyear1" column="YEARONYEAR1"/>
        <result property="yearonyear2" column="YEARONYEAR2"/>
        <result property="yearonyear3" column="YEARONYEAR3"/>
        <result property="cbsl" column="CBSL"/>
        <result property="cbry" column="CBRY"/>
        <result property="cbxh" column="CBXH"/>
        <result property="isfp" column="ISFP"/>
        <result property="sfncys" column="SFNCYS"/>
        <result property="jyz" column="JYZ"/>
        <result property="sbkh" column="SBKH"/>
        <result property="sbwz" column="SBWZ"/>
        <result property="cby" column="CBY"/>
        <result property="tsdh" column="TSDH"/>
        <association property="yhztName" column="YHZT"
                     select="getYhztName"/>
        <association property="sbcjName" column="SBCJ"
                     select="com.tofly.watermeter.mapper.QfkhjbxxMapper.getCjByCode"/>
        <association property="sbkjName" column="SBKJ"
                     select="com.tofly.watermeter.mapper.QfkhjbxxMapper.getKjByCode"/>
        <association property="sblxName" column="SBLX"
                     select="com.tofly.watermeter.mapper.QfkhjbxxMapper.getLxByCode"/>
        <association property="ysxzName" column="YSXZ"
                     select="getYsxzName"/>
        <association property="cbbName" column="CBB"
                     select="getcbbName"/>
        <association property="cbpqName" column="CBPQ"
                     select="getcbpqName"/>
    </resultMap>

    <select id="getYhztName" resultType="string">
        select decode(#{yhzt}, 0, '未启用', 1, '正常', 2, '报停', 3, '停水', 4, '锁定', 5, '关阀', 9, '销户')
        from dual
    </select>

    <select id="getcbpqName" resultType="string">
        select PQMC
        from TF_YWPN_QFCBCBPQ_W
        where PQBM = #{cbpq}
    </select>

    <select id="getcbbName" resultType="string">
        select CBB_MC
        from TF_YWPN_DMACISCBB_W
        where CBB_BM = #{cbb}
    </select>

    <select id="getYsxzName" resultType="string">
        select YSXZ_MC
        from TF_YWPN_QFMIDYSXZBM_E
        where YSXZ_BM = #{ysxz}
    </select>

    <update id="updateKh">
        <foreach collection="khList" open="begin" close=";end;" item="kh" separator=";">
            update TF_YWPN_QFKHJBXX_W
            <set>
                <if test="kh.yhxm!= null">
                    YHXM = #{kh.yhxm} ,
                </if>
                <if test="kh.yhdz!= null">
                    YHDZ = #{kh.yhdz} ,
                </if>
                <if test="kh.lxdh!= null">
                    LXDH = #{kh.lxdh} ,
                </if>
                <if test="kh.lxry!= null">
                    LXRY = #{kh.lxry} ,
                </if>
                <if test="kh.lxsj!= null">
                    LXSJ = #{kh.lxsj} ,
                </if>
                <if test="kh.yyqy!= null">
                    YYQY = #{kh.yyqy} ,
                </if>
                <if test="kh.cbpq!= null">
                    CBPQ = #{kh.cbpq} ,
                </if>
                <if test="kh.cbb!= null">
                    CBB = #{kh.cbb} ,
                </if>
                <if test="kh.yhzt!= null">
                    YHZT = #{kh.yhzt} ,
                </if>
                <if test="kh.jfzh!= null">
                    JFZH = #{kh.jfzh} ,
                </if>
                <if test="kh.zhzt!= null">
                    ZHZT = #{kh.zhzt} ,
                </if>
                <if test="kh.zhye!= null">
                    ZHYE = #{kh.zhye} ,
                </if>
                <if test="kh.gsht!= null">
                    GSHT = #{kh.gsht} ,
                </if>
                <if test="kh.ysxz!= null">
                    YSXZ = #{kh.ysxz} ,
                </if>
                <if test="kh.xzxf!= null">
                    XZXF = #{kh.xzxf} ,
                </if>
                <if test="kh.sbyt!= null">
                    SBYT = #{kh.sbyt} ,
                </if>
                <if test="kh.sfjt!= null">
                    SFJT = #{kh.sfjt} ,
                </if>
                <if test="kh.sfjl!= null">
                    SFJL = #{kh.sfjl} ,
                </if>
                <if test="kh.sfjf!= null">
                    SFJF = #{kh.sfjf} ,
                </if>
                <if test="kh.zbry!= null">
                    ZBRY = #{kh.zbry} ,
                </if>
                <if test="kh.sbbw!= null">
                    SBBW = #{kh.sbbw} ,
                </if>
                <if test="kh.sfYsdh!= null">
                    SF_YSDH = #{kh.sfYsdh} ,
                </if>
                <if test="kh.cbzq!= null">
                    CBZQ = #{kh.cbzq},
                </if>
                <if test="kh.yjfr!= null">
                    YJFR = #{kh.yjfr},
                </if>
                <if test="kh.xzlx!= null">
                    XZLX = #{kh.xzlx},
                </if>
                <if test="kh.sfDwyh!= null">
                    SF_DWYH = #{kh.sfDwyh},
                </if>
                <if test="kh.sfKzzs!= null">
                    SF_KZZS = #{kh.sfKzzs},
                </if>
                <if test="kh.khrq!= null">
                    KHRQ = #{kh.khrq} ,
                </if>
                <if test="kh.sfTsyh!= null">
                    SF_TSYH = #{kh.sfTsyh},
                </if>
                <if test="kh.tsdw!= null">
                    TSDW = #{kh.tsdw} ,
                </if>
                <if test="kh.gsHtzt!= null">
                    GS_HTZT = #{kh.gsHtzt},
                </if>
                <if test="kh.scds!= null">
                    SCDS = #{kh.scds},
                </if>
                <if test="kh.sfqf!= null and kh.sfqf.trim() !=''">
                    SFQF = #{kh.sfqf},
                </if>
                <if test="kh.qfzq!= null and kh.qfzq.trim() !=''">
                    QFZQ = #{kh.qfzq},
                </if>
                <if test="kh.qfje!= null">
                    QFJE = #{kh.qfje}
                </if>
            </set>
            where YHBH = #{kh.yhbh}
        </foreach>

    </update>


    <!--    <select id="getIdByCjCode" resultType="long">-->
    <!--        SELECT ID-->
    <!--        FROM TF_YWPN_SYSCHILDCODE_D-->
    <!--        WHERE PCID = 2-->
    <!--          AND CCODE = #{cjCode}-->
    <!--    </select>-->
    <!--    <select id="getIdByLxCode" resultType="long">-->
    <!--        SELECT ID-->
    <!--        FROM TF_YWPN_SYSCHILDCODE_D-->
    <!--        WHERE PCID = 3-->
    <!--          AND CCODE = #{lxCode}-->
    <!--    </select>-->
    <!--    <select id="getIdByKjCode" resultType="long">-->
    <!--        SELECT ID-->
    <!--        FROM TF_YWPN_SYSCHILDCODE_D-->
    <!--        WHERE PCID = 1-->
    <!--          AND CCODE = #{kjCode}-->
    <!--    </select>-->

    <select id="getCjByCode" resultType="string">
        SELECT SBCJ_MC
        FROM TF_YWPN_DMACISSBCJ_W
        WHERE YXBZ = 1
          AND SBCJ_BM = #{sbcj}
    </select>
    <select id="getKjByCode" resultType="string">
        SELECT CNAME
        FROM TF_YWPN_SYSCHILDCODE_D
        WHERE PCID = 1
          AND CCODE = to_char(#{sbkj})
    </select>
    <select id="getLxByCode" resultType="string">
        SELECT CNAME
        FROM TF_YWPN_SYSCHILDCODE_D
        WHERE PCID = 3
          AND CCODE = to_char(#{sblx})
    </select>
    <select id="getCodeById" resultType="string">
        SELECT CCODE
        FROM TF_YWPN_SYSCHILDCODE_D
        WHERE ID = #{id}
    </select>


    <select id="getCodeByFids" resultType="java.util.Map">
        SELECT ID, CCODE, CNAME
        FROM TF_YWPN_SYSCHILDCODE_D
        WHERE PCID IN (1, 2, 3)
    </select>

    <select id="getIdByFid" resultType="java.util.Map">
        SELECT ID, CCODE
        FROM TF_YWPN_SYSCHILDCODE_D
        WHERE PCID = #{fid}
    </select>

    <select id="getUserInfo" resultType="map" fetchSize="10000" databaseId="oracle">
        select distinct SBKH,
                        m.YHBH,
                        (select nvl(BCDS, 0)
                         from TF_YWPN_READMETERHIS_W
                         where yhbh = m.YHBH
                           and to_char(add_months(sysdate, -1), 'yyyymm') = MONTH_PLAN) scds
        from TF_YWPN_READMETERHIS_W m
                 left join TF_YWPN_QFKHJBXX_W q on m.YHBH = q.YHBH
        where CBRY = #{userId}
          and month_plan = to_char(sysdate, 'yyyymm')
    </select>

    <select id="getWaterValue" resultType="double">
        select *
        from (select BCDS, ROWNUM num
              from TF_YWPN_READMETERHIS_W
              where YHBH = #{khbh}
              order by cbyf)
        where num = 2

    </select>

    <select id="getZjData" resultMap="qfkhjbxxMap">
        SELECT YHBH,
               YHXM,
               YHDZ,
               LXDH,
               CBPQ,
               XC_ZJRQ,
               SBBH,
               SBCJ,
               SBLX,
               SBKJ,
               AZRQ
        FROM TF_YWPN_QFKHJBXX_W
        WHERE TO_CHAR(XC_ZJRQ) = #{month}
    </select>

    <select id="ztName" resultType="string">
        select decode(#{zt}, '0', '否', '1', '是')
        from dual
    </select>

    <resultMap id="getLisrKhMap" type="map" extends="qfkhjbxxMap">
        <!--        <association property="sfjfName" column="SFJF" select="ztName"/>-->
        <!--        <association property="sfjlName" column="SFJL" select="ztName"/>-->
        <!--        <association property="sfjfName" column="SFJF" select="ztName"/>-->
        <!--        <association property="ysdhName" column="SF_YSDH" select="ztName"/>-->
        <!--        <association property="cbzqName" column="CBZQ" select="cbzqName"/>-->
    </resultMap>

    <select id="getLisrKh" resultMap="qfkhjbxxMap">
        select *
        from TF_YWPN_QFKHJBXX_W
        where YHBH = #{input}
           or YHXM = #{input}
    </select>

    <delete id="deleteAll">
        DELETE
            TF_YWPN_QFKHJBXX_W
    </delete>

    <resultMap id="khInfoByJbbh" type="com.tofly.watermeter.entity.Qfkhjbxx">
        <result property="yhbh" column="YHBH"/>
        <result property="yhxm" column="YHXM"/>
        <result property="yhdz" column="YHDZ"/>
        <result property="lxdh" column="LXDH"/>
        <result property="cbpq" column="CBPQ"/>
        <result property="sbbh" column="SBBH"/>
        <result property="sbcj" column="SBCJ"/>
        <result property="sblx" column="SBLX"/>
        <result property="sbkj" column="SBKJ"/>
        <result property="azrq" column="AZRQ"/>
    </resultMap>

    <select id="getIdByCode" resultType="long">
        SELECT ID
        FROM TF_YWPN_SYSCHILDCODE_D
        WHERE PCID = #{pcid}
          AND CCODE = to_char(#{code})
    </select>

    <select id="getKhInfoByJbbh" resultMap="khInfoByJbbh">
        SELECT YHBH,
               YHXM,
               YHDZ,
               LXDH,
               CBPQ,
               SBCJ,
               SBKJ,
               SBLX,
               AZRQ,
               SBBH
        FROM TF_YWPN_QFKHJBXX_W
        WHERE YHBH = #{yhbh}
    </select>


    <update id="updateBatchCustom">
        <foreach collection="list" open="begin" close=";end;" item="ins" separator=";">
            update TF_YWPN_QFKHJBXX_W
            <set>
                SBBH = #{ins.SBBH},
                <if test="ins.SBCJ != null">
                    SBCJ = #{ins.SBCJ},
                </if>
                <if test="ins.SBKJ != null">
                    SBKJ = #{ins.SBKJ},
                </if>
                <if test="ins.SBLX != null">
                    SBLX = #{ins.SBLX},
                </if>
                <if test="ins.xcZjrq != null">
                    XC_ZJRQ = #{ins.xcZjrq},
                </if>
                <if test="ins.xcZjrq == null">
                    XC_ZJRQ = '' ,
                </if>
                SBDD = 0 ,
                AZRQ = #{ins.azrqTime},
                BC_ZJRQ = #{ins.azrqTime},
                ZBRY = #{ins.AZRY}
            </set>
            where yhbh = #{ins.YHBH}
        </foreach>
    </update>


    <select id="getKhLike" resultMap="qfkhjbxxMap">
        SELECT k.yhbh,
        k.yhxm,
        k.SBWZ sbxh,
        k.yhdz,
        k.lxdh,
        k.lxry,
        k.lxsj,
        k.yyqy,
        k.cbpq,
        k.cbb,
        k.yhzt,
        k.jfzh,
        k.zhzt,
        k.zhye,
        k.gsht,
        k.ysxz,
        k.xzxf,
        k.sbyt,
        k.sfjt,
        k.sfjl,
        k.sfjf,
        k.zbry,
        k.sbbw,
        k.sf_ysdh,
        k.cbzq,
        k.yjfr,
        k.xzlx,
        k.sf_dwyh,
        k.sf_kzzs,
        k.khrq,
        k.sf_tsyh,
        k.tsdw,
        k.gs_htzt,
        k.sbbh,
        k.sbcj,
        k.sblx,
        k.sbdd,
        k.sbkj,
        k.azfs,
        k.azrq,
        k.zh_hbrq,
        k.jdrq,
        k.zh_xgrq,
        k.yhbs,
        k.gjbh,
        k.bc_zjrq,
        k.xc_zjrq,
        k.issyn,
        k.sxjmessage,
        k.scds,
        k.sfqf,
        k.qfje,
        k.qfzq,
        k.sfncys,
        k.jyz,
        k.sbkh,
        d.QYMC,
        e.RFID,
        e.VILLAGE,
        f.CLIENT_BZ,
        DECODE(e.ISSUM, 1, 1, 0, 0, 0) ISSUM
        FROM TF_YWPN_QFKHJBXX_W k LEFT JOIN
        TF_YWPN_YHBINGQY_W a ON k.YHBH = a.YHBH
        LEFT JOIN TF_YWPN_CBQYDBM_W c ON c.QYDBM = a.QYDBM
        LEFT JOIN TF_YWPN_CBQYBM_W d ON c.QYBM = d.QYBM
        LEFT JOIN TF_YWPN_WATERMETER_W e ON k.SBBH = e.SID
        left join TF_YWPN_YHFOREVERINFO_W f on k.YHBH = f.YHBH
        <where>
            <if test="inputcontent ==null">
                <if test="phone != null">
                    AND k.LXSJ LIKE '%' || #{phone} || '%'
                </if>
                <if test="yhbh != null">
                    AND k.YHBH LIKE '%' || #{yhbh} || '%'
                </if>
                <if test="yhxm != null">
                    AND k.YHXM LIKE '%' || #{yhxm} || '%'
                </if>
            </if>
            <if test="inputcontent != null and inputcontent != '' ">
                AND k.YHBH || k.YHXM || k.SBWZ || k.LXDH || k.LXSJ || k.SBBH LIKE '%' || #{inputcontent} || '%'
            </if>
        </where>
    </select>

    <update id="updateYhWaterVolumeInfos">
        <foreach collection="list" open="begin" close=";end;" item="item" separator=";">
            update TF_YWPN_QFKHJBXX_W
            <set>
                <if test="item.scds!= null">
                    SCDS = #{item.scds},
                </if>
                <if test="item.sfqf!= null and item.sfqf.trim() !=''">
                    SFQF = #{item.sfqf},
                </if>
                <if test="item.qfzq!= null and item.qfzq.trim() !=''">
                    QFZQ = #{item.qfzq},
                </if>
                <if test="item.qfje!= null">
                    QFJE = #{item.qfje},
                </if>
                <if test="item.zhye!= null">
                    ZHYE = #{item.zhye},
                </if>
            </set>
            where YHBH = #{item.yhbh}
        </foreach>
    </update>

    <resultMap id="householdsCollectMap" type="com.tofly.watermeter.custom.entity.quality.QualityHouse">
        <result property="cbqy" column="QYBM"/>
        <result property="cbqyName" column="QYMC"/>
        <result property="cbqyd" column="QYDBM"/>
        <result property="cbqydName" column="QYDMC"/>
        <result property="sbkj" column="SBKJ"/>
        <result property="ysxz" column="YSXZ"/>
        <result property="sbcj" column="SBCJ"/>
        <result property="collectNum" column="COLLECT_NUM"/>
        <association property="sbkjName" column="SBKJ"
                     select="getKjByCode"/>
        <association property="ysxzName" column="YSXZ"
                     select="getYsxzName"/>
        <association property="sbcjName" column="SBCJ"
                     select="getCjByCode"/>
    </resultMap>

    <select id="householdsCollect" resultMap="householdsCollectMap">
        select
        <if test="cbqyList != null">
            a.QYBM , b.QYMC
        </if>
        <if test="cbqydList != null">
            <if test="cbqyList != null">
                ,
            </if>
            a.QYDBM , c.QYDMC
        </if>
        <if test="sbkjList != null">
            <if test="cbqyList != null or cbqydList != null">
                ,
            </if>
            d.SBKJ
        </if>
        <if test="ysxzList != null">
            <if test="cbqyList != null or cbqydList != null or sbkjList != null">
                ,
            </if>
            d.YSXZ
        </if>
        <if test="sbcjList != null">
            <if test="cbqyList != null or cbqydList != null or sbkjList != null or ysxzList != null">
                ,
            </if>
            d.SBCJ
        </if>
        , count(1) as COLLECT_NUM
        from
        TF_YWPN_YHBINGQY_W a
        LEFT JOIN TF_YWPN_CBQYBM_W b ON a.QYBM = b.QYBM
        LEFT JOIN TF_YWPN_CBQYDBM_W c ON a.QYDBM = c.QYDBM
        LEFT JOIN TF_YWPN_QFKHJBXX_W d ON a.YHBH = d.YHBH
        <where>
            <if test="cbqyList != null">
                AND a.QYBM IN
                <foreach collection="cbqyList" open="(" item="cbqy" separator="," close=")">
                    #{cbqy}
                </foreach>
            </if>
            <if test="cbqydList != null">
                AND a.QYDBM IN
                <foreach collection="cbqydList" open="(" item="cbqyd" separator="," close=")">
                    #{cbqyd}
                </foreach>
            </if>
            <if test="sbkjList != null">
                AND d.SBKJ IN
                <foreach collection="sbkjList" open="(" item="sbkj" separator="," close=")">
                    #{sbkj}
                </foreach>
            </if>
            <if test="ysxzList != null">
                AND d.YSXZ IN
                <foreach collection="ysxzList" open="(" item="ysxz" separator="," close=")">
                    #{ysxz}
                </foreach>
            </if>
            <if test="sbcjList != null">
                AND d.SBCJ IN
                <foreach collection="sbcjList" open="(" item="sbcj" separator="," close=")">
                    #{sbcj}
                </foreach>
            </if>
        </where>
        group by
        <!--根据查询内容分组并求数量-->
        <if test="cbqyList != null">
            a.QYBM , b.QYMC
        </if>
        <if test="cbqydList != null">
            <if test="cbqyList != null">
                ,
            </if>
            a.QYDBM , c.QYDMC
        </if>
        <if test="sbkjList != null">
            <if test="cbqyList != null or cbqydList != null">
                ,
            </if>
            d.SBKJ
        </if>
        <if test="ysxzList != null">
            <if test="cbqyList != null or cbqydList != null or sbkjList != null">
                ,
            </if>
            d.YSXZ
        </if>
        <if test="sbcjList != null">
            <if test="cbqyList != null or cbqydList != null or sbkjList != null or ysxzList != null">
                ,
            </if>
            d.SBCJ
        </if>
    </select>
    <select id="householdsCollectDeatil" resultMap="qfkhjbxxMap">
        select a.QYBM , b.QYMC , a.QYDBM , c.QYDMC , d.* from
        TF_YWPN_YHBINGQY_W a
        LEFT JOIN TF_YWPN_CBQYBM_W b ON a.QYBM = b.QYBM
        LEFT JOIN TF_YWPN_CBQYDBM_W c ON a.QYDBM = c.QYDBM
        LEFT JOIN TF_YWPN_QFKHJBXX_W d ON a.YHBH = d.YHBH
        <where>
            <if test="inputcontent != null and inputcontent != ''">
                AND (d.YHBH LIKE '%' || #{inputcontent} || '%' OR
                d.YHXM LIKE '%' || #{inputcontent} || '%' OR
                d.YHDZ LIKE '%' || #{inputcontent} || '%' OR
                d.LXDH LIKE '%' || #{inputcontent} || '%' OR
                d.LXSJ LIKE '%' || #{inputcontent} || '%')
            </if>
            <if test="cbqyList != null">
                AND a.QYBM IN
                <foreach collection="cbqyList" open="(" item="cbqy" separator="," close=")">
                    #{cbqy}
                </foreach>
            </if>
            <if test="cbqydList != null">
                AND a.QYDBM IN
                <foreach collection="cbqydList" open="(" item="cbqyd" separator="," close=")">
                    #{cbqyd}
                </foreach>
            </if>
            <if test="sbkjList != null">
                AND d.SBKJ IN
                <foreach collection="sbkjList" open="(" item="sbkj" separator="," close=")">
                    #{sbkj}
                </foreach>
            </if>
            <if test="ysxzList != null">
                AND d.YSXZ IN
                <foreach collection="ysxzList" open="(" item="ysxz" separator="," close=")">
                    #{ysxz}
                </foreach>
            </if>
            <if test="sbcjList != null">
                AND d.SBCJ IN
                <foreach collection="sbcjList" open="(" item="sbcj" separator="," close=")">
                    #{sbcj}
                </foreach>
            </if>
        </where>
        order by b.QYMC , c.QYDMC
    </select>

    <select id="commonKh" resultMap="qfkhjbxxMap">
        select distinct a.QYBM , b.QYMC , a.QYDBM , c.QYDMC ,
        (case when a.QYDBM is not null then '已分配' else '未分配' end) as ISFP ,
        d.* from
        TF_YWPN_QFKHJBXX_W d
        LEFT JOIN TF_YWPN_YHBINGQY_W a ON d.YHBH = a.YHBH
        LEFT JOIN TF_YWPN_CBQYBM_W b ON a.QYBM = b.QYBM
        LEFT JOIN TF_YWPN_CBQYDBM_W c ON a.QYDBM = c.QYDBM
        <where>
            <if test="khSearch.sblx != null and khSearch.sblx != ''">
                and d.SBLX like '%' || #{khSearch.sblx} || '%'
            </if>
            <if test="ysxzList != null">
                and YSXZ in
                <foreach collection="ysxzList" item="ysxz" open="(" separator="," close=")">
                    #{ysxz}
                </foreach>
            </if>
            <if test="khSearch.fpState == 0">
                and a.yhbh is null
            </if>
            <if test="khSearch.fpState == 1">
                and a.yhbh is not null
            </if>
            <if test="cbbList != null">
                AND d.CBB IN
                <foreach collection="cbbList" open="(" item="cbb" separator="," close=")">
                    #{cbb}
                </foreach>
            </if>
            <if test="yhztList != null">
                AND d.yhzt IN
                <foreach collection="yhztList" open="(" item="yhzt" separator="," close=")">
                    #{yhzt}
                </foreach>
            </if>
            <if test="sbcjList != null">
                AND d.sbcj IN
                <foreach collection="sbcjList" open="(" item="sbcj" separator="," close=")">
                    #{sbcj}
                </foreach>
            </if>
            <if test="khSearch.startTime != null and khSearch.endTime != null">
                AND d.JDRQ BETWEEN #{khSearch.startTime} and #{khSearch.endTime}
            </if>
            <if test="khSearch.startTime != null and khSearch.endTime == null">
                AND d.JDRQ <![CDATA[ >= ]]> #{khSearch.startTime}
            </if>
            <if test="khSearch.startTime == null and khSearch.endTime != null">
                AND d.JDRQ <![CDATA[ <= ]]> #{khSearch.endTime}
            </if>
            <if test="khSearch.phone != null and khSearch.phone != ''">
                AND (d.LXDH LIKE '%' || #{khSearch.phone} || '%' OR
                d.LXSJ LIKE '%' || #{khSearch.phone} || '%')
            </if>
            <if test="khSearch.yhbh != null and khSearch.yhbh != ''">
                AND d.YHBH LIKE '%' || #{khSearch.yhbh} || '%'
            </if>
            <if test="khSearch.yhxm != null and khSearch.yhxm != ''">
                AND d.YHXM LIKE '%' || #{khSearch.yhxm} || '%'
            </if>
            <if test="khSearch.inputcontent != null and khSearch.inputcontent != ''">
                AND (d.YHBH LIKE '%' || #{khSearch.inputcontent} || '%' OR
                d.YHXM LIKE '%' || #{khSearch.inputcontent} || '%' OR
                d.YHDZ LIKE '%' || #{khSearch.inputcontent} || '%' OR
                d.LXDH LIKE '%' || #{khSearch.inputcontent} || '%' OR
                d.LXSJ LIKE '%' || #{khSearch.inputcontent} || '%' or
                d.CLIENT_BZ like '%' || #{khSearch.inputcontent} || '%' )
            </if>
            <if test="cbqyList != null">
                AND a.QYBM IN
                <foreach collection="cbqyList" open="(" item="cbqy" separator="," close=")">
                    #{cbqy}
                </foreach>
            </if>
            <if test="cbqydList != null">
                AND a.QYDBM IN
                <foreach collection="cbqydList" open="(" item="cbqyd" separator="," close=")">
                    #{cbqyd}
                </foreach>
            </if>
        </where>
        order by b.QYMC , c.QYDMC , d.CBXH
    </select>
    <select id="getYhInfoAndCbslInfo" resultType="com.tofly.watermeter.entity.Readmetereashis">
        select a.yhbh , a.yhxm , a.lxdh , a.lxsj , a.ysxz , a.sbbh , a.sbkj , a.yhdz , b.cbsl , b.month1 , b.month2 ,
        b.month3 ,
        b.yearonyear1 , b.yearonyear2 , b.yearonyear3 , b.MONTH_PLAN
        from TF_YWPN_QFKHJBXX_W a left join
        TF_YWPN_READMETERHIS_W b
        on a.yhbh = b.yhbh
        <where>
            b.MONTH_PLAN = #{yearMonth}
            and b.cbbz = '1'
            <if test="yhbhList != null">
                AND a.yhbh in
                <foreach collection="yhbhList" open="(" item="yhbh" separator="," close=")">
                    #{yhbh}
                </foreach>
            </if>
        </where>
    </select>


    <select id="commonKhList" resultMap="qfkhjbxxMap" fetchSize="1000">
        <!--select temp.* from (-->
        select a.QYBM , b.QYMC , a.QYDBM , c.QYDMC , a.CBXH ,
        (case when a.QYDBM is not null then '已分配' else '未分配' end) as ISFP , d.*
        from
        TF_YWPN_QFKHJBXX_W d
        LEFT JOIN TF_YWPN_YHBINGQY_W a ON d.YHBH = a.YHBH
        LEFT JOIN TF_YWPN_CBQYBM_W b ON a.QYBM = b.QYBM
        LEFT JOIN TF_YWPN_CBQYDBM_W c ON a.QYDBM = c.QYDBM
        <!--LEFT JOIN TF_YWPN_READMETERHIS_W e ON d.yhbh = e.yhbh-->
        <where>
            <if test="ysxzList != null">
                and YSXZ in
                <foreach collection="ysxzList" item="ysxz" open="(" separator="," close=")">
                    #{ysxz}
                </foreach>
            </if>
            <if test="khSearch.fpState == 0">
                and a.yhbh is null
            </if>
            <if test="khSearch.fpState == 1">
                and a.yhbh is not null
            </if>
            <if test="cbbList != null">
                AND d.CBB IN
                <foreach collection="cbbList" open="(" item="cbb" separator="," close=")">
                    #{cbb}
                </foreach>
            </if>
            <if test="yhztList != null">
                AND d.yhzt IN
                <foreach collection="yhztList" open="(" item="yhzt" separator="," close=")">
                    #{yhzt}
                </foreach>
            </if>
            <if test="sbcjList != null">
                AND d.sbcj IN
                <foreach collection="sbcjList" open="(" item="sbcj" separator="," close=")">
                    #{sbcj}
                </foreach>
            </if>
            <if test="khSearch.startTime != null and khSearch.endTime != null">
                AND d.JDRQ BETWEEN #{khSearch.startTime} and #{khSearch.endTime}
            </if>
            <if test="khSearch.startTime != null and khSearch.endTime == null">
                AND d.JDRQ <![CDATA[ >= ]]> #{khSearch.startTime}
            </if>
            <if test="khSearch.startTime == null and khSearch.endTime != null">
                AND d.JDRQ <![CDATA[ <= ]]> #{khSearch.endTime}
            </if>
            <if test="khSearch.phone != null and khSearch.phone != ''">
                AND (d.LXDH LIKE '%' || #{khSearch.phone} || '%' OR
                d.LXSJ LIKE '%' || #{khSearch.phone} || '%')
            </if>
            <if test="khSearch.yhbh != null and khSearch.yhbh != ''">
                AND d.YHBH LIKE '%' || #{khSearch.yhbh} || '%'
            </if>
            <if test="khSearch.yhxm != null and khSearch.yhxm != ''">
                AND d.YHXM LIKE '%' || #{khSearch.yhxm} || '%'
            </if>
            <if test="khSearch.inputcontent != null and khSearch.inputcontent != ''">
                AND (d.YHBH LIKE '%' || #{khSearch.inputcontent} || '%' OR
                d.YHXM LIKE '%' || #{khSearch.inputcontent} || '%' OR
                d.YHDZ LIKE '%' || #{khSearch.inputcontent} || '%' OR
                d.LXDH LIKE '%' || #{khSearch.inputcontent} || '%' OR
                d.LXSJ LIKE '%' || #{khSearch.inputcontent} || '%')
            </if>
            <if test="cbqyList != null">
                AND a.QYBM IN
                <foreach collection="cbqyList" open="(" item="cbqy" separator="," close=")">
                    #{cbqy}
                </foreach>
            </if>
            <if test="cbqydList != null">
                AND a.QYDBM IN
                <foreach collection="cbqydList" open="(" item="cbqyd" separator="," close=")">
                    #{cbqyd}
                </foreach>
            </if>
        </where>
        order by b.QYMC , c.QYDMC , a.CBXH
    </select>
    <select id="allotInfo" resultMap="qfkhjbxxMap">
        select a.QYBM , b.QYMC , a.QYDBM , c.QYDMC , a.CBXH , d.yhxm , d.yhbh , d.yhdz , d.CBPQ , d.cbb , d.sbbh ,
        d.sbkj , d.ysxz,decode(SFNCYS,'0','否','1','是') sfncys,JYZ
        from
        TF_YWPN_QFKHJBXX_W d
        LEFT JOIN TF_YWPN_YHBINGQY_W a ON d.YHBH = a.YHBH
        LEFT JOIN TF_YWPN_CBQYBM_W b ON a.QYBM = b.QYBM
        LEFT JOIN TF_YWPN_CBQYDBM_W c ON a.QYDBM = c.QYDBM
        <where>
            <if test="inputcontent != null and inputcontent != ''">
                AND (d.YHBH LIKE '%' || #{inputcontent} || '%' OR
                d.YHXM LIKE '%' || #{inputcontent} || '%' OR
                d.YHDZ LIKE '%' || #{inputcontent} || '%' OR
                d.LXDH LIKE '%' || #{inputcontent} || '%' OR
                d.LXSJ LIKE '%' || #{inputcontent} || '%')
            </if>

            <if test="cbqyList != null">
                AND a.QYBM IN
                <foreach collection="cbqyList" open="(" item="cbqy" separator="," close=")">
                    #{cbqy}
                </foreach>
            </if>
            <if test="cbqydList != null">
                AND a.QYDBM IN
                <foreach collection="cbqydList" open="(" item="cbqyd" separator="," close=")">
                    #{cbqyd}
                </foreach>
            </if>
            <if test="sbkjList != null">
                AND d.sbkj IN
                <foreach collection="sbkjList" open="(" item="sbkj" separator="," close=")">
                    #{sbkj}
                </foreach>
            </if>
            <if test="cbbList != null">
                AND d.CBB IN
                <foreach collection="cbbList" open="(" item="cbb" separator="," close=")">
                    #{cbb}
                </foreach>
            </if>
            <if test="cbpqList != null">
                AND d.CBPQ IN
                <foreach collection="cbpqList" open="(" item="cbpq" separator="," close=")">
                    #{cbpq}
                </foreach>
            </if>
            <if test="ysxzList != null">
                AND d.YSXZ IN
                <foreach collection="ysxzList" open="(" item="ysxz" separator="," close=")">
                    #{ysxz}
                </foreach>
            </if>
            <if test="jyz != null and jyz != ''">
                AND d.JYZ = #{jyz}
            </if>
            <if test="sfncys != null and sfncys != ''">
                AND d.SFNCYS = #{sfncys}
            </if>
            AND
            <if test="isWatchType == 0">
                NOT
            </if>
            EXISTS (SELECT CLIENT_NUMBER from TF_YWPN_GJGLXQ_W where d.yhbh = CLIENT_NUMBER and COLLECTION_NUMBER =
            #{collectionNumber})
        </where>
    </select>

    <select id="getCodeAndWater" resultType="map" fetchSize="10000">
        select q.YHBH, q.SBKH, nvl(r.SCDS, 0) scds
        from TF_YWPN_QFKHJBXX_W q
                 left join TF_YWPN_READMETERHIS_W r
                           on q.YHBH = r.YHBH and MONTH_PLAN = to_char(add_months(sysdate, -1), 'yyyymm')
    </select>

    <select id="getOfflineInfoList" resultType="map" fetchSize="1000" databaseId="oracle">
        SELECT YHBH,
        YHXM,
        YHDZ,
        CBQY_MC qymc,
        BZ,
        (case when DIFF_TIME is not null then floor(DIFF_TIME / 60) || '分' || MOD(DIFF_TIME, 60) || '秒' end )
        diff_time_str,
        to_char(CBRQ,'yyyy-mm-dd hh24:mi:ss') cbrq_str,
        decode(CBBZ,'0','未抄表','1','已抄表') cbbz_name,
        (select CNAME
        from TF_YWPN_SYSCHILDCODE_D
        where ID = CBFS_CODE) cbfs_name,
        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="getCbqdBm" resultType="string">
        select CBQYD_BM
        from TF_YWPN_READMETERHIS_W
        where MONTH_PLAN = #{month}
          and IS_GENERAL = #{isGeneral}
        group by CBQYD_BM
    </select>

</mapper>
