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.HouseInfo;
import com.izouma.awesomeadmin.service.HouseInfoService;
import com.izouma.awesomeadmin.dao.HouseInfoMapper;

/**
 * service接口实现类
 */
@Service
public class HouseInfoServiceImpl implements HouseInfoService {

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

    @Autowired
    private HouseInfoMapper houseInfoMapper;

    @Override
    public List<HouseInfo> getHouseInfoList(HouseInfo record) {

        logger.info("getHouseInfoList");
        try {

            return houseInfoMapper.queryAllHouseInfo(record);
        } catch (Exception e) {
            logger.error("getHouseInfoList", e);
        }

        return null;
    }

    @Override
    public List<HouseInfo> getHouseInfoByPage(Page page, HouseInfo record) {

        logger.info("getHouseInfoByPage");
        try {

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

            return houseInfoMapper.queryHouseInfoByPage(parameter);
        } catch (Exception e) {
            logger.error("getHouseInfoByPage", e);
        }

        return null;
    }

    @Override
    public HouseInfo getHouseInfoById(String id) {

        logger.info("getHouseInfoyId");
        try {

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

        return null;
    }

    @Override
    public HouseInfo getHouseInfo(HouseInfo record) {

        logger.info("getHouseInfo");
        try {

            return houseInfoMapper.queryHouseInfo(record);
        } catch (Exception e) {
            logger.error("getHouseInfo", e);
        }

        return null;
    }

    @Override
    public HouseInfo getHouseInfoDetail(HouseInfo record) {

        logger.info("getHouseInfoDetail");
        try {

            return houseInfoMapper.queryHouseInfoDetail(record);
        } catch (Exception e) {
            logger.error("getHouseInfoDetail", e);
        }

        return null;
    }

    @Override
    public boolean createHouseInfo(HouseInfo record) {

        logger.info("createHouseInfo");
        try {

            int updates = houseInfoMapper.insertSelective(record);

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

        return false;
    }

    @Override
    public boolean deleteHouseInfo(String id) {

        logger.info("deleteHouseInfo");
        try {

            int updates = houseInfoMapper.delete(id);

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

        return false;
    }

    @Override
    public boolean updateHouseInfo(HouseInfo record) {

        logger.info("updateHouseInfo");
        try {

            int updates = houseInfoMapper.updateByPrimaryKeySelective(record);

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

        return false;
    }
}

