Commit 30e4f0c09c5e53409f4ef2c9e363c819b3fc4dc7

Authored by YunaiV
1 parent a122253a

【功能实现】工作流:流程模型,增加 sort 字段的返回(不包括修改)

yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/controller/admin/definition/BpmModelController.java
... ... @@ -2,8 +2,6 @@ package cn.iocoder.yudao.module.bpm.controller.admin.definition;
2 2  
3 3 import cn.hutool.core.collection.CollUtil;
4 4 import cn.iocoder.yudao.framework.common.pojo.CommonResult;
5   -import cn.iocoder.yudao.framework.common.pojo.PageResult;
6   -import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
7 5 import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model.*;
8 6 import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model.simple.BpmSimpleModelNodeVO;
9 7 import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model.simple.BpmSimpleModelUpdateReqVO;
... ... @@ -28,10 +26,7 @@ import org.springframework.security.access.prepost.PreAuthorize;
28 26 import org.springframework.validation.annotation.Validated;
29 27 import org.springframework.web.bind.annotation.*;
30 28  
31   -import java.util.HashSet;
32   -import java.util.List;
33   -import java.util.Map;
34   -import java.util.Set;
  29 +import java.util.*;
35 30 import java.util.stream.Stream;
36 31  
37 32 import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
... ... @@ -56,38 +51,38 @@ public class BpmModelController {
56 51 @Resource
57 52 private AdminUserApi adminUserApi;
58 53  
59   - @GetMapping("/page")
  54 + @GetMapping("/list")
60 55 @Operation(summary = "获得模型分页")
61   - public CommonResult<PageResult<BpmModelRespVO>> getModelPage(BpmModelPageReqVO pageVO) {
62   - PageResult<Model> pageResult = modelService.getModelPage(pageVO);
63   - if (CollUtil.isEmpty(pageResult.getList())) {
64   - return success(PageResult.empty(pageResult.getTotal()));
  56 + @Parameter(name = "name", description = "模型名称", example = "芋艿")
  57 + public CommonResult<List<BpmModelRespVO>> getModelPage(@RequestParam(value = "name", required = false) String name) {
  58 + List<Model> list = modelService.getModelList(name);
  59 + if (CollUtil.isEmpty(list)) {
  60 + return success(Collections.emptyList());
65 61 }
66 62  
67   - // 拼接数据
68 63 // 获得 Form 表单
69   - Set<Long> formIds = convertSet(pageResult.getList(), model -> {
  64 + Set<Long> formIds = convertSet(list, model -> {
70 65 BpmModelMetaInfoVO metaInfo = BpmModelConvert.INSTANCE.parseMetaInfo(model);
71 66 return metaInfo != null ? metaInfo.getFormId() : null;
72 67 });
73 68 Map<Long, BpmFormDO> formMap = formService.getFormMap(formIds);
74 69 // 获得 Category Map
75 70 Map<String, BpmCategoryDO> categoryMap = categoryService.getCategoryMap(
76   - convertSet(pageResult.getList(), Model::getCategory));
  71 + convertSet(list, Model::getCategory));
77 72 // 获得 Deployment Map
78   - Set<String> deploymentIds = new HashSet<>();
79   - pageResult.getList().forEach(model -> CollectionUtils.addIfNotNull(deploymentIds, model.getDeploymentId()));
80   - Map<String, Deployment> deploymentMap = processDefinitionService.getDeploymentMap(deploymentIds);
  73 + Map<String, Deployment> deploymentMap = processDefinitionService.getDeploymentMap(
  74 + convertSet(list, Model::getDeploymentId));
81 75 // 获得 ProcessDefinition Map
82   - List<ProcessDefinition> processDefinitions = processDefinitionService.getProcessDefinitionListByDeploymentIds(deploymentIds);
  76 + List<ProcessDefinition> processDefinitions = processDefinitionService.getProcessDefinitionListByDeploymentIds(
  77 + deploymentMap.keySet());
83 78 Map<String, ProcessDefinition> processDefinitionMap = convertMap(processDefinitions, ProcessDefinition::getDeploymentId);
84 79 // 获得 User Map
85   - Set<Long> userIds = convertSetByFlatMap(pageResult.getList(), model -> {
  80 + Set<Long> userIds = convertSetByFlatMap(list, model -> {
86 81 BpmModelMetaInfoVO metaInfo = BpmModelConvert.INSTANCE.parseMetaInfo(model);
87 82 return metaInfo != null ? metaInfo.getStartUserIds().stream() : Stream.empty();
88 83 });
89 84 Map<Long, AdminUserRespDTO> userMap = adminUserApi.getUserMap(userIds);
90   - return success(BpmModelConvert.INSTANCE.buildModelPage(pageResult,
  85 + return success(BpmModelConvert.INSTANCE.buildModelList(list,
91 86 formMap, categoryMap, deploymentMap, processDefinitionMap, userMap));
92 87 }
93 88  
... ...
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/controller/admin/definition/vo/model/BpmModelMetaInfoVO.java
... ... @@ -15,7 +15,9 @@ import java.util.List;
15 15 * BPM 流程 MetaInfo Response DTO
16 16 * 主要用于 { Model#setMetaInfo(String)} 的存储
17 17 *
18   - * 最终,它的字段和 {@link cn.iocoder.yudao.module.bpm.dal.dataobject.definition.BpmProcessDefinitionInfoDO} 是一致的
  18 + * 最终,它的字段和
  19 + * {@link cn.iocoder.yudao.module.bpm.dal.dataobject.definition.BpmProcessDefinitionInfoDO}
  20 + * 是一致的
19 21 *
20 22 * @author 芋道源码
21 23 */
... ... @@ -40,13 +42,11 @@ public class BpmModelMetaInfoVO {
40 42 @NotNull(message = "表单类型不能为空")
41 43 private Integer formType;
42 44 @Schema(description = "表单编号", example = "1024")
43   - private Long formId; // formType 为 NORMAL 使用,必须非空
44   - @Schema(description = "自定义表单的提交路径,使用 Vue 的路由地址",
45   - example = "/bpm/oa/leave/create")
46   - private String formCustomCreatePath; // 表单类型为 CUSTOM 时,必须非空
47   - @Schema(description = "自定义表单的查看路径,使用 Vue 的路由地址",
48   - example = "/bpm/oa/leave/view")
49   - private String formCustomViewPath; // 表单类型为 CUSTOM 时,必须非空
  45 + private Long formId; // formType 为 NORMAL 使用,必须非空
  46 + @Schema(description = "自定义表单的提交路径,使用 Vue 的路由地址", example = "/bpm/oa/leave/create")
  47 + private String formCustomCreatePath; // 表单类型为 CUSTOM 时,必须非空
  48 + @Schema(description = "自定义表单的查看路径,使用 Vue 的路由地址", example = "/bpm/oa/leave/view")
  49 + private String formCustomViewPath; // 表单类型为 CUSTOM 时,必须非空
50 50  
51 51 @Schema(description = "是否可见", requiredMode = Schema.RequiredMode.REQUIRED, example = "true")
52 52 @NotNull(message = "是否可见不能为空")
... ... @@ -59,4 +59,7 @@ public class BpmModelMetaInfoVO {
59 59 @NotEmpty(message = "可管理用户编号数组不能为空")
60 60 private List<Long> managerUserIds;
61 61  
  62 + @Schema(description = "排序", example = "1")
  63 + private Long sort; // 创建时,后端自动生成
  64 +
62 65 }
... ...
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/controller/admin/definition/vo/model/BpmModelPageReqVO.java deleted
1   -package cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model;
2   -
3   -import cn.iocoder.yudao.framework.common.pojo.PageParam;
4   -import io.swagger.v3.oas.annotations.media.Schema;
5   -import lombok.Data;
6   -import lombok.EqualsAndHashCode;
7   -import lombok.ToString;
8   -
9   -
10   -@Schema(description = "管理后台 - 流程模型分页 Request VO")
11   -@Data
12   -public class BpmModelPageReqVO extends PageParam {
13   -
14   - @Schema(description = "标识,精准匹配", example = "process1641042089407")
15   - private String key;
16   -
17   - @Schema(description = "名字,模糊匹配", example = "芋道")
18   - private String name;
19   -
20   - @Schema(description = "流程分类", example = "1")
21   - private String category;
22   -
23   -}
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/convert/definition/BpmModelConvert.java
1 1 package cn.iocoder.yudao.module.bpm.convert.definition;
2 2  
3 3 import cn.hutool.core.util.ArrayUtil;
4   -import cn.iocoder.yudao.framework.common.pojo.PageResult;
5 4 import cn.iocoder.yudao.framework.common.util.date.DateUtils;
6 5 import cn.iocoder.yudao.framework.common.util.json.JsonUtils;
7 6 import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
... ... @@ -22,6 +21,7 @@ import org.mapstruct.Mapper;
22 21 import org.mapstruct.factory.Mappers;
23 22  
24 23 import java.util.Collections;
  24 +import java.util.Comparator;
25 25 import java.util.List;
26 26 import java.util.Map;
27 27  
... ... @@ -37,25 +37,31 @@ public interface BpmModelConvert {
37 37  
38 38 BpmModelConvert INSTANCE = Mappers.getMapper(BpmModelConvert.class);
39 39  
40   - default PageResult<BpmModelRespVO> buildModelPage(PageResult<Model> pageResult,
41   - Map<Long, BpmFormDO> formMap,
42   - Map<String, BpmCategoryDO> categoryMap, Map<String, Deployment> deploymentMap,
43   - Map<String, ProcessDefinition> processDefinitionMap,
44   - Map<Long, AdminUserRespDTO> userMap) {
45   - List<BpmModelRespVO> list = convertList(pageResult.getList(), model -> {
  40 + default List<BpmModelRespVO> buildModelList(List<Model> list,
  41 + Map<Long, BpmFormDO> formMap,
  42 + Map<String, BpmCategoryDO> categoryMap,
  43 + Map<String, Deployment> deploymentMap,
  44 + Map<String, ProcessDefinition> processDefinitionMap,
  45 + Map<Long, AdminUserRespDTO> userMap) {
  46 + List<BpmModelRespVO> result = convertList(list, model -> {
46 47 BpmModelMetaInfoVO metaInfo = parseMetaInfo(model);
47 48 BpmFormDO form = metaInfo != null ? formMap.get(metaInfo.getFormId()) : null;
48 49 BpmCategoryDO category = categoryMap.get(model.getCategory());
49 50 Deployment deployment = model.getDeploymentId() != null ? deploymentMap.get(model.getDeploymentId()) : null;
50   - ProcessDefinition processDefinition = model.getDeploymentId() != null ? processDefinitionMap.get(model.getDeploymentId()) : null;
51   - List<AdminUserRespDTO> startUsers = metaInfo != null ? convertList(metaInfo.getStartUserIds(), userMap::get) : null;
  51 + ProcessDefinition processDefinition = model.getDeploymentId() != null
  52 + ? processDefinitionMap.get(model.getDeploymentId())
  53 + : null;
  54 + List<AdminUserRespDTO> startUsers = metaInfo != null ? convertList(metaInfo.getStartUserIds(), userMap::get)
  55 + : null;
52 56 return buildModel0(model, metaInfo, form, category, deployment, processDefinition, startUsers);
53 57 });
54   - return new PageResult<>(list, pageResult.getTotal());
  58 + // 排序
  59 + result.sort(Comparator.comparing(BpmModelMetaInfoVO::getSort));
  60 + return result;
55 61 }
56 62  
57 63 default BpmModelRespVO buildModel(Model model,
58   - byte[] bpmnBytes) {
  64 + byte[] bpmnBytes) {
59 65 BpmModelMetaInfoVO metaInfo = parseMetaInfo(model);
60 66 BpmModelRespVO modelVO = buildModel0(model, metaInfo, null, null, null, null, null);
61 67 if (ArrayUtil.isNotEmpty(bpmnBytes)) {
... ... @@ -65,9 +71,9 @@ public interface BpmModelConvert {
65 71 }
66 72  
67 73 default BpmModelRespVO buildModel0(Model model,
68   - BpmModelMetaInfoVO metaInfo, BpmFormDO form, BpmCategoryDO category,
69   - Deployment deployment, ProcessDefinition processDefinition,
70   - List<AdminUserRespDTO> startUsers) {
  74 + BpmModelMetaInfoVO metaInfo, BpmFormDO form, BpmCategoryDO category,
  75 + Deployment deployment, ProcessDefinition processDefinition,
  76 + List<AdminUserRespDTO> startUsers) {
71 77 BpmModelRespVO modelRespVO = new BpmModelRespVO().setId(model.getId()).setName(model.getName())
72 78 .setKey(model.getKey()).setCategory(model.getCategory())
73 79 .setCreateTime(DateUtils.of(model.getCreateTime()));
... ... @@ -83,8 +89,9 @@ public interface BpmModelConvert {
83 89 // ProcessDefinition
84 90 if (processDefinition != null) {
85 91 modelRespVO.setProcessDefinition(BeanUtils.toBean(processDefinition, BpmProcessDefinitionRespVO.class));
86   - modelRespVO.getProcessDefinition().setSuspensionState(processDefinition.isSuspended() ?
87   - SuspensionState.SUSPENDED.getStateCode() : SuspensionState.ACTIVE.getStateCode());
  92 + modelRespVO.getProcessDefinition()
  93 + .setSuspensionState(processDefinition.isSuspended() ? SuspensionState.SUSPENDED.getStateCode()
  94 + : SuspensionState.ACTIVE.getStateCode());
88 95 if (deployment != null) {
89 96 modelRespVO.getProcessDefinition().setDeploymentTime(DateUtils.of(deployment.getDeploymentTime()));
90 97 }
... ... @@ -112,6 +119,10 @@ public interface BpmModelConvert {
112 119 if (vo.getStartUserIds() == null) {
113 120 vo.setStartUserIds(Collections.emptyList());
114 121 }
  122 + // 如果为空,兜底处理,使用 createTime 创建时间
  123 + if (vo.getSort() == null) {
  124 + vo.setSort(model.getCreateTime().getTime());
  125 + }
115 126 return vo;
116 127 }
117 128  
... ...
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/service/definition/BpmModelService.java
1 1 package cn.iocoder.yudao.module.bpm.service.definition;
2 2  
3   -import cn.iocoder.yudao.framework.common.pojo.PageResult;
4   -import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model.BpmModelPageReqVO;
5 3 import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model.BpmModelSaveReqVO;
6 4 import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model.simple.BpmSimpleModelNodeVO;
7 5 import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model.simple.BpmSimpleModelUpdateReqVO;
... ... @@ -9,20 +7,22 @@ import jakarta.validation.Valid;
9 7 import org.flowable.bpmn.model.BpmnModel;
10 8 import org.flowable.engine.repository.Model;
11 9  
  10 +import java.util.List;
  11 +
12 12 /**
13   - * Flowable流程模型接口
  13 + * 流程模型接口
14 14 *
15 15 * @author yunlongn
16 16 */
17 17 public interface BpmModelService {
18 18  
19 19 /**
20   - * 获得流程模型分页
  20 + * 获得流程模型列表
21 21 *
22   - * @param pageVO 分页查询
23   - * @return 流程模型分页
  22 + * @param name 模型名称
  23 + * @return 流程模型列表
24 24 */
25   - PageResult<Model> getModelPage(BpmModelPageReqVO pageVO);
  25 + List<Model> getModelList(String name);
26 26  
27 27 /**
28 28 * 创建流程模型
... ...
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/service/definition/BpmModelServiceImpl.java
... ... @@ -3,12 +3,9 @@ package cn.iocoder.yudao.module.bpm.service.definition;
3 3 import cn.hutool.core.collection.CollUtil;
4 4 import cn.hutool.core.util.ArrayUtil;
5 5 import cn.hutool.core.util.StrUtil;
6   -import cn.iocoder.yudao.framework.common.pojo.PageResult;
7 6 import cn.iocoder.yudao.framework.common.util.json.JsonUtils;
8   -import cn.iocoder.yudao.framework.common.util.object.PageUtils;
9 7 import cn.iocoder.yudao.framework.common.util.validation.ValidationUtils;
10 8 import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model.BpmModelMetaInfoVO;
11   -import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model.BpmModelPageReqVO;
12 9 import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model.BpmModelSaveReqVO;
13 10 import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model.simple.BpmSimpleModelNodeVO;
14 11 import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model.simple.BpmSimpleModelUpdateReqVO;
... ... @@ -41,8 +38,7 @@ import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionU
41 38 import static cn.iocoder.yudao.module.bpm.enums.ErrorCodeConstants.*;
42 39  
43 40 /**
44   - * Flowable流程模型实现
45   - * 主要进行 Flowable {@link Model} 的维护
  41 + * 流程模型实现:主要进行 Flowable {@link Model} 的维护
46 42 *
47 43 * @author yunlongn
48 44 * @author 芋道源码
... ... @@ -64,27 +60,12 @@ public class BpmModelServiceImpl implements BpmModelService {
64 60 private BpmTaskCandidateInvoker taskCandidateInvoker;
65 61  
66 62 @Override
67   - public PageResult<Model> getModelPage(BpmModelPageReqVO pageVO) {
  63 + public List<Model> getModelList(String name) {
68 64 ModelQuery modelQuery = repositoryService.createModelQuery();
69   - modelQuery.modelTenantId(FlowableUtils.getTenantId());
70   - if (StrUtil.isNotBlank(pageVO.getKey())) {
71   - modelQuery.modelKey(pageVO.getKey());
  65 + if (StrUtil.isNotEmpty(name)) {
  66 + modelQuery.modelNameLike(name);
72 67 }
73   - if (StrUtil.isNotBlank(pageVO.getName())) {
74   - modelQuery.modelNameLike("%" + pageVO.getName() + "%"); // 模糊匹配
75   - }
76   - if (StrUtil.isNotBlank(pageVO.getCategory())) {
77   - modelQuery.modelCategory(pageVO.getCategory());
78   - }
79   - // 执行查询
80   - long count = modelQuery.count();
81   - if (count == 0) {
82   - return PageResult.empty(count);
83   - }
84   - List<Model> models = modelQuery
85   - .orderByCreateTime().desc()
86   - .listPage(PageUtils.getStart(pageVO), pageVO.getPageSize());
87   - return new PageResult<>(models, count);
  68 + return modelQuery.list();
88 69 }
89 70  
90 71 @Override
... ... @@ -100,6 +81,7 @@ public class BpmModelServiceImpl implements BpmModelService {
100 81 }
101 82  
102 83 // 2.1 创建流程定义
  84 + createReqVO.setSort(System.currentTimeMillis()); // 使用当前时间,作为排序
103 85 Model model = repositoryService.newModel();
104 86 BpmModelConvert.INSTANCE.copyToModel(model, createReqVO);
105 87 model.setTenantId(FlowableUtils.getTenantId());
... ...