仿钉钉流程设计- 任务拒绝,跳转到 EndEvent 结束流程

This commit is contained in:
jason 2024-06-13 23:07:32 +08:00
parent b0fe72d735
commit 7423f9ddad
6 changed files with 24 additions and 15 deletions

View File

@ -2,7 +2,6 @@ package cn.iocoder.yudao.module.bpm.framework.flowable.core.custom.delegate;
import cn.hutool.core.lang.Assert; import cn.hutool.core.lang.Assert;
import cn.hutool.core.util.BooleanUtil; import cn.hutool.core.util.BooleanUtil;
import cn.iocoder.yudao.module.bpm.enums.task.BpmCommentTypeEnum;
import cn.iocoder.yudao.module.bpm.framework.flowable.core.enums.BpmnModelConstants; import cn.iocoder.yudao.module.bpm.framework.flowable.core.enums.BpmnModelConstants;
import cn.iocoder.yudao.module.bpm.framework.flowable.core.util.BpmnModelUtils; import cn.iocoder.yudao.module.bpm.framework.flowable.core.util.BpmnModelUtils;
import cn.iocoder.yudao.module.bpm.service.task.BpmProcessInstanceService; import cn.iocoder.yudao.module.bpm.service.task.BpmProcessInstanceService;
@ -24,17 +23,16 @@ public class MultiInstanceServiceTaskDelegate implements JavaDelegate {
@Override @Override
public void execute(DelegateExecution execution) { public void execute(DelegateExecution execution) {
String attachUserTaskId = BpmnModelUtils.parseExtensionElement(execution.getCurrentFlowElement(), String attachUserTaskId = BpmnModelUtils.parseExtensionElement(execution.getCurrentFlowElement(),
BpmnModelConstants.SERVICE_TASK_ATTACH_USER_TASK_ID); BpmnModelConstants.SERVICE_TASK_ATTACH_USER_TASK_ID);
Assert.notNull(attachUserTaskId, "附属的用户任务 Id 不能为空"); Assert.notNull(attachUserTaskId, "附属的用户任务 Id 不能为空");
// 获取会签任务是否被拒绝 // 获取会签任务是否被拒绝
Boolean userTaskRejected = execution.getVariable(String.format("%s_reject", attachUserTaskId), Boolean.class); Boolean userTaskRejected = execution.getVariable(String.format("%s_reject", attachUserTaskId), Boolean.class);
// 如果会签任务被拒绝, 终止流程 // 如果会签任务被拒绝, 终止流程, 跳转到 EndEvent 节点
// TODO @jason重要需要测试下如果基于 createChangeActivityStateBuilder()changeState 到结束节点实现审批不通过
// 注意需要考虑 bpmn 的高亮问题不过这个未来可能会废弃掉
if (BooleanUtil.isTrue(userTaskRejected)) { if (BooleanUtil.isTrue(userTaskRejected)) {
processInstanceService.updateProcessInstanceReject(execution.getProcessInstanceId(), processInstanceService.updateProcessInstanceReject(execution.getProcessInstanceId(),
BpmCommentTypeEnum.REJECT.formatComment("会签任务拒绝人数满足条件")); execution.getCurrentActivityId(), "会签任务未达到通过比例" );
} }
} }

View File

@ -41,7 +41,7 @@ public class BpmProcessInstanceEventListener extends AbstractFlowableEngineEvent
@Override @Override
protected void processCompleted(FlowableEngineEntityEvent event) { protected void processCompleted(FlowableEngineEntityEvent event) {
processInstanceService.updateProcessInstanceWhenApprove((ProcessInstance)event.getEntity()); processInstanceService.updateProcessInstanceWhenCompleted((ProcessInstance)event.getEntity());
} }
} }

View File

