package com.ruoyi.task.balancePeriod;

import com.ruoyi.common.utils.ServiceUtil;
import com.ruoyi.ss.balancePeriod.service.ISmBalancePeriodService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;

/**
 * @author wjh
 * 2024/3/16
 */
@Component("balancePeriodTask")
public class BalancePeriodTask {

    @Autowired
    private ISmBalancePeriodService smBalancePeriodService;

    @Transactional
    public void recordCurrentBalance() throws InterruptedException {
        Date now = new Date();
        ServiceUtil.assertion(smBalancePeriodService.isExist(now, now.getHours()),  "当前时间已经记录");
        smBalancePeriodService.recordCurrentBalance();
        Thread.sleep(3000); // 睡眠3秒，防止quartz重复调度
    }

}
