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.HousingTrust;
import com.izouma.awesomeadmin.service.HousingTrustService;
import com.izouma.awesomeadmin.dao.HousingTrustMapper;

/**
*  service接口实现类
*/
@Service
public class HousingTrustServiceImpl implements HousingTrustService{

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

    @Autowired
    private HousingTrustMapper housingTrustMapper;

    @Override
    public List<HousingTrust> getHousingTrustList(HousingTrust record) {

        logger.info("getHousingTrustList");
        try {

        return housingTrustMapper.queryAllHousingTrust(record);
        } catch (Exception e) {
        logger.error("getHousingTrustList", e);
        }

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

        logger.info("getHousingTrustByPage");
        try {

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

        return housingTrustMapper.queryHousingTrustByPage(parameter);
        } catch (Exception e) {
        logger.error("getHousingTrustByPage", e);
        }

        return null;
    }

    @Override
    public HousingTrust getHousingTrustById(String id) {

        logger.info("getHousingTrustyId");
        try {

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

        return null;
    }

    @Override
    public HousingTrust getHousingTrust(HousingTrust record) {

        logger.info("getHousingTrust");
        try {

            return housingTrustMapper.queryHousingTrust(record);
        } catch (Exception e) {
        logger.error("getHousingTrust", e);
        }

        return null;
    }

    @Override
    public boolean createHousingTrust(HousingTrust record) {

        logger.info("createHousingTrust");
        try {

            int updates = housingTrustMapper.insertSelective(record);

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

        return false;
    }

    @Override
    public boolean deleteHousingTrust(String id) {

        logger.info("deleteHousingTrust");
        try {

             int updates = housingTrustMapper.delete(id);

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

        return false;
    }

    @Override
    public boolean updateHousingTrust(HousingTrust record) {

        logger.info("updateHousingTrust");
        try {

            int updates = housingTrustMapper.updateByPrimaryKeySelective(record);

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

        return false;
    }
}

