Compare commits
3 Commits
92ff130b0d
...
6cf9e2a3fd
Author | SHA1 | Date | |
---|---|---|---|
6cf9e2a3fd | |||
6cf9c71abc | |||
771d251cf3 |
@ -12,16 +12,8 @@ public class ExceptionUtil {
|
|||||||
return supplier.get();
|
return supplier.get();
|
||||||
} catch (RuntimeException e) {
|
} catch (RuntimeException e) {
|
||||||
System.err.println(e.getMessage());
|
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.MybatisPlusInterceptor;
|
||||||
import com.baomidou.mybatisplus.extension.plugins.inner.DataPermissionInterceptor;
|
import com.baomidou.mybatisplus.extension.plugins.inner.DataPermissionInterceptor;
|
||||||
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
|
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.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.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
|
|
||||||
|
|
||||||
import javax.naming.Context;
|
|
||||||
import javax.naming.InitialContext;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Yao
|
* @author Yao
|
||||||
|
@ -1,11 +1,10 @@
|
|||||||
package com.zsc.edu.dify.modules.dify.controller;
|
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.exception.ExceptionUtil;
|
||||||
import com.zsc.edu.dify.framework.mybatisplus.DataPermission;
|
|
||||||
import com.zsc.edu.dify.framework.security.SecurityUtil;
|
import com.zsc.edu.dify.framework.security.SecurityUtil;
|
||||||
import com.zsc.edu.dify.modules.dify.service.AppEntityService;
|
import com.zsc.edu.dify.modules.dify.service.AppEntityService;
|
||||||
import com.zsc.edu.dify.modules.operationLog.entity.OperationLogAnnotation;
|
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.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;
|
||||||
@ -21,6 +20,9 @@ import org.springframework.security.access.prepost.PreAuthorize;
|
|||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
import reactor.core.publisher.Flux;
|
import reactor.core.publisher.Flux;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author yanghq
|
* @author yanghq
|
||||||
* @version 1.0
|
* @version 1.0
|
||||||
@ -132,5 +134,17 @@ public class V1ChatController {
|
|||||||
difyChat.deleteConversation(conversationId, apiKey,userId);
|
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);
|
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')")
|
@PreAuthorize("hasAuthority('dify:workflow:info')")
|
||||||
public WorkflowInfoResponse info(String workflowRunId, @PathVariable String appId) {
|
public WorkflowInfoResponse info(String workflowRunId, @PathVariable String appId) {
|
||||||
String apiKey =appEntityService.getApikey(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){
|
public List<WorkflowData> list(@PathVariable String appId){
|
||||||
return difyWorkflowService.list(new QueryWrapper<WorkflowData>().eq("app_id",appId));
|
return difyWorkflowService.list(new QueryWrapper<WorkflowData>().eq("app_id",appId));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
package com.zsc.edu.dify.modules.dify.entity;
|
package com.zsc.edu.dify.modules.dify.entity;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.annotation.FieldFill;
|
import com.baomidou.mybatisplus.annotation.FieldFill;
|
||||||
|
import com.baomidou.mybatisplus.annotation.IEnum;
|
||||||
import com.baomidou.mybatisplus.annotation.TableField;
|
import com.baomidou.mybatisplus.annotation.TableField;
|
||||||
import com.baomidou.mybatisplus.annotation.TableName;
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
import com.zsc.edu.dify.framework.json.JsonbTypeHandler;
|
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 io.github.guoshiqiufeng.dify.server.dto.response.AppsResponseVO;
|
||||||
import lombok.*;
|
import lombok.*;
|
||||||
|
|
||||||
@ -52,4 +52,22 @@ public class AppEntity extends AppsResponseVO {
|
|||||||
|
|
||||||
@TableField(value = "dept_id", fill = FieldFill.INSERT)
|
@TableField(value = "dept_id", fill = FieldFill.INSERT)
|
||||||
private Long deptId;
|
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);
|
boolean enabledApp(String id);
|
||||||
|
|
||||||
String getApikey(String appId);
|
String getApikey(String appId);
|
||||||
|
|
||||||
|
List<AppEntity> getAppsByAppType(Integer appType);
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package com.zsc.edu.dify.modules.dify.service.Impl;
|
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.core.conditions.query.QueryWrapper;
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
import com.zsc.edu.dify.exception.ConstraintException;
|
import com.zsc.edu.dify.exception.ConstraintException;
|
||||||
@ -90,4 +91,16 @@ public class AppEntityServiceImpl extends ServiceImpl<AppEntityRepository, AppEn
|
|||||||
return appEntityRepository.selectApiKey(appId);
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -93,7 +93,8 @@ class DeptServiceTest {
|
|||||||
assertEquals(tmp.getId(), dept2.id);
|
assertEquals(tmp.getId(), dept2.id);
|
||||||
// 不能改为其他已存在的同名同代码部门
|
// 不能改为其他已存在的同名同代码部门
|
||||||
assertThrows(ConstraintException.class,
|
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));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user