Commit 0cc2b2ebacb577ca05c0198490ae7c910f81aa6e
1 parent
230f61fb
feat(mod): mapper#selectActiveByKeyword REQ-MOD-004
Showing
2 changed files
with
34 additions
and
0 deletions
backend/src/main/java/com/xly/erp/module/mod/mapper/ModuleMapper.java
| ... | ... | @@ -5,6 +5,8 @@ import com.xly.erp.module.mod.entity.Module; |
| 5 | 5 | import org.apache.ibatis.annotations.Param; |
| 6 | 6 | import org.apache.ibatis.annotations.Select; |
| 7 | 7 | |
| 8 | +import java.util.List; | |
| 9 | + | |
| 8 | 10 | public interface ModuleMapper extends BaseMapper<Module> { |
| 9 | 11 | |
| 10 | 12 | @Select("SELECT 1 FROM tModule WHERE iIncrement = #{id} AND bDeleted = 0 LIMIT 1") |
| ... | ... | @@ -23,4 +25,9 @@ public interface ModuleMapper extends BaseMapper<Module> { |
| 23 | 25 | default boolean hasActiveChildren(Integer parentId) { |
| 24 | 26 | return findActiveChildFlag(parentId) != null; |
| 25 | 27 | } |
| 28 | + | |
| 29 | + @Select("SELECT iIncrement, sModuleNameZh, sDisplayType, sManageDeptEn, iParentId, iSortOrder " | |
| 30 | + + "FROM tModule WHERE bDeleted = 0 AND sModuleNameZh LIKE CONCAT('%', #{keyword}, '%') " | |
| 31 | + + "ORDER BY iSortOrder ASC, iIncrement ASC") | |
| 32 | + List<Module> selectActiveByKeyword(@Param("keyword") String keyword); | |
| 26 | 33 | } | ... | ... |
backend/src/test/java/com/xly/erp/module/mod/mapper/ModuleMapperIT.java
| ... | ... | @@ -97,6 +97,33 @@ class ModuleMapperIT { |
| 97 | 97 | assertThat(moduleMapper.hasActiveChildren(root.getIIncrement())).isFalse(); |
| 98 | 98 | } |
| 99 | 99 | |
| 100 | + @Test | |
| 101 | + void selectActiveByKeyword_filtersAndOrders() { | |
| 102 | + Module a = newModule("sp_test_kw_a", "系统-A", null); a.setISortOrder(1); moduleMapper.insert(a); | |
| 103 | + Module b = newModule("sp_test_kw_b", "系统-B", null); b.setISortOrder(0); moduleMapper.insert(b); | |
| 104 | + Module c = newModule("sp_test_kw_c", "用户", null); c.setISortOrder(2); moduleMapper.insert(c); | |
| 105 | + Module d = newModule("sp_test_kw_d", "系统-D", null); d.setISortOrder(3); d.setBDeleted(true); moduleMapper.insert(d); | |
| 106 | + Module e = newModule("sp_test_kw_e", "测试", null); e.setISortOrder(4); moduleMapper.insert(e); | |
| 107 | + | |
| 108 | + java.util.List<String> namesByEmpty = moduleMapper.selectActiveByKeyword("").stream() | |
| 109 | + .filter(m -> m.getSProcedureName() == null && m.getSModuleNameZh().matches("系统-[ABDE]|用户|测试")) | |
| 110 | + .map(Module::getSModuleNameZh).toList(); | |
| 111 | + // 只取本测试用例插入的 4 行(用 sProcedureName 与名字过滤会丢字段,改为按 iIncrement 集合判定) | |
| 112 | + java.util.Set<Integer> insertedIds = java.util.Set.of( | |
| 113 | + a.getIIncrement(), b.getIIncrement(), c.getIIncrement(), e.getIIncrement()); | |
| 114 | + java.util.List<Module> empty = moduleMapper.selectActiveByKeyword("").stream() | |
| 115 | + .filter(m -> insertedIds.contains(m.getIIncrement())).toList(); | |
| 116 | + assertThat(empty).extracting(Module::getIIncrement) | |
| 117 | + .containsExactly(b.getIIncrement(), a.getIIncrement(), c.getIIncrement(), e.getIIncrement()); | |
| 118 | + | |
| 119 | + java.util.List<Module> sys = moduleMapper.selectActiveByKeyword("系统").stream() | |
| 120 | + .filter(m -> insertedIds.contains(m.getIIncrement())).toList(); | |
| 121 | + assertThat(sys).extracting(Module::getIIncrement) | |
| 122 | + .containsExactly(b.getIIncrement(), a.getIIncrement()); | |
| 123 | + | |
| 124 | + assertThat(moduleMapper.selectActiveByKeyword("不存在XYZ-zzz")).isEmpty(); | |
| 125 | + } | |
| 126 | + | |
| 100 | 127 | private Module newModule(String procedureName, String nameZh, Integer parentId) { |
| 101 | 128 | Module m = new Module(); |
| 102 | 129 | m.setSBrandsId("XLY"); | ... | ... |