/*
//信息发布
function loadXxfbDiv(data,num){
	//console.log(data);
	var tmpmsg = new Array();
	tmpmsg.push("<div id='plan_exec_div_'"+num+" style='width:100px;float:left;border:1px solid #ff00ff;'>");
	tmpmsg.push("<div id='plan_execmodel_'"+num+">"+data.execModelName+"</div>");	
	tmpmsg.push("<div>"+data.linkageDeviceName+"</div>");
	tmpmsg.push("<div id='run_zt_'"+num+">等待中</div>");		
	tmpmsg.push("<div id='run_zxzx_'"+num+" style='display:none;' onclick='planExec("+num+",0)' >重新执行</div>");	
	tmpmsg.push("<div id='run_qrzx_'"+num+" style='display:none;' onclick='planExec("+num+",1)' >确认执行</div>");	
	tmpmsg.push("<div id='run_tgzx_'"+num+" onclick='planExec("+num+",2)' >跳过执行</div>");	
	tmpmsg.push("<div id='run_tqzx_'"+num+" onclick='planExec("+num+",3)' >提前执行</div>");	
	tmpmsg.push("<div id='plan_device_div_"+data.linkageID+"'></div>");	
	tmpmsg.push("</div>");
	return tmpmsg.join("");
}
//诱导灯
function loadYddDiv(data,num){
	//console.log(data);
	var tmpmsg = new Array();
	tmpmsg.push("<div id='plan_exec_div_'"+num+" style='width:100px;float:left;border:1px solid #ff00ff;'>");
	tmpmsg.push("<div id='plan_execmodel_'"+num+">"+data.execModelName+"</div>");	
	tmpmsg.push("<div>"+data.linkageDeviceName+"</div>");
	tmpmsg.push("<div id='run_zt_'"+num+">等待中</div>");		
	tmpmsg.push("<div id='run_zxzx_'"+num+" style='display:none;' onclick='planExec("+num+",0)' >重新执行</div>");	
	tmpmsg.push("<div id='run_qrzx_'"+num+" style='display:none;' onclick='planExec("+num+",1)' >确认执行</div>");	
	tmpmsg.push("<div id='run_tgzx_'"+num+" onclick='planExec("+num+",2)' >跳过执行</div>");	
	tmpmsg.push("<div id='run_tqzx_'"+num+" onclick='planExec("+num+",3)' >提前执行</div>");	
	tmpmsg.push("<div id='plan_device_div_"+data.linkageID+"'></div>");	
	tmpmsg.push("</div>");
	return tmpmsg.join("");
}
//大屏上墙
function loadDpsqDiv(data,num){
	//console.log(data);
	var tmpmsg = new Array();
	tmpmsg.push("<div id='plan_exec_div_'"+num+" style='width:100px;float:left;border:1px solid #ff00ff;' >");
	tmpmsg.push("<div id='plan_execmodel_'"+num+">"+data.execModelName+"</div>");	
	tmpmsg.push("<div>"+data.linkageDeviceName+"</div>");
	tmpmsg.push("<div id='run_zt_'"+num+">等待中</div>");		
	tmpmsg.push("<div id='run_zxzx_'"+num+" style='display:none;' onclick='planExec("+num+",0)' >重新执行</div>");	
	tmpmsg.push("<div id='run_qrzx_'"+num+" style='display:none;' onclick='planExec("+num+",1)' >确认执行</div>");	
	tmpmsg.push("<div id='run_tgzx_'"+num+" onclick='planExec("+num+",2)' >跳过执行</div>");	
	tmpmsg.push("<div id='run_tqzx_'"+num+" onclick='planExec("+num+",3)' >提前执行</div>");	
	tmpmsg.push("<div id='plan_device_div_"+data.linkageID+"'></div>");	
	tmpmsg.push("</div>");
	return tmpmsg.join("");
}
//平台通信
function loadPttxDiv(data,num){
	//console.log(data);
	var tmpmsg = new Array();
	tmpmsg.push("<div id='plan_exec_div_'"+num+" style='width:100px;float:left;border:1px solid #ff00ff;' >");
	tmpmsg.push("<div id='plan_execmodel_'"+num+">"+data.execModelName+"</div>");	
	tmpmsg.push("<div>"+data.linkageDeviceName+"</div>");
	tmpmsg.push("<div id='run_zt_'"+num+">等待中</div>");		
	tmpmsg.push("<div id='run_zxzx_'"+num+" style='display:none;' onclick='planExec("+num+",0)' >重新执行</div>");	
	tmpmsg.push("<div id='run_qrzx_'"+num+" style='display:none;' onclick='planExec("+num+",1)' >确认执行</div>");	
	tmpmsg.push("<div id='run_tgzx_'"+num+" onclick='planExec("+num+",2)' >跳过执行</div>");	
	tmpmsg.push("<div id='run_tqzx_'"+num+" onclick='planExec("+num+",3)' >提前执行</div>");	
	tmpmsg.push("<div id='plan_device_div_"+data.linkageID+"'></div>");	
	tmpmsg.push("</div>");
	return tmpmsg.join("");
}
//语音播报
function loadYybbDiv(data,num){
	//console.log(data);
	var tmpmsg = new Array();
	tmpmsg.push("<div id='plan_exec_div_'"+num+" style='width:100px;float:left;border:1px solid #ff00ff;' >");
	tmpmsg.push("<div id='plan_execmodel_'"+num+">"+data.execModelName+"</div>");	
	tmpmsg.push("<div>"+data.linkageDeviceName+"</div>");
	tmpmsg.push("<div id='run_zt_'"+num+">等待中</div>");		
	tmpmsg.push("<div id='run_zxzx_'"+num+" style='display:none;' onclick='planExec("+num+",0)' >重新执行</div>");	
	tmpmsg.push("<div id='run_qrzx_'"+num+" style='display:none;' onclick='planExec("+num+",1)' >确认执行</div>");	
	tmpmsg.push("<div id='run_tgzx_'"+num+" onclick='planExec("+num+",2)' >跳过执行</div>");	
	tmpmsg.push("<div id='run_tqzx_'"+num+" onclick='planExec("+num+",3)' >提前执行</div>");	
	tmpmsg.push("<div id='plan_device_div_"+data.linkageID+"'></div>");	
	tmpmsg.push("</div>");
	return tmpmsg.join("");
}
//声光报警
function loadSgbjDiv(data,num){
	//console.log(data);
	var tmpmsg = new Array();
	tmpmsg.push("<div id='plan_exec_div_'"+num+" style='width:100px;float:left;border:1px solid #ff00ff;' >");
	tmpmsg.push("<div id='plan_execmodel_'"+num+">"+data.execModelName+"</div>");	
	tmpmsg.push("<div>"+data.linkageDeviceName+"</div>");
	tmpmsg.push("<div id='run_zt_'"+num+">等待中</div>");		
	tmpmsg.push("<div id='run_zxzx_'"+num+" style='display:none;' onclick='planExec("+num+",0)' >重新执行</div>");	
	tmpmsg.push("<div id='run_qrzx_'"+num+" style='display:none;' onclick='planExec("+num+",1)' >确认执行</div>");	
	tmpmsg.push("<div id='run_tgzx_'"+num+" onclick='planExec("+num+",2)' >跳过执行</div>");	
	tmpmsg.push("<div id='run_tqzx_'"+num+" onclick='planExec("+num+",3)' >提前执行</div>");	
	tmpmsg.push("<div id='plan_device_div_"+data.linkageID+"'></div>");	
	tmpmsg.push("</div>");
	return tmpmsg.join("");
}
//短信通知
function loadDxtzDiv(data,num){
	//console.log(data);
	var tmpmsg = new Array();
	tmpmsg.push("<div id='plan_exec_div_'"+num+" style='width:100px;float:left;border:1px solid #ff00ff;' >");
	tmpmsg.push("<div id='plan_execmodel_'"+num+">"+data.execModelName+"</div>");	
	tmpmsg.push("<div>"+data.linkageDeviceName+"</div>");
	tmpmsg.push("<div id='run_zt_'"+num+">等待中</div>");		
	tmpmsg.push("<div id='run_zxzx_'"+num+" style='display:none;' onclick='planExec("+num+",0)' >重新执行</div>");	
	tmpmsg.push("<div id='run_qrzx_'"+num+" style='display:none;' onclick='planExec("+num+",1)' >确认执行</div>");	
	tmpmsg.push("<div id='run_tgzx_'"+num+" onclick='planExec("+num+",2)' >跳过执行</div>");	
	tmpmsg.push("<div id='run_tqzx_'"+num+" onclick='planExec("+num+",3)' >提前执行</div>");	
	tmpmsg.push("<div id='plan_device_div_"+data.linkageID+"'></div>");	
	tmpmsg.push("</div>");
	return tmpmsg.join("");
}
//结束预案
function loadJsyaDiv(data,num){
	//console.log(data);
	var tmpmsg = new Array();
	tmpmsg.push("<div id='plan_exec_div_'"+num+" style='width:100px;float:left;border:1px solid #ff00ff;' >");
	tmpmsg.push("<div id='plan_execmodel_'"+num+">"+data.execModelName+"</div>");	
	tmpmsg.push("<div>"+data.linkageDeviceName+"</div>");
	tmpmsg.push("<div id='run_zt_'"+num+">等待中</div>");		
	tmpmsg.push("<div id='run_zxzx_'"+num+" style='display:none;' onclick='planExec("+num+",0)' >重新执行</div>");	
	tmpmsg.push("<div id='run_qrzx_'"+num+" style='display:none;' onclick='planExec("+num+",1)' >确认执行</div>");	
	tmpmsg.push("<div id='run_tgzx_'"+num+" onclick='planExec("+num+",2)' >跳过执行</div>");	
	tmpmsg.push("<div id='run_tqzx_'"+num+" onclick='planExec("+num+",3)' >提前执行</div>");	
	tmpmsg.push("<div id='plan_device_div_"+data.linkageID+"'></div>");	
	tmpmsg.push("</div>");
	return tmpmsg.join("");
}
*/
//通用设备执行
function loadPlanExecDiv(data,num){
	//console.log(data);
	//console.log(num);
	var tmpmsg = new Array();
	//tmpmsg.push("<div class='container'>");
	tmpmsg.push("	<div class='linkageMenu' style='border:1px solid #ff00ff;'>");
	tmpmsg.push("		<div class='linkageMenu-top1'>");
	tmpmsg.push("			<div class='linkageMenu-top1-title'>");
	tmpmsg.push("				<div class='linkageMenu-top1-tb1'>");
	if(data.execModel=="0"){
		tmpmsg.push("					<img src='image/state-zd.png'/>");
	}else{
		tmpmsg.push("					<img src='image/state-sd.png'/>");
	}
	tmpmsg.push("				</div>");
	tmpmsg.push("			</div>");
	tmpmsg.push("			<div class='linkageMenu-top1-state' >");
	tmpmsg.push(data.linkageDeviceName+":<span id='plan_exec_zt_"+num+"'>等待中</span>");
	//语音播报，已完成
	tmpmsg.push("			</div>");
	tmpmsg.push("			<div class='linkageMenu-top3'>");
	tmpmsg.push("		  		<ul class='linkageMenu-control-button'>");			
	tmpmsg.push("		  			<li id='plan_exec_zx_"+num+"' class='linkageMenu-control-active' style='display:none;' onclick='planExec("+num+",0)' >重新执行</li>");
	tmpmsg.push("		  			<li id='plan_exec_qr_"+num+"' class='linkageMenu-control-active' style='display:none;' onclick='planExec("+num+",1)' >确认执行</li>");
	tmpmsg.push("		  			<li id='plan_exec_tg_"+num+"' class='linkageMenu-control-active' onclick='planExec("+num+",2)' >跳过执行</li>");
	tmpmsg.push("		  			<li id='plan_exec_tq_"+num+"' class='linkageMenu-control-active' onclick='planExec("+num+",3)' >提前执行</li>");
	tmpmsg.push("		  		</ul>");
	tmpmsg.push("		  	</div>");
	tmpmsg.push("		</div>");
	tmpmsg.push("		<div class='linkageMenu-top2' id='plan_device_div_"+data.linkageID+"' >");
	//tmpmsg.push("		<div id='plan_device_div_"+data.linkageID+"'></div>");	
	//该列请自由发挥！
	tmpmsg.push("		</div>");
	tmpmsg.push("		<div style='clear:both'></div>");
	tmpmsg.push("	</div>");
	//tmpmsg.push("	<div class='linkageMenu'>");
	//tmpmsg.push("		<div style='clear:both'></div>");
	//tmpmsg.push("	</div>");
	//tmpmsg.push("</div>");
	return tmpmsg.join("");
}

