<%@ page language="java" contentType="text/html; charset=utf-8"%>
<%@ page import="java.io.*"%>
<%@ page import="com.eactive.eai.rms.common.login.SessionManager"%>
<%@ page import="com.eactive.eai.common.util.SystemUtil"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<%
	response.setHeader("Pragma", "No-cache");
	response.setHeader("Cache-Control", "no-cache");
	response.setHeader("Expires", "0");
%>
<html>
	<head>
		<title></title>
		
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
		
		<jsp:include page="/jsp/common/include/css.jsp"/>
		<jsp:include page="/jsp/common/include/script.jsp"/>
		
		<script>
			function init(){
				$.ajax({
					type: "POST",
					url: '<c:url value="/bap/admin/schedule/scheduleMonitorMan.json" />',
					dataType: "json",
					data: {cmd: "LIST_INIT_COMBO"},
					success: function(json){
						new makeOptions("CODE","NAME").setObj($("select[name=searchBjobBzwkDstcd]")).setNoValueInclude(true).setNoValue('','전체').setData(json.bjobBzwkDstcd).rendering();
						new makeOptions("CODE","NAME").setObj($("select[name=searchOsidInstiDstcd]")).setNoValueInclude(true).setNoValue('','전체').setData(json.osidInstiDstcd).rendering();
						
						putSelectFromParam();
						
						if (typeof callback === 'function') {
							callback(url,"");
						}
						
						setSearchable("searchBjobBzwkDstcd");
						setSearchable("searchOsidInstiDstcd");
					},
					error: function(e){
						alert(e.responseText);
					}
				});
			}
		
			function trimFormatter(cellvalue, options, rowObject){
				if (cellvalue == null || cellvalue == undefined || cellvalue == ""){
					return "";
				} else {
					var str = $.trim(cellvalue);
					
					str = str.slice(0, 2) + ":" + str.slice(2, 4)
					
					return str;
				}
			}
			
			function thisMsgUseYnFormatter(cellvalue, options, rowObject){
				if (cellvalue == null || cellvalue == undefined || cellvalue == ""){
					return "";
				} else {
					if(cellvalue == "1"){
						return "사용함";
					} else {
						return "사용안함";
					}
				}
			}
			
			function fileTrsmtHmsFormatter(cellvalue, options, rowObject){
				if (cellvalue == null || cellvalue == undefined || cellvalue == ""){
					return "";
				} else {
					var str = $.trim(cellvalue);
					
					str = str.slice(0, 4) + "-" + str.slice(4, 6) + "-" + str.slice(6, 8) + " " + str.slice(8, 10) + ":" + str.slice(10, 12) + ":" + str.slice(12, 14)
					
					return str;
				}
			}
			
			function thisStgePrcssRsultCdFormatter(cellvalue, options, rowObject){
				if (cellvalue == null || cellvalue == undefined || cellvalue == ""){
					return "";
				} else {
					if(cellvalue == "L"){
						return "지연";
					} else if(cellvalue == "F"){
						return "미도래";
					} else if(cellvalue == "Q"){
						return "큐대기";
					} else if(cellvalue == "S"){
						return "진행중";
					} else if(cellvalue == "T"){
						return "정상종료";
					} else if(cellvalue == "E"){
						return "비정상종료";
					} else if(cellvalue == "C"){
						return "사용자중지";
					} else if(cellvalue == "N"){
						return "파일없음";
					}
				}
			}
			
			function list(){
				var gridPostData = getSearchForJqgrid("cmd", "LIST");
				
				gridPostData["searchBjobDmndMsgID"] = '${param.searchBjobDmndMsgID}';
				gridPostData["searchBjobDmndSubMsgID"] = '${param.searchBjobDmndSubMsgID}';
				gridPostData["searchBjobBzwkDstcd"] = '${param.searchBjobBzwkDstcd}';
				gridPostData["searchBjobMsgDstcd"] = '${param.searchBjobMsgDstcd}';
				gridPostData["searchBjobTranDstcdName"] = '${param.searchBjobTranDstcdName}';
				gridPostData["searchSndrcvFileName"] = '${param.searchSndrcvFileName}';
				gridPostData["searchOsidInstiDstcd"] = '${param.searchOsidInstiDstcd}';
				gridPostData["searchThisMsgUseYn"] = '${param.searchThisMsgUseYn}';
				gridPostData["searchThisStgePrcssRsultCd"] = '${param.searchThisStgePrcssRsultCd}';
				gridPostData["searchInclude"] = '${param.searchInclude}';
				
				var start = $("input[name=searchStartYYYYMMDD]").val().replace(/-/gi,"") + $("input[name=searchStartHHMM]").val().replace(":","");
				var end = $("input[name=searchEndYYYYMMDD]").val().replace(/-/gi,"") + $("input[name=searchEndHHMM]").val().replace(":","");

				gridPostData["searchStartTime"] = start + "000";
				gridPostData["searchEndTime"] = end + "000";
				
				$("#grid").jqGrid({
					datatype: 'json',
					mtype: 'POST',
					url: '<c:url value="/bap/admin/schedule/scheduleMonitorMan.json" />',
					postData: gridPostData,
					colNames: [
						"UUID",
						"SUBUUID",
						"분류코드",
						"분류명",
						"대외일괄업무코드",
						"대외일괄업무명",
						"인터페이스ID",
						"파일코드",
						"사용여부",
						"거래시간내 실행횟수",
						"최근거래시작시간",
						"최근거래종료시간",
						"최근전송상태",
						"파일크기",
						"파일명"
					],
					colModel: [
						{ name: "BJOBDMNDMSGID", align: "center", hidden: true },
						{ name: "BJOBDMNDSUBMSGID", align: "center", hidden: true },
						{ name: "BJOBBZWKDSTCD", align: "center", hidden: true },
						{ name: "BJOBBZWKNAME", align: "center", width: 100 },
						{ name: "OSIDINSTIDSTCD", align: "center", hidden: true },
						{ name: "OSIDINSTINAME", align: "center", width: 150 },
						{ name: "BJOBMSGDSTCD", align: "center", width: 80 },
						{ name: "BJOBTRANDSTCDNAME", align: "center", width: 100 },
						{ name: "THISMSGUSEYN", align: "center", width: 50, formatter: thisMsgUseYnFormatter },
						{ name: "RUNCOUNT", align: "center", width: 80 },
						{ name: "FILETRSMTSTARTHMS", align: "center", width: 80, formatter: fileTrsmtHmsFormatter },
						{ name: "FILETRSMTENDHMS", align: "center", hidden: true, formatter: fileTrsmtHmsFormatter },
						{ name: "THISSTGEPRCSSRSULTCD", align: "center", width: 70, formatter: thisStgePrcssRsultCdFormatter },
						{ name: "SNDRCVFILESIZE", align: "center", width: 50 },
						{ name: "SNDRCVFILENAME", align: "center", width: 150 }
					],
					jsonReader: {
						repeatitems: false
					},
					pager: $("#pager"),
					page: '${param.page}',
					rowNum: '${rmsDefaultRowNum}',
				    autowidth: true,
				    autoheight: true,
					height: $("#container").height(),
					viewrecords: true,
					multiselect: false,
					multiboxonly: false,
					rowList: eval('[${rmsDefaultRowList}]'),
					gridComplete: function(){
						var colModel = $(this).getGridParam("colModel");
						
						for(let i=0; i < colModel.length; i++){
							$(this).setColProp(colModel[i].name, {sortable: false});
						}
					},
					ondblClickRow: function(rowId){
						var rowData = $(this).getRowData(rowId);

						var bjobBzwkDstcd = rowData['BJOBBZWKDSTCD'];
						var bjobBzwkName = rowData['BJOBBZWKNAME'];
						var osidInstiDstcd = rowData['OSIDINSTIDSTCD'];
						var osidInstiName = rowData['OSIDINSTINAME'];
						var bjobMsgDstcd = rowData['BJOBMSGDSTCD'];
						var bjobTranDstcdName = rowData['BJOBTRANDSTCDNAME'];
						var thisMsgUseYn = rowData['THISMSGUSEYN'];
						
						var url2 = '<c:url value="/bap/admin/schedule/scheduleMonitorMan.view" />';
					    
					    url2= url2 + "?cmd=DETAIL";
			            url2= url2 + '&menuId=' + '${param.menuId}';
			            url2= url2 + '&page=' + $(this).getGridParam("page");
				    	url2= url2 + '&returnUrl=' + getReturnUrl();
				    	url2= url2 + '&bjobBzwkDstcd=' + bjobBzwkDstcd;
				    	url2= url2 + '&bjobBzwkName=' + bjobBzwkName;
				    	url2= url2 + '&osidInstiDstcd=' + osidInstiDstcd;
				    	url2= url2 + '&osidInstiName=' + osidInstiName;
				    	url2= url2 + '&bjobMsgDstcd=' + bjobMsgDstcd;
				    	url2= url2 + '&bjobTranDstcdName=' + bjobTranDstcdName;
				    	url2= url2 + '&thisMsgUseYn=' + thisMsgUseYn;
				    	url2= url2 + '&' + getSearchUrl();
				    	
					    goNav(url2);
					},
					loadError: function(jqXHR, textStatus, errorThrown){
						if(jqXHR.status == 400) {
							alert(jqXHR.responseText);
						}
						
			      		if(jqXHR.status == 401) {
							var location = '<%=request.getContextPath()%>/';
							comloadError(jqXHR, textStatus, errorThrown ,location);
						}
					}
				});
			}
		
			$(document).ready(function(){
				$("#startDatepicker").datepicker();
				$("#endDatepicker").datepicker();
				
				$("input[name=searchStartYYYYMMDD],input[name=searchEndYYYYMMDD]").inputmask("yyyy-mm-dd",{'autoUnmask':true});
				$("input[name=searchStartHHMM],input[name=searchEndHHMM]").inputmask("hh:mm:ss",{'autoUnmask':true});
				
				var searchStartYYYYMMDD = "${param.searchStartYYYYMMDD}";
				var searchEndYYYYMMDD   = "${param.searchEndYYYYMMDD}";
				var searchStartHHMM     = "${param.searchStartHHMM}";
				var searchEndHHMM       = "${param.searchEndHHMM}";

				if(searchStartYYYYMMDD == null || searchStartYYYYMMDD == ''){
					$("input[name=searchStartYYYYMMDD]").val(getToday());
				}
				
				if(searchEndYYYYMMDD == null || searchEndYYYYMMDD == ''){
					$("input[name=searchEndYYYYMMDD]").val(getToday());
				}
				
				if(searchStartHHMM == null || searchStartHHMM == ''){
					$("input[name=searchStartHHMM]").val('000000');
				}
				
				if(searchEndHHMM == null || searchEndHHMM == ''){
					$("input[name=searchEndHHMM]").val('235959');
				}
				
				$("input[name=searchStartYYYYMMDD]").on("change", function(){
					$("input[name=searchEndYYYYMMDD]").val($("input[name=searchStartYYYYMMDD]").val());
				});
				
				$("input[name=searchEndYYYYMMDD]").on("change", function(){
					$("input[name=searchStartYYYYMMDD]").val($("input[name=searchEndYYYYMMDD]").val());
				});
				
				$("#btn_search").click(function(){
					var postData = getSearchForJqgrid("cmd","LIST");
					
					var start = $("input[name=searchStartYYYYMMDD]").val().replace(/-/gi,"")+$("input[name=searchStartHHMM]").val().replace(":","");
					var end = $("input[name=searchEndYYYYMMDD]").val().replace(/-/gi,"")+$("input[name=searchEndHHMM]").val().replace(":","");

					postData["searchStartTime"] = start + "000";
					postData["searchEndTime"] = end + "000";
					
					$("#grid").setGridParam({url: '<c:url value="/bap/admin/schedule/scheduleMonitorMan.json" />', postData: postData, page: "1" }).trigger("reloadGrid");
				});
				
				$("input[name^=search]").keydown(function(key){
					if (key.keyCode == 13){
						$("#btn_search").click();
					}
				});
				
				init();
				list();
			});
		</script>
	</head>
	
	<body>
		<div class="right_box">
			<div class="content_top">
				<ul class="path">
					<li> <a href="#">${rmsMenuPath}</a> </li>
				</ul>
			</div>
			
			<div class="content_middle">
				<div class="search_wrap">
					<img id="btn_search" src="<c:url value="/img/btn_search.png"/>" level="R" />
				</div>
				
				<div class="title">파일 송수신 모니터링</div>
				
				<table class="search_condition" cellspacing=0>
					<tr>
						<th style="width: 150px;">UUID</th>
						<td> <input name="searchBjobDmndMsgID" type="text" value="${param.searchBjobDmndMsgID}" /> </td>
						
						<th style="width: 150px;">SUBUUID</th>
						<td> <input name="searchBjobDmndSubMsgID" type="text" value="${param.searchBjobDmndSubMsgID}" /> </td>
						
						<th style="width: 150px;">거래시간</th>
						<td colspan="3" style="width: 300px;">
							<input id="startDatepicker" name="searchStartYYYYMMDD" type="text" value="${param.searchStartYYYYMMDD}" maxlength="10" size="10" style="width: 20%;" readonly />
							<input name="searchStartHHMM" type="text" value="${param.searchStartHHMM}" maxlength="8" size="8" style="width: 20%;" readonly />
							~
							<input id="endDatepicker" name="searchEndYYYYMMDD" type="text" value="${param.searchEndYYYYMMDD}" maxlength="10" size="10" style="width: 20%;" readonly />
							<input name="searchEndHHMM" type="text" value="${param.searchEndHHMM}" maxlength="8" size="8" style="width: 20%;" readonly />
							
							<input type="hidden" name="searchStartTime" value="20230518000000" />
							<input type="hidden" name="searchEndTime" value="20230518235959" />
						</td>
					</tr>
					
					<tr>
						<th style="width: 150px;">분류</th>
						<td>
							<select name="searchBjobBzwkDstcd" value="${param.searchBjobBzwkDstcd}"></select>
						</td>
						
						<th style="width: 150px;">대외일괄업무</th>
						<td>
							<select name="searchOsidInstiDstcd" value="${param.searchOsidInstiDstcd}" style="width: 100%;"></select>
						</td>
						
						<th style="width: 150px;">최근전송상태</th>
						<td>
							<select name="searchThisStgePrcssRsultCd" value="${param.searchThisStgePrcssRsultCd}" style="width: 100%;">
								<option value="">전체</option>
								<option value="L">지연</option>
								<option value="F">미도래</option>
								<option value="Q">큐대기</option>
								<option value="S">진행중</option>
								<option value="T">정상종료</option>
								<option value="E">비정상종료</option>
								<option value="C">사용자중지</option>
								<option value="N">파일없음</option>
							</select>
						</td>
						
						<th style="width: 150px;">거래여부</th>
						<td>
							<select name="searchInclude" value="${param.searchInclude}" style="width: 100%;">
								<option value="">전체</option>
								<option value="1">있음</option>
								<option value="0">없음</option>
							</select>
						</td>
					</tr>
					
					<tr>
						<th style="width: 150px;">인터페이스ID</th>
						<td> <input name="searchBjobMsgDstcd" type="text" value="${param.searchBjobMsgDstcd}" /> </td>
						
						<th style="width: 150px;">파일코드</th>
						<td> <input name="searchBjobTranDstcdName" type="text" value="${param.searchBjobTranDstcdName}" /> </td>
						
						<th style="width: 150px;">파일명</th>
						<td> <input name="searchSndrcvFileName" type="text" value="${param.searchSndrcvFileName}" /> </td>
						
						<th style="width: 150px;">사용여부</th>
						<td>
							<select name="searchThisMsgUseYn" value="${param.searchThisMsgUseYn}" style="width: 100%;">
								<option value="">전체</option>
								<option value="1">사용함</option>
								<option value="0">사용안함</option>
							</select>
						</td>
					</tr>
				</table>
				<table id="grid"></table>
				<div id="pager"></div>
			</div>
		</div>
	</body>
</html>