<?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="zgl" column="ZGL"/>
        <result property="cbry" column="CBRY"/>
        <!--        <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="lxsj" column="LXSJ"/>
        <result property="shrdj" column="SHRDJ"/>
        <result property="djbm" column="DJBM"/>
        <result property="isCb" column="IS_CB"/>
        <result property="soleSign" column="SOLE_SIGN"/>
        <result property="isArchiveHint" column="IS_ARCHIVE_HINT"/>
        <result property="vehicleId" column="VEHICLE_ID"/>
        <result property="vehicleName" column="VEHICLE_NAME"/>
        <!--        <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="com.tofly.baseapi.mapper.ToflyCodeCommonMapper.getUserName"/>
        <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="jgczQwxUserName" column="ID" select="getGgczQwxUserName"/>
        <association property="jgczQwxNote" column="ID" select="getJgczQwxNote"/>
        <association property="overTimeDate" column="ID" select="getOverTimeDate"/>
        <collection property="resultList" column="GDBH"
                    select="com.tofly.xrtymis.mapper.ResultdispMapper.getResultdis"/>
    </resultMap>
    <select id="getGgczQwxUserName" resultType="string">
        select REAL_NAME jgczQwxUserName
        from TF_SMPN_USER_X
        where id = (select (case
                                when (select GDBH FROM TF_YWPN_GDCIRCULATION_W where gdbh = i.GDBH) is not null
                                    then (select RESP_USER
                                          from TF_YWPN_GDCIRCULATION_W g
                                                   left join TF_YWPN_REPAIRUSER_W r on r.REPAIR_ID = g.OTHER_BH
                                          where gdbh = i.gdbh)
                                else CZRY end) czry
                    from TF_YWPN_GDINFO_W i
                    where i.id = #{id})
    </select>
    <select id="getJgczQwxNote" resultType="string">
        select (case
                    when (select GDBH FROM TF_YWPN_GDCIRCULATION_W where gdbh = i.GDBH) is not null then (
                        select c.NOTES
                        from TF_YWPN_GDCIRCULATION_W g
                                 left join TF_YWPN_REPAIRUSER_W r on r.REPAIR_ID = g.OTHER_BH
                                 left join TF_YWPN_REPAIRRECORD_W c on c.REPAIR_USERID = r.ID
                        where gdbh = i.gdbh
                          and ROWNUM = 1
                    )
                    else to_char(CZYJ) end) jgczQwxNote
        from TF_YWPN_GDINFO_W i
        where i.id = #{id}
    </select>
    <select id="getOverTimeDate" resultType="java.util.Date">
        select (case
                    when (select GDBH FROM TF_YWPN_GDCIRCULATION_W where gdbh = i.GDBH) is not null
                        then (select OVER_TIME
                              from TF_YWPN_GDCIRCULATION_W g
                                       left join TF_YWPN_REPAIRUSER_W r on r.REPAIR_ID = g.OTHER_BH
                              where gdbh = i.gdbh)
                    else CZSJ end) overTimeDate
        from TF_YWPN_GDINFO_W i
        where i.id = #{id}

    </select>
    <delete id="removeAudit">
        delete
        from TF_YMPN_AUDIT_W
        where ID = #{id}
    </delete>

    <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,
               n.REAL_NAME     as presentPersonName,
               z.id            as presentDept,
               z.name             presentDeptName
        FROM (SELECT id,
                     CASE LCJD
                         WHEN 39 THEN djry
                         WHEN 40 THEN slry
                         WHEN 41 THEN RZSLRY
                         WHEN 42 THEN SHSLRY
                         WHEN 43 THEN ZJCZRY
                         WHEN 44 THEN (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 ROWNUM = 1
                                         and t1.id = #{id})
                         when 840 then (select RESP_USER
                                        from TF_YWPN_GDCIRCULATION_W g
                                                 left join TF_YWPN_REPAIRUSER_W r on r.REPAIR_ID = g.OTHER_BH
                                        where gdbh = i.gdbh and ROWNUM = 1)
                         END AS presentPerson
              FROM TF_YWPN_GDINFO_W i
              WHERE id = #{id}) m
                 LEFT JOIN TF_XRTY_NEW_UDB.TF_SMPN_USER_X n ON m.presentPerson = n.id
                 LEFT JOIN TF_XRTY_NEW_UDB.TF_SMPN_DEPARTMENT_X z on n.DEPARTMENT_ID = z.ID
    </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>
        and TABLE_NAME = 'TF_YWPN_GDINFO_W'
    </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>
        and TABLE_NAME = 'TF_YWPN_GDINFO_W'
    </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_XRTY_NEW_UDB.TF_SMPN_USER_X t1
                 left join TF_XRTY_NEW_UDB.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 NAME
        FROM "TF_XRTY_NEW_UDB"."TF_SMPN_DEPARTMENT_X"
        WHERE ID = #{slbm}
    </select>
    <select id="shbmName" resultType="string">
        select NAME
        FROM "TF_XRTY_NEW_UDB"."TF_SMPN_DEPARTMENT_X"
        WHERE ID = #{shbm}
    </select>
    <select id="zjbmName" resultType="string">
        select NAME
        FROM "TF_XRTY_NEW_UDB"."TF_SMPN_DEPARTMENT_X"
        WHERE ID = #{zjbm}
    </select>
    <select id="czbmName" resultType="string">
        select NAME
        FROM "TF_XRTY_NEW_UDB"."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_XRTY_NEW_UDB.TF_SMPN_USER_X t2 on t1.AUDIT_USER = t2.ID
                 LEFT JOIN TF_XRTY_NEW_UDB.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_XRTY_NEW_UDB.TF_SMPN_USER_X t2 on t1.AUDIT_USER = t2.ID
                 LEFT JOIN TF_XRTY_NEW_UDB.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 gdNum-gdgdNum as notGdgdNum,round(gdgdNum/gdNum*100,2)||'%' as gdOverRate,
        <!--后面这几个是另加的，因为发现完成率的统计中总数意思混淆了-->
        t1.gdlx,t1.gdlxName,t1.GDXF1,t1.GDXF2,
        t1.gdNum,t1.qwxNum,t1.gdgdNum, t1.gddjNum, t1.rzczNum, t1.rzshNum, t1.rzzjNum, t1.jgczNum, t1.jgshNum,
        (t1.rzczTotalNum + t1.rzczNum) as rzczTotalNum,
        (t1.rzshTotalNum + t1.rzshNum) as rzshTotalNum,
        (t1.rzzjTotalNum + t1.rzzjNum) as rzzjTotalNum,
        (t1.jgczTotalNum + t1.jgczNum) as jgczTotalNum,
--         (t1.jgshTotalNum + t1.jgshNum) as jgshTotalNum
        t1.jgshNum as jgshTotalNum
        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.gdxf1List != null and model.gdxf1List != '' ">
            and g.gdxf1 in
            <foreach collection="model.gdxf1List.split(',')" item="id" open="(" separator="," close=")">
                #{id}
            </foreach>
        </if>
        <if test="model.gdxf2List != null and model.gdxf2List != '' ">
            and g.gdxf2 in
            <foreach collection="model.gdxf2List.split(',')" item="id" open="(" separator="," close=")">
                #{id}
            </foreach>
        </if>
        <if test="model.gdxf1List != null and model.gdxf1List != '' ">
            and g.gdxf1 in
            <foreach collection="model.gdxf1List.split(',')" item="id" open="(" separator="," close=")">
                #{id}
            </foreach>
        </if>
        <if test="model.gdxf2List != null and model.gdxf2List != '' ">
            and g.gdxf2 in
            <foreach collection="model.gdxf2List.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 gdNum-gdgdNum as notGdgdNum,round(gdgdNum/gdNum*100,2)||'%' as gdOverRate,
        <!--后面这几个是另加的，因为发现完成率的统计中总数意思混淆了-->
        t1.gdlx,t1.gdlxName,
        t1.gdNum,t1.qwxNum,t1.gdgdNum, t1.gddjNum, t1.rzczNum, t1.rzshNum, t1.rzzjNum, t1.jgczNum, t1.jgshNum,
        (t1.rzczTotalNum + t1.rzczNum) as rzczTotalNum,
        (t1.rzshTotalNum + t1.rzshNum) as rzshTotalNum,
        (t1.rzzjTotalNum + t1.rzzjNum) as rzzjTotalNum,
        (t1.jgczTotalNum + t1.jgczNum) as jgczTotalNum,
--         (t1.jgshTotalNum + t1.jgshNum) as jgshTotalNum
        t1.jgshNum as jgshTotalNum
        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.gdxf1List != null and model.gdxf1List != '' ">
            and g.gdxf1 in
            <foreach collection="model.gdxf1List.split(',')" item="id" open="(" separator="," close=")">
                #{id}
            </foreach>
        </if>
        <if test="model.gdxf2List != null and model.gdxf2List != '' ">
            and g.gdxf2 in
            <foreach collection="model.gdxf2List.split(',')" item="id" open="(" separator="," close=")">
                #{id}
            </foreach>
        </if>
        <if test="model.gdxf1List != null and model.gdxf1List != '' ">
            and g.gdxf1 in
            <foreach collection="model.gdxf1List.split(',')" item="id" open="(" separator="," close=")">
                #{id}
            </foreach>
        </if>
        <if test="model.gdxf2List != null and model.gdxf2List != '' ">
            and g.gdxf2 in
            <foreach collection="model.gdxf2List.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 gdNum-gdgdNum as notGdgdNum,round(gdgdNum/gdNum*100,2)||'%' as gdOverRate ,
        <!--后面这几个是另加的，因为发现完成率的统计中总数意思混淆了-->
        t1.DJBM,
        t1.gdNum,t1.qwxNum,t1.gdgdNum, t1.gddjNum, t1.rzczNum, t1.rzshNum, t1.rzzjNum, t1.jgczNum, t1.jgshNum,
        (t1.rzczTotalNum + t1.rzczNum) as rzczTotalNum,
        (t1.rzshTotalNum + t1.rzshNum) as rzshTotalNum,
        (t1.rzzjTotalNum + t1.rzzjNum) as rzzjTotalNum,
        (t1.jgczTotalNum + t1.jgczNum) as jgczTotalNum,
--         (t1.jgshTotalNum + t1.jgshNum) as jgshTotalNum
        t1.jgshNum as jgshTotalNum
        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.gdxf1List != null and model.gdxf1List != '' ">
            and g.gdxf1 in
            <foreach collection="model.gdxf1List.split(',')" item="id" open="(" separator="," close=")">
                #{id}
            </foreach>
        </if>
        <if test="model.gdxf2List != null and model.gdxf2List != '' ">
            and g.gdxf2 in
            <foreach collection="model.gdxf2List.split(',')" item="id" open="(" separator="," close=")">
                #{id}
            </foreach>
        </if>
        <if test="model.gdxf1List != null and model.gdxf1List != '' ">
            and g.gdxf1 in
            <foreach collection="model.gdxf1List.split(',')" item="id" open="(" separator="," close=")">
                #{id}
            </foreach>
        </if>
        <if test="model.gdxf2List != null and model.gdxf2List != '' ">
            and g.gdxf2 in
            <foreach collection="model.gdxf2List.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"/>
        </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'
        <include refid="getCollectDetails"/>
        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 = #{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>
    <sql id="getBhByRyId">
        <if test="gdglinfoDTO.lcjdid == 39">
            AND DJRY = #{userId}
        </if>
        <if test="gdglinfoDTO.lcjdid == 40">
            AND (SLRY = #{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 RZRY = #{userId} THEN 1 ELSE 0 END) as rzzt,
        sum(CASE WHEN SHRY = #{userId} THEN 1 ELSE 0 END) as shzt,
        sum(CASE WHEN ZJRY = #{userId} THEN 1 ELSE 0 END) as zjzt,
        sum(CASE WHEN instr(JGCZ_PERSON, #{userId}) > 0 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 = #{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 = #{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.gdxf1List != null and model.gdxf1List != '' ">
            and g.gdxf1 in
            <foreach collection="model.gdxf1List.split(',')" item="id" open="(" separator="," close=")">
                #{id}
            </foreach>
        </if>
        <if test="model.gdxf2List != null and model.gdxf2List != '' ">
            and g.gdxf2 in
            <foreach collection="model.gdxf2List.split(',')" item="id" open="(" separator="," close=")">
                #{id}
            </foreach>
        </if>
        <if test="model.gdxf1List != null and model.gdxf1List != '' ">
            and g.gdxf1 in
            <foreach collection="model.gdxf1List.split(',')" item="id" open="(" separator="," close=")">
                #{id}
            </foreach>
        </if>
        <if test="model.gdxf2List != null and model.gdxf2List != '' ">
            and g.gdxf2 in
            <foreach collection="model.gdxf2List.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.DJBM,g.GDLX,g.GDXF1,g.GDXF2,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>
        <if test="model.gdxf1List != null and model.gdxf1List != '' ">
            and g.gdxf1 in
            <foreach collection="model.gdxf1List.split(',')" item="id" open="(" separator="," close=")">
                #{id}
            </foreach>
        </if>
        <if test="model.gdxf2List != null and model.gdxf2List != '' ">
            and g.gdxf2 in
            <foreach collection="model.gdxf2List.split(',')" item="id" open="(" separator="," close=")">
                #{id}
            </foreach>
        </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
        SUM(decode(g.GDZZZT,'1',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>
        <if test="model.gdxf1List != null and model.gdxf1List != '' ">
            and g.gdxf1 in
            <foreach collection="model.gdxf1List.split(',')" item="id" open="(" separator="," close=")">
                #{id}
            </foreach>
        </if>
        <if test="model.gdxf2List != null and model.gdxf2List != '' ">
            and g.gdxf2 in
            <foreach collection="model.gdxf2List.split(',')" item="id" open="(" separator="," close=")">
                #{id}
            </foreach>
        </if>
        <if test="model.gdxf1List != null and model.gdxf1List != '' ">
            and g.gdxf1 in
            <foreach collection="model.gdxf1List.split(',')" item="id" open="(" separator="," close=")">
                #{id}
            </foreach>
        </if>
        <if test="model.gdxf2List != null and model.gdxf2List != '' ">
            and g.gdxf2 in
            <foreach collection="model.gdxf2List.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>
        <if test="model.gdxf1List != null and model.gdxf1List != '' ">
            and g.gdxf1 in
            <foreach collection="model.gdxf1List.split(',')" item="id" open="(" separator="," close=")">
                #{id}
            </foreach>
        </if>
        <if test="model.gdxf2List != null and model.gdxf2List != '' ">
            and g.gdxf2 in
            <foreach collection="model.gdxf2List.split(',')" item="id" open="(" separator="," close=")">
                #{id}
            </foreach>
        </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.gdxf1List != null and model.gdxf1List != '' ">
            and g.gdxf1 in
            <foreach collection="model.gdxf1List.split(',')" item="id" open="(" separator="," close=")">
                #{id}
            </foreach>
        </if>
        <if test="model.gdxf2List != null and model.gdxf2List != '' ">
            and g.gdxf2 in
            <foreach collection="model.gdxf2List.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>
        <if test="model.gdxf1List != null and model.gdxf1List != '' ">
            and g.gdxf1 in
            <foreach collection="model.gdxf1List.split(',')" item="id" open="(" separator="," close=")">
                #{id}
            </foreach>
        </if>
        <if test="model.gdxf2List != null and model.gdxf2List != '' ">
            and g.gdxf2 in
            <foreach collection="model.gdxf2List.split(',')" item="id" open="(" separator="," close=")">
                #{id}
            </foreach>
        </if>
        <if test="model.gdxf1List != null and model.gdxf1List != '' ">
            and g.gdxf1 in
            <foreach collection="model.gdxf1List.split(',')" item="id" open="(" separator="," close=")">
                #{id}
            </foreach>
        </if>
        <if test="model.gdxf2List != null and model.gdxf2List != '' ">
            and g.gdxf2 in
            <foreach collection="model.gdxf2List.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.gdxf1List != null and model.gdxf1List != '' ">
            and g.gdxf1 in
            <foreach collection="model.gdxf1List.split(',')" item="id" open="(" separator="," close=")">
                #{id}
            </foreach>
        </if>
        <if test="model.gdxf2List != null and model.gdxf2List != '' ">
            and g.gdxf2 in
            <foreach collection="model.gdxf2List.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 and 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,'未催单','已催单') = #{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="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="gdInfoQuery" resultType="map">
        select id, hang_up, sjdh, gdbh, gdlx, gdxf1, gdxf2, khbh, lcid, gddj_zt, process_deposit, khxm, khdz, lxdh,
        gdms, finish_time, lczzyy, cdzt, pdsj, czry, czyj, czsj, djry, djsj, slsx, gdgzyy, gdgzlx, sfbh, sfcq, hfzt,
        gdhf_cs, return_time, return_user, zzzt,(select REAL_NAME from TF_SMPN_USER_X u where CZRY = u.ID) czry_name,
        gdlx_name,gdxf1_name,gdxf2_name,gdzt,yxjb,djry_name,djbm,gdlxfl,return_user_name,gdbz
        from (
        select
        i.ID,
        HANG_UP,
        sjdh,
        i.GDBH,
        (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,
        JGCZ_FSSJ pdsj,
        (case when (select GDBH FROM TF_YWPN_GDCIRCULATION_W where gdbh = i.GDBH) is not null then (select RESP_USER
        from TF_YWPN_GDCIRCULATION_W g
        left join TF_YWPN_REPAIRUSER_W r on r.REPAIR_ID = g.OTHER_BH
        where gdbh = i.gdbh) else CZRY end) czry,
        (case
        when (select GDBH FROM TF_YWPN_GDCIRCULATION_W where gdbh = i.GDBH) is not null then (
        select c.NOTES
        from TF_YWPN_GDCIRCULATION_W g
        left join TF_YWPN_REPAIRUSER_W r on r.REPAIR_ID = g.OTHER_BH
        left join TF_YWPN_REPAIRRECORD_W c on c.REPAIR_USERID = r.ID
        where gdbh = i.gdbh and ROWNUM = 1
        )
        else to_char(CZYJ) end) CZYJ,
        (case when (select GDBH FROM TF_YWPN_GDCIRCULATION_W where gdbh = i.GDBH) is not null then (select OVER_TIME
        from TF_YWPN_GDCIRCULATION_W g
        left join TF_YWPN_REPAIRUSER_W r on r.REPAIR_ID = g.OTHER_BH
        where gdbh = i.gdbh and ROWNUM = 1) when CZSJ is null then FINISH_TIME else CZSJ end) 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,
        case when
        decode(i.RZCZ_CSZT,'1',1,decode(i.RESH_CSZT,'1',1,decode(i.RZZJ_CSZT,'1',1,decode(i.JGCZ_CSZT,'1',1,0)))) > 0
        then '已超时' else '未超时' end 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 DJSJ between to_date(#{dto.start},'yyyy-MM-dd hh24:mi:ss') and to_date(#{dto.end},'yyyy-MM-dd
                hh24:mi:ss')
            </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.bhzt != null">
            and i.BHZT = #{dto.bhzt}
        </if>
        <if test="dto.gdxf1 != null">
            and gdxf1 = #{dto.gdxf1}
        </if>
        <if test="dto.cszt != null and dto.cszt != ''">
            and
            decode(i.RZCZ_CSZT,'1',1,decode(i.RESH_CSZT,'1',1,decode(i.RZZJ_CSZT,'1',1,decode(i.JGCZ_CSZT,'1',1,0)))) >
            0
        </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="gdInfoCount" resultType="long">
        select
        count(1)
        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.bhzt != null">
            and i.BHZT = #{dto.bhzt}
        </if>
        <if test="dto.gdxf1 != null">
            and gdxf1 = #{dto.gdxf1}
        </if>
        <if test="dto.cszt != null and dto.cszt != ''">
            and GDCS_FLAG = #{dto.cszt}
        </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>
    </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>
    <update id="updateReadWater">
        UPDATE TF_YWPN_READMETERHIS_W
        SET SHBZ = '3'
        WHERE SOLE_SIGN = #{soleSign}
    </update>

    <update id="updateYcReadWater">
        UPDATE TF_YWPN_READMETEREASHIS_W
        SET SHBZ = '3'
        WHERE SOLE_SIGN = #{soleSign}
    </update>


    <select id="getOrderUserDealNum" resultType="com.tofly.xrtymis.custom.vo.OrderUserDealNumVo">
        SELECT t.id, t.presentPerson, t.presentPersonName, t.presentDept, t.presentDeptName
        FROM (SELECT m.id,
                     m.presentPerson as presentPerson,
                     n.REAL_NAME     as presentPersonName,
                     z.id            as presentDept,
                     z.name             presentDeptName
              FROM (SELECT id,
                           CASE LCJD
                               WHEN 39 THEN djry
                               WHEN 40 THEN slry
                               WHEN 41 THEN RZSLRY
                               WHEN 42 THEN SHSLRY
                               END AS presentPerson
                    FROM TF_YWPN_GDINFO_W
                    where lcjd != 45
                   ) m
                       LEFT JOIN TF_XRTY_NEW_UDB.TF_SMPN_USER_X n ON m.presentPerson = n.id
                       LEFT JOIN TF_XRTY_NEW_UDB.TF_SMPN_DEPARTMENT_X z on n.DEPARTMENT_ID = z.ID) t
        where t.presentPerson is not null
          and t.presentPersonName is not null
    </select>

    <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>

    <select id="getDmaFinishOrderId" resultType="long">
        select ORDER_ID
        from TF_YWPN_DMAWARNHANDLE_W d
                 left join TF_YWPN_GDINFO_W g on d.ORDER_ID = g.ID
        where LCJD = 45
          and FINISH_TIME is not null
          and HAND_TIME is null
    </select>

    <update id="updateWarnHandle">
        update TF_YWPN_DMAWARNHANDLE_W
        set HAND_TIME = (select FINISH_TIME from TF_YWPN_GDINFO_W where id = #{orderId})
        where ORDER_ID = #{orderId}
    </update>


    <select id="getWorkOrderInfo" resultMap="gdglinfoMap">
        select id,
        gdbh,
        gdly,
        gdlx,
        gdxf1,
        gdxf2,
        gdms,
        jjcd,
        lcid,
        ldhm,
        slbm,
        slry,
        jdsx,
        wcsx,
        djry,
        djsj,
        khbh,
        khxm,
        khdz,
        lxdh,
        jdzt,
        gddj_zt,
        lcjd,
        rz_fileid,
        rzyj,
        rzbm,
        rzsx,
        rzsj,
        rzry,
        lczt,
        shyj,
        shbm,
        shry,
        shsj,
        shsx,
        shzt,
        zjyj,
        zjbm,
        zjry,
        zjsj,
        zjsx,
        zjzt,
        czsx,
        czyj,
        czbm,
        czry,
        czsj,
        jgcz_fileid,
        czzt,
        gdhf_cs,
        zjczry,
        gddj_fssj,
        rzcz_fssj,
        resh_fssj,
        rzzj_fssj,
        jgcz_fssj,
        rzcz_cszt,
        resh_cszt,
        rzzj_cszt,
        jgcz_cszt,
        rzcz_cssj,
        resh_cssj,
        rzzj_cssj,
        jgcz_cssj,
        lczzyy,
        process_deposit,
        rzslry,
        shslry,
        jd_cszt,
        bhzt,
        zpzt,
        jgczry,
        is_rxlx,
        is_quality_flag,
        hang_up,
        is_watermeter_status,
        gddj_fileid,
        zzry,
        zzsj,
        gdgzlx,
        gdgzyy,
        gzszry,
        sqbm,
        sqry,
        gdzzzt,
        gdsx,
        gdcs_flag,
        jgcz_person,
        finish_time,
        address,
        lgtd,
        lttd,
        ysxz,
        sbbh,
        sbkj,
        sjdh,
        shrdj,
        djbm,
        process_info,
        foreign_id,
        foreign_type,
        foreign_state,
        is_cb,
        sole_sign,
        zgl,
        cbry,
        lxsj,
        is_archive_hint
        from TF_YWPN_GDINFO_W
        where 1=1
        <if test="info.jjcd != null and info.jjcd != ''">
            and JJCD = #{info.jjcd}
        </if>
        <if test="info.gdbh != null and info.gdbh != ''">
            and GDBH = #{info.gdbh}
        </if>
        <if test="info.khbh != null and info.khbh != ''">
            and khbh = #{info.khbh}
        </if>
        <if test="info.djry != null">
            and djry = #{info.djry}
        </if>
        <if test="info.hangUp != null">
            and hang_up = #{info.hangUp}
        </if>
        <if test="notLcjd != null and info.Lcjd == null">
            and lcjd > #{notLcjd}
        </if>
        <choose>
            <when test="'1'.equals(sort)">
                and gdgzlx is not null
            </when>
            <when test="'0'.equals(sort)">
                and gdgzlx is null
            </when>
        </choose>
        <if test="startTime != null">
            and djsj > #{startTime}
        </if>
        <if test="endTime != null">
            and djsj &lt; #{endTime}
        </if>
        <if test="info.djbm != null">
            and djbm = #{info.djbm}
        </if>
        <if test="info.lcjd != null">
            and lcjd = #{info.lcjd}
        </if>
        <if test="info.gdlx != null">
            and gdlx = #{info.gdlx}
        </if>
        <if test="info.gdxf1 != null">
            and gdlx = #{info.gdxf1}
        </if>
        <if test="info.gdxf2 != null">
            and gdlx = #{info.gdxf2}
        </if>
        <if test="depts != null">
            and djbm in
            <foreach collection="depts" item="d" open="(" separator="," close=")">
                #{d}
            </foreach>
        </if>
        <if test="aboutDepts != null">
            and(
            rzbm in
            <foreach collection="aboutDepts" item="d" open="(" separator="," close=")">
                #{d}
            </foreach>
            or
            shbm in
            <foreach collection="aboutDepts" item="d" open="(" separator="," close=")">
                #{d}
            </foreach>
            or
            slbm in
            <foreach collection="aboutDepts" item="d" open="(" separator="," close=")">
                #{d}
            </foreach>
            or
            sqbm in
            <foreach collection="aboutDepts" item="d" open="(" separator="," close=")">
                #{d}
            </foreach>
            or
            zjbm in
            <foreach collection="aboutDepts" item="d" open="(" separator="," close=")">
                #{d}
            </foreach>
            or
            djbm in
            <foreach collection="aboutDepts" item="d" open="(" separator="," close=")">
                #{d}
            </foreach>
            )
        </if>

        <if test="aboutUsers != null">
            and(
            <if test="gdbhs != null and gdbhs.size() != 0">
                GDBH in
                <foreach collection="gdbhs" item="cd" index="idx" separator="," open="(" close=")">
                    <if test="(idx % 999) == 998">NULL ) OR GDBH IN (</if>
                    #{cd}
                </foreach>
                or
            </if>
            <if test="gdIds != null and gdIds.size() != 0">
                id in
                <foreach collection="gdIds" item="cd" index="idx" separator="," open="(" close=")">
                    <if test="(idx % 999) == 998">NULL ) OR id IN (</if>
                    #{cd}
                </foreach>
                or
            </if>
            djry in
            <foreach collection="aboutUsers" item="u" open="(" separator="," close=")">
                #{u}
            </foreach>
            or
            slry in
            <foreach collection="aboutUsers" item="u" open="(" separator="," close=")">
                #{u}
            </foreach>
            or
            shslry in
            <foreach collection="aboutUsers" item="u" open="(" separator="," close=")">
                #{u}
            </foreach>
            or
            rzslry in
            <foreach collection="aboutUsers" item="u" open="(" separator="," close=")">
                #{u}
            </foreach>
            )
        </if>
        <if test="gdlx != null">
            and gdlx in
            <foreach collection="gdlx" item="g" open="(" separator="," close=")">
                #{g}
            </foreach>
        </if>
        <if test="gdxf1 != null">
            and gdxf1 in
            <foreach collection="gdxf1" item="g" open="(" separator="," close=")">
                #{g}
            </foreach>
        </if>
        <if test="gdxf2 != null">
            and gdxf2 in
            <foreach collection="gdxf2" item="g" open="(" separator="," close=")">
                #{g}
            </foreach>
        </if>
        <if test="lcjd != null">
            and lcjd in
            <foreach collection="lcjd" item="l" open="(" separator="," close=")">
                #{l}
            </foreach>
        </if>
        <if test="input != null and input != ''">
            and gdbh || khxm || khdz || lxdh || khbh like concat('%',concat(#{input},'%'))
        </if>
        <if test="info.gdzzzt != null and info.gdzzzt != ''">
            and GDZZZT = #{info.gdzzzt}
        </if>
        <if test="info.zpzt != null and info.zpzt != ''">
            and ZPZT = #{info.zpzt}
        </if>
        <if test="info.gdcsFlag != null and info.gdcsFlag != ''">
            and GDCS_FLAG = #{info.gdcsFlag}
        </if>
        <if test="info.bhzt != null and info.bhzt != ''">
            and BHZT = #{info.bhzt}
        </if>
        order by djsj desc
    </select>

    <select id="resultDispositionInfoQuery" resultMap="gdglinfoMap">
        select *
        from TF_YWPN_GDINFO_W
        <where>
            <if test="dto.inputcontent != null and dto.inputcontent != ''">
                and gdbh || gdms like concat('%',concat(#{dto.inputcontent},'%'))
            </if>
            <if test="dto.gdlx != null">
                and 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.startTime != null and dto.endTime != null">
                and djsj between #{dto.startTime} and #{dto.endTime}
            </if>
            <if test="dto.id != null and dto.id.size()>0">
                and id in
                <foreach collection="dto.id" item="cd" index="idx" separator="," open="(" close=")">
                    <if test="(idx % 999) == 998">NULL ) OR id IN (</if>
                    #{cd}
                </foreach>
            </if>
            <if test="dto.gdbh != null and dto.gdbh.size()>0">
                and gdbh in
                <foreach collection="dto.gdbh" item="cd" index="idx" separator="," open="(" close=")">
                    <if test="(idx % 999) == 998">NULL ) OR gdbh IN (</if>
                    #{cd}
                </foreach>
            </if>
            <if test="dto.lcjdid == 43 and dto.queryState == 9">
                and JGCZ_CSZT = '0'
                AND LCJD = 43
                AND ((instr(PROCESS_DEPOSIT, '4') > 0 AND
                (CEIL((SYSDATE - ZJSJ) * 24 * 60) / CEIL((CZSX - ZJSJ) * 24 * 60)) * 100 > #{dto.ratio}
                ) OR (instr(PROCESS_DEPOSIT, '3') > 0 AND
                (CEIL((SYSDATE - SHSJ) * 24 * 60) / CEIL((ZJSX - SHSJ) * 24 * 60)) * 100 > #{dto.ratio}
                ) OR (instr(PROCESS_DEPOSIT, '2') > 0 AND
                (CEIL((SYSDATE - RZSJ) * 24 * 60) / CEIL((SHSX - RZSJ) * 24 * 60)) * 100 > #{dto.ratio}
                ) OR (CEIL((SYSDATE - DJSJ) * 24 * 60) / CEIL((SHSX - DJSJ) * 24 * 60)) * 100 > #{dto.ratio})
            </if>
        </where>

    </select>

    <select id="getOrderCodes" resultType="string">
        select distinct g.GDBH
        from TF_YWPN_GDINFO_W g left join TF_YWPN_RESULTDISP_W r on r.GDBH = g.GDBH
        where PERSON_ID = #{userId}
        <if test="isFinish != null and isFinish != ''">
            and IS_FINISH = #{isFinish}
        </if>
        <if test="dto.gdlx != null">
            and 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.startTime != null and dto.endTime != null">
            and djsj between #{dto.startTime} and #{dto.endTime}
        </if>
    </select>
</mapper>
