package cn.yw.alarmcode.service;

 import cn.yw.alarmcode.dao.YwalarmeventcodeDao;

import java.sql.SQLException;
import java.util.HashMap;
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.util.CommUtils;

@Service("ywalarmeventcodeService")
public class YwalarmeventcodeService extends BaseService {
	
	private static Log log = LogFactory.getLog(YwalarmeventcodeService.class);
	
	@Autowired
	private YwalarmeventcodeDao ywalarmeventcodeDao;
	
	/**
	 * 保存记录
	 */
	public void insert_Ywalarmeventcode(Map map) throws SQLException{
		CommUtils.addParams(map, false);
		ywalarmeventcodeDao.insert_Ywalarmeventcode(map);
	}

	
	/**
	 * 修改记录
	 */
	public Integer update_Ywalarmeventcode(Map map) throws SQLException{
		CommUtils.validateUpdateParams(map);
		CommUtils.addParams(map, true);
		return ywalarmeventcodeDao.update_Ywalarmeventcode(map);
	}
	
	/**
	 * 删除记录
	 */
	public Integer delete_Ywalarmeventcode(Map map) throws SQLException{
		CommUtils.validateDeleteParams(map);
		if (map.get("type").toString().equals("treeNode")) {
			Map pMap = new HashMap();
			pMap.put("parentcode", map.get("parentcode"));
			List<Map> deleteMap = ywalarmeventcodeDao.query_Ywalarmeventcode(pMap);
			if (deleteMap != null && deleteMap.size() > 0) {
				for (Map del : deleteMap) {
					ywalarmeventcodeDao.delete_Ywalarmeventcode(del);
				}
			}
		}
		Map dleMap = new HashMap();
		dleMap.put("alarmcodeid", map.get("alarmcodeid"));
		return ywalarmeventcodeDao.delete_Ywalarmeventcode(dleMap);
	}
	
	/**
	 * 批处理删除记录
	 */
	/*
	public Integer batch_delete_Ywalarmeventcode(Map map) throws SQLException{
		return ywalarmeventcodeDao.batch_delete_Ywalarmeventcode(map);
	}
	*/
	
	/**
	 * 查询总数
	 */
	/*
	public Integer count_Ywalarmeventcode(Map map) throws SQLException{
		return ywalarmeventcodeDao.count_Ywalarmeventcode(map);
	}
	*/
	
	/**
	 * 查询列表记录SELECT
	 */
	public List<Map> query_Ywalarmeventcode(Map map) throws SQLException{
		return ywalarmeventcodeDao.query_Ywalarmeventcode(map);
	}
	
	/**
	 * 查询一条
	 */
	 
	/*
	public Map get_Ywalarmeventcode(Map map) throws SQLException{
		return ywalarmeventcodeDao.get_Ywalarmeventcode(map);
	}
	*/
	
	/**
	 * 导出EXCEL
	 */
	 
	/*
	public Map exportYwalarmeventcode(Map map) throws SQLException{
		return this.listYwalarmeventcodeByPage(map);
	}
	*/
	
	/**
	 * Ywalarmeventcode 分页
	 */
	public Map listYwalarmeventcodeByPage(Map map) throws SQLException {
		List<Map> list = ywalarmeventcodeDao.query_Ywalarmeventcode(map);
		Integer totalCount = ywalarmeventcodeDao.count_Ywalarmeventcode(map);
		map.clear();
		map.put("total", totalCount);
		map.put("rows", list);
		return map;
	}
	
	public List<Map> listYwalarmeventcodeByTree(Map map)  throws SQLException {
		List<Map> list = ywalarmeventcodeDao.query_YwalarmeventcodeByTree(map);
		return list;
	}
}
