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()); + } + } +}