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.SystemConfig;
import com.izouma.awesomeadmin.service.SystemConfigService;
import com.izouma.awesomeadmin.dao.SystemConfigMapper;

/**
*  service接口实现类
*/
@Service
public class SystemConfigServiceImpl implements SystemConfigService{

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

    @Autowired
    private SystemConfigMapper systemConfigMapper;

    @Override
    public List<SystemConfig> getSystemConfigList(SystemConfig record) {

        logger.info("getSystemConfigList");
        try {

        return systemConfigMapper.queryAllSystemConfig(record);
        } catch (Exception e) {
        logger.error("getSystemConfigList", e);
        }

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

        logger.info("getSystemConfigByPage");
        try {

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

        return systemConfigMapper.querySystemConfigByPage(parameter);
        } catch (Exception e) {
        logger.error("getSystemConfigByPage", e);
        }

        return null;
    }

    @Override
    public SystemConfig getSystemConfigById(String id) {

        logger.info("getSystemConfigyId");
        try {

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

        return null;
    }

    @Override
    public SystemConfig getSystemConfig(SystemConfig record) {

        logger.info("getSystemConfig");
        try {

            return systemConfigMapper.querySystemConfig(record);
        } catch (Exception e) {
        logger.error("getSystemConfig", e);
        }

        return null;
    }

    @Override
    public boolean createSystemConfig(SystemConfig record) {

        logger.info("createSystemConfig");
        try {

            int updates = systemConfigMapper.insertSelective(record);

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

        return false;
    }

    @Override
    public boolean deleteSystemConfig(SystemConfig record) {

        logger.info("deleteSystemConfig");
        try {

             int updates = systemConfigMapper.delete(record);

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

        return false;
    }

    @Override
    public boolean updateSystemConfig(SystemConfig record) {

        logger.info("updateSystemConfig");
        try {

            int updates = systemConfigMapper.updateByPrimaryKeySelective(record);

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

        return false;
    }
}

