All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.zodiac.flowable.business.service.impl.DefaultFlowServiceImpl Maven / Gradle / Ivy

There is a newer version: 1.6.8
Show newest version
package org.zodiac.flowable.business.service.impl;

import org.flowable.engine.IdentityService;
import org.flowable.engine.RuntimeService;
import org.flowable.engine.TaskService;
import org.flowable.engine.runtime.ProcessInstance;
import org.springframework.web.bind.annotation.RestController;
import org.zodiac.commons.api.R;
import org.zodiac.commons.util.Func;
import org.zodiac.flowable.business.service.FlowService;
import org.zodiac.flowable.core.model.PlatformProcessFlow;
import org.zodiac.flowable.core.util.ProcessTaskUtil;
import org.zodiac.sdk.toolkit.support.Kv;
import org.zodiac.sdk.toolkit.util.lang.StrUtil;

import java.util.Map;

/**
 * 流程实现类。
 *
 */
@RestController
public class DefaultFlowServiceImpl implements FlowService {

    private final RuntimeService runtimeService;
    private final IdentityService identityService;
    private final TaskService taskService;

    public DefaultFlowServiceImpl(RuntimeService runtimeService, IdentityService identityService,
        TaskService taskService) {
        super();
        this.runtimeService = runtimeService;
        this.identityService = identityService;
        this.taskService = taskService;
    }

    @Override
    public PlatformProcessFlow startProcessInstanceById(String processDefinitionId, String businessKey,
        Map variables) {
        /*设置流程启动用户*/
        identityService.setAuthenticatedUserId(ProcessTaskUtil.getTaskUser());
        /*开启流程*/
        ProcessInstance processInstance =
            runtimeService.startProcessInstanceById(processDefinitionId, businessKey, variables);
        /*组装流程通用类。*/
        PlatformProcessFlow flow = new PlatformProcessFlow().setProcessInstanceId(processInstance.getId());
        return flow;
    }

    @Override
    public PlatformProcessFlow startProcessInstanceByKey(String processDefinitionKey, String businessKey,
        Map variables) {
        /*设置流程启动用户。*/
        identityService.setAuthenticatedUserId(ProcessTaskUtil.getTaskUser());
        /*开启流程。*/
        ProcessInstance processInstance =
            runtimeService.startProcessInstanceByKey(processDefinitionKey, businessKey, variables);
        /*组装流程通用类。*/
        PlatformProcessFlow flow = new PlatformProcessFlow().setProcessInstanceId(processInstance.getId());
        return flow;
    }

    @Override
    public boolean completeTask(String taskId, String processInstanceId, String comment,
        Map variables) {
        /*增加评论。*/
        if (StrUtil.isNoneBlank(processInstanceId, comment)) {
            taskService.addComment(taskId, processInstanceId, comment);
        }
        /*非空判断。*/
        if (Func.isEmpty(variables)) {
            variables = Kv.create();
        }
        /*完成任务。*/
        taskService.complete(taskId, variables);
        return true;
    }

    @Override
    public Object taskVariable(String taskId, String variableName) {
        return R.data(taskService.getVariable(taskId, variableName));
    }

    @Override
    public Map taskVariables(String taskId) {
        return taskService.getVariables(taskId);
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy