package com.izouma.awesomeadmin.service.impl;

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

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.GenTestTableMapper;
import com.izouma.awesomeadmin.dto.Page;
import com.izouma.awesomeadmin.model.GenTestTable;
import com.izouma.awesomeadmin.service.GenTestTableService;

/**
 * gen_test_table service接口实现类
 * Fri Apr 20 09:24:30 CST 2018  Suo Chen Cheng
 */ 
@Service
public class GenTestTableServiceImpl implements GenTestTableService {

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

	@Autowired
	private GenTestTableMapper genTestTableMapper;

	@Override
	public List <GenTestTable> getGenTestTableList(GenTestTable record) {

		logger.info("getGenTestTableList");
		try {

			return genTestTableMapper.queryAllGenTestTable(record);
		} catch (Exception e) {
			logger.error("getGenTestTableList", e);
		}

		return null;
	}

	@Override
	public List <GenTestTable> getGenTestTableByPage(Page page, GenTestTable record) {

		logger.info("getGenTestTableByPage");
		try {

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

			return genTestTableMapper.queryGenTestTablesByPage(parameter);
		} catch (Exception e) {
			logger.error("getGenTestTableByPage", e);
		}

		return null;
	}

	@Override
	public GenTestTable getGenTestTableById(String id) {

		logger.info("getGenTestTableById");
		try {

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

		return null;
	}

	@Override
	public GenTestTable getGenTestTable(GenTestTable record) {

		logger.info("getGenTestTable");
		try {

			return genTestTableMapper.queryGenTestTable(record);
		} catch (Exception e) {
			logger.error("getGenTestTable", e);
		}

		return null;
	}

	@Override
	public boolean createGenTestTable(GenTestTable record) {

		logger.info("createGenTestTable");
		try {

			int updates = genTestTableMapper.insertSelective(record);

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

		return false;
	}

	@Override
	public boolean deleteGenTestTable(String id) {

		logger.info("deleteGenTestTable");
		try {

			int updates = genTestTableMapper.delete(id);

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

		return false;
	}

	@Override
	public boolean updateGenTestTable(GenTestTable record) {

		logger.info("updateGenTestTable");
		try {

			int updates = genTestTableMapper.updateByPrimaryKeySelective(record);

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

		return false;
	}

}

