From c920d954efabf58274394f550f5779eb29c798fc Mon Sep 17 00:00:00 2001 From: liuyihe <2513762445@qq.com> Date: Tue, 13 Oct 2026 10:47:58 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B4=B4=E6=A0=87=E7=94=B3=E8=AF=B7=EF=BC=8C?= =?UTF-8?q?=E4=BB=93=E5=82=A8=E8=BD=AC=E8=BF=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ReturnInventoryMovementSqlTest.java | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 lastleg-service/src/test/java/com/baiyue/lastleg/returnreceipt/service/ReturnInventoryMovementSqlTest.java diff --git a/lastleg-service/src/test/java/com/baiyue/lastleg/returnreceipt/service/ReturnInventoryMovementSqlTest.java b/lastleg-service/src/test/java/com/baiyue/lastleg/returnreceipt/service/ReturnInventoryMovementSqlTest.java new file mode 100644 index 000000000..b9915e50f --- /dev/null +++ b/lastleg-service/src/test/java/com/baiyue/lastleg/returnreceipt/service/ReturnInventoryMovementSqlTest.java @@ -0,0 +1,42 @@ +package com.baiyue.lastleg.returnreceipt.service; + +import com.baiyue.lastleg.returnreceipt.mapper.ReturnInventoryMovementMapper; +import org.apache.ibatis.builder.annotation.MapperAnnotationBuilder; +import org.apache.ibatis.session.Configuration; +import org.junit.jupiter.api.Test; + +import java.util.Map; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; + +class ReturnInventoryMovementSqlTest { + @Test + void everyUnionBranchNormalizesAllSixTextColumns() { + String[] branches = ReturnInventoryMovementMapper.MOVEMENTS.split("UNION ALL"); + assertEquals(7, branches.length); + for (String branch : branches) { + String projection = branch.substring(0, branch.indexOf("FROM")); + assertEquals(6, projection.split("COLLATE utf8mb4_unicode_ci", -1).length - 1, branch); + assertEquals(6, projection.split("USING utf8mb4", -1).length - 1, branch); + } + } + + @Test + void countAndPageShareNormalizedProjectionAndKeepScopeFilters() { + Configuration configuration = new Configuration(); + new MapperAnnotationBuilder(configuration, ReturnInventoryMovementMapper.class).parse(); + Map params = Map.of("customerId", "CUSTOMER", "warehouseId", "WAREHOUSE", + "skuCode", "SKU", "offset", 0L, "size", 20L); + for (String method : new String[]{"platformCount", "platformPage"}) { + var boundSql = configuration.getMappedStatement(ReturnInventoryMovementMapper.class.getName() + "." + method) + .getBoundSql(params); + String sql = boundSql.getSql(); + assertEquals(42, sql.split("COLLATE utf8mb4_unicode_ci", -1).length - 1); + assertTrue(sql.contains("m.customerId=?")); + assertTrue(sql.contains("m.overseasWarehouseId=?")); + assertTrue(sql.contains("m.skuCode LIKE CONCAT('%',?,'%')")); + assertEquals(method.equals("platformPage") ? 5 : 3, boundSql.getParameterMappings().size()); + } + } +}