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.CityInfo;
import com.izouma.awesomeadmin.service.CityInfoService;
import com.izouma.awesomeadmin.dao.CityInfoMapper;

/**
*  service接口实现类
*/
@Service
public class CityInfoServiceImpl implements CityInfoService{

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

    @Autowired
    private CityInfoMapper cityInfoMapper;

    @Override
    public List<CityInfo> getCityInfoList(CityInfo record) {

        logger.info("getCityInfoList");
        try {

        return cityInfoMapper.queryAllCityInfo(record);
        } catch (Exception e) {
        logger.error("getCityInfoList", e);
        }

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

        logger.info("getCityInfoByPage");
        try {

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

        return cityInfoMapper.queryCityInfoByPage(parameter);
        } catch (Exception e) {
        logger.error("getCityInfoByPage", e);
        }

        return null;
    }

    @Override
    public CityInfo getCityInfoById(String id) {

        logger.info("getCityInfoyId");
        try {

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

        return null;
    }

    @Override
    public CityInfo getCityInfo(CityInfo record) {

        logger.info("getCityInfo");
        try {

            return cityInfoMapper.queryCityInfo(record);
        } catch (Exception e) {
        logger.error("getCityInfo", e);
        }

        return null;
    }

    @Override
    public boolean createCityInfo(CityInfo record) {

        logger.info("createCityInfo");
        try {

            int updates = cityInfoMapper.insertSelective(record);

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

        return false;
    }

    @Override
    public boolean deleteCityInfo(CityInfo record) {

        logger.info("deleteCityInfo");
        try {

             int updates = cityInfoMapper.delete(record);

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

        return false;
    }

    @Override
    public boolean updateCityInfo(CityInfo record) {

        logger.info("updateCityInfo");
        try {

            int updates = cityInfoMapper.updateByPrimaryKeySelective(record);

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

        return false;
    }
}

