<!-- 同一客户集中度限额查询优化 -->
	<select id="listPagecustomConcentration_NEW_YH" parameterType="pd"
		resultType="java.util.LinkedHashMap" resultMap="customConcentration_NEW"
		statementType="PREPARED">
		SELECT DFJ.NEWDATE,
		       DFJ.CUSTNAME,
		       DFJ.CERTCODE,
		       vg.B_GRADE2 CREDITISSUEIN,--内部评级
		       DFJ.BUSI_NAME,
		       DFJ.INDU_NAME,
		       DFJ.FLAG,
		       DFJ.ONE_DEPT,
		       DFJ.CITY_NAME,
		       DFJ.PROVINCE_NAME,
		       DFJ.UNIQUE_ID,
		       DFJ.DEPT_AMT_FICC,
		       DFJ.DEPT_AMT_RL_FICC,
		       DFJ.DEPT_AMT_SALE,
		       DFJ.DEPT_AMT_RL_SALE,
		       DFJ.DEPT_AMT_ZIJIN,
		       DFJ.DEPT_AMT_RL_ZIJIN,
		       DFJ.DEPT_AMT_ZQTZ,
		       DFJ.DEPT_AMT_RL_ZQTZ,
		       DFJ.CAN_DO_AMT_FICC,
		       DFJ.CAN_DO_AMT_SALE,
		       DFJ.CAN_DO_AMT_ZIJIN,
		       DFJ.CAN_DO_AMT_ZQTZ,
               (SELECT SUM(vos.order_scale)
           FROM ficrm_v_ucc_ORDERSCALE vos
        WHERE 1=1
        	and vos.DEPARTMENT_TYPE = '01' --只查询ficc事业部
          <if test="pd.p2!='' and pd.p2!=null">
            and vos.lastoptdate+7 >= to_date(#{pd.p2},'yyyy-mm-dd') --预约额度七天之后过期
           </if>
           <if test="pd.p2=='' or pd.p2==null">
            and to_char(vos.lastoptdate+7,'yyyymmdd') >= to_char(SYSDATE,'yyyymmdd')
           </if>
           AND vos.custname IN 
           (SELECT M.RELA_CUST_NAME AS RELA_CUST_NAME
              FROM FICRM_V_UCC_RELATPL M
             WHERE 1=1
                 <if test="pd.p2!='' and pd.p2!=null">
                  AND TO_DATE(M.DATE_1, 'yyyyMMdd') = TO_DATE(#{pd.p2}, 'yyyy-MM-dd')
                 </if>
                 <if test="pd.p2=='' or pd.p2==null">
                  AND to_date(M.DATE_1,'yyyyMMdd') = (select max(FDATE) FDATE from FICRM_Q_DATE_WORKDAY
                      where 1=1
                        and FDATE &lt;= SYSDATE-1
                      and jys=0)
                 </if>
               
               AND M.CUST_NAME = DFJ.CUSTNAME 
               AND M.TYPE_1 = '子主体'
               
               )
           ) AS ORDER_SCALE_VIEW,
           (SELECT TO_CHAR(UEF.BUSI_EXCEED / 100000000) FROM FICRM_V_UCC_EXCEED_FICC UEF
              WHERE DFJ.CUSTNAME = UEF.CUST_NAME
              AND TRIM(UEF.DATE_1) = DFJ.NEWDATE
              AND uef.dept_name = 'FICC事业部') AS BUSI_EXCEED_FICC,
           (SELECT TO_CHAR(UEF.BUSI_EXCEED / 100000000) FROM FICRM_V_UCC_EXCEED_FICC UEF
              WHERE DFJ.CUSTNAME = UEF.CUST_NAME
              AND TRIM(UEF.DATE_1) = DFJ.NEWDATE
              AND uef.dept_name = '固定收益销售交易总部') AS BUSI_EXCEED_XSZB,
           case when CRE.TYPE in ('穿透类','观察类','限制类','评级过期','银行未准入') then '限制类'
         		when CRE.TYPE in ('C9以下','高风险预警类','关注类') then '关注类'
           		else '' end as ASCRIPTION,
           VOS.ORDER_SCALE AS ORDER_SCALE,
           to_char(VOS.LASTOPTDATE,'yyyy-MM-dd')|| ' ' ||VOS.LASTOPTTIME as ORDER_DATE,
           CASE WHEN to_date(#{pd.p2},'yyyy-MM-dd')+1 &lt;= VOS.LASTOPTDATE 
             THEN '待生效'
               WHEN to_date(#{pd.p2},'yyyy-MM-dd')+1 BETWEEN VOS.LASTOPTDATE+1 AND VOS.LASTOPTDATE+8
                 THEN '已生效'
                   END AS ORDER_STATE,
                   DFJ.DEPT_AMT_RL_YWLBXE AS DEPT_AMT_RL_YWLBXE,
                   VUMC.AREA_NAME,
                   CASE WHEN VUMC.AREA_LEVEL = '区县级' AND VUMC.STATE_ZONE = '是'
                     THEN '地市级（国家级园区）'
                       ELSE
                         VUMC.AREA_LEVEL
                         END AS AREA_LEVEL,
                   VUMC.STATE_ZONE
		  FROM FICRM_V_UCC_DEPTAMT_FICC_JRBJ DFJ
		  LEFT JOIN crs_vcorp_grade_list vg
		     ON DFJ.CUSTNAME = vg.o_name
		     <if test="pd.np_date!='' and pd.np_date!=null">
		         <!-- and to_date(vg.DATE_1,'yyyyMMdd') = to_date(#{pd.np_date},'yyyy-MM-dd') -->
		         AND vg.DATE_1 = to_char(to_date(#{pd.np_date},'yyyy-MM-dd'),'yyyyMMdd')
		     </if>
		    <if test="pd.np_date=='' or pd.np_date==null">
		        and vg.DATE_1 = to_char(SYSDATE,'yyyymmdd')
		    </if>
		  LEFT JOIN ficrm_v_ucc_ORDERSCALE vos
		    ON DFJ.CUSTNAME = vos.custname
		    and vos.DEPARTMENT_TYPE = '01' --只查询ficc事业部
		    <if test="pd.p2!='' and pd.p2!=null">
		      and vos.lastoptdate+7 > to_date(#{pd.p2},'yyyy-mm-dd') --预约额度七天之后过期
		     </if>
		     <if test="pd.p2=='' or pd.p2==null">
		      and to_char(vos.lastoptdate+7,'yyyymmdd') >= to_char(SYSDATE,'yyyymmdd')
		     </if>
		  LEFT JOIN FICRM_C_RESTRICTE CRE
		    ON DFJ.CUSTNAME = CRE.CUST_NAME
		    AND DFJ.NEWDATE = CRE.BASE_DATE
	      LEFT JOIN ficrm_v_ucc_municipalcust VUMC
    		ON VUMC.cust_name = DFJ.CUSTNAME
		  WHERE 1=1
	     <if test="pd.p2!='' and pd.p2!=null">
	      <!-- AND to_date(DFJ.NEWDATE,'yyyyMMdd') = to_date(#{pd.p2},'yyyy-MM-dd') -->
	      AND DFJ.NEWDATE = to_char(to_date(#{pd.p2},'yyyy-MM-dd'),'yyyyMMdd')
	     </if>
	     <if test="pd.p2=='' or pd.p2==null">
	      AND DFJ.NEWDATE = (select to_char(max(FDATE),'yyyy-MM-dd') FDATE from FICRM_Q_DATE_WORKDAY
	          where 1=1
	            and FDATE &lt;= SYSDATE-1
	          and jys=0)
	     </if>
	     <if test="pd.p1!='' and pd.p1!=null">
	          and DFJ.CUSTNAME LIKE '%' ||#{pd.p1}|| '%'
	     </if>
	</select>
分析下这段sql