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.HousePart;
import com.izouma.awesomeadmin.service.HousePartService;
import com.izouma.awesomeadmin.dao.HousePartMapper;

/**
*  service接口实现类
*/
@Service
public class HousePartServiceImpl implements HousePartService{

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

    @Autowired
    private HousePartMapper housePartMapper;

    @Override
    public List<HousePart> getHousePartList(HousePart record) {

        logger.info("getHousePartList");
        try {

        return housePartMapper.queryAllHousePart(record);
        } catch (Exception e) {
        logger.error("getHousePartList", e);
        }

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

        logger.info("getHousePartByPage");
        try {

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

        return housePartMapper.queryHousePartByPage(parameter);
        } catch (Exception e) {
        logger.error("getHousePartByPage", e);
        }

        return null;
    }

    @Override
    public HousePart getHousePartById(String id) {

        logger.info("getHousePartyId");
        try {

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

        return null;
    }

    @Override
    public HousePart getHousePart(HousePart record) {

        logger.info("getHousePart");
        try {

            return housePartMapper.queryHousePart(record);
        } catch (Exception e) {
        logger.error("getHousePart", e);
        }

        return null;
    }

    @Override
    public boolean createHousePart(HousePart record) {

        logger.info("createHousePart");
        try {

            int updates = housePartMapper.insertSelective(record);

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

        return false;
    }

    @Override
    public boolean deleteHousePart(String id) {

        logger.info("deleteHousePart");
        try {

             int updates = housePartMapper.delete(id);

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

        return false;
    }

    @Override
    public boolean updateHousePart(HousePart record) {

        logger.info("updateHousePart");
        try {

            int updates = housePartMapper.updateByPrimaryKeySelective(record);

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

        return false;
    }
}

