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.HouseImage;
import com.izouma.awesomeadmin.service.HouseImageService;
import com.izouma.awesomeadmin.dao.HouseImageMapper;

/**
*  service接口实现类
*/
@Service
public class HouseImageServiceImpl implements HouseImageService{

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

    @Autowired
    private HouseImageMapper houseImageMapper;

    @Override
    public List<HouseImage> getHouseImageList(HouseImage record) {

        logger.info("getHouseImageList");
        try {

        return houseImageMapper.queryAllHouseImage(record);
        } catch (Exception e) {
        logger.error("getHouseImageList", e);
        }

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

        logger.info("getHouseImageByPage");
        try {

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

        return houseImageMapper.queryHouseImageByPage(parameter);
        } catch (Exception e) {
        logger.error("getHouseImageByPage", e);
        }

        return null;
    }

    @Override
    public HouseImage getHouseImageById(String id) {

        logger.info("getHouseImageyId");
        try {

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

        return null;
    }

    @Override
    public HouseImage getHouseImage(HouseImage record) {

        logger.info("getHouseImage");
        try {

            return houseImageMapper.queryHouseImage(record);
        } catch (Exception e) {
        logger.error("getHouseImage", e);
        }

        return null;
    }

    @Override
    public boolean createHouseImage(HouseImage record) {

        logger.info("createHouseImage");
        try {

            int updates = houseImageMapper.insertSelective(record);

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

        return false;
    }

    @Override
    public boolean deleteHouseImage(String id) {

        logger.info("deleteHouseImage");
        try {

             int updates = houseImageMapper.delete(id);

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

        return false;
    }

    @Override
    public boolean updateHouseImage(HouseImage record) {

        logger.info("updateHouseImage");
        try {

            int updates = houseImageMapper.updateByPrimaryKeySelective(record);

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

        return false;
    }
}

