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

This commit is contained in:
YunaiV 2024-11-02 18:11:21 +08:00
parent ff23f866c9
commit 73b68a10db
11 changed files with 86 additions and 6 deletions

View File

@ -23,7 +23,7 @@ public interface ErrorCodeConstants {
"原因:用户任务({})未配置审批人,请点击【流程设计】按钮,选择该它的【任务(审批人)】进行配置");
ErrorCode MODEL_DEPLOY_FAIL_BPMN_START_EVENT_NOT_EXISTS = new ErrorCode(1_009_002_005, "部署流程失败原因BPMN 流程图中,没有开始事件");
ErrorCode MODEL_DEPLOY_FAIL_BPMN_USER_TASK_NAME_NOT_EXISTS = new ErrorCode(1_009_002_006, "部署流程失败原因BPMN 流程图中,用户任务({})的名字不存在");
ErrorCode MODEL_UPDATE_FAIL_NOT_MANAGER = new ErrorCode(1_009_002_007, "操作流程失败,原因:你不是该流程的管理员");
ErrorCode MODEL_UPDATE_FAIL_NOT_MANAGER = new ErrorCode(1_009_002_007, "操作流程失败,原因:你不是该流程({})的管理员");
// ========== 流程定义 1-009-003-000 ==========
ErrorCode PROCESS_DEFINITION_KEY_NOT_MATCH = new ErrorCode(1_009_003_000, "流程定义的标识期望是({}),当前是({}),请修改 BPMN 流程图");

View File

@ -26,7 +26,10 @@ import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import java.util.*;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Stream;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
@ -106,6 +109,7 @@ public class BpmModelController {
return success(modelService.createModel(createRetVO));
}
@PutMapping("/update")
@Operation(summary = "修改模型")
@PreAuthorize("@ss.hasPermission('bpm:model:update')")
@ -114,6 +118,14 @@ public class BpmModelController {
return success(true);
}
@PutMapping("/update-sort-batch")
@Operation(summary = "批量修改模型排序")
@Parameter(name = "ids", description = "编号数组", required = true, example = "1,2,3")
public CommonResult<Boolean> updateModelSortBatch(@RequestParam("ids") List<String> ids) {
modelService.updateModelSortBatch(getLoginUserId(), ids);
return success(true);
}
@PostMapping("/deploy")
@Operation(summary = "部署模型")
@Parameter(name = "id", description = "编号", required = true, example = "1024")

View File

