refactor(dify): 优化 workflow 运行接口返回值类型- 将 DifyWorkflowService接口的 run 方法返回值类型从 WorkflowData 改为 WorkflowRunResponse

- 更新 DifyWorkflowServiceImpl 中的 run 方法实现
-调整 V1WorkflowController 中的 runWorkflow 方法返回类型
This commit is contained in:
zhuangtianxiang 2025-05-06 19:24:12 +08:00
parent d64f4958d0
commit c1f8f896d6
3 changed files with 10 additions and 6 deletions

View File

@ -37,7 +37,7 @@ public class V1WorkflowController {
*/
@PostMapping("/run/{appId}")
@PreAuthorize("hasAuthority('dify:workflow:run')")
public WorkflowData runWorkflow(@RequestBody WorkflowRunRequest request, @PathVariable String appId) {
public WorkflowRunResponse runWorkflow(@RequestBody WorkflowRunRequest request, @PathVariable String appId) {
return difyWorkflowService.run(request, appId);
}
@ -60,7 +60,7 @@ public class V1WorkflowController {
* @return
*/
@PatchMapping("/stop/{appId}")
public WorkflowStopResponse stopWorkflowStream( String taskId, String userId, @PathVariable String appId) {
public WorkflowStopResponse stopWorkflowStream(String taskId, String userId, @PathVariable String appId) {
String apiKey = appEntityRepository.selectApiKey(appId);
return difyWorkflow.stopWorkflowStream(apiKey, taskId, userId);
}

View File

@ -3,7 +3,9 @@ package com.zsc.edu.dify.modules.dify.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.zsc.edu.dify.modules.dify.entity.WorkflowData;
import io.github.guoshiqiufeng.dify.workflow.dto.request.WorkflowRunRequest;
import io.github.guoshiqiufeng.dify.workflow.dto.response.WorkflowRunResponse;
public interface DifyWorkflowService extends IService<WorkflowData> {
WorkflowData run(WorkflowRunRequest request, String appId);
WorkflowRunResponse run(WorkflowRunRequest request, String appId);
}

View File

@ -8,6 +8,7 @@ import com.zsc.edu.dify.modules.dify.repo.WorkflowRepository;
import com.zsc.edu.dify.modules.dify.service.DifyWorkflowService;
import io.github.guoshiqiufeng.dify.workflow.DifyWorkflow;
import io.github.guoshiqiufeng.dify.workflow.dto.request.WorkflowRunRequest;
import io.github.guoshiqiufeng.dify.workflow.dto.response.WorkflowRunResponse;
import jakarta.annotation.Resource;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;
@ -23,12 +24,13 @@ public class DifyWorkflowServiceImpl extends ServiceImpl<WorkflowRepository, Wor
WorkflowMapper mapper;
@Override
public WorkflowData run(WorkflowRunRequest request, String appId){
public WorkflowRunResponse run(WorkflowRunRequest request, String appId){
String apiKey = appEntityRepository.selectApiKey(appId);
request.setApiKey(apiKey);
WorkflowData workflowData =mapper.toEntity(difyWorkflow.runWorkflow(request));
WorkflowRunResponse response = difyWorkflow.runWorkflow(request);
WorkflowData workflowData =mapper.toEntity(response);
workflowData.setAppId(appId);
baseMapper.insert(workflowData);
return workflowData;
return response;
}
}