package cn.yw.video.videoalarm.service;

 import cn.base.bean.BaseService;
import cn.base.util.CommUtils;
import cn.yw.video.videoalarm.dao.YwvideotaskrunresultDao;
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 java.sql.SQLException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service("ywvideotaskrunresultService")
public class YwvideotaskrunresultService extends BaseService {
	private static Log log = LogFactory.getLog(YwvideotaskrunresultService.class);
	
	@Autowired
	private YwvideotaskrunresultDao ywvideotaskrunresultDao;
	
	/**
	 * 保存记录
	 */
	public void insert_Ywvideotaskrunresult(Map map) throws SQLException{
		CommUtils.addParams(map, false);
		ywvideotaskrunresultDao.insert_Ywvideotaskrunresult(map);
	}

	
	/**
	 * 修改记录
	 */
	public Integer update_Ywvideotaskrunresult(Map map) throws SQLException{
		CommUtils.validateUpdateParams(map);
		CommUtils.addParams(map, true);
		return ywvideotaskrunresultDao.update_Ywvideotaskrunresult(map);
	}
	
	/**
	 * 删除记录
	 */
	public Integer delete_Ywvideotaskrunresult(Map map) throws SQLException{
		CommUtils.validateDeleteParams(map);
		return ywvideotaskrunresultDao.delete_Ywvideotaskrunresult(map);
	}
	
	/**
	 * 批处理删除记录
	 */
	public Integer batch_delete_Ywvideotaskrunresult(Map map) throws SQLException{
		return ywvideotaskrunresultDao.batch_delete_Ywvideotaskrunresult(map);
	}
	
	/**
	 * 查询总数
	 */
	public Integer count_Ywvideotaskrunresult(Map map) throws SQLException{
		return ywvideotaskrunresultDao.count_Ywvideotaskrunresult(map);
	}
	
	/**
	 * 查询列表记录SELECT
	 */
	public List<Map> query_Ywvideotaskrunresult(Map map) throws SQLException{
		return ywvideotaskrunresultDao.query_Ywvideotaskrunresult(map);
	}
	/**
	 * 统计
	 * @param map
	 * @return
	 * @throws SQLException
	 */
	public Map videoStatistics(Map map) throws SQLException{
		Map<String,Integer> result = new HashMap<String,Integer>();
		List<Map> list = ywvideotaskrunresultDao.videoStatistics(map);
		int total = 0;//总数
		int normalNum = 0;//正常
		int abnormalNum = 0;//异常
		int isonlineNum = 0;//是否在线
		int playfailNum = 0;//播放失败
		int networkerrorNum = 0;//网络异常
		int nosignalstatusNum = 0;//无信号
		int imgclearstatusNum = 0;//图像清晰检测状态
		int imgcontraststatusNum = 0;//图像对比检测状态
		int imgcolorstatusNum = 0;//颜色检测状态
		int imglightstatusNum = 0;//亮度检测状态
		int videofreezestatusNum = 0;//视频冻结检测状态
		int videojitterstatusNum = 0;//镜头抖动检测状态
		int videoupheavalstatusNum = 0;//视频剧变检测状态
		int videocodeerrorstatusNum = 0;//编码异常检测状态
		int videonoisestatusNum = 0;//噪声雪花检测状态
		int videorollstripestatusNum = 0;//滚动条纹检测状态
		int runstatusNum = 0;//执行状态
		if(list!=null && list.size()>0){
			total = list.size();
			for(int i=0;i<list.size();i++){
				Map m = list.get(i);
				if("0".equals(m.get("videostatus")+"")){
					abnormalNum++;
				}else{
					normalNum++;
				}
				if("0".equals(m.get("runstatus")+"")){
					runstatusNum++;
				}
				if("0".equals(m.get("videorollstripestatus")+"")){
					videorollstripestatusNum++;
				}
				if("0".equals(m.get("videonoisestatus")+"")){
					videonoisestatusNum++;
				}
				if("0".equals(m.get("videocodeerrorstatus")+"")){
					videocodeerrorstatusNum++;
				}
				if("0".equals(m.get("videoupheavalstatus")+"")){
					videoupheavalstatusNum++;
				}
				if("0".equals(m.get("videojitterstatus")+"")){
					videojitterstatusNum++;
				}
				if("0".equals(m.get("videofreezestatus")+"")){
					videofreezestatusNum++;
				}
				if("0".equals(m.get("imglightstatus")+"")){
					imglightstatusNum++;
				}
				if("0".equals(m.get("imgcolorstatus")+"")){
					imgcolorstatusNum++;
				}
				if("0".equals(m.get("imgcontraststatus")+"")){
					imgcontraststatusNum++;
				}
				if("0".equals(m.get("imgclearstatus")+"")){
					imgclearstatusNum++;
				}
				if("0".equals(m.get("nosignalstatus")+"")){
					nosignalstatusNum++;
				}
				if("0".equals(m.get("networkerror")+"")){
					networkerrorNum++;
				}
				if("0".equals(m.get("playfail")+"")){
					playfailNum++;
				}
				if("0".equals(m.get("isonline")+"")){
					isonlineNum++;
				}
			}
		}
		result.put("total", total);
		result.put("normalNum", normalNum);
		result.put("abnormalNum", abnormalNum);
		result.put("isonlineNum", isonlineNum);
		result.put("playfailNum", playfailNum);
		result.put("networkerrorNum", networkerrorNum);
		result.put("nosignalstatusNum", nosignalstatusNum);
		result.put("imgclearstatusNum", imgclearstatusNum);
		result.put("imgcontraststatusNum", imgcontraststatusNum);
		result.put("imgcolorstatusNum", imgcolorstatusNum);
		result.put("imglightstatusNum", imglightstatusNum);
		result.put("videofreezestatusNum", videofreezestatusNum);
		result.put("videojitterstatusNum", videojitterstatusNum);
		result.put("videoupheavalstatusNum", videoupheavalstatusNum);
		result.put("videocodeerrorstatusNum", videocodeerrorstatusNum);
		result.put("videonoisestatusNum", videonoisestatusNum);
		result.put("videorollstripestatusNum", videorollstripestatusNum);
		return result;
	}
	/**
	 * 折线统计
	 * @param map
	 * @return
	 * @throws SQLException
	 */
	public List<Map> videoStatisticsLine(Map map) throws SQLException{
		return ywvideotaskrunresultDao.videoStatisticsLine(map);
	}
	
	/**
	 * 查询一条
	 */
	 
	public Map get_Ywvideotaskrunresult(Map map) throws SQLException{
		return ywvideotaskrunresultDao.get_Ywvideotaskrunresult(map);
	}
	
	/**
	 * 导出EXCEL
	 */
	 
	/*
	public Map exportYwvideotaskrunresult(Map map) throws SQLException{
		return this.listYwvideotaskrunresultByPage(map);
	}
	*/
	
	/**
	 * Ywvideotaskrunresult 分页
	 */
	public Map listYwvideotaskrunresultByPage(Map map) throws SQLException {
		List<Map> list = ywvideotaskrunresultDao.query_Ywvideotaskrunresult(map);
		Integer totalCount = ywvideotaskrunresultDao.count_Ywvideotaskrunresult(map);
		map.clear();
		map.put("total", totalCount);
		map.put("rows", list);
		return map;
	}
	/**
	 * 查询 Ywvideotaskrunresult巡检设备和未巡检设备
	 */
	public List<Map> query_Ywvideotaskrunresultsbtdspsr(Map map) throws SQLException {
		return  ywvideotaskrunresultDao.query_YwvideotaskSbtdspsr(map);
	}



}