//关联显示预案
function unionPlan(){
	var params = {};
	params.alarmType = planRecords.eventType;
	params.planGrade = planRecords.alarmLevel;
	params.channelId = planRecords.vdId+"-"+planRecords.channelId;
	params.page = "1";
	params.rows = "1";
	$.ajax({
		type: "post",
		url: "trafficplanmanageAction!query_Trafficplanmanage_sjgl.do",
		dataType: "json",
		data: params,
	}).done(function(res) {
		if(res.length>0){
			$('#planName').append(res[0].planName);
			loadPlanExecAction(res[0].planID);
		}
	});
}
//加载预案执行任务
function loadPlanExecAction(planID){
	var params = {};
	params.planID = planID;
	params.page = "1";
	params.rows = "100";
	params.order = " order by linkageOrder asc ";
	$.ajax({
		type: "post",
		url: "trafficplanlinkagedeviceAction!query_Trafficplanlinkagedevice.do",
		dataType: "json",
		data: params,
	}).done(function(res) {
		var tmplinkage = new Array();
		planExecRecord = res;
		$('#allExecStep').val(res.length);
		for(var x=0;x<res.length;x++){
			var tmpplan = res[x];
			tmpplan = changeExecModel(tmpplan);
			tmplinkage.push(loadPlanExecDiv(tmpplan,(1+x)));
			if(x==(res.length-1)){
				$('#planlinageDiv').append(tmplinkage.join(""));
				$('#planName').append(res[0].planName);
				loadPlanDeviceAction(res[0].planID);
			}
		}
	});
}
////加载预案设备
function loadPlanDeviceAction(planID){
	var params = {};
	params.planID = planID;
	params.page = "1";
	params.rows = "100";
	params.order = " order by linkageId,execOrder asc ";
	$.ajax({
		type: "post",
		url: "trafficplanexecmodeAction!query_Trafficplanexecmode.do",
		dataType: "json",
		data: params,
	}).done(function(res) {
		var deviceHtml = "";
		planDeviceRecord = res;
		for(var x=0;x<res.length;x++){
			var tmpplanDevice = res[x];
			deviceHtml = loadPlanDeviceDiv(tmpplanDevice);
			if($('#plan_device_div_'+tmpplanDevice.linkageID)){
				$('#plan_device_div_'+tmpplanDevice.linkageID).append(deviceHtml);
			}else{
				console.log("===error======");
			}
			if(x==(res.length-1)){
				startPlanExec();
			}
		}
	});
}

