package cn.iocoder.yudao.module.member.job;

import cn.hutool.core.collection.CollectionUtil;
import cn.iocoder.yudao.framework.quartz.core.handler.JobHandler;
import cn.iocoder.yudao.framework.tenant.core.aop.TenantIgnore;
import cn.iocoder.yudao.module.member.dal.dataobject.activitypay.ActivityPayDO;
import cn.iocoder.yudao.module.member.service.activitypay.ActivityPayService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author:qjq
 * @Date:2024/4/3 14:50
 */
@Slf4j
@Component
public class ActivityReserveJob implements JobHandler {


    @Resource
    private ActivityPayService activityPayService;
    /**
     * 执行任务
     *
     * @param param 参数
     * @return 结果
     * @throws Exception 异常
     */
    @Override
    @TenantIgnore
    public String execute(String param){

        List<ActivityPayDO> listByTime = activityPayService.getListByTime();
        if(CollectionUtil.isNotEmpty(listByTime)){
            for (ActivityPayDO activityPayDO : listByTime) {
                activityPayDO.setStatus("2");
            }
            activityPayService.updateBatch(listByTime);
        }

        log.info("[execute][上一天预约信息过期 {}条]", listByTime.size());
        return String.format("预约信息过期 %s 条   ",listByTime.size());
    }
}
