nvsanalysis.js 10.6 KB

var g_alarminfoCount1 = null;
var g_alarminfoCount2 = null;
var g_alarminfoCount3 = null;
var g_alarminfoDate1 = null;
var g_alarminfoDate2 = null;
var g_alarminfoDate3 = null;
var g_alarmType = ['移动侦测','入侵检测','视频丢失','遗留物检测','镜头遮挡','动环联动','存储丢失','存储空间不足','硬盘故障','设备离线','服务离线'];
var layer = null;


$(function(){
	layui.use('layer', function(){
		layer = layui.layer; 
    });
	
	if(!getAlarmCount()) {
		layer.msg('获取信息失败', {icon: 2, time: 2000,title:'获取列表',skin: 'layer-ext-moon' });
	} else {
		 char1();
	}
	
	getTopAlarm();
});




function delimiterConvert(val){
   return val.replace('-','/').replace('-','/')
}

function dateFormat(fmt, date) {
    var o = {        
		"M+" : date.getMonth()+1,                 //月份       
		"d+" : date.getDate(),                    //日        
		"h+" : date.getHours(),                   //小时        
		"m+" : date.getMinutes(),                 //分        
		"s+" : date.getSeconds(),                 //秒       
		"q+" : Math.floor((date.getMonth()+3)/3), //季度        
		"S"  : date.getMilliseconds()             //毫秒    
	};    
	
	if(/(y+)/.test(fmt))  {    
		fmt=fmt.replace(RegExp.$1, (date.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 getAlarmCount() {
	var b = "" + getNowFormatDate() + " 00:00:00";
	var e = "" + getNowFormatDate() + " 23:59:59";
	g_alarminfoDate3 = getNowFormatDate();
	g_alarminfoCount3 = getAlarmInfoCountFromServer(b,e);
	if(isEmpty(g_alarminfoCount3)){
		return false;
	}
	
	//console.log('1 b:'+b + " e:"+e); 
	
	var timestamp = Date.parse(delimiterConvert(b)) - 3600 * 24 * 1000;
	var tmpDate = new Date(timestamp);
	b = dateFormat('yyyy-MM-dd hh:mm:ss',tmpDate);
	g_alarminfoDate2 = dateFormat('yyyy-MM-dd',tmpDate);
	timestamp = Date.parse(delimiterConvert(e)) - 3600 * 24 * 1000;
	tmpDate = new Date(timestamp);
	e = dateFormat('yyyy-MM-dd hh:mm:ss',tmpDate);
	g_alarminfoCount2 = getAlarmInfoCountFromServer(b,e);
	
	if(isEmpty(g_alarminfoCount2)){
		return false;
	}
	//console.log('2 b:'+b + " e:"+e); 
	
	timestamp = Date.parse(delimiterConvert(b)) - 3600 * 24 * 1000;
	tmpDate = new Date(timestamp);
	b = dateFormat('yyyy-MM-dd hh:mm:ss',tmpDate);
	g_alarminfoDate1 = dateFormat('yyyy-MM-dd',tmpDate);
	timestamp = Date.parse(delimiterConvert(e)) - 3600 * 24 * 1000;
	tmpDate = new Date(timestamp);
	e = dateFormat('yyyy-MM-dd hh:mm:ss',tmpDate);
	g_alarminfoCount1 = getAlarmInfoCountFromServer(b,e);
	if(isEmpty(g_alarminfoCount1)){
		return false;
	}
	//console.log('3 b:'+b + " e:"+e); 
	
	return true;
}


function getAlarmInfoCountFromServer(b,e){
	
	var timeoutDefaultValue = getNetTimeout() * 1000;
	
	var resData = null;
	var xhr = $.ajax({
		url: "/nvsthird/getalarminfocount",
		type: "post",
		async: false,
		dataType: "json",
		contentType: "application/json",
		data: JSON.stringify({
			token: "",
			begintime: b,
			endtime: e
		}),
		timeout: timeoutDefaultValue,
		success: function(res) {
			if (res != null) {
				resData = res;
			} else {
				layer.msg('获取告警信息列表失败',{icon: 2, title:'获取列表',time: 2000,skin: 'layer-ext-moon' });
			}
		},
		error: function(XMLHttpRequest, textStatus, errorThrown){
			layer.msg('获取警信息列表超时:' + errorThrown, {icon: 2, title:'获取列表',time: 2000,skin: 'layer-ext-moon' });  
		},
		complete : function(XMLHttpRequest,status){ //请求完成后最终执行参数
    	if(status == 'timeout'){//超时,status还有success,error等值的情况
      	 	xhr.abort();
    	} else if(status == 'error') {
				xhr.abort();
				layer.msg('获取警信息列表失败', {icon: 2, time: 2000,title:'获取列表',skin: 'layer-ext-moon' });
			}
  	}
	});
	
	return resData;
}

//统计分析图
function char1() {

    var myChart = echarts.init($("#char1")[0]);

    option = {
		title: {
			text: '告警趋势统计',
			textStyle : {
                color : '#ffffff'
            }
		},
		tooltip: {
			trigger: 'axis'
		},
		legend: {
			data:g_alarmType,
			textStyle : {
                color : '#ffffff'
            }
		},
		grid: {
			left: '3%',
			right: '4%',
			bottom: '3%',
			containLabel: true
		},
		toolbox: {
			feature: {
				saveAsImage: {}
			}
		},
		xAxis: {
			type: 'category',
			boundaryGap: false,
			data: [g_alarminfoDate1,g_alarminfoDate2,g_alarminfoDate3],
			axisLabel: {
                show: true,
                textStyle: {
					color: '#fff'
                }
            }
		},
		yAxis: {
			type: 'value',
			splitLine: {
				show:true,
				lineStyle:{
					color:['#8C8C8C'],
					width: 2,
					type:'dashed'  
				}
			},
			axisLabel: {
                show: true,
                textStyle: {
                    color: '#8C8C8C'
                }
            }
		},
		color:['#00CC00', '#99CCFF','#FF9900','#FF99CC', '#91c7ae','#749f83',  '#ca8622', '#87CEEB','#66CDAA', '#CD1076', '#BF3EFF'],
		series: [
			{
				name:g_alarmType[0],
				type:'line',
				//stack: '总量',
				lineStyle: {
                    width: 2
                },
				data:[g_alarminfoCount1.movingCount, g_alarminfoCount2.movingCount, g_alarminfoCount3.movingCount]
			},
			{
				name:g_alarmType[1],
				type:'line',
				//stack: '总量',
				lineStyle: {
                    width: 2
                },
				data:[g_alarminfoCount1.intrusionCount, g_alarminfoCount2.intrusionCount, g_alarminfoCount3.intrusionCount]
			},
			
			{
				name:g_alarmType[2],
				type:'line',
				//stack: '总量',
				lineStyle: {
                    width: 2
                },
				data:[g_alarminfoCount1.videoLostCount, g_alarminfoCount2.videoLostCount, g_alarminfoCount3.videoLostCount]
			},
			{
				name:g_alarmType[3],
				type:'line',
				//stack: '总量',
				lineStyle: {
                    width: 2
                },
				data:[g_alarminfoCount1.leftTakeCount, g_alarminfoCount2.leftTakeCount, g_alarminfoCount3.leftTakeCount]
			},
			{
				name:g_alarmType[4],
				type:'line',
				//stack: '总量',
				lineStyle: {
                    width: 2
                },
				data:[g_alarminfoCount1.videoCoverCount, g_alarminfoCount2.videoCoverCount, g_alarminfoCount3.videoCoverCount]
			},
			{
				name:g_alarmType[5],
				type:'line',
				//stack: '总量',
				lineStyle: {
                    width: 2
                },
				data:[g_alarminfoCount1.gpioInCount, g_alarminfoCount2.gpioInCount, g_alarminfoCount3.gpioInCount]
			},
			
			{
				name:g_alarmType[6],
				type:'line',
				//stack: '总量',
				lineStyle: {
                    width: 2
                },
				data:[g_alarminfoCount1.recordLostCount, g_alarminfoCount2.recordLostCount, g_alarminfoCount3.recordLostCount]
			},
			{
				name:g_alarmType[7],
				type:'line',
				//stack: '总量',
				lineStyle: {
                    width: 2
                },
				data:[g_alarminfoCount1.recordNoSpaceCount, g_alarminfoCount2.recordNoSpaceCount, g_alarminfoCount3.recordNoSpaceCount]
			},
			{
				name:g_alarmType[8],
				type:'line',
			//	stack: '总量',
				lineStyle: {
                    width: 2
                },
				data:[g_alarminfoCount1.diskFaultCount, g_alarminfoCount2.diskFaultCount, g_alarminfoCount3.diskFaultCount]
			},
			{
				name:g_alarmType[9],
				type:'line',
			//	stack: '总量',
				lineStyle: {
                    width: 2
                },
				data:[g_alarminfoCount1.encoderOffCount, g_alarminfoCount2.encoderOffCount, g_alarminfoCount3.encoderOffCount]
			},
			{
				name:g_alarmType[10],
				type:'line',
				//stack: '总量',
				lineStyle: {
                    width: 2
                },
				data:[g_alarminfoCount1.cruServerOffCount + g_alarminfoCount1.mduServerOffCount + g_alarminfoCount1.msuServerOffCount, 
					  g_alarminfoCount2.cruServerOffCount + g_alarminfoCount2.mduServerOffCount + g_alarminfoCount2.msuServerOffCount, 
				      g_alarminfoCount3.cruServerOffCount + g_alarminfoCount3.mduServerOffCount + g_alarminfoCount3.msuServerOffCount]
			}
			
		]
	};

    myChart.setOption(option,true);
    window.addEventListener('resize', function () {myChart.resize();})

}




function getTopAlarm(){
	var alarmArray = [
		{"type":g_alarmType[0],"count":0},
		{"type":g_alarmType[1],"count":0},
		{"type":g_alarmType[2],"count":0},
		{"type":g_alarmType[3],"count":0},
		{"type":g_alarmType[4],"count":0},
		{"type":g_alarmType[5],"count":0},
		{"type":g_alarmType[6],"count":0},
		{"type":g_alarmType[7],"count":0},
		{"type":g_alarmType[8],"count":0},
		{"type":g_alarmType[9],"count":0},
		{"type":g_alarmType[10],"count":0} ];
		
		
	alarmArray[0].count = g_alarminfoCount1.movingCount + g_alarminfoCount2.movingCount + g_alarminfoCount3.movingCount;
		
	alarmArray[1].count = g_alarminfoCount1.intrusionCount +  g_alarminfoCount2.intrusionCount + g_alarminfoCount3.intrusionCount;
	
	alarmArray[2].count = g_alarminfoCount1.videoLostCount +  g_alarminfoCount2.videoLostCount + g_alarminfoCount3.videoLostCount;
		
	alarmArray[3].count = g_alarminfoCount1.leftTakeCount + g_alarminfoCount2.leftTakeCount + g_alarminfoCount3.leftTakeCount;

	alarmArray[4].count = g_alarminfoCount1.videoCoverCount + g_alarminfoCount2.videoCoverCount + g_alarminfoCount3.videoCoverCount;

	alarmArray[5].count = g_alarminfoCount1.gpioInCount + g_alarminfoCount2.gpioInCount + g_alarminfoCount3.gpioInCount;

	alarmArray[6].count = g_alarminfoCount1.recordLostCount + g_alarminfoCount2.recordLostCount + g_alarminfoCount3.recordLostCount;

	alarmArray[7].count = g_alarminfoCount1.recordNoSpaceCount + g_alarminfoCount2.recordNoSpaceCount + g_alarminfoCount3.recordNoSpaceCount;

	alarmArray[8].count = g_alarminfoCount1.diskFaultCount + g_alarminfoCount2.diskFaultCount + g_alarminfoCount3.diskFaultCount;

	alarmArray[9].count = g_alarminfoCount1.encoderOffCount + g_alarminfoCount2.encoderOffCount + g_alarminfoCount3.encoderOffCount;

	alarmArray[10].count = g_alarminfoCount1.cruServerOffCount + g_alarminfoCount1.mduServerOffCount + g_alarminfoCount1.msuServerOffCount + g_alarminfoCount2.cruServerOffCount + g_alarminfoCount2.mduServerOffCount + g_alarminfoCount2.msuServerOffCount + g_alarminfoCount3.cruServerOffCount + g_alarminfoCount3.mduServerOffCount + g_alarminfoCount3.msuServerOffCount;

	alarmArray.sort(function(a, b){return b.count - a.count});
	
	$("#alarm-type-1").html(alarmArray[0].type);
	$("#alarm-count-1").html("" + alarmArray[0].count);
	
	$("#alarm-type-2").html(alarmArray[1].type);
	$("#alarm-count-2").html("" + alarmArray[1].count);
	
	$("#alarm-type-3").html(alarmArray[2].type);
	$("#alarm-count-3").html("" + alarmArray[2].count);
}