<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<c:set var="ctx" value="${pageContext.request.contextPath}" />
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css"
	href="${ctx}/styles/jquery-ui.css" />
</head>
<body>
	<div class="header-title table com-head">
		<div>
			<h1>报表展示</h1>
		</div>
		<div class="borderClass"></div>
		<ul>
			<li>
				<button type="button" id="export" name="export" title="导出"></button>
			</li>
		</ul>
	</div>
	<div class="table-forms-container reports clearfix">
		<div class="reports-cell">
			<div class="dashbrd-widget2">
				<div class="body">
					<ul class="dashbrd-ul">
						<li class="current"><a href="${ctx}/report/abnormalAlarm.php"><span
								class="iconfont icon-gaojingxinxi"></span><label>异常告警报表</label></a></li>
						<li><a href="${ctx}/report/responseTime.php"><span
								class="iconfont icon-iconxiangying"></span><label>响应时间报表</label></a></li>
						<li><a href="${ctx}/report/icmppingLoss.php"><span
								class="iconfont icon-youjianbaoguo"></span><label>丢包率报表</label></a></li>
						<li><a href="${ctx}/report/cpuUsageRate.php"><span
								class="iconfont icon-cpu"></span><label>CPU使用率报表</label></a></li>
						<li><a href="${ctx}/report/memoryUsageRate.php"><span
								class="iconfont icon-neicun"></span><label>内存使用率报表</label></a></li>
						<li><a href="${ctx}/report/diskUsageRate.php"><span
								class="iconfont icon-xunicipanxuanzhong"></span><label>磁盘利用率报表</label></a></li>
						<li><a href="${ctx}/report/interfaceIncoming.php"><span
								class="iconfont icon-xitongjiekou"></span><label>接口的流入流量报表</label></a></li>
						<li><a href="${ctx}/report/interfaceOutgoing.php"><span
								class="iconfont icon-kaifangjiekou"></span><label>接口的流出流量报表</label></a></li>
					</ul>
				</div>
			</div>
		</div>

		<div class="reports-cell">
			<div class="dashbrd-widget3 margin-w  cell-has-line">
				<!-- <div class="dashbrd-widget-head dashbrd-widget-head-hasbtn dashbrd-widget-head-nobg">
						<h4 id = "reportName">异常告警报表</h4>
						<ul>
							<li><button type="button" id="export" name="export" value="导出">导出</button></li>
						</ul>
					</div> -->
				<div class="body">
					<div class="body-count">
						<div class="countTime">

							<select autocomplete="off" id="selectHostGroup"
								onchange="getconfirm()">
							</select> <select autocomplete="off" id="selectHostByGroup"
								style="width: 200px;" onchange="getconfirm()">
								<option value="0" selected="selected">所有主机</option>
							</select> <select autocomplete="off" id="selectPriority"
								onchange="getconfirm()">
								<option value="0" selected="selected">所有异常告警</option>
								<option value="1">未分类</option>
								<option value="2">信息</option>
								<option value="3">警告</option>
								<option value="4">一般严重</option>
								<option value="5">严重</option>
								<option value="6">灾难</option>
							</select>
							<ul class="radio-segmented">
								<li class="lightenblue-bg"><input type="radio"
									id="severity_min_0" name="severity_min" value="0"
									onchange="getconfirm()"> <label for="severity_min_0">最近24小时</label>
								</li>
								<li class="lightenblue-bg">
								<li class="lightenblue-bg"><input type="radio"
									id="severity_min_1" name="severity_min" value="1"
									checked="checked" onchange="getconfirm()"> <label
									for="severity_min_1">最近7天</label></li>
								<li class="lightenblue-bg"><input type="radio"
									id="severity_min_2" name="severity_min" value="2"
									onchange="getconfirm()"> <label for="severity_min_2">最近30天</label>
								</li>
								<li class="lightenblue-bg"><input type="radio"
									id="severity_min_3" name="severity_min" value="3"
									onchange="getconfirm()"> <label for="severity_min_3">最近3个月</label>
								</li>
								<li class="lightenblue-bg"><input type="radio"
									id="severity_min_4" name="severity_min" value="3"
									onclick="customTime()"> <label for="severity_min_4">自定义</label>
								</li>
								<li class="lightenblue-bg datepicker"><input
									id="datepicker_from" name="minDate" class="custom-date"
									disabled="disabled"></li>
								<span class="font">到</span>
								<li class="lightenblue-bg datepicker"><input
									id="datepicker_to" name="maxDate" class="custom-date"
									disabled="disabled"></li>
							</ul>
							<!-- <button type="button" id="confirm" name="confirm" value="确定">确定</button> -->
						</div>
						<div class="countTime"></div>
						<!-- <ul class="radio-segmented">
								<li class="lightenblue-bg">
									<input type="radio" id="severity_min_0" name="severity_min" value="0" checked="checked">
									<label for="severity_min_0">最近7天</label>
								</li><li class="lightenblue-bg">
									<input type="radio" id="severity_min_1" name="severity_min" value="1">
									<label for="severity_min_1">最近30天</label>
								</li><li class="lightenblue-bg">
									<input type="radio" id="severity_min_2" name="severity_min" value="2">
									<label for="severity_min_2">最近半年</label>
								</li><li class="lightenblue-bg">
									<input type="radio" id="severity_min_3" name="severity_min" value="3">
									<label for="severity_min_3">最近1年</label>
								</li>
							</ul>
							<select autocomplete="off" id="selectHostGroup">
							</select>
							<select autocomplete="off" id="selectHostByGroup" style="width:200px;">
								<option value="0" selected="selected">所有主机</option>
							</select>
							<select autocomplete="off" id="selectPriority">
								<option value="0" selected="selected">所有异常告警</option>
								<option value="1">未分类</option>
								<option value="2">信息</option>
								<option value="3">警告</option>
								<option value="4">一般严重</option>
								<option value="5">严重</option>
								<option value="6">灾难</option>
							</select>
						    <button type="button" id="confirm" name="confirm" value="确定">确定</button> -->
					</div>
					<div id="container" style="height: 400px"></div>
				</div>
				<div
					class="dashbrd-widget-head dashbrd-widget-head-hasbtn dashbrd-widget-head-nobg">
					<h4>常发问题TOP10</h4>
				</div>
				<div class="body">
					<div>
						<table class="list-table">
							<thead>
								<tr id="topTen">
									<th>主机</th>
									<th width="60%">问题</th>
									<th>严重性</th>
									<th>发生次数</th>
								</tr>
							</thead>
							<tbody id="topAbnormalAlarm">
								<c:forEach items="${topAbnormalAlarmReports}" varStatus="status"
									var="abnormalAlarm">
									<tr>
										<td>${abnormalAlarm.hname}</td>
										<td>${abnormalAlarm.description}</td>
										<c:if test="${abnormalAlarm.priority == 0}">
											<td>未分类</td>
										</c:if>
										<c:if test="${abnormalAlarm.priority == 1}">
											<td>信息</td>
										</c:if>
										<c:if test="${abnormalAlarm.priority == 2}">
											<td>警告</td>
										</c:if>
										<c:if test="${abnormalAlarm.priority == 3}">
											<td>一般严重</td>
										</c:if>
										<c:if test="${abnormalAlarm.priority == 4}">
											<td>严重</td>
										</c:if>
										<c:if test="${abnormalAlarm.priority == 5}">
											<td>灾难</td>
										</c:if>
										<td>${abnormalAlarm.countPriority}</td>
									</tr>
								</c:forEach>
							</tbody>
						</table>
					</div>
				</div>
			</div>
		</div>
	</div>



	<script src="${ctx}/js/vendors/jquery-ui.js"></script>
	<script src="${ctx}/js/vendors/jquery-datepicker-zh.js"></script>


	<script>
    MMenu.def_label = 'reports';
    var xText = [];
    var sData = [];
    var pname = '';
    var pcolor = '';
    var reportName = jQuery("#reportName").text();
    
    var priorityName = ['未分类','信息','警告','一般严重','严重','灾难'];
    var colors = ['#97AAB3','#7499FF','#FFC859','#FFA059','#E97659','#E45959'];
    //var priorityName = ['未分类','信息','警告','一般严重','严重','灾难'];
    //var priorityName = ['灾难','严重','一般严重','警告','信息','未分类'];
    //var colors = ['#97AAB3','#7499FF','#FFC859','#FFA059','#E97659','#E45959'];
    //var colors = ['#E45959','#E97659','#FFA059','#FFC859','#7499FF','#97AAB3'];
    var date = new Date(),timeValue=[],maxTime=[];
    timeValue.push(date.getFullYear()-1);
	timeValue.push(date.getMonth()+1);
	timeValue.push(date.getDate());
	var minDate = timeValue.join("-");
	maxTime.push(date.getFullYear());
	maxTime.push(date.getMonth()+1);
	maxTime.push(date.getDate());
	var maxDate = maxTime.join("-");
    jQuery("#datepicker_from").datepicker({
    	 defaultDate: new Date() ,
         changeMonth: true,
         numberOfMonths:1,
         changeYear: true,
         dateFormat:"yy-mm-dd"
    }).on( "change", function() {
    	//debugger
    	jQuery("#datepicker_to").datepicker( "option", "minDate", this.value );
    	getconfirm();
    });
   // debugger
    jQuery("#datepicker_from").datepicker( "option", "minDate", minDate );
    jQuery("#datepicker_from").datepicker( "option", "maxDate", maxDate );
    jQuery("#datepicker_to").datepicker({
    	 defaultDate: new Date() ,
         changeMonth: true,
         numberOfMonths: 1,
         changeMonth: true,
         changeYear: true,
         dateFormat:"yy-mm-dd"
    }).on( "change", function() {
    	jQuery("#datepicker_from").datepicker( "option", "maxDate", this.value );
    	getconfirm();
    });
    jQuery("#datepicker_to").datepicker( "option", "maxDate", maxDate );
    jQuery("#datepicker_to").datepicker( "option", "minDate", minDate );
    //处理主机组下拉框信息
    function dealGroupInfo() {
    	var group = jQuery("#selectHostGroup").val();
    	if(group == '所有主机组') {
			group = "1 = 1";
		} else {
			group = "g.name = '" + group + "'";
		}
    	return group;
    }
    
    //处理主机下拉框信息
    function dealHostInfo() {
    	var host = jQuery("#selectHostByGroup :selected").text();
    	if(host.trim() == '所有主机') {
			host = "1 = 1";
		} else {
			host = "h.name= '" + host + "'";
		}
    	return host;
    }
    
    //处理优先级下拉框信息
    function dealPriorityInfo() {
    	var priority = jQuery("#selectPriority :selected").val();
    	if(parseInt(priority) == 0) {
			priority = "1 = 1";
		} else {
			priority = "t.priority = " + (parseInt(priority) - 1);
		}
    	return priority;
    }
    
    //处理时间间隔下拉框信息
    function dealIntervalInfo() {
    	var interval = jQuery("input[name = 'severity_min']:checked ~ label").text();
    	if(interval == '最近7天') {
			interval = 7;
		} else if(interval == '最近30天') {
			interval = 30;
		} else if(interval == '最近半年') {
			interval = 6;
		} else if(interval == '最近24小时'){
			interval = 24;
		} else if(interval == '最近3个月'){
			interval = 3;
		} else {
			interval = 12;
		}
    	return interval;
    }
    
    //绘制图表
    function drawPicture() {
    	var chart = new Highcharts.Chart({
            chart:{
                renderTo:'container',
                type:'column' //显示类型 柱形
            },
            title: {
                text: ''
            },
            credits:{
            	enabled: false
            },
            exporting:{
            	filename:reportName
            },
            legend: {
                align: 'right',
                verticalAlign: 'top',
                x: 0,
                y: 100,
                layout: 'vertical'
            },
            xAxis: {
                categories: xText
            },
            yAxis: {
                min: 0,
                minRange: 0.0001,
                title: {
                    text: ''
                },
                stackLabels:{
                	enabled:true,
                }
            },
            tooltip: {
                pointFormat: '<span style="color:{series.color}">{series.name}</span>: <b>{point.y}</b> ({point.percentage:.0f}%)<br/>',
                shared: true
            },
            plotOptions: {
                column: {
                    stacking: 'column',
                    maxPointWidth: 100
                } ,
                series: {
                	events: {
                    	legendItemClick: function() {
                    		return false;
                    	}
                	}
            	}
            },
            series: sData,
            navigation: {
	            buttonOptions: {
	                enabled: false
	            }
	        }
        });
    }
    
    
  //绘制特定告警级别的图表
    function drawPriorityPicture() {
    	var chart = new Highcharts.Chart({
            chart:{
                renderTo:'container',
                type:'column' //显示类型 柱形
            },
            title: {
                text: ''
            },
            credits:{
            	enabled: false
            },
            exporting:{
            	filename:reportName
            },
            legend: {
                align: 'right',
                verticalAlign: 'top',
                x: 0,
                y: 100,
                layout: 'vertical'
            },
            xAxis: {
                categories: xText
            },
            yAxis: {
                min: 0,
        		minRange: 0.0001,
                title: {
                    text: ''
                },
                stackLabels:{
                	enabled:true,
                }
            },
            tooltip: {
                pointFormat: '<span style="color:{series.color}">{series.name}</span>: <b>{point.y}</b> ({point.percentage:.0f}%)<br/>',
                shared: true
            },
            plotOptions: {
                column: {
                    stacking: 'column'
                } ,
                series: {
                	events: {
                    	legendItemClick: function() {
                    		return false;
                    	}
                	}
            	}
            },
            series:[{
	        	name: pname,
	        	color: pcolor,
	        	data: sData
	        }],
            navigation: {
	            buttonOptions: {
	                enabled: false
	            }
	        }
        });
    }
    
    //统计异常告警
    function countAbnormalAlarm(group,host,priority,interval,startDate,endDate) {
    	
		if("" == startDate && "" == endDate || undefined == startDate && undefined == endDate|| 
				document.getElementById("severity_min_4").checked == false){
	    	jQuery.ajax({
				type:'post',
			    url:"${ctx}/report/countAbnormalAlarm.json", //请求数据的地址
			    async: false,
			    data : {
			    	group : group,
			    	host : host,
			    	priority : priority,
			    	interval : interval
			    },
			    success:function(data){
			    	
			    	var length = 0;
			    	xText = [];
			    	for(var key in data) {
			    		length++;
			    		xText.push(key);
			    	}
			    	
			    	var value = jQuery("#selectPriority :selected").val();  //获取异常告警级别选择的等级
			    	if(value != 0) {   //选择具体的异常告警等级
			    		sData = [];
			    		pname = priorityName[value-1];
			    		pcolor = colors[value-1];
			    		for(var i = 0;i < length;i++){
			    			p = new Object();   //考虑到横坐标会变化
			    			if(data[xText[i]][0] == null) {
			    				p.y = 0;
			    			} else {
			    				p.y = data[xText[i]][0].countPriority;
			    			}
			         		sData.push(p);
				    	}
			    	} else {   //所有异常告警
			    		//初始化一个二维数组，并填充相关数据
				    	var arr = new Array();
				        for(var i = 0;i < 6;i++) {
				    		arr[i] = new Array();
				    		for(var j = 0;j < length;j++) {
				    			arr[i][j] = 0;
				    		}
				    	}
				    	
				       for(var i = 0;i<length;i++){
				    		for(var j = 0;j < 6;j++) {
				    			if(data[xText[i]][j] != null) {
				    				var pp = data[xText[i]][j].priority;
				    				arr[pp][i] = data[xText[i]][j].countPriority;		    		    		
				    			}
				    		}
				        }
				    	sData = [];   //清空数据
				    	
	           		    	//设置数据
	 			    	for(var i = 5;i > -1;i--) {
				    		p = new Object();
			    			p.name = priorityName[i];
			    			p.data = arr[i];
			    			p.color = colors[i];
			    			sData.push(p);
				    	} 
				    	
				    	
	 					/* for(var i = 0;i < 6;i++) {
				    		p = new Object();
			    			p.name = priorityName[i];
			    			p.data = arr[i];
			    			p.color = colors[i];
			    			sData.push(p);
				    	}  */
			    	}
			    },
			    error:function(err){
					alert(err);
				}
			});
	    	return sData;
		}else{
	    	jQuery.ajax({
				type:'post',
			    url:"${ctx}/report/countAbnormalAlarmByDate.json", //请求数据的地址
			    async: false,
			    data : {
			    	group : group,
			    	host : host,
			    	priority : priority,
			    	interval : interval,
			    	startDate: startDate,
			    	endDate: endDate
			    },
			    success:function(data){
			    	
			    	var length = 0;
			    	xText = [];
			    	for(var key in data) {
			    		length++;
			    		xText.push(key);
			    	}
			    	
			    	var value = jQuery("#selectPriority :selected").val();  //获取异常告警级别选择的等级
			    	if(value != 0) {   //选择具体的异常告警等级
			    		sData = [];
			    		pname = priorityName[value-1];
			    		pcolor = colors[value-1];
			    		for(var i = 0;i < length;i++){
			    			p = new Object();   //考虑到横坐标会变化
			    			if(data[xText[i]][0] == null) {
			    				p.y = 0;
			    			} else {
			    				p.y = data[xText[i]][0].countPriority;
			    			}
			         		sData.push(p);
				    	}
			    	} else {   //所有异常告警
			    		//初始化一个二维数组，并填充相关数据
				    	var arr = new Array();
				        for(var i = 0;i < 6;i++) {
				    		arr[i] = new Array();
				    		for(var j = 0;j < length;j++) {
				    			arr[i][j] = 0;
				    		}
				    	}
				    	
				       for(var i = 0;i<length;i++){
				    		for(var j = 0;j < 6;j++) {
				    			if(data[xText[i]][j] != null) {
				    				var pp = data[xText[i]][j].priority;
				    				arr[pp][i] = data[xText[i]][j].countPriority;		    		    		
				    			}
				    		}
				        }
				    	sData = [];   //清空数据
	           		    	//设置数据
	 			    	for(var i = 5;i > -1;i--) {
				    		p = new Object();
			    			p.name = priorityName[i];
			    			p.data = arr[i];
			    			p.color = colors[i];
			    			sData.push(p);
				    	} 
			    	}
			    },
			    error:function(err){
					alert(err);
				}
			});
	    	return sData;
		}
    }
    
    
    
    //format date
    Date.prototype.Format = function (fmt) { 
        var o = {
            "M+": this.getMonth() + 1, //月份 
            "d+": this.getDate(), //日 
            "h+": this.getHours(), //小时 
            "m+": this.getMinutes(), //分 
            "s+": this.getSeconds(), //秒 
            "S": this.getMilliseconds() 
        };
        if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
        for (var k in o)
        if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
        return fmt;
    }
    
    function del() { 
    	 var msg = "确认导出报表\n\n请确认！"; 
    	 if (confirm(msg)==true){ 
    	  return true; 
    	 }else{ 
    	  return false; 
    	 } 
    } 
    
    function exportPdf() {
		var startDate = jQuery("input[name='minDate']").val();
		var endDate = jQuery("input[name='maxDate']").val();
		var startDate = startInput.val();
		var endDate = endInput.val();
    	
    	//var date = new Date().Format("yyyy-MM-dd hh:mm:ss");
    	var date = new Date().Format("yyyy-MM-dd");
    	//console.log("date:"+date);
    	//var filename = "异常告警报表.pdf";
    	var str = "异常告警报表.pdf";
    	var filename = date + str;

		var chart_line = jQuery("#container").highcharts();  
		//图片流hightcharts api
        var svg = chart_line.getSVG();  
        //debugger
        var a = del();
        if(a){
            jQuery.ajax({
    			type:'post',
    		    url:"${ctx}/report/abnormalAlarmExport", //请求数据的地址
    		    data : {
    				svg :	svg,   	
    		    	group : dealGroupInfo(),
    		    	host : dealHostInfo(),
    		    	priority : dealPriorityInfo(),
    		    	interval : dealIntervalInfo(),
    		    	filename : filename,
    		    	startDate: startDate,
    		    	endDate: endDate
    		    },
    		    success:function(data){
    		    	
    		    	window.location.href = "${ctx}/report/download?filename=" + filename;
    		    },
    		    error:function(err){
    				alert(err);
    			}
    		});
        } else{
        	return;
        }

	}
    
    
    function exportPdf2() {
		/* var startDate = jQuery("input[name='minDate']").val();
		var endDate = jQuery("input[name='maxDate']").val(); */
		var startDate = startInput.val();
		var endDate = endInput.val();
    
    	var date = new Date().Format("yyyy-MM-dd");
    	//console.log("date:"+date);
    	//var filename = "异常告警报表.pdf";
    	var str = "异常告警报表.pdf";
    	var filename = date + str;
 
        group = "1 = 1";
        host = "1 = 1";
        priority = "1 = 1";
        interval = "24";
        //debugger
            jQuery.ajax({
    			type:'post',
    		    url:"${ctx}/report/abnormalAlarmExport", //请求数据的地址
    		    data : {
    		  	
    		    	group : group,
    		    	host : host,
    		    	priority : priority,
    		    	interval : interval,
    		    	filename : filename,
    		    	startDate: startDate,
    		    	endDate: endDate
    		    },
    		    success:function(data){
    		    	window.location.href = "${ctx}/report/download?filename=" + filename;
    		    },
    		    error:function(err){
    				alert(err);
    			}
    		});

	}
    
    //
    function expTime(){
    	//11 13 indexOf
    	//2018-07-04 13:15
    	//2018-07-04 09:00
    	var date = new Date().Format("yyyy-MM-dd hh:mm");
    	//截取判断
    	var subStr = date.substring(11,13);
    	console.log("subStr:" + subStr)
    	//
    	if(subStr=="15"){ 
    		exportPdf2();
        	console.log("当前小时:"+subStr);
    	}else{
    		console.log("error");
    	}
}