function loadPlanDeviceDiv(data){
	data = changeExecModel(data);
	var tmpkey = "_"+data.linkageID+"_"+data.planType+"_"+data.execOrder;
	var tmpmsg = new Array();
	tmpmsg.push("<div>"+data.typeName);
	tmpmsg.push("	<div id='plan_linkage_"+tmpkey+"' >");
	tmpmsg.push("		<div id='plan_linkage_deviceId_"+tmpkey+"' >"+data.linkageDeviceId+"</div>");
	tmpmsg.push("		<div id='plan_linkage_deviceName_"+tmpkey+"' >"+data.linkageDeviceName+"</div>");
	tmpmsg.push("		<div id='plan_linkage_message_"+tmpkey+"' >"+data.messageContent+"</div>");
	tmpmsg.push("		<div id='plan_linkage_runmode_"+tmpkey+"' >"+data.execModelName+"</div>");
	tmpmsg.push("		<div id='plan_linkage_statu_"+tmpkey+"' >等待中</div>");	
	tmpmsg.push("	</div>");
	tmpmsg.push("</div>");
	return tmpmsg.join("");
}
function startPlanExec(){
	var currentExecStep = $('#currentExecStep').val();
	if(!currentExecStep){
		currentExecStep = 1;
		$('#currentExecStep').val(currentExecStep);
		var tmpplanexec = planExecRecord[(currentExecStep-1)];
		if(tmpplanexec){
			$('#currentExecLinkage').val(tmpplanexec.linkageID);
			//自动，手动执行
			if(tmpplanexec.execModel=="0"){
				//确认执行
				planExec((currentExecStep),'1');
			}else{
				//$('#plan_exec_zt_'+currentStepStat).html(data.linkageDeviceName+":正在执行");
			}
		}
	}
}
function planExec(num,type){
	if(planExecRecord){
		var planExecModel = planExecRecord[(num-1)];
		console.log(planExecModel);
		//改变状态
		$('#plan_exec_zt_'+num).html(planExecModel.linkageDeviceName+":正在执行");
		var currentDeviceStep = $('#currentDeviceStep').val();
		console.log("=currentDeviceStep="+currentDeviceStep);
		for(var i=0;i<planDeviceRecord.length;i++){
			var planDeviceInfo = planDeviceRecord[i];
			var tmpStep = planDeviceInfo.linkageID+"_"+planDeviceInfo.execOrder;
			if(planDeviceInfo.linkageID==planExecModel.linkageID){
				if(currentDeviceStep==tmpStep){
					planExecDevice(planDeviceInfo,'0');
					break;
				}
				if(!currentDeviceStep){
					currentDeviceStep = (tmpStep);
					planExecDevice(planDeviceInfo,'0');
					break;
				}
			}
		}
		$('#currentDeviceStep').val(currentDeviceStep);
	}
}

