package com.starry.admin.common.task;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.starry.admin.modules.clerk.module.entity.ClerkPkEnum;
import com.starry.admin.modules.clerk.module.entity.PlayClerkPkEntity;
import com.starry.admin.modules.clerk.service.IPlayClerkPkService;
import java.util.Date;
import javax.annotation.Resource;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

/**
 * @Author: huchuansai
 * @Date: 2024/8/2 4:31 PM
 * @Description:
 */
@Component
public class ClerkPkJob {

    @Resource
    private IPlayClerkPkService playClerkPkService;

    @Scheduled(fixedRate = 60000)
    public void pkJobStatus() {
        // 更新状态将待开始的状态改为进行中
        playClerkPkService.update(Wrappers.lambdaUpdate(PlayClerkPkEntity.class)
                .eq(PlayClerkPkEntity::getStatus, ClerkPkEnum.TO_BE_STARTED.name())
                .le(PlayClerkPkEntity::getPkBeginTime, new Date())
                .set(PlayClerkPkEntity::getStatus, ClerkPkEnum.IN_PROGRESS.name()));

        playClerkPkService.update(Wrappers.lambdaUpdate(PlayClerkPkEntity.class)
                .eq(PlayClerkPkEntity::getStatus, ClerkPkEnum.IN_PROGRESS.name())
                .le(PlayClerkPkEntity::getPkEndTime, new Date())
                .set(PlayClerkPkEntity::getStatus, ClerkPkEnum.FINISHED.name()));
    }
}
