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.ShopAgreement;
import com.izouma.awesomeadmin.service.ShopAgreementService;
import com.izouma.awesomeadmin.dao.ShopAgreementMapper;

/**
*  service接口实现类
*/
@Service
public class ShopAgreementServiceImpl implements ShopAgreementService{

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

    @Autowired
    private ShopAgreementMapper shopAgreementMapper;

    @Override
    public List<ShopAgreement> getShopAgreementList(ShopAgreement record) {

        logger.info("getShopAgreementList");
        try {

        return shopAgreementMapper.queryAllShopAgreement(record);
        } catch (Exception e) {
        logger.error("getShopAgreementList", e);
        }

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

        logger.info("getShopAgreementByPage");
        try {

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

        return shopAgreementMapper.queryShopAgreementByPage(parameter);
        } catch (Exception e) {
        logger.error("getShopAgreementByPage", e);
        }

        return null;
    }

    @Override
    public ShopAgreement getShopAgreementById(String id) {

        logger.info("getShopAgreementyId");
        try {

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

        return null;
    }

    @Override
    public ShopAgreement getShopAgreement(ShopAgreement record) {

        logger.info("getShopAgreement");
        try {

            return shopAgreementMapper.queryShopAgreement(record);
        } catch (Exception e) {
        logger.error("getShopAgreement", e);
        }

        return null;
    }

    @Override
    public boolean createShopAgreement(ShopAgreement record) {

        logger.info("createShopAgreement");
        try {

            int updates = shopAgreementMapper.insertSelective(record);

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

        return false;
    }

    @Override
    public boolean deleteShopAgreement(String id) {

        logger.info("deleteShopAgreement");
        try {

             int updates = shopAgreementMapper.delete(id);

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

        return false;
    }

    @Override
    public boolean updateShopAgreement(ShopAgreement record) {

        logger.info("updateShopAgreement");
        try {

            int updates = shopAgreementMapper.updateByPrimaryKeySelective(record);

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

        return false;
    }
}

