feat(common): 添加 MybatisPlusConfig/StateValidator,修复 jsqlparser 依赖 (T010/T011)
- MybatisPlusConfig: TenantLineInnerInterceptor + PaginationInnerInterceptor - StateValidator: 通用状态机校验,失败抛出 INVALID_STATE_TRANSITION - pom.xml: 新增 mybatis-plus-jsqlparser 3.5.9(3.5.7+ 必须显式引入)
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
package com.label.common.statemachine;
|
||||
|
||||
import com.label.common.exception.BusinessException;
|
||||
import org.springframework.http.HttpStatus;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Generic state machine validator.
|
||||
* Validates state transitions against a predefined transitions map.
|
||||
*/
|
||||
public final class StateValidator {
|
||||
|
||||
private StateValidator() {}
|
||||
|
||||
/**
|
||||
* Assert that a state transition from {@code current} to {@code next} is valid.
|
||||
*
|
||||
* @param transitions the allowed transitions map
|
||||
* @param current the current state
|
||||
* @param next the desired next state
|
||||
* @param <S> the state type (enum)
|
||||
* @throws BusinessException with code INVALID_STATE_TRANSITION if transition not allowed
|
||||
*/
|
||||
public static <S> void assertTransition(Map<S, Set<S>> transitions, S current, S next) {
|
||||
Set<S> allowed = transitions.get(current);
|
||||
if (allowed == null || !allowed.contains(next)) {
|
||||
throw new BusinessException(
|
||||
"INVALID_STATE_TRANSITION",
|
||||
String.format("不允许的状态转换: %s → %s", current, next),
|
||||
HttpStatus.CONFLICT
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user