feat(REQ-4624) - 1.调整表单相关 API 的使用权限 2.新增直接查询表单数据的API

This commit is contained in:
wangli 2025-07-29 15:32:53 +08:00
parent b3e3652082
commit 86f7f2ba0b
7 changed files with 119 additions and 1 deletions

View File

@ -6,6 +6,7 @@ import cn.axzo.workflow.common.annotation.Manageable;
import cn.axzo.workflow.common.model.request.form.definition.StartFormSearchDTO;
import cn.axzo.workflow.common.model.request.form.instance.FormDetailDTO;
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.FormInstanceVO;
@ -27,13 +28,19 @@ import static cn.axzo.workflow.common.enums.RpcInvokeModeEnum.SYNC;
* @since 2024-11-11 20:08
*/
@WorkflowEngineFeignClient
@Manageable
public interface FormAdminApi {
@PostMapping("/api/form/admin/form/page")
@InvokeMode(SYNC)
@Manageable
CommonResponse<List<FormVO>> formPage(@Validated @RequestBody FormSearchDTO dto);
/**
* 获取流程配置的表单模型和权限主要用于发起页
*
* @param dto
* @return
*/
@PostMapping("/api/form/admin/start/form")
@InvokeMode(SYNC)
CommonResponse<FormDefinitionVO> getFormDefinition(@Validated @RequestBody StartFormSearchDTO dto);
@ -50,4 +57,14 @@ public interface FormAdminApi {
@PostMapping("/api/form/admin/instance/render")
@InvokeMode(SYNC)
CommonResponse<FormInstanceVO> getFormInstance(@Validated @RequestBody FormDetailDTO dto);
/**
* 获取流程中表单直接数据不包含模型
*
* @param dto
* @return
*/
@PostMapping("/instance/form/data")
@InvokeMode(SYNC)
CommonResponse<String> getFormData(@Validated @RequestBody FromDataSearchDTO dto);
}

View File

@ -0,0 +1,32 @@
package cn.axzo.workflow.common.model.request.form.instance;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import javax.validation.constraints.NotBlank;
import java.io.Serializable;
/**
* 表单数据搜索入参模型
*
* @author wangli
* @since 2025-07-29 14:33
*/
@ApiModel("表单数据搜索入参模型")
@Data
public class FromDataSearchDTO implements Serializable {
/**
* 流程实例 ID
*/
@ApiModelProperty(value = "流程实例ID")
@NotBlank(message = "流程实例 ID 不能为空")
private String processInstanceId;
/**
* 任务 ID
*/
@ApiModelProperty(value = "任务 ID")
private String taskId;
}

View File

@ -0,0 +1,44 @@
package cn.axzo.workflow.core.engine.cmd;
import org.flowable.common.engine.impl.interceptor.Command;
import org.flowable.common.engine.impl.interceptor.CommandContext;
import org.flowable.engine.impl.cfg.ProcessEngineConfigurationImpl;
import org.flowable.engine.impl.util.CommandContextUtil;
import org.flowable.form.api.FormEngineConfigurationApi;
import org.flowable.form.api.FormInstance;
import org.flowable.form.api.FormService;
import org.springframework.util.StringUtils;
import java.util.Comparator;
import java.util.List;
import java.util.Objects;
/**
* cn.axzo.workflow.core.engine.cmd.CustomGetFormInstanceLatestValuesCmd 的另一种实现吧
*
* @author wangli
* @since 2025-07-29 15:19
*/
public class CustomGetFormDataValuesCmd implements Command<byte[]> {
private final String processInstanceId;
private final String taskId;
public CustomGetFormDataValuesCmd(String processInstanceId, String taskId) {
this.processInstanceId = processInstanceId;
this.taskId = taskId;
}
@Override
public byte[] execute(CommandContext commandContext) {
FormEngineConfigurationApi formEngineConfiguration = CommandContextUtil.getFormEngineConfiguration(commandContext);
FormService formService = formEngineConfiguration.getFormService();
List<FormInstance> list = formService.createFormInstanceQuery().processInstanceId(processInstanceId).list();
FormInstance formInstance = list.stream().max(Comparator.comparing(FormInstance::getSubmittedDate)).orElse(null);
if (StringUtils.hasText(taskId)) {
formInstance = list.stream().filter(i -> Objects.equals(i.getTaskId(), taskId)).findFirst()
.orElse(formInstance);
}
return formInstance.getFormValueBytes();
}
}

View File

@ -35,6 +35,7 @@ import static cn.axzo.workflow.common.enums.BpmnProcessInstanceResultEnum.PROCES
* @since 2025-01-21 10:24
*/
public class CustomGetFormInstanceLatestValuesCmd extends GetFormInstanceValuesCmd {
private static final long serialVersionUID = -1017881786777839488L;
private String processInstanceId;
private Boolean throwException;

View File

@ -3,9 +3,11 @@ package cn.axzo.workflow.core.service;
import cn.axzo.workflow.common.model.dto.BpmnFormRelationSearchDTO;
import cn.axzo.workflow.common.model.request.form.definition.StartFormSearchDTO;
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.FormInstanceVO;
import com.alibaba.fastjson.JSONObject;
import java.util.List;
@ -22,4 +24,6 @@ public interface FormCoreService {
FormDefinitionVO getStartForm(StartFormSearchDTO dto);
FormInstanceVO getFormInstance(FormDetailDTO dto);
String getFormData(FromDataSearchDTO dto);
}

View File

@ -4,6 +4,7 @@ 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;
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.bpmn.process.BpmnProcessDefinitionVO;
import cn.axzo.workflow.common.model.response.category.CategoryItemVO;
import cn.axzo.workflow.common.model.response.form.FormVO;
@ -11,6 +12,7 @@ import cn.axzo.workflow.common.model.response.form.definition.FormDefinitionVO;
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;
@ -20,6 +22,7 @@ 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;
@ -28,12 +31,14 @@ 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.FormField;
import org.flowable.form.model.SimpleFormModel;
import org.flowable.spring.SpringProcessEngineConfiguration;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
@ -130,4 +135,12 @@ public class FormCoreServiceImpl implements FormCoreService {
bpmnProcessTaskForEsService, dto.getAssigner(), dto.getProcessInstanceId(), dto.getTaskId(), dto.getShowOriginDefaultValue()));
return formInstanceConverter.toVo(formInstanceInfo);
}
@Override
public String 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);
}
}

View File

@ -5,6 +5,7 @@ import cn.axzo.workflow.common.model.dto.BpmnFormRelationSearchDTO;
import cn.axzo.workflow.common.model.request.form.definition.StartFormSearchDTO;
import cn.axzo.workflow.common.model.request.form.instance.FormDetailDTO;
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.FormInstanceVO;
@ -60,4 +61,10 @@ public class FormAdminController implements FormAdminApi {
public CommonResponse<FormInstanceVO> getFormInstance(@Validated @RequestBody FormDetailDTO dto) {
return success(formCoreService.getFormInstance(dto));
}
@Operation(summary = "获取指定表单审批的实例数据")
@PostMapping("/instance/form/data")
public CommonResponse<String> getFormData(@Validated @RequestBody FromDataSearchDTO dto) {
return success(formCoreService.getFormData(dto));
}
}