package com.fs.course.task;

import com.fs.company.service.ICompanyService;
import com.fs.course.service.BalanceRollbackErrorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Component;

/**
 * @description: 公司余额同步定时任务
 * @author: Xgb
 * @createDate: 2025/10/22
 * @version: 1.0
 */
@Component("companyBalanceTask")
public class CompanyBalanceTask {


    @Autowired
    private BalanceRollbackErrorService balanceRollbackErrorService;

    @Autowired
    private ICompanyService companyService;


    /**
     * @Description: 每10分钟从缓存获取余额同步到公司账户中
     * @Param:
     * @Return:
     * @Author xgb
     * @Date 2025/10/22 10:56
     */
    public void syncCompanyBalance() {
        companyService.syncCompanyBalance();
    }

    /**
     * @Description: 定时回滚公司余额数据
     * @Param:
     * @Return:
     * @Author xgb
     * @Date 2025/10/22 11:48
     */
    public void processBatchRollbackByCompanyId() {
        balanceRollbackErrorService.processBatchRollbackByCompanyId();
    }

    /**
     * @Description: spring启动执行 initCompanyBalance 查询余额报存到缓存中
     * 如果新增公司可以重启admin或者定时配置一下这个方法手动执行一次
     * @Param:
     * @Return:
     * @Author xgb
     * @Date 2025/10/22 11:52
     */
    public void initCompanyBalance() {
        balanceRollbackErrorService.initCompanyBalance();

    }



}
