Merge branch 'feature/REQ-4624' into dev

This commit is contained in:
wangli 2025-08-04 16:28:07 +08:00
commit 4610efa3f9
6 changed files with 140 additions and 11 deletions

View File

@ -9,6 +9,7 @@ import cn.axzo.workflow.common.model.request.form.instance.FormSearchDTO;
import cn.axzo.workflow.common.model.request.form.instance.FromDataSearchDTO;
import cn.axzo.workflow.common.model.response.form.FormVO;
import cn.axzo.workflow.common.model.response.form.definition.FormDefinitionVO;
import cn.axzo.workflow.common.model.response.form.instance.FormDataVO;
import cn.axzo.workflow.common.model.response.form.instance.FormInstanceVO;
import cn.azxo.framework.common.model.CommonResponse;
import org.springframework.validation.annotation.Validated;
@ -66,5 +67,5 @@ public interface FormAdminApi {
*/
@PostMapping("/instance/form/data")
@InvokeMode(SYNC)
CommonResponse<String> getFormData(@Validated @RequestBody FromDataSearchDTO dto);
CommonResponse<List<FormDataVO>> getFormData(@Validated @RequestBody FromDataSearchDTO dto);
}

View File

@ -0,0 +1,75 @@
package cn.axzo.workflow.common.enums;
import cn.axzo.workflow.common.model.dto.UploadFieldDTO;
import cn.axzo.workflow.common.model.request.bpmn.task.BpmnTaskDelegateAssigner;
import com.alibaba.fastjson.TypeReference;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.Objects;
/**
* 流程引擎表单字段类型枚举
* <p>
* 参考文档{@see https://alidocs.dingtalk.com/i/nodes/ZgpG2NdyVXKy17o6fQ5nKGvMWMwvDqPk}
*
* @author wangli
* @since 2025-08-04 11:44
*/
public enum FormFieldTypeEnum {
input("input", "文本", new TypeReference<String>() {
}),
textarea("textarea", "多行文本", new TypeReference<String>() {
}),
upload("upload", "上传文件", new TypeReference<List<UploadFieldDTO>>() {
}),
image("image", "图片", new TypeReference<List<UploadFieldDTO>>() {
}),
date("date", "日期", new TypeReference<String>() {
}),
customComponent("customComponent", "自定义组件", new TypeReference<List<Map<String, Object>>>() {
}),
taskOrder("taskOrder", "任务顺序", new TypeReference<Map<String, Object>>() {
}),
rectifyOrder("rectifyOrder", "整改顺序", new TypeReference<Map<String, Object>>() {
}),
changeSignatureOrder("changeSignatureOrder", "变更签署顺序", new TypeReference<Map<String, Object>>() {
}),
contacts("contacts", "联系人", new TypeReference<List<BpmnTaskDelegateAssigner>>() {
}),
amount("amount", "金额", new TypeReference<String>() {
}),
decimal("decimal", "小数", new TypeReference<Map<String, Object>>() {
}),
;
private final String type;
private final String desc;
private final TypeReference<?> typeReference;
FormFieldTypeEnum(String type, String desc, TypeReference<?> typeReference) {
this.type = type;
this.desc = desc;
this.typeReference = typeReference;
}
public String getType() {
return type;
}
public String getDesc() {
return desc;
}
public TypeReference<?> getTypeReference() {
return typeReference;
}
public static FormFieldTypeEnum valueOfType(String type) {
return Arrays.stream(FormFieldTypeEnum.values())
.filter(i -> Objects.equals(i.getType(), type))
.findAny()
.orElse(null);
}
}

View File

@ -0,0 +1,21 @@
package cn.axzo.workflow.common.model.response.form.instance;
import cn.axzo.workflow.common.enums.FormFieldTypeEnum;
import io.swagger.annotations.ApiModel;
import lombok.Data;
/**
* 表单实例数据的响应模型
*
* @author wangli
* @since 2025-08-04 10:54
*/
@ApiModel("表单实例数据的响应模型")
@Data
public class FormDataVO {
private String fieldId;
private Object fieldValue;
private FormFieldTypeEnum fieldType;
}

View File

@ -6,6 +6,7 @@ import cn.axzo.workflow.common.model.request.form.instance.FormDetailDTO;
import cn.axzo.workflow.common.model.request.form.instance.FromDataSearchDTO;
import cn.axzo.workflow.common.model.response.form.FormVO;
import cn.axzo.workflow.common.model.response.form.definition.FormDefinitionVO;
import cn.axzo.workflow.common.model.response.form.instance.FormDataVO;
import cn.axzo.workflow.common.model.response.form.instance.FormInstanceVO;
import com.alibaba.fastjson.JSONObject;
@ -25,5 +26,5 @@ public interface FormCoreService {
FormInstanceVO getFormInstance(FormDetailDTO dto);
String getFormData(FromDataSearchDTO dto);
List<FormDataVO> getFormData(FromDataSearchDTO dto);
}

View File

@ -1,5 +1,6 @@
package cn.axzo.workflow.core.service.impl;
import cn.axzo.workflow.common.enums.FormFieldTypeEnum;
import cn.axzo.workflow.common.exception.WorkflowEngineException;
import cn.axzo.workflow.common.model.dto.BpmnFormRelationSearchDTO;
import cn.axzo.workflow.common.model.request.form.definition.StartFormSearchDTO;
@ -9,10 +10,10 @@ import cn.axzo.workflow.common.model.response.bpmn.process.BpmnProcessDefinition
import cn.axzo.workflow.common.model.response.category.CategoryItemVO;
import cn.axzo.workflow.common.model.response.form.FormVO;
import cn.axzo.workflow.common.model.response.form.definition.FormDefinitionVO;
import cn.axzo.workflow.common.model.response.form.instance.FormDataVO;
import cn.axzo.workflow.common.model.response.form.instance.FormInstanceVO;
import cn.axzo.workflow.core.common.utils.BpmnMetaParserHelper;
import cn.axzo.workflow.core.common.utils.FormHelper;
import cn.axzo.workflow.core.engine.cmd.CustomGetFormDataValuesCmd;
import cn.axzo.workflow.core.engine.cmd.GetFormInstanceAndPermissionCmd;
import cn.axzo.workflow.core.repository.entity.ExtAxBpmnFormRelation;
import cn.axzo.workflow.core.service.BpmnProcessDefinitionService;
@ -22,7 +23,6 @@ import cn.axzo.workflow.core.service.ExtAxBpmnFormRelationService;
import cn.axzo.workflow.core.service.FormCoreService;
import cn.axzo.workflow.form.service.converter.FormFieldConverter;
import cn.axzo.workflow.form.service.converter.FormInstanceConverter;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.extern.slf4j.Slf4j;
import org.flowable.bpmn.model.BpmnModel;
import org.flowable.common.engine.api.FlowableObjectNotFoundException;
@ -31,14 +31,16 @@ import org.flowable.engine.impl.cmd.GetBpmnModelCmd;
import org.flowable.form.api.FormInfo;
import org.flowable.form.api.FormInstanceInfo;
import org.flowable.form.api.FormRepositoryService;
import org.flowable.form.api.FormService;
import org.flowable.form.model.FormContainer;
import org.flowable.form.model.FormField;
import org.flowable.form.model.SimpleFormModel;
import org.flowable.spring.SpringProcessEngineConfiguration;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import javax.annotation.Resource;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
@ -137,10 +139,38 @@ public class FormCoreServiceImpl implements FormCoreService {
}
@Override
public String getFormData(FromDataSearchDTO dto) {
public List<FormDataVO> getFormData(FromDataSearchDTO dto) {
CommandExecutor commandExecutor = springProcessEngineConfiguration.getCommandExecutor();
// ObjectMapper objectMapper = springProcessEngineConfiguration.getObjectMapper();
byte[] values = commandExecutor.execute(new CustomGetFormDataValuesCmd(dto.getProcessInstanceId(), dto.getTaskId()));
return new String(values, StandardCharsets.UTF_8);
FormInstanceInfo formInstanceInfo = commandExecutor.execute(new GetFormInstanceAndPermissionCmd(bpmnFormRelationService,
bpmnProcessTaskForEsService, null, dto.getProcessInstanceId(), dto.getTaskId(), true));
List<FormField> fields = null;
if (Objects.isNull(formInstanceInfo)
|| Objects.isNull(formInstanceInfo.getFormModel())
|| (formInstanceInfo.getFormModel() instanceof SimpleFormModel) && CollectionUtils.isEmpty(fields = ((SimpleFormModel) formInstanceInfo.getFormModel()).getFields())) {
return Collections.emptyList();
}
if (!CollectionUtils.isEmpty(fields)) {
List<FormDataVO> dataList = new ArrayList<>();
fields.forEach(i -> recursiveConvert(i, dataList));
return dataList;
}
return Collections.emptyList();
}
private void recursiveConvert(FormField field, List<FormDataVO> formDataList) {
if (Objects.isNull(field)) {
return;
}
if (field instanceof FormContainer) {
((FormContainer) field).getFields().forEach(subField -> subField.forEach(i -> recursiveConvert(i, formDataList)));
} else {
FormDataVO formDataVO = new FormDataVO();
formDataVO.setFieldId(field.getId());
formDataVO.setFieldType(FormFieldTypeEnum.valueOfType(field.getType()));
formDataVO.setFieldValue(field.getValue());
formDataList.add(formDataVO);
}
}
}

View File

@ -8,6 +8,7 @@ import cn.axzo.workflow.common.model.request.form.instance.FormSearchDTO;
import cn.axzo.workflow.common.model.request.form.instance.FromDataSearchDTO;
import cn.axzo.workflow.common.model.response.form.FormVO;
import cn.axzo.workflow.common.model.response.form.definition.FormDefinitionVO;
import cn.axzo.workflow.common.model.response.form.instance.FormDataVO;
import cn.axzo.workflow.common.model.response.form.instance.FormInstanceVO;
import cn.axzo.workflow.core.service.FormCoreService;
import cn.axzo.workflow.server.common.annotation.ErrorReporter;
@ -64,7 +65,7 @@ public class FormAdminController implements FormAdminApi {
@Operation(summary = "获取指定表单审批的实例数据")
@PostMapping("/instance/form/data")
public CommonResponse<String> getFormData(@Validated @RequestBody FromDataSearchDTO dto) {
public CommonResponse<List<FormDataVO>> getFormData(@Validated @RequestBody FromDataSearchDTO dto) {
return success(formCoreService.getFormData(dto));
}
}