package com.izouma.nineth.task;

import com.izouma.nineth.domain.*;
import com.izouma.nineth.repo.*;
import com.izouma.nineth.service.ActivityInviteService;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
import java.util.List;

@Service
@AllArgsConstructor
@Slf4j
public class InviteDateServiceTask {

    private ActivityInviteService activityInviteService;
    private InviteDateRepo inviteDateRepo;

    private final static int count =1000;//一次更新数量
    /**
     * 定时发放邀请活动奖励
     */
    @Scheduled(fixedDelay = 30000)
    public void batchSendPrize() {
        try {
            List<InviteDate>  listdata =  inviteDateRepo.findActivitydata(count);
            if (listdata.size()==0){
                return ;
            }
            activityInviteService.sendPrize(listdata);
        }catch (Exception e){
            log.error("发放奖励报错:" ,e);
        }
    }

}
