Commit ff23f866c95d60bc3ce696daef9563cd98c519d9

Authored by YunaiV
1 parent 30e4f0c0

【功能新增】工作流:流程分类增加批量修改 sort 接口

yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/controller/admin/definition/BpmCategoryController.java
... ... @@ -48,6 +48,15 @@ public class BpmCategoryController {
48 48 return success(true);
49 49 }
50 50  
  51 + @PutMapping("/update-sort-batch")
  52 + @Operation(summary = "批量更新流程分类的排序")
  53 + @Parameter(name = "ids", description = "分类编号列表", required = true, example = "1,2,3")
  54 + @PreAuthorize("@ss.hasPermission('bpm:category:update')")
  55 + public CommonResult<Boolean> updateCategorySortBatch(@RequestParam("ids") List<Long> ids) {
  56 + categoryService.updateCategorySortBatch(ids);
  57 + return success(true);
  58 + }
  59 +
51 60 @DeleteMapping("/delete")
52 61 @Operation(summary = "删除流程分类")
53 62 @Parameter(name = "id", description = "编号", required = true)
... ...
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/service/definition/BpmCategoryService.java
... ... @@ -82,4 +82,11 @@ public interface BpmCategoryService {
82 82 */
83 83 List<BpmCategoryDO> getCategoryListByStatus(Integer status);
84 84  
  85 + /**
  86 + * 更新流程分类的排序:每个分类的 sort 值,从 0 开始递增
  87 + *
  88 + * @param ids 分类编号列表
  89 + */
  90 + void updateCategorySortBatch(List<Long> ids);
  91 +
85 92 }
86 93 \ No newline at end of file
... ...
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/service/definition/BpmCategoryServiceImpl.java
... ... @@ -2,21 +2,22 @@ package cn.iocoder.yudao.module.bpm.service.definition;
2 2  
3 3 import cn.hutool.core.collection.CollUtil;
4 4 import cn.hutool.core.util.ObjUtil;
  5 +import cn.iocoder.yudao.framework.common.pojo.PageResult;
  6 +import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
5 7 import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.category.BpmCategoryPageReqVO;
6 8 import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.category.BpmCategorySaveReqVO;
7   -import org.springframework.stereotype.Service;
8   -import jakarta.annotation.Resource;
9   -import org.springframework.validation.annotation.Validated;
10   -
11 9 import cn.iocoder.yudao.module.bpm.dal.dataobject.definition.BpmCategoryDO;
12   -import cn.iocoder.yudao.framework.common.pojo.PageResult;
13   -import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
14   -
15 10 import cn.iocoder.yudao.module.bpm.dal.mysql.category.BpmCategoryMapper;
  11 +import jakarta.annotation.Resource;
  12 +import org.springframework.stereotype.Service;
  13 +import org.springframework.transaction.annotation.Transactional;
  14 +import org.springframework.validation.annotation.Validated;
16 15  
17 16 import java.util.Collection;
18 17 import java.util.Collections;
19 18 import java.util.List;
  19 +import java.util.stream.Collectors;
  20 +import java.util.stream.IntStream;
20 21  
21 22 import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
22 23 import static cn.iocoder.yudao.module.bpm.enums.ErrorCodeConstants.*;
... ... @@ -58,7 +59,7 @@ public class BpmCategoryServiceImpl implements BpmCategoryService {
58 59 private void validateCategoryNameUnique(BpmCategorySaveReqVO updateReqVO) {
59 60 BpmCategoryDO category = bpmCategoryMapper.selectByName(updateReqVO.getName());
60 61 if (category == null
61   - || ObjUtil.equal(category.getId(), updateReqVO.getId())) {
  62 + || ObjUtil.equal(category.getId(), updateReqVO.getId())) {
62 63 return;
63 64 }
64 65 throw exception(CATEGORY_NAME_DUPLICATE, updateReqVO.getName());
... ... @@ -67,7 +68,7 @@ public class BpmCategoryServiceImpl implements BpmCategoryService {
67 68 private void validateCategoryCodeUnique(BpmCategorySaveReqVO updateReqVO) {
68 69 BpmCategoryDO category = bpmCategoryMapper.selectByCode(updateReqVO.getCode());
69 70 if (category == null
70   - || ObjUtil.equal(category.getId(), updateReqVO.getId())) {
  71 + || ObjUtil.equal(category.getId(), updateReqVO.getId())) {
71 72 return;
72 73 }
73 74 throw exception(CATEGORY_CODE_DUPLICATE, updateReqVO.getCode());
... ... @@ -110,4 +111,20 @@ public class BpmCategoryServiceImpl implements BpmCategoryService {
110 111 return bpmCategoryMapper.selectListByStatus(status);
111 112 }
112 113  
  114 + @Override
  115 + @Transactional(rollbackFor = Exception.class)
  116 + public void updateCategorySortBatch(List<Long> ids) {
  117 + // 校验分类都存在
  118 + List<BpmCategoryDO> categories = bpmCategoryMapper.selectByIds(ids);
  119 + if (categories.size() != ids.size()) {
  120 + throw exception(CATEGORY_NOT_EXISTS);
  121 + }
  122 +
  123 + // 批量更新排序
  124 + List<BpmCategoryDO> updateList = IntStream.range(0, ids.size())
  125 + .mapToObj(index -> new BpmCategoryDO().setId(ids.get(index)).setSort(index))
  126 + .collect(Collectors.toList());
  127 + bpmCategoryMapper.updateBatch(updateList);
  128 + }
  129 +
113 130 }
114 131 \ No newline at end of file
... ...