<%@ 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"%>

<%
	String actionMessage = "";
    EAIServiceMonitor   monitor             = EAIServiceMonitor.getInstance();
    String[]            voKey               = monitor.getAllMonitorVOKey(); 
    String              action              = request.getParameter("actionType");
    MonitorVO           vo                  = null;
    String[]            pssCntKey           = null;
    String[] 			pssErrCntKey		= null;
    HashMap             pssCnt              = null;
    HashMap             pssCntInPeriod      = null;
    HashMap             errPssCnt           = null;
    HashMap             errPssCntInPeriod   = null;
    
    String selectedSvcCds = request.getParameter("svcCds");
    if(selectedSvcCds == null && voKey.length>=1) {
         selectedSvcCds = voKey[0];
    }
    
    if(selectedSvcCds!=null) {
        vo                  = monitor.getMonitorVO(selectedSvcCds);
        if("RESET".equals(action)) {
            vo.reset();
        }    
        pssCntKey           = vo.getAllPssCntKey(); 
        pssCnt              = vo.getPssCnt();             
        pssCntInPeriod      = vo.getPssCntInPeriod();      
        errPssCnt           = vo.getErrPssCnt();
        errPssCntInPeriod   = vo.getErrPssCntInPeriod();

    }
    
    if("ALLRESET".equalsIgnoreCase(action)){
        monitor.resetAll();  
    }
    else if("RESET_TOLIST".equalsIgnoreCase(action)){
    	actionMessage = monitor.resetErrorList();  
    }
%>

<html>
<head>
<title>Service ID/Log Sequence 별 통계 Monitor</title>
<script type="text/javascript">
        function doAction() {
            document.frm.submit();
        }
        
        function doReset() {
            document.frm.actionType.value="RESET";
            document.frm.submit();
        }
        
        function doAllReset() {
            document.frm.actionType.value="ALLRESET";
            document.frm.submit();
        }
        
        function doResetToList() {
            document.frm.actionType.value="RESET_TOLIST";
            document.frm.submit();
        }
        
        </script>
</head>
<body>
<p style="font-size:12pt;"><b>Service ID/Log Sequence 별 통계 데이터</b> <br>
<% if(actionMessage != null && actionMessage.length() > 0) { %>
Action result : <%=  actionMessage %><br>
<% } %>
<br>
</p>
<form name="frm" 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">EAI Service Message ID : &nbsp;</td>
				<td align='left'>&nbsp;<select name="svcCds" onchange="doAction();">
					<%
                for(int i=0;i<voKey.length;i++) {
            %>
					<option value="<%=voKey[i]%>" <%= (voKey[i].equals(selectedSvcCds)) ? "selected" : "" %>><%=voKey[i]%> <%           
                }
            %></option>
				</select></td>
			</tr>
		</table>
		</td>
		<td align='right'><input type="button" value="RESET" onclick="doReset()"></td>
		<td align='right'><input type="button" value="ALL RESET" onclick="doAllReset()"></td>
		<td align='right'><input type="button" value="reload Timeout Error Code" onclick="doResetToList()"></td>

	</tr>
</table>
<br>
<table width="800" border="0" bgcolor='black' cellpadding="1" cellspacing="1">
<%
   if(pssCntKey != null && pssCntKey.length >0){
    if(vo != null) {
    	pssErrCntKey		= vo.getAllErrPssCntKey();
    	int pssCntKeyLength = pssCntKey.length;
    	int pssErrCntKeyLength = pssErrCntKey.length;
%>
	<tr bgcolor='white'>
		<td align='center' bgcolor="#003366" colspan="11">&nbsp;<font color="yellow">&nbsp; <b>일일 통계</b></font></td>
	</tr>
	<tr bgcolor='white'>
		<td align='right' 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];
                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++) {
					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());
                    } 
                    if(Long.parseLong(pssCnt.get(pssCntKey[3]).toString()) >0 && vo.getSumOfprocessTime() > 0 ){
                        avgOfprocessTime = vo.getSumOfprocessTime()/1000/Long.parseLong(pssCnt.get(pssCntKey[3]).toString());
                    } 
                }
                else{
                
                    if(Long.parseLong(pssCnt.get(pssCntKey[3]).toString()) >0 && vo.getSumOfprocessTime() > 0 ){
                        avgOfprocessTime = vo.getSumOfprocessTime()/1000/Long.parseLong(pssCnt.get(pssCntKey[3]).toString());
                    }
                }
                if(Long.parseLong(pssCnt.get(pssCntKey[2]).toString()) > 0 && vo.getPsvSumOfPssTime() > 0 ){
                    psvAvgOfProcessTime = vo.getPsvSumOfPssTime()/1000/Long.parseLong(pssCnt.get(pssCntKey[2]).toString());

                }
                System.out.println("vo.getPsvSumOfPssTime() : "+ vo.getPsvSumOfPssTime());
            %>
		<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="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++) {                                                                                                                       
		%>
		<td align='right'><input align='right' type="text" name="sumOfLogSeqInPeriod" size='10' value="<%=verTotal[i]%>"></td>
		<%                                                                                                                                                     
                                                                                                                                                                   
                }                                                                                                                                                  
		%>
	</tr>

	<!---  최근시간 --->

	<tr bgcolor='white'>
		<td align='center' bgcolor="#003366" colspan="11">&nbsp;<font color="yellow">&nbsp; <b>최근시간 통계</b></font></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'>
		<%   
    
                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());
                    }
                    if(Long.parseLong(pssCntInPeriod.get(pssCntKey[3]).toString()) >0 && vo.getSumOfProcessTimeInPeriod() > 0){
                        avgOfprocessTimeInPeriod = vo.getSumOfProcessTimeInPeriod()/1000/Long.parseLong(pssCntInPeriod.get(pssCntKey[3]).toString());
                    }
                }
                else{
                    if(Long.parseLong(pssCntInPeriod.get(pssCntKey[3]).toString()) >0 && vo.getSumOfProcessTimeInPeriod() > 0){
                    avgOfprocessTimeInPeriod = vo.getSumOfProcessTimeInPeriod()/1000/Long.parseLong(pssCntInPeriod.get(pssCntKey[3]).toString());
                    }
                }
                
                if(Long.parseLong(pssCntInPeriod.get(pssCntKey[2]).toString()) >0 && vo.getPsvSumOfPssTimeInPeriod() > 0){
                    psvAvgOfProcessTimeInPeriod = vo.getPsvSumOfPssTimeInPeriod()/1000/Long.parseLong(pssCntInPeriod.get(pssCntKey[2]).toString());
                }

		%>
		<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='right' 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++) {                                                                                                                       
		%>
		<td align='right'><input align='right' type="text" name="sumOfLogSeqInPeriod" size='10'
			value="<%=verInPeriodTotal[i]%>"></td>
		<%                                                                                                                                                     
                                                                                                                                                                   
                }                                                                                                                                                  
		%>
	</tr>

	<% 
        } 
    } else{
 %>
</table>
해당 서비스 ID에 대한 거래 내역이 없습니다. <% 
    }
 %></form>
</body>
</html>
