package cn.amq.videotask;

import java.util.ArrayList;
import java.util.List;
import org.apache.log4j.Logger;
import cn.amq.basis.AmqBasisEvent;
import cn.amq.basis.AmqConst;
import cn.amq.business.AmqMainPoint;
import cn.amq.peas.VideoTaskAlarmHolder;
import cn.amq.peas.VideoTaskAlarmPeas;
import cn.base.bean.BeanHelper;

/**
 * 发送巡检任务告警信息amq
 * 
 * */
public class AmqVideoTaskAlarmService {

static Logger logger = Logger.getLogger(AmqVideoTaskAlarmService.class);
	
	/**
	 * 发送巡检任务告警信息 AMQ
	 * return msg 0：AMQ发送失败；1：AMQ发送成功。
	 * 
	*/
	public String publishVideoTaskAlarmAction(VideoTaskAlarmHolder holder) {
		String msg = "1";
		try {
			AmqMainPoint.publishJob.publishGeneralEvent(holder, AmqConst.AMQ_SUBJECT_videoTaskAlarm);//发送AMQ消息
			//logger.info("******发送AMQ消息******【巡检任务告警信息AMQ】，告警数量为："+holder.getList().size());
		}catch(Exception e) {
			e.printStackTrace();
			msg = "0";
			logger.error("******发送AMQ消息error******【巡检任务告警信息AMQ出现异常】，告警数量为："+holder.getList().size());
		}
		return msg;
	}
	
	/**
	 * 读取 巡检任务告警信息AMQ消息<br>
	 * return msg 0：失败；1：成功。
	 */
	public void doVideoTaskAlarmAction(AmqBasisEvent amqBasisMsg) {
		VideoTaskAlarmHolder entity = (VideoTaskAlarmHolder)amqBasisMsg;
		List<VideoTaskAlarmPeas> list = entity.getList();
		try {
			List<VideoTaskAlarmPeas> list_alarm = new ArrayList<VideoTaskAlarmPeas>();
			VideoTaskAlarmPeas info = null;
			
			for (VideoTaskAlarmPeas peas : list) {
				info = new VideoTaskAlarmPeas();
				info.setGjxh(peas.getGjxh());
				info.setGjbh(peas.getGjbh());
				info.setAlarmEventId(peas.getAlarmEventId());
	 			info.setAlarmRuleName(peas.getAlarmRuleName());
	 			info.setAlarmDeviceName(peas.getAlarmDeviceName());
	 			info.setAlarmDeviceId(peas.getAlarmDeviceId());
	 			info.setChannelNum(peas.getChannelNum());
	 			info.setAlarmGrade(peas.getAlarmGrade());
	 			info.setAlarmReason(peas.getAlarmReason());
	 			info.setAlarmTime(peas.getAlarmTime());
	 			System.out.println("---------------"+info);
	 			list_alarm.add(info);
			}
			// 安全帽告警信息缓存（推送给前端）
			BeanHelper.getVideoTaskAlarmDateService().setVideoTaskAlarmDataList(list_alarm);
		}catch(Exception e) {
			e.printStackTrace();
		}
	}
	
}
