<%@ page import="java.util.ArrayList"%>
<%@ page import="java.util.HashMap"%>
<%@ page import="com.eactive.eai.batch.rule.dirInfo.BatchJobPriorityManager"%>
<%@ page import="com.eactive.eai.batch.rule.dirInfo.BatchJobPriorityVO"%>
<%@ page language="java" contentType="text/html;charset=euc-kr"%>

<%
    
	BatchJobPriorityManager jobpmanager = BatchJobPriorityManager.getInstance();

	HashMap<String, ArrayList<BatchJobPriorityVO>> jobmap = jobpmanager.getPriorityDatas();
	String[] keys = jobpmanager.getPriorityKeys();

%>

<html>
    <head>
        <title>
            실행중인 우선순위 대상 작업 정보
        </title>
        <script language="javascript">
        function submitForm(key, count) {

        	document.forms.frm.index.value = count;    
        	document.forms.frm.key.value = key;
        	document.forms.frm.scr_name.value = "UPDATE";      
            document.frm.submit();
        } 
        
        function isNumber(val)
		{    
		alert('val : '+val);
		    if(val.length > 0) {
			    for(i=0;i<val.length;i++) {
			    	abit = parseInt(val.substring(i,i+1));
			    	if(('0' < abit) || ('9' > abit)) {
			    	}
			    	else {
			    		return false;
			    	}
			    }
		    }
		    return true;
		}
		
		
		function submitDelete(val){
        	document.forms.frm.key.value = val;
			document.forms.frm.scr_name.value = "DELETE";      
            document.frm.submit();
		}
        </script>
    </head>
    <body>
        <p style="font-size:12pt;">
        <b>실행중인 우선순위 대상 작업 정보</b> <br><br>
        </p>

        <form name="frm" method="POST" action="<%=request.getContextPath()%>/BatchJobPriorityMan">
        <input type="hidden" name="index" >
        <input type="hidden" name="scr_name" >
        <input type="hidden" name="key" >
        <br>
        
        <%
       		int count = -1;
        	boolean tableIndex = false;
        	String mapkey = "";
        	if (keys !=null && keys.length > 0) {
        		
        		for (int keyindex =0; keyindex < keys.length; keyindex++){
        			mapkey = keys[keyindex];
	        		ArrayList<BatchJobPriorityVO> alist = jobmap.get(mapkey);
	        		for (int j=0; j <alist.size(); j++) {
	        			BatchJobPriorityVO hvo = alist.get(j);
	        			
	        			if (hvo == null){
	        				break;
	        			}
	        			int delay = 0;
	        			if (hvo.getFirstCallForDelayTime() > 0){
		        			delay = (int)((System.currentTimeMillis() - hvo.getFirstCallForDelayTime())/1000.0);
	        			}
	        			count++;
		        	    if(j == 0) {
		        	    	tableIndex = true;
	        				
        %>
         <table id='tbl' width="950" border=0 bgcolor='black' cellpadding="1" cellspacing="1">
             <tr bgcolor='white'>
                <td align='center' rowspan="<%= alist.size() + 1 %>" bgcolor="#ccccff"><%= hvo.getProcessName() %></td>
                <td align='center' width=20 bgcolor="#ccccff">최우선순위 작업(Key)</td>
                <td align='center' bgcolor="#ccccff">Batch작업거래<br>구분코드</td>
                <td align='center' bgcolor="#ccccff">UUID</td>
                <td align='center' width=70 bgcolor="#ccccff">기관명</td>
                <td align='center' bgcolor="#ccccff">파일명</td>
                <td align='center' bgcolor="#ccccff">Delay경과시간(초)</td>
                <td align='center' bgcolor="#ccccff">실행할 파일 수</td>
                <td align='center' bgcolor="#ccccff">실행된 파일 수</td>
                <td align='center' bgcolor="#ccccff">실행여부</td>
                <td align='center' bgcolor="#ccccff">변경</td>
             </tr>
			<tr bgcolor='white'>
	            <td align='left' width=20 rowspan="<%= alist.size() %>"  bgcolor="#ffffff"><%= mapkey %>&nbsp;
	            <br>
	            <input type="button" class="form1" value=" 삭제  " onclick="submitDelete('<%=mapkey %>');">
	            </td>
	            <td align='left'   bgcolor="#ffffff"><input type="hidden" name="bizCode" value="<%=hvo.getBizCode()%>"><%= hvo.getBizCode() %>&nbsp;</td>
	            <td align='center' bgcolor="#ffffff"><%= hvo.getUUID() %>&nbsp;</td>
	            <td align='left'   width=70 bgcolor="#ffffff"><%= hvo.getOsdName() %>&nbsp;</td>
	            <td align='left'   bgcolor="#ffffff"><%= hvo.getFileName() %>&nbsp;</td>
   	            <td align='left'   bgcolor="#ffffff"><%=delay%>&nbsp;</td>
   	            <td align='left'   bgcolor="#ffffff"><%=hvo.getDataCountInfo()%>&nbsp;</td>
	            <td align='left'   bgcolor="#ffffff"><input type="text" name="dataCount" size='10' value="<%=hvo.getDataCount()%>">&nbsp;</td>
	            <td align='left'   bgcolor="#ffffff"><input type="text" name="isexe" size='10' value="<%=hvo.isExecuted()%>">&nbsp;</td>
	            <td align="right"><input type="button" class="form1" value=" 변경  " onclick="submitForm( '<%=mapkey %>', '<%= count%>' );"></td>
	        </tr>
<%
			}
			else {
%>
        <tr bgcolor='white'>
            	<td align='left'   bgcolor="#ffffff"><input type="hidden" name="bizCode" value="<%=hvo.getBizCode()%>"><%= hvo.getBizCode() %>&nbsp;</td>
	           	<td align='center' bgcolor="#ffffff"><%= hvo.getUUID() %>&nbsp;</td>
	            <td align='left'   bgcolor="#ffffff"><%= hvo.getOsdName() %>&nbsp;</td>
	            <td align='left'   bgcolor="#ffffff"><%= hvo.getFileName() %>&nbsp;</td>
   	            <td align='left'   bgcolor="#ffffff"><%=delay%>&nbsp;</td>
   	            <td align='left'   bgcolor="#ffffff"><%=hvo.getDataCountInfo()%>&nbsp;</td>
	            <td align='left'   bgcolor="#ffffff"><input type="text" name="dataCount" size='10' value="<%=hvo.getDataCount()%>" >&nbsp;</td>
	            <td align='left'   bgcolor="#ffffff"><input type="text" name="isexe" size='10' value="<%=hvo.isExecuted()%>">&nbsp;</td>
	            <td align="right"><input type="button" class="form1" value=" 변경  " onclick="submitForm( '<%=mapkey %>', '<%= count%>');"></td>
        </tr>
<%
			}
	  }
	        		if(tableIndex){
	  %>
</table>
<br>
<%}
        	}
       	}else {
       		%>
       		실행중인 우선순위 대상 작업목록이 없습니다.
       		<%
       	}
        	if(count == 0 && tableIndex==true){
        		%>
           		실행중인 우선순위 대상 작업목록이 없습니다.
           		<%
        	}
      %>
        </form>
    </body>
</html>