package com.izouma.awesomeadmin.service.impl;

import java.util.*;
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.dto.Page;
import com.izouma.awesomeadmin.model.QueryConfig;
import com.izouma.awesomeadmin.service.QueryConfigService;
import com.izouma.awesomeadmin.dao.QueryConfigMapper;

/**
*  service接口实现类
*/
@Service
public class QueryConfigServiceImpl implements QueryConfigService{

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

    @Autowired
    private QueryConfigMapper queryConfigMapper;

    @Override
    public List<QueryConfig> getQueryConfigList(QueryConfig record) {

        logger.info("getQueryConfigList");
        try {

        return queryConfigMapper.queryAllQueryConfig(record);
        } catch (Exception e) {
        logger.error("getQueryConfigList", e);
        }

        return null;
    }
    @Override
    public List<QueryConfig> getQueryConfigByPage(Page page, QueryConfig record) {

        logger.info("getQueryConfigByPage");
        try {

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

        return queryConfigMapper.queryQueryConfigByPage(parameter);
        } catch (Exception e) {
        logger.error("getQueryConfigByPage", e);
        }

        return null;
    }

    @Override
    public QueryConfig getQueryConfigById(String id) {

        logger.info("getQueryConfigyId");
        try {

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

        return null;
    }

    @Override
    public QueryConfig getQueryConfig(QueryConfig record) {

        logger.info("getQueryConfig");
        try {

            return queryConfigMapper.queryQueryConfig(record);
        } catch (Exception e) {
        logger.error("getQueryConfig", e);
        }

        return null;
    }

    @Override
    public boolean createQueryConfig(QueryConfig record) {

        logger.info("createQueryConfig");
        try {

            int updates = queryConfigMapper.insertSelective(record);

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

        return false;
    }

    @Override
    public boolean deleteQueryConfig(String id) {

        logger.info("deleteQueryConfig");
        try {

             int updates = queryConfigMapper.delete(id);

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

        return false;
    }

    @Override
    public boolean updateQueryConfig(QueryConfig record) {

        logger.info("updateQueryConfig");
        try {

            int updates = queryConfigMapper.updateByPrimaryKeySelective(record);

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

        return false;
    }
}

