package com.ruoyi.project.task;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import com.ruoyi.project.service.IBizProjectService;

/**
 * 项目相关定时任务
 */
@Component("projectTask")
public class ProjectTask {

    @Autowired
    private IBizProjectService projectService;

    /**
     * 将已到期未完成项目置为“立项中”(2)
     * 可在定时任务中配置调用目标：projectTask.projectAutoInitiate
     */
    public void projectAutoInitiate() {
        try {
            // 直接调用实现类新增方法
            if (projectService instanceof com.ruoyi.project.service.impl.BizProjectServiceImpl) {
                ((com.ruoyi.project.service.impl.BizProjectServiceImpl) projectService).markOverdueProjectsAsInitiating();
            } else {
                // 兼容代理：通过反射尝试调用
                projectService.getClass().getMethod("markOverdueProjectsAsInitiating").invoke(projectService);
            }
        } catch (Exception ignored) {
        }
    }

    /**
     * 起始时间到达：自动将“立项中”(2) 转为 “进行中”(0)
     * 调用目标：projectTask.projectAutoStart
     */
    public void projectAutoStart() {
        try {
            if (projectService instanceof com.ruoyi.project.service.impl.BizProjectServiceImpl) {
                ((com.ruoyi.project.service.impl.BizProjectServiceImpl) projectService).markInitiatingToOngoingByStartTime();
            } else {
                projectService.getClass().getMethod("markInitiatingToOngoingByStartTime").invoke(projectService);
            }
        } catch (Exception ignored) {
        }
    }
}


