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.MetroInfo;
import com.izouma.awesomeadmin.service.MetroInfoService;
import com.izouma.awesomeadmin.dao.MetroInfoMapper;

/**
*  service接口实现类
*/
@Service
public class MetroInfoServiceImpl implements MetroInfoService{

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

    @Autowired
    private MetroInfoMapper metroInfoMapper;

    @Override
    public List<MetroInfo> getMetroInfoList(MetroInfo record) {

        logger.info("getMetroInfoList");
        try {

        return metroInfoMapper.queryAllMetroInfo(record);
        } catch (Exception e) {
        logger.error("getMetroInfoList", e);
        }

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

        logger.info("getMetroInfoByPage");
        try {

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

        return metroInfoMapper.queryMetroInfoByPage(parameter);
        } catch (Exception e) {
        logger.error("getMetroInfoByPage", e);
        }

        return null;
    }

    @Override
    public MetroInfo getMetroInfoById(String id) {

        logger.info("getMetroInfoyId");
        try {

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

        return null;
    }

    @Override
    public MetroInfo getMetroInfo(MetroInfo record) {

        logger.info("getMetroInfo");
        try {

            return metroInfoMapper.queryMetroInfo(record);
        } catch (Exception e) {
        logger.error("getMetroInfo", e);
        }

        return null;
    }

    @Override
    public boolean createMetroInfo(MetroInfo record) {

        logger.info("createMetroInfo");
        try {

            int updates = metroInfoMapper.insertSelective(record);

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

        return false;
    }

    @Override
    public boolean deleteMetroInfo(String id) {

        logger.info("deleteMetroInfo");
        try {

             int updates = metroInfoMapper.delete(id);

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

        return false;
    }

    @Override
    public boolean updateMetroInfo(MetroInfo record) {

        logger.info("updateMetroInfo");
        try {

            int updates = metroInfoMapper.updateByPrimaryKeySelective(record);

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

        return false;
    }
}

