Commit c4b2e2ddb20c2cc46169ee903752c518d08d8e1a
1 parent
6c892322
feat(mod): mapper#selectParentIdById for cycle check REQ-MOD-002
Showing
2 changed files
with
21 additions
and
0 deletions
backend/src/main/java/com/xly/erp/module/mod/mapper/ModuleMapper.java
| ... | ... | @@ -13,4 +13,7 @@ public interface ModuleMapper extends BaseMapper<Module> { |
| 13 | 13 | default boolean existsActiveById(Integer iIncrement) { |
| 14 | 14 | return findActiveFlagById(iIncrement) != null; |
| 15 | 15 | } |
| 16 | + | |
| 17 | + @Select("SELECT iParentId FROM tModule WHERE iIncrement = #{id} AND bDeleted = 0") | |
| 18 | + Integer selectParentIdById(@Param("id") Integer iIncrement); | |
| 16 | 19 | } | ... | ... |
backend/src/test/java/com/xly/erp/module/mod/mapper/ModuleMapperIT.java
| ... | ... | @@ -60,6 +60,24 @@ class ModuleMapperIT { |
| 60 | 60 | assertThat(moduleMapper.existsActiveById(99999999)).isFalse(); |
| 61 | 61 | } |
| 62 | 62 | |
| 63 | + @Test | |
| 64 | + void selectParentIdById_returnsNullForRootOrMissing_andValueForChild() { | |
| 65 | + Module root = newModule("sp_test_root", "根", null); | |
| 66 | + moduleMapper.insert(root); | |
| 67 | + | |
| 68 | + Module child = newModule("sp_test_child", "子", root.getIIncrement()); | |
| 69 | + moduleMapper.insert(child); | |
| 70 | + | |
| 71 | + Module deleted = newModule("sp_test_del", "删", root.getIIncrement()); | |
| 72 | + deleted.setBDeleted(true); | |
| 73 | + moduleMapper.insert(deleted); | |
| 74 | + | |
| 75 | + assertThat(moduleMapper.selectParentIdById(root.getIIncrement())).isNull(); | |
| 76 | + assertThat(moduleMapper.selectParentIdById(child.getIIncrement())).isEqualTo(root.getIIncrement()); | |
| 77 | + assertThat(moduleMapper.selectParentIdById(deleted.getIIncrement())).isNull(); | |
| 78 | + assertThat(moduleMapper.selectParentIdById(99999998)).isNull(); | |
| 79 | + } | |
| 80 | + | |
| 63 | 81 | private Module newModule(String procedureName, String nameZh, Integer parentId) { |
| 64 | 82 | Module m = new Module(); |
| 65 | 83 | m.setSBrandsId("XLY"); | ... | ... |