<%@ page import="java.io.*, java.util.*"%>
<%@ page language="java" contentType="text/html;charset=utf-8"%>
<%@ page import="com.eactive.eai.common.EAITable"%>
<%@ page import="com.eactive.eai.common.message.EAIMessage"%>
<%@ page import="com.eactive.eai.common.message.ServiceMessage"%>
<%@ page import="com.eactive.eai.common.message.EAIMessageManager"%>
<%@ page import="com.eactive.eai.common.monitor.EAIServiceMonitor"%>
<%@ page import="com.eactive.eai.common.monitor.MonitorVO"%>
<%@ page import="java.util.HashMap"%>

<%

    EAIServiceMonitor   monitor             = EAIServiceMonitor.getInstance();
    String[]            voKey               = monitor.getAllBwkClsKey();
    String              action              = request.getParameter("actionType");
    
    String[]            pssCntKey           = null;
    String[] 			pssErrCntKey		= null;
    HashMap             pssCnt              = null;
    HashMap             pssCntInPeriod      = null;
    HashMap             errPssCnt           = null;
    HashMap             errPssCntInPeriod   = null;
    HashMap             voByBwk             = null;
    
    long[]              verTotalByBwk       = null;;
    long[]              verTotalInPeriodByBwk = null;
    double              sumOfprocessTimeByBwk   = 0;
    double              psvSumOfProcessTimeByBwk = 0;
    double              sumOfprocessTimeInPeriodByBwk   = 0;
    double              psvSumOfProcessTimeInPeriodByBwk = 0;
    double              avgOfprocessTimeByBwk   = 0;
    double              psvAvgOfProcessTimeByBwk = 0;
    double              avgOfprocessTimeInPeriodByBwk   = 0;
    double              psvAvgOfProcessTimeInPeriodByBwk = 0;
    
    int                 countEaiSvcCd               = 0;
    int                 countEaiSvcCdInPeriod       = 0;
    
    String selectedBwkCls = request.getParameter("bwkCls");
    if(selectedBwkCls == null && voKey.length>=1){
         selectedBwkCls = voKey[0];
    }
    
    if(selectedBwkCls!=null) {
        voByBwk             = monitor.getBwkCls(selectedBwkCls);  
    }
    
%>

<html>
    <head>
        <title>
            업무구분 코드/Log Sequence 별 통계 Monitor
        </title>
        <script>
        function doAction() {
            document.frm.submit();
        }
        
        </script>
    </head>
    <body>
        <p style="font-size:12pt;">
        <b>업무구분 코드/Log Sequence 별 통계 데이터</b> <br><br>
        </p>
        <form name="frm" method="POST" action="">
        <input type="hidden" name="actionType" value="">
        <table border='0' width="800" >
        <tr>
        <td align='left'>
        <table width="450" border=0 bgcolor='black' cellpadding="1" cellspacing="1">
        <tr bgcolor='white'>
            <td align='right' width='180' bgcolor="#ccccff"><label value="업무 구분 : "/>&nbsp;</td>
            <td align='left'>&nbsp;<select name="bwkCls" onchange="doAction();">
            <%
                for(int i=0;i<voKey.length;i++) {
            %>
                <option value="<%=voKey[i]%>" <%= (voKey[i].equals(selectedBwkCls)) ? "selected" : "" %>><%=voKey[i]%>
            <%           
                }
            %></select>
            </td>
        </tr>
        </table>
        </td>
        
        </tr>
        </table><br>
        

