Commit 3aac40a51e6dcdd449e4ea5d0418ca837de5a2da
1 parent
d36c0dce
fix:【BPM 工作流】流程模型分类删除时,额外校验是否被流程模型所使用。
Showing
4 changed files
with
30 additions
and
3 deletions
yudao-module-bpm/src/main/java/cn/iocoder/yudao/module/bpm/enums/ErrorCodeConstants.java
| @@ -74,6 +74,7 @@ public interface ErrorCodeConstants { | @@ -74,6 +74,7 @@ public interface ErrorCodeConstants { | ||
| 74 | ErrorCode CATEGORY_NOT_EXISTS = new ErrorCode(1_009_012_000, "流程分类不存在"); | 74 | ErrorCode CATEGORY_NOT_EXISTS = new ErrorCode(1_009_012_000, "流程分类不存在"); |
| 75 | ErrorCode CATEGORY_NAME_DUPLICATE = new ErrorCode(1_009_012_001, "流程分类名字【{}】重复"); | 75 | ErrorCode CATEGORY_NAME_DUPLICATE = new ErrorCode(1_009_012_001, "流程分类名字【{}】重复"); |
| 76 | ErrorCode CATEGORY_CODE_DUPLICATE = new ErrorCode(1_009_012_002, "流程分类编码【{}】重复"); | 76 | ErrorCode CATEGORY_CODE_DUPLICATE = new ErrorCode(1_009_012_002, "流程分类编码【{}】重复"); |
| 77 | + ErrorCode CATEGORY_DELETE_FAIL_MODEL_USED = new ErrorCode(1_009_012_003, "删除失败,流程分类【{}】已被流程模型使用,请先删除对应的流程模型"); | ||
| 77 | 78 | ||
| 78 | // ========== BPM 流程监听器 1-009-013-000 ========== | 79 | // ========== BPM 流程监听器 1-009-013-000 ========== |
| 79 | ErrorCode PROCESS_LISTENER_NOT_EXISTS = new ErrorCode(1_009_013_000, "流程监听器不存在"); | 80 | ErrorCode PROCESS_LISTENER_NOT_EXISTS = new ErrorCode(1_009_013_000, "流程监听器不存在"); |
yudao-module-bpm/src/main/java/cn/iocoder/yudao/module/bpm/service/definition/BpmCategoryServiceImpl.java
| @@ -34,6 +34,9 @@ public class BpmCategoryServiceImpl implements BpmCategoryService { | @@ -34,6 +34,9 @@ public class BpmCategoryServiceImpl implements BpmCategoryService { | ||
| 34 | @Resource | 34 | @Resource |
| 35 | private BpmCategoryMapper bpmCategoryMapper; | 35 | private BpmCategoryMapper bpmCategoryMapper; |
| 36 | 36 | ||
| 37 | + @Resource | ||
| 38 | + private BpmModelService modelService; | ||
| 39 | + | ||
| 37 | @Override | 40 | @Override |
| 38 | public Long createCategory(BpmCategorySaveReqVO createReqVO) { | 41 | public Long createCategory(BpmCategorySaveReqVO createReqVO) { |
| 39 | // 校验唯一 | 42 | // 校验唯一 |
| @@ -77,15 +80,22 @@ public class BpmCategoryServiceImpl implements BpmCategoryService { | @@ -77,15 +80,22 @@ public class BpmCategoryServiceImpl implements BpmCategoryService { | ||
| 77 | @Override | 80 | @Override |
| 78 | public void deleteCategory(Long id) { | 81 | public void deleteCategory(Long id) { |
| 79 | // 校验存在 | 82 | // 校验存在 |
| 80 | - validateCategoryExists(id); | 83 | + BpmCategoryDO category = validateCategoryExists(id); |
| 84 | + // 校验是否被流程模型使用 | ||
| 85 | + Long count = modelService.getModelCountByCategory(category.getCode()); | ||
| 86 | + if (count > 0) { | ||
| 87 | + throw exception(CATEGORY_DELETE_FAIL_MODEL_USED, category.getName()); | ||
| 88 | + } | ||
| 81 | // 删除 | 89 | // 删除 |
| 82 | bpmCategoryMapper.deleteById(id); | 90 | bpmCategoryMapper.deleteById(id); |
| 83 | } | 91 | } |
| 84 | 92 | ||
| 85 | - private void validateCategoryExists(Long id) { | ||
| 86 | - if (bpmCategoryMapper.selectById(id) == null) { | 93 | + private BpmCategoryDO validateCategoryExists(Long id) { |
| 94 | + BpmCategoryDO category = bpmCategoryMapper.selectById(id); | ||
| 95 | + if (category == null) { | ||
| 87 | throw exception(CATEGORY_NOT_EXISTS); | 96 | throw exception(CATEGORY_NOT_EXISTS); |
| 88 | } | 97 | } |
| 98 | + return category; | ||
| 89 | } | 99 | } |
| 90 | 100 | ||
| 91 | @Override | 101 | @Override |
yudao-module-bpm/src/main/java/cn/iocoder/yudao/module/bpm/service/definition/BpmModelService.java
| @@ -25,6 +25,14 @@ public interface BpmModelService { | @@ -25,6 +25,14 @@ public interface BpmModelService { | ||
| 25 | List<Model> getModelList(String name); | 25 | List<Model> getModelList(String name); |
| 26 | 26 | ||
| 27 | /** | 27 | /** |
| 28 | + * 根据分类编码获得流程模型数量 | ||
| 29 | + * | ||
| 30 | + * @param category 分类编码 | ||
| 31 | + * @return 流程模型数量 | ||
| 32 | + */ | ||
| 33 | + Long getModelCountByCategory(String category); | ||
| 34 | + | ||
| 35 | + /** | ||
| 28 | * 创建流程模型 | 36 | * 创建流程模型 |
| 29 | * | 37 | * |
| 30 | * @param modelVO 创建信息 | 38 | * @param modelVO 创建信息 |
yudao-module-bpm/src/main/java/cn/iocoder/yudao/module/bpm/service/definition/BpmModelServiceImpl.java
| @@ -89,6 +89,14 @@ public class BpmModelServiceImpl implements BpmModelService { | @@ -89,6 +89,14 @@ public class BpmModelServiceImpl implements BpmModelService { | ||
| 89 | } | 89 | } |
| 90 | 90 | ||
| 91 | @Override | 91 | @Override |
| 92 | + public Long getModelCountByCategory(String category) { | ||
| 93 | + return repositoryService.createModelQuery() | ||
| 94 | + .modelCategory(category) | ||
| 95 | + .modelTenantId(FlowableUtils.getTenantId()) | ||
| 96 | + .count(); | ||
| 97 | + } | ||
| 98 | + | ||
| 99 | + @Override | ||
| 92 | @Transactional(rollbackFor = Exception.class) | 100 | @Transactional(rollbackFor = Exception.class) |
| 93 | public String createModel(@Valid BpmModelSaveReqVO createReqVO) { | 101 | public String createModel(@Valid BpmModelSaveReqVO createReqVO) { |
| 94 | if (!ValidationUtils.isXmlNCName(createReqVO.getKey())) { | 102 | if (!ValidationUtils.isXmlNCName(createReqVO.getKey())) { |