@ -62,6 +62,9 @@ public class BpmProcessDefinitionRespVO {
@Schema(description = "BPMN XML")
private String bpmnXml; // 需要从对应的 BpmnModel 读取非必须返回
@Schema(description = "流程定义排序", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
private Long sort;
@Schema(description = "发起用户需要选择审批人的任务数组")
private List<UserTask> startUserSelectTasks; // 需要从对应的 BpmnModel 读取非必须返回

View File

@ -20,6 +20,7 @@ import org.mapstruct.Mapping;
import org.mapstruct.MappingTarget;
import org.mapstruct.factory.Mappers;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
@ -47,7 +48,7 @@ public interface BpmProcessDefinitionConvert {
Map<String, BpmProcessDefinitionInfoDO> processDefinitionInfoMap,
Map<Long, BpmFormDO> formMap,
Map<String, BpmCategoryDO> categoryMap) {
return CollectionUtils.convertList(list, definition -> {
List<BpmProcessDefinitionRespVO> result = CollectionUtils.convertList(list, definition -> {
Deployment deployment = MapUtil.get(deploymentMap, definition.getDeploymentId(), Deployment.class);
BpmProcessDefinitionInfoDO processDefinitionInfo = MapUtil.get(processDefinitionInfoMap, definition.getId(), BpmProcessDefinitionInfoDO.class);
BpmFormDO form = null;
@ -57,6 +58,9 @@ public interface BpmProcessDefinitionConvert {
BpmCategoryDO category = MapUtil.get(categoryMap, definition.getCategory(), BpmCategoryDO.class);
return buildProcessDefinition(definition, deployment, processDefinitionInfo, form, category, null, null);
});
// 排序
result.sort(Comparator.comparing(BpmProcessDefinitionRespVO::getSort));
return result;
}
default BpmProcessDefinitionRespVO buildProcessDefinition(ProcessDefinition definition,

View File

@ -121,6 +121,10 @@ public class BpmProcessDefinitionInfoDO extends BaseDO {
* 目的如果 false 不可见则不展示在发起流程的列表里
*/
private Boolean visible;
/**
* 排序值
*/
private Long sort;
/**
* 可发起用户编号数组

View File

@ -1,5 +1,6 @@
package cn.iocoder.yudao.module.bpm.dal.mysql.definition;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.bpm.dal.dataobject.definition.BpmProcessDefinitionInfoDO;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import org.apache.ibatis.annotations.Mapper;
@ -18,4 +19,9 @@ public interface BpmProcessDefinitionInfoMapper extends BaseMapperX<BpmProcessDe
return selectOne(BpmProcessDefinitionInfoDO::getProcessDefinitionId, processDefinitionId);
}
default void updateByModelId(String modelId, BpmProcessDefinitionInfoDO updateObj) {
update(updateObj,
new LambdaQueryWrapperX<BpmProcessDefinitionInfoDO>().eq(BpmProcessDefinitionInfoDO::getModelId, modelId));
}
}

View File

@ -83,7 +83,7 @@ public interface BpmCategoryService {
List<BpmCategoryDO> getCategoryListByStatus(Integer status);
/**
* 更新流程分类的排序每个分类的 sort 0 开始递增
* 批量更新流程分类的排序每个分类的 sort 0 开始递增
*
* @param ids 分类编号列表
*/

View File

@ -64,6 +64,14 @@ public interface BpmModelService {
*/
void updateModel(Long userId, @Valid BpmModelSaveReqVO updateReqVO);
/**
* 批量更新模型排序
*
* @param userId 用户编号
* @param ids 编号列表
*/
void updateModelSortBatch(Long userId, List<String> ids);
/**
* 将流程模型部署成一个流程定义
*

View File

@ -32,9 +32,11 @@ import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertMap;
import static cn.iocoder.yudao.module.bpm.enums.ErrorCodeConstants.*;
/**
@ -102,6 +104,34 @@ public class BpmModelServiceImpl implements BpmModelService {
repositoryService.saveModel(model);
}
@Override
@Transactional(rollbackFor = Exception.class)
public void updateModelSortBatch(Long userId, List<String> ids) {
// 1.1 校验流程模型存在
List<Model> models = repositoryService.createModelQuery()
.modelTenantId(FlowableUtils.getTenantId()).list();
models.removeIf(model ->!ids.contains(model.getId()));
if (ids.size() != models.size()) {
throw exception(MODEL_NOT_EXISTS);
}
Map<String, Model> modelMap = convertMap(models, Model::getId);
// 1.2 校验是否为管理员
ids.forEach(id -> validateModelManager(id, userId));
// 保存排序
long sort = System.currentTimeMillis(); // 使用时间戳 - i 作为排序
for (int i = ids.size() - 1; i > 0; i--) {
Model model = modelMap.get(ids.get(i));
// 更新模型
BpmModelMetaInfoVO metaInfo = BpmModelConvert.INSTANCE.parseMetaInfo(model).setSort(sort);
model.setMetaInfo(JsonUtils.toJsonString(metaInfo));
repositoryService.saveModel(model);
// 更新排序
processDefinitionService.updateProcessDefinitionSortByModelId(model.getId(), sort);
sort--;
}
}
private Model validateModelExists(String id) {
Model model = repositoryService.getModel(id);
if (model == null) {
@ -121,7 +151,7 @@ public class BpmModelServiceImpl implements BpmModelService {
Model model = validateModelExists(id);
BpmModelMetaInfoVO metaInfo = BpmModelConvert.INSTANCE.parseMetaInfo(model);
if (metaInfo == null || !CollUtil.contains(metaInfo.getManagerUserIds(), userId)) {
throw exception(MODEL_UPDATE_FAIL_NOT_MANAGER);
throw exception(MODEL_UPDATE_FAIL_NOT_MANAGER, model.getName());
}
return model;
}

View File

@ -18,7 +18,7 @@ import java.util.Set;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertMap;
/**
* Flowable流程定义接口
* 流程定义接口
*
* @author yunlong.li
* @author ZJQ
@ -63,6 +63,14 @@ public interface BpmProcessDefinitionService {
*/
void updateProcessDefinitionState(String id, Integer state);
/**
* 更新模型编号
*
* @param modelId 流程定义编号
* @param sort 排序
*/
void updateProcessDefinitionSortByModelId(String modelId, Long sort);
/**
* 获得流程定义对应的 BPMN
*

View File

@ -172,6 +172,11 @@ public class BpmProcessDefinitionServiceImpl implements BpmProcessDefinitionServ
log.error("[updateProcessDefinitionState][流程定义({}) 修改未知状态({})]", id, state);
}
@Override
public void updateProcessDefinitionSortByModelId(String modelId, Long sort) {
processDefinitionMapper.updateByModelId(modelId, new BpmProcessDefinitionInfoDO().setSort(sort));
}
@Override
public BpmnModel getProcessDefinitionBpmnModel(String id) {
return repositoryService.getBpmnModel(id);