<%
        
   if(voByBwk != null){
        
        Iterator it = voByBwk.keySet().iterator();
 
        String[] keys = new String[voByBwk.size()];  
        for(int i = 0; it.hasNext(); i++){
            keys[i] = (String)it.next();
        }
        Arrays.sort(keys);
 %>
    <table width="800" border=0 bgcolor='black' cellpadding="1" cellspacing="1">
        <tr bgcolor='white'>
            <td align='center' bgcolor="#990000" colspan="11">&nbsp;<font color="yellow">&nbsp; <b>일일 통계</b></font></td>
        </tr>
 <%       
        
        for(int j = 0; j< keys.length; j++){
            MonitorVO vo = (MonitorVO)voByBwk.get(keys[j]);
            pssCntKey           = vo.getAllPssCntKey(); 
            pssCnt              = vo.getPssCnt();             
            errPssCnt           = vo.getErrPssCnt();
            
            pssErrCntKey		= vo.getAllErrPssCntKey();
            
            //verTotalByBwk = new long[pssCntKey.length];
            //verTotalInPeriodByBwk = new long[pssCntKey.length];
            
            verTotalByBwk = new long[pssErrCntKey.length];
            verTotalInPeriodByBwk = new long[pssErrCntKey.length];
            
            if(pssCntKey != null && pssCntKey.length >0){
                countEaiSvcCd ++; 
                int pssCntKeyLength = pssCntKey.length;
                int pssErrCntKeyLength = pssErrCntKey.length;
%>  

        <tr bgcolor='white'>
            <td align='center' bgcolor="#003366" >&nbsp;<font color="yellow"><b>EAI Service Code</b></font></td>
            <td align='left' colspan="10">&nbsp;<%=keys[j]%></td>
        </tr>
        
        <tr bgcolor='white'> 
        	<td align='center'   width="200" bgcolor="#6699cc" rowspan ="2">구분</td>
            <td align='center' bgcolor="#6699cc" colspan="<%= pssErrCntKeyLength %>">Log Sequence 별 처리 누적 </td>
            <td align='center' bgcolor="#6699cc" rowspan ="2">EAI 시스템 평균 처리시간(초) </td>
            <td align='center' bgcolor="#6699cc" rowspan ="2">수동 시스템 평균 처리시간(초) </td>
        </tr>
        
        <tr bgcolor='white'>
            <%  
            	
            
                long[] verTotal = new long[pssErrCntKeyLength];
                
                for(int i=0;i<pssErrCntKeyLength;i++) {
            %>                                                                                                                       
                <td align='center' width='40' bgcolor="#ccccff"><%=pssErrCntKey[i]%></td>                                                                     
 
            <%           
                }
            %>
        </tr>       
        <tr bgcolor='white'> 
            <td align='center'  width="200" bgcolor="#6699cc" >정상</td>
            <%
                for(int i=0;i<pssCntKeyLength;i++) {
                        verTotal[i] = verTotal[i]+Long.parseLong(pssCnt.get(pssCntKey[i]).toString());
            %>    
 
            <td align='right'>&nbsp;<input align='right' type="text" name="recvCount" size='10' value="<%=pssCnt.get(pssCntKey[i])%>"> </td>                                  

            <%           
                }
                
                double avgOfprocessTime = 0;
                double psvAvgOfProcessTime = 0;
                
                if("AA".equalsIgnoreCase(vo.getIfType())){
                    if(Long.parseLong(pssCnt.get(pssCntKey[1]).toString()) >0 && vo.getSumOfprocessTime() > 0 ){
                        avgOfprocessTime = vo.getSumOfprocessTime()/1000/Long.parseLong(pssCnt.get(pssCntKey[1]).toString());
                        
                        sumOfprocessTimeByBwk = sumOfprocessTimeByBwk + avgOfprocessTime;
                        avgOfprocessTimeByBwk = sumOfprocessTimeByBwk / countEaiSvcCd;
                    } 
                    if(Long.parseLong(pssCnt.get(pssCntKey[3]).toString()) >0 && vo.getSumOfprocessTime() > 0 ){
                        avgOfprocessTime = vo.getSumOfprocessTime()/1000/Long.parseLong(pssCnt.get(pssCntKey[3]).toString());
                        
                        sumOfprocessTimeByBwk = sumOfprocessTimeByBwk + avgOfprocessTime;
                        avgOfprocessTimeByBwk = sumOfprocessTimeByBwk / countEaiSvcCd;
                    }

                }
                else{
                
                    if(Long.parseLong(pssCnt.get(pssCntKey[3]).toString()) >0 && vo.getSumOfprocessTime() > 0 ){
                        avgOfprocessTime = vo.getSumOfprocessTime()/1000/Long.parseLong(pssCnt.get(pssCntKey[3]).toString());
                    }
                    
                    sumOfprocessTimeByBwk = sumOfprocessTimeByBwk + avgOfprocessTime;
                    avgOfprocessTimeByBwk = sumOfprocessTimeByBwk / countEaiSvcCd;
                }
                if(Long.parseLong(pssCnt.get(pssCntKey[2]).toString()) > 0 && vo.getPsvSumOfPssTime() > 0 ){
                    psvAvgOfProcessTime = vo.getPsvSumOfPssTime()/1000/Long.parseLong(pssCnt.get(pssCntKey[2]).toString());
                    
                    psvSumOfProcessTimeByBwk = psvSumOfProcessTimeByBwk + psvAvgOfProcessTime;
                    psvAvgOfProcessTimeByBwk = psvSumOfProcessTimeByBwk / countEaiSvcCd;
                }
            %>
            <td align='right'>&nbsp;<input align='right' type="text" name="recvCount2" size='10'value="0">
            <td align='right' rowspan="3">&nbsp;<input align='right' type="text" name="avgOfprocessTime" size='10' value="<%=avgOfprocessTime%>"> </td>
            <td align='right' rowspan="3">&nbsp;<input align='right' type="text" name="psvAvgOfProcessTime" size='10' value="<%=psvAvgOfProcessTime%>"> </td>
        </tr>
        
                                                                                                                                     
        <tr bgcolor='white'>                                                                                                                                                      
        	<td align='center' width="200" bgcolor="#6699cc" >에러</td>                     
            <%                                                                                                                                                                                                                                                                                
                for(int i=0;i<pssErrCntKeyLength;i++) {                                                                                                               
                        verTotal[i] = verTotal[i] + Long.parseLong(errPssCnt.get(pssErrCntKey[i]).toString());                                                           
            %>                                                                                                                                                     
                                                                                                                                                                   
            <td align='right'>&nbsp;<input align='right' type="text" name="errorCount" size='10' value="<%=errPssCnt.get(pssErrCntKey[i])%>"> </td>                                  
                                                                                                                                                                   
            <%                                                                                                                                                                                                                                                                                                                   
                }                                                                                                                                                  
            %>                                                                                                                                                                                               
                                                                                          
        </tr>                                                                                                                                                      
 
        <tr bgcolor='white'>                                                                                                                                     
            <td align='center' width="200" bgcolor="#6699cc">합계</td>   
             <%                                                                                                                                                                                                                                                                                        
                
                for(int i=0;i<pssErrCntKeyLength;i++) {     
                    verTotalByBwk[i] = verTotalByBwk[i] +  verTotal[i];                                                                                                                 
            %>                                                                        
            <td align='right' ><input align='right' type="text" name="sumOfLogSeq" size='10' value="<%=verTotal[i]%>"> </td>                                  
            <%                                                                                                                                                     
                                                                                                                                                                   
                }                                                                                                                                                  
            %>  
        </tr>
<%
        }
    }
%>
        <tr bgcolor='white'>
            <td align='center' bgcolor="#990000" >&nbsp;<font color="yellow"><b>합계</b></font></td>
            <%                                                                                                                                                                   
                for(int i=0;i<verTotalByBwk.length;i++) {
            %>                                                                        
            <td align='right' ><input align='right' type="text" name="sumOfLogSeqByBwk" size='10' value="<%=verTotalByBwk[i]%>"> </td>                                  
            <%                                                                                                                                                     
                                                                                                                                                                   
                }                                                                                                                                                  
            %>  
            <td align='right' rowspan="3">&nbsp;<input align='right' type="text" name="avgOfprocessTimeByBwk" size='10'value="<%=avgOfprocessTimeByBwk%>"> </td>
            <td align='right' rowspan="3">&nbsp;<input align='right' type="text" name="psvAvgOfProcessTimeByBwk" size='10'value="<%=psvAvgOfProcessTimeByBwk %>"> </td>
        </tr>
    </table>  
        <br>
        <!---  최근시간 --->
    <table width="800" border=0 bgcolor='black' cellpadding="1" cellspacing="1">
        <tr bgcolor='white'>
            <td align='center' bgcolor="#990000" colspan="11">&nbsp;<font color="yellow">&nbsp; <b>최근시간 통계</b></font></td>
        </tr>
<%
    for(int j = 0; j< keys.length; j++){
            MonitorVO vo = (MonitorVO)voByBwk.get(keys[j]);
            pssCntKey           = vo.getAllPssCntKey(); 
            pssCntInPeriod      = vo.getPssCntInPeriod();      
            errPssCntInPeriod   = vo.getErrPssCntInPeriod();
            
            pssErrCntKey		= vo.getAllErrPssCntKey();
   
            if(pssCntKey != null && pssCntKey.length >0){
                countEaiSvcCdInPeriod++;
                int pssCntKeyLength = pssCntKey.length;
                int pssErrCntKeyLength = pssErrCntKey.length;
%>  

        
        <tr bgcolor='white'>
            <td align='center' bgcolor="#003366" >&nbsp;<font color="yellow">&nbsp; <b>EAI Service Code</b></font></td>
            <td align='left' colspan="10">&nbsp;<%=keys[j]%></td>
        </tr>
        
        <tr bgcolor='white'> 
            <td align='center'   width="200" bgcolor="#6699cc" rowspan ="2">구분</td>
            <td align='center' bgcolor="#6699cc" colspan="<%= pssErrCntKeyLength %>">Log Sequence 별 처리 누적 </td>
            <td align='center' bgcolor="#6699cc" rowspan ="2">EAI 시스템 평균 처리시간(초) </td>
            <td align='center' bgcolor="#6699cc" rowspan ="2">수동 시스템 평균 처리시간(초) </td>
        </tr>
        
        <tr bgcolor='white'>
            <%
				long[] verInPeriodTotal = new long[pssErrCntKeyLength];
               
                for(int i=0;i<pssErrCntKeyLength;i++) {
            %>                                                                                                                       
                <td align='center' width='40' bgcolor="#ccccff"><%=pssErrCntKey[i]%></td>                                                                     
 
            <%           
                }
            %>
        </tr>       
        <tr bgcolor='white'> 
            <td align='center'  width="200" bgcolor="#6699cc" >정상</td>
            <%
                for(int i=0;i<pssCntKeyLength;i++) {
                        verInPeriodTotal[i] = verInPeriodTotal[i]+Long.parseLong(pssCntInPeriod.get(pssCntKey[i]).toString());
            %>    
 
            <td align='right'>&nbsp;<input align='right' type="text" name="recvCountInPeriod" size='10' value="<%=pssCntInPeriod.get(pssCntKey[i])%>"> </td>                                  

            <%           
                }
                
                double avgOfprocessTimeInPeriod = 0;
                double psvAvgOfProcessTimeInPeriod = 0;
                
                if("AA".equalsIgnoreCase(vo.getIfType())){
                    if(Long.parseLong(pssCntInPeriod.get(pssCntKey[1]).toString()) >0 && vo.getSumOfProcessTimeInPeriod() > 0){
                        avgOfprocessTimeInPeriod = vo.getSumOfProcessTimeInPeriod()/1000/Long.parseLong(pssCntInPeriod.get(pssCntKey[1]).toString());
                        sumOfprocessTimeInPeriodByBwk = sumOfprocessTimeInPeriodByBwk + avgOfprocessTimeInPeriod;
                        avgOfprocessTimeInPeriodByBwk = sumOfprocessTimeInPeriodByBwk / countEaiSvcCdInPeriod;
                    }
                    if(Long.parseLong(pssCntInPeriod.get(pssCntKey[3]).toString()) >0 && vo.getSumOfProcessTimeInPeriod() > 0){
                        avgOfprocessTimeInPeriod = vo.getSumOfProcessTimeInPeriod()/1000/Long.parseLong(pssCntInPeriod.get(pssCntKey[3]).toString());
                        sumOfprocessTimeInPeriodByBwk = sumOfprocessTimeInPeriodByBwk + avgOfprocessTimeInPeriod;
                        avgOfprocessTimeInPeriodByBwk = sumOfprocessTimeInPeriodByBwk / countEaiSvcCdInPeriod;
                    }
                    
                }
                else{
                    if(Long.parseLong(pssCntInPeriod.get(pssCntKey[3]).toString()) >0 && vo.getSumOfProcessTimeInPeriod() > 0){
                    avgOfprocessTimeInPeriod = vo.getSumOfProcessTimeInPeriod()/1000/Long.parseLong(pssCntInPeriod.get(pssCntKey[3]).toString());
                    
                    sumOfprocessTimeInPeriodByBwk = sumOfprocessTimeInPeriodByBwk + avgOfprocessTimeInPeriod;
                    avgOfprocessTimeInPeriodByBwk = sumOfprocessTimeInPeriodByBwk / countEaiSvcCdInPeriod;
                    }
                }
                
                if(Long.parseLong(pssCntInPeriod.get(pssCntKey[2]).toString()) >0 && vo.getPsvSumOfPssTimeInPeriod() > 0){
                    psvAvgOfProcessTimeInPeriod = vo.getPsvSumOfPssTimeInPeriod()/1000/Long.parseLong(pssCntInPeriod.get(pssCntKey[2]).toString());
                    
                    psvSumOfProcessTimeInPeriodByBwk = psvSumOfProcessTimeInPeriodByBwk + psvAvgOfProcessTimeInPeriod;
                    psvAvgOfProcessTimeInPeriodByBwk = psvSumOfProcessTimeInPeriodByBwk / countEaiSvcCdInPeriod;
                }

            %>
            <td align='right'>&nbsp;<input align='right' type="text" name="recvCountInPeriod" size='10' value="0"></td>
            <td align='right' rowspan="3">&nbsp;<input align='right' type="text" name="avgOfprocessTimeInPeriod" size='10' value="<%=avgOfprocessTimeInPeriod%>"> </td>
            <td align='right' rowspan="3">&nbsp;<input align='right' type="text" name="psvAvgOfProcessTimeInPeriod" size='10' value="<%=psvAvgOfProcessTimeInPeriod%>"> </td>
        </tr>
        
                                                                                                                                     
        <tr bgcolor='white'>                                                                                                                                                      
        	<td align='center' width="200" bgcolor="#6699cc" >에러</td>                     
            <%                                                                                                                                                     
                for(int i=0;i<pssErrCntKeyLength;i++) {                                                                                                               
                        verInPeriodTotal[i] = verInPeriodTotal[i] + Long.parseLong(errPssCntInPeriod.get(pssErrCntKey[i]).toString());                                                           
            %>                                                                                                                                                     
                                                                                                                                                                   
            <td align='right'>&nbsp;<input align='right' type="text" name="sendCount" size='10'value="<%=errPssCntInPeriod.get(pssErrCntKey[i])%>"> </td>                                  
                                                                                                                                                                   
            <%                                                                                                                                                                                                                                                                                                                   
                }                                                                                                                                                  
            %>                                                                                                                                                     
                                                                                          
        </tr>                                                                                                                                                      
 
        <tr bgcolor='white'>                                                                                                                                     
            <td align='center' width="200" bgcolor="#6699cc">합계</td>   
             <%                                                                                                                                                                                                                                                                                        
                for(int i=0;i<pssErrCntKeyLength;i++) {     
                    verTotalInPeriodByBwk[i] = verTotalInPeriodByBwk[i] +  verInPeriodTotal[i];                                                                                                                                                                                                                                   
            %>                                                                        
            <td align='right' ><input align='right' type="text" name="sumOfLogSeqInPeriod" size='10' value="<%=verInPeriodTotal[i]%>"> </td>                                  
            <%                                                                                                                                                     
                                                                                                                                                                   
                }                                                                                                                                                  
            %>  
        </tr> 
                                                                                                                                      
 <% 
        } 
    }
%>
        <tr bgcolor='white'>
            <td align='center' bgcolor="#990000" >&nbsp;<font color="yellow"><b>합계</b></font></td>
            <%                                                                                                                                                                                                                                                                                        
                for(int i=0;i<verTotalInPeriodByBwk.length;i++) {                                                                                                                       
            %>                                                                        
            <td align='right' ><input align='right' type="text" name="sumOfLogSeqInPeriodByBwk" size='10' value="<%=verTotalInPeriodByBwk[i]%>"> </td>                                  
            <%                                                                                                                                                     
                                                                                                                                                                   
                }                                                                                                                                                  
            %>  
            <td align='right' rowspan="3">&nbsp;<input align='right' type="text" name="sumOfprocessTimeInPeriodByBwk" size='10' value="<%=avgOfprocessTimeInPeriodByBwk%>"> </td>
            <td align='right' rowspan="3">&nbsp;<input align='right' type="text" name="psvSumOfProcessTimeInPeriodByBwk" size='10' value="<%=psvAvgOfProcessTimeInPeriodByBwk %>"> </td>
        </tr>
    </table>
<%    
}else{
 %>  
        
    해당 업무 구분에 대한 거래 내역이 없습니다.
 <% 
    }
 %>

        </form>
    </body>
</html>