bladex 工作流flowable笔记

以请假作为例子

bladex 工作流flowable笔记_第1张图片

 

 

1.通过部署模型,然后流程实例就创建成功了。

2.发起请假

发起请假,流程实例就启动起来了,启动的时候,相应的参数是在车传入的,比如,比如请假天数,用户判断后面流程的流向。

import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springblade.core.log.exception.ServiceException;
import org.springblade.core.mp.base.BaseServiceImpl;
import org.springblade.core.secure.utils.SecureUtil;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.support.Kv;
import org.springblade.core.tool.utils.DateUtil;
import org.springblade.core.tool.utils.Func;
import org.springblade.desk.entity.ProcessLeave;
import org.springblade.desk.mapper.LeaveMapper;
import org.springblade.desk.service.ILeaveService;
import org.springblade.flow.core.constant.ProcessConstant;
import org.springblade.flow.core.entity.BladeFlow;
import org.springblade.flow.core.feign.IFlowClient;
import org.springblade.flow.core.utils.FlowUtil;
import org.springblade.flow.core.utils.TaskUtil;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * 服务实现类
 *
 * @author Chill
 */
@Slf4j
@Service
@AllArgsConstructor
public class LeaveServiceImpl extends BaseServiceImpl implements ILeaveService {

    private IFlowClient flowClient;

    @Override
    @Transactional(rollbackFor = Exception.class)
    // @GlobalTransactional
    public boolean startProcess(ProcessLeave leave) {
        String businessTable = FlowUtil.getBusinessTable(ProcessConstant.LEAVE_KEY);
        if (Func.isEmpty(leave.getId())) {
            // 保存leave
            leave.setApplyTime(DateUtil.now());
            save(leave);
            // 启动流程
            Kv variables = Kv.create()
                .set(ProcessConstant.TASK_VARIABLE_CREATE_USER, SecureUtil.getUserName())
                .set("taskUser", TaskUtil.getTaskUser(leave.getTaskUser()))
                .set("days", DateUtil.between(leave.getStartTime(), leave.getEndTime()).toDays());
            R result = flowClient.startProcessInstanceById(leave.getProcessDefinitionId(), FlowUtil.getBusinessKey(businessTable, String.valueOf(leave.getId())), variables);
            if (result.isSuccess()) {
                log.debug("流程已启动,流程ID:" + result.getData().getProcessInstanceId());
                // 返回流程id写入leave
                leave.setProcessInstanceId(result.getData().getProcessInstanceId());
                updateById(leave);
            } else {
                throw new ServiceException("开启流程失败");
            }
        } else {

            updateById(leave);
        }
        return true;
    }

}

 另外,在请假流程的xml中,我们发现了变了applyUser,applyUser是flowable引擎内部定义的发起人的参数名,代码位置:

@RestController
@AllArgsConstructor
public class FlowClient implements IFlowClient {

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

    @Override
    @PostMapping(START_PROCESS_INSTANCE_BY_ID)
    public R startProcessInstanceById(String processDefinitionId, String businessKey, @RequestBody Map variables) {
        // 设置流程启动用户
        identityService.setAuthenticatedUserId(TaskUtil.getTaskUser());
        // 开启流程
        ProcessInstance processInstance = runtimeService.startProcessInstanceById(processDefinitionId, businessKey, variables);
        // 组装流程通用类
        BladeFlow flow = new BladeFlow();
        flow.setProcessInstanceId(processInstance.getId());
        return R.data(flow);
    }

 

然后就是“发起事物”,通过填写请假需要的信息,发起请假流程

进入控制搜索:start-process,查看启动流程,请假单据实体:public class ProcessLeave extends FlowEntity,对应数据库表blade_process_leave

3.第一次处理请假(人事审批)

发起请假的时候,指定了第一个处理的人。这个人登录的时候,在“待办事物”菜单查看

审批处理同意:blade-flow/work/complete-task

4.第二次处理请假(老板或者经理审批)

因为“发起请假”的时候,传入了请假天数,流程自动判断是老板还是经理审批

其他问题,xml流程中的相关变量,是如何设定的,同指定xml流程的时候,可以进入流程设计中具体看看

你可能感兴趣的:(bladex 工作流flowable笔记)