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.activityawardsuser.ActivityAwardsUserDO;
import cn.iocoder.yudao.module.member.service.activityawardsuser.ActivityAwardsUserService;
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 ActivityJob implements JobHandler {


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

        List<ActivityAwardsUserDO> listByTime = activityAwardsUserService.getListByTime();
        if(CollectionUtil.isNotEmpty(listByTime)){
            for (ActivityAwardsUserDO activityAwardsUserDO : listByTime) {
                activityAwardsUserDO.setAwardsStatus("2");
            }
            activityAwardsUserService.updateBatch(listByTime);
        }

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