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.DistrictInfo;
import com.izouma.awesomeadmin.service.DistrictInfoService;
import com.izouma.awesomeadmin.dao.DistrictInfoMapper;

/**
*  service接口实现类
*/
@Service
public class DistrictInfoServiceImpl implements DistrictInfoService{

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

    @Autowired
    private DistrictInfoMapper districtInfoMapper;

    @Override
    public List<DistrictInfo> getDistrictInfoList(DistrictInfo record) {

        logger.info("getDistrictInfoList");
        try {

        return districtInfoMapper.queryAllDistrictInfo(record);
        } catch (Exception e) {
        logger.error("getDistrictInfoList", e);
        }

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

        logger.info("getDistrictInfoByPage");
        try {

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

        return districtInfoMapper.queryDistrictInfoByPage(parameter);
        } catch (Exception e) {
        logger.error("getDistrictInfoByPage", e);
        }

        return null;
    }

    @Override
    public DistrictInfo getDistrictInfoById(String id) {

        logger.info("getDistrictInfoyId");
        try {

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

        return null;
    }

    @Override
    public DistrictInfo getDistrictInfo(DistrictInfo record) {

        logger.info("getDistrictInfo");
        try {

            return districtInfoMapper.queryDistrictInfo(record);
        } catch (Exception e) {
        logger.error("getDistrictInfo", e);
        }

        return null;
    }

    @Override
    public boolean createDistrictInfo(DistrictInfo record) {

        logger.info("createDistrictInfo");
        try {

            int updates = districtInfoMapper.insertSelective(record);

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

        return false;
    }

    @Override
    public boolean deleteDistrictInfo(String id) {

        logger.info("deleteDistrictInfo");
        try {

             int updates = districtInfoMapper.delete(id);

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

        return false;
    }

    @Override
    public boolean updateDistrictInfo(DistrictInfo record) {

        logger.info("updateDistrictInfo");
        try {

            int updates = districtInfoMapper.updateByPrimaryKeySelective(record);

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

        return false;
    }
}

