Commit 9d9351d066a856f11b9f580bc770b8fc5f95e618
1 parent
d11684c2
【代码评审】Bpm:更多设置-摘要设置
Showing
5 changed files
with
82 additions
and
48 deletions
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/controller/admin/definition/vo/model/BpmFormFieldVO.java renamed to yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/controller/admin/definition/vo/form/BpmFormFieldVO.java
| 1 | -package cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model; | |
| 1 | +package cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.form; | |
| 2 | 2 | |
| 3 | 3 | import lombok.Data; |
| 4 | 4 | |
| 5 | +/** | |
| 6 | + * 流程表单字段 VO | |
| 7 | + */ | |
| 5 | 8 | @Data |
| 6 | 9 | public class BpmFormFieldVO { |
| 7 | 10 | |
| 11 | + /** | |
| 12 | + * 字段类型 | |
| 13 | + */ | |
| 8 | 14 | private String type; |
| 9 | - | |
| 15 | + /** | |
| 16 | + * 字段标识 | |
| 17 | + */ | |
| 10 | 18 | private String field; |
| 11 | - | |
| 19 | + /** | |
| 20 | + * 字段标题 | |
| 21 | + */ | |
| 12 | 22 | private String title; |
| 13 | 23 | |
| 14 | 24 | } | ... | ... |
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/controller/admin/task/vo/instance/BpmProcessInstanceRespVO.java
| ... | ... | @@ -20,6 +20,9 @@ public class BpmProcessInstanceRespVO { |
| 20 | 20 | @Schema(description = "流程名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋道") |
| 21 | 21 | private String name; |
| 22 | 22 | |
| 23 | + @Schema(description = "流程摘要") | |
| 24 | + private List<KeyValue<String, String>> summary; // 只有流程表单,才有摘要! | |
| 25 | + | |
| 23 | 26 | @Schema(description = "流程分类", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") |
| 24 | 27 | private String category; |
| 25 | 28 | @Schema(description = "流程分类名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "请假") |
| ... | ... | @@ -60,8 +63,6 @@ public class BpmProcessInstanceRespVO { |
| 60 | 63 | */ |
| 61 | 64 | private List<Task> tasks; // 仅在流程实例分页才返回 |
| 62 | 65 | |
| 63 | - private List<KeyValue<String, String>> summary; | |
| 64 | - | |
| 65 | 66 | @Schema(description = "流程任务") |
| 66 | 67 | @Data |
| 67 | 68 | public static class Task { | ... | ... |
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/controller/admin/task/vo/task/BpmTaskRespVO.java
| ... | ... | @@ -85,8 +85,9 @@ public class BpmTaskRespVO { |
| 85 | 85 | @Schema(description = "是否填写审批意见", example = "false") |
| 86 | 86 | private Boolean reasonRequire; |
| 87 | 87 | |
| 88 | - @Schema(description = "摘要", example = "[]") | |
| 89 | - private List<KeyValue<String, String>> summary; | |
| 88 | + // TODO @lesan:要不放到 processInstance 里面?因为摘要是流程实例的,不是流程任务的 | |
| 89 | + @Schema(description = "流程摘要", example = "[]") | |
| 90 | + private List<KeyValue<String, String>> summary; // 只有流程表单,才有摘要! | |
| 90 | 91 | |
| 91 | 92 | @Data |
| 92 | 93 | @Schema(description = "流程实例") | ... | ... |
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/convert/task/BpmProcessInstanceConvert.java
| ... | ... | @@ -2,7 +2,6 @@ package cn.iocoder.yudao.module.bpm.convert.task; |
| 2 | 2 | |
| 3 | 3 | import cn.hutool.core.collection.CollUtil; |
| 4 | 4 | import cn.hutool.core.util.StrUtil; |
| 5 | -import cn.iocoder.yudao.framework.common.core.KeyValue; | |
| 6 | 5 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 7 | 6 | import cn.iocoder.yudao.framework.common.util.collection.MapUtils; |
| 8 | 7 | import cn.iocoder.yudao.framework.common.util.collection.SetUtils; | ... | ... |
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/framework/flowable/core/util/FlowableUtils.java
| ... | ... | @@ -6,7 +6,7 @@ import cn.iocoder.yudao.framework.common.core.KeyValue; |
| 6 | 6 | import cn.iocoder.yudao.framework.common.util.json.JsonUtils; |
| 7 | 7 | import cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder; |
| 8 | 8 | import cn.iocoder.yudao.framework.tenant.core.util.TenantUtils; |
| 9 | -import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model.BpmFormFieldVO; | |
| 9 | +import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.form.BpmFormFieldVO; | |
| 10 | 10 | import cn.iocoder.yudao.module.bpm.dal.dataobject.definition.BpmProcessDefinitionInfoDO; |
| 11 | 11 | import cn.iocoder.yudao.module.bpm.enums.definition.BpmModelFormTypeEnum; |
| 12 | 12 | import cn.iocoder.yudao.module.bpm.framework.flowable.core.enums.BpmnVariableConstants; |
| ... | ... | @@ -193,6 +193,68 @@ public class FlowableUtils { |
| 193 | 193 | BpmnVariableConstants.PROCESS_INSTANCE_VARIABLE_START_USER_SELECT_ASSIGNEES); |
| 194 | 194 | } |
| 195 | 195 | |
| 196 | + // TODO @lesan:如果值是 null 的情况,可能要调研下飞书、钉钉,是不是不返回哈! | |
| 197 | + /** | |
| 198 | + * 获得流程实例的摘要 | |
| 199 | + * | |
| 200 | + * 仅有 {@link BpmModelFormTypeEnum#getType()} 表单,才有摘要。 | |
| 201 | + * 原因是,只有它才有表单项的配置,从而可以根据配置,展示摘要。 | |
| 202 | + * | |
| 203 | + * @param processDefinitionInfo 流程定义 | |
| 204 | + * @param processVariables 流程实例的 variables | |
| 205 | + * @return 摘要 | |
| 206 | + */ | |
| 207 | + public static List<KeyValue<String, String>> getSummary(BpmProcessDefinitionInfoDO processDefinitionInfo, | |
| 208 | + Map<String, Object> processVariables) { | |
| 209 | + // TODO @lesan:建议 if return,减少 { 层级 | |
| 210 | + if (ObjectUtil.isNotNull(processDefinitionInfo) | |
| 211 | + && BpmModelFormTypeEnum.NORMAL.getType().equals(processDefinitionInfo.getFormType())) { | |
| 212 | + List<KeyValue<String, String>> summaryList = new ArrayList<>(); | |
| 213 | + // TODO @lesan:可以使用 CollUtils.convertMap 简化工作量哈。 | |
| 214 | + Map<String, BpmFormFieldVO> formFieldsMap = new HashMap<>(); | |
| 215 | + processDefinitionInfo.getFormFields().forEach(formFieldStr -> { | |
| 216 | + BpmFormFieldVO formField = JsonUtils.parseObject(formFieldStr, BpmFormFieldVO.class); | |
| 217 | + if (formField != null) { | |
| 218 | + formFieldsMap.put(formField.getField(), formField); | |
| 219 | + } | |
| 220 | + }); | |
| 221 | + | |
| 222 | + // TODO @lesan:这里也可以 if return,还是为了减少括号哈。这样,就可以写注释,情况一:;情况二: | |
| 223 | + if (ObjectUtil.isNotNull(processDefinitionInfo.getSummarySetting()) | |
| 224 | + && Boolean.TRUE.equals(processDefinitionInfo.getSummarySetting().getEnable())) { | |
| 225 | + // TODO @lesan:这里,也可以通过 CollUtils.convertList 简化哈。 | |
| 226 | + for (String item : processDefinitionInfo.getSummarySetting().getSummary()) { | |
| 227 | + BpmFormFieldVO formField = formFieldsMap.get(item); | |
| 228 | + if (formField != null) { | |
| 229 | + summaryList.add(new KeyValue<>(formField.getTitle(), | |
| 230 | + processVariables.getOrDefault(item, "").toString())); | |
| 231 | + } | |
| 232 | + } | |
| 233 | + } else { | |
| 234 | + // 默认展示前三个 | |
| 235 | + /* TODO @lesan:stream 简化 | |
| 236 | + * summaryList.addAll(formFieldsMap.entrySet().stream() | |
| 237 | + * .limit(3) | |
| 238 | + * .map(entry -> new KeyValue<>(entry.getValue().getTitle(), | |
| 239 | + * processVariables.getOrDefault(entry.getValue().getField(), "").toString())) | |
| 240 | + * .collect(Collectors.toList())); | |
| 241 | + */ | |
| 242 | + int j = 0; | |
| 243 | + for (Map.Entry<String, BpmFormFieldVO> entry : formFieldsMap.entrySet()) { | |
| 244 | + BpmFormFieldVO formField = entry.getValue(); | |
| 245 | + if (j > 2) { | |
| 246 | + break; | |
| 247 | + } | |
| 248 | + summaryList.add(new KeyValue<>(formField.getTitle(), | |
| 249 | + processVariables.getOrDefault(formField.getField(), "").toString())); | |
| 250 | + j++; | |
| 251 | + } | |
| 252 | + } | |
| 253 | + return summaryList; | |
| 254 | + } | |
| 255 | + return null; | |
| 256 | + } | |
| 257 | + | |
| 196 | 258 | // ========== Task 相关的工具方法 ========== |
| 197 | 259 | |
| 198 | 260 | /** |
| ... | ... | @@ -279,43 +341,4 @@ public class FlowableUtils { |
| 279 | 341 | return getExpressionValue(variableContainer, expressionString); |
| 280 | 342 | } |
| 281 | 343 | |
| 282 | - public static List<KeyValue<String, String>> getSummary(BpmProcessDefinitionInfoDO processDefinitionInfo, | |
| 283 | - Map<String, Object> processVariables) { | |
| 284 | - if (ObjectUtil.isNotNull(processDefinitionInfo) | |
| 285 | - && BpmModelFormTypeEnum.NORMAL.getType().equals(processDefinitionInfo.getFormType())) { | |
| 286 | - List<KeyValue<String, String>> summaryList = new ArrayList<>(); | |
| 287 | - Map<String, BpmFormFieldVO> formFieldsMap = new HashMap<>(); | |
| 288 | - processDefinitionInfo.getFormFields().forEach(formFieldStr -> { | |
| 289 | - BpmFormFieldVO formField = JsonUtils.parseObject(formFieldStr, BpmFormFieldVO.class); | |
| 290 | - if (formField != null) { | |
| 291 | - formFieldsMap.put(formField.getField(), formField); | |
| 292 | - } | |
| 293 | - }); | |
| 294 | - if (ObjectUtil.isNotNull(processDefinitionInfo.getSummarySetting()) | |
| 295 | - && Boolean.TRUE.equals(processDefinitionInfo.getSummarySetting().getEnable())) { | |
| 296 | - for (String item : processDefinitionInfo.getSummarySetting().getSummary()) { | |
| 297 | - BpmFormFieldVO formField = formFieldsMap.get(item); | |
| 298 | - if (formField != null) { | |
| 299 | - summaryList.add(new KeyValue<>(formField.getTitle(), | |
| 300 | - processVariables.getOrDefault(item, "").toString())); | |
| 301 | - } | |
| 302 | - } | |
| 303 | - } else { | |
| 304 | - // 默认展示前三个 | |
| 305 | - int j = 0; | |
| 306 | - for (Map.Entry<String, BpmFormFieldVO> entry : formFieldsMap.entrySet()) { | |
| 307 | - BpmFormFieldVO formField = entry.getValue(); | |
| 308 | - if (j > 2) { | |
| 309 | - break; | |
| 310 | - } | |
| 311 | - summaryList.add(new KeyValue<>(formField.getTitle(), | |
| 312 | - processVariables.getOrDefault(formField.getField(), "").toString())); | |
| 313 | - j++; | |
| 314 | - } | |
| 315 | - } | |
| 316 | - return summaryList; | |
| 317 | - } | |
| 318 | - return null; | |
| 319 | - } | |
| 320 | - | |
| 321 | 344 | } | ... | ... |