package cn.stylefeng.workflow.instance.core.timer.demo;

import cn.hutool.core.util.StrUtil;
import cn.stylefeng.workflow.api.entity.instance.RuntimeNode;
import cn.stylefeng.workflow.api.pojo.InstanceContext;
import cn.stylefeng.workflow.api.timer.BaseWorkflowTimerAction;
import cn.stylefeng.workflow.log.api.WorkflowLogApi;
import com.alibaba.fastjson.JSON;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Component;

@Component
public class ExampleWorkflowTimerAction implements BaseWorkflowTimerAction {

    @Resource
    private WorkflowLogApi workflowLogApi;

    @Override
    public void action(RuntimeNode runtimeNode, InstanceContext instanceContext) {
        String message = StrUtil.format("开始执行定时任务，这是一个工作流的demo定时任务！当前流程的运行时节点：{}。当前流程的上下文如下：{}",
                JSON.toJSONString("无节点，因为是流程发起"), JSON.toJSONString(instanceContext));
        workflowLogApi.logSuccess(instanceContext, null, message);
    }

}
