feat(dify): 更新菜单项并添加新功能

- 将 DiFyProxyBackend 菜单项改为 AI 菜单项
- 添加爬虫、文本和 PPT 相关的子菜单项- 更新权限控制,为新功能添加相应的权限
- 新增 PPT、Spider2 和 Word 控制器类
This commit is contained in:
zhuangtianxiang 2025-05-21 19:25:46 +08:00
parent c586a2239e
commit 0632d2b242
5 changed files with 149 additions and 28 deletions

View File

@ -0,0 +1,33 @@
package com.zsc.edu.dify.modules.dify.controller;
import com.zsc.edu.dify.exception.ExceptionUtil;
import com.zsc.edu.dify.framework.security.SecurityUtil;
import com.zsc.edu.dify.modules.dify.service.DifyWorkflowService;
import com.zsc.edu.dify.modules.operationLog.entity.OperationLogAnnotation;
import io.github.guoshiqiufeng.dify.workflow.dto.request.WorkflowRunRequest;
import io.github.guoshiqiufeng.dify.workflow.dto.response.WorkflowRunResponse;
import jakarta.annotation.Resource;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
@RestController
@RequestMapping("/api/ppt")
public class PPTController {
@Resource
private DifyWorkflowService difyWorkflowService;
/**
* 运行从可研申报书生成科技项目PPT_工作流
*
* @param request
* @return
*/
@PostMapping("/run")
@PreAuthorize("hasAuthority('dify:workflow:ppt')")
@OperationLogAnnotation(content = "'dify工作流'", operationType = "运行")
public WorkflowRunResponse runWorkflow(@RequestBody WorkflowRunRequest request) {
request.setUserId(SecurityUtil.getUserInfo().id.toString());
return ExceptionUtil.difyException(() -> difyWorkflowService.run(request, "ee3889b6-50fa-463e-b956-3b93447727fc"));
}
}

View File

@ -0,0 +1,35 @@
package com.zsc.edu.dify.modules.dify.controller;
import com.zsc.edu.dify.exception.ExceptionUtil;
import com.zsc.edu.dify.framework.security.SecurityUtil;
import com.zsc.edu.dify.modules.dify.service.DifyWorkflowService;
import com.zsc.edu.dify.modules.operationLog.entity.OperationLogAnnotation;
import io.github.guoshiqiufeng.dify.workflow.dto.request.WorkflowRunRequest;
import io.github.guoshiqiufeng.dify.workflow.dto.response.WorkflowRunResponse;
import jakarta.annotation.Resource;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/api/spider2")
public class Spider2Controller {
@Resource
private DifyWorkflowService difyWorkflowService;
/**
* 运行广州公共资源交易中心 招标小助手
*
* @param request
* @return
*/
@PostMapping("/run")
@PreAuthorize("hasAuthority('dify:spider2:run')")
@OperationLogAnnotation(content = "'dify工作流'", operationType = "运行")
public WorkflowRunResponse runWorkflow(@RequestBody WorkflowRunRequest request) {
request.setUserId(SecurityUtil.getUserInfo().id.toString());
return ExceptionUtil.difyException(() -> difyWorkflowService.run(request, "c736edd0-925d-4877-9223-56aab7342311"));
}
}

View File

