package cn.im.operation;

import java.sql.SQLException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import cn.base.bean.BaseService;

@Service("operationService")
public class OperationService extends BaseService{
	
	@Autowired
	private OperationDao operationDao;
	
	
	// 查询节点下服务信息（分页）	
	public Map getNodeServerStatus(Map obj) throws SQLException{ 
		Map res = new HashMap();
		List<Map> list = operationDao.getNodeServerStatus(obj);
		int totalCount = operationDao.getNodeServerStatusCount(obj);
		res.put("data", list);
		res.put("totalCount", totalCount);
		return res;
	}
	
	// 查询相机并分页
	public Map query_CaVideoSourcePage(Map map) throws SQLException{ 
		Map resMap = new HashMap();
		List<Map> list = operationDao.query_CaVideoSource(map);
		int totalSize = operationDao.query_CaVideoSourceCount(map);
		
		resMap.put("totalSize", totalSize);
		resMap.put("dataList", list);
		return resMap;
	}
	
	// 查询服务信息并分页
	public Map getServers(Map obj) throws SQLException{ 
		Map map = new HashMap();
		//	异常服务信息
		List<Map> abnormalList = operationDao.getAbnormalServers(obj);
		// 异常相机数	
		int abnormalCount = operationDao.getAbnormalCameraCount(obj);
		map.put("abnormalService", abnormalList);
		map.put("abnormalCount", abnormalCount);
		// 正常服务信息
		List<Map> normalList = operationDao.getNormalServers(obj);
		// 正常相机数	
		int normalCount = operationDao.getNormalCameraCount(obj);
		map.put("normalList", normalList);
		map.put("normalCount",normalCount);
		return map;
	}
	
	// 查询异常相机并分页
	public Map getAbnormalCamera(Map obj) throws SQLException{ 
		Map map = new HashMap();
		List<Map> list = operationDao.getAbnormalCamera(obj);
		int totalCount = operationDao.getAbnormalCameraCount(obj);
		map.put("abnormalCamera", list);
		map.put("totalCount", totalCount);
		return map;
	}
	
	// 查询正常相机并分页
	public Map getNormalCamera(Map obj) throws SQLException{ 
		Map map = new HashMap();
		List<Map> list = operationDao.getNormalCamera(obj);
		int totalCount = operationDao.getNormalCameraCount(obj);
		map.put("abnormalCamera", list);
		map.put("totalCount", totalCount);
		return map;
	}
	
	// 根据 id 和 type 查询某一服务的详细信息
	public Map getServerInfoById(Map obj) throws SQLException{
		String type = String.valueOf( obj.get("type"));
		Map map = new HashMap();
		if("服务业务".equals(type)) {
			map = operationDao.getServerInfoById(obj);
		}else if("视频业务".equals(type)) {
			map = operationDao.getCaVideoSourceById(obj);
		}
		return map;
	}
}
