package com.izouma.awesomeadmin.service.impl;

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

import com.izouma.awesomeadmin.model.GenCode;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.izouma.awesomeadmin.constant.AppConstant;
import com.izouma.awesomeadmin.dao.GenCodeMapper;
import com.izouma.awesomeadmin.dto.Page;
import com.izouma.awesomeadmin.service.GenCodeService;

/**
 * gen_code_model service接口实现类
 * Fri May 04 15:57:06 CST 2018  Suo Chen Cheng
 */ 
@Service
public class GenCodeServiceImpl implements GenCodeService {

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

	@Autowired
	private GenCodeMapper genCodeMapper;

	@Override
	public List <GenCode> getGenCodeList(GenCode record) {

		logger.info("getGenCodeList");
		try {

			return genCodeMapper.queryAllGenCode(record);
		} catch (Exception e) {
			logger.error("getGenCodeList", e);
		}

		return null;
	}

	@Override
	public List <GenCode> getGenCodeByPage(Page page, GenCode record) {

		logger.info("getGenCodeByPage");
		try {

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

			return genCodeMapper.queryGenCodeByPage(parameter);
		} catch (Exception e) {
			logger.error("getGenCodeByPage", e);
		}

		return null;
	}

	@Override
	public GenCode getGenCodeById(String id) {

		logger.info("getGenCodeById");
		try {

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

		return null;
	}

	@Override
	public GenCode getGenCode(GenCode record) {

		logger.info("getGenCode");
		try {

			return genCodeMapper.queryGenCode(record);
		} catch (Exception e) {
			logger.error("getGenCode", e);
		}

		return null;
	}

	@Override
	public boolean createGenCode(GenCode record) {

		logger.info("createGenCode");
		try {

			int updates = genCodeMapper.insertSelective(record);

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

		return false;
	}

	@Override
	public boolean deleteGenCode(String id) {

		logger.info("deleteGenCode");
		try {

			int updates = genCodeMapper.delete(id);

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

		return false;
	}

	@Override
	public boolean updateGenCode(GenCode record) {

		logger.info("updateGenCode");
		try {

			int updates = genCodeMapper.updateByPrimaryKeySelective(record);

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

		return false;
	}

}

