|
|
@@ -0,0 +1,33 @@
|
|
|
+package com.etotem.cfc.config;
|
|
|
+
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.inner.OptimisticLockerInnerInterceptor;
|
|
|
+import org.junit.jupiter.api.Test;
|
|
|
+
|
|
|
+import static org.junit.jupiter.api.Assertions.assertTrue;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 回归(2026-11-17):EnergyBalance 带 {@code @Version}(SC-X-21,d39aa5282),但
|
|
|
+ * MybatisPlusInterceptor 只注册了 PaginationInnerInterceptor,未注册
|
|
|
+ * {@link OptimisticLockerInnerInterceptor} —— MyBatis-Plus 3.5.x 对 @Version 实体的
|
|
|
+ * updateById 会静态生成 {@code AND version = #{MP_OPTLOCK_VERSION_ORIGINAL}},该参数
|
|
|
+ * 仅由乐观锁拦截器注入;缺注册则任何有积/能量发放的 updateById 抛
|
|
|
+ * BindingException(GitHub issue #3121 逐字一致),并因异常穿过
|
|
|
+ * {@code @Transactional awardEnergy} 代理边界把整笔打卡事务标记 rollback-only →
|
|
|
+ * UnexpectedRollbackException → 500,打卡整体回滚。
|
|
|
+ *
|
|
|
+ * <p>纯单元(无 Spring 上下文/DB),任何环境可跑。
|
|
|
+ */
|
|
|
+class MyBatisPlusOptimisticLockerContractTest {
|
|
|
+
|
|
|
+ @Test
|
|
|
+ void 拦截器链_应注册乐观锁拦截器() {
|
|
|
+ MybatisPlusInterceptor interceptor = new MyBatisPlusConfig().mybatisPlusInterceptor();
|
|
|
+ boolean hasOptimisticLocker = interceptor.getInterceptors().stream()
|
|
|
+ .anyMatch(i -> i instanceof OptimisticLockerInnerInterceptor);
|
|
|
+ assertTrue(hasOptimisticLocker,
|
|
|
+ "RED[mybatis.optimistic.locker]:MybatisPlusInterceptor 未注册 OptimisticLockerInnerInterceptor。"
|
|
|
+ + "EnergyBalance 的 @Version(SC-X-21)将导致所有能量发放 updateById 抛"
|
|
|
+ + " BindingException[MP_OPTLOCK_VERSION_ORIGINAL not found],打卡 500 整体回滚。");
|
|
|
+ }
|
|
|
+}
|