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.DataSourceInfo;
import com.izouma.awesomeadmin.service.DataSourceInfoService;
import com.izouma.awesomeadmin.dao.DataSourceInfoMapper;

/**
*  service接口实现类
*/
@Service
public class DataSourceInfoServiceImpl implements DataSourceInfoService{

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

    @Autowired
    private DataSourceInfoMapper dataSourceInfoMapper;

    @Override
    public List<DataSourceInfo> getDataSourceInfoList(DataSourceInfo record) {

        logger.info("getDataSourceInfoList");
        try {

        return dataSourceInfoMapper.queryAllDataSourceInfo(record);
        } catch (Exception e) {
        logger.error("getDataSourceInfoList", e);
        }

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

        logger.info("getDataSourceInfoByPage");
        try {

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

        return dataSourceInfoMapper.queryDataSourceInfoByPage(parameter);
        } catch (Exception e) {
        logger.error("getDataSourceInfoByPage", e);
        }

        return null;
    }

    @Override
    public DataSourceInfo getDataSourceInfoById(String id) {

        logger.info("getDataSourceInfoyId");
        try {

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

        return null;
    }

    @Override
    public DataSourceInfo getDataSourceInfo(DataSourceInfo record) {

        logger.info("getDataSourceInfo");
        try {

            return dataSourceInfoMapper.queryDataSourceInfo(record);
        } catch (Exception e) {
        logger.error("getDataSourceInfo", e);
        }

        return null;
    }

    @Override
    public boolean createDataSourceInfo(DataSourceInfo record) {

        logger.info("createDataSourceInfo");
        try {

            int updates = dataSourceInfoMapper.insertSelective(record);

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

        return false;
    }

    @Override
    public boolean deleteDataSourceInfo(String id) {

        logger.info("deleteDataSourceInfo");
        try {

             int updates = dataSourceInfoMapper.delete(id);

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

        return false;
    }

    @Override
    public boolean updateDataSourceInfo(DataSourceInfo record) {

        logger.info("updateDataSourceInfo");
        try {

            int updates = dataSourceInfoMapper.updateByPrimaryKeySelective(record);

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

        return false;
    }
}

