package cn.im.trafficdevice.service;

 import java.sql.SQLException;
import java.util.List;
import java.util.Map;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cn.base.bean.BaseService;
import cn.base.bean.BeanHelper;
import cn.base.util.CommUtils;
import cn.base.util.DateUtil;
import cn.base.util.Struts2Utils;
import cn.bsystem.ptuserrole.model.PtyhBean;
import cn.im.trafficdevice.dao.TrafficdevicerelateDao;
import cn.im.trafficdevice.dao.TrafficroadinfoDao;

@Service("trafficroadinfoService")
public class TrafficroadinfoService extends BaseService {
	
	private static Log log = LogFactory.getLog(TrafficroadinfoService.class);
	
	@Autowired
	private TrafficroadinfoDao trafficroadinfoDao;
	@Autowired
	private TrafficdevicerelateDao trafficdevicerelateDao;
	
	/**
	 * 获取全部路段信息
	 * @return
	 */
	public List<Map> getTrafficroadinfoAll()throws SQLException{
		return trafficroadinfoDao.getTrafficroadinfoAll();
	}
	
	/**
	 * 保存记录
	 */

	public void insert_Trafficroadinfo(Map map) throws SQLException{
//		CommUtils.addParams(map, false);
		String username = ((PtyhBean)Struts2Utils.getSession().getAttribute("userInfo")).getYhbh();
		map.put("createAccount", username);
		map.put("createTime", DateUtil.currentDateTime());
		map.put("modifyAccount", username);
		map.put("modifyTime", DateUtil.currentDateTime());
		trafficroadinfoDao.insert_Trafficroadinfo(map);
	}
	


	
	/**
	 * 修改记录
	 */
	
	public Integer update_Trafficroadinfo(Map map) throws SQLException{
		CommUtils.validateUpdateParams(map);
//		CommUtils.addParams(map, true);
		String username = ((PtyhBean)Struts2Utils.getSession().getAttribute("userInfo")).getYhbh();
		map.put("modifyAccount", username);
		map.put("modifyTime", DateUtil.currentDateTime());
		return trafficroadinfoDao.update_Trafficroadinfo(map);
	}
	
	
	/**
	 * 删除记录
	 */

	public Integer delete_Trafficroadinfo(Map map) throws SQLException{
		CommUtils.validateDeleteParams(map);
		return trafficroadinfoDao.delete_Trafficroadinfo(map);
	}

	
	/**
	 * 批处理删除记录
	 */
	 
	/*
	
	public Integer batch_delete_Trafficroadinfo(Map map) throws SQLException{
		return trafficroadinfoDao.batch_delete_Trafficroadinfo(map);
	}
	
	*/
	
	/**
	 * 查询总数
	 */
	 
	public Integer count_Trafficroadinfo(Map map) throws SQLException{
		return trafficroadinfoDao.count_Trafficroadinfo(map);
	}
	

	
	/**
	 * 查询列表记录SELECT
	 */
	
	public List<Map> query_Trafficroadinfo(Map map) throws SQLException{
		return trafficroadinfoDao.query_Trafficroadinfo(map);
	}
	

	
	/**
	 * 查询一条
	 */
	 

	public Map get_Trafficroadinfo(Map map) throws SQLException{
		return trafficroadinfoDao.get_Trafficroadinfo(map);
	}
	

	/**
	 * 导出EXCEL
	 */
	/*
	public Map exportTrafficroadinfo(Map map) throws SQLException{
		return this.listTrafficroadinfoByPage(map);
	}
	
	*/
	
	/**
	 * Trafficroadinfo 分页
	 */
	 	
