mirror of
https://github.com/dromara/RuoYi-Vue-Plus.git
synced 2025-12-05 07:46:07 +08:00
refactor 优化工作流服务中的异常处理
This commit is contained in:
@@ -42,7 +42,7 @@ public class DataBaseHelper {
|
|||||||
String databaseProductName = metaData.getDatabaseProductName();
|
String databaseProductName = metaData.getDatabaseProductName();
|
||||||
return DataBaseType.find(databaseProductName);
|
return DataBaseType.find(databaseProductName);
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
throw new ServiceException(e.getMessage());
|
throw new RuntimeException("获取数据库类型失败", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -211,27 +211,17 @@ public class FlwInstanceServiceImpl implements IFlwInstanceService {
|
|||||||
Function.identity()
|
Function.identity()
|
||||||
);
|
);
|
||||||
|
|
||||||
try {
|
// 逐一触发删除事件
|
||||||
// 逐一触发删除事件
|
instances.forEach(instance -> {
|
||||||
instances.forEach(instance -> {
|
Definition definition = definitionMap.get(instance.getDefinitionId());
|
||||||
Definition definition = definitionMap.get(instance.getDefinitionId());
|
if (ObjectUtil.isNull(definition)) {
|
||||||
if (ObjectUtil.isNull(definition)) {
|
log.warn("实例 ID: {} 对应的流程定义信息未找到,跳过删除事件触发。", instance.getId());
|
||||||
log.warn("实例 ID: {} 对应的流程定义信息未找到,跳过删除事件触发。", instance.getId());
|
return;
|
||||||
return;
|
|
||||||
}
|
|
||||||
flowProcessEventHandler.processDeleteHandler(definition.getFlowCode(), instance.getBusinessId());
|
|
||||||
});
|
|
||||||
// 删除实例
|
|
||||||
boolean remove = insService.remove(instanceIds);
|
|
||||||
if (!remove) {
|
|
||||||
log.warn("删除流程实例失败!");
|
|
||||||
throw new ServiceException("删除流程实例失败");
|
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
flowProcessEventHandler.processDeleteHandler(definition.getFlowCode(), instance.getBusinessId());
|
||||||
log.warn("操作失败!{}", e.getMessage());
|
});
|
||||||
throw new ServiceException(e.getMessage());
|
// 删除实例
|
||||||
}
|
return insService.remove(instanceIds);
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -254,27 +244,22 @@ public class FlwInstanceServiceImpl implements IFlwInstanceService {
|
|||||||
Definition::getId,
|
Definition::getId,
|
||||||
Function.identity()
|
Function.identity()
|
||||||
);
|
);
|
||||||
try {
|
// 逐一触发删除事件
|
||||||
// 逐一触发删除事件
|
instances.forEach(instance -> {
|
||||||
instances.forEach(instance -> {
|
Definition definition = definitionMap.get(instance.getDefinitionId());
|
||||||
Definition definition = definitionMap.get(instance.getDefinitionId());
|
if (ObjectUtil.isNull(definition)) {
|
||||||
if (ObjectUtil.isNull(definition)) {
|
log.warn("实例 ID: {} 对应的流程定义信息未找到,跳过删除事件触发。", instance.getId());
|
||||||
log.warn("实例 ID: {} 对应的流程定义信息未找到,跳过删除事件触发。", instance.getId());
|
return;
|
||||||
return;
|
|
||||||
}
|
|
||||||
flowProcessEventHandler.processDeleteHandler(definition.getFlowCode(), instance.getBusinessId());
|
|
||||||
});
|
|
||||||
List<FlowTask> flowTaskList = flwTaskService.selectByInstIds(instanceIds);
|
|
||||||
if (CollUtil.isNotEmpty(flowTaskList)) {
|
|
||||||
FlowEngine.userService().deleteByTaskIds(StreamUtils.toList(flowTaskList, FlowTask::getId));
|
|
||||||
}
|
}
|
||||||
FlowEngine.taskService().deleteByInsIds(instanceIds);
|
flowProcessEventHandler.processDeleteHandler(definition.getFlowCode(), instance.getBusinessId());
|
||||||
FlowEngine.hisTaskService().deleteByInsIds(instanceIds);
|
});
|
||||||
FlowEngine.insService().removeByIds(instanceIds);
|
List<FlowTask> flowTaskList = flwTaskService.selectByInstIds(instanceIds);
|
||||||
} catch (Exception e) {
|
if (CollUtil.isNotEmpty(flowTaskList)) {
|
||||||
log.warn("操作失败!{}", e.getMessage());
|
FlowEngine.userService().deleteByTaskIds(StreamUtils.toList(flowTaskList, FlowTask::getId));
|
||||||
throw new ServiceException(e.getMessage());
|
|
||||||
}
|
}
|
||||||
|
FlowEngine.taskService().deleteByInsIds(instanceIds);
|
||||||
|
FlowEngine.hisTaskService().deleteByInsIds(instanceIds);
|
||||||
|
FlowEngine.insService().removeByIds(instanceIds);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -286,29 +271,24 @@ public class FlwInstanceServiceImpl implements IFlwInstanceService {
|
|||||||
@Override
|
@Override
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public boolean cancelProcessApply(FlowCancelBo bo) {
|
public boolean cancelProcessApply(FlowCancelBo bo) {
|
||||||
try {
|
Instance instance = selectInstByBusinessId(bo.getBusinessId());
|
||||||
Instance instance = selectInstByBusinessId(bo.getBusinessId());
|
if (instance == null) {
|
||||||
if (instance == null) {
|
throw new ServiceException(ExceptionCons.NOT_FOUNT_INSTANCE);
|
||||||
throw new ServiceException(ExceptionCons.NOT_FOUNT_INSTANCE);
|
|
||||||
}
|
|
||||||
Definition definition = defService.getById(instance.getDefinitionId());
|
|
||||||
if (definition == null) {
|
|
||||||
throw new ServiceException(ExceptionCons.NOT_FOUNT_DEF);
|
|
||||||
}
|
|
||||||
String message = bo.getMessage();
|
|
||||||
String userIdStr = LoginHelper.getUserIdStr();
|
|
||||||
BusinessStatusEnum.checkCancelStatus(instance.getFlowStatus());
|
|
||||||
FlowParams flowParams = FlowParams.build()
|
|
||||||
.message(message)
|
|
||||||
.flowStatus(BusinessStatusEnum.CANCEL.getStatus())
|
|
||||||
.hisStatus(BusinessStatusEnum.CANCEL.getStatus())
|
|
||||||
.handler(userIdStr)
|
|
||||||
.ignore(true);
|
|
||||||
taskService.revoke(instance.getId(), flowParams);
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.error("撤销失败: {}", e.getMessage(), e);
|
|
||||||
throw new ServiceException(e.getMessage());
|
|
||||||
}
|
}
|
||||||
|
Definition definition = defService.getById(instance.getDefinitionId());
|
||||||
|
if (definition == null) {
|
||||||
|
throw new ServiceException(ExceptionCons.NOT_FOUNT_DEF);
|
||||||
|
}
|
||||||
|
String message = bo.getMessage();
|
||||||
|
String userIdStr = LoginHelper.getUserIdStr();
|
||||||
|
BusinessStatusEnum.checkCancelStatus(instance.getFlowStatus());
|
||||||
|
FlowParams flowParams = FlowParams.build()
|
||||||
|
.message(message)
|
||||||
|
.flowStatus(BusinessStatusEnum.CANCEL.getStatus())
|
||||||
|
.hisStatus(BusinessStatusEnum.CANCEL.getStatus())
|
||||||
|
.handler(userIdStr)
|
||||||
|
.ignore(true);
|
||||||
|
taskService.revoke(instance.getId(), flowParams);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -422,20 +402,14 @@ public class FlwInstanceServiceImpl implements IFlwInstanceService {
|
|||||||
if (flowInstance == null) {
|
if (flowInstance == null) {
|
||||||
throw new ServiceException(ExceptionCons.NOT_FOUNT_INSTANCE);
|
throw new ServiceException(ExceptionCons.NOT_FOUNT_INSTANCE);
|
||||||
}
|
}
|
||||||
try {
|
Map<String, Object> variableMap = new HashMap<>(Optional.ofNullable(flowInstance.getVariableMap()).orElse(Collections.emptyMap()));
|
||||||
Map<String, Object> variableMap = new HashMap<>(Optional.ofNullable(flowInstance.getVariableMap()).orElse(Collections.emptyMap()));
|
if (!variableMap.containsKey(bo.getKey())) {
|
||||||
if (!variableMap.containsKey(bo.getKey())) {
|
log.error("变量不存在: {}", bo.getKey());
|
||||||
log.error("变量不存在: {}", bo.getKey());
|
return false;
|
||||||
return false;
|
|
||||||
}
|
|
||||||
variableMap.put(bo.getKey(), bo.getValue());
|
|
||||||
flowInstance.setVariable(FlowEngine.jsonConvert.objToStr(variableMap));
|
|
||||||
flowInstanceMapper.updateById(flowInstance);
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.error("设置流程变量失败: {}", e.getMessage(), e);
|
|
||||||
throw new ServiceException(e.getMessage());
|
|
||||||
}
|
}
|
||||||
return true;
|
variableMap.put(bo.getKey(), bo.getValue());
|
||||||
|
flowInstance.setVariable(FlowEngine.jsonConvert.objToStr(variableMap));
|
||||||
|
return flowInstanceMapper.updateById(flowInstance) > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -480,21 +454,16 @@ public class FlwInstanceServiceImpl implements IFlwInstanceService {
|
|||||||
@Override
|
@Override
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public boolean processInvalid(FlowInvalidBo bo) {
|
public boolean processInvalid(FlowInvalidBo bo) {
|
||||||
try {
|
Instance instance = insService.getById(bo.getId());
|
||||||
Instance instance = insService.getById(bo.getId());
|
if (instance != null) {
|
||||||
if (instance != null) {
|
BusinessStatusEnum.checkInvalidStatus(instance.getFlowStatus());
|
||||||
BusinessStatusEnum.checkInvalidStatus(instance.getFlowStatus());
|
|
||||||
}
|
|
||||||
FlowParams flowParams = FlowParams.build()
|
|
||||||
.message(bo.getComment())
|
|
||||||
.flowStatus(BusinessStatusEnum.INVALID.getStatus())
|
|
||||||
.hisStatus(TaskStatusEnum.INVALID.getStatus())
|
|
||||||
.ignore(true);
|
|
||||||
taskService.terminationByInsId(bo.getId(), flowParams);
|
|
||||||
return true;
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.error(e.getMessage(), e);
|
|
||||||
throw new ServiceException(e.getMessage());
|
|
||||||
}
|
}
|
||||||
|
FlowParams flowParams = FlowParams.build()
|
||||||
|
.message(bo.getComment())
|
||||||
|
.flowStatus(BusinessStatusEnum.INVALID.getStatus())
|
||||||
|
.hisStatus(TaskStatusEnum.INVALID.getStatus())
|
||||||
|
.ignore(true);
|
||||||
|
taskService.terminationByInsId(bo.getId(), flowParams);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -150,12 +150,7 @@ public class FlwTaskServiceImpl implements IFlwTaskService {
|
|||||||
.flowCode(startProcessBo.getFlowCode())
|
.flowCode(startProcessBo.getFlowCode())
|
||||||
.variable(startProcessBo.getVariables())
|
.variable(startProcessBo.getVariables())
|
||||||
.flowStatus(BusinessStatusEnum.DRAFT.getStatus());
|
.flowStatus(BusinessStatusEnum.DRAFT.getStatus());
|
||||||
Instance instance;
|
Instance instance = insService.start(businessId, flowParams);
|
||||||
try {
|
|
||||||
instance = insService.start(businessId, flowParams);
|
|
||||||
} catch (Exception e) {
|
|
||||||
throw new ServiceException(e.getMessage());
|
|
||||||
}
|
|
||||||
// 保存流程实例业务信息
|
// 保存流程实例业务信息
|
||||||
this.buildFlowInstanceBizExt(instance, bizExt);
|
this.buildFlowInstanceBizExt(instance, bizExt);
|
||||||
// 申请人执行流程
|
// 申请人执行流程
|
||||||
@@ -202,52 +197,47 @@ public class FlwTaskServiceImpl implements IFlwTaskService {
|
|||||||
@Override
|
@Override
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public boolean completeTask(CompleteTaskBo completeTaskBo) {
|
public boolean completeTask(CompleteTaskBo completeTaskBo) {
|
||||||
try {
|
// 获取任务ID并查询对应的流程任务和实例信息
|
||||||
// 获取任务ID并查询对应的流程任务和实例信息
|
Long taskId = completeTaskBo.getTaskId();
|
||||||
Long taskId = completeTaskBo.getTaskId();
|
List<String> messageType = completeTaskBo.getMessageType();
|
||||||
List<String> messageType = completeTaskBo.getMessageType();
|
String notice = completeTaskBo.getNotice();
|
||||||
String notice = completeTaskBo.getNotice();
|
// 获取抄送人
|
||||||
// 获取抄送人
|
List<FlowCopyBo> flowCopyList = completeTaskBo.getFlowCopyList();
|
||||||
List<FlowCopyBo> flowCopyList = completeTaskBo.getFlowCopyList();
|
// 设置抄送人
|
||||||
// 设置抄送人
|
Map<String, Object> variables = completeTaskBo.getVariables();
|
||||||
Map<String, Object> variables = completeTaskBo.getVariables();
|
variables.put(FlowConstant.FLOW_COPY_LIST, flowCopyList);
|
||||||
variables.put(FlowConstant.FLOW_COPY_LIST, flowCopyList);
|
// 消息类型
|
||||||
// 消息类型
|
variables.put(FlowConstant.MESSAGE_TYPE, messageType);
|
||||||
variables.put(FlowConstant.MESSAGE_TYPE, messageType);
|
// 消息通知
|
||||||
// 消息通知
|
variables.put(FlowConstant.MESSAGE_NOTICE, notice);
|
||||||
variables.put(FlowConstant.MESSAGE_NOTICE, notice);
|
|
||||||
|
|
||||||
|
|
||||||
FlowTask flowTask = flowTaskMapper.selectById(taskId);
|
FlowTask flowTask = flowTaskMapper.selectById(taskId);
|
||||||
if (ObjectUtil.isNull(flowTask)) {
|
if (ObjectUtil.isNull(flowTask)) {
|
||||||
throw new ServiceException("流程任务不存在或任务已审批!");
|
throw new ServiceException("流程任务不存在或任务已审批!");
|
||||||
}
|
|
||||||
Instance ins = insService.getById(flowTask.getInstanceId());
|
|
||||||
// 检查流程状态是否为草稿、已撤销或已退回状态,若是则执行流程提交监听
|
|
||||||
if (BusinessStatusEnum.isDraftOrCancelOrBack(ins.getFlowStatus())) {
|
|
||||||
variables.put(FlowConstant.SUBMIT, true);
|
|
||||||
}
|
|
||||||
// 设置弹窗处理人
|
|
||||||
Map<String, Object> assigneeMap = setPopAssigneeMap(completeTaskBo.getAssigneeMap(), ins.getVariableMap());
|
|
||||||
if (CollUtil.isNotEmpty(assigneeMap)) {
|
|
||||||
variables.putAll(assigneeMap);
|
|
||||||
}
|
|
||||||
// 构建流程参数,包括变量、跳转类型、消息、处理人、权限等信息
|
|
||||||
FlowParams flowParams = FlowParams.build()
|
|
||||||
.handler(completeTaskBo.getHandler())
|
|
||||||
.variable(variables)
|
|
||||||
.skipType(SkipType.PASS.getKey())
|
|
||||||
.message(completeTaskBo.getMessage())
|
|
||||||
.flowStatus(BusinessStatusEnum.WAITING.getStatus())
|
|
||||||
.hisStatus(TaskStatusEnum.PASS.getStatus())
|
|
||||||
.hisTaskExt(completeTaskBo.getFileId());
|
|
||||||
Boolean autoPass = Convert.toBool(variables.getOrDefault(AUTO_PASS, false));
|
|
||||||
skipTask(taskId, flowParams, flowTask.getInstanceId(), autoPass);
|
|
||||||
return true;
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.error(e.getMessage(), e);
|
|
||||||
throw new ServiceException(e.getMessage());
|
|
||||||
}
|
}
|
||||||
|
Instance ins = insService.getById(flowTask.getInstanceId());
|
||||||
|
// 检查流程状态是否为草稿、已撤销或已退回状态,若是则执行流程提交监听
|
||||||
|
if (BusinessStatusEnum.isDraftOrCancelOrBack(ins.getFlowStatus())) {
|
||||||
|
variables.put(FlowConstant.SUBMIT, true);
|
||||||
|
}
|
||||||
|
// 设置弹窗处理人
|
||||||
|
Map<String, Object> assigneeMap = setPopAssigneeMap(completeTaskBo.getAssigneeMap(), ins.getVariableMap());
|
||||||
|
if (CollUtil.isNotEmpty(assigneeMap)) {
|
||||||
|
variables.putAll(assigneeMap);
|
||||||
|
}
|
||||||
|
// 构建流程参数,包括变量、跳转类型、消息、处理人、权限等信息
|
||||||
|
FlowParams flowParams = FlowParams.build()
|
||||||
|
.handler(completeTaskBo.getHandler())
|
||||||
|
.variable(variables)
|
||||||
|
.skipType(SkipType.PASS.getKey())
|
||||||
|
.message(completeTaskBo.getMessage())
|
||||||
|
.flowStatus(BusinessStatusEnum.WAITING.getStatus())
|
||||||
|
.hisStatus(TaskStatusEnum.PASS.getStatus())
|
||||||
|
.hisTaskExt(completeTaskBo.getFileId());
|
||||||
|
Boolean autoPass = Convert.toBool(variables.getOrDefault(AUTO_PASS, false));
|
||||||
|
skipTask(taskId, flowParams, flowTask.getInstanceId(), autoPass);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -478,40 +468,35 @@ public class FlwTaskServiceImpl implements IFlwTaskService {
|
|||||||
@Override
|
@Override
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public boolean backProcess(BackProcessBo bo) {
|
public boolean backProcess(BackProcessBo bo) {
|
||||||
try {
|
Long taskId = bo.getTaskId();
|
||||||
Long taskId = bo.getTaskId();
|
String notice = bo.getNotice();
|
||||||
String notice = bo.getNotice();
|
List<String> messageType = bo.getMessageType();
|
||||||
List<String> messageType = bo.getMessageType();
|
String message = bo.getMessage();
|
||||||
String message = bo.getMessage();
|
FlowTask task = flowTaskMapper.selectById(taskId);
|
||||||
FlowTask task = flowTaskMapper.selectById(taskId);
|
if (ObjectUtil.isNull(task)) {
|
||||||
if (ObjectUtil.isNull(task)) {
|
throw new ServiceException("任务不存在!");
|
||||||
throw new ServiceException("任务不存在!");
|
|
||||||
}
|
|
||||||
Instance inst = insService.getById(task.getInstanceId());
|
|
||||||
BusinessStatusEnum.checkBackStatus(inst.getFlowStatus());
|
|
||||||
Long definitionId = task.getDefinitionId();
|
|
||||||
String applyNodeCode = flwCommonService.applyNodeCode(definitionId);
|
|
||||||
|
|
||||||
Map<String, Object> variable = new HashMap<>();
|
|
||||||
// 消息类型
|
|
||||||
variable.put(FlowConstant.MESSAGE_TYPE, messageType);
|
|
||||||
// 消息通知
|
|
||||||
variable.put(FlowConstant.MESSAGE_NOTICE, notice);
|
|
||||||
|
|
||||||
FlowParams flowParams = FlowParams.build()
|
|
||||||
.nodeCode(bo.getNodeCode())
|
|
||||||
.variable(variable)
|
|
||||||
.message(message)
|
|
||||||
.skipType(SkipType.REJECT.getKey())
|
|
||||||
.flowStatus(applyNodeCode.equals(bo.getNodeCode()) ? TaskStatusEnum.BACK.getStatus() : TaskStatusEnum.WAITING.getStatus())
|
|
||||||
.hisStatus(TaskStatusEnum.BACK.getStatus())
|
|
||||||
.hisTaskExt(bo.getFileId());
|
|
||||||
taskService.skip(task.getId(), flowParams);
|
|
||||||
return true;
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.error(e.getMessage(), e);
|
|
||||||
throw new ServiceException(e.getMessage());
|
|
||||||
}
|
}
|
||||||
|
Instance inst = insService.getById(task.getInstanceId());
|
||||||
|
BusinessStatusEnum.checkBackStatus(inst.getFlowStatus());
|
||||||
|
Long definitionId = task.getDefinitionId();
|
||||||
|
String applyNodeCode = flwCommonService.applyNodeCode(definitionId);
|
||||||
|
|
||||||
|
Map<String, Object> variable = new HashMap<>();
|
||||||
|
// 消息类型
|
||||||
|
variable.put(FlowConstant.MESSAGE_TYPE, messageType);
|
||||||
|
// 消息通知
|
||||||
|
variable.put(FlowConstant.MESSAGE_NOTICE, notice);
|
||||||
|
|
||||||
|
FlowParams flowParams = FlowParams.build()
|
||||||
|
.nodeCode(bo.getNodeCode())
|
||||||
|
.variable(variable)
|
||||||
|
.message(message)
|
||||||
|
.skipType(SkipType.REJECT.getKey())
|
||||||
|
.flowStatus(applyNodeCode.equals(bo.getNodeCode()) ? TaskStatusEnum.BACK.getStatus() : TaskStatusEnum.WAITING.getStatus())
|
||||||
|
.hisStatus(TaskStatusEnum.BACK.getStatus())
|
||||||
|
.hisTaskExt(bo.getFileId());
|
||||||
|
taskService.skip(task.getId(), flowParams);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -565,26 +550,21 @@ public class FlwTaskServiceImpl implements IFlwTaskService {
|
|||||||
@Override
|
@Override
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public boolean terminationTask(FlowTerminationBo bo) {
|
public boolean terminationTask(FlowTerminationBo bo) {
|
||||||
try {
|
Long taskId = bo.getTaskId();
|
||||||
Long taskId = bo.getTaskId();
|
Task task = taskService.getById(taskId);
|
||||||
Task task = taskService.getById(taskId);
|
if (task == null) {
|
||||||
if (task == null) {
|
throw new ServiceException("任务不存在!");
|
||||||
throw new ServiceException("任务不存在!");
|
|
||||||
}
|
|
||||||
Instance instance = insService.getById(task.getInstanceId());
|
|
||||||
if (ObjectUtil.isNotNull(instance)) {
|
|
||||||
BusinessStatusEnum.checkInvalidStatus(instance.getFlowStatus());
|
|
||||||
}
|
|
||||||
FlowParams flowParams = FlowParams.build()
|
|
||||||
.message(bo.getComment())
|
|
||||||
.flowStatus(BusinessStatusEnum.TERMINATION.getStatus())
|
|
||||||
.hisStatus(TaskStatusEnum.TERMINATION.getStatus());
|
|
||||||
taskService.termination(taskId, flowParams);
|
|
||||||
return true;
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.error(e.getMessage(), e);
|
|
||||||
throw new ServiceException(e.getMessage());
|
|
||||||
}
|
}
|
||||||
|
Instance instance = insService.getById(task.getInstanceId());
|
||||||
|
if (ObjectUtil.isNotNull(instance)) {
|
||||||
|
BusinessStatusEnum.checkInvalidStatus(instance.getFlowStatus());
|
||||||
|
}
|
||||||
|
FlowParams flowParams = FlowParams.build()
|
||||||
|
.message(bo.getComment())
|
||||||
|
.flowStatus(BusinessStatusEnum.TERMINATION.getStatus())
|
||||||
|
.hisStatus(TaskStatusEnum.TERMINATION.getStatus());
|
||||||
|
taskService.termination(taskId, flowParams);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -806,23 +786,18 @@ public class FlwTaskServiceImpl implements IFlwTaskService {
|
|||||||
if (CollUtil.isEmpty(taskIdList)) {
|
if (CollUtil.isEmpty(taskIdList)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
try {
|
List<FlowTask> flowTasks = this.selectByIdList(taskIdList);
|
||||||
List<FlowTask> flowTasks = this.selectByIdList(taskIdList);
|
// 批量删除现有任务的办理人记录
|
||||||
// 批量删除现有任务的办理人记录
|
if (CollUtil.isNotEmpty(flowTasks)) {
|
||||||
if (CollUtil.isNotEmpty(flowTasks)) {
|
FlowEngine.userService().deleteByTaskIds(StreamUtils.toList(flowTasks, FlowTask::getId));
|
||||||
FlowEngine.userService().deleteByTaskIds(StreamUtils.toList(flowTasks, FlowTask::getId));
|
List<User> userList = StreamUtils.toList(flowTasks, flowTask ->
|
||||||
List<User> userList = StreamUtils.toList(flowTasks, flowTask ->
|
new FlowUser()
|
||||||
new FlowUser()
|
.setType(TaskAssigneeType.APPROVER.getCode())
|
||||||
.setType(TaskAssigneeType.APPROVER.getCode())
|
.setProcessedBy(userId)
|
||||||
.setProcessedBy(userId)
|
.setAssociated(flowTask.getId()));
|
||||||
.setAssociated(flowTask.getId()));
|
if (CollUtil.isNotEmpty(userList)) {
|
||||||
if (CollUtil.isNotEmpty(userList)) {
|
FlowEngine.userService().saveBatch(userList);
|
||||||
FlowEngine.userService().saveBatch(userList);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
|
||||||
log.error(e.getMessage(), e);
|
|
||||||
throw new ServiceException(e.getMessage());
|
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -862,21 +837,16 @@ public class FlwTaskServiceImpl implements IFlwTaskService {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean urgeTask(FlowUrgeTaskBo bo) {
|
public boolean urgeTask(FlowUrgeTaskBo bo) {
|
||||||
try {
|
if (CollUtil.isEmpty(bo.getTaskIdList())) {
|
||||||
if (CollUtil.isEmpty(bo.getTaskIdList())) {
|
return false;
|
||||||
return false;
|
|
||||||
}
|
|
||||||
List<UserDTO> userList = this.currentTaskAllUser(bo.getTaskIdList());
|
|
||||||
if (CollUtil.isEmpty(userList)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
List<String> messageType = bo.getMessageType();
|
|
||||||
String message = bo.getMessage();
|
|
||||||
flwCommonService.sendMessage(messageType, message, "单据审批提醒", userList);
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.error(e.getMessage(), e);
|
|
||||||
throw new ServiceException(e.getMessage());
|
|
||||||
}
|
}
|
||||||
|
List<UserDTO> userList = this.currentTaskAllUser(bo.getTaskIdList());
|
||||||
|
if (CollUtil.isEmpty(userList)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
List<String> messageType = bo.getMessageType();
|
||||||
|
String message = bo.getMessage();
|
||||||
|
flwCommonService.sendMessage(messageType, message, "单据审批提醒", userList);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ import lombok.RequiredArgsConstructor;
|
|||||||
import org.dromara.common.core.domain.dto.CompleteTaskDTO;
|
import org.dromara.common.core.domain.dto.CompleteTaskDTO;
|
||||||
import org.dromara.common.core.domain.dto.StartProcessDTO;
|
import org.dromara.common.core.domain.dto.StartProcessDTO;
|
||||||
import org.dromara.common.core.domain.dto.StartProcessReturnDTO;
|
import org.dromara.common.core.domain.dto.StartProcessReturnDTO;
|
||||||
import org.dromara.common.core.exception.ServiceException;
|
|
||||||
import org.dromara.common.core.service.WorkflowService;
|
import org.dromara.common.core.service.WorkflowService;
|
||||||
import org.dromara.common.core.utils.StringUtils;
|
import org.dromara.common.core.utils.StringUtils;
|
||||||
import org.dromara.warm.flow.orm.entity.FlowInstance;
|
import org.dromara.warm.flow.orm.entity.FlowInstance;
|
||||||
@@ -161,28 +160,19 @@ public class WorkflowServiceImpl implements WorkflowService {
|
|||||||
@Override
|
@Override
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public boolean startCompleteTask(StartProcessDTO startProcess) {
|
public boolean startCompleteTask(StartProcessDTO startProcess) {
|
||||||
try {
|
StartProcessBo processBo = new StartProcessBo();
|
||||||
StartProcessBo processBo = new StartProcessBo();
|
processBo.setBusinessId(startProcess.getBusinessId());
|
||||||
processBo.setBusinessId(startProcess.getBusinessId());
|
processBo.setFlowCode(startProcess.getFlowCode());
|
||||||
processBo.setFlowCode(startProcess.getFlowCode());
|
processBo.setVariables(startProcess.getVariables());
|
||||||
processBo.setVariables(startProcess.getVariables());
|
processBo.setHandler(startProcess.getHandler());
|
||||||
processBo.setHandler(startProcess.getHandler());
|
processBo.setBizExt(BeanUtil.toBean(startProcess.getBizExt(), FlowInstanceBizExt.class));
|
||||||
processBo.setBizExt(BeanUtil.toBean(startProcess.getBizExt(), FlowInstanceBizExt.class));
|
|
||||||
|
|
||||||
StartProcessReturnDTO result = flwTaskService.startWorkFlow(processBo);
|
StartProcessReturnDTO result = flwTaskService.startWorkFlow(processBo);
|
||||||
CompleteTaskBo taskBo = new CompleteTaskBo();
|
CompleteTaskBo taskBo = new CompleteTaskBo();
|
||||||
taskBo.setTaskId(result.getTaskId());
|
taskBo.setTaskId(result.getTaskId());
|
||||||
taskBo.setMessageType(Collections.singletonList(MessageTypeEnum.SYSTEM_MESSAGE.getCode()));
|
taskBo.setMessageType(Collections.singletonList(MessageTypeEnum.SYSTEM_MESSAGE.getCode()));
|
||||||
taskBo.setVariables(startProcess.getVariables());
|
taskBo.setVariables(startProcess.getVariables());
|
||||||
taskBo.setHandler(startProcess.getHandler());
|
taskBo.setHandler(startProcess.getHandler());
|
||||||
|
return flwTaskService.completeTask(taskBo);
|
||||||
boolean flag = flwTaskService.completeTask(taskBo);
|
|
||||||
if (!flag) {
|
|
||||||
throw new ServiceException("流程发起异常");
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
} catch (Exception e) {
|
|
||||||
throw new ServiceException(e.getMessage());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user