feat(REQ-4624) - 添加获取表单实例数据的逻辑
This commit is contained in:
parent
6fdb3f99ff
commit
f21d2282d4
@ -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);
|
||||
}
|
||||
|
||||
@ -18,7 +18,7 @@ import java.util.Objects;
|
||||
* @since 2025-08-04 11:44
|
||||
*/
|
||||
public enum FormFieldTypeEnum {
|
||||
text("text", "文本", new TypeReference<String>() {
|
||||
input("input", "文本", new TypeReference<String>() {
|
||||
}),
|
||||
textarea("textarea", "多行文本", new TypeReference<String>() {
|
||||
}),
|
||||
|
||||
@ -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);
|
||||
}
|
||||
|
||||
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user