	public Map listTrafficroadinfoByPage(Map map) throws SQLException {
		/*
		System.out.println("*************--start-----开始发送【设备联动AMQ】  subject.trafficEventLinkageAction ****************");
		String CreateAccount = ((PtyhBean)Struts2Utils.getSession().getAttribute("userInfo")).getYhmc();
		//发送设备联动AMQ
		String eventId = "00121fbe6b754235bbb8797b8ff4aa6c";
		String alarmCode = "10";
		String deviceType = "1";  //1-信息发布；2-诱导灯联动； 
		String deviceId = "34cc1762366a4e659ed4e38b5fdde801"; //led的id   
		String deviceInstruction = "杭州奇令信息技术有限公司欢迎您！";
		String operationType = "1"; //操作类型，代码，1-预案执行；2-人工编辑；3-人工报警
		String operationId = "111";  //操作源表主键
		BeanHelper.getAmqTrafficEventLinkageActionService().publishTrafficEventLinkageAction(eventId,alarmCode,deviceType,deviceId,deviceInstruction,operationType,operationId,CreateAccount);
		*/
		/*
		eventId = "00a20a42ff56410ebcfeb7ff11c833b9";
		alarmCode = "3";
		deviceType = "2";  //1-信息发布；2-诱导灯联动； 
		deviceId = "34cc1762366a4e659ed4e38b5fdde802";
		deviceInstruction = "1";
		operationType = "3"; //操作类型，代码，1-预案执行；2-人工编辑；3-人工报警
		operationId = "222";  //操作源表主键
		BeanHelper.getAmqTrafficEventLinkageActionService().publishTrafficEventLinkageAction(eventId,alarmCode,deviceType,deviceId,deviceInstruction,operationType,operationId,CreateAccount);
		
		System.out.println("*************-----end------开始发送【设备联动AMQ】  subject.trafficEventLinkageAction ****************");

		System.out.println("*************--start-----开始发送【设备联动执行状态AMQ】  subject.trafficEventLinkageAction ****************");
		//发送设备联动执行状态
		eventId = "01094b134062489fa499513858fc4277";
		//String alarmCode = "";
		deviceType = "1"; //1-信息发布；2-诱导灯联动； 
		deviceId = "34cc1762366a4e659ed4e38b5fdde801";
		String execState = "3";
		String execTime = "2018-01-19 10:10:10";
		BeanHelper.getAmqTrafficEventExecStateActionService().publishTrafficEventExecStateAction(eventId,alarmCode,deviceType,deviceId,execState,execTime);
		System.out.println("*************-----end------开始发送【设备联动执行状态AMQ】  subject.trafficEventLinkageAction ****************");
		 */
		//发送同步预案amq
		//BeanHelper.getAmqTrafficPlanSynNotifyService().publishTrafficPlanSynNotifyAction("6dd5cc9b9e844b3e8944b60a4055516a");
		
		/*  
		System.out.println("*************--start-----开始发送【视频联动上墙AMQ】 subject.VideoToWall ****************");
		//视频联动上墙
		String alarmId = "14";
		String fdId = "201801231351222132";
		String channelId = "1";
		alarmCode = "1";
		String alarmTime = "2018-02-02 14:10:10";
		String alarmName = "交通联动平台测试发送";
		String videoType = "0";
		String beginTime = "";
		String duration = "60";
		String secnceId = "";
		String wallId = "墙ID";
		String winId = "窗口ID";
		String overlayText = "交通联动平台测试发送";
		String jpgurl = "";
		CreateAccount = "amq";
		BeanHelper.getAmqTrafficVideoToWallService().publishTrafficVideoToWallAction(eventId, deviceId, fdId, channelId, alarmCode, alarmTime, alarmName, videoType, wallId, winId);
		System.out.println("*************-----end------开始发送【视频联动上墙AMQ】 subject.VideoToWall ****************");

		System.out.println("*************--start-----开始发送【取消视频联动上墙AMQ】 subject.ClearVideoToWall ****************");
		//发送取消视频联动上墙
		BeanHelper.getAmqTrafficClearVideoToWallService().publishTrafficVideoToWallAction(eventId, deviceId, fdId, channelId, alarmCode, alarmTime, alarmName, videoType, winId);   
		System.out.println("*************-----end------开始发送【取消视频联动上墙AMQ】subject.ClearVideoToWall ****************");
		*/
		//发送结束预案amq 
		/*
		String planId = "2";
		System.out.println("*************-----end------开始发送【发送结束预案AMQ】 ****************");
		BeanHelper.getAmqTrafficPlanEndService().publishTrafficPlanEndAction(eventId, planId);
		*/
		//模拟发送告警事件amq 
		System.out.println("********************模拟发送【告警事件amq】***********************");
		/*
		String gjxh = "00121fbe6b754235bbb8797b8ff4aa6c";
		String gjsj = "2018-05-09 09:52:25";
		String sbbh = "201804271058022521";
		String sbmc = "摄像头01";
		String tdbh = "1";
		String sjlx = "99";
		String sjdj = "1";
		String jcfx = "";
		String mblx = "";
		String ruleNum = "";
		String tpurllj = "ftp://vpftp:vp1234@192.168.2.101:21//traffaccident/2018/04/19/330100180419101533_99_1_middle.jpg";
		String bz = "";
		BeanHelper.getAmqTrafficEventAlarmService().publishTrafficEventAlarmAction(gjxh, gjsj, 
				sbbh, sbmc, tdbh, sjlx, sjdj, jcfx, mblx, ruleNum, tpurllj, bz);
		
		*/
		
		List<Map> list = trafficroadinfoDao.query_Trafficroadinfo(map);
		Integer totalCount = trafficroadinfoDao.count_Trafficroadinfo(map);
		map.clear();
		map.put("total", totalCount);
		map.put("rows", list);
		return map;
	}
	/**
	 * 删除  路段信息        级联删除trafficdevicerelate表中的信息
	 */
	public Integer delete_TrafficRoadDeviceInfo(Map map) throws SQLException{
		CommUtils.validateDeleteParams(map);
		
		int delRoad = trafficroadinfoDao.delete_Trafficroadinfo(map);
		int delDevice = trafficdevicerelateDao.delete_Trafficdevicerelate(map);
		
		return delDevice;
	}
}
