function PlanRun(){}
PlanRun.init = function (){
	PlanRun();
}
//开启第一个节点任务--0:重新执行，1:确认执行, 2跳过执行，3提早执行，4手动执行，5延时执行
PlanRun.startPlanFirst = function(data){	
	if(data){
		for(var i=0;i<data.length;i++){
			var tmpplanDevice = data[i];
			var tmpPlanStep = PlanExec.stepMap.get(tmpplanDevice.linkageID);
			if(tmpPlanStep.execModel=="0"){
				$('#plan_exec_tp_'+tmpPlanStep.linkageID).attr("src","../../../../../../bigscreen/bigpage2/resource/img/jian1.png");
				$("#plan_linkage_statu_"+tmpPlanStep.linkageID).removeClass("state-wait");
				$('#plan_exec_jd_'+tmpPlanStep.linkageID).removeClass("planYuan-first2");
				$('#plan_exec_jd_'+tmpPlanStep.linkageID).addClass("planYuan-first4");
				$("#plan_exec_zt_"+tmpPlanStep.linkageID).html("<span class='icon-state icon-run' ></span>正在执行");
				PlanRun.planDeviceAmq(tmpplanDevice);
			}
			if(tmpPlanStep.execModel=="1"){
				//PlanRun.planDeviceAmq(tmpplanDevice);
			}
			if(tmpPlanStep.execModel=="2"){
				//console.log(i+"=execModel111="+tmpPlanStep.execModel+"=delayLinkageID="+$('#delayLinkageID').val());
				if(i==0){
					$('#delayLinkageID').val(tmpPlanStep.linkageID+";");
				}else{
					if(tmpplanDevice.linkageID!=data[i-1].linkageID){
						var delayLinkageID = $('#delayLinkageID').val();
						if(delayLinkageID){
							$('#delayLinkageID').val(delayLinkageID+tmpPlanStep.linkageID+";");
						}else{
							$('#delayLinkageID').val(tmpPlanStep.linkageID+";");
						}
					}
				}
				$('#plan_step_delay_'+tmpPlanStep.linkageID).html(tmpPlanStep.delayTime);
			}
		}
		$("#planState").val("1");
		$("#requestState").val("1");
	}
}

//预案设备执行发布,调用后台及AMQ
PlanRun.planDeviceAmq = function(planDeviceModel){
	if(planDeviceModel.planType=="1"||planDeviceModel.planType=="2"||planDeviceModel.planType=="3"||planDeviceModel.planType=="4"){
		var mm = {};
		mm.senderModuleName = "trafficLinkage";
		mm.eventId = PlanExec.planRecord.eventId;
		mm.alarmCode = PlanExec.planRecord.eventType;
		mm.deviceType = planDeviceModel.planType;
		mm.deviceId = planDeviceModel.linkageDeviceId;
		mm.execState = "4";
		//mm.type = runType;
		mm.deviceInstruction = "";//设备指令；		Led情报板指令：情报板显示文字。		交通诱导灯指令：1：禁止-红灯；2：通行-绿灯；3：黄灯；4：关灯。
		//mm.createAppName = runType;		
		$.ajax({
			type:'post',
			dataType : 'json',
			url:'amqTrafficLinkageDeviceAction!publish_TrafficEventLinkageAction.do',
			data:mm,
			success:function(value){
				if(value=="success"){
					
				}
			}
		});
	}
	if(planDeviceModel.planType=="5"){
		var mm = {};
		mm.senderModuleName = "trafficLinkage";
		mm.alarmId = PlanExec.planRecord.eventId;
		mm.alarmCode = PlanExec.planRecord.eventType;
		mm.deviceType = planDeviceModel.planType;
		mm.deviceId = planDeviceModel.linkageDeviceId;
		mm.execState = "4";
		//mm.createAppName = runType;		
		$.ajax({
			type:'post',
			dataType : 'json',
			url:'amqTrafficLinkageDeviceAction!publish_VideoToWall.do',
			data:mm,
			success:function(value){
				if(value=="success"){
					
				}
			}
		});
	}
	if(planDeviceModel.planType=="7"){
		var mm = {};
		mm.senderModuleName = "trafficLinkage";
		mm.eventId = PlanExec.planRecord.eventId;
		mm.alarmCode = PlanExec.planRecord.eventType;
		mm.deviceType = planDeviceModel.planType;
		mm.deviceId = planDeviceModel.linkageDeviceId;
		mm.execState = "3";
		//mm.createAppName = runType;
		$.ajax({
			type:'post',
			dataType : 'json',
			url:'amqTrafficLinkageDeviceAction!publish_TrafficEventExecState_yybb.do',
			data:mm,
			success:function(value){
				if(value=="success"){
					
				}
			}
		});
	}
	if(planDeviceModel.planType=="8"){
		var mm = {};
		mm.senderModuleName = "trafficLinkage";
		mm.eventId = PlanExec.planRecord.eventId;
		mm.alarmCode = PlanExec.planRecord.eventType;
		mm.deviceType = planDeviceModel.planType;
		mm.deviceId = planDeviceModel.linkageDeviceId;
		mm.execState = "3";
		//mm.createAppName = runType;
		$.ajax({
			type:'post',
			dataType : 'json',
			url:'amqTrafficLinkageDeviceAction!publish_TrafficEventExecState_sdzm.do',
			data:mm,
			success:function(value){
				if(value=="success"){
					
				}
			}
		});
	}
	//预案执行设备日志信息
	var operateLog = {};
	var operateCommand = "";
	/*
	var operateCommand = "";
	if(runType=="1"){
		operateCommand = "自动执行";
	}
	if(runType=="0"){
		operateCommand = "重新执行";
	}
	if(runType=="3"){
		operateCommand = "提前执行";
	}
	if(runType=="4"){
		operateCommand = "手动执行";
	}		
	*/
	operateLog.operateCommand = operateCommand		
	operateLog.operateModule = planDeviceModel.typeName;
	operateLog.operateContent = '['+planDeviceModel.linkageDeviceName+']['+planDeviceModel.typeName+']'+operateCommand+'';
	operateLog.operateState = '执行中';
	operateLog.deviceType = '';
	operateLog.deviceId = planDeviceModel.linkageDeviceId;
	operateLog.deviceName = planDeviceModel.linkageDeviceName;
	PlanExec.insert_trafficplanexeclog(operateLog);
}
PlanRun.runDelayLinkage = function (linkageID){
	for(var i=0;i<PlanExec.deviceMap.size();i++){
		var tmpDevice = PlanExec.deviceMap.next().value();
		if(linkageID == tmpDevice.linkageID){
			PlanRun.planDeviceAmq(tmpDevice);
		}
	}
}
PlanRun.handRun = function (num,linkageID,type){
	$("#plan_exec_zt_"+linkageID).html("<span class='icon-state icon-run' ></span>正在执行");
	for(var i=0;i<PlanExec.deviceMap.size();i++){
		var tmpDevice = PlanExec.deviceMap.next().value();
		if(linkageID == tmpDevice.linkageID){
			PlanRun.planDeviceAmq(tmpDevice);
		}
	}
	$('#plan_step_delayrun_'+linkageID).html("5");
	var handLinkageID = $('#handLinkageID').val();
	if(handLinkageID){
		$('#handLinkageID').val(handLinkageID+linkageID+";");
	}else{
		$('#handLinkageID').val(linkageID+";");
	}
}

