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.HouseKeeper;
import com.izouma.awesomeadmin.service.HouseKeeperService;
import com.izouma.awesomeadmin.dao.HouseKeeperMapper;

/**
*  service接口实现类
*/
@Service
public class HouseKeeperServiceImpl implements HouseKeeperService{

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

    @Autowired
    private HouseKeeperMapper houseKeeperMapper;

    @Override
    public List<HouseKeeper> getHouseKeeperList(HouseKeeper record) {

        logger.info("getHouseKeeperList");
        try {

        return houseKeeperMapper.queryAllHouseKeeper(record);
        } catch (Exception e) {
        logger.error("getHouseKeeperList", e);
        }

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

        logger.info("getHouseKeeperByPage");
        try {

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

        return houseKeeperMapper.queryHouseKeeperByPage(parameter);
        } catch (Exception e) {
        logger.error("getHouseKeeperByPage", e);
        }

        return null;
    }

    @Override
    public HouseKeeper getHouseKeeperById(String id) {

        logger.info("getHouseKeeperyId");
        try {

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

        return null;
    }

    @Override
    public HouseKeeper getHouseKeeper(HouseKeeper record) {

        logger.info("getHouseKeeper");
        try {

            return houseKeeperMapper.queryHouseKeeper(record);
        } catch (Exception e) {
        logger.error("getHouseKeeper", e);
        }

        return null;
    }

    @Override
    public boolean createHouseKeeper(HouseKeeper record) {

        logger.info("createHouseKeeper");
        try {

            int updates = houseKeeperMapper.insertSelective(record);

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

        return false;
    }

    @Override
    public boolean deleteHouseKeeper(String id) {

        logger.info("deleteHouseKeeper");
        try {

             int updates = houseKeeperMapper.delete(id);

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

        return false;
    }

    @Override
    public boolean updateHouseKeeper(HouseKeeper record) {

        logger.info("updateHouseKeeper");
        try {

            int updates = houseKeeperMapper.updateByPrimaryKeySelective(record);

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

        return false;
    }
}

