package com.izouma.awesomeadmin.service.impl;


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

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

/**
 * power_info service接口实现类
 * Wed Apr 11 11:04:02 CST 2018  Suo Chen Cheng
 */ 
@Service
public class PowerInfoServiceImpl implements PowerInfoService {

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

	@Autowired
	private PowerInfoMapper powerInfoMapper;

	@Override
	public List<PowerInfo> getPowerInfoList(PowerInfo record) {

		logger.info("getPowerInfoList");
		try {

			return powerInfoMapper.queryAllPowerInfo(record);
		} catch (Exception e) {
			logger.error("getPowerInfoList", e);
		}

		return null;
	}

	@Override
	public List<PowerInfo> getPowerInfoByPage(Page page, PowerInfo record) {

		logger.info("getPowerInfoByPage");
		try {

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

			return powerInfoMapper.queryPowerInfosByPage(parameter);
		} catch (Exception e) {
			logger.error("getPowerInfoByPage", e);
		}

		return null;
	}

	@Override
	public PowerInfo getPowerInfoById(String id) {

		logger.info("getPowerInfoById");
		try {

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

		return null;
	}

	@Override
	public PowerInfo getPowerInfo(PowerInfo record) {

		logger.info("getPowerInfo");
		try {

			return powerInfoMapper.queryPowerInfo(record);
		} catch (Exception e) {
			logger.error("getPowerInfo", e);
		}

		return null;
	}

	@Override
	public boolean createPowerInfo(PowerInfo record) {

		logger.info("createPowerInfo");
		try {

			int updates = powerInfoMapper.insertSelective(record);

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

		return false;
	}

	@Override
	public boolean deletePowerInfo(String id) {

		logger.info("deletePowerInfo");
		try {

			int updates = powerInfoMapper.delete(id);

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

		return false;
	}

	@Override
	public boolean updatePowerInfo(PowerInfo record) {

		logger.info("updatePowerInfo");
		try {

			int updates = powerInfoMapper.updateByPrimaryKeySelective(record);

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

		return false;
	}

	@Override
	public boolean deletePowerInfoByRoleId(String roleId) {
		logger.info("deletePowerInfoByRoleId");
		try {

			int updates = powerInfoMapper.deleteByRoleId(roleId);

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

		return false;
	}

}

