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.MetroStation;
import com.izouma.awesomeadmin.service.MetroStationService;
import com.izouma.awesomeadmin.dao.MetroStationMapper;

/**
*  service接口实现类
*/
@Service
public class MetroStationServiceImpl implements MetroStationService{

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

    @Autowired
    private MetroStationMapper metroStationMapper;

    @Override
    public List<MetroStation> getMetroStationList(MetroStation record) {

        logger.info("getMetroStationList");
        try {

        return metroStationMapper.queryAllMetroStation(record);
        } catch (Exception e) {
        logger.error("getMetroStationList", e);
        }

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

        logger.info("getMetroStationByPage");
        try {

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

        return metroStationMapper.queryMetroStationByPage(parameter);
        } catch (Exception e) {
        logger.error("getMetroStationByPage", e);
        }

        return null;
    }

    @Override
    public MetroStation getMetroStationById(String id) {

        logger.info("getMetroStationyId");
        try {

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

        return null;
    }

    @Override
    public MetroStation getMetroStation(MetroStation record) {

        logger.info("getMetroStation");
        try {

            return metroStationMapper.queryMetroStation(record);
        } catch (Exception e) {
        logger.error("getMetroStation", e);
        }

        return null;
    }

    @Override
    public boolean createMetroStation(MetroStation record) {

        logger.info("createMetroStation");
        try {

            int updates = metroStationMapper.insertSelective(record);

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

        return false;
    }

    @Override
    public boolean deleteMetroStation(String id) {

        logger.info("deleteMetroStation");
        try {

             int updates = metroStationMapper.delete(id);

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

        return false;
    }

    @Override
    public boolean updateMetroStation(MetroStation record) {

        logger.info("updateMetroStation");
        try {

            int updates = metroStationMapper.updateByPrimaryKeySelective(record);

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

        return false;
    }
}

