package com.ruoyi.mall.service.impl;

import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.mall.mapper.UserCouponMapper;
import com.ruoyi.mall.domain.UserCoupon;
import com.ruoyi.mall.service.IUserCouponService;

import javax.annotation.Resource;

/**
 * 优惠卷发放Service业务层处理
 *
 * @author ruoyi
 * @date 2023-11-07
 */
@Service
public class UserCouponServiceImpl implements IUserCouponService
{
    @Resource
    private UserCouponMapper userCouponMapper;

    /**
     * 查询优惠卷发放
     *
     * @param cuId 优惠卷发放主键
     * @return 优惠卷发放
     */
    @Override
    public UserCoupon selectUserCouponByCuId(Long cuId)
    {
        return userCouponMapper.selectUserCouponByCuId(cuId);
    }

    /**
     * 查询优惠卷发放列表
     *
     * @param userCoupon 优惠卷发放
     * @return 优惠卷发放
     */
    @Override
    public List<UserCoupon> selectUserCouponList(UserCoupon userCoupon)
    {
        // 修改过期优惠券
        userCouponMapper.updateUserExpireCoupon();
        return userCouponMapper.selectUserCouponList(userCoupon);
    }

    /**
     * 新增优惠卷发放
     *
     * @param userCoupon 优惠卷发放
     * @return 结果
     */
    @Override
    public int insertUserCoupon(UserCoupon userCoupon)
    {
        userCoupon.setCreateTime(DateUtils.getNowDate());
        return userCouponMapper.insertUserCoupon(userCoupon);
    }

    /**
     * 修改优惠卷发放
     *
     * @param userCoupon 优惠卷发放
     * @return 结果
     */
    @Override
    public int updateUserCoupon(UserCoupon userCoupon)
    {
        userCoupon.setUpdateTime(DateUtils.getNowDate());
        return userCouponMapper.updateUserCoupon(userCoupon);
    }

    /**
     * 批量删除优惠卷发放
     *
     * @param cuIds 需要删除的优惠卷发放主键
     * @return 结果
     */
    @Override
    public int deleteUserCouponByCuIds(Long[] cuIds)
    {
        return userCouponMapper.deleteUserCouponByCuIds(cuIds);
    }

    /**
     * 删除优惠卷发放信息
     *
     * @param cuId 优惠卷发放主键
     * @return 结果
     */
    @Override
    public int deleteUserCouponByCuId(Long cuId)
    {
        return userCouponMapper.deleteUserCouponByCuId(cuId);
    }
}
