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.UserAgreement;
import com.izouma.awesomeadmin.service.UserAgreementService;
import com.izouma.awesomeadmin.dao.UserAgreementMapper;

/**
*  service接口实现类
*/
@Service
public class UserAgreementServiceImpl implements UserAgreementService{

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

    @Autowired
    private UserAgreementMapper userAgreementMapper;

    @Override
    public List<UserAgreement> getUserAgreementList(UserAgreement record) {

        logger.info("getUserAgreementList");
        try {

        return userAgreementMapper.queryAllUserAgreement(record);
        } catch (Exception e) {
        logger.error("getUserAgreementList", e);
        }

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

        logger.info("getUserAgreementByPage");
        try {

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

        return userAgreementMapper.queryUserAgreementByPage(parameter);
        } catch (Exception e) {
        logger.error("getUserAgreementByPage", e);
        }

        return null;
    }

    @Override
    public UserAgreement getUserAgreementById(String id) {

        logger.info("getUserAgreementyId");
        try {

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

        return null;
    }

    @Override
    public UserAgreement getUserAgreement(UserAgreement record) {

        logger.info("getUserAgreement");
        try {

            return userAgreementMapper.queryUserAgreement(record);
        } catch (Exception e) {
        logger.error("getUserAgreement", e);
        }

        return null;
    }

    @Override
    public boolean createUserAgreement(UserAgreement record) {

        logger.info("createUserAgreement");
        try {

            int updates = userAgreementMapper.insertSelective(record);

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

        return false;
    }

    @Override
    public boolean deleteUserAgreement(UserAgreement record) {

        logger.info("deleteUserAgreement");
        try {

             int updates = userAgreementMapper.delete(record);

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

        return false;
    }

    @Override
    public boolean updateUserAgreement(UserAgreement record) {

        logger.info("updateUserAgreement");
        try {

            int updates = userAgreementMapper.updateByPrimaryKeySelective(record);

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

        return false;
    }
}

