<?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">
<!-- 不使用namespace的话sql搜索定位会比较方便 -->
<mapper namespace="com.blueland.bpm.manage.countAnalysis.dao.IndexDao">	
	<!-- 流程应用总数 -->
	<select id="getAppCount" resultType="java.lang.Integer">
		SELECT count(1) as count FROM T_PUB_APPLICATION WHERE APP_TYPE !='task'
	</select>
	<!-- 流程定义总数 -->
	<select id="getProcDefKeyCount" resultType="java.lang.Integer">
		SELECT count(1) as count FROM T_WF_PROCESS_INFO_CONFIG t  WHERE t.PROCESS_MGR_ISSHOW = 'Y' 
	</select>
	<!-- 流程运行情况 -->
	<select id="getProcessRunCount" resultType="java.util.Map">
		SELECT count(1) AS total, count(CASE WHEN res.PROC_STATE =1 THEN  'un_deal' END) un_deal, 
		count(CASE WHEN res.PROC_STATE =5 THEN  'deal' END) deal,
		count(CASE WHEN res.PROC_STATE =3 THEN  'cancle' END) cancle from ACT_HI_PROCINST RES
	</select>
	<!-- 流程执行情况 -->
	<select id="getProcessLogCount" resultType="java.util.Map">
		SELECT count(CASE WHEN PROCESS_LOG_LEVEL ='info' THEN  'info' END) info,
		count(CASE WHEN PROCESS_LOG_LEVEL ='error' THEN  'error' END) error 
		FROM T_WF_PROCESS_ERROR_LOG
	</select>
	<!-- 近一年、一月、一周流程 -->
	<select id="getProcessByTime" resultType="java.util.Map">
		SELECT * FROM 
  (SELECT count(CASE WHEN  PRO.START_TIME_  >= to_date(to_char(add_months(sysdate,-12),'yyyy-mm-dd'),'yyyy-mm-dd') THEN  'year' END) YEAR,
		  count(CASE WHEN PRO.START_TIME_  >= to_date(to_char(sysdate-30,'yyyy-mm-dd'),'yyyy-mm-dd') THEN  'month' END) month,
		  count(CASE WHEN PRO.START_TIME_  >= to_date(to_char(sysdate-7,'yyyy-mm-dd'),'yyyy-mm-dd') THEN  'week' END) week from ACT_HI_PROCINST PRO WHERE pro.proc_state = 1 ),
   (SELECT count(CASE WHEN  PRO.START_TIME_  >= to_date(to_char(add_months(sysdate,-12),'yyyy-mm-dd'),'yyyy-mm-dd') THEN  'year' END) finish_YEAR,
		  count(CASE WHEN PRO.START_TIME_  >= to_date(to_char(sysdate-30,'yyyy-mm-dd'),'yyyy-mm-dd') THEN  'month' END) finish_month,
		  count(CASE WHEN PRO.START_TIME_  >= to_date(to_char(sysdate-7,'yyyy-mm-dd'),'yyyy-mm-dd') THEN  'week' END) finish_week from ACT_HI_PROCINST PRO WHERE pro.proc_state = 5)
	</select>	
	<!-- 应用监控TOP -->
	<select id="getAppTop" resultType="java.util.Map">
		  SELECT
         COUNT(1) AS RUNCOUNT, TO_CHAR(PRO.PELOG_CREATE_TIME,  'MM') AS MONTH,APP.APP_ID AS APPID, APP.APP_NAME AS APPNAME
    FROM
        T_PUB_APPLICATION APP 
    LEFT JOIN
        T_WF_PROCESS_ERROR_LOG PRO 
            ON APP.APP_ID  = PRO.APP_ID 
    WHERE
        PRO.PROCESS_LOG_LEVEL='info' 
        AND TO_CHAR(PRO.PELOG_CREATE_TIME, 'yyyy')  = to_char(sysdate,'yyyy')
    GROUP BY
        TO_CHAR(PRO.PELOG_CREATE_TIME, 'MM'),APP.APP_ID,APP.APP_NAME
    ORDER BY
        RUNCOUNT DESC, MONTH 
	</select>	
	<!-- 系统负载数据 -->
	<select id="getSysLoadData" resultType="java.util.Map">
		SELECT
         COUNT(1) AS RUNCOUNT, TO_CHAR(PRO.PELOG_CREATE_TIME,  'DD') AS DAY,TO_CHAR(PRO.PELOG_CREATE_TIME,  'MM') AS MONTH
    FROM
        T_PUB_APPLICATION APP 
    LEFT JOIN
        T_WF_PROCESS_ERROR_LOG PRO 
            ON APP.APP_ID  = PRO.APP_ID 
    WHERE
        PRO.PROCESS_LOG_LEVEL='info' 
        AND to_date(TO_CHAR(PRO.PELOG_CREATE_TIME, 'yyyy-MM-DD'),'yyyy-MM-DD')  >= to_date(to_char(sysdate-10,'yyyy-MM-DD'),'yyyy-MM-DD')
    GROUP BY
        TO_CHAR(PRO.PELOG_CREATE_TIME, 'DD') ,TO_CHAR(PRO.PELOG_CREATE_TIME,  'MM')
      ORDER BY
        MONTH, DAY 
	</select>	
</mapper>

