package cn.com.ty.lift.ud.userCoupon.task;

import java.util.List;

import cn.com.ty.lift.ud.coupon.mapper.entity.Coupon;
import cn.com.ty.lift.ud.coupon.service.ICouponService;
import cn.com.ty.lift.ud.userCoupon.service.IUserCouponService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

@Component
public class CouponTask {

    private static final Logger logger = LoggerFactory.getLogger(CouponTask.class);

    private @Autowired ICouponService iCouponService;
    private @Autowired IUserCouponService iUserCouponService;

    /**
     * 每10分钟执行一次
     */
    @Scheduled(fixedDelay = 60000 * 10)
    protected void updateMemberLevel() {
        logger.info("执行更新卡券状态操作！");
        List<Coupon> allFailureByDate = iCouponService.getAllFailureByDate();
        for (Coupon c : allFailureByDate) {
            iUserCouponService.updateUsedFlagByCouponId(c.getId());
            iCouponService.updateCouponById(c.getId());
        }
    }
}
