mirror of
https://gitee.com/huangge1199_admin/vue-pro.git
synced 2025-01-19 03:30:06 +08:00
仿钉钉流程设计- 任务拒绝,跳转到 EndEvent 结束流程
This commit is contained in:
parent
b0fe72d735
commit
7423f9ddad
@ -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.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.util.BpmnModelUtils;
|
||||
import cn.iocoder.yudao.module.bpm.service.task.BpmProcessInstanceService;
|
||||
@ -24,17 +23,16 @@ public class MultiInstanceServiceTaskDelegate implements JavaDelegate {
|
||||
|
||||
@Override
|
||||
public void execute(DelegateExecution execution) {
|
||||
|
||||
String attachUserTaskId = BpmnModelUtils.parseExtensionElement(execution.getCurrentFlowElement(),
|
||||
BpmnModelConstants.SERVICE_TASK_ATTACH_USER_TASK_ID);
|
||||
Assert.notNull(attachUserTaskId, "附属的用户任务 Id 不能为空");
|
||||
// 获取会签任务是否被拒绝
|
||||
Boolean userTaskRejected = execution.getVariable(String.format("%s_reject", attachUserTaskId), Boolean.class);
|
||||
// 如果会签任务被拒绝, 终止流程
|
||||
// TODO @jason:【重要】需要测试下,如果基于 createChangeActivityStateBuilder()、changeState 到结束节点,实现审批不通过;
|
||||
// 注意:需要考虑 bpmn 的高亮问题;(不过这个,未来可能会废弃掉!)
|
||||
// 如果会签任务被拒绝, 终止流程, 跳转到 EndEvent 节点
|
||||
if (BooleanUtil.isTrue(userTaskRejected)) {
|
||||
processInstanceService.updateProcessInstanceReject(execution.getProcessInstanceId(),
|
||||
BpmCommentTypeEnum.REJECT.formatComment("会签任务拒绝人数满足条件"));
|
||||
execution.getCurrentActivityId(), "会签任务未达到通过比例" );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -41,7 +41,7 @@ public class BpmProcessInstanceEventListener extends AbstractFlowableEngineEvent
|
||||
|
||||
@Override
|
||||
protected void processCompleted(FlowableEngineEntityEvent event) {
|
||||
processInstanceService.updateProcessInstanceWhenApprove((ProcessInstance)event.getEntity());
|
||||
processInstanceService.updateProcessInstanceWhenCompleted((ProcessInstance)event.getEntity());
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -136,6 +136,12 @@ public class BpmnModelUtils {
|
||||
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) {
|
||||
if (ArrayUtil.isEmpty(bpmnBytes)) {
|
||||
return null;
|
||||
|
@ -137,8 +137,16 @@ public interface BpmProcessInstanceService {
|
||||
* 更新 ProcessInstance 拓展记录为不通过
|
||||
*
|
||||
* @param id 流程编号
|
||||
* @param currentActivityId 当前的活动Id
|
||||
* @param reason 理由。例如说,审批不通过时,需要传递该值
|
||||
*/
|
||||
void updateProcessInstanceReject(String id, String reason);
|
||||
void updateProcessInstanceReject(String id, String currentActivityId, String reason);
|
||||
|
||||
/**
|
||||
* 当流程结束时候。 更新 ProcessInstance
|
||||
*
|
||||
* @param instance 流程任务
|
||||
*/
|
||||
void updateProcessInstanceWhenCompleted(ProcessInstance instance);
|
||||
|
||||
}
|
||||
|
File diff suppressed because one or more lines are too long
@ -5,7 +5,6 @@ import cn.hutool.core.util.ArrayUtil;
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
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.util.date.DateUtils;
|
||||
import cn.iocoder.yudao.framework.common.util.number.NumberUtils;
|
||||
@ -353,19 +352,17 @@ public class BpmTaskServiceImpl implements BpmTaskService {
|
||||
return;
|
||||
} else if (userTaskRejectHandlerType == BpmUserTaskRejectHandlerType.FINISH_PROCESS_BY_REJECT_NUMBER) {
|
||||
// 3.3 按拒绝人数终止流程
|
||||
// TODO @jason:建议抛出系统异常。类似 throw new IllegalStateException()
|
||||
if (!flowElement.hasMultiInstanceLoopCharacteristics()) {
|
||||
log.error("[rejectTask] 用户任务拒绝处理类型配置错误, 按拒绝人数终止流程只能用于会签任务");
|
||||
throw exception(GlobalErrorCodeConstants.ERROR_CONFIGURATION);
|
||||
log.error("[rejectTask] 按拒绝人数终止流程类型,只能用于会签任务. 当前任务【{}】不是会签任务", task.getId());
|
||||
throw new IllegalStateException("按拒绝人数终止流程类型,只能用于会签任务");
|
||||
}
|
||||
// 设置变量值为拒绝
|
||||
runtimeService.setVariableLocal(task.getExecutionId(), BpmConstants.TASK_VARIABLE_STATUS, BpmTaskStatusEnum.REJECT.getStatus());
|
||||
// 完成任务
|
||||
taskService.complete(task.getId());
|
||||
return;
|
||||
}
|
||||
// 3.4 其他情况 终止流程。 TODO 后续可能会增加处理类型
|
||||
processInstanceService.updateProcessInstanceReject(instance.getProcessInstanceId(), reqVO.getReason());
|
||||
// 3.4 其他情况 终止流程。
|
||||
processInstanceService.updateProcessInstanceReject(instance.getProcessInstanceId(), task.getTaskDefinitionKey(), reqVO.getReason());
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user