@ -25,6 +25,7 @@ public class SpiderController {
private static final String API_KEY = "77c068fd-d5b6-4c33-97d8-db5511a09b26";
@PostMapping("/run")
@PreAuthorize("hasAuthority('dify:spider:run')")
public JSONObject run(@RequestBody SpiderDto dto) throws JsonProcessingException {
dto.setLlm_api_key(API_KEY);
String body = objectMapper.writeValueAsString(dto);
@ -37,6 +38,7 @@ public class SpiderController {
}
@PostMapping("/status")
@PreAuthorize("hasAuthority('dify:spider:status')")
public JSONObject status() {
return WebClient.create(SPIDER_URL).post().uri("/crawl_status")
.retrieve()
@ -45,6 +47,7 @@ public class SpiderController {
}
@PostMapping("/logs")
@PreAuthorize("hasAuthority('dify:spider:log')")
public JSONObject logs() {
return WebClient.create(SPIDER_URL).post().uri("/logs")
.retrieve()
@ -53,6 +56,7 @@ public class SpiderController {
}
@PostMapping("/stop")
@PreAuthorize("hasAuthority('dify:spider:stop')")
public JSONObject stop() {
return WebClient.create(SPIDER_URL).post().uri("/stop_crawl")
.retrieve()

View File

@ -0,0 +1,38 @@
package com.zsc.edu.dify.modules.dify.controller;
import com.zsc.edu.dify.exception.ExceptionUtil;
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 io.github.guoshiqiufeng.dify.chat.DifyChat;
import io.github.guoshiqiufeng.dify.chat.dto.request.ChatMessageSendRequest;
import io.github.guoshiqiufeng.dify.chat.dto.response.ChatMessageSendResponse;
import jakarta.annotation.Resource;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
@RestController
@RequestMapping("/api/word")
public class WordController {
@Resource
private DifyChat difyChat;
@Resource
private AppEntityService appEntityService;
/**
* 发送职业创新申报书_对话流路线
*
* @param sendRequest 消息参数 可以自定义参数调用 difyChat 实例时重新组装即可
* 用户 id可以改为从上下文token获取
* apikey 建议在数据库进行存储前端调用时传智能体 id从数据库查询
*/
@PostMapping("/completions")
@PreAuthorize("hasAuthority('dify:chat:word')")
@OperationLogAnnotation(content = "'dify对话'", operationType = "发送")
public ChatMessageSendResponse sendChatMessage(@RequestBody ChatMessageSendRequest sendRequest){
sendRequest.setApiKey(appEntityService.getApikey("baca08c1-e92b-4dc9-a445-3584803f54d4"));
sendRequest.setUserId(SecurityUtil.getUserInfo().id.toString());
return ExceptionUtil.difyException(()->difyChat.send(sendRequest));
}
}

View File

@ -32,8 +32,8 @@ class MenuServiceImplTest {
Menu user = new Menu(null, Menu.Type.PAGE, "User", "/user", "menu.user", "icon-user", true, false, 3, "user", "");
Menu message = new Menu(null, Menu.Type.PAGE, "Message", "/message", "消息管理", "icon-message", true, false, 4, "message", "");
Menu operationLog = new Menu(null, Menu.Type.PAGE, "OperationLog", "/operationLog", "操作日志", "icon-log", true, false, 6, "operationLog", "");
Menu difyProxyBackend = new Menu(null, Menu.Type.PAGE, "DiFyProxyBackend", "/diFyProxyBackend", "dify", "icon-dify", true, false, 5, "dify", "");
menuService.saveBatch(List.of(dashboard, system, user, message, operationLog,difyProxyBackend));
Menu ai = new Menu(null, Menu.Type.PAGE, "Ai", "/ai", "AI", "icon-ai", true, false, 5, "ai", "");
menuService.saveBatch(List.of(dashboard, system, user, message, operationLog,ai));
Menu workplace = new Menu(dashboard.getId(), Menu.Type.PAGE, "Workplace", "workplace", "工作台", "icon-dashboard", true, false, 1, "dashboard:workplace", "");
Menu role = new Menu(system.getId(), Menu.Type.PAGE, "Role", "role", "角色管理", null, true, false, 1, "system:role", "");
Menu dept = new Menu(system.getId(), Menu.Type.PAGE, "Dept", "dept", "部门管理", null, true, false, 2, "system:dept", "");
@ -43,8 +43,10 @@ class MenuServiceImplTest {
Menu notice = new Menu(message.getId(), Menu.Type.PAGE, "Notice", "notice", "通知管理", null, true, false, 1, "message:notice", "");
Menu bulletin = new Menu(message.getId(), Menu.Type.PAGE, "Bulletin", "bulletin", "公告管理", null, true, false, 2, "message:bulletin", "");
Menu log = new Menu(operationLog.getId(), Menu.Type.PAGE, "OperationLog", "operationLog", "操作日志", null, true, false, 1, "operationLog", "");
Menu dify = new Menu(difyProxyBackend.getId(), Menu.Type.PAGE, "Dify", "dify", "dify", null, true, false, 1, "dify", "");
menuService.saveBatch(List.of(workplace, dept, users, authority, menu, notice, bulletin,role, log, dify));
Menu aiSpider = new Menu(ai.getId(), Menu.Type.PAGE, "Spider", "spider", "爬虫", null, true, false, 1, "ai:spider", "");
Menu aiWord = new Menu(ai.getId(), Menu.Type.PAGE, "Word", "word", "文本", null, true, false, 2, "ai:word", "");
Menu aiPpt = new Menu(ai.getId(), Menu.Type.PAGE, "PPT", "ppt", "PPT", null, true, false, 3, "ai:ppt", "");
menuService.saveBatch(List.of(workplace, dept, users, authority, menu, notice, bulletin,role, log,aiSpider,aiWord,aiPpt));
Menu roleCreate = new Menu(role.getId(), Menu.Type.OPERATION, "roleCreate", null, "角色新增", null, true, false, 1, "system:role:create", "");
Menu roleDelete = new Menu(role.getId(), Menu.Type.OPERATION, "roleDelete", null, "角色删除", null, true, false, 1, "system:role:delete", "");
Menu roleUpdate = new Menu(role.getId(), Menu.Type.OPERATION, "roleUpdate", null, "角色修改", null, true, false, 1, "system:role:update", "");
@ -71,29 +73,36 @@ class MenuServiceImplTest {
Menu bulletinDelete = new Menu(bulletin.getId(), Menu.Type.OPERATION, "bulletinDelete", null, "公告删除", null, true, false, 1, "message:bulletin:delete", "");
Menu operationLogQuery = new Menu(operationLog.getId(), Menu.Type.OPERATION, "operationLogQuery", null, "操作日志查询", null, true, false, 1, "operationLog:query", "");
Menu operationLogDelete = new Menu(operationLog.getId(), Menu.Type.OPERATION, "operationLogDelete", null, "操作日志删除", null, true, false, 1, "operationLog:delete", "");
Menu difyChatQuery = new Menu(dify.getId(), Menu.Type.OPERATION, "difyChatQuery", null, "difyChat查询", null, true, false, 1, "dify:chat:query", "");
Menu difyChatCreate = new Menu(dify.getId(), Menu.Type.OPERATION, "difyChatCreate", null, "difyChat新增", null, true, false, 1, "dify:chat:create", "");
Menu difyChatUpdate = new Menu(dify.getId(), Menu.Type.OPERATION, "difyChatUpdate", null, "difyChat修改", null, true, false, 1, "dify:chat:update", "");
Menu difyChatStop = new Menu(dify.getId(), Menu.Type.OPERATION, "difyChatStop", null, "difyChat停止", null, true, false, 1, "dify:chat:stop", "");
Menu difyChatSend = new Menu(dify.getId(), Menu.Type.OPERATION, "difyChatSend", null, "difyChat发送", null, true, false, 1, "dify:chat:send", "");
Menu difyChatDelete = new Menu(dify.getId(), Menu.Type.OPERATION, "difyChatDelete", null, "difyChat删除", null, true, false, 1, "dify:chat:delete", "");
Menu difyServerQuery = new Menu(dify.getId(), Menu.Type.OPERATION, "difyServerQuery", null, "difyServer查询", null, true, false, 1, "dify:server:query", "");
Menu difyServerCreate = new Menu(dify.getId(), Menu.Type.OPERATION, "difyServerCreate", null, "difyServer新增", null, true, false, 1, "dify:server:create", "");
Menu difyServerUpdate = new Menu(dify.getId(), Menu.Type.OPERATION, "difyServerUpdate", null, "difyServer修改", null, true, false, 1, "dify:server:update", "");
Menu difyServerInit = new Menu(dify.getId(), Menu.Type.OPERATION, "difyServerInit", null, "difyServer初始化", null, true, false, 1, "dify:server:init", "");
Menu difyServerDelete = new Menu(dify.getId(), Menu.Type.OPERATION, "difyServerDelete", null, "difyServer删除", null, true, false, 1, "dify:server:delete", "");
Menu difyDataSetQuery = new Menu(dify.getId(), Menu.Type.OPERATION, "difyDataSetQuery", null, "difyDataSet查询", null, true, false, 1, "dify:dataset:query", "");
Menu difyDataSetCreate = new Menu(dify.getId(), Menu.Type.OPERATION, "difyDataSetCreate", null, "difyDataSet新增", null, true, false, 1, "dify:dataset:create", "");
Menu difyDataSetUpdate = new Menu(dify.getId(), Menu.Type.OPERATION, "difyDataSetUpdate", null, "difyDataSet修改", null, true, false, 1, "dify:dataset:update", "");
Menu difyDataSetRetrieve = new Menu(dify.getId(), Menu.Type.OPERATION, "difyDataSetRetrieve", null, "difyDataSet检索", null, true, false, 1, "dify:dataset:retrieve", "");
Menu difyDataSetDelete = new Menu(dify.getId(), Menu.Type.OPERATION, "difyDataSetDelete", null, "difyDataSet删除", null, true, false, 1, "dify:dataset:delete", "");
Menu difyWorkFlowQuery = new Menu(dify.getId(), Menu.Type.OPERATION, "difyWorkFlowQuery", null, "difyWorkFlow查询", null, true, false, 1, "dify:workflow:query", "");
Menu difyWorkFlowCreate = new Menu(dify.getId(), Menu.Type.OPERATION, "difyWorkFlowCreate", null, "difyWorkFlow新增", null, true, false, 1, "dify:workflow:create", "");
Menu difyWorkFlowUpdate = new Menu(dify.getId(), Menu.Type.OPERATION, "difyWorkFlowUpdate", null, "difyWorkFlow修改", null, true, false, 1, "dify:workflow:update", "");
Menu difyWorkFlowInfo = new Menu(dify.getId(), Menu.Type.OPERATION, "difyWorkFlowInfo", null, "difyWorkFlow信息", null, true, false, 1, "dify:workflow:info", "");
Menu difyWorkFlowLog = new Menu(dify.getId(), Menu.Type.OPERATION, "difyWorkFlowLog", null, "difyWorkFlow日志", null, true, false, 1, "dify:workflow:log", "");
Menu difyWorkFlowRun = new Menu(dify.getId(), Menu.Type.OPERATION, "difyWorkFlowRun", null, "difyWorkFlow运行", null, true, false, 1, "dify:workflow:run", "");
Menu difyWorkFlowDelete = new Menu(dify.getId(), Menu.Type.OPERATION, "difyWorkFlowDelete", null, "difyWorkFlow删除", null, true, false, 1, "dify:workflow:delete", "");
Menu difyChatQuery = new Menu(ai.getId(), Menu.Type.OPERATION, "difyChatQuery", null, "difyChat查询", null, true, false, 1, "dify:chat:query", "");
Menu difyChatCreate = new Menu(ai.getId(), Menu.Type.OPERATION, "difyChatCreate", null, "difyChat新增", null, true, false, 1, "dify:chat:create", "");
Menu difyChatUpdate = new Menu(ai.getId(), Menu.Type.OPERATION, "difyChatUpdate", null, "difyChat修改", null, true, false, 1, "dify:chat:update", "");
Menu difyChatStop = new Menu(ai.getId(), Menu.Type.OPERATION, "difyChatStop", null, "difyChat停止", null, true, false, 1, "dify:chat:stop", "");
Menu difyChatSend = new Menu(ai.getId(), Menu.Type.OPERATION, "difyChatSend", null, "difyChat发送", null, true, false, 1, "dify:chat:send", "");
Menu difyChatDelete = new Menu(ai.getId(), Menu.Type.OPERATION, "difyChatDelete", null, "difyChat删除", null, true, false, 1, "dify:chat:delete", "");
Menu difyServerQuery = new Menu(ai.getId(), Menu.Type.OPERATION, "difyServerQuery", null, "difyServer查询", null, true, false, 1, "dify:server:query", "");
Menu difyServerCreate = new Menu(ai.getId(), Menu.Type.OPERATION, "difyServerCreate", null, "difyServer新增", null, true, false, 1, "dify:server:create", "");
Menu difyServerUpdate = new Menu(ai.getId(), Menu.Type.OPERATION, "difyServerUpdate", null, "difyServer修改", null, true, false, 1, "dify:server:update", "");
Menu difyServerInit = new Menu(ai.getId(), Menu.Type.OPERATION, "difyServerInit", null, "difyServer初始化", null, true, false, 1, "dify:server:init", "");
Menu difyServerDelete = new Menu(ai.getId(), Menu.Type.OPERATION, "difyServerDelete", null, "difyServer删除", null, true, false, 1, "dify:server:delete", "");
Menu difyDataSetQuery = new Menu(ai.getId(), Menu.Type.OPERATION, "difyDataSetQuery", null, "difyDataSet查询", null, true, false, 1, "dify:dataset:query", "");
Menu difyDataSetCreate = new Menu(ai.getId(), Menu.Type.OPERATION, "difyDataSetCreate", null, "difyDataSet新增", null, true, false, 1, "dify:dataset:create", "");
Menu difyDataSetUpdate = new Menu(ai.getId(), Menu.Type.OPERATION, "difyDataSetUpdate", null, "difyDataSet修改", null, true, false, 1, "dify:dataset:update", "");
Menu difyDataSetRetrieve = new Menu(ai.getId(), Menu.Type.OPERATION, "difyDataSetRetrieve", null, "difyDataSet检索", null, true, false, 1, "dify:dataset:retrieve", "");
Menu difyDataSetDelete = new Menu(ai.getId(), Menu.Type.OPERATION, "difyDataSetDelete", null, "difyDataSet删除", null, true, false, 1, "dify:dataset:delete", "");
Menu difyWorkFlowQuery = new Menu(ai.getId(), Menu.Type.OPERATION, "difyWorkFlowQuery", null, "difyWorkFlow查询", null, true, false, 1, "dify:workflow:query", "");
Menu difyWorkFlowCreate = new Menu(ai.getId(), Menu.Type.OPERATION, "difyWorkFlowCreate", null, "difyWorkFlow新增", null, true, false, 1, "dify:workflow:create", "");
Menu difyWorkFlowUpdate = new Menu(ai.getId(), Menu.Type.OPERATION, "difyWorkFlowUpdate", null, "difyWorkFlow修改", null, true, false, 1, "dify:workflow:update", "");
Menu difyWorkFlowInfo = new Menu(ai.getId(), Menu.Type.OPERATION, "difyWorkFlowInfo", null, "difyWorkFlow信息", null, true, false, 1, "dify:workflow:info", "");
Menu difyWorkFlowLog = new Menu(ai.getId(), Menu.Type.OPERATION, "difyWorkFlowLog", null, "difyWorkFlow日志", null, true, false, 1, "dify:workflow:log", "");
Menu difyWorkFlowRun = new Menu(ai.getId(), Menu.Type.OPERATION, "difyWorkFlowRun", null, "difyWorkFlow运行", null, true, false, 1, "dify:workflow:run", "");
Menu difyWorkFlowDelete = new Menu(ai.getId(), Menu.Type.OPERATION, "difyWorkFlowDelete", null, "difyWorkFlow删除", null, true, false, 1, "dify:workflow:delete", "");
Menu difyWorkFlowPPT = new Menu(ai.getId(), Menu.Type.OPERATION, "difyWorkFlowPpt", null, "difyWorkFlowPPT", null, true, false, 1, "dify:workflow:ppt", "");
Menu difyChatWord = new Menu(ai.getId(), Menu.Type.OPERATION, "difyChatWord", null, "difyChatWord", null, true, false, 1, "dify:chat:word", "");
Menu difySpiderRun = new Menu(ai.getId(), Menu.Type.OPERATION, "difySpiderRun", null, "difySpiderRun", null, true, false, 1, "dify:spider:run", "");
Menu difySpiderStop = new Menu(ai.getId(), Menu.Type.OPERATION, "difySpiderStop", null, "difySpiderStop", null, true, false, 1, "dify:spider:stop", "");
Menu difySpider2Run = new Menu(ai.getId(), Menu.Type.OPERATION, "difySpider2Run", null, "difySpider2Run", null, true, false, 1, "dify:spider2:run", "");
Menu difySpiderStatus = new Menu(ai.getId(), Menu.Type.OPERATION, "difySpiderStatus", null, "difySpiderStatus", null, true, false, 1, "dify:spider:status", "");
Menu difySpiderLog = new Menu(ai.getId(), Menu.Type.OPERATION, "difySpiderLog", null, "difySpiderLog", null, true, false, 1, "dify:spider:log", "");
menuService.saveBatch(List.of(roleCreate, roleDelete, roleUpdate, roleQuery,
deptSave, deptUpdate, deptQuery, deptDelete,
userSave, userUpdate, userQuery, userDelete,
@ -104,7 +113,9 @@ class MenuServiceImplTest {
difyChatQuery, difyChatCreate, difyChatUpdate, difyChatDelete,difyChatSend,difyChatStop,
difyServerQuery, difyServerCreate, difyServerUpdate, difyServerDelete,difyServerInit,
difyDataSetQuery, difyDataSetCreate, difyDataSetUpdate, difyDataSetDelete,difyDataSetRetrieve,
difyWorkFlowQuery, difyWorkFlowCreate, difyWorkFlowUpdate, difyWorkFlowDelete, difyWorkFlowInfo,difyWorkFlowLog,difyWorkFlowRun
difyWorkFlowQuery, difyWorkFlowCreate, difyWorkFlowUpdate, difyWorkFlowDelete, difyWorkFlowInfo,difyWorkFlowLog,difyWorkFlowRun,
difyWorkFlowPPT, difyChatWord,
difySpiderRun, difySpiderStop, difySpider2Run, difySpiderStatus, difySpiderLog
));
}