package com.izouma.awesomeadmin.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.izouma.awesomeadmin.constant.AppConstant;
import com.izouma.awesomeadmin.dao.SysDataruleMapper;
import com.izouma.awesomeadmin.dto.Page;
import com.izouma.awesomeadmin.model.SysDatarule;
import com.izouma.awesomeadmin.service.SysDataruleService;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


/**
 * sys_datarule service接口实现类
 * Tue Apr 17 10:44:06 CST 2018  Suo Chen Cheng
 */ 
@Service
public class SysDataruleServiceImpl implements SysDataruleService {

	private static Logger   logger = Logger.getLogger(SysDataruleServiceImpl.class);

	@Autowired
	private SysDataruleMapper sysDataruleMapper;

	@Override
	public List <SysDatarule> getSysDataruleList(SysDatarule record) {

		logger.info("getSysDataruleList");
		try {

			return sysDataruleMapper.queryAllSysDatarule(record);
		} catch (Exception e) {
			logger.error("getSysDataruleList", e);
		}

		return null;
	}

	@Override
	public List <SysDatarule> getSysDataruleByPage(Page page, SysDatarule record) {

		logger.info("getSysDataruleByPage");
		try {

			Map <String, Object> parameter = new HashMap <String, Object>();
			parameter.put("record", record);
			parameter.put(AppConstant.PAGE, page);

			return sysDataruleMapper.querySysDatarulesByPage(parameter);
		} catch (Exception e) {
			logger.error("getSysDataruleByPage", e);
		}

		return null;
	}

	@Override
	public SysDatarule getSysDataruleById(String id) {

		logger.info("getSysDataruleById");
		try {

			return sysDataruleMapper.selectByPrimaryKey(Integer.valueOf(id));
		} catch (Exception e) {
			logger.error("getSysDataruleById", e);
		}

		return null;
	}

	@Override
	public SysDatarule getSysDatarule(SysDatarule record) {

		logger.info("getSysDatarule");
		try {

			return sysDataruleMapper.querySysDatarule(record);
		} catch (Exception e) {
			logger.error("getSysDatarule", e);
		}

		return null;
	}

	@Override
	public boolean createSysDatarule(SysDatarule record) {

		logger.info("createSysDatarule");
		try {

			int updates = sysDataruleMapper.insertSelective(record);

			if (updates > 0) {
				return true;
			}
		} catch (Exception e) {
			logger.error("createSysDatarule", e);
		}

		return false;
	}

	@Override
	public boolean deleteSysDatarule(String id) {

		logger.info("deleteSysDatarule");
		try {

			int updates = sysDataruleMapper.delete(id);

			if (updates > 0) {
				return true;
			}
		} catch (Exception e) {
			logger.error("deleteSysDatarule", e);
		}

		return false;
	}

	@Override
	public boolean updateSysDatarule(SysDatarule record) {

		logger.info("updateSysDatarule");
		try {

			int updates = sysDataruleMapper.updateByPrimaryKeySelective(record);

			if (updates > 0) {
				return true;
			}
		} catch (Exception e) {
			logger.error("updateSysDatarule", e);
		}

		return false;
	}

}

