【代码评审】Bpm:更多设置-摘要设置
This commit is contained in:
parent
d11684c2ae
commit
9d9351d066
|
@ -1,14 +1,24 @@
|
|||
package cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model;
|
||||
package cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.form;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 流程表单字段 VO
|
||||
*/
|
||||
@Data
|
||||
public class BpmFormFieldVO {
|
||||
|
||||
/**
|
||||
* 字段类型
|
||||
*/
|
||||
private String type;
|
||||
|
||||
/**
|
||||
* 字段标识
|
||||
*/
|
||||
private String field;
|
||||
|
||||
/**
|
||||
* 字段标题
|
||||
*/
|
||||
private String title;
|
||||
|
||||
}
|
|
@ -20,6 +20,9 @@ public class BpmProcessInstanceRespVO {
|
|||
@Schema(description = "流程名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋道")
|
||||
private String name;
|
||||
|
||||
@Schema(description = "流程摘要")
|
||||
private List<KeyValue<String, String>> summary; // 只有流程表单,才有摘要!
|
||||
|
||||
@Schema(description = "流程分类", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
|
||||
private String category;
|
||||
@Schema(description = "流程分类名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "请假")
|
||||
|
@ -60,8 +63,6 @@ public class BpmProcessInstanceRespVO {
|
|||
*/
|
||||
private List<Task> tasks; // 仅在流程实例分页才返回
|
||||
|
||||
private List<KeyValue<String, String>> summary;
|
||||
|
||||
@Schema(description = "流程任务")
|
||||
@Data
|
||||
public static class Task {
|
||||
|
|
|
@ -85,8 +85,9 @@ public class BpmTaskRespVO {
|
|||
@Schema(description = "是否填写审批意见", example = "false")
|
||||
private Boolean reasonRequire;
|
||||
|
||||
@Schema(description = "摘要", example = "[]")
|
||||
private List<KeyValue<String, String>> summary;
|
||||
// TODO @lesan:要不放到 processInstance 里面?因为摘要是流程实例的,不是流程任务的
|
||||
@Schema(description = "流程摘要", example = "[]")
|
||||
private List<KeyValue<String, String>> summary; // 只有流程表单,才有摘要!
|
||||
|
||||
@Data
|
||||
@Schema(description = "流程实例")
|
||||
|
|
|
@ -2,7 +2,6 @@ package cn.iocoder.yudao.module.bpm.convert.task;
|
|||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.iocoder.yudao.framework.common.core.KeyValue;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.common.util.collection.MapUtils;
|
||||
import cn.iocoder.yudao.framework.common.util.collection.SetUtils;
|
||||
|
|
|
@ -6,7 +6,7 @@ import cn.iocoder.yudao.framework.common.core.KeyValue;
|
|||
import cn.iocoder.yudao.framework.common.util.json.JsonUtils;
|
||||
import cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder;
|
||||
import cn.iocoder.yudao.framework.tenant.core.util.TenantUtils;
|
||||
import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model.BpmFormFieldVO;
|
||||
import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.form.BpmFormFieldVO;
|
||||
import cn.iocoder.yudao.module.bpm.dal.dataobject.definition.BpmProcessDefinitionInfoDO;
|
||||
import cn.iocoder.yudao.module.bpm.enums.definition.BpmModelFormTypeEnum;
|
||||
import cn.iocoder.yudao.module.bpm.framework.flowable.core.enums.BpmnVariableConstants;
|
||||
|
@ -193,6 +193,68 @@ public class FlowableUtils {
|
|||
BpmnVariableConstants.PROCESS_INSTANCE_VARIABLE_START_USER_SELECT_ASSIGNEES);
|
||||
}
|
||||
|
||||
// TODO @lesan:如果值是 null 的情况,可能要调研下飞书、钉钉,是不是不返回哈!
|
||||
/**
|
||||
* 获得流程实例的摘要
|
||||
*
|
||||
* 仅有 {@link BpmModelFormTypeEnum#getType()} 表单,才有摘要。
|
||||
* 原因是,只有它才有表单项的配置,从而可以根据配置,展示摘要。
|
||||
*
|
||||
* @param processDefinitionInfo 流程定义
|
||||
* @param processVariables 流程实例的 variables
|
||||
* @return 摘要
|
||||
*/
|
||||
public static List<KeyValue<String, String>> getSummary(BpmProcessDefinitionInfoDO processDefinitionInfo,
|
||||
Map<String, Object> processVariables) {
|
||||
// TODO @lesan:建议 if return,减少 { 层级
|
||||
if (ObjectUtil.isNotNull(processDefinitionInfo)
|
||||
&& BpmModelFormTypeEnum.NORMAL.getType().equals(processDefinitionInfo.getFormType())) {
|
||||
List<KeyValue<String, String>> summaryList = new ArrayList<>();
|
||||
// TODO @lesan:可以使用 CollUtils.convertMap 简化工作量哈。
|
||||
Map<String, BpmFormFieldVO> formFieldsMap = new HashMap<>();
|
||||
processDefinitionInfo.getFormFields().forEach(formFieldStr -> {
|
||||
BpmFormFieldVO formField = JsonUtils.parseObject(formFieldStr, BpmFormFieldVO.class);
|
||||
if (formField != null) {
|
||||
formFieldsMap.put(formField.getField(), formField);
|
||||
}
|
||||
});
|
||||
|
||||
// TODO @lesan:这里也可以 if return,还是为了减少括号哈。这样,就可以写注释,情况一:;情况二:
|
||||
if (ObjectUtil.isNotNull(processDefinitionInfo.getSummarySetting())
|
||||
&& Boolean.TRUE.equals(processDefinitionInfo.getSummarySetting().getEnable())) {
|
||||
// TODO @lesan:这里,也可以通过 CollUtils.convertList 简化哈。
|
||||
for (String item : processDefinitionInfo.getSummarySetting().getSummary()) {
|
||||
BpmFormFieldVO formField = formFieldsMap.get(item);
|
||||
if (formField != null) {
|
||||
summaryList.add(new KeyValue<>(formField.getTitle(),
|
||||
processVariables.getOrDefault(item, "").toString()));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// 默认展示前三个
|
||||
/* TODO @lesan:stream 简化
|
||||
* summaryList.addAll(formFieldsMap.entrySet().stream()
|
||||
* .limit(3)
|
||||
* .map(entry -> new KeyValue<>(entry.getValue().getTitle(),
|
||||
* processVariables.getOrDefault(entry.getValue().getField(), "").toString()))
|
||||
* .collect(Collectors.toList()));
|
||||
*/
|
||||
int j = 0;
|
||||
for (Map.Entry<String, BpmFormFieldVO> entry : formFieldsMap.entrySet()) {
|
||||
BpmFormFieldVO formField = entry.getValue();
|
||||
if (j > 2) {
|
||||
break;
|
||||
}
|
||||
summaryList.add(new KeyValue<>(formField.getTitle(),
|
||||
processVariables.getOrDefault(formField.getField(), "").toString()));
|
||||
j++;
|
||||
}
|
||||
}
|
||||
return summaryList;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
// ========== Task 相关的工具方法 ==========
|
||||
|
||||
/**
|
||||
|
@ -279,43 +341,4 @@ public class FlowableUtils {
|
|||
return getExpressionValue(variableContainer, expressionString);
|
||||
}
|
||||
|
||||
public static List<KeyValue<String, String>> getSummary(BpmProcessDefinitionInfoDO processDefinitionInfo,
|
||||
Map<String, Object> processVariables) {
|
||||
if (ObjectUtil.isNotNull(processDefinitionInfo)
|
||||
&& BpmModelFormTypeEnum.NORMAL.getType().equals(processDefinitionInfo.getFormType())) {
|
||||
List<KeyValue<String, String>> summaryList = new ArrayList<>();
|
||||
Map<String, BpmFormFieldVO> formFieldsMap = new HashMap<>();
|
||||
processDefinitionInfo.getFormFields().forEach(formFieldStr -> {
|
||||
BpmFormFieldVO formField = JsonUtils.parseObject(formFieldStr, BpmFormFieldVO.class);
|
||||
if (formField != null) {
|
||||
formFieldsMap.put(formField.getField(), formField);
|
||||
}
|
||||
});
|
||||
if (ObjectUtil.isNotNull(processDefinitionInfo.getSummarySetting())
|
||||
&& Boolean.TRUE.equals(processDefinitionInfo.getSummarySetting().getEnable())) {
|
||||
for (String item : processDefinitionInfo.getSummarySetting().getSummary()) {
|
||||
BpmFormFieldVO formField = formFieldsMap.get(item);
|
||||
if (formField != null) {
|
||||
summaryList.add(new KeyValue<>(formField.getTitle(),
|
||||
processVariables.getOrDefault(item, "").toString()));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// 默认展示前三个
|
||||
int j = 0;
|
||||
for (Map.Entry<String, BpmFormFieldVO> entry : formFieldsMap.entrySet()) {
|
||||
BpmFormFieldVO formField = entry.getValue();
|
||||
if (j > 2) {
|
||||
break;
|
||||
}
|
||||
summaryList.add(new KeyValue<>(formField.getTitle(),
|
||||
processVariables.getOrDefault(formField.getField(), "").toString()));
|
||||
j++;
|
||||
}
|
||||
}
|
||||
return summaryList;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue