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

<!--    <select id="getEventQuery" resultType="hashmap">
        select yh.YHBH as yhbh,yh.YHXM as yhxm
             ,nvl((select count(*) from TF_YWPN_GDINFO_W gd where gd.KHBH = yh.YHBH
                and to_char(gd.CREATE_TIME,'yyyy-mm') between #{startDate} AND #{endDate} ),0) as gdsl
             ,nvl((select count(*) from TF_YWPN_QFCBQFMXLS_W cb where cb.YHBH = yh.YHBH
                and to_char(cb.CBRQ,'yyyy-mm') between #{startDate} AND #{endDate} ),0) as cbsl
             ,nvl((select count(*) from TF_YWPN_ZLZG_W zj left join TF_YWPN_ZLRZ_W rz on zj.CERTIFICATION_NUMBER = rz.CERTIFICATION_NUMBER
                where zj.CLIENT_NUMBER = yh.YHBH and to_char(rz.DISPATCH_TIME,'yyyy-mm') between #{startDate} AND #{endDate} ),0) as zjsl
        from TF_YWPN_QFKHJBXX_W yh
        where yh.YHBH like '%'||#{queryCode}||'%' or yh.YHXM like '%'||#{queryCode}||'%'
        group by yh.YHBH,yh.YHXM
       </select>-->

<!--    <select id="getEventQuery" resultType="hashmap">
        select nvl(count(*),0) cbsl,
               nvl((select count(*) from TF_YWPN_GDINFO_W where KHBH = #{yhbh}
                           and to_char(GDDJ_FSSJ,'yyyy-mm') between #{yhbh} AND #{endDate}),0) gdsl,
               nvl((select count(*) from TF_YWPN_ZLZG_W zj left join TF_YWPN_ZLRZ_W rz on zj.CERTIFICATION_NUMBER = rz.CERTIFICATION_NUMBER
                    where zj.CLIENT_NUMBER = #{yhbh} and to_char(rz.DISPATCH_TIME,'yyyy-mm')  between #{yhbh} AND #{endDate}),0) as zjsl
        from TF_YWPN_QFCBQFMXLS_W where YHBH = #{yhbh}
            and to_char(CBRQ,'yyyy-mm') between #{startDate} AND #{endDate}
        group by YHBH
    </select>-->

    <!--
    6.23 数据库抄表调整 调整语句
    -->
    <select id="getEventQuery" resultType="hashmap">
        select nvl(count(*),0) cbsl,
               nvl((select count(*) from TF_YWPN_GDINFO_W where KHBH = #{yhbh}
                           and to_char(GDDJ_FSSJ,'yyyy-mm') between #{startDate} AND #{endDate}),0) gdsl,
               nvl((select count(*) from TF_YWPN_ZLZG_W zj left join TF_YWPN_ZLRZ_W rz on zj.CERTIFICATION_NUMBER = rz.CERTIFICATION_NUMBER
                           where zj.CLIENT_NUMBER = #{yhbh} and to_char(rz.DISPATCH_TIME,'yyyy-mm')  between #{startDate} AND #{endDate}),0) as zjsl
        from TF_YWPN_QFCBYWLS_W where YHBH = #{yhbh}
               and to_char(CBRQ,'yyyy-mm') between #{startDate} AND #{endDate}
        group by YHBH
    </select>

    <select id="getHouseholdsQuery" resultType="string" >
        select gl.YHBH yhbh from TF_YWPN_YHBINGQY_W gl LEFT JOIN TF_YWPN_QFKHJBXX_W cb ON cb.YHBH = gl.YHBH
        where 1 = 1
        <include refid="querySql" />
    </select>

    <!--  TF_YWPN_QFKHJBXX_W 客户档案信息表 -->
    <select id="getHouseholdsQueryDetail" resultType="hashmap" >
        select cb.*,d.qydmc,b.QYMC from TF_YWPN_YHBINGQY_W gl LEFT JOIN TF_YWPN_QFKHJBXX_W cb ON cb.YHBH = gl.YHBH
        LEFT JOIN TF_YWPN_CBQYDBM_W d on (gl.QYDBM = d.QYDBM)
        LEFT JOIN TF_YWPN_CBQYBM_W b on (gl.QYBM = b.QYBM)
        where 1 = 1
        <include refid="querySql" />
    </select>

    <sql id="querySql" >
        <if test="parseObject.qybm != null and parseObject.qybm != '' ">
            and gl.QYBM = #{parseObject.qybm}
        </if>
        <if test="parseObject.qydbm != null and parseObject.qydbm != '' ">
            and gl.QYDBM = #{parseObject.qydbm}
        </if>
        <if test="parseObject.sbkj != null and parseObject.sbkj != '' ">
            and cb.sbkj = #{parseObject.sbkj}
        </if>
        <if test="parseObject.ysxz != null and parseObject.ysxz != '' ">
            and cb.YSXZ = #{parseObject.ysxz}
        </if>
        <if test="parseObject.sbcj != null and parseObject.sbcj != '' ">
            and cb.SBCJ = #{parseObject.sbcj}
        </if>
    </sql>

    <!-- TF_YWPN_QFCBYWLS_W 抄表数据总表 （TF_YWPN_QFCBQFMXLS_W）仅为普表 -->
    <select id="getCBEvent" resultType="hashmap">
        select * from TF_YWPN_QFCBYWLS_W
        where YHBH = #{khbh} and to_char(CBRQ,'yyyy-mm') between #{startDate} AND #{endDate}
    </select>

    <select id="getGDEvent" resultType="hashmap">
        select * from TF_YWPN_GDINFO_W
        where KHBH = #{khbh} and to_char(GDDJ_FSSJ,'yyyy-mm') between #{startDate} AND #{endDate}
    </select>

    <select id="getZJEvent" resultType="hashmap">
        select zg.* from TF_YWPN_ZLZG_W zg left join TF_YWPN_ZLRZ_W rz on zg.CERTIFICATION_NUMBER = rz.CERTIFICATION_NUMBER
        where zg.CLIENT_NUMBER = #{khbh} and to_char(rz.DISPATCH_TIME,'yyyy-mm') between #{startDate} AND #{endDate}
    </select>

</mapper>
