mirror of
https://gitee.com/dromara/RuoYi-Vue-Plus.git
synced 2026-11-02 21:36:59 +08:00
refactor: 使用通用转换工具解析请假业务主键,移除相关测试并完善工作流注释
This commit is contained in:
parent
390290a662
commit
a6d1be7141
@ -15,14 +15,28 @@ public class StartMessageEventDTO implements Serializable {
|
|||||||
@Serial
|
@Serial
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
/** 业务主键,调用方必须提供。 */
|
/**
|
||||||
|
* 业务主键,调用方必须提供。
|
||||||
|
*/
|
||||||
private String businessId;
|
private String businessId;
|
||||||
/** 流程定义编码。 */
|
|
||||||
|
/**
|
||||||
|
* 流程定义编码。
|
||||||
|
*/
|
||||||
private String flowCode;
|
private String flowCode;
|
||||||
/** 消息启动事件名称。 */
|
|
||||||
|
/**
|
||||||
|
* 消息启动事件名称。
|
||||||
|
*/
|
||||||
private String eventName;
|
private String eventName;
|
||||||
/** 合并到流程变量的消息数据,可为空。 */
|
|
||||||
|
/**
|
||||||
|
* 合并到流程变量的消息数据,可为空。
|
||||||
|
*/
|
||||||
private Map<String, Object> payload;
|
private Map<String, Object> payload;
|
||||||
/** 操作人,留空时使用系统处理人。 */
|
|
||||||
|
/**
|
||||||
|
* 操作人,留空时使用系统处理人。
|
||||||
|
*/
|
||||||
private String handler;
|
private String handler;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -15,14 +15,28 @@ public class StartTimerEventDTO implements Serializable {
|
|||||||
@Serial
|
@Serial
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
/** 业务主键,留空时生成数字雪花 ID。 */
|
/**
|
||||||
|
* 业务主键,留空时生成数字雪花 ID。
|
||||||
|
*/
|
||||||
private String businessId;
|
private String businessId;
|
||||||
/** 已发布的流程定义 ID。 */
|
|
||||||
|
/**
|
||||||
|
* 已发布的流程定义 ID。
|
||||||
|
*/
|
||||||
private Long definitionId;
|
private Long definitionId;
|
||||||
/** 定时启动事件节点编码。 */
|
|
||||||
|
/**
|
||||||
|
* 定时启动事件节点编码。
|
||||||
|
*/
|
||||||
private String nodeCode;
|
private String nodeCode;
|
||||||
/** 合并到流程变量的业务数据,可为空。 */
|
|
||||||
|
/**
|
||||||
|
* 合并到流程变量的业务数据,可为空。
|
||||||
|
*/
|
||||||
private Map<String, Object> payload;
|
private Map<String, Object> payload;
|
||||||
/** 操作人,留空时使用系统处理人。 */
|
|
||||||
|
/**
|
||||||
|
* 操作人,留空时使用系统处理人。
|
||||||
|
*/
|
||||||
private String handler;
|
private String handler;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -15,12 +15,23 @@ public class TriggerMessageEventDTO implements Serializable {
|
|||||||
@Serial
|
@Serial
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
/** 已存在的流程实例 ID。 */
|
/**
|
||||||
|
* 已存在的流程实例 ID。
|
||||||
|
*/
|
||||||
private Long instanceId;
|
private Long instanceId;
|
||||||
/** 等待中的消息捕获或消息边界事件名称。 */
|
|
||||||
|
/**
|
||||||
|
* 等待中的消息捕获或消息边界事件名称。
|
||||||
|
*/
|
||||||
private String eventName;
|
private String eventName;
|
||||||
/** 合并到流程变量的消息数据,可为空。 */
|
|
||||||
|
/**
|
||||||
|
* 合并到流程变量的消息数据,可为空。
|
||||||
|
*/
|
||||||
private Map<String, Object> payload;
|
private Map<String, Object> payload;
|
||||||
/** 操作人,留空时使用系统处理人。 */
|
|
||||||
|
/**
|
||||||
|
* 操作人,留空时使用系统处理人。
|
||||||
|
*/
|
||||||
private String handler;
|
private String handler;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -306,6 +306,13 @@ public class FlwInstanceServiceImpl implements IFlwInstanceService {
|
|||||||
return flowHisTaskList(null, businessId);
|
return flowHisTaskList(null, businessId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 按实例 ID、业务 ID 查询流程图及历史办理记录;同时提供时须指向同一实例。
|
||||||
|
*
|
||||||
|
* @param instanceId 流程实例 ID,可为空
|
||||||
|
* @param businessId 业务 ID,可为空
|
||||||
|
* @return 流程图与办理记录
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Map<String, Object> flowHisTaskList(Long instanceId, String businessId) {
|
public Map<String, Object> flowHisTaskList(Long instanceId, String businessId) {
|
||||||
if (instanceId == null && StringUtils.isBlank(businessId)) {
|
if (instanceId == null && StringUtils.isBlank(businessId)) {
|
||||||
|
|||||||
@ -229,7 +229,7 @@ public class TestLeaveServiceImpl implements ITestLeaveService {
|
|||||||
@EventListener(condition = "#processEvent.flowCode.startsWith('demo')")
|
@EventListener(condition = "#processEvent.flowCode.startsWith('demo')")
|
||||||
public void processHandler(ProcessEvent processEvent) {
|
public void processHandler(ProcessEvent processEvent) {
|
||||||
log.info("当前任务执行了{}", processEvent.toString());
|
log.info("当前任务执行了{}", processEvent.toString());
|
||||||
Long leaveId = parseLeaveId(processEvent.getBusinessId());
|
Long leaveId = Convert.toLong(processEvent.getBusinessId());
|
||||||
if (leaveId == null) {
|
if (leaveId == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -287,7 +287,7 @@ public class TestLeaveServiceImpl implements ITestLeaveService {
|
|||||||
@EventListener(condition = "#processDeleteEvent.flowCode.startsWith('demo')")
|
@EventListener(condition = "#processDeleteEvent.flowCode.startsWith('demo')")
|
||||||
public void processDeleteHandler(ProcessDeleteEvent processDeleteEvent) {
|
public void processDeleteHandler(ProcessDeleteEvent processDeleteEvent) {
|
||||||
log.info("监听删除流程事件,当前任务执行了{}", processDeleteEvent.toString());
|
log.info("监听删除流程事件,当前任务执行了{}", processDeleteEvent.toString());
|
||||||
Long leaveId = parseLeaveId(processDeleteEvent.getBusinessId());
|
Long leaveId = Convert.toLong(processDeleteEvent.getBusinessId());
|
||||||
if (leaveId == null) {
|
if (leaveId == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -298,12 +298,4 @@ public class TestLeaveServiceImpl implements ITestLeaveService {
|
|||||||
leaveMapper.deleteById(testLeave.getId());
|
leaveMapper.deleteById(testLeave.getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
static Long parseLeaveId(String businessId) {
|
|
||||||
try {
|
|
||||||
return Long.valueOf(businessId);
|
|
||||||
} catch (NumberFormatException e) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -178,6 +178,12 @@ public class WorkflowServiceImpl implements WorkflowService {
|
|||||||
return flwTaskService.completeTask(taskBo);
|
return flwTaskService.completeTask(taskBo);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 外部消息按流程编码和事件名称启动新实例。
|
||||||
|
*
|
||||||
|
* @param request 消息启动参数,业务 ID 由调用方提供
|
||||||
|
* @return 新建流程实例 ID
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public Long startByMessageEvent(StartMessageEventDTO request) {
|
public Long startByMessageEvent(StartMessageEventDTO request) {
|
||||||
@ -188,6 +194,12 @@ public class WorkflowServiceImpl implements WorkflowService {
|
|||||||
request.getEventName(), request.getPayload(), eventContext(request.getHandler())).getId();
|
request.getEventName(), request.getPayload(), eventContext(request.getHandler())).getId();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 触发实例中等待的消息捕获或消息边界事件。重复投递时引擎保持实例不变。
|
||||||
|
*
|
||||||
|
* @param request 消息事件参数
|
||||||
|
* @return 流程实例 ID
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public Long triggerMessageEvent(TriggerMessageEventDTO request) {
|
public Long triggerMessageEvent(TriggerMessageEventDTO request) {
|
||||||
@ -198,6 +210,12 @@ public class WorkflowServiceImpl implements WorkflowService {
|
|||||||
request.getPayload(), eventContext(request.getHandler())).getId();
|
request.getPayload(), eventContext(request.getHandler())).getId();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 手动发起定时启动事件,不改变等待记录及下一次自动触发时间。
|
||||||
|
*
|
||||||
|
* @param request 定时启动参数,业务 ID 留空时生成数字雪花 ID
|
||||||
|
* @return 新建流程实例 ID
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public Long startByTimerEvent(StartTimerEventDTO request) {
|
public Long startByTimerEvent(StartTimerEventDTO request) {
|
||||||
@ -210,18 +228,40 @@ public class WorkflowServiceImpl implements WorkflowService {
|
|||||||
request.getNodeCode(), request.getPayload(), eventContext(request.getHandler())).getId();
|
request.getNodeCode(), request.getPayload(), eventContext(request.getHandler())).getId();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 从实例级错误捕获节点处理外部错误。
|
||||||
|
*
|
||||||
|
* @param instanceId 流程实例 ID
|
||||||
|
* @param errorCode 错误码,精确匹配优先于通配
|
||||||
|
* @param errorMessage 错误描述
|
||||||
|
* @return 错误事件已被处理时返回 true
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public boolean throwInstanceErrorEvent(Long instanceId, String errorCode, String errorMessage) {
|
public boolean throwInstanceErrorEvent(Long instanceId, String errorCode, String errorMessage) {
|
||||||
return FlowEngine.insService().throwError(instanceId, errorCode, errorMessage);
|
return FlowEngine.insService().throwError(instanceId, errorCode, errorMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 从当前待办的错误边界节点处理外部错误。
|
||||||
|
*
|
||||||
|
* @param taskId 当前待办任务 ID
|
||||||
|
* @param errorCode 错误码,精确匹配优先于通配
|
||||||
|
* @param errorMessage 错误描述
|
||||||
|
* @return 错误事件已被处理时返回 true
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public boolean throwTaskErrorEvent(Long taskId, String errorCode, String errorMessage) {
|
public boolean throwTaskErrorEvent(Long taskId, String errorCode, String errorMessage) {
|
||||||
return FlowEngine.taskService().throwError(taskId, errorCode, errorMessage);
|
return FlowEngine.taskService().throwError(taskId, errorCode, errorMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 构建事件上下文
|
||||||
|
*
|
||||||
|
* @param handler 操作人
|
||||||
|
* @return 事件上下文
|
||||||
|
*/
|
||||||
private WorkflowContext eventContext(String handler) {
|
private WorkflowContext eventContext(String handler) {
|
||||||
WorkflowContext context = new WorkflowContext();
|
WorkflowContext context = new WorkflowContext();
|
||||||
context.setHandler(StringUtils.isNotBlank(handler) ? handler : FlowEngine.getFlowConfig().getSystemHandler());
|
context.setHandler(StringUtils.isNotBlank(handler) ? handler : FlowEngine.getFlowConfig().getSystemHandler());
|
||||||
|
|||||||
@ -1,17 +0,0 @@
|
|||||||
package org.dromara.workflow.service.impl;
|
|
||||||
|
|
||||||
import org.junit.jupiter.api.Test;
|
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
|
||||||
|
|
||||||
class TestLeaveServiceImplTest {
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void ignoresEngineGeneratedBusinessIds() {
|
|
||||||
assertNull(TestLeaveServiceImpl.parseLeaveId("T2114648233624309762_1793006432000"));
|
|
||||||
assertNull(TestLeaveServiceImpl.parseLeaveId("9223372036854775808"));
|
|
||||||
assertNull(TestLeaveServiceImpl.parseLeaveId(null));
|
|
||||||
assertEquals(123L, TestLeaveServiceImpl.parseLeaveId("123"));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Loading…
Reference in New Issue
Block a user