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.TableFieldMapper;
import com.izouma.awesomeadmin.dto.Page;
import com.izouma.awesomeadmin.model.TableField;
import com.izouma.awesomeadmin.service.TableFieldService;

/**
 * table_field service接口实现类
 * Fri May 04 13:38:24 CST 2018  Suo Chen Cheng
 */ 
@Service
public class TableFieldServiceImpl implements TableFieldService {

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

	@Autowired
	private TableFieldMapper tableFieldMapper;

	@Override
	public List <TableField> getTableFieldList(TableField record) {

		logger.info("getTableFieldList");
		try {

			return tableFieldMapper.queryAllTableField(record);
		} catch (Exception e) {
			logger.error("getTableFieldList", e);
		}

		return null;
	}

	@Override
	public List <TableField> getTableFieldByPage(Page page, TableField record) {

		logger.info("getTableFieldByPage");
		try {

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

			return tableFieldMapper.queryTableFieldsByPage(parameter);
		} catch (Exception e) {
			logger.error("getTableFieldByPage", e);
		}

		return null;
	}

	@Override
	public TableField getTableFieldById(String id) {

		logger.info("getTableFieldById");
		try {

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

		return null;
	}

	@Override
	public TableField getTableField(TableField record) {

		logger.info("getTableField");
		try {

			return tableFieldMapper.queryTableField(record);
		} catch (Exception e) {
			logger.error("getTableField", e);
		}

		return null;
	}

	@Override
	public boolean createTableField(TableField record) {

		logger.info("createTableField");
		try {

			int updates = tableFieldMapper.insertSelective(record);

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

		return false;
	}

	@Override
	public boolean deleteTableField(String id) {

		logger.info("deleteTableField");
		try {

			int updates = tableFieldMapper.delete(id);

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

		return false;
	}

	@Override
	public boolean updateTableField(TableField record) {

		logger.info("updateTableField");
		try {

			int updates = tableFieldMapper.updateByPrimaryKeySelective(record);

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

		return false;
	}

}

