Compare commits

...

3 Commits

Author SHA1 Message Date
6cf9e2a3fd feat(dify): 增加基于 appType 的应用查询功能并优化异常处理
- 在 AppEntity 中添加 AppType 枚举字段,用于区分不同类型的 app
- 在 AppEntityService 中新增 getAppsByAppType 方法,根据 appType 获取应用列表
- 在 AppEntityServiceImpl 中实现 getAppsByAppType 方法,使用 LambdaQueryWrapper 进行查询
- 在 V1ServerController 中添加 getAppsByAppType 接口,提供基于 appType 的应用列表查询
- 优化 ExceptionUtil 中的异常处理,统一使用 difyException 方法处理异常- 在 V1ChatController 和V1WorkflowController 中使用新的 difyException 方法处理异常
- 移除 MybatisPlusConfig 中未使用的代码,简化配置
2025-05-13 21:03:18 +08:00
6cf9c71abc Merge remote-tracking branch 'origin/feature/dify' into feature/dify
# Conflicts:
#	src/test/java/com/zsc/edu/dify/service/system/DeptServiceTest.java
#	src/test/java/com/zsc/edu/dify/service/system/RoleServiceTest.java
#	src/test/java/com/zsc/edu/dify/service/system/UserServiceTest.java
2025-05-13 10:15:38 +08:00
771d251cf3 test: 注释掉部分测试用例的断言
- 在 DeptServiceTest 中注释掉了测试部门编辑时的约束异常断言- 在 RoleServiceTest 中注释掉了测试角色创建时的约束异常断言
- 在 UserServiceTest 中注释掉了用户更新时的启用状态设置

这些修改可能是为了暂时跳过某些测试逻辑,或者准备对相关功能进行调整。
2025-05-13 10:14:52 +08:00
9 changed files with 67 additions and 25 deletions

View File

@ -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("数据不存在,请检查传递参数是否错误!");
}
}
}

View File

@ -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

View File

@ -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));
}
}

View File

@ -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);
}
}

View File

@ -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));
}
}

View File

@ -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;
}
}
}

View File

@ -12,4 +12,6 @@ public interface AppEntityService extends IService<AppEntity> {
boolean enabledApp(String id);
String getApikey(String appId);
List<AppEntity> getAppsByAppType(Integer appType);
}

View File

@ -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);
}
}

View File

@ -93,7 +93,8 @@ class DeptServiceTest {
assertEquals(tmp.getId(), dept2.id);
// 不能改为其他已存在的同名同代码部门
assertThrows(ConstraintException.class,
() -> service.edit(new DeptDto(dept3.getName(), true, "remark",null), dept2.id));
() -> service.edit(
new DeptDto(dept3.getName(), true,null, dept3.id), dept2.id));
}