package cn.im.trafficcount.service;

import cn.base.bean.BaseService;
import cn.base.util.DateUtil;
import cn.base.util.RHUtil;
import cn.base.util.Struts2Utils;
import cn.im.trafficcount.dao.BigScreenDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.*;

@Service("bigScreenService")
public class BigScreenService extends BaseService {
	
	
	@Autowired
	private BigScreenDao bigScreenDao;
	

	// ======================== 首页  ==================
	 // 点击   监控  发布屏  诱导灯  告警事件  查询相应信息  在地图上打点
	public List getBigScreenInfo(Map map) {
		
		String type = (String) map.get("type");
		List list = new ArrayList();
		if("1".equals(type)) {
			list = bigScreenDao.getVideoInfos(map);
		}else if("2".equals(type)) {
			list = bigScreenDao.getLedInfos(map);
		}else if("3".equals(type)) {
			list = bigScreenDao.getLedInfos(map);
		}else if("4".equals(type)) {
			
		}		
		return list;		
	}
	
	// 点击圈圈查询事件详情 
	public List<Map> getEventInfo(Map map) {
	
		List list = bigScreenDao.getEventInfo(map);
		return list;		
	}
	
	//查询相机详情
	public Map getSbtdspsr(Map map) {

		return bigScreenDao.getSbtdspsr(map);
	}
	
	
	// 首页 右侧告警事件查询
	public Map getAlarmEvent(Map map) {
		
		//发生时间
		String startTime = null;
		String endTime = null;
		String occurTime = Struts2Utils.getParameter("occurTime");
		if (RHUtil.isNotEmpty(occurTime)) {  //发生时间
			if("1".equals(occurTime)) { //1-今天
				String currDate = DateUtil.getYMD();
				startTime = currDate + " 00:00:00";
				endTime = currDate + " 23:59:59";
			}else if("2".equals(occurTime)) {  //2-最近一周
				String currDate = DateUtil.getYMD();
				Date currDay_date = DateUtil.day(-7);
				String currDay = DateUtil.date(currDay_date);
				startTime = currDay +" 00:00:00";
				endTime = currDate + " 23:59:59";
			}else if("3".equals(occurTime)) {  //3-最近一月
				String currDate = DateUtil.getYMD();
				Date currMonth_date = DateUtil.month(-1);
				String currMonth = DateUtil.date(currMonth_date);
				startTime = currMonth + " 00:00:00";
				endTime = currDate + " 23:59:59";
			}
			map.put("startTime", startTime);
			map.put("endTime", endTime);
		}
		//事故状态 
		String accidentState = Struts2Utils.getParameter("accidentState");
		if (RHUtil.isNotEmpty(accidentState)) {  //事故状态 
			System.out.println("accidentState = " + accidentState);
			String[] state = null;
			if("199".equals(accidentState)) {  //【199为全部】
				state = null;
			}else if ("0".equals(accidentState)){ //0-未处理，【未处理    0 1 5】
				state = new String[]{"0","1","5"};
			}else if("2".equals(accidentState)) {  //2-处理中，【处理中  2】
				state = new String[]{"2"};
				System.out.println("state = " + state);
			}else if("1".equals(accidentState)) {  //1-已处理     【已处理 3 4 6 7】
				state = new String[]{"3","4","6","7"};
			}
			map.put("accidentState",state );
		}
		
		int page = Integer.parseInt((String) map.get("pageNum"));
		int rows = Integer.parseInt((String) map.get("rows"));
		int start = ( (page == 0 ?  1 : page ) - 1) * rows ;
		map.put("start",start);
		map.put("limit",rows*(start+1));
		
		List<Map> list = bigScreenDao.getEventAlarm(map);
		int totalCount = bigScreenDao.getEventAlarmCount(map);
		Map resMap = new HashMap();
		resMap.put("listData", list);
		resMap.put("totalCount", totalCount);
		return resMap;
	}
	
}
