package com.th.demo.service.impl.process;

import com.th.demo.model.system.Type;
import com.th.demo.service.process.InstanceService;
import org.activiti.engine.IdentityService;
import org.activiti.engine.RuntimeService;
import org.activiti.engine.runtime.ProcessInstance;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

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

/**
 * Created by dell on 2018-11-16.
 */
@Service("InstanceService")
public class InstanceServiceImpl implements InstanceService {
    @Autowired
    private RuntimeService runtimeService;
    @Autowired
    private IdentityService identityService;
    /**
     * 启动流程实例
     **/
    String result = Type.FAIL;

    public ProcessInstance start(String key,
                                 String userId) throws Exception {
        ProcessInstance pi;
        Map<String, Object> map = new HashMap<>();
      //  map.put("day", 3);
       // map.put("myListener", new MyListener());
        identityService.setAuthenticatedUserId(userId);

        pi = runtimeService.startProcessInstanceByKey(key,map);

        return pi;


    }
}
