package cn.iocoder.yudao.module.crm.job.salesperformance;

import cn.iocoder.yudao.framework.tenant.core.job.TenantJob;
import cn.iocoder.yudao.module.crm.service.salesperformancesettlement.SalesPerformanceSettlementService;
import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.handler.annotation.XxlJob;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.time.LocalDateTime;

@Component
@Slf4j
public class SalesPerformanceJob {

    // TODO: 2024/11/04  - 每个月月初 凌晨0点01分结算上个月的数据
    @Resource
    private SalesPerformanceSettlementService salesPerformanceSettlementService;

    @XxlJob("salesPerformanceJob")
    @TenantJob // --- ⚠️ 这个注解 会将租户列表拉出来 完了后逐个租户执行 定时任务需要注意
    public ReturnT<String> execute() throws Exception {
        log.info("开始 销售业绩结算");
        salesPerformanceSettlementService.settlement();
        log.info("结束 销售业绩结算");
        return ReturnT.SUCCESS;
    }
}
