package com.ruoyi.scientific.listener;
import com.ruoyi.common.utils.spring.SpringUtils;
import com.ruoyi.scientific.service.IProjectApplicationService;
import org.flowable.engine.delegate.DelegateExecution;
import org.flowable.engine.delegate.ExecutionListener;
import org.springframework.stereotype.Component;
import org.springframework.beans.factory.annotation.Autowired;


@Component
public class BudgetUpdateTaskListener implements ExecutionListener {
    /**
     * 注入字段（名称与流程设计时字段名称一致）
     */

    private final IProjectApplicationService iProjectApplicationService =
        SpringUtils.getBean(IProjectApplicationService.class);


    @Override
    public void notify(DelegateExecution execution) {
        System.out.println("科研模块：执行任务监听器...");

        String projectIdStr = (String) execution.getVariable("projectId");
        Long projectId = Long.parseLong(projectIdStr);

        String projectBudget = (String) execution.getVariable("newBudget");
        Long budget = Long.parseLong(projectBudget);

        iProjectApplicationService.updateBudgetInfoById(projectId, budget);

        System.out.println("科研模块：项目Id：" + projectIdStr);
        System.out.println("科研模块：项目预算：" + projectBudget);
        // 调用其他模块的服务完成数据库的更新操作
        // Your Code
    }
}
