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.BusinessCircle;
import com.izouma.awesomeadmin.service.BusinessCircleService;
import com.izouma.awesomeadmin.dao.BusinessCircleMapper;

/**
*  service接口实现类
*/
@Service
public class BusinessCircleServiceImpl implements BusinessCircleService{

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

    @Autowired
    private BusinessCircleMapper businessCircleMapper;

    @Override
    public List<BusinessCircle> getBusinessCircleList(BusinessCircle record) {

        logger.info("getBusinessCircleList");
        try {

        return businessCircleMapper.queryAllBusinessCircle(record);
        } catch (Exception e) {
        logger.error("getBusinessCircleList", e);
        }

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

        logger.info("getBusinessCircleByPage");
        try {

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

        return businessCircleMapper.queryBusinessCircleByPage(parameter);
        } catch (Exception e) {
        logger.error("getBusinessCircleByPage", e);
        }

        return null;
    }

    @Override
    public BusinessCircle getBusinessCircleById(String id) {

        logger.info("getBusinessCircleyId");
        try {

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

        return null;
    }

    @Override
    public BusinessCircle getBusinessCircle(BusinessCircle record) {

        logger.info("getBusinessCircle");
        try {

            return businessCircleMapper.queryBusinessCircle(record);
        } catch (Exception e) {
        logger.error("getBusinessCircle", e);
        }

        return null;
    }

    @Override
    public boolean createBusinessCircle(BusinessCircle record) {

        logger.info("createBusinessCircle");
        try {

            int updates = businessCircleMapper.insertSelective(record);

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

        return false;
    }

    @Override
    public boolean deleteBusinessCircle(String id) {

        logger.info("deleteBusinessCircle");
        try {

             int updates = businessCircleMapper.delete(id);

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

        return false;
    }

    @Override
    public boolean updateBusinessCircle(BusinessCircle record) {

        logger.info("updateBusinessCircle");
        try {

            int updates = businessCircleMapper.updateByPrimaryKeySelective(record);

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

        return false;
    }
}

