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.UserCoupon;
import com.izouma.awesomeadmin.service.UserCouponService;
import com.izouma.awesomeadmin.dao.UserCouponMapper;

/**
*  service接口实现类
*/
@Service
public class UserCouponServiceImpl implements UserCouponService{

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

    @Autowired
    private UserCouponMapper userCouponMapper;

    @Override
    public List<UserCoupon> getUserCouponList(UserCoupon record) {

        logger.info("getUserCouponList");
        try {

        return userCouponMapper.queryAllUserCoupon(record);
        } catch (Exception e) {
        logger.error("getUserCouponList", e);
        }

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

        logger.info("getUserCouponByPage");
        try {

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

        return userCouponMapper.queryUserCouponByPage(parameter);
        } catch (Exception e) {
        logger.error("getUserCouponByPage", e);
        }

        return null;
    }

    @Override
    public UserCoupon getUserCouponById(String id) {

        logger.info("getUserCouponyId");
        try {

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

        return null;
    }

    @Override
    public UserCoupon getUserCoupon(UserCoupon record) {

        logger.info("getUserCoupon");
        try {

            return userCouponMapper.queryUserCoupon(record);
        } catch (Exception e) {
        logger.error("getUserCoupon", e);
        }

        return null;
    }

    @Override
    public boolean createUserCoupon(UserCoupon record) {

        logger.info("createUserCoupon");
        try {

            int updates = userCouponMapper.insertSelective(record);

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

        return false;
    }

    @Override
    public boolean deleteUserCoupon(String id) {

        logger.info("deleteUserCoupon");
        try {

             int updates = userCouponMapper.delete(id);

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

        return false;
    }

    @Override
    public boolean updateUserCoupon(UserCoupon record) {

        logger.info("updateUserCoupon");
        try {

            int updates = userCouponMapper.updateByPrimaryKeySelective(record);

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

        return false;
    }
}

