|
@@ -1,44 +1,52 @@
|
|
|
package com.ruoyi.system.mapper;
|
|
package com.ruoyi.system.mapper;
|
|
|
|
|
|
|
|
import org.apache.ibatis.builder.xml.XMLMapperBuilder;
|
|
import org.apache.ibatis.builder.xml.XMLMapperBuilder;
|
|
|
|
|
+import org.apache.ibatis.mapping.BoundSql;
|
|
|
import org.apache.ibatis.session.Configuration;
|
|
import org.apache.ibatis.session.Configuration;
|
|
|
import org.junit.jupiter.api.Test;
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
|
|
|
|
|
|
+import java.io.IOException;
|
|
|
import java.io.InputStream;
|
|
import java.io.InputStream;
|
|
|
|
|
+import java.util.HashMap;
|
|
|
|
|
+import java.util.Map;
|
|
|
|
|
|
|
|
-import static org.junit.jupiter.api.Assertions.assertFalse;
|
|
|
|
|
|
|
+import static org.junit.jupiter.api.Assertions.assertNotNull;
|
|
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
- * 摊位资料审核列表 filter 片段渲染回归:status 基础条件与动态条件之间必须保留分隔空白。
|
|
|
|
|
|
|
+ * 平台审核列表 filter 渲染回归:静态文本 status != 0 与动态 if 的 AND 之间必须保留空白,
|
|
|
|
|
+ * 防止拼出 "0AND" 导致 SQL 语法错误(线上 2026-10-16 报过)。
|
|
|
*/
|
|
*/
|
|
|
class StallQualificationMapperXmlTest {
|
|
class StallQualificationMapperXmlTest {
|
|
|
|
|
|
|
|
- private Configuration loadMapper() throws Exception {
|
|
|
|
|
- String resource = "mapper/chanting/StallQualificationMapper.xml";
|
|
|
|
|
|
|
+ @Test
|
|
|
|
|
+ void selectApplicationsKeepsWhitespaceBetweenStaticTextAndIf() throws IOException {
|
|
|
|
|
+ Configuration configuration = mapperConfiguration();
|
|
|
|
|
+ Map<String, Object> query = new HashMap<>();
|
|
|
|
|
+ query.put("status", 1);
|
|
|
|
|
+
|
|
|
|
|
+ BoundSql select = configuration
|
|
|
|
|
+ .getMappedStatement("com.ruoyi.system.mapper.StallQualificationMapper.selectApplications")
|
|
|
|
|
+ .getBoundSql(query);
|
|
|
|
|
+ String flat = select.getSql().replaceAll("\\s+", " ").trim();
|
|
|
|
|
+ assertTrue(flat.contains("status != 0 AND status = ?"),
|
|
|
|
|
+ "静态文本与动态 if 之间缺少空白,实际渲染: " + flat);
|
|
|
|
|
+
|
|
|
|
|
+ BoundSql count = configuration
|
|
|
|
|
+ .getMappedStatement("com.ruoyi.system.mapper.StallQualificationMapper.countApplications")
|
|
|
|
|
+ .getBoundSql(query);
|
|
|
|
|
+ String countFlat = count.getSql().replaceAll("\\s+", " ").trim();
|
|
|
|
|
+ assertTrue(countFlat.contains("status != 0 AND status = ?"),
|
|
|
|
|
+ "count 语句同样缺少空白,实际渲染: " + countFlat);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private Configuration mapperConfiguration() throws IOException {
|
|
|
Configuration configuration = new Configuration();
|
|
Configuration configuration = new Configuration();
|
|
|
|
|
+ String resource = "mapper/chanting/StallQualificationMapper.xml";
|
|
|
try (InputStream input = getClass().getClassLoader().getResourceAsStream(resource)) {
|
|
try (InputStream input = getClass().getClassLoader().getResourceAsStream(resource)) {
|
|
|
|
|
+ assertNotNull(input);
|
|
|
new XMLMapperBuilder(input, configuration, resource, configuration.getSqlFragments()).parse();
|
|
new XMLMapperBuilder(input, configuration, resource, configuration.getSqlFragments()).parse();
|
|
|
}
|
|
}
|
|
|
return configuration;
|
|
return configuration;
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
- @Test
|
|
|
|
|
- void filterKeepsSeparatorBetweenBaseAndDynamicConditions() throws Exception {
|
|
|
|
|
- Configuration configuration = loadMapper();
|
|
|
|
|
- String namespace = "com.ruoyi.system.mapper.StallQualificationMapper.";
|
|
|
|
|
- String sql = configuration.getMappedStatement(namespace + "selectApplications")
|
|
|
|
|
- .getBoundSql(java.util.Map.of("status", 1, "limit", 10, "offset", 0)).getSql();
|
|
|
|
|
- System.out.println("RENDERED SQL >>> " + sql + " <<<");
|
|
|
|
|
- String collapsed = sql.replaceAll("\\s+", " ").toLowerCase();
|
|
|
|
|
- assertFalse(collapsed.contains("0and"), "条件之间丢失分隔空白: " + collapsed);
|
|
|
|
|
- assertTrue(collapsed.contains("status != 0 and status = ?"), collapsed);
|
|
|
|
|
- assertTrue(collapsed.contains("limit ? offset ?"), collapsed);
|
|
|
|
|
-
|
|
|
|
|
- String withStore = configuration.getMappedStatement(namespace + "selectApplications")
|
|
|
|
|
- .getBoundSql(java.util.Map.of("status", 2, "storeId", 7L, "limit", 10, "offset", 0)).getSql();
|
|
|
|
|
- String collapsedStore = withStore.replaceAll("\\s+", " ").toLowerCase();
|
|
|
|
|
- assertFalse(collapsedStore.contains("?and"), "动态条件之间丢失分隔空白: " + collapsedStore);
|
|
|
|
|
- assertTrue(collapsedStore.contains("and store_id = ?"), collapsedStore);
|
|
|
|
|
- }
|
|
|
|
|
}
|
|
}
|