Commit 0ef8467546ed18c60d13833fc431dd55e3e7ceda
1 parent
f60a4dfa
feat: 摘要设置代码评审修改
Showing
3 changed files
with
38 additions
and
52 deletions
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/controller/admin/task/vo/task/BpmTaskRespVO.java
| @@ -85,10 +85,6 @@ public class BpmTaskRespVO { | @@ -85,10 +85,6 @@ public class BpmTaskRespVO { | ||
| 85 | @Schema(description = "是否填写审批意见", example = "false") | 85 | @Schema(description = "是否填写审批意见", example = "false") |
| 86 | private Boolean reasonRequire; | 86 | private Boolean reasonRequire; |
| 87 | 87 | ||
| 88 | - // TODO @lesan:要不放到 processInstance 里面?因为摘要是流程实例的,不是流程任务的 | ||
| 89 | - @Schema(description = "流程摘要", example = "[]") | ||
| 90 | - private List<KeyValue<String, String>> summary; // 只有流程表单,才有摘要! | ||
| 91 | - | ||
| 92 | @Data | 88 | @Data |
| 93 | @Schema(description = "流程实例") | 89 | @Schema(description = "流程实例") |
| 94 | public static class ProcessInstance { | 90 | public static class ProcessInstance { |
| @@ -105,6 +101,9 @@ public class BpmTaskRespVO { | @@ -105,6 +101,9 @@ public class BpmTaskRespVO { | ||
| 105 | @Schema(description = "流程定义的编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "2048") | 101 | @Schema(description = "流程定义的编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "2048") |
| 106 | private String processDefinitionId; | 102 | private String processDefinitionId; |
| 107 | 103 | ||
| 104 | + @Schema(description = "流程摘要", example = "[]") | ||
| 105 | + private List<KeyValue<String, String>> summary; // 只有流程表单,才有摘要! | ||
| 106 | + | ||
| 108 | /** | 107 | /** |
| 109 | * 发起人的用户信息 | 108 | * 发起人的用户信息 |
| 110 | */ | 109 | */ |
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/convert/task/BpmTaskConvert.java
| @@ -54,7 +54,7 @@ public interface BpmTaskConvert { | @@ -54,7 +54,7 @@ public interface BpmTaskConvert { | ||
| 54 | AdminUserRespDTO startUser = userMap.get(NumberUtils.parseLong(processInstance.getStartUserId())); | 54 | AdminUserRespDTO startUser = userMap.get(NumberUtils.parseLong(processInstance.getStartUserId())); |
| 55 | taskVO.getProcessInstance().setStartUser(BeanUtils.toBean(startUser, UserSimpleBaseVO.class)); | 55 | taskVO.getProcessInstance().setStartUser(BeanUtils.toBean(startUser, UserSimpleBaseVO.class)); |
| 56 | // 摘要 | 56 | // 摘要 |
| 57 | - taskVO.setSummary(FlowableUtils.getSummary(processDefinitionInfoMap.get(processInstance.getProcessDefinitionId()), | 57 | + taskVO.getProcessInstance().setSummary(FlowableUtils.getSummary(processDefinitionInfoMap.get(processInstance.getProcessDefinitionId()), |
| 58 | processInstance.getProcessVariables())); | 58 | processInstance.getProcessVariables())); |
| 59 | }); | 59 | }); |
| 60 | } | 60 | } |
| @@ -80,7 +80,7 @@ public interface BpmTaskConvert { | @@ -80,7 +80,7 @@ public interface BpmTaskConvert { | ||
| 80 | taskVO.setProcessInstance(BeanUtils.toBean(processInstance, BpmTaskRespVO.ProcessInstance.class)); | 80 | taskVO.setProcessInstance(BeanUtils.toBean(processInstance, BpmTaskRespVO.ProcessInstance.class)); |
| 81 | taskVO.getProcessInstance().setStartUser(BeanUtils.toBean(startUser, UserSimpleBaseVO.class)); | 81 | taskVO.getProcessInstance().setStartUser(BeanUtils.toBean(startUser, UserSimpleBaseVO.class)); |
| 82 | // 摘要 | 82 | // 摘要 |
| 83 | - taskVO.setSummary(FlowableUtils.getSummary(processDefinitionInfoMap.get(processInstance.getProcessDefinitionId()), | 83 | + taskVO.getProcessInstance().setSummary(FlowableUtils.getSummary(processDefinitionInfoMap.get(processInstance.getProcessDefinitionId()), |
| 84 | processInstance.getProcessVariables())); | 84 | processInstance.getProcessVariables())); |
| 85 | } | 85 | } |
| 86 | return taskVO; | 86 | return taskVO; |
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/framework/flowable/core/util/FlowableUtils.java
| @@ -27,6 +27,8 @@ import org.flowable.task.api.TaskInfo; | @@ -27,6 +27,8 @@ import org.flowable.task.api.TaskInfo; | ||
| 27 | import java.util.*; | 27 | import java.util.*; |
| 28 | import java.util.concurrent.Callable; | 28 | import java.util.concurrent.Callable; |
| 29 | 29 | ||
| 30 | +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList; | ||
| 31 | + | ||
| 30 | /** | 32 | /** |
| 31 | * Flowable 相关的工具方法 | 33 | * Flowable 相关的工具方法 |
| 32 | * | 34 | * |
| @@ -193,7 +195,6 @@ public class FlowableUtils { | @@ -193,7 +195,6 @@ public class FlowableUtils { | ||
| 193 | BpmnVariableConstants.PROCESS_INSTANCE_VARIABLE_START_USER_SELECT_ASSIGNEES); | 195 | BpmnVariableConstants.PROCESS_INSTANCE_VARIABLE_START_USER_SELECT_ASSIGNEES); |
| 194 | } | 196 | } |
| 195 | 197 | ||
| 196 | - // TODO @lesan:如果值是 null 的情况,可能要调研下飞书、钉钉,是不是不返回哈! | ||
| 197 | /** | 198 | /** |
| 198 | * 获得流程实例的摘要 | 199 | * 获得流程实例的摘要 |
| 199 | * | 200 | * |
| @@ -206,53 +207,39 @@ public class FlowableUtils { | @@ -206,53 +207,39 @@ public class FlowableUtils { | ||
| 206 | */ | 207 | */ |
| 207 | public static List<KeyValue<String, String>> getSummary(BpmProcessDefinitionInfoDO processDefinitionInfo, | 208 | public static List<KeyValue<String, String>> getSummary(BpmProcessDefinitionInfoDO processDefinitionInfo, |
| 208 | Map<String, Object> processVariables) { | 209 | 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); | 210 | + // 只有流程表单才会显示摘要! |
| 211 | + if (ObjectUtil.isNull(processDefinitionInfo) | ||
| 212 | + || !BpmModelFormTypeEnum.NORMAL.getType().equals(processDefinitionInfo.getFormType())) { | ||
| 213 | + return null; | ||
| 214 | + } | ||
| 215 | + List<KeyValue<String, String>> summaryList; | ||
| 216 | + Map<String, BpmFormFieldVO> formFieldsMap = new HashMap<>(); | ||
| 217 | + processDefinitionInfo.getFormFields().forEach(formFieldStr -> { | ||
| 218 | + BpmFormFieldVO formField = JsonUtils.parseObject(formFieldStr, BpmFormFieldVO.class); | ||
| 219 | + if (formField != null) { | ||
| 220 | + formFieldsMap.put(formField.getField(), formField); | ||
| 221 | + } | ||
| 222 | + }); | ||
| 223 | + if (ObjectUtil.isNotNull(processDefinitionInfo.getSummarySetting()) | ||
| 224 | + && Boolean.TRUE.equals(processDefinitionInfo.getSummarySetting().getEnable())) { | ||
| 225 | + // 情况一:当自定义了摘要 | ||
| 226 | + summaryList = convertList(processDefinitionInfo.getSummarySetting().getSummary(), item -> { | ||
| 227 | + BpmFormFieldVO formField = formFieldsMap.get(item); | ||
| 217 | if (formField != null) { | 228 | if (formField != null) { |
| 218 | - formFieldsMap.put(formField.getField(), formField); | 229 | + return new KeyValue<String, String>(formField.getTitle(), |
| 230 | + processVariables.getOrDefault(item, "").toString()); | ||
| 219 | } | 231 | } |
| 232 | + return null; | ||
| 220 | }); | 233 | }); |
| 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; | 234 | + } else { |
| 235 | + // 情况二:默认摘要展示前三个表单字段 | ||
| 236 | + summaryList = new ArrayList<>(formFieldsMap.entrySet().stream() | ||
| 237 | + .limit(3) | ||
| 238 | + .map(entry -> new KeyValue<>(entry.getValue().getTitle(), | ||
| 239 | + processVariables.getOrDefault(entry.getValue().getField(), "").toString())) | ||
| 240 | + .toList()); | ||
| 254 | } | 241 | } |
| 255 | - return null; | 242 | + return summaryList; |
| 256 | } | 243 | } |
| 257 | 244 | ||
| 258 | // ========== Task 相关的工具方法 ========== | 245 | // ========== Task 相关的工具方法 ========== |
| @@ -317,9 +304,9 @@ public class FlowableUtils { | @@ -317,9 +304,9 @@ public class FlowableUtils { | ||
| 317 | 304 | ||
| 318 | private static Object getExpressionValue(VariableContainer variableContainer, String expressionString, | 305 | private static Object getExpressionValue(VariableContainer variableContainer, String expressionString, |
| 319 | ProcessEngineConfigurationImpl processEngineConfiguration) { | 306 | ProcessEngineConfigurationImpl processEngineConfiguration) { |
| 320 | - assert processEngineConfiguration!= null; | 307 | + assert processEngineConfiguration != null; |
| 321 | ExpressionManager expressionManager = processEngineConfiguration.getExpressionManager(); | 308 | ExpressionManager expressionManager = processEngineConfiguration.getExpressionManager(); |
| 322 | - assert expressionManager!= null; | 309 | + assert expressionManager != null; |
| 323 | Expression expression = expressionManager.createExpression(expressionString); | 310 | Expression expression = expressionManager.createExpression(expressionString); |
| 324 | return expression.getValue(variableContainer); | 311 | return expression.getValue(variableContainer); |
| 325 | } | 312 | } |