Compare commits

...

12 Commits

14 changed files with 240 additions and 18 deletions

View File

@ -23,6 +23,8 @@ public enum FormInstanceRespCode implements IModuleRespCode {
FORM_DATA_PARSE_ERROR_BY_IMAGE("008", "表单图片组件的数据解析异常"),
FORM_DATA_PARSE_ERROR_BY_CUSTOM_COMPONENT("009", "表单自定义组件的数据解析异常"),
FORM_DATA_PARSE_ERROR_BY_AMOUNT("010", "表单金额组件的数据解析异常"),
FORM_DATA_PARSE_ERROR_BY_CHECKBOX("011", "表单复选框组件的数据解析异常"),
FORM_DATA_PARSE_ERROR_BY_RADIO("012", "表单单选框组件的数据解析异常"),
;
private final String code;

View File

@ -46,6 +46,10 @@ public enum FormFieldTypeEnum {
}),
decimal("decimal", "小数", new TypeReference<Map<String, Object>>() {
}),
checkbox("checkbox", "复选框", new TypeReference<List<String>>() {
}),
radio("radio", "单选框", new TypeReference<String>() {
})
;
private final String type;

View File

@ -22,7 +22,7 @@ import java.util.Map;
public class FormFieldDTO {
/**
* 字段类型, 如果是分组:FormContainer,其他表单组件:FormField
* 字段类型, 如果是分组:FormContainer,单选复选组件OptionFormField,其他表单组件:FormField,
*/
@ApiModelProperty(value = "表单字段类型")
@NotBlank(message = "字段类型不能为空")
@ -41,6 +41,9 @@ public class FormFieldDTO {
* { label: "变洽签单", value: "changeSignatureOrder" },
* { label: "通讯录", value: "contacts" },
* { label: "金额", value: "amount" },
* { label: "复选", value: "checkbox" },
* { label: "单选", value: "radio" },
*
*/
@ApiModelProperty(value = "前端的组件类型")
private String type;
@ -76,6 +79,14 @@ public class FormFieldDTO {
@ApiModelProperty(value = "该表单字段的其他扩展属性,期望 JSON 格式")
private Map<String, Object> params;
/**
* 单选复选框的选项
* <p>
* {@see org.flowable.form.model.OptionFormField}
*/
@ApiModelProperty(value = "单选复选框的选项,配合 fieldType=OptionFormField 使用")
private List<OptionDTO> options;
/**
* fieldType=FormContainer ,这里的代表内部的集合
*/

View File

@ -0,0 +1,24 @@
package cn.axzo.workflow.common.model.request.form.definition;
import io.swagger.annotations.ApiModel;
import lombok.Data;
/**
* 单选复选框的选项入参模型
*
* @author wangli
* @since 2025-11-20 10:57
*/
@ApiModel("单选复选框的选项入参模型")
@Data
public class OptionDTO {
/**
* 选项 ID
*/
private String id;
/**
* 选项名称
*/
private String name;
}

View File

@ -0,0 +1,52 @@
package cn.axzo.workflow.core.engine.cmd;
import com.alibaba.fastjson.JSON;
import org.flowable.common.engine.impl.interceptor.CommandContext;
import org.flowable.engine.impl.util.CommandContextUtil;
import org.flowable.form.api.FormEngineConfigurationApi;
import org.flowable.form.api.FormInfo;
import org.flowable.form.api.FormInstance;
import org.flowable.form.api.FormRepositoryService;
import org.flowable.form.api.FormService;
import org.springframework.util.CollectionUtils;
import java.io.Serializable;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* 通过审批实例 ID 获取对应的表单定义实体的自定义命令
*
* @author wangli
* @since 2025-11-20 10:18
*/
public class CustomGetFormModelByProcessInstanceIdCmd extends AbstractCommand<FormInfo> implements Serializable {
private final String processInstanceId;
public CustomGetFormModelByProcessInstanceIdCmd(String processInstanceId) {
this.processInstanceId = processInstanceId;
}
@Override
public String paramToJsonString() {
Map<String, Object> params = new HashMap<>();
params.put("processInstanceId", processInstanceId);
return JSON.toJSONString(params);
}
@Override
public FormInfo executeInternal(CommandContext commandContext) {
FormEngineConfigurationApi formEngineConfiguration = CommandContextUtil.getFormEngineConfiguration(commandContext);
FormService formService = formEngineConfiguration.getFormService();
List<FormInstance> list = formService.createFormInstanceQuery().processInstanceId(processInstanceId).orderBySubmittedDate().desc().list();
if (CollectionUtils.isEmpty(list)) {
return null;
}
String formDefinitionId = list.get(0).getFormDefinitionId();
FormRepositoryService formRepositoryService = formEngineConfiguration.getFormRepositoryService();
return formRepositoryService.getFormModelById(formDefinitionId);
}
}

View File

@ -15,6 +15,7 @@ import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.google.common.collect.Lists;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.ListUtils;
import org.flowable.common.engine.api.FlowableObjectNotFoundException;
import org.flowable.common.engine.impl.interceptor.CommandContext;
import org.flowable.engine.HistoryService;
@ -27,6 +28,8 @@ import org.flowable.form.api.FormService;
import org.flowable.form.model.FormContainer;
import org.flowable.form.model.FormField;
import org.flowable.form.model.FormFieldTypes;
import org.flowable.form.model.Option;
import org.flowable.form.model.OptionFormField;
import org.flowable.form.model.SimpleFormModel;
import org.springframework.util.CollectionUtils;
import org.springframework.util.ObjectUtils;
@ -42,6 +45,8 @@ import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors;
import static cn.axzo.workflow.common.code.FormInstanceRespCode.FORM_DATA_PARSE_ERROR_BY_CHECKBOX;
import static cn.axzo.workflow.common.code.FormInstanceRespCode.FORM_DATA_PARSE_ERROR_BY_RADIO;
import static cn.axzo.workflow.common.code.FormModelRespCode.FORM_MODEL_NOT_EXISTS;
import static cn.axzo.workflow.common.constant.BpmnConstants.BPM_MODEL_CATEGORY;
import static cn.axzo.workflow.common.constant.BpmnConstants.INTERNAL_INITIATOR;
@ -75,7 +80,7 @@ public class CustomGetProcessInstanceVariablesToObjectCmd extends AbstractComman
private final String processInstanceId;
private final SimpleDateFormat sdf = new SimpleDateFormat("yyyy.MM.dd HH:mm:ss");
private static final List<String> SUPPORTED_FORM_TYPES = Lists.newArrayList("input", "date", "textarea", "image", "contacts", "amount", "decimal");
private static final List<String> SUPPORTED_FORM_TYPES = Lists.newArrayList("input", "date", "textarea", "image", "contacts", "amount", "decimal", "checkbox", "radio");
public CustomGetProcessInstanceVariablesToObjectCmd(String processInstanceId) {
this.processInstanceId = processInstanceId;
@ -219,6 +224,39 @@ public class CustomGetProcessInstanceVariablesToObjectCmd extends AbstractComman
.type(convert(field.getType()))
.build());
}
} else if (Objects.equals(field.getType(), "checkbox")) {
if (field instanceof OptionFormField) {
OptionFormField optionField = (OptionFormField) field;
if (StringUtils.hasText(fieldValue.toString())
&& fieldValue.toString().startsWith("[")
&& fieldValue.toString().endsWith("]")) {
List<String> selectedOptions = JSON.parseArray((String) fieldValue, String.class);
List<String> optionNames = ListUtils.emptyIfNull(optionField.getOptions()).stream().filter(i -> selectedOptions.contains(i.getId())).map(Option::getName).collect(Collectors.toList());
variables.add(VariableObjectDTO.builder()
.key(field.getId())
.desc(field.getName())
.value(StringUtils.collectionToDelimitedString(optionNames, ""))
.type(convert(field.getType()))
.build());
}
} else {
throw new WorkflowEngineException(FORM_DATA_PARSE_ERROR_BY_CHECKBOX);
}
} else if (Objects.equals(field.getType(), "radio")) {
if (field instanceof OptionFormField) {
OptionFormField optionField = (OptionFormField) field;
if (StringUtils.hasText(fieldValue.toString())) {
List<String> optionNames = ListUtils.emptyIfNull(optionField.getOptions()).stream().filter(i -> Objects.equals(fieldValue, i.getId())).map(Option::getName).collect(Collectors.toList());
variables.add(VariableObjectDTO.builder()
.key(field.getId())
.desc(field.getName())
.value(StringUtils.collectionToDelimitedString(optionNames, ""))
.type(convert(field.getType()))
.build());
}
} else {
throw new WorkflowEngineException(FORM_DATA_PARSE_ERROR_BY_RADIO);
}
} else {
variables.add(VariableObjectDTO.builder()
.key(field.getId())
@ -310,6 +348,8 @@ public class CustomGetProcessInstanceVariablesToObjectCmd extends AbstractComman
case "amount":
case "contacts":
case "decimal":
case "checkbox":
case "radio":
return VariableObjectDTO.Type.text;
case "image":
return VariableObjectDTO.Type.img;

View File

@ -1,10 +1,16 @@
package cn.axzo.workflow.core.listener;
import cn.axzo.workflow.common.constant.BpmnConstants;
import cn.axzo.workflow.core.common.context.OperationContext;
import cn.hutool.json.JSONUtil;
import org.slf4j.MDC;
import org.springframework.util.StringUtils;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import static cn.azxo.framework.common.constatns.Constants.CTX_LOG_ID_MDC;
/**
@ -43,4 +49,30 @@ public abstract class AbstractBpmnEventListener<T extends OperationContext> impl
}
return processDefinitionId.split(":")[0];
}
/**
* 移除一些业务不需要关心的变量
*
* @param originVariables
* @return
*/
public static Map<String, Object> removeBpmnConstantsVariables(Map<String, Object> originVariables) {
if (originVariables == null) return new HashMap<>();
// 定义需要移除的前缀列表
List<String> prefixesToRemove = Arrays.asList(
BpmnConstants.INTERNAL_TASK_RELATION_ASSIGNEE_INFO,
BpmnConstants.INTERNAL_ACTIVITY_RELATION_ASSIGNEE_LIST_INFO_SNAPSHOT,
BpmnConstants.TASK_COMPLETE_OPERATION_TYPE,
BpmnConstants.INTERNAL_TASK_RELATION_ASSIGNEE_LIST_INFO
);
return originVariables.entrySet().stream()
.filter(entry -> entry.getKey() != null)
// 核心修改检查 key 是否以任一前缀开头
.filter(entry -> prefixesToRemove.stream()
.noneMatch(prefix -> entry.getKey().startsWith(prefix)))
.collect(HashMap::new, (m, e) -> m.put(e.getKey(), e.getValue()), HashMap::putAll);
}
}

View File

@ -3,6 +3,7 @@ package cn.axzo.workflow.form.service.converter;
import cn.axzo.workflow.common.model.request.form.definition.FormFieldDTO;
import org.flowable.form.model.FormContainer;
import org.flowable.form.model.FormField;
import org.flowable.form.model.OptionFormField;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
@ -34,6 +35,16 @@ public interface FormFieldConverter extends EntityConverter<FormFieldDTO, FormFi
@Mapping(target = "params", source = "entity.params")
FormFieldDTO toVo(FormField entity);
@Mapping(target = "fieldType", expression = "java(entity.getClass().getSimpleName())")
@Mapping(target = "id", source = "entity.id")
@Mapping(target = "name", source = "entity.name")
@Mapping(target = "type", source = "entity.type")
@Mapping(target = "value", expression = "java(ConversionUtils.convertObject(entity.getValue()))")
@Mapping(target = "placeholder", source = "entity.placeholder")
@Mapping(target = "params", source = "entity.params")
@Mapping(target = "options", source = "entity.options")
FormFieldDTO toVo(OptionFormField entity);
@Mapping(target = "fieldType", expression = "java(entity.getClass().getSimpleName())")
@Mapping(target = "id", source = "entity.id")
@Mapping(target = "name", source = "entity.name")
@ -50,7 +61,9 @@ public interface FormFieldConverter extends EntityConverter<FormFieldDTO, FormFi
for (FormField entity : entities) {
if(entity instanceof FormContainer) {
dtos.add(toVo((FormContainer) entity));
} else{
} else if (entity instanceof OptionFormField) {
dtos.add(toVo((OptionFormField) entity));
} else {
dtos.add(toVo((FormField) entity));
}
}

View File

@ -1,15 +1,19 @@
package cn.axzo.workflow.form.service.converter;
import cn.axzo.workflow.common.model.request.form.definition.FormFieldDTO;
import cn.axzo.workflow.common.model.request.form.definition.OptionDTO;
import cn.axzo.workflow.common.model.response.form.instance.FormInstanceVO;
import cn.axzo.workflow.common.model.response.form.model.FormModelVO;
import org.flowable.form.api.FormInstanceInfo;
import org.flowable.form.api.FormModel;
import org.flowable.form.model.FormContainer;
import org.flowable.form.model.FormField;
import org.flowable.form.model.Option;
import org.flowable.form.model.OptionFormField;
import org.flowable.form.model.SimpleFormModel;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.springframework.util.CollectionUtils;
import java.util.Arrays;
import java.util.List;
@ -64,6 +68,11 @@ public interface FormInstanceConverter extends EntityConverter<FormInstanceVO, F
formFieldDTO.setValue(ConversionUtils.convertObject(formField.getValue()));
formFieldDTO.setPlaceholder(formField.getPlaceholder());
formFieldDTO.setParams(formField.getParams());
if (formField instanceof OptionFormField) {
OptionFormField optionFormField = (OptionFormField) formField;
formFieldDTO.setFieldType(optionFormField.getClass().getSimpleName());
formFieldDTO.setOptions(optionsToOptionDTOs(optionFormField.getOptions()));
}
if (formField instanceof FormContainer) {
FormContainer formContainer = (FormContainer) formField;
formFieldDTO.setFieldType(formContainer.getClass().getSimpleName());
@ -72,6 +81,19 @@ public interface FormInstanceConverter extends EntityConverter<FormInstanceVO, F
return formFieldDTO;
}
default List<OptionDTO> optionsToOptionDTOs(List<Option> options) {
if (CollectionUtils.isEmpty(options)) {
return null;
}
return options.stream()
.map(option -> {
OptionDTO optionDTO = new OptionDTO();
optionDTO.setId(option.getId());
optionDTO.setName(option.getName());
return optionDTO;
})
.collect(Collectors.toList());
}
// 辅助方法用于处理List<FormContainer>到List<FormFieldDTO>的转换调用上面自定义的转换方法
default List<FormFieldDTO> formContainersToFormFieldDTOs(List<FormField> formContainers) {

View File

@ -178,7 +178,7 @@ public class RocketMqBpmActivityEvent_100_Listener extends AbstractBpmnEventList
if (Objects.nonNull(processInstance)) {
dto.setProcessDefinitionKey(processInstance.getProcessDefinitionKey());
dto.setBusinessKey(processInstance.getBusinessKey());
dto.setVariables(processInstance.getProcessVariables());
dto.setVariables(removeBpmnConstantsVariables(processInstance.getProcessVariables()));
dto.setWorkflowEngineVersion(String.valueOf(processInstance.getProcessVariables()
.getOrDefault(WORKFLOW_ENGINE_VERSION, FLOW_SERVER_VERSION_121)));
} else {

View File

@ -26,7 +26,6 @@ import org.flowable.engine.HistoryService;
import org.flowable.engine.TaskService;
import org.flowable.engine.impl.util.CommandContextUtil;
import org.flowable.engine.impl.util.ProcessDefinitionUtil;
import org.flowable.task.api.Task;
import org.flowable.task.api.history.HistoricTaskInstance;
import org.flowable.task.service.impl.persistence.entity.TaskEntity;
import org.springframework.beans.factory.annotation.Value;
@ -451,7 +450,7 @@ public class RocketMqMessagePushEventListener extends AbstractBpmnEventListener<
.setTemplateId(templateId)
.setTaskId(event.getTaskId())
.setReceivePersons(event.getAssigners())
.setVariables(variables)
.setVariables(removeBpmnConstantsVariables(variables))
.setProcessApproveConf(event.getProcessApproveConfig())
.setActivitySignature(activitySignature)
.setTerminalType(terminalType);

View File

@ -81,7 +81,7 @@ public class RocketMqBpmnProcessEventListener extends AbstractBpmnEventListener<
.setProcessDefinitionKey(((ExecutionEntityImpl) event.getEntity()).getProcessDefinitionKey())
.setProcessDefinitionVersion(((ExecutionEntityImpl) event.getEntity()).getProcessDefinitionVersion())
.setInitiator(initiator)
.setVariables(((ExecutionEntityImpl) event.getEntity()).getVariables())
.setVariables(removeBpmnConstantsVariables(((ExecutionEntityImpl) event.getEntity()).getVariables()))
.setStartTime(((ExecutionEntityImpl) event.getEntity()).getStartTime())
.setTenantId(((ExecutionEntityImpl) event.getEntity()).getTenantId())
.setBusinessKey(((ExecutionEntityImpl) event.getEntity()).getBusinessKey())
@ -117,7 +117,7 @@ public class RocketMqBpmnProcessEventListener extends AbstractBpmnEventListener<
.setProcessDefinitionKey(((ExecutionEntityImpl) event.getEntity()).getProcessDefinitionKey())
.setProcessDefinitionVersion(((ExecutionEntityImpl) event.getEntity()).getProcessDefinitionVersion())
.setInitiator(initiator)
.setVariables(((ExecutionEntityImpl) event.getEntity()).getVariables())
.setVariables(removeBpmnConstantsVariables(((ExecutionEntityImpl) event.getEntity()).getVariables()))
.setStartTime(((ExecutionEntityImpl) event.getEntity()).getStartTime())
.setTenantId(((ExecutionEntityImpl) event.getEntity()).getTenantId())
.setBusinessKey(((ExecutionEntityImpl) event.getEntity()).getProcessInstance().getBusinessKey())
@ -151,7 +151,7 @@ public class RocketMqBpmnProcessEventListener extends AbstractBpmnEventListener<
.setInitiator(initiator)
.setLastOperationAssigner(getContext().getLastOperationAssigner(() -> BpmnTaskDelegateAssigner.toObjectCompatible(
runtimeService.getVariable(event.getProcessInstanceId(), CLOSE_PROCESS_ASSIGNER, BpmnTaskDelegateAssigner.class))))
.setVariables(((FlowableProcessCancelledEventImpl) event).getExecution().getVariables())
.setVariables(removeBpmnConstantsVariables(((FlowableProcessCancelledEventImpl) event).getExecution().getVariables()))
.setStartTime(((ExecutionEntityImpl) ((FlowableProcessCancelledEventImpl) event).getExecution()).getStartTime())
.setTenantId(((FlowableProcessCancelledEventImpl) event).getExecution().getTenantId())
.setBusinessKey(((FlowableProcessCancelledEventImpl) event).getExecution().getProcessInstanceBusinessKey())
@ -192,7 +192,7 @@ public class RocketMqBpmnProcessEventListener extends AbstractBpmnEventListener<
.setInitiator(initiator)
.setLastOperationAssigner(getContext().getLastOperationAssigner(() -> BpmnTaskDelegateAssigner.toObjectCompatible(
runtimeService.getVariable(event.getProcessInstanceId(), CLOSE_PROCESS_ASSIGNER, BpmnTaskDelegateAssigner.class))))
.setVariables(((FlowableProcessCancelledEventImpl) event).getExecution().getVariables())
.setVariables(removeBpmnConstantsVariables(((FlowableProcessCancelledEventImpl) event).getExecution().getVariables()))
.setStartTime(((ExecutionEntityImpl) ((FlowableProcessCancelledEventImpl) event).getExecution()).getStartTime())
.setTenantId(((FlowableProcessCancelledEventImpl) event).getExecution().getTenantId())
.setBusinessKey(((FlowableProcessCancelledEventImpl) event).getExecution().getProcessInstanceBusinessKey())
@ -228,7 +228,7 @@ public class RocketMqBpmnProcessEventListener extends AbstractBpmnEventListener<
.setInitiator(initiator)
.setLastOperationAssigner(getContext().getLastOperationAssigner(() -> BpmnTaskDelegateAssigner.toObjectCompatible(
runtimeService.getVariable(event.getProcessInstanceId(), CLOSE_PROCESS_ASSIGNER, BpmnTaskDelegateAssigner.class))))
.setVariables(((FlowableProcessCancelledEventImpl) event).getExecution().getVariables())
.setVariables(removeBpmnConstantsVariables(((FlowableProcessCancelledEventImpl) event).getExecution().getVariables()))
.setStartTime(((ExecutionEntityImpl) ((FlowableProcessCancelledEventImpl) event).getExecution()).getStartTime())
.setTenantId(((FlowableProcessCancelledEventImpl) event).getExecution().getTenantId())
.setBusinessKey(((FlowableProcessCancelledEventImpl) event).getExecution().getProcessInstanceBusinessKey())
@ -264,7 +264,7 @@ public class RocketMqBpmnProcessEventListener extends AbstractBpmnEventListener<
.setInitiator(initiator)
.setLastOperationAssigner(getContext().getLastOperationAssigner(() -> BpmnTaskDelegateAssigner.toObjectCompatible(
runtimeService.getVariable(event.getProcessInstanceId(), CLOSE_PROCESS_ASSIGNER, BpmnTaskDelegateAssigner.class))))
.setVariables(((ExecutionEntityImpl) event.getEntity()).getVariables())
.setVariables(removeBpmnConstantsVariables(((ExecutionEntityImpl) event.getEntity()).getVariables()))
.setStartTime(((ExecutionEntityImpl) event.getEntity()).getStartTime())
.setTenantId(((ExecutionEntityImpl) event.getEntity()).getTenantId())
.setBusinessKey(((ExecutionEntityImpl) event.getEntity()).getProcessInstanceBusinessKey())

View File

@ -154,7 +154,7 @@ public class RocketMqBpmnTaskEvent_102_Listener extends AbstractBpmnEventListene
.setInitiator(BpmnTaskDelegateAssigner.toObjectCompatible(delegateTask.getVariable(INTERNAL_INITIATOR)))
.setApprover(BpmnTaskDelegateAssigner.toObjectCompatible(
delegateTask.getVariable(INTERNAL_TASK_RELATION_ASSIGNEE_INFO + delegateTask.getId())))
.setVariables(delegateTask.getVariables())
.setVariables(removeBpmnConstantsVariables(delegateTask.getVariables()))
.setStartTime(delegateTask.getCreateTime())
.setTenantId(delegateTask.getTenantId())
.setBusinessKey(processInstance.getBusinessKey())

View File

@ -18,6 +18,7 @@ import cn.axzo.workflow.common.model.response.bpmn.process.BpmnProcessInstanceLo
import cn.axzo.workflow.common.model.response.category.CategoryGroupVarItemVo;
import cn.axzo.workflow.core.common.utils.BpmnMetaParserHelper;
import cn.axzo.workflow.core.engine.cmd.CustomGetFormInstanceLatestValuesCmd;
import cn.axzo.workflow.core.engine.cmd.CustomGetFormModelByProcessInstanceIdCmd;
import cn.axzo.workflow.core.engine.cmd.CustomGetProcessInstanceVariablesCmd;
import cn.axzo.workflow.core.service.BpmnProcessDefinitionService;
import cn.axzo.workflow.core.service.BpmnProcessInstanceService;
@ -40,6 +41,8 @@ import org.flowable.form.api.FormRepositoryService;
import org.flowable.form.model.FormContainer;
import org.flowable.form.model.FormField;
import org.flowable.form.model.FormFieldTypes;
import org.flowable.form.model.Option;
import org.flowable.form.model.OptionFormField;
import org.flowable.form.model.SimpleFormModel;
import org.flowable.spring.SpringProcessEngineConfiguration;
import org.springframework.util.CollectionUtils;
@ -162,6 +165,7 @@ public class PrintAdminController implements PrintAdminApi {
bpmnProcessModelService.printTemplateConfig(dto);
return success();
}
/**
* 获取打印模板中可打印的字段, 或者是 WPS 模板中可配置的变量字段
*
@ -335,21 +339,30 @@ public class PrintAdminController implements PrintAdminApi {
// 生成系统字段的变量
generateSystemFieldVariables(processInstanceId, result);
FormInfo formInfo = commandExecutor.execute(new CustomGetFormModelByProcessInstanceIdCmd(processInstanceId));
// 将所有变量都转换成 JSON 对象返回
convertValueToObject(result);
convertValueToObject(result, formInfo);
return success(result);
}
private void convertValueToObject(Map<String, Object> result) {
if (CollectionUtils.isEmpty(result)) {
private void convertValueToObject(Map<String, Object> result, FormInfo formInfo) {
if (CollectionUtils.isEmpty(result) || Objects.isNull(formInfo)) {
return;
}
Map<String, FormField> stringFormFieldMap = ((SimpleFormModel) formInfo.getFormModel()).allFieldsAsMap();
result.forEach((key, value) -> {
if (!(value instanceof String)) {
return;
}
if (((String) value).startsWith("[")) {
if (stringFormFieldMap.containsKey(key) && stringFormFieldMap.get(key) instanceof OptionFormField) {
OptionFormField optionFormField = (OptionFormField) stringFormFieldMap.get(key);
if (Objects.equals("checkbox", optionFormField.getType())) {
result.put(key, buildOptionFieldValue(optionFormField, JSONObject.parseArray((String) value, String.class)));
} else if (Objects.equals("radio", optionFormField.getType())) {
result.put(key, buildOptionFieldValue(optionFormField, Lists.newArrayList((String) value)));
}
} else if (((String) value).startsWith("[")) {
result.put(key, JSONArray.parseArray((String) value));
} else if (((String) value).startsWith("{")) {
result.put(key, JSONObject.parseObject((String) value));
@ -357,6 +370,16 @@ public class PrintAdminController implements PrintAdminApi {
});
}
private String buildOptionFieldValue(OptionFormField optionFormField, List<String> selectedValues) {
if (CollectionUtils.isEmpty(optionFormField.getOptions())) {
return "";
}
return optionFormField.getOptions().stream()
.filter(i -> selectedValues.contains(i.getId()))
.map(Option::getName)
.collect(Collectors.joining(""));
}
private void generateSystemFieldVariables(String processInstanceId, Map<String, Object> result) {
CommandExecutor commandExecutor = processEngineConfiguration.getCommandExecutor();
Map<String, Object> variables = commandExecutor.execute(new CustomGetProcessInstanceVariablesCmd(processInstanceId));