<?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.xrtymis.mapper.GdglinfoMapper">

    <resultMap id="gdglinfoMap" type="com.tofly.xrtymis.entity.Gdglinfo">
        <result property="id" column="ID"/>
        <result property="gdbh" column="GDBH"/>
        <result property="gdly" column="GDLY"/>
        <result property="gdlx" column="GDLX"/>
        <result property="gdxf1" column="GDXF1"/>
        <result property="gdxf2" column="GDXF2"/>
        <result property="gdms" column="GDMS"/>
        <result property="jjcd" column="JJCD"/>
        <result property="lcid" column="LCID"/>
        <result property="ldhm" column="LDHM"/>
        <result property="slbm" column="SLBM"/>
        <result property="slry" column="SLRY"/>
        <result property="jdsx" column="JDSX"/>
        <result property="djry" column="DJRY"/>
        <result property="djsj" column="DJSJ"/>
        <result property="khbh" column="KHBH"/>
        <result property="khxm" column="KHXM"/>
        <result property="khdz" column="KHDZ"/>
        <result property="lxdh" column="LXDH"/>
        <result property="jdzt" column="JDZT"/>
        <result property="gddjZt" column="GDDJ_ZT"/>
        <result property="lcjd" column="LCJD"/>
        <result property="rzFileid" column="RZ_FILEID"/>
        <result property="rzyj" column="RZYJ"/>
        <result property="rzbm" column="RZBM"/>
        <result property="rzsx" column="RZSX"/>
        <result property="rzsj" column="RZSJ"/>
        <result property="rzry" column="RZRY"/>
        <result property="lczt" column="LCZT"/>
        <result property="shyj" column="SHYJ"/>
        <result property="shbm" column="SHBM"/>
        <result property="shry" column="SHRY"/>
        <result property="shsj" column="SHSJ"/>
        <result property="shsx" column="SHSX"/>
        <result property="shzt" column="SHZT"/>
        <result property="zjyj" column="ZJYJ"/>
        <result property="zjbm" column="ZJBM"/>
        <result property="zjry" column="ZJRY"/>
        <result property="zjsj" column="ZJSJ"/>
        <result property="zjsx" column="ZJSX"/>
        <result property="zjzt" column="ZJZT"/>
        <result property="czsx" column="CZSX"/>
        <result property="czyj" column="CZYJ"/>
        <result property="czbm" column="CZBM"/>
        <result property="czry" column="CZRY"/>
        <result property="czsj" column="CZSJ"/>
        <result property="jgczFileid" column="JGCZ_FILEID"/>
        <result property="czzt" column="CZZT"/>
        <result property="gdhfCs" column="GDHF_CS"/>
        <result property="gddjFssj" column="GDDJ_FSSJ"/>
        <result property="rzczFssj" column="RZCZ_FSSJ"/>
        <result property="reshFssj" column="RESH_FSSJ"/>
        <result property="rzzjFssj" column="RZZJ_FSSJ"/>
        <result property="jgczFssj" column="JGCZ_FSSJ"/>
        <result property="rzczCszt" column="RZCZ_CSZT"/>
        <result property="reshCszt" column="RESH_CSZT"/>
        <result property="rzzjCszt" column="RZZJ_CSZT"/>
        <result property="jgczCszt" column="JGCZ_CSZT"/>
        <result property="rzczCssj" column="RZCZ_CSSJ"/>
        <result property="reshCssj" column="RESH_CSSJ"/>
        <result property="rzzjCssj" column="RZZJ_CSSJ"/>
        <result property="jgczCssj" column="JGCZ_CSSJ"/>
        <result property="lczzyy" column="LCZZYY"/>
        <result property="processDeposit" column="PROCESS_DEPOSIT"/>
        <result property="processInfo" column="PROCESS_INFO"/>
        <result property="rzslry" column="RZSLRY"/>
        <result property="shslry" column="SHSLRY"/>
        <result property="zjczry" column="ZJCZRY"/>
        <result property="jdCszt" column="JD_CSZT"/>
        <result property="bhzt" column="BHZT"/>
        <result property="zpzt" column="ZPZT"/>
        <result property="jgczry" column="JGCZRY"/>
        <result property="isRxlx" column="IS_RXLX"/>
        <result property="isQualityFlag" column="IS_QUALITY_FLAG"/>
        <result property="hangUp" column="HANG_UP"/>
        <result property="gddjFileid" column="GDDJ_FILEID"/>
        <result property="isWatermeterStatus" column="IS_WATERMETER_STATUS"/>
        <result property="zzry" column="ZZRY"/>
        <result property="zzsj" column="ZZSJ"/>
        <result property="gdgzlx" column="GDGZLX"/>
        <result property="gdgzyy" column="GDGZYY"/>
        <result property="gzszry" column="GZSZRY"/>
        <result property="sqbm" column="SQBM"/>
        <result property="sqry" column="SQRY"/>
        <result property="gdzzzt" column="GDZZZT"/>
        <result property="gdsx" column="GDSX"/>
        <result property="gdcsFlag" column="GDCS_FLAG"/>
        <result property="jgczPerson" column="JGCZ_PERSON"/>
        <!--        <result property="presentPerson" column="PRESENT_PERSON"/>-->
        <result property="address" column="ADDRESS"/>
        <result property="lgtd" column="LGTD"/>
        <result property="lttd" column="LTTD"/>
        <result property="finishTime" column="FINISH_TIME"/>
        <result property="ysxz" column="YSXZ"/>
        <result property="sbbh" column="SBBH"/>
        <result property="sbkj" column="SBKJ"/>
        <result property="sjdh" column="SJDH"/>
        <result property="shrdj" column="SHRDJ"/>
        <result property="djbm" column="DJBM"/>
        <result property="isLeak" column="IS_LEAK"/>
        <result property="isNoise" column="IS_NOISE"/>
        <result property="isRewardWater" column="IS_REWARD_WATER"/>
        <!--        <result property="rzczsj" column="RZCZSJ"/>-->

        <!--        <association property="gdlyName" column="GDLY" select="gdlyName"/> 汪截流注释：发现与下面这个一模一样的-->
        <association property="gdlxName" column="GDLX" select="gdlxName"/>
        <association property="gdxf1Name" column="GDXF1" select="gdlxName"/>
        <association property="gdxf2Name" column="GDXF2" select="gdlxName"/>
        <association property="jjcdName" column="JJCD" select="jjcdName"/>
        <association property="slbmName" column="SLBM" select="slbmName"/>
        <association property="gddjZtName" column="GDDJ_ZT" select="gddjZtName"/>
        <association property="lcjdName" column="LCJD" select="lcjdName"/>
        <association property="lcztName" column="LCZT" select="lcztName"/>
        <association property="shbmName" column="SHBM" select="shbmName"/>
        <association property="shztName" column="SHZT" select="shztName"/>
        <association property="zjbmName" column="ZJBM" select="zjbmName"/>
        <association property="zjztName" column="ZJZT" select="zjztName"/>
        <association property="czbmName" column="CZBM" select="czbmName"/>
        <association property="czztName" column="CZZT" select="czztName"/>
        <association property="rzbmName" column="RZBM" select="shbmName"/>
        <association property="sqbmName" column="SQBM" select="czbmName"/>
        <association property="gdgzlxName" column="GDGZLX" select="lxName"/>
        <association property="djryDeptName" column="DJRY" select="getDjryDeptName"/>

        <association property="files" column="RZ_FILEID" select="files"/>
        <association property="jgczFile" column="JGCZ_FILEID" select="jgczFile"/>
        <association property="gddjFiles" column="GDDJ_FILEID" select="jgczFile"/>

        <association column="LCID" property="allLcjd" select="getlcjd"/>
        <association column="bhzt" property="bhztName" select="bhztName"/>
        <association column="zpzt" property="zpztName" select="bhztName"/>
        <association column="LCID" property="jgshCcjb" select="getshdj"/>
        <association property="gdflowconfig" column="LCID" select="gdflowconfig" javaType="Gdflowconfig"/>
        <association property="gdcsFlagName" column="GDCS_FLAG" select="getGdcsFlagName"/>
        <association property="gdzzztName" column="GDZZZT" select="getGdzzztName"/>

        <association property="auditHisList" column="ID" select="getAuditHisList"/>

        <association property="jgAuditList" column="ID" select="getJgAuditList"/>

        <association property="shslryName" column="SHSLRY"
                     select="com.tofly.baseapi.mapper.ToflyCodeCommonMapper.getUserName"/>
        <association property="jgczryName" column="JGCZRY"
                     select="com.tofly.baseapi.mapper.ToflyCodeCommonMapper.getUserName"/>
        <association property="slryName" column="SLRY"
                     select="getSlryName"/>
        <association property="djryName" column="DJRY"
                     select="com.tofly.baseapi.mapper.ToflyCodeCommonMapper.getUserName"/>
        <association property="rzryName" column="RZRY"
                     select="com.tofly.baseapi.mapper.ToflyCodeCommonMapper.getUserName"/>
        <association property="shryName" column="shry"
                     select="com.tofly.baseapi.mapper.ToflyCodeCommonMapper.getUserName"/>
        <association property="zjryName" column="zjry"
                     select="com.tofly.baseapi.mapper.ToflyCodeCommonMapper.getUserName"/>
        <association property="zjczryName" column="zjczry"
                     select="com.tofly.baseapi.mapper.ToflyCodeCommonMapper.getUserName"/>
        <association property="czryName" column="czry"
                     select="com.tofly.baseapi.mapper.ToflyCodeCommonMapper.getUserName"/>
        <association property="rzslryName" column="RZSLRY"
                     select="com.tofly.baseapi.mapper.ToflyCodeCommonMapper.getUserName"/>
        <association property="zzryName" column="ZZRY"
                     select="com.tofly.baseapi.mapper.ToflyCodeCommonMapper.getUserName"/>
        <association property="gzszryName" column="GZSZRY"
                     select="com.tofly.baseapi.mapper.ToflyCodeCommonMapper.getUserName"/>
        <association property="sqryName" column="SQRY"
                     select="com.tofly.baseapi.mapper.ToflyCodeCommonMapper.getUserName"/>
        <!--        <association property="presentPersonName" column="PRESENT_PERSON"-->
        <!--                     select="com.tofly.baseapi.mapper.ToflyCodeCommonMapper.getUserName"/>-->
        <!--        <collection property="jgczPersonList" column="JGCZ_PERSON"-->
        <!--                    select="getUserByIds"/>-->

        <association property="presentPersonName" column="PRESENT_PERSON"
                     select="com.tofly.baseapi.mapper.ToflyCodeCommonMapper.getUserName"/>
        <association property="nodeInfo" column="ID" select="getPresentInfo"/>
        <association property="noises" column="ID" select="com.tofly.xrtymis.mapper.NoiseLoggerInfoMapper.getNoises"/>
        <association property="rewardWaterVolume" column="ID" select="getRewardWaterVolume"/>
        <collection property="leakInfo" column="ID" select="com.tofly.xrtymis.mapper.LeakInfoMapper.getLeakInfo"/>
        <collection property="resultList" column="GDBH"
                    select="getResultdis"/>
    </resultMap>

    <select id="getSlryName" resultType="string">
        select wm_concat(REAL_NAME)
        from TF_SMPN_USER_X
        where id in
        <foreach collection="slry.split(',')" item="id" open="(" separator="," close=")">
            #{id}
        </foreach>
    </select>

    <select id="getUserByRole" resultType="map">
        select ID,REAL_NAME,USERNAME from TF_SMPN_USER_X where ID in (select distinct USER_ID from TF_SMPN_USERROLE_X
        where ROLE_ID
        in
        <foreach collection="roleId" item="id" open="(" separator="," close=")">
            #{id}
        </foreach>)

    </select>

    <select id="getRewardWaterVolume" resultType="String">
        SELECT REWARD_WATER_VOLUME AS rewardWaterVolume
        FROM TF_PUBLIC_LEAKAGE_INFO
        WHERE ORDER_ID = #{id}
    </select>
    <select id="getResultdis" resultType="map">
        SELECT *
        FROM TF_YWPN_RESULTDISP_W
        WHERE GDBH = #{gdbh}
    </select>
    <select id="getUserByIds" resultType="string">
        select real_name from tf_smpn_user_x where ID in
        <if test="userIds != null and userIds != '' ">
            <foreach collection="userIds.split(',')" item="id" open="(" separator="," close=")">
                #{id}
            </foreach>
        </if>
    </select>
    <select id="getGdcsFlagName" resultType="string">
        select decode(#{gdcsFlag}, '0', '否', '1', '是')
        from dual
    </select>

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

    <select id="getPresentInfo" resultType="com.tofly.xrtymis.custom.vo.CurrentNodeInformationVo">
        SELECT m.presentPerson as presentPerson,
               (SELECT wm_concat(REAL_NAME) FROM TF_SMPN_USER_X WHERE  instr(m.presentPerson, id) > 0) as presentPersonName,
               (SELECT wm_concat(distinct(DEPARTMENT_ID)) FROM TF_SMPN_USER_X WHERE  instr(m.presentPerson, id) > 0) as presentDept,
               (SELECT wm_concat(NAME) FROM TF_SMPN_DEPARTMENT_X where id in
               (SELECT distinct (DEPARTMENT_ID) FROM TF_SMPN_USER_X WHERE  instr(m.presentPerson, id) > 0)) as presentDeptName
        FROM (SELECT id,
                     CASE LCJD
                         WHEN 39 THEN to_char(djry)
                         WHEN 40 THEN slry
                         WHEN 41 THEN to_char(RZSLRY)
                         WHEN 42 THEN to_char(SHSLRY)
                         WHEN 43 THEN to_char(ZJCZRY)
                         WHEN 44 THEN to_char((SELECT t2.AUDIT_USER
                                       FROM TF_YWPN_GDINFO_W t1
                                                JOIN TF_YMPN_AUDIT_W t2 on t1.id = t2.AUDIT_PLAN_ID
                                       WHERE t2.AUDIT_TYPE = '12'
                                         and t2.AUDIT_STATE = '0'
                                         and t1.id = #{id}))
                         END AS presentPerson
              FROM TF_YWPN_GDINFO_W
              WHERE id = #{id}) m
    </select>

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

    <select id="files" resultType="File">
        select * FROM TF_YWPN_FILE_W WHERE ID in
        <if test="fileid != null and fileid.trim() != ''">
            <foreach item="fileid" index="fileid" collection="fileid.split(',')" separator="," open="(" close=")">
                #{fileid}
            </foreach>
        </if>
    </select>
    <select id="jgczFile" resultType="File">
        select * FROM TF_YWPN_FILE_W WHERE ID in
        <if test="jgczFileid != null and jgczFileid.trim() != ''">
            <foreach item="jgczFileid" index="jgczFileid" collection="jgczFileid.split(',')" separator="," open="("
                     close=")">
                #{jgczFileid}
            </foreach>
        </if>
    </select>

    <select id="lxName" resultType="string">
        SELECT wm_concat(GDLX_MC)
        FROM (
                 SELECT GDLX_MC
                 FROM TF_YWPN_GDGLTYPEBM_W
                 START WITH id = #{id}
                 CONNECT BY PRIOR GDLX_ID = ID
                 ORDER BY id)
    </select>

    <select id="getDjryDeptName" resultType="string">
        select t2.NAME djryDeptName
        FROM TF_SMPN_USER_X t1
                 left join TF_SMPN_DEPARTMENT_X t2 on t1.DEPARTMENT_ID = t2.ID
        WHERE t1.ID = #{djry}
    </select>
    <select id="getshdj" resultType="string">
        select JGSH_CCJB
        FROM TF_YWPN_GDYWCONFIG_W
        WHERE ID = #{lcid}
    </select>

    <select id="getlcjd" resultType="string">
        select ALL_LCJD
        FROM TF_YWPN_GDYWCONFIG_W
        WHERE ID = #{lcid}
    </select>

    <select id="gdflowconfig" resultType="Gdflowconfig">
        select *
        FROM TF_YWPN_GDYWCONFIG_W
        WHERE ID = #{lcid}
    </select>

    <select id="gdxqName" resultType="string">
        SELECT MC
        FROM "TF_YWPN_GDGLPROBLEMDETAILS_W"
        WHERE ID = #{gdxq}
    </select>
    <select id="hfztName" resultType="string">
        select CNAME
        FROM TF_YWPN_SYSCHILDCODE_D
        WHERE ID = #{hfzt}
    </select>
    <select id="czztName" resultType="string">
        select CNAME
        FROM TF_YWPN_SYSCHILDCODE_D
        WHERE ID = #{czzt}
    </select>
    <select id="gddjZtName" resultType="string">
        select CNAME
        FROM TF_YWPN_SYSCHILDCODE_D
        WHERE ID = #{gddjZt}
    </select>
    <select id="lcztName" resultType="string">
        select CNAME
        FROM TF_YWPN_SYSCHILDCODE_D
        WHERE ID = #{lczt}
    </select>
    <select id="zjztName" resultType="string">
        select CNAME
        FROM TF_YWPN_SYSCHILDCODE_D
        WHERE ID = #{zjzt}
    </select>
    <select id="shztName" resultType="string">
        select CNAME
        FROM TF_YWPN_SYSCHILDCODE_D
        WHERE ID = #{shzt}
    </select>
    <select id="lcjdName" resultType="string">
        select CNAME
        FROM TF_YWPN_SYSCHILDCODE_D
        WHERE ID = #{lcjd}
    </select>
    <select id="khpjName" resultType="string">
        select CNAME
        FROM TF_YWPN_SYSCHILDCODE_D
        WHERE ID = #{khpj}
    </select>
    <select id="jjcdName" resultType="string">
        select CNAME
        FROM TF_YWPN_SYSCHILDCODE_D
        WHERE ID = #{jjcd}
    </select>
    <select id="gdlyName" resultType="string">
        select decode(#{gdly}, '1', '成都兴蓉沱源自来水有限责任公司', '2', '综合管理部', '3', '质量安全部', '4', '生产运行部', '5', '营销管理所', '6',
                      '工程管理部', '7', '净水厂', '8', '管网管理所', '9', '计划财务部', '10', '党群工作部')
        from dual
    </select>
    <select id="gdlxName" resultType="string">
        SELECT GDLX_MC
        FROM "TF_YWPN_GDGLTYPEBM_W"
        WHERE ID = #{gdlx}
    </select>
    <select id="slbmName" resultType="string">
        select wm_concat(NAME)
        FROM "TF_SMPN_DEPARTMENT_X"
        WHERE ID in
        <foreach collection="slbm.split(',')" item="id" open="(" separator="," close=")">
            #{id}
        </foreach>
    </select>
    <select id="shbmName" resultType="string">
        select NAME
        FROM "TF_SMPN_DEPARTMENT_X"
        WHERE ID = #{shbm}
    </select>
    <select id="zjbmName" resultType="string">
        select NAME
        FROM "TF_SMPN_DEPARTMENT_X"
        WHERE ID = #{zjbm}
    </select>
    <select id="czbmName" resultType="string">
        select NAME
        FROM "TF_SMPN_DEPARTMENT_X"
        WHERE ID = #{czbm}
    </select>
    <select id="hfbmName" resultType="string">
        select NAME
        FROM TF_SMPN_DEPARTMENT_X
        WHERE ID = #{hfbm}
    </select>

    <select id="getAuditHisList" resultType="com.tofly.xrtymis.custom.vo.CheckhistoryInfoVo">
        SELECT t1.id,
               t1.TYPE,
               t1.CHECK_ID                                                checkId,
               t1.AUDIT_RESULT                                            auditResult,
               decode(t1.AUDIT_RESULT, '0', '不同意', '1', '同意', '2', '未审核') auditResultName,
               t1.AUDIT_NOTES                                             auditNotes,
               t1.AUDIT_USER                                              auditUser,
               t1.AUDIT_TIME                                              auditTime,
               t2.REAL_NAME                                               auditUserName,
               t2.DEPARTMENT_ID                                           deptId,
               t3.name                                                    deptName
        FROM TF_YWPN_CHECKHISTORY_W t1
                 LEFT JOIN TF_SMPN_USER_X t2 on t1.AUDIT_USER = t2.ID
                 LEFT JOIN TF_SMPN_DEPARTMENT_X t3 on t2.DEPARTMENT_ID = t3.ID
        WHERE t1.type = '12'
          AND t1.CHECK_ID = #{ID}
        ORDER BY auditTime desc
    </select>

    <select id="getJgAuditList" resultType="com.tofly.xrtymis.custom.dto.JgshAudit">
        SELECT t1.id,
               t1.AUDIT_STATE                                           auditState ,
               decode(t1.AUDIT_STATE, '0', '未审核', '1', '同意', '2', '不同意','3','不可审批') auditStateName,
               t1.AUDIT_NOTE                                             auditNote,
               t1.AUDIT_USER                                              auditUser,
               t1.AUDIT_TIME                                              auditTime,
               t1.AUDIT_LEVEL                                              auditLevel,
               t2.REAL_NAME                                               auditUserName,
               t1.AUDIT_LEVEL                                             auditLevel,
               t2.DEPARTMENT_ID                                           deptId,
               t3.name                                                    deptName
        FROM TF_YMPN_AUDIT_W t1
                 LEFT JOIN TF_SMPN_USER_X t2 on t1.AUDIT_USER = t2.ID
                 LEFT JOIN TF_SMPN_DEPARTMENT_X t3 on t2.DEPARTMENT_ID = t3.ID
        WHERE t1.AUDIT_TYPE = '12'
          AND t1.AUDIT_PLAN_ID = #{ID}
        ORDER BY AUDIT_TIME desc
    </select>


    <select id="orderMonitoring" resultType="map" databaseId="oracle">
        SELECT to_char("DJSJ",'yyyy-mm-dd') AS times , COUNT(LCJD) num,
        NVL( SUM( CASE WHEN LCJD = '45' THEN 1 ELSE 0 END ) ,0) AS pass,
        NVL( SUM( CASE WHEN LCJD != '45' THEN 1 ELSE 0 END ) ,0) AS unPass
        FROM
        TF_YWPN_GDINFO_W
        where
        1=1
        <if test="map.startAuditTime != null">
            and DJSJ >= #{map.startAuditTime}
        </if>
        <if test="map.endAuditTime != null ">
            <![CDATA[ and DJSJ <= #{map.endAuditTime}   ]]>
        </if>
        GROUP BY to_char(DJSJ,'yyyy-mm-dd') ORDER BY times DESC
    </select>


    <select id="summarizeNumber" resultType="map" databaseId="oracle">
        SELECT GDLY,
               GDLX,
               IFNULL(SUM(CASE WHEN LCZT = '2' THEN 1 ELSE 0 END), 0) AS rejected
        FROM TF_YWPN_GDINFO_W
        where 1 = 1
        GROUP BY GDLY, GDLX
    </select>


    <select id="orderAnalysis" resultType="map" databaseId="oracle">
        SELECT to_char("DJSJ",'yyyy-mm-dd') AS times ,COUNT (*) sumNumber, COUNT(LCJD) num,
        IFNULL( SUM( CASE WHEN HF_SFWC = '1' THEN 1 ELSE 0 END ) ,0) AS pass,
        IFNULL( SUM( CASE WHEN HF_SFWC = '0' THEN 1 ELSE 0 END ) ,0) AS unPass
        FROM
        TF_YWPN_GDINFO_W
        where
        1=1
        <if test="map.StartAuditTime != null">
            and DJSJ >= #{map.StartAuditTime}
        </if>
        <if test="map.endAuditTime != null ">
            <![CDATA[ and DJSJ <= #{map.endAuditTime}   ]]>
        </if>
        GROUP BY to_char("DJSJ",'yyyy-mm-dd')
    </select>

    <select id="orderAnalysisDetails" resultType="map" databaseId="oracle">
        SELECT COUNT (*) sumNumber, COUNT(LCJD) num,
        IFNULL( SUM( CASE WHEN HF_SFWC = '1' THEN 1 ELSE 0 END ) ,0) AS pass,
        IFNULL( SUM( CASE WHEN HF_SFWC = '0' THEN 1 ELSE 0 END ) ,0) AS unPass
        FROM
        TF_YWPN_GDINFO_W
        where
        1=1
        <if test="map.time != null ">
            and DJSJ >= #{map.time}
        </if>
        GROUP BY GDLX
    </select>

    <select id="orderAnalysisByTimeAndType" resultType="map" databaseId="oracle">
        SELECT * FROM "TF_YWPN_GDINFO_W"
        where
        1=1
        <if test="map.time != null and map.time.trim() != ''">
            and to_char(DJSJ,'yyyy-MM-dd') >= #{map.time}
        </if>
        <if test="map.type != null and map.type.trim() != ''">
            and GDLX = #{map.type}
        </if>
    </select>

    <select id="collectionManagementTwo" resultType="map" databaseId="oracle">
        SELECT GDLY,
        IFNULL( SUM( CASE WHEN LCZT = '2' THEN 1 ELSE 0 END ) ,0) AS rejected
        FROM
        TF_YWPN_GDINFO_W
        where
        1=1
        <if test="map.gdly != null and map.gdly.trim() != ''">
            and GDLY = #{map.gdly}
        </if>
        GROUP BY GDLX
    </select>
    <select id="monthCount" resultType="map" databaseId="oracle">
        SELECT to_char("DJSJ", 'yyyy-mm') AS times, COUNT(LCJD = 50) sumNumber
        FROM TF_YWPN_GDINFO_W
        where 1 = 1
        GROUP BY to_char("DJSJ", 'yyyy-mm')
    </select>

    <select id="count" resultType="Integer" databaseId="oracle">
        SELECT COUNT (*)
        FROM
        TF_YWPN_GDINFO_W
        where
        1=1
        and LCJD=45
        <if test="deta != null and deta.trim() != ''">
            and to_char(DJSJ,'yyyy-MM') = #{deta}
        </if>
    </select>

    <select id="collectionManagementThree" resultType="map" databaseId="oracle">
        SELECT *,
        IFNULL( SUM( CASE WHEN LCZT = '2' THEN 1 ELSE 0 END ) ,0) AS rejected,
        IFNULL( SUM( CASE WHEN LCZT = '3' THEN 1 ELSE 0 END ) ,0) AS termination
        FROM
        TF_YWPN_GDINFO_W
        where
        1=1
        <if test="map.gdly != null and map.gdly.trim() != ''">
            and GDLY = #{map.gdly}
        </if>
        <if test="map.gdlx != null and map.gdlx.trim() != ''">
            and GDLX = #{map.gdlx}
        </if>
        GROUP BY GDLX,GDLY
    </select>

    <resultMap type="com.tofly.xrtymis.custom.vo.GdPercentStatic" id="gdPercentStaticMap">
        <result property="gdlx" column="gdlx"/>
        <result property="gdxf1" column="GDXF1"/>
        <result property="gdxf2" column="GDXF2"/>
        <result property="gdlxName" column="gdlxName"/>
        <result property="gddjNum" column="gddjNum"/>
        <result property="rzczNum" column="rzczNum"/>
        <result property="rzczTotalNum" column="rzczTotalNum"/>
        <result property="rzshNum" column="rzshNum"/>
        <result property="rzshTotalNum" column="rzshTotalNum"/>
        <result property="rzzjNum" column="rzzjNum"/>
        <result property="rzzjTotalNum" column="rzzjTotalNum"/>
        <result property="jgczNum" column="jgczNum"/>
        <result property="jgczTotalNum" column="jgczTotalNum"/>
        <result property="jgshNum" column="jgshNum"/>
        <result property="jgshTotalNum" column="jgshTotalNum"/>
        <result property="qwxNum" column="qwxNum"/>
        <result property="gdNum" column="gdNum"/>
        <result property="gdgdNum" column="gdgdNum"/>
        <result property="notGdgdNum" column="notGdgdNum"/>
        <result property="gdOverRate" column="gdOverRate"/>
        <result property="djbm" column="DJBM"/>
        <association property="djbmName" column="DJBM" select="zjbmName"/>
        <association property="gdxf1Name" column="GDXF1" select="getGdxf1Name"/>
        <association property="gdxf2Name" column="GDXF2" select="getGdxf2Name"/>
    </resultMap>

    <select id="collectGDCompleteDetailsInfo" resultMap="gdPercentStaticMap" databaseId="oracle">
        SELECT t1.* ,gdNum-gdgdNum as notGdgdNum,round(gdgdNum/gdNum*100,2)||'%' as gdOverRate FROM (
        SELECT g.GDLX as gdlx,t.GDLX_MC as gdlxName,g.GDXF1,g.GDXF2,COUNT(g.ID) as gdNum,
        sum(decode(LCJD,39,1,0)) as gddjNum,
        sum(decode(LCJD,40,1,0)) as rzczNum,
        sum(decode(LCJD,41,1,0)) as rzshNum,
        sum(decode(LCJD,42,1,0)) as rzzjNum,
        sum(decode(LCJD,43,1,0)) as jgczNum,
        sum(decode(LCJD,44,1,0)) as jgshNum,
        sum(decode(HANG_UP,1,1,0)) as qwxNum,
        sum( CASE WHEN instr(PROCESS_INFO,'2')>0 THEN 1 ELSE 0 END ) as rzczTotalNum,
        sum( CASE WHEN instr(PROCESS_INFO,'3')>0 THEN 1 ELSE 0 END ) as rzshTotalNum,
        sum( CASE WHEN instr(PROCESS_INFO,'4')>0 THEN 1 ELSE 0 END ) as rzzjTotalNum,
        sum( CASE WHEN instr(PROCESS_INFO,'5')>0 THEN 1 ELSE 0 END ) as jgczTotalNum,
        sum( CASE WHEN instr(PROCESS_INFO,'6')>0 THEN 1 ELSE 0 END ) as jgshTotalNum,
        sum(case g.LCJD when 45 then 1 else 0 end) as gdgdNum

        FROM TF_YWPN_GDINFO_W g
        LEFT JOIN TF_YWPN_GDGLTYPEBM_W t ON (g.GDLX = t.ID)
        WHERE 1=1
        <if test="model.gdlxList != null and model.gdlxList != '' ">
            and g.GDLX in
            <foreach collection="model.gdlxList.split(',')" item="id" open="(" separator="," close=")">
                #{id}
            </foreach>
        </if>
        <if test="model.deptIdList != null and model.deptIdList != '' ">
            and DJBM in
            <foreach collection="model.deptIdList.split(',')" item="id" open="(" separator="," close=")">
                #{id}
            </foreach>
        </if>
        <if test="model.isRxlx != null ">
            and IS_RXLX = #{model.isRxlx}
        </if>
        <if test="model.startTime != null ">
            and DJSJ >= #{model.startTime}
        </if>
        <if test="model.endTime != null ">
            <![CDATA[ and DJSJ <= #{model.endTime}   ]]>
        </if>
        GROUP BY g.GDLX,t.GDLX_MC,g.GDXF1,g.GDXF2
        <!--<if test="model.gdlx != null ">
            ,g.GDXF1,t1.GDLX_MC
        </if>-->
        ) t1 ORDER BY gdOverRate

    </select>

    <select id="collectGDCompleteInfo" resultMap="gdPercentStaticMap" databaseId="oracle">
        SELECT t1.* ,gdNum-gdgdNum as notGdgdNum,round(gdgdNum/gdNum*100,2)||'%' as gdOverRate FROM (
        SELECT g.GDLX as gdlx,t.GDLX_MC as gdlxName,COUNT(g.ID) as gdNum,
        sum(decode(LCJD,39,1,0)) as gddjNum,
        sum(decode(LCJD,40,1,0)) as rzczNum,
        sum(decode(LCJD,41,1,0)) as rzshNum,
        sum(decode(LCJD,42,1,0)) as rzzjNum,
        sum(decode(LCJD,43,1,0)) as jgczNum,
        sum(decode(LCJD,44,1,0)) as jgshNum,
        sum(decode(HANG_UP,1,1,0)) as qwxNum,
        sum( CASE WHEN instr(PROCESS_INFO,'2')>0 THEN 1 ELSE 0 END ) as rzczTotalNum,
        sum( CASE WHEN instr(PROCESS_INFO,'3')>0 THEN 1 ELSE 0 END ) as rzshTotalNum,
        sum( CASE WHEN instr(PROCESS_INFO,'4')>0 THEN 1 ELSE 0 END ) as rzzjTotalNum,
        sum( CASE WHEN instr(PROCESS_INFO,'5')>0 THEN 1 ELSE 0 END ) as jgczTotalNum,
        sum( CASE WHEN instr(PROCESS_INFO,'6')>0 THEN 1 ELSE 0 END ) as jgshTotalNum,
        sum(case g.LCJD when 45 then 1 else 0 end) as gdgdNum

        FROM TF_YWPN_GDINFO_W g
        LEFT JOIN TF_YWPN_GDGLTYPEBM_W t ON (g.GDLX = t.ID)
        WHERE 1=1
        <if test="model.gdlxList != null and model.gdlxList != '' ">
            and g.GDLX in
            <foreach collection="model.gdlxList.split(',')" item="id" open="(" separator="," close=")">
                #{id}
            </foreach>
        </if>
        <if test="model.deptIdList != null and model.deptIdList != '' ">
            and DJBM in
            <foreach collection="model.deptIdList.split(',')" item="id" open="(" separator="," close=")">
                #{id}
            </foreach>
        </if>
        <if test="model.isRxlx != null ">
            and IS_RXLX = #{model.isRxlx}
        </if>
        <if test="model.startTime != null ">
            and DJSJ >= #{model.startTime}
        </if>
        <if test="model.endTime != null ">
            <![CDATA[ and DJSJ <= #{model.endTime}   ]]>
        </if>
        GROUP BY g.GDLX,t.GDLX_MC
        <!--<if test="model.gdlx != null ">
            ,g.GDXF1,t1.GDLX_MC
        </if>-->
        ) t1 ORDER BY gdOverRate

    </select>
    <select id="collectDeptGDCompleteInfo" resultMap="gdPercentStaticMap" databaseId="oracle">
        SELECT t1.* ,gdNum-gdgdNum as notGdgdNum,round(gdgdNum/gdNum*100,2)||'%' as gdOverRate FROM (
        SELECT g.DJBM,COUNT(g.ID) as gdNum,
        sum(decode(LCJD,39,1,0)) as gddjNum,
        sum(decode(LCJD,40,1,0)) as rzczNum,
        sum(decode(LCJD,41,1,0)) as rzshNum,
        sum(decode(LCJD,42,1,0)) as rzzjNum,
        sum(decode(LCJD,43,1,0)) as jgczNum,
        sum(decode(LCJD,44,1,0)) as jgshNum,
        sum(decode(HANG_UP,1,1,0)) as qwxNum,
        sum( CASE WHEN instr(PROCESS_INFO,'2')>0 THEN 1 ELSE 0 END ) as rzczTotalNum,
        sum( CASE WHEN instr(PROCESS_INFO,'3')>0 THEN 1 ELSE 0 END ) as rzshTotalNum,
        sum( CASE WHEN instr(PROCESS_INFO,'4')>0 THEN 1 ELSE 0 END ) as rzzjTotalNum,
        sum( CASE WHEN instr(PROCESS_INFO,'5')>0 THEN 1 ELSE 0 END ) as jgczTotalNum,
        sum( CASE WHEN instr(PROCESS_INFO,'6')>0 THEN 1 ELSE 0 END ) as jgshTotalNum,
        sum(case g.LCJD when 45 then 1 else 0 end) as gdgdNum

        FROM TF_YWPN_GDINFO_W g
        LEFT JOIN TF_YWPN_GDGLTYPEBM_W t ON (g.GDLX = t.ID)
        WHERE 1=1
        <if test="model.gdlxList != null and model.gdlxList != '' ">
            and g.GDLX in
            <foreach collection="model.gdlxList.split(',')" item="id" open="(" separator="," close=")">
                #{id}
            </foreach>
        </if>
        <if test="model.deptIdList != null and model.deptIdList != '' ">
            and DJBM in
            <foreach collection="model.deptIdList.split(',')" item="id" open="(" separator="," close=")">
                #{id}
            </foreach>
        </if>
        <if test="model.isRxlx != null ">
            and IS_RXLX = #{model.isRxlx}
        </if>
        <if test="model.startTime != null ">
            and DJSJ >= #{model.startTime}
        </if>
        <if test="model.endTime != null ">
            <![CDATA[ and DJSJ <= #{model.endTime}   ]]>
        </if>
        and g.djbm is not null
        GROUP BY g.DJBM
        <!--<if test="model.gdlx != null ">
            ,g.GDXF1,t1.GDLX_MC
        </if>-->
        ) t1 ORDER BY gdOverRate

    </select>


    <select id="getGdxf1Name" resultType="string">
        select GDLX_MC as gdxf1Name  from TF_YWPN_GDGLTYPEBM_W where ID = #{gdxf1}
    </select>
    <select id="getGdxf2Name" resultType="string">
        select GDLX_MC as gdxf1Name  from TF_YWPN_GDGLTYPEBM_W where ID = #{gdxf2}
    </select>

    <select id="collectGdInfoDetail" resultType="map">
        SELECT d.* , decode(e.bhs , null , 0, e.bhs) bhcount , decode(f.zpcount , null , 0, f.zpcount) zpcount
        FROM (
        SELECT c.* , c.waitcount + c.ybct as allCount
        FROM (
        SELECT g.GDLX , g.GDXF1 , g.GDXF2 , t.GDLX_MC as gdlxmc ,
        <!--为防止工单细分1/2为空的情况，如果是空，根本无法使用字段关联-->
        DECODE(a.GDLX_MC, null , '-' , a.GDLX_MC) as gdxf1Name,
        DECODE(b.GDLX_MC, null , '-' , b.GDLX_MC) as gdxf2Name,
        <if test="gdglinfoDTO.lcjdid == 39">
            <!--工单登记 1-->
            <!--待办-->
            sum(CASE WHEN g.LCJD = 39 THEN 1 ELSE 0 END ) as waitcount ,
            <!--已办-->
            sum(CASE WHEN instr(PROCESS_DEPOSIT, '1') > 0 THEN 1 ELSE 0 END) as ybct ,
            <!--终止个数-->
            sum(CASE WHEN GDZZZT = '1' THEN 1 ELSE 0 END) as zzct ,
            <!--工单登记超时总数-->
            sum(CASE WHEN g.GDCS_FLAG = '1' THEN 1 ELSE 0 END) as csct ,
            <!--工单登记即将超时总数；但是在工单没有超时、没有归档完成的情况才计算即将超时数-->
            sum(CASE WHEN g.GDCS_FLAG = '0' AND g.LCJD != 45 THEN
            CASE WHEN <![CDATA[ (CEIL((SYSDATE - g.DJSJ)*24*60) / CEIL((g.GDSX - g.DJSJ)*24*60)) *100 > #{ratio} ]]>
            THEN 1 ELSE 0 END
            ELSE 0 END) upcomingct
        </if>
        <if test="gdglinfoDTO.lcjdid == 40">
            <!--认证处置 2-->
            sum(CASE WHEN g.LCJD = 40 THEN 1 ELSE 0 END ) as waitcount ,
            sum(CASE WHEN instr(PROCESS_DEPOSIT, '2') > 0 THEN 1 ELSE 0 END) as ybct ,
            <!--认证处置 超时-->
            sum(CASE WHEN RZCZ_CSZT = '1' THEN 1 ELSE 0 END) as csct ,
            <!--认证处置 即将超时 需要判断在认证处置流程下的工单，没有超时的情况才计算即将超时数-->
            sum(CASE WHEN g.RZCZ_CSZT = '0' AND g.LCJD = 40 THEN
            CASE WHEN <![CDATA[ (CEIL((SYSDATE - g.DJSJ)*24*60) / CEIL((g.RZSX - g.DJSJ)*24*60)) *100 > #{ratio} ]]>
            THEN 1 ELSE 0 END
            ELSE 0 END) upcomingct
        </if>
        <if test="gdglinfoDTO.lcjdid == 41">
            <!--认证审核 3-->
            sum(CASE WHEN g.LCJD = 41 THEN 1 ELSE 0 END ) as waitcount ,
            sum(CASE WHEN instr(PROCESS_DEPOSIT, '3') > 0 THEN 1 ELSE 0 END) as ybct ,
            <!--认证审核 超时-->
            sum(CASE WHEN RESH_CSZT = '1' THEN 1 ELSE 0 END) as csct ,
            sum(CASE WHEN g.RESH_CSZT = '0' AND g.LCJD = 41 THEN
            <!--因为即将超时是去上一次流程处理的时间开始计算的，所以需要挨个算上一个流程是什么，比如如果认证审核的上一个流程是认证处置，那么就取认证处置的处理时间计算即将超时-->
            (CASE WHEN instr(PROCESS_DEPOSIT, '2') > 0 THEN
            (CASE WHEN <![CDATA[ (CEIL((SYSDATE - g.RZSJ)*24*60) / CEIL((g.SHSX - g.RZSJ)*24*60)) *100 > #{ratio} ]]>
            THEN 1 ELSE 0 END)
            ELSE
            (CASE WHEN <![CDATA[ (CEIL((SYSDATE - g.DJSJ)*24*60) / CEIL((g.SHSX - g.DJSJ)*24*60)) *100 > #{ratio} ]]>
            THEN 1 ELSE 0 END)
            END)
            ELSE 0 END) upcomingct
        </if>
        <if test="gdglinfoDTO.lcjdid == 42">
            <!--认证质检 4-->
            sum(CASE WHEN g.LCJD = 42 THEN 1 ELSE 0 END ) as waitcount ,
            sum(CASE WHEN instr(PROCESS_DEPOSIT, '4') > 0 THEN 1 ELSE 0 END) as ybct,
            <!--认证质检 超时-->
            sum(CASE WHEN RZZJ_CSZT = '1' THEN 1 ELSE 0 END) as csct ,
            sum(CASE WHEN g.RZZJ_CSZT = '0' AND g.LCJD = 42 THEN(
            CASE WHEN instr(PROCESS_DEPOSIT, '3') > 0 THEN(
            CASE WHEN <![CDATA[ (CEIL((SYSDATE - g.SHSJ)*24*60) / CEIL((g.ZJSX - g.SHSJ)*24*60)) *100 > #{ratio} ]]>
            THEN 1 ELSE 0 END)
            ELSE(
            CASE WHEN instr(PROCESS_DEPOSIT, '2') > 0 THEN(
            CASE WHEN <![CDATA[ (CEIL((SYSDATE - g.RZSJ)*24*60) / CEIL((g.SHSX - g.RZSJ)*24*60)) *100 > #{ratio} ]]>
            THEN 1 ELSE 0 END)
            ELSE
            (CASE WHEN <![CDATA[ (CEIL((SYSDATE - g.DJSJ)*24*60) / CEIL((g.SHSX - g.DJSJ)*24*60)) *100 > #{ratio} ]]>
            THEN 1 ELSE 0 END)
            END)
            END)
            ELSE 0 END) upcomingct
        </if>
        <if test="gdglinfoDTO.lcjdid == 43">
            <!--结果处置 5-->
            sum(CASE WHEN g.LCJD = 43 THEN 1 ELSE 0 END ) as waitcount ,
            sum(CASE WHEN instr(PROCESS_DEPOSIT, '5') > 0 THEN 1 ELSE 0 END) as ybct ,
            <!--结果处置 超时-->
            sum(CASE WHEN JGCZ_CSZT = '1' THEN 1 ELSE 0 END) as csct ,
            sum(CASE WHEN g.JGCZ_CSZT = '0' AND g.LCJD = 43 THEN
            (CASE WHEN instr(PROCESS_DEPOSIT, '4') > 0 THEN(
            CASE WHEN <![CDATA[ (CEIL((SYSDATE - g.ZJSJ)*24*60) / CEIL((g.CZSX - g.ZJSJ)*24*60)) *100 > #{ratio} ]]>
            THEN 1 ELSE 0 END)
            ELSE
            (CASE WHEN instr(PROCESS_DEPOSIT, '3') > 0 THEN(
            CASE WHEN <![CDATA[ (CEIL((SYSDATE - g.SHSJ)*24*60) / CEIL((g.ZJSX - g.SHSJ)*24*60)) *100 > #{ratio} ]]>
            THEN 1 ELSE 0 END)
            ELSE(
            CASE WHEN instr(PROCESS_DEPOSIT, '2') > 0 THEN(
            CASE WHEN <![CDATA[ (CEIL((SYSDATE - g.RZSJ)*24*60) / CEIL((g.SHSX - g.RZSJ)*24*60)) *100 > #{ratio} ]]>
            THEN 1 ELSE 0 END)
            ELSE
            (CASE WHEN <![CDATA[ (CEIL((SYSDATE - g.DJSJ)*24*60) / CEIL((g.SHSX - g.DJSJ)*24*60)) *100 > #{ratio} ]]>
            THEN 1 ELSE 0 END)
            END)
            END)
            END)
            ELSE 0 END) upcomingct
        </if>
        <if test="gdglinfoDTO.lcjdid == 44">
            <!--结果审核 6-->
            sum(CASE WHEN g.LCJD = 44 THEN 1 ELSE 0 END ) as waitcount ,
            sum(CASE WHEN instr(PROCESS_DEPOSIT, '6') > 0 THEN 1 ELSE 0 END) as ybct
        </if>
        FROM TF_YWPN_GDINFO_W g
        LEFT JOIN TF_YWPN_GDGLTYPEBM_W t ON g.GDLX = t.ID
        LEFT JOIN TF_YWPN_GDGLTYPEBM_W a ON g.GDXF1 = a.ID
        LEFT JOIN TF_YWPN_GDGLTYPEBM_W b ON g.GDXF2 = b.ID
        <where>
            <!--g.LCJD = #{gdglinfoDTO.lcjdid}-->
            <include refid="getByRyId"></include>
            <include refid="getCollectDetails"></include>
        </where>
        GROUP BY g.GDLX , g.GDXF1 , g.GDXF2 , t.GDLX_MC, a.GDLX_MC, b.GDLX_MC) c ) d
        <!--关联查询驳回总数 需要重新关联查询的原因是：目前需要根据流程节点查询了，所以需要另外查询后再关联；包括下面的转派个数也是-->
        LEFT JOIN (
        SELECT bb.GDLX_MC,
        <!--为防止工单细分1/2为空的情况，如果是空，根本无法使用字段关联-->
        DECODE(cc.GDLX_MC , null , '-' , cc.GDLX_MC) as GDXF1 ,
        DECODE(dd.GDLX_MC , null , '-' , dd.GDLX_MC) as GDXF2 ,
        <!--如果有重复的工单编号，则只算一条记录：去重-->
        COUNT(DISTINCT ee.GDBH) bhs
        FROM TF_YWPN_GDINFO_W aa
        LEFT JOIN TF_YWPN_GDGLTYPEBM_W bb ON aa.GDLX = bb.ID
        LEFT JOIN TF_YWPN_GDGLTYPEBM_W cc ON aa.GDXF1 = cc.ID
        LEFT JOIN TF_YWPN_GDGLTYPEBM_W dd ON aa.GDXF2 = dd.ID
        LEFT JOIN TF_YWPN_GDGLFLOW_W ee ON ee.GDBH = aa.GDBH
        <where>
            (ee.STATUS_FLAG=1 or ee.STATUS_FLAG is null)
            <include refid="getByRyId"></include>
            <include refid="getCollectDetails"></include>
            <!--因为驳回记录表中存的是流程节点字符串；并且有很多一条工单被驳回的情况，所以必须要根据流程节点筛选-->
            and ee.BBH_LCJD = #{gdglinfoDTO.lcjdName}
        </where>
        GROUP BY bb.GDLX_MC, cc.GDLX_MC, dd.GDLX_MC ) e
        ON (d.gdlxmc = e.GDLX_MC and d.gdxf1Name = e.GDXF1 and d.gdxf2Name = e.GDXF2)
        <!--关联查询转派个数-->
        LEFT JOIN (
        SELECT bbb.GDLX_MC,
        DECODE(ccc.GDLX_MC , null , '-' , ccc.GDLX_MC) as GDXF1 ,
        DECODE(ddd.GDLX_MC , null , '-' , ddd.GDLX_MC) as GDXF2 ,
        COUNT(DISTINCT eee.GDBH) as zpcount
        FROM TF_YWPN_GDINFO_W aaa
        LEFT JOIN TF_YWPN_GDGLTYPEBM_W bbb ON aaa.GDLX = bbb.ID
        LEFT JOIN TF_YWPN_GDGLTYPEBM_W ccc ON aaa.GDXF1 = ccc.ID
        LEFT JOIN TF_YWPN_GDGLTYPEBM_W ddd ON aaa.GDXF2 = ddd.ID
        LEFT JOIN TF_YWPN_REDEPLOY_W eee ON eee.GDBH = aaa.GDBH
        WHERE
        (eee.STATUS_FLAG=1 or eee.STATUS_FLAG is null)
        AND eee.LCJD = #{gdglinfoDTO.lcjdName}
        <include refid="getByRyId"></include>
        <include refid="getCollectDetails"></include>
        GROUP BY bbb.GDLX_MC, ccc.GDLX_MC, ddd.GDLX_MC ) f
        ON (d.gdlxmc = f.GDLX_MC and d.gdxf1Name = f.GDXF1 and d.gdxf2Name = f.GDXF2)
    </select>

    <select id="collectGdInfoDetailByGddj" resultType="java.util.Map">
        SELECT d.* , decode(e.bhs , null , 0, e.bhs) bhcount
        FROM (
        SELECT c.* , c.waitcount + c.ybct as allCount
        FROM (
        SELECT g.GDLX , g.GDXF1 , g.GDXF2 , t.GDLX_MC as gdlxmc ,
        <!--为防止工单细分1/2为空的情况，如果是空，根本无法使用字段关联-->
        DECODE(a.GDLX_MC, null , '-' , a.GDLX_MC) as gdxf1Name,
        DECODE(b.GDLX_MC, null , '-' , b.GDLX_MC) as gdxf2Name,
        <!--工单登记 1-->
        <!--待办-->
        sum(CASE WHEN g.LCJD = 39 THEN 1 ELSE 0 END ) as waitcount ,
        <!--已办-->
        sum(CASE WHEN instr(PROCESS_DEPOSIT, '1') > 0 THEN 1 ELSE 0 END) as ybct ,
        <!--终止个数-->
        sum(CASE WHEN GDZZZT = '1' THEN 1 ELSE 0 END) as zzct ,
        <!--工单登记超时总数-->
        sum(CASE WHEN g.GDCS_FLAG = '1' THEN 1 ELSE 0 END) as csct ,
        <!--工单登记即将超时总数；但是在工单没有超时、没有归档完成的情况才计算即将超时数-->
        sum(CASE WHEN g.GDCS_FLAG = '0' AND g.LCJD != 45 THEN
        CASE WHEN <![CDATA[ (CEIL((SYSDATE - g.DJSJ)*24*60) / CEIL((g.GDSX - g.DJSJ)*24*60)) *100 > #{ratio} ]]>
        THEN 1 ELSE 0 END
        ELSE 0 END) upcomingct
        FROM TF_YWPN_GDINFO_W g
        LEFT JOIN TF_YWPN_GDGLTYPEBM_W t ON g.GDLX = t.ID
        LEFT JOIN TF_YWPN_GDGLTYPEBM_W a ON g.GDXF1 = a.ID
        LEFT JOIN TF_YWPN_GDGLTYPEBM_W b ON g.GDXF2 = b.ID
        <where>
            DJRY = #{userId}
            <include refid="getCollectDetails"></include>
        </where>
        GROUP BY g.GDLX , g.GDXF1 , g.GDXF2 , t.GDLX_MC, a.GDLX_MC, b.GDLX_MC) c ) d
        <!--关联查询驳回总数 需要重新关联查询的原因是：目前需要根据流程节点查询了，所以需要另外查询后再关联；包括下面的转派个数也是-->
        LEFT JOIN (
        SELECT bb.GDLX_MC,
        <!--为防止工单细分1/2为空的情况，如果是空，根本无法使用字段关联-->
        DECODE(cc.GDLX_MC , null , '-' , cc.GDLX_MC) as GDXF1 ,
        DECODE(dd.GDLX_MC , null , '-' , dd.GDLX_MC) as GDXF2 ,
        <!--如果有重复的工单编号，则只算一条记录：去重-->
        COUNT(DISTINCT ee.GDBH) bhs
        FROM TF_YWPN_GDINFO_W aa
        LEFT JOIN TF_YWPN_GDGLTYPEBM_W bb ON aa.GDLX = bb.ID
        LEFT JOIN TF_YWPN_GDGLTYPEBM_W cc ON aa.GDXF1 = cc.ID
        LEFT JOIN TF_YWPN_GDGLTYPEBM_W dd ON aa.GDXF2 = dd.ID
        LEFT JOIN TF_YWPN_GDGLFLOW_W ee ON ee.GDBH = aa.GDBH
        <where>
            (ee.STATUS_FLAG=1 or ee.STATUS_FLAG is null)
            AND DJRY = #{userId}
            <include refid="getCollectDetails"></include>
            <!--因为驳回记录表中存的是流程节点字符串；并且有很多一条工单被驳回的情况，所以必须要根据流程节点筛选-->
            and ee.BBH_LCJD = #{gdglinfoDTO.lcjdName}
        </where>
        GROUP BY bb.GDLX_MC, cc.GDLX_MC, dd.GDLX_MC ) e
        ON (d.gdlxmc = e.GDLX_MC and d.gdxf1Name = e.GDXF1 and d.gdxf2Name = e.GDXF2)
    </select>

    <select id="collectGdInfoDetailByRzcz" resultType="java.util.Map">
        SELECT d.* , decode(e.bhs , null , 0, e.bhs) bhcount , decode(f.zpcount , null , 0, f.zpcount) zpcount
        FROM (
        SELECT c.* , c.waitcount + c.ybct as allCount
        FROM (
        SELECT g.GDLX , g.GDXF1 , g.GDXF2 , t.GDLX_MC as gdlxmc,
        <!--为防止工单细分1/2为空的情况，如果是空，根本无法使用字段关联-->
        DECODE(a.GDLX_MC, null , '-' , a.GDLX_MC) as gdxf1Name,
        DECODE(b.GDLX_MC, null , '-' , b.GDLX_MC) as gdxf2Name,
        <!--认证处置 2-->
        sum(CASE WHEN g.LCJD = 40 THEN 1 ELSE 0 END ) as waitcount ,
        sum(CASE WHEN instr(PROCESS_DEPOSIT, '2') > 0 THEN 1 ELSE 0 END) as ybct ,
        <!--认证处置 超时-->
        sum(CASE WHEN RZCZ_CSZT = '1' THEN 1 ELSE 0 END) as csct ,
        <!--认证处置 即将超时 需要判断在认证处置流程下的工单，没有超时的情况才计算即将超时数-->
        sum(CASE WHEN g.RZCZ_CSZT = '0' AND g.LCJD = 40 THEN
        CASE WHEN <![CDATA[ (CEIL((SYSDATE - g.DJSJ)*24*60) / CEIL((g.RZSX - g.DJSJ)*24*60)) *100 > #{ratio} ]]>
        THEN 1 ELSE 0 END
        ELSE 0 END) upcomingct
        FROM TF_YWPN_GDINFO_W g
        LEFT JOIN TF_YWPN_GDGLTYPEBM_W t ON g.GDLX = t.ID
        LEFT JOIN TF_YWPN_GDGLTYPEBM_W a ON g.GDXF1 = a.ID
        LEFT JOIN TF_YWPN_GDGLTYPEBM_W b ON g.GDXF2 = b.ID
        <where>
            <include refid="getByRyId"></include>
            <include refid="getCollectDetails"></include>
        </where>
        GROUP BY g.GDLX , g.GDXF1 , g.GDXF2 , t.GDLX_MC, a.GDLX_MC, b.GDLX_MC) c ) d
        <!--关联查询驳回总数 需要重新关联查询的原因是：目前需要根据流程节点查询了，所以需要另外查询后再关联；包括下面的转派个数也是-->
        LEFT JOIN (
        SELECT bb.GDLX_MC,
        <!--为防止工单细分1/2为空的情况，如果是空，根本无法使用字段关联-->
        DECODE(cc.GDLX_MC , null , '-' , cc.GDLX_MC) as GDXF1 ,
        DECODE(dd.GDLX_MC , null , '-' , dd.GDLX_MC) as GDXF2 ,
        <!--如果有重复的工单编号，则只算一条记录：去重-->
        COUNT(DISTINCT ee.GDBH) bhs
        FROM TF_YWPN_GDINFO_W aa
        LEFT JOIN TF_YWPN_GDGLTYPEBM_W bb ON aa.GDLX = bb.ID
        LEFT JOIN TF_YWPN_GDGLTYPEBM_W cc ON aa.GDXF1 = cc.ID
        LEFT JOIN TF_YWPN_GDGLTYPEBM_W dd ON aa.GDXF2 = dd.ID
        LEFT JOIN TF_YWPN_GDGLFLOW_W ee ON ee.GDBH = aa.GDBH
        <where>
            (ee.STATUS_FLAG=1 or ee.STATUS_FLAG is null)
            <include refid="getByRyId"></include>
            <include refid="getCollectDetails"></include>
            <!--因为驳回记录表中存的是流程节点字符串；并且有很多一条工单被驳回的情况，所以必须要根据流程节点筛选-->
            and ee.BBH_LCJD = #{gdglinfoDTO.lcjdName}
        </where>
        GROUP BY bb.GDLX_MC, cc.GDLX_MC, dd.GDLX_MC ) e
        ON (d.gdlxmc = e.GDLX_MC and d.gdxf1Name = e.GDXF1 and d.gdxf2Name = e.GDXF2)
        <!--关联查询转派个数-->
        LEFT JOIN (
        SELECT bbb.GDLX_MC,
        DECODE(ccc.GDLX_MC , null , '-' , ccc.GDLX_MC) as GDXF1 ,
        DECODE(ddd.GDLX_MC , null , '-' , ddd.GDLX_MC) as GDXF2 ,
        COUNT(DISTINCT eee.GDBH) as zpcount
        FROM TF_YWPN_GDINFO_W aaa
        LEFT JOIN TF_YWPN_GDGLTYPEBM_W bbb ON aaa.GDLX = bbb.ID
        LEFT JOIN TF_YWPN_GDGLTYPEBM_W ccc ON aaa.GDXF1 = ccc.ID
        LEFT JOIN TF_YWPN_GDGLTYPEBM_W ddd ON aaa.GDXF2 = ddd.ID
        LEFT JOIN TF_YWPN_REDEPLOY_W eee ON eee.GDBH = aaa.GDBH
        WHERE
        (eee.STATUS_FLAG=1 or eee.STATUS_FLAG is null)
        AND eee.LCJD = #{gdglinfoDTO.lcjdName}
        <include refid="getByRyId"></include>
        <include refid="getCollectDetails"></include>
        GROUP BY bbb.GDLX_MC, ccc.GDLX_MC, ddd.GDLX_MC ) f
        ON (d.gdlxmc = f.GDLX_MC and d.gdxf1Name = f.GDXF1 and d.gdxf2Name = f.GDXF2)
    </select>

    <select id="collectGdInfoDetailByRzsh" resultType="java.util.Map">
        SELECT d.* , decode(e.bhs , null , 0, e.bhs) bhcount , decode(f.zpcount , null , 0, f.zpcount) zpcount
        FROM (
        SELECT c.* , c.waitcount + c.ybct as allCount
        FROM (
        SELECT g.GDLX , g.GDXF1 , g.GDXF2 , t.GDLX_MC as gdlxmc ,
        <!--为防止工单细分1/2为空的情况，如果是空，根本无法使用字段关联-->
        DECODE(a.GDLX_MC, null , '-' , a.GDLX_MC) as gdxf1Name,
        DECODE(b.GDLX_MC, null , '-' , b.GDLX_MC) as gdxf2Name,
        <!--认证审核 3-->
        sum(CASE WHEN g.LCJD = 41 THEN 1 ELSE 0 END ) as waitcount ,
        sum(CASE WHEN instr(PROCESS_DEPOSIT, '3') > 0 THEN 1 ELSE 0 END) as ybct ,
        <!--认证审核 超时-->
        sum(CASE WHEN RESH_CSZT = '1' THEN 1 ELSE 0 END) as csct ,
        sum(CASE WHEN g.RESH_CSZT = '0' AND g.LCJD = 41 THEN
        <!--因为即将超时是去上一次流程处理的时间开始计算的，所以需要挨个算上一个流程是什么，比如如果认证审核的上一个流程是认证处置，那么就取认证处置的处理时间计算即将超时-->
        (CASE WHEN instr(PROCESS_DEPOSIT, '2') > 0 THEN
        (CASE WHEN <![CDATA[ (CEIL((SYSDATE - g.RZSJ)*24*60) / CEIL((g.SHSX - g.RZSJ)*24*60)) *100 > #{ratio} ]]>
        THEN 1 ELSE 0 END)
        ELSE
        (CASE WHEN <![CDATA[ (CEIL((SYSDATE - g.DJSJ)*24*60) / CEIL((g.SHSX - g.DJSJ)*24*60)) *100 > #{ratio} ]]>
        THEN 1 ELSE 0 END)
        END)
        ELSE 0 END) upcomingct
        FROM TF_YWPN_GDINFO_W g
        LEFT JOIN TF_YWPN_GDGLTYPEBM_W t ON g.GDLX = t.ID
        LEFT JOIN TF_YWPN_GDGLTYPEBM_W a ON g.GDXF1 = a.ID
        LEFT JOIN TF_YWPN_GDGLTYPEBM_W b ON g.GDXF2 = b.ID
        <where>
            <include refid="getByRyId"></include>
            <include refid="getCollectDetails"></include>
        </where>
        GROUP BY g.GDLX , g.GDXF1 , g.GDXF2 , t.GDLX_MC, a.GDLX_MC, b.GDLX_MC) c ) d
        <!--关联查询驳回总数 需要重新关联查询的原因是：目前需要根据流程节点查询了，所以需要另外查询后再关联；包括下面的转派个数也是-->
        LEFT JOIN (
        SELECT bb.GDLX_MC,
        <!--为防止工单细分1/2为空的情况，如果是空，根本无法使用字段关联-->
        DECODE(cc.GDLX_MC , null , '-' , cc.GDLX_MC) as GDXF1 ,
        DECODE(dd.GDLX_MC , null , '-' , dd.GDLX_MC) as GDXF2 ,
        <!--如果有重复的工单编号，则只算一条记录：去重-->
        COUNT(DISTINCT ee.GDBH) bhs
        FROM TF_YWPN_GDINFO_W aa
        LEFT JOIN TF_YWPN_GDGLTYPEBM_W bb ON aa.GDLX = bb.ID
        LEFT JOIN TF_YWPN_GDGLTYPEBM_W cc ON aa.GDXF1 = cc.ID
        LEFT JOIN TF_YWPN_GDGLTYPEBM_W dd ON aa.GDXF2 = dd.ID
        LEFT JOIN TF_YWPN_GDGLFLOW_W ee ON ee.GDBH = aa.GDBH
        <where>
            (ee.STATUS_FLAG=1 or ee.STATUS_FLAG is null)
            <include refid="getByRyId"></include>
            <include refid="getCollectDetails"></include>
            <!--因为驳回记录表中存的是流程节点字符串；并且有很多一条工单被驳回的情况，所以必须要根据流程节点筛选-->
            and ee.BBH_LCJD = #{gdglinfoDTO.lcjdName}
        </where>
        GROUP BY bb.GDLX_MC, cc.GDLX_MC, dd.GDLX_MC ) e
        ON (d.gdlxmc = e.GDLX_MC and d.gdxf1Name = e.GDXF1 and d.gdxf2Name = e.GDXF2)
        <!--关联查询转派个数-->
        LEFT JOIN (
        SELECT bbb.GDLX_MC,
        DECODE(ccc.GDLX_MC , null , '-' , ccc.GDLX_MC) as GDXF1 ,
        DECODE(ddd.GDLX_MC , null , '-' , ddd.GDLX_MC) as GDXF2 ,
        COUNT(DISTINCT eee.GDBH) as zpcount
        FROM TF_YWPN_GDINFO_W aaa
        LEFT JOIN TF_YWPN_GDGLTYPEBM_W bbb ON aaa.GDLX = bbb.ID
        LEFT JOIN TF_YWPN_GDGLTYPEBM_W ccc ON aaa.GDXF1 = ccc.ID
        LEFT JOIN TF_YWPN_GDGLTYPEBM_W ddd ON aaa.GDXF2 = ddd.ID
        LEFT JOIN TF_YWPN_REDEPLOY_W eee ON eee.GDBH = aaa.GDBH
        WHERE
        (eee.STATUS_FLAG=1 or eee.STATUS_FLAG is null)
        AND eee.LCJD = #{gdglinfoDTO.lcjdName}
        <include refid="getByRyId"></include>
        <include refid="getCollectDetails"></include>
        GROUP BY bbb.GDLX_MC, ccc.GDLX_MC, ddd.GDLX_MC ) f
        ON (d.gdlxmc = f.GDLX_MC and d.gdxf1Name = f.GDXF1 and d.gdxf2Name = f.GDXF2)
    </select>

    <select id="collectGdInfoDetailByRzzj" resultType="java.util.Map">
        SELECT d.* , decode(e.bhs , null , 0, e.bhs) bhcount , decode(f.zpcount , null , 0, f.zpcount) zpcount
        FROM (
        SELECT c.* , c.waitcount + c.ybct as allCount
        FROM (
        SELECT g.GDLX , g.GDXF1 , g.GDXF2 , t.GDLX_MC as gdlxmc ,
        <!--为防止工单细分1/2为空的情况，如果是空，根本无法使用字段关联-->
        DECODE(a.GDLX_MC, null , '-' , a.GDLX_MC) as gdxf1Name,
        DECODE(b.GDLX_MC, null , '-' , b.GDLX_MC) as gdxf2Name,
        <!--认证质检 4-->
        sum(CASE WHEN g.LCJD = 42 THEN 1 ELSE 0 END ) as waitcount ,
        sum(CASE WHEN instr(PROCESS_DEPOSIT, '4') > 0 THEN 1 ELSE 0 END) as ybct,
        <!--认证质检 超时-->
        sum(CASE WHEN RZZJ_CSZT = '1' THEN 1 ELSE 0 END) as csct ,
        sum(CASE WHEN g.RZZJ_CSZT = '0' AND g.LCJD = 42 THEN(
        CASE WHEN instr(PROCESS_DEPOSIT, '3') > 0 THEN(
        CASE WHEN <![CDATA[ (CEIL((SYSDATE - g.SHSJ)*24*60) / CEIL((g.ZJSX - g.SHSJ)*24*60)) *100 > #{ratio} ]]>
        THEN 1 ELSE 0 END)
        ELSE(
        CASE WHEN instr(PROCESS_DEPOSIT, '2') > 0 THEN(
        CASE WHEN <![CDATA[ (CEIL((SYSDATE - g.RZSJ)*24*60) / CEIL((g.SHSX - g.RZSJ)*24*60)) *100 > #{ratio} ]]>
        THEN 1 ELSE 0 END)
        ELSE
        (CASE WHEN <![CDATA[ (CEIL((SYSDATE - g.DJSJ)*24*60) / CEIL((g.SHSX - g.DJSJ)*24*60)) *100 > #{ratio} ]]>
        THEN 1 ELSE 0 END)
        END)
        END)
        ELSE 0 END) upcomingct
        FROM TF_YWPN_GDINFO_W g
        LEFT JOIN TF_YWPN_GDGLTYPEBM_W t ON g.GDLX = t.ID
        LEFT JOIN TF_YWPN_GDGLTYPEBM_W a ON g.GDXF1 = a.ID
        LEFT JOIN TF_YWPN_GDGLTYPEBM_W b ON g.GDXF2 = b.ID
        <where>
            <!--g.LCJD = #{gdglinfoDTO.lcjdid}-->
            <include refid="getByRyId"></include>
            <include refid="getCollectDetails"></include>
        </where>
        GROUP BY g.GDLX , g.GDXF1 , g.GDXF2 , t.GDLX_MC, a.GDLX_MC, b.GDLX_MC) c ) d
        <!--关联查询驳回总数 需要重新关联查询的原因是：目前需要根据流程节点查询了，所以需要另外查询后再关联；包括下面的转派个数也是-->
        LEFT JOIN (
        SELECT bb.GDLX_MC,
        <!--为防止工单细分1/2为空的情况，如果是空，根本无法使用字段关联-->
        DECODE(cc.GDLX_MC , null , '-' , cc.GDLX_MC) as GDXF1 ,
        DECODE(dd.GDLX_MC , null , '-' , dd.GDLX_MC) as GDXF2 ,
        <!--如果有重复的工单编号，则只算一条记录：去重-->
        COUNT(DISTINCT ee.GDBH) bhs
        FROM TF_YWPN_GDINFO_W aa
        LEFT JOIN TF_YWPN_GDGLTYPEBM_W bb ON aa.GDLX = bb.ID
        LEFT JOIN TF_YWPN_GDGLTYPEBM_W cc ON aa.GDXF1 = cc.ID
        LEFT JOIN TF_YWPN_GDGLTYPEBM_W dd ON aa.GDXF2 = dd.ID
        LEFT JOIN TF_YWPN_GDGLFLOW_W ee ON ee.GDBH = aa.GDBH
        <where>
            (ee.STATUS_FLAG=1 or ee.STATUS_FLAG is null)
            <include refid="getByRyId"></include>
            <include refid="getCollectDetails"></include>
            <!--因为驳回记录表中存的是流程节点字符串；并且有很多一条工单被驳回的情况，所以必须要根据流程节点筛选-->
            and ee.BBH_LCJD = #{gdglinfoDTO.lcjdName}
        </where>
        GROUP BY bb.GDLX_MC, cc.GDLX_MC, dd.GDLX_MC ) e
        ON (d.gdlxmc = e.GDLX_MC and d.gdxf1Name = e.GDXF1 and d.gdxf2Name = e.GDXF2)
        <!--关联查询转派个数-->
        LEFT JOIN (
        SELECT bbb.GDLX_MC,
        DECODE(ccc.GDLX_MC , null , '-' , ccc.GDLX_MC) as GDXF1 ,
        DECODE(ddd.GDLX_MC , null , '-' , ddd.GDLX_MC) as GDXF2 ,
        COUNT(DISTINCT eee.GDBH) as zpcount
        FROM TF_YWPN_GDINFO_W aaa
        LEFT JOIN TF_YWPN_GDGLTYPEBM_W bbb ON aaa.GDLX = bbb.ID
        LEFT JOIN TF_YWPN_GDGLTYPEBM_W ccc ON aaa.GDXF1 = ccc.ID
        LEFT JOIN TF_YWPN_GDGLTYPEBM_W ddd ON aaa.GDXF2 = ddd.ID
        LEFT JOIN TF_YWPN_REDEPLOY_W eee ON eee.GDBH = aaa.GDBH
        WHERE
        (eee.STATUS_FLAG=1 or eee.STATUS_FLAG is null)
        AND eee.LCJD = #{gdglinfoDTO.lcjdName}
        <include refid="getByRyId"></include>
        <include refid="getCollectDetails"></include>
        GROUP BY bbb.GDLX_MC, ccc.GDLX_MC, ddd.GDLX_MC ) f
        ON (d.gdlxmc = f.GDLX_MC and d.gdxf1Name = f.GDXF1 and d.gdxf2Name = f.GDXF2)
    </select>
    <select id="collectInfoByJgcz" resultType="java.util.Map">
        SELECT d.* , decode(e.bhs , null , 0, e.bhs) bhcount , decode(f.zpcount , null , 0, f.zpcount) zpcount
        FROM (
        SELECT c.* , c.waitcount + c.ybct as allCount
        FROM (
        SELECT temp.* , (temp.waitcount1+ nvl(resultdis.waitcount2,0)) as waitcount ,
        (temp.ybct1+nvl(resultdis.ybct2,0)) as ybct
        FROM (
        SELECT g.GDLX , g.GDXF1 , g.GDXF2 , t.GDLX_MC as gdlxmc ,
        <!--为防止工单细分1/2为空的情况，如果是空，根本无法使用字段关联-->
        DECODE(a.GDLX_MC, null , '-' , a.GDLX_MC) as gdxf1Name,
        DECODE(b.GDLX_MC, null , '-' , b.GDLX_MC) as gdxf2Name,
        <!--结果处置 5-->
        sum(CASE WHEN ZJCZRY = #{userId} AND g.LCJD = 43 THEN 1 ELSE 0 END ) as waitcount1 ,
        sum(CASE WHEN ZJCZRY = #{userId} AND instr(PROCESS_DEPOSIT, '5') > 0 THEN 1 ELSE 0 END) as ybct1 ,
        <!--结果处置 超时-->
        sum(CASE WHEN JGCZ_CSZT = '1' THEN 1 ELSE 0 END) as csct ,
        <!--即将超时-->
        sum(CASE WHEN g.JGCZ_CSZT = '0' AND g.LCJD = 43 THEN
        (CASE WHEN instr(PROCESS_DEPOSIT, '4') > 0 THEN(
        CASE WHEN <![CDATA[ (CEIL((SYSDATE - g.ZJSJ)*24*60) / CEIL((g.CZSX - g.ZJSJ)*24*60)) *100 > #{ratio} ]]>
        THEN 1 ELSE 0 END)
        ELSE
        (CASE WHEN instr(PROCESS_DEPOSIT, '3') > 0 THEN(
        CASE WHEN <![CDATA[ (CEIL((SYSDATE - g.SHSJ)*24*60) / CEIL((g.ZJSX - g.SHSJ)*24*60)) *100 > #{ratio} ]]>
        THEN 1 ELSE 0 END)
        ELSE(
        CASE WHEN instr(PROCESS_DEPOSIT, '2') > 0 THEN(
        CASE WHEN <![CDATA[ (CEIL((SYSDATE - g.RZSJ)*24*60) / CEIL((g.SHSX - g.RZSJ)*24*60)) *100 > #{ratio} ]]>
        THEN 1 ELSE 0 END)
        ELSE
        (CASE WHEN <![CDATA[ (CEIL((SYSDATE - g.DJSJ)*24*60) / CEIL((g.SHSX - g.DJSJ)*24*60)) *100 > #{ratio} ]]>
        THEN 1 ELSE 0 END)
        END)
        END)
        END)
        ELSE 0 END) upcomingct
        FROM TF_YWPN_GDINFO_W g
        LEFT JOIN TF_YWPN_GDGLTYPEBM_W t ON g.GDLX = t.ID
        LEFT JOIN TF_YWPN_GDGLTYPEBM_W a ON g.GDXF1 = a.ID
        LEFT JOIN TF_YWPN_GDGLTYPEBM_W b ON g.GDXF2 = b.ID
        <where>
            <!--<include refid="getByRyId"></include>-->
            (ZJCZRY = #{userId} or instr(JGCZ_PERSON , #{userId}) > 0)
            <include refid="getCollectDetails"></include>
        </where>
        GROUP BY g.GDLX , g.GDXF1 , g.GDXF2 , t.GDLX_MC, a.GDLX_MC, b.GDLX_MC) temp
        LEFT JOIN (SELECT
        aa.GDLX , aa.GDXF1 , aa.GDXF2 , bb.GDLX_MC as gdlxmc ,
        DECODE(cc.GDLX_MC, null , '-' , cc.GDLX_MC) as gdxf1Name,
        DECODE(dd.GDLX_MC, null , '-' , dd.GDLX_MC) as gdxf2Name,
        sum(CASE WHEN ZJCZRY != #{userId} AND IS_FINISH = 0 THEN 1 ELSE 0 END ) as waitcount2 ,
        sum(CASE WHEN ZJCZRY != #{userId} AND IS_FINISH = 1 THEN 1 ELSE 0 END) as ybct2
        FROM
        TF_YWPN_RESULTDISP_W ee
        LEFT JOIN TF_YWPN_GDINFO_W aa ON ee.GDBH = aa.GDBH
        LEFT JOIN TF_YWPN_GDGLTYPEBM_W bb ON aa.GDLX = bb.ID
        LEFT JOIN TF_YWPN_GDGLTYPEBM_W cc ON aa.GDXF1 = cc.ID
        LEFT JOIN TF_YWPN_GDGLTYPEBM_W dd ON aa.GDXF2 = dd.ID
        WHERE ee.PERSON_ID = #{userId}
        GROUP BY aa.GDLX , aa.GDXF1 , aa.GDXF2 , bb.GDLX_MC, cc.GDLX_MC, dd.GDLX_MC) resultdis
        ON (temp.gdlxmc = resultdis.gdlxmc AND temp.gdxf1Name = resultdis.gdxf1Name AND temp.gdxf2Name =
        resultdis.gdxf2Name)) c ) d
        <!--关联查询驳回总数 需要重新关联查询的原因是：目前需要根据流程节点查询了，所以需要另外查询后再关联；包括下面的转派个数也是-->
        LEFT JOIN (
        SELECT bb.GDLX_MC,
        <!--为防止工单细分1/2为空的情况，如果是空，根本无法使用字段关联-->
        DECODE(cc.GDLX_MC , null , '-' , cc.GDLX_MC) as GDXF1 ,
        DECODE(dd.GDLX_MC , null , '-' , dd.GDLX_MC) as GDXF2 ,
        <!--如果有重复的工单编号，则只算一条记录：去重-->
        COUNT(DISTINCT ee.GDBH) bhs
        FROM TF_YWPN_GDINFO_W aa
        LEFT JOIN TF_YWPN_GDGLTYPEBM_W bb ON aa.GDLX = bb.ID
        LEFT JOIN TF_YWPN_GDGLTYPEBM_W cc ON aa.GDXF1 = cc.ID
        LEFT JOIN TF_YWPN_GDGLTYPEBM_W dd ON aa.GDXF2 = dd.ID
        LEFT JOIN TF_YWPN_GDGLFLOW_W ee ON ee.GDBH = aa.GDBH
        <where>
            (ee.STATUS_FLAG=1 or ee.STATUS_FLAG is null)
            AND ZJCZRY = #{userId}
            <include refid="getCollectDetails"></include>
            <!--因为驳回记录表中存的是流程节点字符串；并且有很多一条工单被驳回的情况，所以必须要根据流程节点筛选-->
            and ee.BBH_LCJD = #{gdglinfoDTO.lcjdName}
        </where>
        GROUP BY bb.GDLX_MC, cc.GDLX_MC, dd.GDLX_MC ) e
        ON (d.gdlxmc = e.GDLX_MC and d.gdxf1Name = e.GDXF1 and d.gdxf2Name = e.GDXF2)
        <!--关联查询转派个数-->
        LEFT JOIN (
        SELECT bbb.GDLX_MC,
        DECODE(ccc.GDLX_MC , null , '-' , ccc.GDLX_MC) as GDXF1 ,
        DECODE(ddd.GDLX_MC , null , '-' , ddd.GDLX_MC) as GDXF2 ,
        COUNT(DISTINCT eee.GDBH) as zpcount
        FROM TF_YWPN_GDINFO_W aaa
        LEFT JOIN TF_YWPN_GDGLTYPEBM_W bbb ON aaa.GDLX = bbb.ID
        LEFT JOIN TF_YWPN_GDGLTYPEBM_W ccc ON aaa.GDXF1 = ccc.ID
        LEFT JOIN TF_YWPN_GDGLTYPEBM_W ddd ON aaa.GDXF2 = ddd.ID
        LEFT JOIN TF_YWPN_REDEPLOY_W eee ON eee.GDBH = aaa.GDBH
        WHERE
        (eee.STATUS_FLAG=1 or eee.STATUS_FLAG is null)
        AND eee.LCJD = #{gdglinfoDTO.lcjdName}
        AND ZJCZRY = #{userId}
        <include refid="getCollectDetails"></include>
        GROUP BY bbb.GDLX_MC, ccc.GDLX_MC, ddd.GDLX_MC ) f
        ON (d.gdlxmc = f.GDLX_MC and d.gdxf1Name = f.GDXF1 and d.gdxf2Name = f.GDXF2)
    </select>


    <select id="collectInfoByJgsh" resultType="java.util.Map">
        SELECT temp.* , (temp.waitcount1+NVL(auditct.waitcount2, 0)) as waitcount , (temp.ybct1+NVL(auditct.ybct2, 0))
        as ybct,
        (temp.waitcount1 + NVL(auditct.waitcount2, 0) + temp.ybct1 + NVL(auditct.ybct2, 0)) as allcount
        FROM (
        SELECT g.GDLX , g.GDXF1 , g.GDXF2 , t.GDLX_MC as gdlxmc ,
        DECODE(a.GDLX_MC, null , '-' , a.GDLX_MC) as gdxf1Name,
        DECODE(b.GDLX_MC, null , '-' , b.GDLX_MC) as gdxf2Name,
        sum(CASE WHEN JGCZRY = #{userId} AND g.LCJD = 44 THEN 1 ELSE 0 END ) as waitcount1 ,
        sum(CASE WHEN JGCZRY = #{userId} AND instr(PROCESS_DEPOSIT, '6') > 0 THEN 1 ELSE 0 END) as ybct1
        FROM TF_YWPN_GDINFO_W g
        LEFT JOIN TF_YWPN_GDGLTYPEBM_W t ON g.GDLX = t.ID
        LEFT JOIN TF_YWPN_GDGLTYPEBM_W a ON g.GDXF1 = a.ID
        LEFT JOIN TF_YWPN_GDGLTYPEBM_W b ON g.GDXF2 = b.ID
        <where>
            <include refid="getCollectDetails"></include>
        </where>
        GROUP BY g.GDLX , g.GDXF1 , g.GDXF2 , t.GDLX_MC, a.GDLX_MC, b.GDLX_MC) temp
        LEFT JOIN
        (SELECT
        aa.GDLX , aa.GDXF1 , aa.GDXF2 , cc.GDLX_MC as gdlxmc ,
        DECODE(dd.GDLX_MC, null , '-' , dd.GDLX_MC) as gdxf1Name,
        DECODE(ee.GDLX_MC, null , '-' , ee.GDLX_MC) as gdxf2Name,
        sum(CASE WHEN JGCZRY != #{userId} AND AUDIT_STATE = 0 THEN 1 ELSE 0 END ) as waitcount2 ,
        sum(CASE WHEN JGCZRY != #{userId} AND AUDIT_STATE = 1 THEN 1 ELSE 0 END) as ybct2
        FROM TF_YWPN_GDINFO_W aa JOIN TF_YMPN_AUDIT_W bb ON aa.ID = bb.AUDIT_PLAN_ID
        LEFT JOIN TF_YWPN_GDGLTYPEBM_W cc ON aa.GDLX = cc.ID
        LEFT JOIN TF_YWPN_GDGLTYPEBM_W dd ON aa.GDXF1 = dd.ID
        LEFT JOIN TF_YWPN_GDGLTYPEBM_W ee ON aa.GDXF2 = ee.ID
        where AUDIT_USER = #{userId} AND AUDIT_TYPE = '12'
        GROUP BY aa.GDLX , aa.GDXF1 , aa.GDXF2 , cc.GDLX_MC, dd.GDLX_MC, ee.GDLX_MC) auditct
        ON (temp.gdlxmc = auditct.gdlxmc AND temp.gdxf1Name = auditct.gdxf1Name AND temp.gdxf2Name = auditct.gdxf2Name)
        WHERE (temp.waitcount1!=0 or temp.ybct1!=0 or auditct.waitcount2!=0 or auditct.ybct2!=0 )

    </select>


    <sql id="getCollectDetails">
        <if test="gdglinfoDTO.gdlx != null">
            AND GDLX = #{gdglinfoDTO.gdlx}
        </if>
        <if test="gdglinfoDTO.gdxf1 != null">
            AND GDXF1 = #{gdglinfoDTO.gdxf1}
        </if>
        <if test="gdglinfoDTO.gdxf2 != null">
            AND GDXF2 = #{gdglinfoDTO.gdxf2}
        </if>
        <if test="gdglinfoDTO.inputcontent != null and gdglinfoDTO.inputcontent != ''">
            AND (GDBH LIKE '%' || #{gdglinfoDTO.inputcontent} || '%' OR GDMS LIKE '%' || #{gdglinfoDTO.inputcontent} ||
            '%')
        </if>
        <if test="gdglinfoDTO.startTime != null and gdglinfoDTO.endTime != null">
            AND DJSJ BETWEEN #{gdglinfoDTO.startTime} AND #{gdglinfoDTO.endTime}
        </if>
    </sql>

    <sql id="getByRyId">
        <if test="gdglinfoDTO.lcjdid == 39">
            AND DJRY = #{userId}
        </if>
        <if test="gdglinfoDTO.lcjdid == 40">
            AND (SLRY LIKE '%' || #{userId} || '%'  or RZRY = #{userId})
        </if>
        <if test="gdglinfoDTO.lcjdid == 41">
            AND (RZSLRY = #{userId} or SHRY = #{userId})
        </if>
        <if test="gdglinfoDTO.lcjdid == 42">
            AND (SHSLRY = #{userId} or ZJRY = #{userId})
        </if>
        <if test="gdglinfoDTO.lcjdid == 43">
            AND (ZJCZRY = #{userId} or CZRY = #{userId})
        </if>
    </sql>


    <select id="getCollectDetailsByBh" resultMap="gdglinfoMap">
        SELECT *
        FROM TF_YWPN_GDINFO_W
        <where>
            BHZT = '1'
            <include refid="getByRyId"></include>
            AND GDBH IN
            (SELECT GDBH
            FROM TF_YWPN_GDGLFLOW_W
            WHERE BBH_LCJD = #{gdglinfoDTO.lcjdName} and (STATUS_FLAG = '1' or STATUS_FLAG is null)
            GROUP BY GDBH)
            <include refid="getCollectDetails"></include>
        </where>
        ORDER BY DJSJ
    </select>

    <select id="getCollectDetailsByZp" resultMap="gdglinfoMap">
        SELECT * FROM TF_YWPN_GDINFO_W
        <where>
            ZPZT = '1'
            <include refid="getByRyId"></include>
            AND GDBH IN
            (SELECT GDBH
            FROM TF_YWPN_REDEPLOY_W
            WHERE LCJD = #{gdglinfoDTO.lcjdName} and STATUS_FLAG = '1'
            GROUP BY GDBH)
            <include refid="getCollectDetails"></include>
        </where>
    </select>


    <select id="collectGdIndex" resultType="map" databaseId="oracle">
        SELECT temp.* , nvl(temp.jgzt + nvl(auditct.auditnum,0) , 0)as jgshzt FROM (SELECT g.GDLX , t.GDLX_MC ,
        sum(CASE WHEN DJRY = #{userId} THEN 1 ELSE 0 END) as djzt,
        sum(CASE WHEN SLRY LIKE '%' || #{userId} || '%' or RZRY = #{userId} THEN 1 ELSE 0 END) as rzzt,
        sum(CASE WHEN RZSLRY = #{userId} or SHRY = #{userId} THEN 1 ELSE 0 END) as shzt,
        sum(CASE WHEN SHSLRY = #{userId} or ZJRY = #{userId} THEN 1 ELSE 0 END) as zjzt,
        sum(CASE WHEN ZJCZRY = #{userId} or instr(JGCZ_PERSON, #{userId}) > 0 or CZRY = #{userId} THEN 1 ELSE 0 END) as
        czzt,
        sum(CASE WHEN JGCZRY = #{userId} THEN 1 ELSE 0 END) as jgzt
        FROM TF_YWPN_GDINFO_W g
        LEFT JOIN TF_YWPN_GDGLTYPEBM_W t ON (g.GDLX = t.ID)
        <where>
            <if test="model.gdlx != null ">
                and GDLX = #{model.gdlx}
            </if>
            <if test="model.startTime != null ">
                and DJSJ >= #{model.startTime}
            </if>
            <if test="model.endTime != null ">
                <![CDATA[ and DJSJ <= #{model.endTime}   ]]>
            </if>
        </where>
        GROUP BY g.GDLX, t.GDLX_MC) temp LEFT JOIN (SELECT aa.GDLX , sum(CASE WHEN JGCZRY = #{userId} THEN 0 ELSE 1 END)
        auditnum FROM TF_YWPN_GDINFO_W aa JOIN TF_YMPN_AUDIT_W bb
        ON aa.ID = bb.AUDIT_PLAN_ID
        <where>
            AUDIT_USER = #{userId}
            AND AUDIT_TYPE = '12'
            <if test="model.gdlx != null ">
                and GDLX = #{model.gdlx}
            </if>
            <if test="model.startTime != null ">
                and DJSJ >= #{model.startTime}
            </if>
            <if test="model.endTime != null ">
                <![CDATA[ and DJSJ <= #{model.endTime}   ]]>
            </if>
        </where>
        GROUP BY aa.GDLX) auditct ON temp.GDLX = auditct.GDLX
        WHERE (temp.djzt!=0 or temp.rzzt!=0 or temp.shzt!=0 or temp.zjzt!=0 or temp.jgzt!=0 or auditct.auditnum!=0 or
        temp.czzt!=0)
    </select>

    <select id="collectGdAll" resultMap="gdglinfoMap">
        SELECT * FROM TF_YWPN_GDINFO_W
        WHERE 1=1
        <include refid="getCollectDetails"></include>
        <if test="gdglinfoDTO.lcjdid == 39">
            AND DJRY = #{userId}
            <!--已办-->
            <if test="gdglinfoDTO.queryState == 2 ">
                AND instr(PROCESS_DEPOSIT, '1') > 0
            </if>
            <!--超时-->
            <if test="gdglinfoDTO.queryState == 3 ">
                AND GDCS_FLAG = '1'
            </if>
            <!--终止-->
            <if test="gdglinfoDTO.queryState == 5 ">
                AND GDZZZT = 1
            </if>
        </if>
        <if test="gdglinfoDTO.lcjdid == 40">
            AND SLRY LIKE '%' || #{userId} || '%'
            <!--已办-->
            <if test="gdglinfoDTO.queryState == 2 ">
                AND instr(PROCESS_DEPOSIT, '2') > 0
            </if>
            <!--超时-->
            <if test="gdglinfoDTO.queryState == 3 ">
                AND RZCZ_CSZT = '1'
            </if>
        </if>
        <if test="gdglinfoDTO.lcjdid == 41">
            AND RZSLRY = #{userId}
            <!--已办-->
            <if test="gdglinfoDTO.queryState == 2 ">
                AND instr(PROCESS_DEPOSIT, '3') > 0
            </if>
            <!--超时-->
            <if test="gdglinfoDTO.queryState == 3 ">
                AND RESH_CSZT = '1'
            </if>
        </if>
        <if test="gdglinfoDTO.lcjdid == 42">
            AND SHSLRY = #{userId}
            <!--已办-->
            <if test="gdglinfoDTO.queryState == 2 ">
                AND instr(PROCESS_DEPOSIT, '4') > 0
            </if>
            <!--超时-->
            <if test="gdglinfoDTO.queryState == 3 ">
                AND RZZJ_CSZT = '1'
            </if>
        </if>
        <if test="gdglinfoDTO.lcjdid == 43">
            AND ZJCZRY = #{userId}
            <!--已办-->
            <if test="gdglinfoDTO.queryState == 2 ">
                AND instr(PROCESS_DEPOSIT, '5') > 0
            </if>
            <!--超时-->
            <if test="gdglinfoDTO.queryState == 3 ">
                AND JGCZ_CSZT = '1'
            </if>
        </if>
        <!--代办-->
        <if test="gdglinfoDTO.queryState == 1 ">
            AND LCJD = #{gdglinfoDTO.lcjdid}
        </if>
        <!--驳回-->
        <if test="gdglinfoDTO.queryState == 4 ">
            AND GDBH IN (
            (SELECT GDBH
            FROM TF_YWPN_GDGLFLOW_W
            WHERE BBH_LCJD = #{gdglinfoDTO.lcjdName}
            AND (STATUS_FLAG = '1' or STATUS_FLAG is null)
            GROUP BY GDBH))
        </if>
    </select>
    <select id="collectGdAllByRzzj" resultMap="gdglinfoMap">
        SELECT * FROM TF_YWPN_GDINFO_W
        WHERE 1=1
        <include refid="getCollectDetails"></include>
        <if test="gdglinfoDTO.queryState == null or gdglinfoDTO.queryState == ''">
            AND (instr(PROCESS_DEPOSIT, '4') > 0 or LCJD = #{gdglinfoDTO.lcjdid})
            <include refid="getByRyId"></include>
        </if>
        <!--已办-->
        <if test="gdglinfoDTO.queryState == 2 ">
            AND ZJRY = #{userId}
            AND instr(PROCESS_DEPOSIT, '4') > 0
        </if>
        <!--超时-->
        <if test="gdglinfoDTO.queryState == 3 ">
            <include refid="getByRyId"></include>
            AND RZZJ_CSZT = '1'
        </if>
        <!--代办-->
        <if test="gdglinfoDTO.queryState == 1 ">
            AND SHSLRY = #{userId}
            AND LCJD = #{gdglinfoDTO.lcjdid}
        </if>
        <!--驳回-->
        <if test="gdglinfoDTO.queryState == 4 ">
            <include refid="getByRyId"></include>
            AND GDBH IN (
            (SELECT GDBH
            FROM TF_YWPN_GDGLFLOW_W
            WHERE BBH_LCJD = #{gdglinfoDTO.lcjdName}
            AND (STATUS_FLAG = '1' or STATUS_FLAG is null)
            GROUP BY GDBH))
        </if>
    </select>

    <select id="collectGdAllByJgcz" resultMap="gdglinfoMap">
        SELECT * FROM TF_YWPN_GDINFO_W
        WHERE 1=1
        <include refid="getCollectDetails"></include>
        <if test="gdglinfoDTO.queryState == null or gdglinfoDTO.queryState == ''">
            AND GDBH IN (SELECT GDBH FROM TF_YWPN_RESULTDISP_W WHERE PERSON_ID = #{userId})
        </if>
        <!--已办-->
        <if test="gdglinfoDTO.queryState == 2 ">
            AND GDBH IN (SELECT GDBH FROM TF_YWPN_RESULTDISP_W WHERE PERSON_ID = #{userId} and IS_FINISH = '1')
            <!--AND instr(PROCESS_DEPOSIT, '5') > 0-->
        </if>
        <!--超时-->
        <if test="gdglinfoDTO.queryState == 3 ">
            AND JGCZ_CSZT = '1'
            AND GDBH IN (SELECT GDBH FROM TF_YWPN_RESULTDISP_W WHERE PERSON_ID = #{userId})
        </if>
        <!--代办-->
        <if test="gdglinfoDTO.queryState == 1 ">
            <!--AND LCJD = #{gdglinfoDTO.lcjdid}
            AND JGCZ_PERSON LIKE '%' || #{userId} || '%'-->
            AND (GDBH IN (SELECT GDBH FROM TF_YWPN_RESULTDISP_W WHERE PERSON_ID = #{userId} and IS_FINISH = '0')
            or (LCJD = #{gdglinfoDTO.lcjdid} and ZJCZRY = #{userId}))
        </if>
        <!--驳回-->
        <if test="gdglinfoDTO.queryState == 4 ">
            AND GDBH IN (SELECT GDBH FROM TF_YWPN_RESULTDISP_W WHERE PERSON_ID = #{userId})
            AND GDBH IN (
            (SELECT GDBH
            FROM TF_YWPN_GDGLFLOW_W
            WHERE BBH_LCJD = #{gdglinfoDTO.lcjdName}
            AND (STATUS_FLAG = '1' or STATUS_FLAG is null)
            GROUP BY GDBH))
        </if>
    </select>

    <select id="collectGdAllByJgsh" resultMap="gdglinfoMap">
        SELECT * FROM TF_YWPN_GDINFO_W
        WHERE 1=1
        <include refid="getCollectDetails"></include>
        <if test="gdglinfoDTO.queryState == null or gdglinfoDTO.queryState == ''">
            AND ((ID IN (SELECT AUDIT_PLAN_ID FROM TF_YMPN_AUDIT_W WHERE AUDIT_USER = #{userId}))
            or (jgczry =#{userId}))
        </if>
        <!--已办-->
        <if test="gdglinfoDTO.queryState == 2 ">
            AND ((ID IN (SELECT AUDIT_PLAN_ID FROM TF_YMPN_AUDIT_W WHERE AUDIT_USER = #{userId} AND AUDIT_TYPE = '12'
            AND AUDIT_STATE IN
            ('1','2')))
            or (jgczry =#{userId} AND instr(PROCESS_DEPOSIT, '6') > 0))
        </if>
        <!--代办-->
        <if test="gdglinfoDTO.queryState == 1 ">
            AND LCJD = #{gdglinfoDTO.lcjdid}
            AND ((ID IN (SELECT AUDIT_PLAN_ID FROM TF_YMPN_AUDIT_W WHERE AUDIT_USER = #{userId} AND AUDIT_TYPE = '12'
            AND AUDIT_STATE IN
            ('0')))
            or (jgczry =#{userId}))
        </if>
    </select>

    <select id="collectGdAllBygddj" resultMap="gdglinfoMap">
        SELECT * FROM TF_YWPN_GDINFO_W
        WHERE 1=1
        <include refid="getCollectDetails"></include>
        AND DJRY = #{userId}
        <!--已办-->
        <if test="gdglinfoDTO.queryState == 2 ">
            AND instr(PROCESS_DEPOSIT, '1') > 0
        </if>
        <!--超时-->
        <if test="gdglinfoDTO.queryState == 3 ">
            AND GDCS_FLAG = '1'
        </if>
        <!--终止-->
        <if test="gdglinfoDTO.queryState == 5 ">
            AND GDZZZT = 1
        </if>
        <!--代办-->
        <if test="gdglinfoDTO.queryState == 1 ">
            AND LCJD = #{gdglinfoDTO.lcjdid}
        </if>
        <!--驳回-->
        <if test="gdglinfoDTO.queryState == 4 ">
            AND GDBH IN (
            (SELECT GDBH
            FROM TF_YWPN_GDGLFLOW_W
            WHERE BBH_LCJD = #{gdglinfoDTO.lcjdName}
            AND (STATUS_FLAG = '1' or STATUS_FLAG is null)
            GROUP BY GDBH))
        </if>
    </select>
    <select id="collectGdAllByRzcz" resultMap="gdglinfoMap">
        SELECT * FROM TF_YWPN_GDINFO_W
        WHERE 1=1
        <include refid="getCollectDetails"></include>
        <if test="gdglinfoDTO.queryState == null or gdglinfoDTO.queryState == ''">
            AND (instr(PROCESS_DEPOSIT, '2') > 0 or LCJD = #{gdglinfoDTO.lcjdid})
            <include refid="getByRyId"></include>
        </if>
        <!--已办-->
        <if test="gdglinfoDTO.queryState == 2 ">
            AND RZRY = #{userId}
            AND instr(PROCESS_DEPOSIT, '2') > 0
        </if>
        <!--超时-->
        <if test="gdglinfoDTO.queryState == 3 ">
            <include refid="getByRyId"></include>
            AND RZCZ_CSZT = '1'
        </if>
        <!--代办-->
        <if test="gdglinfoDTO.queryState == 1 ">
            AND SLRY LIKE '%' || #{userId} || '%'
            AND LCJD = #{gdglinfoDTO.lcjdid}
        </if>
        <!--驳回-->
        <if test="gdglinfoDTO.queryState == 4 ">
            <include refid="getByRyId"></include>
            AND GDBH IN (
            (SELECT GDBH
            FROM TF_YWPN_GDGLFLOW_W
            WHERE BBH_LCJD = #{gdglinfoDTO.lcjdName}
            AND (STATUS_FLAG = '1' or STATUS_FLAG is null)
            GROUP BY GDBH))
        </if>
    </select>
    <select id="collectGdAllByRzsh" resultMap="gdglinfoMap">
        SELECT * FROM TF_YWPN_GDINFO_W
        WHERE 1=1
        <include refid="getCollectDetails"></include>
        <if test="gdglinfoDTO.queryState == null or gdglinfoDTO.queryState == ''">
            AND (instr(PROCESS_DEPOSIT, '3') > 0 or LCJD = #{gdglinfoDTO.lcjdid})
            <include refid="getByRyId"></include>
        </if>
        <!--已办-->
        <if test="gdglinfoDTO.queryState == 2 ">
            AND RZSLRY = #{userId}
            AND instr(PROCESS_DEPOSIT, '3') > 0
        </if>
        <!--超时-->
        <if test="gdglinfoDTO.queryState == 3 ">
            <include refid="getByRyId"></include>
            AND RESH_CSZT = '1'
        </if>
        <!--代办-->
        <if test="gdglinfoDTO.queryState == 1 ">
            AND SHRY = #{userId}
            AND LCJD = #{gdglinfoDTO.lcjdid}
        </if>
        <!--驳回-->
        <if test="gdglinfoDTO.queryState == 4 ">
            <include refid="getByRyId"></include>
            AND GDBH IN (
            (SELECT GDBH
            FROM TF_YWPN_GDGLFLOW_W
            WHERE BBH_LCJD = #{gdglinfoDTO.lcjdName}
            AND (STATUS_FLAG = '1' or STATUS_FLAG is null)
            GROUP BY GDBH))
        </if>
    </select>


    <select id="collectRXGDCompleteErrorInfo" resultType="map" databaseId="oracle">
        select c.* , d.gdlx_mc from (SELECT a.*,ct-ywc as wwc,decode(ct,0,0,round(ywc/ct*100,2))||'%' as wcbfb,b.*
        ,decode(hfcs,0,0,round( (fcme+me)/hfcs*100,2))||'%'as myl FROM(
        SELECT COUNT(g.ID) ct,
        sum(case g.LCJD when 45 then 1 else 0 end) as ywc ,g.GDLX gdlx1
        FROM TF_YWPN_GDINFO_W g
        WHERE IS_RXLX = '1'
        <if test="model.startTime != null ">
            and DJSJ >= #{model.startTime}
        </if>
        <if test="model.endTime != null ">
            <![CDATA[ and DJSJ <= #{model.endTime}   ]]>
        </if>
        GROUP BY g.GDLX) a , (
        SELECT count(b.ID) hfcs,SUM(decode(b.RETURN_RESLUT,'3',1,0)) as fcme,
        SUM(decode(b.RETURN_RESLUT,'2',1,0)) as me,
        SUM(decode(b.RETURN_RESLUT,'1',1,0)) as yb,
        SUM(decode(b.RETURN_RESLUT,'0',1,0)) as bme,
        g.GDLX gdlx2
        FROM TF_YWPN_GDINFO_W g
        LEFT JOIN TF_YWPN_GDRETURN_W b ON (g.GDBH = b.GDBH)
        WHERE g.IS_RXLX = '1'
        <if test="model.startTime != null ">
            and g.DJSJ >= #{model.startTime}
        </if>
        <if test="model.endTime != null ">
            <![CDATA[ and g.DJSJ <= #{model.endTime}   ]]>
        </if>
        GROUP BY g.GDLX) b WHERE a.gdlx1 = b.gdlx2) c , TF_YWPN_GDGLTYPEBM_W d WHERE c.gdlx2 = d.ID
    </select>

    <resultMap type="com.tofly.xrtymis.custom.vo.GdAbnormalPercentStatic" id="getGdAbnormalPercentStatic">
        <result property="gdlx" column="gdlx"/>
        <result property="gdxf1" column="GDXF1"/>
        <result property="gdxf2" column="GDXF2"/>
        <result property="gdlxName" column="gdlxName"/>
        <result property="gdNum" column="gdNum"/>
        <result property="bhNum" column="bhNum"/>
        <result property="csNum" column="csNum"/>
        <result property="zpNum" column="zpNum"/>
        <result property="zzNum" column="zzNum"/>
        <result property="bhRate" column="bhRate"/>
        <result property="csRate" column="csRate"/>
        <result property="zpRate" column="zpRate"/>
        <result property="zzRate" column="zzRate"/>
        <result property="djbm" column="DJBM"/>
        <association property="djbmName" column="DJBM" select="zjbmName"/>
        <association property="gdxf1Name" column="GDXF1" select="getGdxf1Name"/>
        <association property="gdxf2Name" column="GDXF2" select="getGdxf2Name"/>
    </resultMap>
    <select id="collectGDCompleteErrorDetailsInfo" resultMap="getGdAbnormalPercentStatic" databaseId="oracle">
        SELECT n.*,round(n.bhNum/n.gdNum*100,2)||'%' as bhRate,round(n.csNum/n.gdNum*100,2)||'%' as csRate,
        round(n.zpNum/n.gdNum*100,2)||'%' as zpRate, round(n.zzNum/n.gdNum*100,2)||'%' as zzRate
        FROM
        (SELECT a.GDLX as gdlx,GDLX_MC as gdlxName,a.GDXF1,a.GDXF2,ct as gdNum,zzs as zzNum,bhgds as bhNum,zpgds as zpNum,csgds as csNum
        FROM(
        SELECT g.DJBM,g.GDLX,g.GDXF1,g.GDXF2,t.GDLX_MC,COUNT(distinct g.ID) ct,SUM(decode(g.BHZT,'1',1,0)) bhgds,SUM(decode(g.ZPZT,'1',1,0))
        zpgds,
        SUM(decode(g.RZCZ_CSZT,'1',1,0)+decode(g.RESH_CSZT,'1',1,0)+decode(g.RZZJ_CSZT,'1',1,0)+decode(g.JGCZ_CSZT,'1',1,0))
        as css,
        SUM(decode(g.RZCZ_CSZT,'1',1,decode(g.RESH_CSZT,'1',1,decode(g.RZZJ_CSZT,'1',1,decode(g.JGCZ_CSZT,'1',1,0)))))
        as csgds,
        SUM(decode(g.GDDJ_ZT,'54',1,0)) as zzs
        FROM TF_YWPN_GDINFO_W g
        LEFT JOIN TF_YWPN_GDGLTYPEBM_W t ON (g.GDLX = t.ID)
        WHERE 1=1
        <if test="model.startTime != null ">
            and DJSJ >= #{model.startTime}
        </if>
        <if test="model.deptIdList != null and model.deptIdList != '' ">
            and DJBM in
            <foreach collection="model.deptIdList.split(',')" item="id" open="(" separator="," close=")">
                #{id}
            </foreach>
        </if>
        <if test="model.gdlxList != null and model.gdlxList != '' ">
            and g.GDLX in
            <foreach collection="model.gdlxList.split(',')" item="id" open="(" separator="," close=")">
                #{id}
            </foreach>
        </if>
        <if test="model.isRxlx != null ">
            and IS_RXLX = #{model.isRxlx}
        </if>
        <if test="model.endTime != null ">
            <![CDATA[ and DJSJ <= #{model.endTime}   ]]>
        </if>
<!--        <if test="model.gdlx != null ">-->
<!--            and g.GDLX = #{model.gdlx}-->
<!--        </if>-->
        GROUP BY g.GDLX,g.GDXF1,g.GDXF2,t.GDLX_MC,g.DJBM) a LEFT JOIN (
        SELECT g.GDLX,SUM(decode(b.id,null,0,1)) as bhs,
        SUM(decode(z.id,null,0,1)) as zps
        FROM TF_YWPN_GDINFO_W g
        LEFT JOIN TF_YWPN_GDGLFLOW_W b ON (g.GDBH = b.GDBH)
        LEFT JOIN TF_YWPN_REDEPLOY_W z ON (g.GDBH = z.GDBH)
        WHERE (b.STATUS_FLAG=1 or b.STATUS_FLAG is null)
        <if test="model.startTime != null ">
            and DJSJ >= #{model.startTime}
        </if>
        <if test="model.endTime != null ">
            <![CDATA[ and DJSJ <= #{model.endTime}   ]]>
        </if>
        <if test="model.gdlx != null ">
            and g.GDLX = #{model.gdlx}
        </if>
        GROUP BY g.GDLX
        ) b on(a.gdlx=b.GDLX)) n

    </select>
    <select id="collectGDCompleteErrorInfo" resultMap="getGdAbnormalPercentStatic" databaseId="oracle">
        SELECT n.*,round(n.bhNum/n.gdNum*100,2)||'%' as bhRate,round(n.csNum/n.gdNum*100,2)||'%' as csRate,
        round(n.zpNum/n.gdNum*100,2)||'%' as zpRate, round(n.zzNum/n.gdNum*100,2)||'%' as zzRate
        FROM
        (SELECT a.GDLX as gdlx,GDLX_MC as gdlxName,ct as gdNum,zzs as zzNum,bhgds as bhNum,zpgds as zpNum,csgds as csNum
        FROM(
        SELECT g.GDLX,t.GDLX_MC,COUNT(distinct g.ID) ct,SUM(decode(g.BHZT,'1',1,0)) bhgds,SUM(decode(g.ZPZT,'1',1,0))
        zpgds,
        SUM(decode(g.RZCZ_CSZT,'1',1,0)+decode(g.RESH_CSZT,'1',1,0)+decode(g.RZZJ_CSZT,'1',1,0)+decode(g.JGCZ_CSZT,'1',1,0))
        as css,
        SUM(decode(g.RZCZ_CSZT,'1',1,decode(g.RESH_CSZT,'1',1,decode(g.RZZJ_CSZT,'1',1,decode(g.JGCZ_CSZT,'1',1,0)))))
        as csgds,
        SUM(decode(g.GDDJ_ZT,'54',1,0)) as zzs
        FROM TF_YWPN_GDINFO_W g
        LEFT JOIN TF_YWPN_GDGLTYPEBM_W t ON (g.GDLX = t.ID)
        WHERE 1=1
        <if test="model.startTime != null ">
            and DJSJ >= #{model.startTime}
        </if>
        <if test="model.deptIdList != null and model.deptIdList != '' ">
            and DJBM in
            <foreach collection="model.deptIdList.split(',')" item="id" open="(" separator="," close=")">
                #{id}
            </foreach>
        </if>
        <if test="model.isRxlx != null ">
            and IS_RXLX = #{model.isRxlx}
        </if>
        <if test="model.endTime != null ">
            <![CDATA[ and DJSJ <= #{model.endTime}   ]]>
        </if>
        <if test="model.gdlxList != null and model.gdlxList != '' ">
            and g.GDLX in
            <foreach collection="model.gdlxList.split(',')" item="id" open="(" separator="," close=")">
                #{id}
            </foreach>
        </if>
        GROUP BY g.GDLX,t.GDLX_MC) a LEFT JOIN (
        SELECT g.GDLX,SUM(decode(b.id,null,0,1)) as bhs,
        SUM(decode(z.id,null,0,1)) as zps
        FROM TF_YWPN_GDINFO_W g
        LEFT JOIN TF_YWPN_GDGLFLOW_W b ON (g.GDBH = b.GDBH)
        LEFT JOIN TF_YWPN_REDEPLOY_W z ON (g.GDBH = z.GDBH)
        WHERE (b.STATUS_FLAG=1 or b.STATUS_FLAG is null)
        <if test="model.startTime != null ">
            and DJSJ >= #{model.startTime}
        </if>
        <if test="model.endTime != null ">
            <![CDATA[ and DJSJ <= #{model.endTime}   ]]>
        </if>
        <if test="model.gdlx != null ">
            and g.GDLX = #{model.gdlx}
        </if>
        GROUP BY g.GDLX
        ) b on(a.gdlx=b.GDLX)) n

    </select>
    <select id="collectDeptGDCompleteErrorInfo" resultMap="getGdAbnormalPercentStatic" databaseId="oracle">
        SELECT n.*,round(n.bhNum/n.gdNum*100,2)||'%' as bhRate,round(n.csNum/n.gdNum*100,2)||'%' as csRate,
        round(n.zpNum/n.gdNum*100,2)||'%' as zpRate, round(n.zzNum/n.gdNum*100,2)||'%' as zzRate
        FROM
        (SELECT a.DJBM,ct as gdNum,zzs as zzNum,bhgds as bhNum,zpgds as zpNum,csgds as csNum
        FROM(
        SELECT g.DJBM,COUNT(distinct g.ID) ct,SUM(decode(g.BHZT,'1',1,0)) bhgds,SUM(decode(g.ZPZT,'1',1,0))
        zpgds,
        SUM(decode(g.RZCZ_CSZT,'1',1,0)+decode(g.RESH_CSZT,'1',1,0)+decode(g.RZZJ_CSZT,'1',1,0)+decode(g.JGCZ_CSZT,'1',1,0))
        as css,
        SUM(decode(g.RZCZ_CSZT,'1',1,decode(g.RESH_CSZT,'1',1,decode(g.RZZJ_CSZT,'1',1,decode(g.JGCZ_CSZT,'1',1,0)))))
        as csgds,
        SUM(decode(g.GDDJ_ZT,'54',1,0)) as zzs
        FROM TF_YWPN_GDINFO_W g
        LEFT JOIN TF_YWPN_GDGLTYPEBM_W t ON (g.GDLX = t.ID)
        WHERE 1=1
        <if test="model.startTime != null ">
            and DJSJ >= #{model.startTime}
        </if>
        <if test="model.deptIdList != null and model.deptIdList != '' ">
            and DJBM in
            <foreach collection="model.deptIdList.split(',')" item="id" open="(" separator="," close=")">
                #{id}
            </foreach>
        </if>
        <if test="model.isRxlx != null ">
            and IS_RXLX = #{model.isRxlx}
        </if>
        <if test="model.endTime != null ">
            <![CDATA[ and DJSJ <= #{model.endTime}   ]]>
        </if>
        <if test="model.gdlxList != null and model.gdlxList != '' ">
            and g.GDLX in
            <foreach collection="model.gdlxList.split(',')" item="id" open="(" separator="," close=")">
                #{id}
            </foreach>
        </if>
        and g.DJBM is not null
        GROUP BY g.DJBM) a LEFT JOIN (
        SELECT g.DJBM,SUM(decode(b.id,null,0,1)) as bhs,
        SUM(decode(z.id,null,0,1)) as zps
        FROM TF_YWPN_GDINFO_W g
        LEFT JOIN TF_YWPN_GDGLFLOW_W b ON (g.GDBH = b.GDBH)
        LEFT JOIN TF_YWPN_REDEPLOY_W z ON (g.GDBH = z.GDBH)
        WHERE (b.STATUS_FLAG=1 or b.STATUS_FLAG is null)
        <if test="model.startTime != null ">
            and DJSJ >= #{model.startTime}
        </if>
        <if test="model.endTime != null ">
            <![CDATA[ and DJSJ <= #{model.endTime}   ]]>
        </if>
        <if test="model.deptIdList != null and model.deptIdList != '' ">
            and DJBM in
            <foreach collection="model.deptIdList.split(',')" item="id" open="(" separator="," close=")">
                #{id}
            </foreach>
        </if>
        <if test="model.gdlxList != null and model.gdlxList != '' ">
            and g.GDLX in
            <foreach collection="model.gdlxList.split(',')" item="id" open="(" separator="," close=")">
                #{id}
            </foreach>
        </if>
        <if test="model.isRxlx != null ">
            and IS_RXLX = #{model.isRxlx}
        </if>
        GROUP BY g.DJBM
        ) b on(a.DJBM=b.DJBM)) n

    </select>

    <select id="selectSpotCheckInfo" resultType="Gdglinfo" databaseId="oracle">
        SELECT * FROM (
        SELECT g.*,rownum as vseq ,t.GDLX_MC as gdlxName ,x.GDLX_MC as gdxf1Name,j.CNAME as jjcdName ,u.real_name as
        djryName,td.CNAME as lcjdName
        FROM TF_YWPN_GDINFO_W g
        LEFT JOIN TF_YWPN_GDGLTYPEBM_W t ON (g.GDLX = t.ID)
        LEFT JOIN TF_YWPN_GDGLTYPEBM_W x ON (g.GDXF1 = x.ID)
        left Join TF_YWPN_SYSCHILDCODE_D j on (g.jjcd=j.id)
        left join tf_smpn_user_x u on (g.djry =u.id)
        LEFT JOIN TF_YWPN_SYSCHILDCODE_D td on (g.lcjd = td.id)
        WHERE g.LCJD =45
        <if test="isRxlx != null ">
            AND g.IS_RXLX = #{isRxlx}
        </if>
        AND DJSJ >= #{model.startTime}
        <![CDATA[ and DJSJ <= #{model.endTime}   ]]>
        ORDER BY g.ID )b WHERE
        <![CDATA[ b.vseq <= #{number}   ]]>

    </select>

    <select id="loadTabTypeInfo" resultType="Gdglinfo" databaseId="oracle">
        SELECT i.ID FROM TF_YWPN_GDINFO_W i
        LEFT JOIN TF_YWPN_GDYWCONFIG_W g ON (i.LCID = g.id)
        WHERE 1=1
        <if test="map.gdlx != null ">
            AND i.GDLX= #{map.gdlx}
        </if>
        <if test="map.lcjd != null ">
            AND i.LCJD= #{map.lcjd}
        </if>
        <if test="map.tabtype != null ">
            AND g.TAB_TYPE= #{map.tabtype}
        </if>
        <if test="status != null and status.trim() != ''">
            AND i.IS_WATERMETER_STATUS= #{status}
        </if>
        <if test="stTime != null ">
            and i.DJSJ >= #{stTime}
        </if>
        <if test="enTime != null ">
            <![CDATA[ and i.DJSJ <= #{enTime}   ]]>
        </if>
    </select>

    <sql id="reminder">
        (select count(*)
         from TF_YWPN_MESSAGEPUSH_W
         where TYPE = '6'
           and TOPIC like '%' || ${gdbh} || '%')

    </sql>

    <sql id="userNameQuery">
            (select REAL_NAME from TF_SMPN_USER_X u where ${userId} = u.ID)
            clry_name,
    </sql>

    <sql id="deptNameQuery">
            (select NAME from TF_SMPN_DEPARTMENT_X d where ${deptId} = d.ID)
            clbm_name,
    </sql>

    <sql id="sum_count">
        (select count(*)
        from TF_YWPN_GDINFO_W i
        left join TF_YWPN_GDRETURN_W r on i.GDBH = r.GDBH
        where JDZT = 1
        <choose>
            <when test="dto.start != null and dto.end != null">
                and to_char(DJSJ,'yyyy-mm-dd hh24:mi:ss') between #{dto.start} and #{dto.end}
            </when>
            <otherwise>
                and djsj between add_months(sysdate,-1) and sysdate
            </otherwise>
        </choose>
        <if test="dto.gdlx != null">
            and i.GDLX = #{dto.gdlx}
        </if>
        <if test="dto.gdxf1 != null">
            and gdxf1 = #{dto.gdxf1}
        </if>
        <if test="dto.gdxf2 != null">
            and gdxf2 = #{dto.gdxf2}
        </if>
        <if test="dto.gdzt != null">
            and i.lcjd = #{dto.gdzt}
        </if>
        <if test="dto.zzzt != null">
            and i.GDZZZT = #{dto.zzzt}
        </if>
        <if test="dto.cdzt != null">
            and decode(
            <include refid="reminder">
                <property name="gdbh" value="i.gdbh"/>
            </include>
            ,0,'未催单','已催单') = #{dto.cdzt}
        </if>
        <if test="dto.gdflx != null">
            and GDGZLX = #{dto.gdflx}
        </if>
        <if test="dto.hfzt != null">
            and decode(BHZT, '0', '无驳回', '1', '有驳回') = #{dto.hfzt}
        </if>
        <if test="dto.str != null">
            and i.gdbh || i.khbh || i.khxm || i.khdz || i.lxdh like '%' || #{dto.str} || '%'
        </if>
        <if test="dto.djry">
            and i.djry = #{dto.djry}
        </if>
        )
    </sql>

    <select id="gdInfoQuery" resultType="map"  databaseId="oracle">
        select
        i.ID,
        HANG_UP,
        sjdh,
        i.GDBH,
        i.ldhm,
        (select cname from TF_YWPN_SYSCHILDCODE_D s where s.id = i.LCJD) lcjd_name,
        (SELECT GDLX_MC FROM TF_YWPN_GDGLTYPEBM_W WHERE ID = GDLX) gdlx_name,
        GDLX,
        (SELECT GDLX_MC FROM TF_YWPN_GDGLTYPEBM_W WHERE ID = GDXF1) gdxf1_name,
        GDXF1,
        (SELECT GDLX_MC FROM TF_YWPN_GDGLTYPEBM_W WHERE ID = GDXF2) gdxf2_name,
        GDXF2,
        KHBH,
        LCID,
        GDDJ_ZT,
        PROCESS_DEPOSIT,
        KHXM,
        KHDZ,
        LXDH,
        GDMS,
        FINISH_TIME,
        LCZZYY,
        decode(
        <include refid="reminder">
            <property name="gdbh" value="i.gdbh"/>
        </include>
        ,0,'未催单','已催单') cdzt,
        (select cname from TF_YWPN_SYSCHILDCODE_D s where s.id = LCJD) gdzt,
        decode(LCJD,40,RZRY,41,SHRY,42,ZJRY,43,CZRY) clry,
        decode(LCJD,40,RZBM,41,SHBM,42,ZJBM,43,CZBM) clbm,
        <include refid="userNameQuery">
            <property name="userId" value="decode(LCJD,40,RZRY,41,SHRY,42,ZJRY,43,CZRY)"/>
        </include>
        <include refid="deptNameQuery">
            <property name="deptId" value="decode(LCJD,40,RZBM,41,SHBM,42,ZJBM,43,CZBM)"/>
        </include>
        JGCZ_FSSJ pdsj,
        CZRY,
        (select REAL_NAME from TF_SMPN_USER_X u where CZRY = u.ID) czry_name,
        CZYJ,
        CZSJ,
        (select cname from TF_YWPN_SYSCHILDCODE_D s where s.id = JJCD) yxjb,
        (select REAL_NAME from TF_SMPN_USER_X u where DJRY = u.ID) djry_name,
        djry,
        (select name from TF_SMPN_DEPARTMENT_X where id = DJBM) djbm,
        DJSJ,
        JDSX slsx,
        (SELECT GDLX_MC FROM TF_YWPN_GDGLTYPEBM_W WHERE ID = GDGZLX) gdlxfl,
        GDGZYY,
        GDGZLX,
        decode(BHZT, '0', '未驳回', '1', '有驳回') sfbh,
        decode(GDCS_FLAG, '0', '未超时', '1', '已超时') sfcq,
        decode(GDHF_CS, 0, '未回访',null,'未回访', '已回访') hfzt,
        GDHF_CS,
        r.RETURN_TIME,
        (select REAL_NAME from TF_SMPN_USER_X u where r.RETURN_USER = u.ID) return_user_name,
        r.RETURN_USER,
        decode(GDZZZT, '0', '未终止', '1', '已终止') zzzt,
        (select GDBZ from TF_YWPN_RXGDBZINFO_W b where b.GDBH = i.GDBH and ROWNUM = 1) gdbz
        from TF_YWPN_GDINFO_W i
        left join TF_YWPN_GDRETURN_W r on i.GDBH = r.GDBH
        where IS_RXLX = 1
        <choose>
            <when test="dto.start != null and dto.end != null">
                and to_char(DJSJ,'yyyy-mm-dd hh24:mi:ss') between #{dto.start} and #{dto.end}
            </when>
            <otherwise>
                and djsj between add_months(sysdate,-1) and sysdate
            </otherwise>
        </choose>
        <if test="dto.gdlx != null">
            and i.GDLX = #{dto.gdlx}
        </if>
        <if test="dto.gdxf1 != null">
            and gdxf1 = #{dto.gdxf1}
        </if>
        <if test="dto.gdxf2 != null">
            and gdxf2 = #{dto.gdxf2}
        </if>
        <if test="dto.gdzt != null">
            and i.lcjd = #{dto.gdzt}
        </if>
        <if test="dto.zzzt != null">
            and i.GDZZZT = #{dto.zzzt}
        </if>
        <if test="dto.cdzt != null">
            and decode(
            <include refid="reminder">
                <property name="gdbh" value="i.gdbh"/>
            </include>
            ,0,'0','1') = #{dto.cdzt}
        </if>
        <if test="dto.gdflx != null">
            and GDGZLX = #{dto.gdflx}
        </if>
        <if test="dto.hfzt != null">
            and decode(GDHF_CS, 0, '0', '1') = #{dto.hfzt}
        </if>
        <if test="dto.str != null">
            and i.gdbh || i.khbh || i.khxm || i.khdz || i.lxdh || i.sjdh like '%' || #{dto.str} || '%'
        </if>
        <if test="dto.djry != null">
            and i.djry = #{dto.djry}
        </if>
        <if test="dto.ratio != null">
            and rownum &lt;= ceil(
            <include refid="sum_count"/>
            * (#{dto.ratio} / 100))
        </if>
        order by djsj desc
    </select>
    <select id="getReadYhbh" resultType="com.tofly.xrtymis.custom.entity.ReadEntity">
        SELECT YHBH as yhbh , ISBREAK_READ as isBreak , ORDER_IDS as orderIds , CBBZ as cbbz
        FROM TF_YWPN_READMETERHIS_W WHERE YHBH = #{yhbh} AND MONTH_PLAN = #{yearMonth}
    </select>
    <update id="updateRead">
        UPDATE TF_YWPN_READMETERHIS_W
        SET ISBREAK_READ = '1', ORDER_IDS = #{orderIds}
        WHERE YHBH = #{yhbh} AND MONTH_PLAN = #{yearMonth}
    </update>

    <select id="getOrderUserDealNum" resultType="com.tofly.xrtymis.custom.vo.OrderUserDealNumVo">
        SELECT t.id,t.presentPerson
        FROM
            (SELECT m.id,m.presentPerson as presentPerson
             FROM (SELECT id,
                          CASE LCJD
                              WHEN 39 THEN to_char(djry)
                              WHEN 40 THEN slry
                              WHEN 41 THEN to_char(RZSLRY)
                              WHEN 42 THEN to_char(SHSLRY)

                              END AS presentPerson
                   FROM TF_YWPN_GDINFO_W
                   where lcjd !=45
                  ) m
                     ) t
        where t.presentPerson is not null
    </select>

    <update id="updateRewardWater">
        UPDATE TF_PUBLIC_LEAKAGE_INFO
        SET REWARD_WATER_VOLUME = #{rewardWaterValue}, IS_REWARD_WATER = #{isRewardWater}
        WHERE ORDER_ID = #{orderId}
    </update>

    <select id="getClassificationStatisticsVO" resultType="com.tofly.xrtymis.custom.vo.ClassificationStatisticsVO">
        select (select count(1)
                from TF_YWPN_GDINFO_W
                where djry = #{userId}
                  and lcjd = 39
                  and hang_up != '1')  gddj,
            (select count(1)
        from TF_YWPN_GDINFO_W
        where slry = #{userId}
          and lcjd = 40
          and hang_up != '1')  rzcz,
            (select count(1)
        from TF_YWPN_GDINFO_W
        where rzslry = #{userId}
          and lcjd = 41
          and hang_up != '1')  gdsh,
            (select count(1)
        from TF_YWPN_GDINFO_W
        where shslry = #{userId}
          and lcjd = 42
          and hang_up != '1')  gdzj,
            (select count(1)
        from TF_YWPN_RESULTDISP_W
        where person_id = #{userId}
          and is_finish = '0') jgcz
        from dual
    </select>

</mapper>
