package cn.amq.safetyhat;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.log4j.Logger;
import org.springframework.util.StringUtils;

import cn.amq.basis.AmqBasisEvent;
import cn.amq.basis.AmqConst;
import cn.amq.business.AmqMainPoint;
import cn.amq.peas.SafetyHatAlarmHolder;
import cn.amq.peas.SafetyHatAlarmPeas;
import cn.base.bean.BeanHelper;

/**
 * 发送安全帽告警信息amq
 * 
 * */
public class AmqSafetyHatAlarmService {

static Logger logger = Logger.getLogger(AmqSafetyHatAlarmService.class);
	
	/**
	 * 发送安全帽告警信息 AMQ
	 * * return msg 0：AMQ发送失败；1：AMQ发送成功。
	 * */
	public String publishSafetyHatAlarmAction(SafetyHatAlarmHolder holder) {
		String msg = "1";
		try {
			AmqMainPoint.publishJob.publishGeneralEvent(holder, AmqConst.AMQ_SUBJECT_safetyHatAlarm);//发送大屏上墙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>
	 * 读取消息后续处理：将接收到的数据加入SafetyHatAlarmDateService缓存中。
	 * return msg 0：数据写入失败；1：数据写入成功。
	 * 
	 */
	public void doSafetyHatAlarmAction(AmqBasisEvent amqBasisMsg) {
		SafetyHatAlarmHolder entity = (SafetyHatAlarmHolder)amqBasisMsg;
		List<SafetyHatAlarmPeas> list = entity.getList();
		try {
			logger.info("******读取AMQ消息******【安全帽告警信息AMQ】，接收告警事件数量为："+list.size());
			List list_alarm = new ArrayList();
			SafetyHatAlarmPeas info = null;
			for (SafetyHatAlarmPeas peas : list) {
				info = new SafetyHatAlarmPeas();
				info.setGjxh(peas.getGjxh());
				info.setGjbh(peas.getGjbh());
				info.setBjxxid(peas.getBjxxid());
	 			info.setBjbh(peas.getBjbh());
	 			info.setBjzwmc(peas.getBjzwmc());
	 			info.setFxsbmc(peas.getFxsbmc());
	 			info.setFxsbbh(peas.getFxsbbh());
	 			info.setFxtdbh(peas.getFxtdbh());
	 			info.setFxsbip(peas.getFxsbip());
	 			info.setBjlx(peas.getBjlx());
	 			info.setBjdj(peas.getBjdj());
	 			info.setBjtplj(peas.getBjtplj());
	 			info.setFwdsdksbjsj(peas.getFwdsdksbjsj());
	 			info.setZt(peas.getZt());
				list_alarm.add(info);
			}
			// 安全帽告警信息缓存（推送给前端）
			BeanHelper.getSafetyHatAlarmDateService().setSafetyHatAlarmDataList(list_alarm);
		}catch(Exception e) {
			e.printStackTrace();
		}
	}
	
}
