Flowable 适用于开发人员,系统管理员和业务用户的紧凑且高效的工作流程和业务流程管理(BPM)平台。
1.application.yml配置 添加以下属性
flowable:
#关闭定时任务JOB
async-executor-activate: false
# 将databaseSchemaUpdate设置为true。当Flowable发现库与数据库表结构不一致时,会自动将数据库表结构升级至新版本。
database-schema-update: true
2、通过自定义表单设计器设计流程表单
3、然后根据工作流设计器设计流程执行模型
4、参考代码
/**
* 【认领任务】认领/签收任务
* @param req
* @return
*/
@KeyLock(lockKeyParts = "taskId")
@Transactional(rollbackFor = Exception.class)
@Override
public ServiceResult claimWorkflowTask(ClaimWorkflowTaskReq req) {
//查询工作流记录
WorkflowRecord workflowRecord = workflowRecordMapper.selectByPrimaryKey(req.getRecordId());
if (workflowRecord==null){
throw new DuoJuHeException(ErrorCodes.PARAM_ERROR);
}
//任务id
String taskId = req.getTaskId();
//校验并获取任务
Task task = checkWorkflowTaskAndRecord(taskId,workflowRecord);
if (StringUtils.isNotBlank(task.getAssignee())){
return ServiceResult.fail("该任务已被其他人签收,不可重复签收!");
}
//任务节点名称
String taskName = task.getName();
//当前时间
Date nowDate = new Date();
//当前登录人
UserTokenInfoVo userTokenInfoVo = getCurrentLoginUserInfoDTO();
//当前登录人id
String userId = userTokenInfoVo.getUserId();
//流程实例id
String processInstanceId = task.getProcessInstanceId();
//认领
taskService.claim(taskId, userId);
//当前用户
String formUser = userTokenInfoVo.getLoginName()+"("+userTokenInfoVo.getRealName()+")";
//认领意见
String comment = "【签收】"+formUser+":认领签收了任务";
taskService.addComment(taskId, processInstanceId, WorkflowEnum.WorkflowComment.CLAIM_WORKFLOW_COMMENT.getKey(), comment);
//消息标题
String messageTitle = "【签收通知】"+workflowRecord.getProjectName();
//消息内容
String messageContent = formUser+",签收了你的流程:"+workflowRecord.getProjectName()+"(流程编号:"+workflowRecord.getSerialNumber()+"),节点名称:"+taskName;
//发送工作流系统消息
workflowToStartUserSendSystemMessage(nowDate,workflowRecord,messageTitle,messageContent);
return ServiceResult.ok(ErrorCodes.SUCCESS);
}
/**
* 【取消认领任务】取消认领
* @param req
* @return
*/
@KeyLock(lockKeyParts = "taskId")
@Transactional(rollbackFor = Exception.class)
@Override
public ServiceResult unClaimWorkflowTask(UnClaimWorkflowTaskReq req) {
//查询工作流记录
WorkflowRecord workflowRecord = workflowRecordMapper.selectByPrimaryKey(req.getRecordId());
if (workflowRecord==null){
throw new DuoJuHeException(ErrorCodes.PARAM_ERROR);
}
//任务id
String taskId = req.getTaskId();
//校验并获取任务
Task task = checkWorkflowTaskAndRecord(taskId,workflowRecord);
//任务节点名称
String taskName = task.getName();
//当前登录人
UserTokenInfoVo userTokenInfoVo = getCurrentLoginUserInfoDTO();
//当前登录人id
String userId = userTokenInfoVo.getUserId();
if (!userId.equals(task.getAssignee())){
return ServiceResult.fail(ErrorCodes.PARAM_ERROR);
}
//当前时间
Date nowDate = new Date();
//流程实例id
String processInstanceId = task.getProcessInstanceId();
List identityLinks = taskService.getIdentityLinksForTask(taskId);
boolean flag = false;
if (CollectionUtils.isNotEmpty(identityLinks)) {
for (IdentityLink link : identityLinks) {
if (IdentityLinkType.CANDIDATE.equals(link.getType())) {
flag = true;
break;
}
}
}
if (flag){
//取消认领
taskService.unclaim(taskId);
//当前用户
String formUser = userTokenInfoVo.getLoginName()+"("+userTokenInfoVo.getRealName()+")";
//取消原因
String comment = "【反签】"+formUser+":取消认领签收任务。";
if (StringUtils.isNotBlank(req.getComment())){
comment = comment+ ",原因:" +req.getComment();
}
//取消认领意见
taskService.addComment(taskId, processInstanceId, WorkflowEnum.WorkflowComment.CLAIM_WORKFLOW_COMMENT.getKey(), comment);
//消息标题
String messageTitle = "【反签通知】"+workflowRecord.getProjectName();
//消息内容
String messageContent = formUser+",放弃处理你流程:"+workflowRecord.getProjectName()+"(流程编号:"+workflowRecord.getSerialNumber()+"),节点名称:"+taskName;
//发送工作流系统消息
workflowToStartUserSendSystemMessage(nowDate,workflowRecord,messageTitle,messageContent);
return ServiceResult.ok(ErrorCodes.SUCCESS);
}else {
return ServiceResult.fail("由于没有候选人或候选组,会导致任务无法认领,请确认!");
}
}
/**
* 【转办任务】转办任务
* @param req
* @return
*/
@KeyLock(lockKeyParts = "taskId")
@Transactional(rollbackFor = Exception.class)
@Override
public ServiceResult transferWorkflowTask(TransferWorkflowTaskReq req) {
//查询工作流记录
WorkflowRecord workflowRecord = workflowRecordMapper.selectByPrimaryKey(req.getRecordId());
if (workflowRecord==null){
throw new DuoJuHeException(ErrorCodes.PARAM_ERROR);
}
//任务id
String taskId = req.getTaskId();
//校验并获取任务
Task task = checkWorkflowTaskAndRecord(taskId,workflowRecord);
//任务节点名称
String taskName = task.getName();
//当前登录人
UserTokenInfoVo userTokenInfoVo = getCurrentLoginUserInfoDTO();
//当前登录人id
String userId = userTokenInfoVo.getUserId();
if (!userId.equals(task.getAssignee())){
return ServiceResult.fail(ErrorCodes.PARAM_ERROR);
}
//转办的用户id
String transferToUserId = req.getTransferToUserId();
if (transferToUserId.equals(userId)){
return ServiceResult.fail("转办用户不可选择自己,请重新选择!");
}
//校验用户是否存在
SystemUser systemUser = systemUserMapper.selectByPrimaryKey(transferToUserId);
if (systemUser==null){
return ServiceResult.fail("转办用户不存在,请重新选择!");
}
//当前时间
Date nowDate = new Date();
//流程实例id
String processInstanceId = task.getProcessInstanceId();
//直接转派就可以覆盖掉之前的
taskService.setAssignee(taskId,transferToUserId);
//当前用户
String formUser = userTokenInfoVo.getLoginName()+"("+userTokenInfoVo.getRealName()+")";
//转办用户
String toUser = systemUser.getLoginName()+"("+systemUser.getRealName()+")";
//添加转办意见
String comment = "【转办】"+formUser+" → "+toUser;
if (StringUtils.isNotBlank(req.getComment())){
comment = comment+ ":" +req.getComment();
}
taskService.addComment(taskId, processInstanceId, WorkflowEnum.WorkflowComment.ASSIGN_WORKFLOW_COMMENT.getKey(), comment);
//消息标题
String messageChangeTitle = "【办理人变更通知】"+workflowRecord.getProjectName();
//消息内容
String messageChangeContent = "你的流程:"+workflowRecord.getProjectName()+"(流程编号:"+workflowRecord.getSerialNumber()+"),办理人已变更,"+formUser+" → "+toUser+",节点名称:"+taskName;
//发送工作流系统消息
workflowToStartUserSendSystemMessage(nowDate,workflowRecord,messageChangeTitle,messageChangeContent);
return ServiceResult.ok(ErrorCodes.SUCCESS);
}
多聚合是一套全部开源的Java快速开发平台,毫无保留给个人及企业免费使用。 我们集成了常见的功能模块。
开源地址:https://gitee.com/duojuhe/duojuheAdmin