package cn.iocoder.yudao.module.system.job.holiday;

import cn.iocoder.yudao.framework.tenant.core.job.TenantJob;
import cn.iocoder.yudao.module.system.dal.dataobject.holiday.holidayuserrecord.HolidayUserRecordDO;
import cn.iocoder.yudao.module.system.service.holiday.holidayuserrecord.HolidayUserRecordService;
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;
import java.util.List;

@Component
@Slf4j
public class HolidayBeOverdueJob {
    @Resource
    private HolidayUserRecordService holidayUserRecordService;

    @XxlJob("holidayBeOverdueJob")
    @TenantJob // --- ⚠️ 这个注解 会将租户列表拉出来 完了后逐个租户执行 定时任务需要注意
    public ReturnT<String> execute() throws Exception {
        // -- 发放假期定时任务 - 每天凌晨3点执行一次 判断下是不是该发放了
        log.info("开始 假期过期扣减");
        // -- 先获取所有假期余额设置
        LocalDateTime now = LocalDateTime.now();
        //获取假期过期的对象
        List<HolidayUserRecordDO> list = holidayUserRecordService.getHolidayBeOverdue(now);
        holidayUserRecordService.beOverdue(list);
        log.info("结束 假期过期扣减");
        // 返回执行成功
        return ReturnT.SUCCESS;
    }

}
