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.AreaInfo;
import com.izouma.awesomeadmin.service.AreaInfoService;
import com.izouma.awesomeadmin.dao.AreaInfoMapper;

/**
*  service接口实现类
*/
@Service
public class AreaInfoServiceImpl implements AreaInfoService{

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

    @Autowired
    private AreaInfoMapper areaInfoMapper;

    @Override
    public List<AreaInfo> getAreaInfoList(AreaInfo record) {

        logger.info("getAreaInfoList");
        try {

        return areaInfoMapper.queryAllAreaInfo(record);
        } catch (Exception e) {
        logger.error("getAreaInfoList", e);
        }

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

        logger.info("getAreaInfoByPage");
        try {

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

        return areaInfoMapper.queryAreaInfoByPage(parameter);
        } catch (Exception e) {
        logger.error("getAreaInfoByPage", e);
        }

        return null;
    }

    @Override
    public AreaInfo getAreaInfoById(String id) {

        logger.info("getAreaInfoyId");
        try {

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

        return null;
    }

    @Override
    public AreaInfo getAreaInfo(AreaInfo record) {

        logger.info("getAreaInfo");
        try {

            return areaInfoMapper.queryAreaInfo(record);
        } catch (Exception e) {
        logger.error("getAreaInfo", e);
        }

        return null;
    }

    @Override
    public boolean createAreaInfo(AreaInfo record) {

        logger.info("createAreaInfo");
        try {

            int updates = areaInfoMapper.insertSelective(record);

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

        return false;
    }

    @Override
    public boolean deleteAreaInfo(AreaInfo record) {

        logger.info("deleteAreaInfo");
        try {

             int updates = areaInfoMapper.delete(record);

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

        return false;
    }

    @Override
    public boolean updateAreaInfo(AreaInfo record) {

        logger.info("updateAreaInfo");
        try {

            int updates = areaInfoMapper.updateByPrimaryKeySelective(record);

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

        return false;
    }
}