@ -136,6 +136,12 @@ public class BpmnModelUtils {
return (StartEvent) CollUtil.findOne(process.getFlowElements(), flowElement -> flowElement instanceof StartEvent); return (StartEvent) CollUtil.findOne(process.getFlowElements(), flowElement -> flowElement instanceof StartEvent);
} }
public static EndEvent getEndEvent(BpmnModel model) {
Process process = model.getMainProcess();
// flowElementList endEvent. TODO 多个 EndEvent 会有问题
return (EndEvent) CollUtil.findOne(process.getFlowElements(), flowElement -> flowElement instanceof EndEvent);
}
public static BpmnModel getBpmnModel(byte[] bpmnBytes) { public static BpmnModel getBpmnModel(byte[] bpmnBytes) {
if (ArrayUtil.isEmpty(bpmnBytes)) { if (ArrayUtil.isEmpty(bpmnBytes)) {
return null; return null;

View File

@ -137,8 +137,16 @@ public interface BpmProcessInstanceService {
* 更新 ProcessInstance 拓展记录为不通过 * 更新 ProcessInstance 拓展记录为不通过
* *
* @param id 流程编号 * @param id 流程编号
* @param currentActivityId 当前的活动Id
* @param reason 理由例如说审批不通过时需要传递该值 * @param reason 理由例如说审批不通过时需要传递该值
*/ */
void updateProcessInstanceReject(String id, String reason); void updateProcessInstanceReject(String id, String currentActivityId, String reason);
/**
* 当流程结束时候 更新 ProcessInstance
*
* @param instance 流程任务
*/
void updateProcessInstanceWhenCompleted(ProcessInstance instance);
} }

View File

@ -5,7 +5,6 @@ import cn.hutool.core.util.ArrayUtil;
import cn.hutool.core.util.IdUtil; import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
import cn.iocoder.yudao.framework.common.exception.enums.GlobalErrorCodeConstants;
import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.date.DateUtils; import cn.iocoder.yudao.framework.common.util.date.DateUtils;
import cn.iocoder.yudao.framework.common.util.number.NumberUtils; import cn.iocoder.yudao.framework.common.util.number.NumberUtils;
@ -353,19 +352,17 @@ public class BpmTaskServiceImpl implements BpmTaskService {
return; return;
} else if (userTaskRejectHandlerType == BpmUserTaskRejectHandlerType.FINISH_PROCESS_BY_REJECT_NUMBER) { } else if (userTaskRejectHandlerType == BpmUserTaskRejectHandlerType.FINISH_PROCESS_BY_REJECT_NUMBER) {
// 3.3 按拒绝人数终止流程 // 3.3 按拒绝人数终止流程
// TODO @jason建议抛出系统异常类似 throw new IllegalStateException()
if (!flowElement.hasMultiInstanceLoopCharacteristics()) { if (!flowElement.hasMultiInstanceLoopCharacteristics()) {
log.error("[rejectTask] 用户任务拒绝处理类型配置错误, 按拒绝人数终止流程只能用于会签任务"); log.error("[rejectTask] 按拒绝人数终止流程类型,只能用于会签任务. 当前任务【{}】不是会签任务", task.getId());
throw exception(GlobalErrorCodeConstants.ERROR_CONFIGURATION); throw new IllegalStateException("按拒绝人数终止流程类型,只能用于会签任务");
} }
// 设置变量值为拒绝 // 设置变量值为拒绝
runtimeService.setVariableLocal(task.getExecutionId(), BpmConstants.TASK_VARIABLE_STATUS, BpmTaskStatusEnum.REJECT.getStatus()); runtimeService.setVariableLocal(task.getExecutionId(), BpmConstants.TASK_VARIABLE_STATUS, BpmTaskStatusEnum.REJECT.getStatus());
// 完成任务
taskService.complete(task.getId()); taskService.complete(task.getId());
return; return;
} }
// 3.4 其他情况 终止流程 TODO 后续可能会增加处理类型 // 3.4 其他情况 终止流程
processInstanceService.updateProcessInstanceReject(instance.getProcessInstanceId(), reqVO.getReason()); processInstanceService.updateProcessInstanceReject(instance.getProcessInstanceId(), task.getTaskDefinitionKey(), reqVO.getReason());
} }
/** /**