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.HousingDistrict;
import com.izouma.awesomeadmin.service.HousingDistrictService;
import com.izouma.awesomeadmin.dao.HousingDistrictMapper;

/**
*  service接口实现类
*/
@Service
public class HousingDistrictServiceImpl implements HousingDistrictService{

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

    @Autowired
    private HousingDistrictMapper housingDistrictMapper;

    @Override
    public List<HousingDistrict> getHousingDistrictList(HousingDistrict record) {

        logger.info("getHousingDistrictList");
        try {

        return housingDistrictMapper.queryAllHousingDistrict(record);
        } catch (Exception e) {
        logger.error("getHousingDistrictList", e);
        }

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

        logger.info("getHousingDistrictByPage");
        try {

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

        return housingDistrictMapper.queryHousingDistrictByPage(parameter);
        } catch (Exception e) {
        logger.error("getHousingDistrictByPage", e);
        }

        return null;
    }

    @Override
    public HousingDistrict getHousingDistrictById(String id) {

        logger.info("getHousingDistrictyId");
        try {

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

        return null;
    }

    @Override
    public HousingDistrict getHousingDistrict(HousingDistrict record) {

        logger.info("getHousingDistrict");
        try {

            return housingDistrictMapper.queryHousingDistrict(record);
        } catch (Exception e) {
        logger.error("getHousingDistrict", e);
        }

        return null;
    }

    @Override
    public boolean createHousingDistrict(HousingDistrict record) {

        logger.info("createHousingDistrict");
        try {

            int updates = housingDistrictMapper.insertSelective(record);

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

        return false;
    }

    @Override
    public boolean deleteHousingDistrict(String id) {

        logger.info("deleteHousingDistrict");
        try {

             int updates = housingDistrictMapper.delete(id);

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

        return false;
    }

    @Override
    public boolean updateHousingDistrict(HousingDistrict record) {

        logger.info("updateHousingDistrict");
        try {

            int updates = housingDistrictMapper.updateByPrimaryKeySelective(record);

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

        return false;
    }
}