function planExecDevice(planDeviceInfo,type){
	/*
	private String senderModuleName;//消息发送模块名称，trafficLinkage 交通联动
	private String eventId;//事故主键
	private String alarmCode;//事故类型编码，1：交通事故；2：自然灾害；3：恶劣天气；4：严重违法行为；5：路面损毁；6：交通拥堵；7：货物散落；8：特殊事件；9：其他事件
	private String deviceType;//设备类型，代码字段：1：情报板；2：交通诱导灯。3
	 1-信息发布；2-诱导灯联动； 3-大屏上墙； 4-平台通信； 5-语音提醒；6-声光报警；7-短信通知；99-结束预案
	private String deviceId;//设备ID，多个设备id用分号隔开
	private String execState;//设备执行状态代码； 1：未执行，2：执行中，3：执行成功，4：执行失败。
	private String execTime;//执行时间字符串，格式YYYY-MM-DD HH24:MI:SS
	private String createAppName;//创建人，trafficLinkage
	private String createTime;//创建时间
	private String type;
	*/
	var tmpkey = "_"+planDeviceInfo.linkageID+"_"+planDeviceInfo.planType+"_"+planDeviceInfo.execOrder;
	
	console.log("======planExecDevice======tmpkey="+tmpkey);
	if($("#plan_linkage_statu_"+tmpkey)){
		$("#plan_linkage_statu_"+tmpkey).html("执行中");	
	}
	if(planDeviceInfo.planType=="5"){
		var mm = {};
		mm.senderModuleName = "trafficLinkage";
		mm.eventId = planRecords.eventId;
		mm.alarmCode = planRecords.eventType;
		mm.deviceType = planDeviceInfo.planType;
		mm.deviceId = planDeviceInfo.linkageDeviceId;
		mm.execState = "4";
		mm.createAppName = type;
		$.ajax({
			type:'post',
			dataType : 'json',
			url:'amqTrafficLinkageDeviceAction!publish_TrafficEventExecState_yybb.do',
			data:mm,
			success:function(value){
				if(value=="success"){
					$("#requestState").val("1");
					$.showMsg('语音播报中! ');
				}
			}
		});
	}
	if(planDeviceInfo.planType=="3"){
		var mm = {};
		mm.senderModuleName = "trafficLinkage";
		mm.alarmId = planRecords.eventId;
		mm.alarmCode = planRecords.eventType;
		mm.deviceType = planDeviceInfo.planType;
		mm.deviceId = planDeviceInfo.linkageDeviceId;
		mm.execState = "4";
		mm.createAppName = type;		
		/*
		VideoToWallHolder holder = new VideoToWallHolder();
		VideoToWall action = new VideoToWall();
		if(RHUtil.isNotEmpty(map.get("type"))){
			action.setType(map.get("type").toString());
		}
		if(RHUtil.isNotEmpty(map.get("alarmId"))){
			action.setAlarmId(map.get("alarmId").toString());//告警id
		}
		if(RHUtil.isNotEmpty(map.get("alarmCode"))){
			action.setAlarmCode(map.get("alarmCode").toString()); //事故类型编码
		}
		if(RHUtil.isNotEmpty(map.get("alarmTime"))){
			action.setAlarmTime(map.get("alarmTime").toString());
		}
		if(RHUtil.isNotEmpty(map.get("alarmName"))){
			action.setAlarmName(map.get("alarmName").toString());
		}
		if(RHUtil.isNotEmpty(map.get("fdId"))){
			action.setFdId(map.get("fdId").toString()); //
		}
		if(RHUtil.isNotEmpty(map.get("channelId"))){
			action.setChannelId(map.get("channelId").toString()); 
		}
		if(RHUtil.isNotEmpty(map.get("videoType"))){
			action.setVideoType(map.get("videoType").toString());
		}
		if(RHUtil.isNotEmpty(map.get("beginTime"))){
			action.setBeginTime(map.get("beginTime").toString());
		}			
		if(RHUtil.isNotEmpty(map.get("duration"))){
			action.setDuration(map.get("duration").toString());
		}
		if(RHUtil.isNotEmpty(map.get("wallId"))){
			action.setWallId(map.get("wallId").toString());
		}
		if(RHUtil.isNotEmpty(map.get("secnceId"))){
			action.setSecnceId(map.get("secnceId").toString());
		}
		if(RHUtil.isNotEmpty(map.get("winId"))){
			action.setWinId(map.get("winId").toString());
		}
		if(RHUtil.isNotEmpty(map.get("overlayText"))){
			action.setOverlayText(map.get("overlayText").toString());
		}
		if(RHUtil.isNotEmpty(map.get("jpgurl"))){
			action.setJpgurl(map.get("jpgurl").toString());
		}
		*/
		$.ajax({
			type:'post',
			dataType : 'json',
			url:'amqTrafficLinkageDeviceAction!publish_VideoToWall.do',
			data:mm,
			success:function(value){
				if(value=="success"){
					$("#requestState").val("1");
					$.showMsg('上墙联动中! ');
				}
			}
		});
	}
}
