以請假作為例子
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<LeaveMapper, ProcessLeave> 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<BladeFlow> 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<BladeFlow> startProcessInstanceById(String processDefinitionId, String businessKey, @RequestBody Map<String, Object> 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流程的時候,可以進入流程設計中具體看看