feat(dify): 增加基于 appType 的应用查询功能并优化异常处理
- 在 AppEntity 中添加 AppType 枚举字段,用于区分不同类型的 app - 在 AppEntityService 中新增 getAppsByAppType 方法,根据 appType 获取应用列表 - 在 AppEntityServiceImpl 中实现 getAppsByAppType 方法,使用 LambdaQueryWrapper 进行查询 - 在 V1ServerController 中添加 getAppsByAppType 接口,提供基于 appType 的应用列表查询 - 优化 ExceptionUtil 中的异常处理,统一使用 difyException 方法处理异常- 在 V1ChatController 和V1WorkflowController 中使用新的 difyException 方法处理异常 - 移除 MybatisPlusConfig 中未使用的代码,简化配置
This commit is contained in:
parent
6cf9c71abc
commit
6cf9e2a3fd
@ -12,16 +12,8 @@ public class ExceptionUtil {
|
||||
return supplier.get();
|
||||
} catch (RuntimeException e) {
|
||||
System.err.println(e.getMessage());
|
||||
throw new ApiException("服务器错误,请联系工作人员!");
|
||||
throw new ApiException("出现错误,请联系工作人员!报错信息:"+e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public static <T> T difyNotFoundException(Supplier<T> supplier) throws ApiException {
|
||||
try {
|
||||
return supplier.get();
|
||||
} catch (RuntimeException e) {
|
||||
System.err.println(e.getMessage());
|
||||
throw new ApiException("数据不存在,请检查传递参数是否错误!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -4,20 +4,10 @@ import com.baomidou.mybatisplus.annotation.DbType;
|
||||
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
|
||||
import com.baomidou.mybatisplus.extension.plugins.inner.DataPermissionInterceptor;
|
||||
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
|
||||
import jakarta.activation.DataSource;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.apache.ibatis.session.ExecutorType;
|
||||
import org.mybatis.spring.SqlSessionFactoryBean;
|
||||
import org.mybatis.spring.SqlSessionTemplate;
|
||||
import org.mybatis.spring.annotation.MapperScan;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.boot.jdbc.DataSourceBuilder;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
|
||||
|
||||
import javax.naming.Context;
|
||||
import javax.naming.InitialContext;
|
||||
|
||||
/**
|
||||
* @author Yao
|
||||
|
@ -1,11 +1,10 @@
|
||||
package com.zsc.edu.dify.modules.dify.controller;
|
||||
|
||||
import com.zsc.edu.dify.exception.ApiException;
|
||||
import com.zsc.edu.dify.exception.ExceptionUtil;
|
||||
import com.zsc.edu.dify.framework.mybatisplus.DataPermission;
|
||||
import com.zsc.edu.dify.framework.security.SecurityUtil;
|
||||
import com.zsc.edu.dify.modules.dify.service.AppEntityService;
|
||||
import com.zsc.edu.dify.modules.operationLog.entity.OperationLogAnnotation;
|
||||
import com.zsc.edu.dify.modules.system.service.UserService;
|
||||
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;
|
||||
@ -21,6 +20,9 @@ import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import reactor.core.publisher.Flux;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
/**
|
||||
* @author yanghq
|
||||
* @version 1.0
|
||||
@ -132,5 +134,17 @@ public class V1ChatController {
|
||||
difyChat.deleteConversation(conversationId, apiKey,userId);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取会话建议
|
||||
* @param messageId
|
||||
* @param appId
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/messages/suggested")
|
||||
@PreAuthorize("hasAuthority('dify:chat:query')")
|
||||
public List<String> messagesSuggested(String messageId,String appId){
|
||||
String apiKey = appEntityService.getApikey(appId);
|
||||
String userId = SecurityUtil.getUserInfo().id.toString();
|
||||
return ExceptionUtil.difyException(()->difyChat.messagesSuggested(messageId,apiKey,userId));
|
||||
}
|
||||
}
|
@ -116,4 +116,15 @@ public class V1ServerController {
|
||||
return appEntityService.list(queryWrapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据appType获取应用列表
|
||||
* @param appType
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/apps/type")
|
||||
@PreAuthorize("hasAuthority('dify:server:query')")
|
||||
@DataPermission
|
||||
public List<AppEntity> getAppsByAppType(Integer appType){
|
||||
return appEntityService.getAppsByAppType(appType);
|
||||
}
|
||||
}
|
||||
|
@ -81,7 +81,7 @@ public class V1WorkflowController {
|
||||
@PreAuthorize("hasAuthority('dify:workflow:info')")
|
||||
public WorkflowInfoResponse info(String workflowRunId, @PathVariable String appId) {
|
||||
String apiKey =appEntityService.getApikey(appId);
|
||||
return ExceptionUtil.difyNotFoundException(() -> difyWorkflow.info(workflowRunId, apiKey));
|
||||
return ExceptionUtil.difyException(() -> difyWorkflow.info(workflowRunId, apiKey));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -110,4 +110,5 @@ public class V1WorkflowController {
|
||||
public List<WorkflowData> list(@PathVariable String appId){
|
||||
return difyWorkflowService.list(new QueryWrapper<WorkflowData>().eq("app_id",appId));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,10 +1,10 @@
|
||||
package com.zsc.edu.dify.modules.dify.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.FieldFill;
|
||||
import com.baomidou.mybatisplus.annotation.IEnum;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.zsc.edu.dify.framework.json.JsonbTypeHandler;
|
||||
import com.zsc.edu.dify.modules.system.vo.MenuVo;
|
||||
import io.github.guoshiqiufeng.dify.server.dto.response.AppsResponseVO;
|
||||
import lombok.*;
|
||||
|
||||
@ -52,4 +52,22 @@ public class AppEntity extends AppsResponseVO {
|
||||
|
||||
@TableField(value = "dept_id", fill = FieldFill.INSERT)
|
||||
private Long deptId;
|
||||
|
||||
private AppType appType;
|
||||
|
||||
public enum AppType implements IEnum<Integer>{
|
||||
WORD(1),
|
||||
PPT(2),
|
||||
SCRAPER(3);
|
||||
|
||||
private final Integer value;
|
||||
|
||||
AppType(int value) {
|
||||
this.value=value;
|
||||
}
|
||||
@Override
|
||||
public Integer getValue() {
|
||||
return this.value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -12,4 +12,6 @@ public interface AppEntityService extends IService<AppEntity> {
|
||||
boolean enabledApp(String id);
|
||||
|
||||
String getApikey(String appId);
|
||||
|
||||
List<AppEntity> getAppsByAppType(Integer appType);
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
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.exception.ConstraintException;
|
||||
@ -90,4 +91,16 @@ public class AppEntityServiceImpl extends ServiceImpl<AppEntityRepository, AppEn
|
||||
return appEntityRepository.selectApiKey(appId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据appType获取应用
|
||||
* @param appType
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public List<AppEntity> getAppsByAppType(Integer appType) {
|
||||
LambdaQueryWrapper<AppEntity> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.eq(AppEntity::getAppType, appType).eq(AppEntity::isEnabled, true);
|
||||
return this.list(queryWrapper);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -94,7 +94,7 @@ class DeptServiceTest {
|
||||
// 不能改为其他已存在的同名同代码部门
|
||||
assertThrows(ConstraintException.class,
|
||||
() -> service.edit(
|
||||
new DeptDto(dept3.getName(), "remark",null), dept2.id));
|
||||
new DeptDto(dept3.getName(), true,null, dept3.id), dept2.id));
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user