//test
jQuery(document).ready(function() {
	setTimeout(function(){
		//expTime();
		
	},200)
	
	
});
    
    
    
    
    
    
    
    function customTime(){
    	if(jQuery(".radio-segmented li.datepicker").hasClass("isShow")){
    	/* if(jQuery(".radio-segmented li.datepicker").hasClass("isShow")){
    		jQuery(".radio-segmented li.datepicker").removeClass("isShow");
    		jQuery(".radio-segmented span.font").removeClass("isShow");
    	}else{
    		jQuery(".radio-segmented li.datepicker").addClass("isShow");
    		jQuery(".radio-segmented span.font").addClass("isShow");
    	}*/
    	} 
    	var inputTime=jQuery(".radio-segmented li.datepicker").find('input');
    	inputTime.removeAttr("disabled");
    	
    }
    
    function getconfirm(){
    	  jQuery(function(e) {
    		  //debugger
    	    	var group = '1 = 1';
    	    	var host = '1 = 1';
    	    	var priority = '1 = 1';
    	    	var interval = 7;
    	    	sData = countAbnormalAlarm(group,host,priority,interval);
    	    	drawPicture();
    	    	
    	    	var hostGroup = '<option selected="selected">所有主机组</option>';
/*     	    	jQuery.ajax({
    	    		type:'post',
    	    		url:"${ctx}/report/selectAllHosts.json", //请求查询所有主机的url
    	    		data : null,
    	    		success:function(data){
    	    			host = '<option selected="selected">所有主机</option>';
    	    			for(var i=0;i<data.length;i++){
    	    				host += '<option>' + data[i].name + '</option>';
    	    		    }
    	    		    jQuery("#selectHostByGroup").html(host);
    	    	    }
    	    	}); */
/*     	    	jQuery.ajax({
    	    		type:'post',
    	    		url:"${ctx}/report/selectAllHostGroups.json", //请求数据的地址
    	    		data : null,
    	    		success:function(data){
    	    			
    	    			for(var i=0;i<data.length;i++){
    	    				hostGroup += '<option>' + data[i].name + '</option>';
    	    		    }
    	    		    jQuery("#selectHostGroup").html(hostGroup);
    	    	    }
    	    	}); */
    	    	
    	    	jQuery("#selectHostGroup").change(function() {
    	    		var group = jQuery("#selectHostGroup").val();  //获取主机组下拉菜单的值
    	    		var host = '<option selected="selected">所有主机</option>';
    	    		if(group == '所有主机组') {
    	    			jQuery.ajax({
    	            		type:'post',
    	            		url:"${ctx}/report/selectAllHosts.json", //请求查询所有主机的url
    	            		data : null,
    	            		success:function(data){
    	            			console.log(data)
    	            			for(var i=0;i<data.length;i++){
    	            				host += '<option>' + data[i].name + '</option>';
    	            		    }
    	            		    jQuery("#selectHostByGroup").html(host);
    	            	    },
    	            	    error:function(err){
    	            			alert(err);
    	            		}
    	            	});
    	    		} else {
    	        		jQuery.ajax({
    	            		type:'post',
    	            		url:"${ctx}/report/selectHostByHostGroupName.json", //请求特定主机组所属的主机
    	            		data : {
    	        		    	group : group
    	        		    },
    	            		success:function(data){
    	            			for(var i=0;i<data.length;i++){
    	            				host += '<option>' + data[i].name + '</option>';
    	            		    }
    	            		    jQuery("#selectHostByGroup").html(host);
    	            	    },
    	            	    error:function(err){
    	            			alert(err);
    	            		}
    	            	});
    	    		}
    	    	});
    	    	
    	    	jQuery("#selectHostByGroup").change(function() {
    	    		var group = jQuery("#selectHostGroup").val();  //获取主机组下拉菜单的值
    	    		var host = '<option selected="selected">所有主机</option>';
    	    		if(group == '所有主机组') {
    	    			jQuery.ajax({
    	            		type:'post',
    	            		url:"${ctx}/report/selectAllHosts.json", //请求查询所有主机的url
    	            		data : null,
    	            		success:function(data){
    	            			for(var i=0;i<data.length;i++){
    	            				host += '<div style="background:#ccc;"><option>' + data[i].name + '</option></div>';
    	            		    }
    	            	    },
    	            	    error:function(err){
    	            			alert(err);
    	            		}
    	            	});
    	    		}
    	    	}); 
    	    	jQuery(".dashbrd-ul>li").click(function(e) {
    	    		var href = jQuery(e.target).children("a").attr("href") || jQuery(e.target).parent("a").attr("href");
    	    		if(href){
    	    			window.location.href = href;
    	    		}
    	        })
    	        });
    	    
    	    	var startInput=jQuery("input[name='minDate']");
    			var endInput=jQuery("input[name='maxDate']");

    	    		group = dealGroupInfo();
    	    		host = dealHostInfo();
    	    		priority = dealPriorityInfo();
    	    		interval = dealIntervalInfo();
    	    		var startDate = jQuery("input[name='minDate']").val();
    	    		var endDate = jQuery("input[name='maxDate']").val();
    	    		var startDate = startInput.val();
    	    		var endDate = endInput.val();
    	    		var firstLine=startDate.substring(4,5);
    	    		var secondLine=endDate.substring(4,5);
    	    		var flug=startInput.attr('disabled');
    	    		if(flug!='disabled'){
    	    			if(firstLine!='-'&&secondLine!=='-'){
    	        			startInput.val(" ");
    	            		endInput.val(" ");
    	        			alert('请输入正确格式日期');
    	        			return;
    	        		}
    	    		}
    	    		
    	    		sData = countAbnormalAlarm(group,host,priority,interval,startDate,endDate);

    	    		//startInput.val(" ");
    	    		//endInput.val(" ");
    	    		if(priority == '1 = 1') {   //判断是否画单一告警级别
    	    			drawPicture();
    	    		} else {
    	    			drawPriorityPicture();
    	    		}
    	        	
    	    		if("" == startDate && "" == endDate || undefined == startDate && undefined == endDate|| 
    	    				document.getElementById("severity_min_4").checked == false){
    	            	jQuery.ajax({
    	    				type:'post',
    	    			    url:"${ctx}/report/selectTopAbnormalAlarm.json", //请求数据的地址
    	    			    
    	    			    data : {
    	    			    	group : dealGroupInfo(),
    	    			    	host : dealHostInfo(),
    	    			    	priority : dealPriorityInfo(),
    	    			    	interval : dealIntervalInfo(),
    	    			    	startDate: startDate,
    	    			    	endDate: endDate
    	    			    },
    	    			    success:function(data){
    	    			    	var length = data.length;
    	    			    	jQuery("tbody tr").remove();
    	    			    	var tr = "";
    	    			    	for(var i = 0;i < length;i++) {			    		
    	    			    		tr += "<tr>"
    	    			    	    tr += "<td>" + data[i].hname + "</td>";
    	    			    		tr += "<td>" + data[i].description + "</td>";
    	    			    		tr += "<td>" + priorityName[data[i].priority] + "</td>";
    	    			    		tr += "<td>" + data[i].countPriority + "</td>";
    	    			    		tr += "</tr>"
    	    				    } 
    	    			    	jQuery("tbody").append(tr);
    	    		        },
    	    		        error:function(err){
    	    		    		alert(err);
    	    		    	}
    	    			});
    	    		}else{
    	            	jQuery.ajax({
    	    				type:'post',
    	    			    url:"${ctx}/report/selectTopAbnormalAlarmByDate.json", //请求数据的地址
    	    			    
    	    			    data : {
    	    			    	group : dealGroupInfo(),
    	    			    	host : dealHostInfo(),
    	    			    	priority : dealPriorityInfo(),
    	    			    	interval : dealIntervalInfo(),
    	    			    	startDate: startDate,
    	    			    	endDate: endDate
    	    			    },
    	    			    success:function(data){
    	    			    	//debugger
    	    			    	var length = data.length;
    	    			    	jQuery("#topAbnormalAlarm tr").remove();
    	    			    	var tr = "";
    	    			    	for(var i = 0;i < length;i++) {			    		
    	    			    		tr += "<tr>"
    	    			    	    tr += "<td>" + data[i].hname + "</td>";
    	    			    		tr += "<td>" + data[i].description + "</td>";
    	    			    		tr += "<td>" + priorityName[data[i].priority] + "</td>";
    	    			    		tr += "<td>" + data[i].countPriority + "</td>";
    	    			    		tr += "</tr>"
    	    				    } 
    	    			    	jQuery("#topAbnormalAlarm").append(tr);
    	    		        },
    	    		        error:function(err){
    	    		    		alert(err);
    	    		    	}
    	    			});
    	    		}
    	    		
    	    		if(document.getElementById("severity_min_4").checked == false){
        	    		jQuery.ajax({
        	    			type:'post',
        	    			    url:"${ctx}/report/gettimeslot.json", //请求数据的地址
        	    			   data : {
        	    				  interval : interval
        	    				    },
        	    			    success:function(data){
        	    			    	//debugger
        	    			    	var datafrom = data.stringList[0];
        	    			    	var datato = data.stringList[1];
        	    			    	jQuery("#datepicker_from").removeAttr("disabled").val(datafrom);
        	    			 		jQuery("#datepicker_to").removeAttr("disabled").val(datato);
        	    			 		jQuery("#datepicker_from").attr("disabled",true);
        	   			 		    jQuery("#datepicker_to").attr("disabled",true);

        	    			    },
        	    			    error:function(err){
        	    					alert(err);
        	    				}  
        	    		   });
    	    		}
    }
    
    
    jQuery(function(e) {
    	var group = '1 = 1';
    	var host = '1 = 1';
    	var priority = '1 = 1';
    	var interval = 7;
    	sData = countAbnormalAlarm(group,host,priority,interval);
    	drawPicture();
    	
    	var hostGroup = '<option selected="selected">所有主机组</option>';
     	jQuery.ajax({
    		type:'post',
    		url:"${ctx}/report/selectAllHosts.json", //请求查询所有主机的url
    		data : null,
    		success:function(data){
    			host = '<option selected="selected">所有主机</option>';
    			for(var i=0;i<data.length;i++){
    				host += '<option>' + data[i].name + '</option>';
    		    }
    		    jQuery("#selectHostByGroup").html(host);
    	    },
    	    error:function(err){
    			alert(err);
    		}
    	}); 
    	jQuery.ajax({
    		type:'post',
    		url:"${ctx}/report/selectAllHostGroups.json", //请求数据的地址
    		data : null,
    		success:function(data){
    			
    			for(var i=0;i<data.length;i++){
    				hostGroup += '<option>' + data[i].name + '</option>';
    		    }
    		    jQuery("#selectHostGroup").html(hostGroup);
    	    },
    	    error:function(err){
    			alert(err);
    		}
    	});
    	
    	jQuery("#selectHostGroup").change(function() {
    		var group = jQuery("#selectHostGroup").val();  //获取主机组下拉菜单的值
    		var host = '<option selected="selected">所有主机</option>';
    		if(group == '所有主机组') {
    			jQuery.ajax({
            		type:'post',
            		url:"${ctx}/report/selectAllHosts.json", //请求查询所有主机的url
            		data : null,
            		success:function(data){
            			console.log(data)
            			for(var i=0;i<data.length;i++){
            				host += '<option>' + data[i].name + '</option>';
            		    }
            		    jQuery("#selectHostByGroup").html(host);
            	    },
            	    error:function(err){
            			alert(err);
            		}
            	});
    		} else {
        		jQuery.ajax({
            		type:'post',
            		url:"${ctx}/report/selectHostByHostGroupName.json", //请求特定主机组所属的主机
            		data : {
        		    	group : group
        		    },
            		success:function(data){
            			for(var i=0;i<data.length;i++){
            				host += '<option>' + data[i].name + '</option>';
            		    }
            		    jQuery("#selectHostByGroup").html(host);
            	    },
            	    error:function(err){
            			alert(err);
            		}
            	});
    		}
    	});
    	
    	jQuery("#selectHostByGroup").change(function() {
    		var group = jQuery("#selectHostGroup").val();  //获取主机组下拉菜单的值
    		var host = '<option selected="selected">所有主机</option>';
    		if(group == '所有主机组') {
    			jQuery.ajax({
            		type:'post',
            		url:"${ctx}/report/selectAllHosts.json", //请求查询所有主机的url
            		data : null,
            		success:function(data){
            			for(var i=0;i<data.length;i++){
            				host += '<div style="background:#ccc;"><option>' + data[i].name + '</option></div>';
            		    }
            	    },
            	    error:function(err){
            			alert(err);
            		}
            	});
    		}
    	}); 
    	jQuery(".dashbrd-ul>li").click(function(e) {
    		var href = jQuery(e.target).children("a").attr("href") || jQuery(e.target).parent("a").attr("href");
    		if(href){
    			window.location.href = href;
    		}
        });
    	
		
 		jQuery.ajax({
			type:'post',
			    url:"${ctx}/report/gettimeslot.json", //请求数据的地址
			   data : {
				  interval : 7
				    },
			    success:function(data){
			    	//debugger
			    	var datafrom = data.stringList[0];
			    	var datato = data.stringList[1];
			    	jQuery("#datepicker_from").val(datafrom);
			    	
			 		jQuery("#datepicker_to").val(datato);
			 		
			 		 jQuery("#datepicker_from").attr("disabled",true);
			 		 jQuery("#datepicker_to").attr("disabled",true);
			 		jQuery("#datepicker_from").attr("disabled",true);
			 		    jQuery("#datepicker_to").attr("disabled",true);

			 	    
			    },
			    error:function(err){
					alert(err);
				}
		   }); 
        });
    
    	var startInput=jQuery("input[name='minDate']");
		var endInput=jQuery("input[name='maxDate']");
    	jQuery("#confirm").click(function(e) {
    		group = dealGroupInfo();
    		host = dealHostInfo();
    		priority = dealPriorityInfo();
    		interval = dealIntervalInfo();
    		var startDate = jQuery("input[name='minDate']").val();
    		var endDate = jQuery("input[name='maxDate']").val();
    		var startDate = startInput.val();
    		var endDate = endInput.val();
    		var firstLine=startDate.substring(4,5);
    		var secondLine=endDate.substring(4,5);
    		var flug=startInput.attr('disabled');
    		if(flug!='disabled'){
    			if(firstLine!='-'&&secondLine!=='-'){
        			startInput.val(" ");
            		endInput.val(" ");
        			alert('请输入正确格式日期');
        			return;
        		}
    		}
    		
    		sData = countAbnormalAlarm(group,host,priority,interval,startDate,endDate);

    		//startInput.val(" ");
    		//endInput.val(" ");
    		if(priority == '1 = 1') {   //判断是否画单一告警级别
    			drawPicture();
    		} else {
    			drawPriorityPicture();
    		}
        	
    		if("" == startDate && "" == endDate || undefined == startDate && undefined == endDate|| 
    				document.getElementById("severity_min_4").checked == false){
            	jQuery.ajax({
    				type:'post',
    			    url:"${ctx}/report/selectTopAbnormalAlarm.json", //请求数据的地址
    			    
    			    data : {
    			    	group : dealGroupInfo(),
    			    	host : dealHostInfo(),
    			    	priority : dealPriorityInfo(),
    			    	interval : dealIntervalInfo(),
    			    	startDate: startDate,
    			    	endDate: endDate
    			    },
    			    success:function(data){
    			    	var length = data.length;
    			    	jQuery("tbody tr").remove();
    			    	var tr = "";
    			    	for(var i = 0;i < length;i++) {			    		
    			    		tr += "<tr>"
    			    	    tr += "<td>" + data[i].hname + "</td>";
    			    		tr += "<td>" + data[i].description + "</td>";
    			    		tr += "<td>" + priorityName[data[i].priority] + "</td>";
    			    		tr += "<td>" + data[i].countPriority + "</td>";
    			    		tr += "</tr>"
    				    } 
    			    	jQuery("tbody").append(tr);
    		        },
    		        error:function(err){
    		    		alert(err);
    		    	}
    			});
    		}else{
            	jQuery.ajax({
    				type:'post',
    			    url:"${ctx}/report/selectTopAbnormalAlarmByDate.json", //请求数据的地址
    			    
    			    data : {
    			    	group : dealGroupInfo(),
    			    	host : dealHostInfo(),
    			    	priority : dealPriorityInfo(),
    			    	interval : dealIntervalInfo(),
    			    	startDate: startDate,
    			    	endDate: endDate
    			    },
    			    success:function(data){
    			    	var length = data.length;
    			    	jQuery("tbody tr").remove();
    			    	var tr = "";
    			    	for(var i = 0;i < length;i++) {			    		
    			    		tr += "<tr>"
    			    	    tr += "<td>" + data[i].hname + "</td>";
    			    		tr += "<td>" + data[i].description + "</td>";
    			    		tr += "<td>" + priorityName[data[i].priority] + "</td>";
    			    		tr += "<td>" + data[i].countPriority + "</td>";
    			    		tr += "</tr>"
    				    } 
    			    	jQuery("tbody").append(tr);
    		        },
    		        error:function(err){
    		    		alert(err);
    		    	}
    			});
    		}
    		

    	});
    	
    	jQuery("#export").click(function(e) {
    		exportPdf();
    	});
    	jQuery('.lightenblue-bg').on('click','input',function(event){
    		var lable=event.target;
    		var lableObj=jQuery(lable).next().html();
    		if(lableObj=='最近24小时'||lableObj=='最近7天'||lableObj=='最近30天'||lableObj=='最近3个月'){
    			var inputTime=jQuery(".radio-segmented li.datepicker").find('input');
    	    	inputTime.attr("disabled","disabled");
    	    	startInput.val(" ");
        		endInput.val(" ");
    		}
    	})
    
</script>

</body>
</html>
