feat(dify): 添加工作流数据相关接口和功能
- 新增工作流数据的详情、分页查询和删除接口 - 实现工作流数据的存储和解析- 优化聊天控制器中的异常处理 - 更新工作流控制器,支持新的数据操作接口 - 修改工作流实体类,增加运行数据和自定义数据字段
This commit is contained in:
parent
eb134a034d
commit
5ea0ad3edc
@ -54,7 +54,7 @@ public class V1ChatController {
|
||||
) {
|
||||
sendRequest.setApiKey(appEntityService.getApikey(appId));
|
||||
sendRequest.setUserId(SecurityUtil.getUserInfo().id.toString());
|
||||
return ExceptionUtil.difyException(()->difyChat.send(sendRequest));
|
||||
return difyChat.send(sendRequest);
|
||||
}
|
||||
|
||||
|
||||
@ -100,11 +100,12 @@ public class V1ChatController {
|
||||
*/
|
||||
@PostMapping("/messages/{appid}")
|
||||
@PreAuthorize("hasAuthority('dify:chat:query')")
|
||||
public DifyPageResult<MessagesResponseVO> conversations(
|
||||
public DifyPageResult<MessagesResponseVO> messages(
|
||||
@RequestBody MessagesRequest request,
|
||||
@PathVariable String appid
|
||||
) {
|
||||
String apiKey = appEntityService.getApikey(appid);
|
||||
request.setUserId(SecurityUtil.getUserInfo().id.toString());
|
||||
request.setApiKey(apiKey);
|
||||
return ExceptionUtil.difyException(()->difyChat.messages(request));
|
||||
}
|
||||
@ -136,7 +137,7 @@ public class V1ChatController {
|
||||
try{
|
||||
difyChat.deleteConversation(conversationId, apiKey,userId);
|
||||
}catch (RuntimeException e){
|
||||
throw new RuntimeException("删除会话失败"+e.getMessage());
|
||||
throw new ApiException("删除会话失败"+e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
package com.zsc.edu.dify.modules.dify.controller;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.zsc.edu.dify.exception.ExceptionUtil;
|
||||
import com.zsc.edu.dify.framework.mybatisplus.DataPermission;
|
||||
import com.zsc.edu.dify.framework.security.SecurityUtil;
|
||||
@ -101,6 +102,7 @@ public class V1WorkflowController {
|
||||
|
||||
/**
|
||||
* 日志列表
|
||||
*
|
||||
* @param appId
|
||||
* @return
|
||||
*/
|
||||
@ -111,4 +113,39 @@ public class V1WorkflowController {
|
||||
return difyWorkflowService.list(new QueryWrapper<WorkflowData>().eq("app_id",appId));
|
||||
}
|
||||
|
||||
/**
|
||||
* 详情
|
||||
*
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/detail/{id}")
|
||||
@PreAuthorize("hasAuthority('dify:workflow:query')")
|
||||
public WorkflowData detail(@PathVariable Long id){
|
||||
return difyWorkflowService.detail(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除
|
||||
*
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@DeleteMapping("/delete/{id}")
|
||||
@PreAuthorize("hasAuthority('dify:workflow:delete')")
|
||||
public boolean delete(@PathVariable Long id){
|
||||
return difyWorkflowService.delete(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页查询
|
||||
*
|
||||
* @param page
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/query")
|
||||
@PreAuthorize("hasAuthority('dify:workflow:query')")
|
||||
public Page<WorkflowData> query(Page<WorkflowData> page){
|
||||
return difyWorkflowService.query(page);
|
||||
}
|
||||
}
|
||||
|
@ -1,9 +1,12 @@
|
||||
package com.zsc.edu.dify.modules.dify.entity;
|
||||
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.baomidou.mybatisplus.annotation.FieldFill;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.zsc.edu.dify.framework.json.JsonbTypeHandler;
|
||||
import io.github.guoshiqiufeng.dify.workflow.dto.response.WorkflowRunResponse;
|
||||
import lombok.Data;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
@ -13,7 +16,7 @@ import lombok.Setter;
|
||||
@Setter
|
||||
@Data
|
||||
@TableName("workflow_data")
|
||||
public class WorkflowData {
|
||||
public class WorkflowData{
|
||||
@TableId
|
||||
private Long id;
|
||||
|
||||
@ -31,4 +34,10 @@ public class WorkflowData {
|
||||
|
||||
@TableField(value = "dept_id", fill = FieldFill.INSERT)
|
||||
private Long deptId;
|
||||
|
||||
@TableField(exist = false)
|
||||
private WorkflowRunResponse.WorkflowRunData runData;
|
||||
|
||||
@TableField(typeHandler = JsonbTypeHandler.class)
|
||||
private String data;
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.zsc.edu.dify.modules.dify.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
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;
|
||||
@ -8,4 +9,10 @@ import io.github.guoshiqiufeng.dify.workflow.dto.response.WorkflowRunResponse;
|
||||
|
||||
public interface DifyWorkflowService extends IService<WorkflowData> {
|
||||
WorkflowRunResponse run(WorkflowRunRequest request, String appId);
|
||||
|
||||
WorkflowData detail(Long id);
|
||||
|
||||
Page<WorkflowData> query(Page<WorkflowData> page);
|
||||
|
||||
boolean delete(Long id);
|
||||
}
|
||||
|
@ -1,5 +1,8 @@
|
||||
package com.zsc.edu.dify.modules.dify.service.Impl;
|
||||
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.zsc.edu.dify.modules.dify.entity.WorkflowData;
|
||||
import com.zsc.edu.dify.modules.dify.mapper.WorkflowMapper;
|
||||
@ -36,7 +39,30 @@ public class DifyWorkflowServiceImpl extends ServiceImpl<WorkflowRepository, Wor
|
||||
WorkflowRunResponse response = difyWorkflow.runWorkflow(request);
|
||||
WorkflowData workflowData =mapper.toEntity(response);
|
||||
workflowData.setAppId(appId);
|
||||
workflowData.setData(String.valueOf(response.getData()));
|
||||
baseMapper.insert(workflowData);
|
||||
return response;
|
||||
}
|
||||
|
||||
@Override
|
||||
public WorkflowData detail(Long id) {
|
||||
WorkflowData workflowData = this.getById(id);
|
||||
if(workflowData == null){
|
||||
throw new RuntimeException("未找到数据");
|
||||
}
|
||||
WorkflowRunResponse.WorkflowRunData parsedData =
|
||||
JSON.parseObject(workflowData.getData(), WorkflowRunResponse.WorkflowRunData.class);
|
||||
workflowData.setRunData(parsedData);
|
||||
return workflowData;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Page<WorkflowData> query(Page<WorkflowData> page){
|
||||
return baseMapper.selectPage(page,new QueryWrapper<>());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean delete(Long id){
|
||||
return baseMapper.deleteById(id) > 0;
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,7 @@
|
||||
package com.zsc.edu.dify;
|
||||
|
||||
import com.zsc.edu.dify.modules.dify.repo.AppEntityRepository;
|
||||
import com.zsc.edu.dify.modules.dify.service.AppEntityService;
|
||||
import com.zsc.edu.dify.modules.message.repo.BulletinRepository;
|
||||
import com.zsc.edu.dify.modules.system.repo.UserRepository;
|
||||
import jakarta.annotation.Resource;
|
||||
@ -17,7 +19,4 @@ class DifyBackendApplicationTests {
|
||||
void contextLoads() {
|
||||
// bulletinRepository.selectAll();
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user