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

This commit is contained in:
YunaiV 2024-11-02 16:58:17 +08:00
parent 30e4f0c09c
commit ff23f866c9
3 changed files with 43 additions and 10 deletions

View File

@ -48,6 +48,15 @@ public class BpmCategoryController {
return success(true);
}
@PutMapping("/update-sort-batch")
@Operation(summary = "批量更新流程分类的排序")
@Parameter(name = "ids", description = "分类编号列表", required = true, example = "1,2,3")
@PreAuthorize("@ss.hasPermission('bpm:category:update')")
public CommonResult<Boolean> updateCategorySortBatch(@RequestParam("ids") List<Long> ids) {
categoryService.updateCategorySortBatch(ids);
return success(true);
}
@DeleteMapping("/delete")
@Operation(summary = "删除流程分类")
@Parameter(name = "id", description = "编号", required = true)

View File

@ -82,4 +82,11 @@ public interface BpmCategoryService {
*/
List<BpmCategoryDO> getCategoryListByStatus(Integer status);
/**
* 更新流程分类的排序每个分类的 sort 0 开始递增
*
* @param ids 分类编号列表
*/
void updateCategorySortBatch(List<Long> ids);
}

View File

@ -2,21 +2,22 @@ package cn.iocoder.yudao.module.bpm.service.definition;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.ObjUtil;
import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.category.BpmCategoryPageReqVO;
import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.category.BpmCategorySaveReqVO;
import org.springframework.stereotype.Service;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import cn.iocoder.yudao.module.bpm.dal.dataobject.definition.BpmCategoryDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.category.BpmCategoryPageReqVO;
import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.category.BpmCategorySaveReqVO;
import cn.iocoder.yudao.module.bpm.dal.dataobject.definition.BpmCategoryDO;
import cn.iocoder.yudao.module.bpm.dal.mysql.category.BpmCategoryMapper;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.bpm.enums.ErrorCodeConstants.*;
@ -58,7 +59,7 @@ public class BpmCategoryServiceImpl implements BpmCategoryService {
private void validateCategoryNameUnique(BpmCategorySaveReqVO updateReqVO) {
BpmCategoryDO category = bpmCategoryMapper.selectByName(updateReqVO.getName());
if (category == null
|| ObjUtil.equal(category.getId(), updateReqVO.getId())) {
|| ObjUtil.equal(category.getId(), updateReqVO.getId())) {
return;
}
throw exception(CATEGORY_NAME_DUPLICATE, updateReqVO.getName());
@ -67,7 +68,7 @@ public class BpmCategoryServiceImpl implements BpmCategoryService {
private void validateCategoryCodeUnique(BpmCategorySaveReqVO updateReqVO) {
BpmCategoryDO category = bpmCategoryMapper.selectByCode(updateReqVO.getCode());
if (category == null
|| ObjUtil.equal(category.getId(), updateReqVO.getId())) {
|| ObjUtil.equal(category.getId(), updateReqVO.getId())) {
return;
}
throw exception(CATEGORY_CODE_DUPLICATE, updateReqVO.getCode());
@ -110,4 +111,20 @@ public class BpmCategoryServiceImpl implements BpmCategoryService {
return bpmCategoryMapper.selectListByStatus(status);
}
@Override
@Transactional(rollbackFor = Exception.class)
public void updateCategorySortBatch(List<Long> ids) {
// 校验分类都存在
List<BpmCategoryDO> categories = bpmCategoryMapper.selectByIds(ids);
if (categories.size() != ids.size()) {
throw exception(CATEGORY_NOT_EXISTS);
}
// 批量更新排序
List<BpmCategoryDO> updateList = IntStream.range(0, ids.size())
.mapToObj(index -> new BpmCategoryDO().setId(ids.get(index)).setSort(index))
.collect(Collectors.toList());
bpmCategoryMapper.updateBatch(updateList);
}
}