Commit b8957829d2c8c6c37d8aabdbabc95573efab64b7
1 parent
c9162362
feat(mod): mapper#hasActiveChildren for delete check REQ-MOD-003
Showing
2 changed files
with
26 additions
and
0 deletions
backend/src/main/java/com/xly/erp/module/mod/mapper/ModuleMapper.java
| ... | ... | @@ -16,4 +16,11 @@ public interface ModuleMapper extends BaseMapper<Module> { |
| 16 | 16 | |
| 17 | 17 | @Select("SELECT iParentId FROM tModule WHERE iIncrement = #{id} AND bDeleted = 0") |
| 18 | 18 | Integer selectParentIdById(@Param("id") Integer iIncrement); |
| 19 | + | |
| 20 | + @Select("SELECT 1 FROM tModule WHERE iParentId = #{parentId} AND bDeleted = 0 LIMIT 1") | |
| 21 | + Integer findActiveChildFlag(@Param("parentId") Integer parentId); | |
| 22 | + | |
| 23 | + default boolean hasActiveChildren(Integer parentId) { | |
| 24 | + return findActiveChildFlag(parentId) != null; | |
| 25 | + } | |
| 19 | 26 | } | ... | ... |
backend/src/test/java/com/xly/erp/module/mod/mapper/ModuleMapperIT.java
| ... | ... | @@ -78,6 +78,25 @@ class ModuleMapperIT { |
| 78 | 78 | assertThat(moduleMapper.selectParentIdById(99999998)).isNull(); |
| 79 | 79 | } |
| 80 | 80 | |
| 81 | + @Test | |
| 82 | + void hasActiveChildren_trueIfChildAliveExists_falseOtherwise() { | |
| 83 | + Module root = newModule("sp_test_hac_root", "根", null); | |
| 84 | + moduleMapper.insert(root); | |
| 85 | + | |
| 86 | + Module child1 = newModule("sp_test_hac_alive", "存活子", root.getIIncrement()); | |
| 87 | + moduleMapper.insert(child1); | |
| 88 | + | |
| 89 | + Module child2 = newModule("sp_test_hac_dead", "已删子", root.getIIncrement()); | |
| 90 | + child2.setBDeleted(true); | |
| 91 | + moduleMapper.insert(child2); | |
| 92 | + | |
| 93 | + assertThat(moduleMapper.hasActiveChildren(root.getIIncrement())).isTrue(); | |
| 94 | + assertThat(moduleMapper.hasActiveChildren(99999996)).isFalse(); | |
| 95 | + | |
| 96 | + jdbcTemplate.update("UPDATE tModule SET bDeleted = 1 WHERE iIncrement = ?", child1.getIIncrement()); | |
| 97 | + assertThat(moduleMapper.hasActiveChildren(root.getIIncrement())).isFalse(); | |
| 98 | + } | |
| 99 | + | |
| 81 | 100 | private Module newModule(String procedureName, String nameZh, Integer parentId) { |
| 82 | 101 | Module m = new Module(); |
| 83 | 102 | m.setSBrandsId("XLY"); | ... | ... |