feat(dify): 更新 Dify相关接口并添加新功能- 移除 DifyChatService 类
- 在 V1ChatController 中直接使用 DifyChat 类- 新增多个 Dify 相关的 API 接口 - 添加 AppsResponse 实体类和相关 mapper、repository - 实现 DifyServerService 接口 - 新增 V1DatasetController 和V1WorkflowController 控制器
This commit is contained in:
parent
b5efc4863c
commit
b482197819
@ -1,11 +1,14 @@
|
|||||||
package com.zsc.edu.dify.modules.dify.controller;
|
package com.zsc.edu.dify.modules.dify.controller;
|
||||||
|
|
||||||
import com.zsc.edu.dify.modules.dify.service.DifyChatService;
|
import com.zsc.edu.dify.modules.dify.service.DifyServerService;
|
||||||
|
import io.github.guoshiqiufeng.dify.chat.DifyChat;
|
||||||
import io.github.guoshiqiufeng.dify.chat.dto.request.ChatMessageSendRequest;
|
import io.github.guoshiqiufeng.dify.chat.dto.request.ChatMessageSendRequest;
|
||||||
import io.github.guoshiqiufeng.dify.chat.dto.request.MessageConversationsRequest;
|
import io.github.guoshiqiufeng.dify.chat.dto.request.MessageConversationsRequest;
|
||||||
|
import io.github.guoshiqiufeng.dify.chat.dto.request.MessagesRequest;
|
||||||
import io.github.guoshiqiufeng.dify.chat.dto.response.ChatMessageSendCompletionResponse;
|
import io.github.guoshiqiufeng.dify.chat.dto.response.ChatMessageSendCompletionResponse;
|
||||||
import io.github.guoshiqiufeng.dify.chat.dto.response.MessageConversationsResponse;
|
import io.github.guoshiqiufeng.dify.chat.dto.response.MessageConversationsResponse;
|
||||||
import io.github.guoshiqiufeng.dify.core.pojo.DifyPageResult;
|
import io.github.guoshiqiufeng.dify.core.pojo.DifyPageResult;
|
||||||
|
import io.github.guoshiqiufeng.dify.core.pojo.response.MessagesResponseVO;
|
||||||
import jakarta.annotation.Resource;
|
import jakarta.annotation.Resource;
|
||||||
import org.springframework.http.MediaType;
|
import org.springframework.http.MediaType;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
@ -21,7 +24,7 @@ import reactor.core.publisher.Flux;
|
|||||||
public class V1ChatController {
|
public class V1ChatController {
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private DifyChatService difyChatService;
|
private DifyChat difyChat;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 发送消息(流式)
|
* 发送消息(流式)
|
||||||
@ -32,13 +35,52 @@ public class V1ChatController {
|
|||||||
*/
|
*/
|
||||||
@PostMapping(value = "/completions", produces = MediaType.TEXT_EVENT_STREAM_VALUE)
|
@PostMapping(value = "/completions", produces = MediaType.TEXT_EVENT_STREAM_VALUE)
|
||||||
public Flux<ChatMessageSendCompletionResponse> sendChatMessageStream(@RequestBody ChatMessageSendRequest sendRequest) {
|
public Flux<ChatMessageSendCompletionResponse> sendChatMessageStream(@RequestBody ChatMessageSendRequest sendRequest) {
|
||||||
return difyChatService.sendChatMessageStream(sendRequest);
|
return difyChat.sendChatMessageStream(sendRequest);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取会话列表
|
||||||
|
*
|
||||||
|
* @param request 请求参数
|
||||||
|
* @return 会话列表
|
||||||
|
*/
|
||||||
@GetMapping("/conversations")
|
@GetMapping("/conversations")
|
||||||
public DifyPageResult<MessageConversationsResponse> conversations(@RequestBody MessageConversationsRequest request) {
|
public DifyPageResult<MessageConversationsResponse> conversations(@RequestBody MessageConversationsRequest request) {
|
||||||
return difyChatService.conversations(request);
|
request.setApiKey("app-mM2UGTE5QVPLCwGvwifnV0g7");
|
||||||
|
return difyChat.conversations(request);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 停止流式消息
|
||||||
|
*
|
||||||
|
* @param taskId 任务id
|
||||||
|
* @param userId 用户id
|
||||||
|
*/
|
||||||
|
@GetMapping("/stopMessagesStream")
|
||||||
|
public void stopMessagesStream( String taskId, String userId) {
|
||||||
|
difyChat.stopMessagesStream("app-mM2UGTE5QVPLCwGvwifnV0g7", taskId, userId);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取消息列表
|
||||||
|
*
|
||||||
|
* @param request 请求参数
|
||||||
|
* @return 消息列表
|
||||||
|
*/
|
||||||
|
@GetMapping("/messages")
|
||||||
|
public DifyPageResult<MessagesResponseVO> messages(@RequestBody MessagesRequest request) {
|
||||||
|
request.setApiKey("app-mM2UGTE5QVPLCwGvwifnV0g7");
|
||||||
|
return difyChat.messages(request);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除会话
|
||||||
|
*
|
||||||
|
* @param conversationId 会话id
|
||||||
|
* @param userId 用户id
|
||||||
|
*/
|
||||||
|
@DeleteMapping("/messages/suggested")
|
||||||
|
public void deleteConversation(String conversationId, String userId) {
|
||||||
|
difyChat.deleteConversation(conversationId, "app-mM2UGTE5QVPLCwGvwifnV0g7", userId);
|
||||||
|
}
|
||||||
}
|
}
|
@ -0,0 +1,105 @@
|
|||||||
|
package com.zsc.edu.dify.modules.dify.controller;
|
||||||
|
|
||||||
|
import io.github.guoshiqiufeng.dify.core.pojo.DifyPageResult;
|
||||||
|
import io.github.guoshiqiufeng.dify.dataset.DifyDataset;
|
||||||
|
import io.github.guoshiqiufeng.dify.dataset.dto.request.*;
|
||||||
|
import io.github.guoshiqiufeng.dify.dataset.dto.response.*;
|
||||||
|
import jakarta.annotation.Resource;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/v1/dataset")
|
||||||
|
public class V1DatasetController {
|
||||||
|
@Resource
|
||||||
|
private DifyDataset difyDataset;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 分页查询知识库
|
||||||
|
*
|
||||||
|
* @param request
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@GetMapping("/page")
|
||||||
|
public DifyPageResult<DatasetResponse> page(@RequestBody DatasetPageRequest request){
|
||||||
|
return difyDataset.page(request);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通过文件创建文档
|
||||||
|
*
|
||||||
|
* @param request
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@GetMapping("/createDocumentByFile")
|
||||||
|
public DocumentCreateResponse createDocumentByFile(@RequestBody DocumentCreateByFileRequest request){
|
||||||
|
return difyDataset.createDocumentByFile(request);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 分页查询文档
|
||||||
|
*
|
||||||
|
* @param request
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@GetMapping("/pageDocument")
|
||||||
|
public DifyPageResult<DocumentInfo> pageDocument(@RequestBody DatasetPageDocumentRequest request){
|
||||||
|
return difyDataset.pageDocument(request);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取上传文件信息
|
||||||
|
*
|
||||||
|
* @param datasetId
|
||||||
|
* @param documentId
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@PostMapping("/uploadFileInfo")
|
||||||
|
public UploadFileInfoResponse uploadFileInfo(String datasetId, String documentId){
|
||||||
|
return difyDataset.uploadFileInfo(datasetId, documentId,"app-mM2UGTE5QVPLCwGvwifnV0g7");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除文档
|
||||||
|
*
|
||||||
|
* @param datasetId
|
||||||
|
* @param documentId
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@DeleteMapping("/deleteDocument")
|
||||||
|
public DocumentDeleteResponse deleteDocument(String datasetId, String documentId){
|
||||||
|
return difyDataset.deleteDocument(datasetId, documentId, "app-mM2UGTE5QVPLCwGvwifnV0g7");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建分段
|
||||||
|
*
|
||||||
|
* @param request
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@PostMapping("/createSegment")
|
||||||
|
public SegmentResponse createSegment(@RequestBody SegmentCreateRequest request){
|
||||||
|
return difyDataset.createSegment(request);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建子分段
|
||||||
|
*
|
||||||
|
* @param request
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@PostMapping("/createSegmentChildChunk")
|
||||||
|
public SegmentChildChunkCreateResponse createSegmentChildChunk(@RequestBody SegmentChildChunkCreateRequest request){
|
||||||
|
return difyDataset.createSegmentChildChunk(request);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 检索
|
||||||
|
*
|
||||||
|
* @param request
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@GetMapping("/retrieve")
|
||||||
|
public RetrieveResponse retrieve(@RequestBody RetrieveRequest request){
|
||||||
|
return difyDataset.retrieve(request);
|
||||||
|
}
|
||||||
|
}
|
@ -1,11 +1,13 @@
|
|||||||
package com.zsc.edu.dify.modules.dify.controller;
|
package com.zsc.edu.dify.modules.dify.controller;
|
||||||
|
|
||||||
|
import com.zsc.edu.dify.modules.dify.service.DifyServerService;
|
||||||
import io.github.guoshiqiufeng.dify.server.DifyServer;
|
import io.github.guoshiqiufeng.dify.server.DifyServer;
|
||||||
|
import io.github.guoshiqiufeng.dify.server.dto.response.ApiKeyResponseVO;
|
||||||
import io.github.guoshiqiufeng.dify.server.dto.response.AppsResponseVO;
|
import io.github.guoshiqiufeng.dify.server.dto.response.AppsResponseVO;
|
||||||
|
import io.github.guoshiqiufeng.dify.server.dto.response.DatasetApiKeyResponseVO;
|
||||||
import jakarta.annotation.Resource;
|
import jakarta.annotation.Resource;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.apache.ibatis.annotations.Param;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.*;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@ -15,6 +17,8 @@ public class V1ServerController {
|
|||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private DifyServer difyServer;
|
private DifyServer difyServer;
|
||||||
|
@Resource
|
||||||
|
private DifyServerService difyServerService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取应用列表
|
* 获取应用列表
|
||||||
@ -24,7 +28,54 @@ public class V1ServerController {
|
|||||||
*/
|
*/
|
||||||
@GetMapping("/apps")
|
@GetMapping("/apps")
|
||||||
public List<AppsResponseVO> getApps(String mode, String name) {
|
public List<AppsResponseVO> getApps(String mode, String name) {
|
||||||
return difyServer.apps(mode, name);
|
return difyServerService.getApps(mode, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取应用详情
|
||||||
|
* @param id 应用id
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@GetMapping("/{id}")
|
||||||
|
public AppsResponseVO getApp(@PathVariable("id") String id) {
|
||||||
|
return difyServer.app(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取应用api-key
|
||||||
|
* @param id 应用id
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@GetMapping("/api-key/{id}")
|
||||||
|
public List<ApiKeyResponseVO> getAppApiKey(@PathVariable("id") String id) {
|
||||||
|
return difyServer.getAppApiKey(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 初始化应用api-key
|
||||||
|
* @param id 应用id
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@PostMapping("/api-key/init/{id}")
|
||||||
|
public List<ApiKeyResponseVO> initAppApiKey(@PathVariable("id") String id) {
|
||||||
|
return difyServer.initAppApiKey(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取知识库api-key
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@GetMapping("/api-key/dataset")
|
||||||
|
public List<DatasetApiKeyResponseVO> getDatasetApiKey() {
|
||||||
|
return difyServer.getDatasetApiKey();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 初始化知识库api-key
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@PostMapping("/api-key/dataset/init")
|
||||||
|
public List<DatasetApiKeyResponseVO> initDatasetApiKey() {
|
||||||
|
return difyServer.initDatasetApiKey();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,74 @@
|
|||||||
|
package com.zsc.edu.dify.modules.dify.controller;
|
||||||
|
|
||||||
|
import io.github.guoshiqiufeng.dify.core.pojo.DifyPageResult;
|
||||||
|
import io.github.guoshiqiufeng.dify.workflow.DifyWorkflow;
|
||||||
|
import io.github.guoshiqiufeng.dify.workflow.dto.request.WorkflowLogsRequest;
|
||||||
|
import io.github.guoshiqiufeng.dify.workflow.dto.request.WorkflowRunRequest;
|
||||||
|
import io.github.guoshiqiufeng.dify.workflow.dto.response.*;
|
||||||
|
import jakarta.annotation.Resource;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
import reactor.core.publisher.Flux;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/v1/work")
|
||||||
|
public class V1WorkflowController {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private DifyWorkflow difyWorkflow;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 运行工作流
|
||||||
|
*
|
||||||
|
* @param request
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@PostMapping("/run")
|
||||||
|
public WorkflowRunResponse runWorkflow(@RequestBody WorkflowRunRequest request) {
|
||||||
|
return difyWorkflow.runWorkflow(request);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 运行工作流(流式)
|
||||||
|
*
|
||||||
|
* @param request
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@PostMapping("/run/stream")
|
||||||
|
public Flux<WorkflowRunStreamResponse> runWorkflowStream(@RequestBody WorkflowRunRequest request) {
|
||||||
|
return difyWorkflow.runWorkflowStream(request);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 停止工作流(流式)
|
||||||
|
*
|
||||||
|
* @param taskId
|
||||||
|
* @param userId
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@PatchMapping("/stop")
|
||||||
|
public WorkflowStopResponse stopWorkflowStream( String taskId, String userId){
|
||||||
|
return difyWorkflow.stopWorkflowStream("app-mM2UGTE5QVPLCwGvwifnV0g7", taskId, userId);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取工作流信息
|
||||||
|
*
|
||||||
|
* @param workflowRunId
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@GetMapping("/info")
|
||||||
|
public WorkflowInfoResponse info(String workflowRunId) {
|
||||||
|
return difyWorkflow.info(workflowRunId, "app-mM2UGTE5QVPLCwGvwifnV0g7");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取工作流日志
|
||||||
|
*
|
||||||
|
* @param request
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@GetMapping("/logs")
|
||||||
|
public DifyPageResult<WorkflowLogs> logs(@RequestBody WorkflowLogsRequest request) {
|
||||||
|
return difyWorkflow.logs(request);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,29 @@
|
|||||||
|
package com.zsc.edu.dify.modules.dify.entity;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableField;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
|
import com.zsc.edu.dify.framework.json.JsonbTypeHandler;
|
||||||
|
import io.github.guoshiqiufeng.dify.server.dto.response.AppsResponseVO;
|
||||||
|
import lombok.*;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author zhuang
|
||||||
|
*/
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
@TableName("apps_response")
|
||||||
|
public class AppsResponse extends AppsResponseVO {
|
||||||
|
|
||||||
|
@TableField(typeHandler = JsonbTypeHandler.class)
|
||||||
|
private Map<String, Object> modelConfig;
|
||||||
|
|
||||||
|
@TableField(typeHandler = JsonbTypeHandler.class)
|
||||||
|
private Map<String, Object> workflow;
|
||||||
|
|
||||||
|
@TableField(typeHandler = JsonbTypeHandler.class)
|
||||||
|
private List<String> tags;
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,11 @@
|
|||||||
|
package com.zsc.edu.dify.modules.dify.mapper;
|
||||||
|
|
||||||
|
import com.zsc.edu.dify.common.mapstruct.BaseMapper;
|
||||||
|
import com.zsc.edu.dify.modules.dify.entity.AppsResponse;
|
||||||
|
import io.github.guoshiqiufeng.dify.server.dto.response.AppsResponseVO;
|
||||||
|
import org.mapstruct.Mapper;
|
||||||
|
import org.mapstruct.ReportingPolicy;
|
||||||
|
|
||||||
|
@Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.IGNORE)
|
||||||
|
public interface AppsResponseMapper extends BaseMapper<AppsResponseVO, AppsResponse> {
|
||||||
|
}
|
@ -0,0 +1,7 @@
|
|||||||
|
package com.zsc.edu.dify.modules.dify.repo;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import com.zsc.edu.dify.modules.dify.entity.AppsResponse;
|
||||||
|
|
||||||
|
public interface AppsResponseRepository extends BaseMapper<AppsResponse> {
|
||||||
|
}
|
@ -1,35 +0,0 @@
|
|||||||
package com.zsc.edu.dify.modules.dify.service;
|
|
||||||
|
|
||||||
import io.github.guoshiqiufeng.dify.chat.DifyChat;
|
|
||||||
import io.github.guoshiqiufeng.dify.chat.dto.request.ChatMessageSendRequest;
|
|
||||||
import io.github.guoshiqiufeng.dify.chat.dto.request.MessageConversationsRequest;
|
|
||||||
import io.github.guoshiqiufeng.dify.chat.dto.response.ChatMessageSendCompletionResponse;
|
|
||||||
import io.github.guoshiqiufeng.dify.chat.dto.response.MessageConversationsResponse;
|
|
||||||
import io.github.guoshiqiufeng.dify.core.pojo.DifyPageResult;
|
|
||||||
import jakarta.annotation.Resource;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
import reactor.core.publisher.Flux;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author yanghq
|
|
||||||
* @version 1.0
|
|
||||||
* @since 2025/3/25 10:48
|
|
||||||
*/
|
|
||||||
@Slf4j
|
|
||||||
@Service
|
|
||||||
public class DifyChatService {
|
|
||||||
|
|
||||||
@Resource
|
|
||||||
private DifyChat difyChat;
|
|
||||||
|
|
||||||
public Flux<ChatMessageSendCompletionResponse> sendChatMessageStream(ChatMessageSendRequest sendRequest) {
|
|
||||||
// 可以进行自定义逻辑处理:参数转换、权限校验等
|
|
||||||
return difyChat.sendChatMessageStream(sendRequest);
|
|
||||||
}
|
|
||||||
|
|
||||||
public DifyPageResult<MessageConversationsResponse> conversations(MessageConversationsRequest request) {
|
|
||||||
return difyChat.conversations(request);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -0,0 +1,11 @@
|
|||||||
|
package com.zsc.edu.dify.modules.dify.service;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
|
import com.zsc.edu.dify.modules.dify.entity.AppsResponse;
|
||||||
|
import io.github.guoshiqiufeng.dify.server.dto.response.AppsResponseVO;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public interface DifyServerService extends IService<AppsResponse> {
|
||||||
|
List<AppsResponseVO> getApps(String mode, String name);
|
||||||
|
}
|
@ -0,0 +1,46 @@
|
|||||||
|
package com.zsc.edu.dify.modules.dify.service.Impl;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||||
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
|
import com.zsc.edu.dify.modules.dify.entity.AppsResponse;
|
||||||
|
import com.zsc.edu.dify.modules.dify.mapper.AppsResponseMapper;
|
||||||
|
import com.zsc.edu.dify.modules.dify.repo.AppsResponseRepository;
|
||||||
|
import com.zsc.edu.dify.modules.dify.service.DifyServerService;
|
||||||
|
import io.github.guoshiqiufeng.dify.server.DifyServer;
|
||||||
|
import io.github.guoshiqiufeng.dify.server.dto.response.AppsResponseVO;
|
||||||
|
import jakarta.annotation.Resource;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author zhuang
|
||||||
|
*/
|
||||||
|
@AllArgsConstructor
|
||||||
|
@Service
|
||||||
|
public class DifyServerServiceImpl extends ServiceImpl<AppsResponseRepository, AppsResponse> implements DifyServerService {
|
||||||
|
@Resource
|
||||||
|
private AppsResponseMapper appsResponseMapper;
|
||||||
|
@Resource
|
||||||
|
private DifyServer difyServer;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<AppsResponseVO> getApps(String mode, String name) {
|
||||||
|
return addApps(difyServer.apps(mode, name));
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<AppsResponseVO> addApps(List<AppsResponseVO> appsResponseList) {
|
||||||
|
for(AppsResponseVO appsResponse : appsResponseList){
|
||||||
|
boolean isHave = baseMapper.exists(new QueryWrapper<AppsResponse>().eq("id", appsResponse.getId()));
|
||||||
|
if(!isHave){
|
||||||
|
baseMapper.insert(appsResponseMapper.toEntity(appsResponse));
|
||||||
|
}else{
|
||||||
|
baseMapper.updateById(appsResponseMapper.toEntity(appsResponse));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
return appsResponseList;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user