package vip.xiaonuo.biz.modular.task;

import cn.hutool.core.date.DateField;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import jakarta.annotation.Resource;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import vip.xiaonuo.biz.modular.couponrecord.entity.BizCouponRecord;
import vip.xiaonuo.biz.modular.couponrecord.service.BizCouponRecordService;
import vip.xiaonuo.common.timer.CommonTimerTaskRunner;

import java.util.Date;
import java.util.List;

@Slf4j
@Component
public class couponRecordTask implements CommonTimerTaskRunner {

    @Resource
    private BizCouponRecordService bizCouponRecordService;

    @Override
    public void action(String extJson) {
        log.info("=====蛋糕券检验开始=====");
        //查询所有未核销的蛋糕券
        List<BizCouponRecord> list = bizCouponRecordService.list(new QueryWrapper<BizCouponRecord>().lambda().eq(BizCouponRecord::getCouponStatus, "0"));
        for(BizCouponRecord bizCouponRecord:list){
            //判断蛋糕券是否过期
            if(ObjectUtil.isNotEmpty(bizCouponRecord.getEndTime())){
                if(new Date().getTime() > bizCouponRecord.getEndTime().getTime()){
                    //已过期
                    bizCouponRecord.setCouponStatus("2");
                    bizCouponRecordService.updateById(bizCouponRecord);
                    log.info("=====蛋糕券："+bizCouponRecord.getCouponNo()+"已过期=====");
                }
            }
        }
    }


}
