package com.customer.work.service;

import org.flowable.engine.RuntimeService;
import org.flowable.task.service.delegate.DelegateTask;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

@Component("taskProcessStarter")
public class TaskProcessStarter {
    @Autowired
    private RuntimeService runtimeService;

    public void start(String processKey, DelegateTask task) {
//        String processKey = (String) task.getVariable("subProcessKey"); // key from variable

        Map<String, Object> vars = new HashMap<>(task.getVariables()); // carry over existing vars
        vars.put("originTaskId",   task.getId());
        vars.put("originTaskName", task.getName());

        runtimeService.startProcessInstanceByKey(processKey, vars);
//        runtimeService.startProcessInstanceById(processKey, vars);
    }
}
