dcs 1 week ago
parent
commit
4ff254f565

+ 127 - 10
virgo.api/src/main/java/com/bosshand/virgo/api/workark/controller/DifyController.java

@@ -1,27 +1,30 @@
 package com.bosshand.virgo.api.workark.controller;
 
-import com.bosshand.virgo.api.workark.model.DifyCompletion;
-import com.bosshand.virgo.api.workark.model.DifyType;
-import com.bosshand.virgo.api.workark.model.DifyWorkFlow;
-import com.bosshand.virgo.api.workark.model.HtmlCode;
+import com.bosshand.virgo.api.workark.model.*;
+import com.bosshand.virgo.api.workark.service.DifyDatasetService;
 import com.bosshand.virgo.api.workark.service.DifyService;
 import com.bosshand.virgo.core.response.Response;
-import io.swagger.annotations.Api;
-import io.swagger.annotations.ApiOperation;
+import com.bosshand.virgo.exception.Constant;
+import io.swagger.annotations.*;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
+import org.springframework.web.multipart.MultipartFile;
 
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Arrays;
+import java.util.List;
 import java.util.Map;
 
 @RestController
 @RequestMapping({"ai"})
-@Api(tags = {"dify"})
+@Api(tags = {"dify平台接口管理"})
 public class DifyController {
 
     @Autowired
     DifyService difyService;
 
-    @ApiOperation("保存dify类型")
+    @ApiOperation("新增dify类型")
     @RequestMapping(value = "/type", method = RequestMethod.POST)
     public Response insertType(@RequestBody DifyType difyType) {
         difyService.saveType(difyType);
@@ -41,7 +44,7 @@ public class DifyController {
         return Response.ok(difyService.getListType());
     }
 
-    @ApiOperation("保存HtmlCode")
+    @ApiOperation("新增HtmlCode")
     @RequestMapping(value = "/htmlCode", method = RequestMethod.POST)
     public Response insertHtmlCode(@RequestBody HtmlCode htmlCode) {
         return Response.ok(difyService.saveHtmlCode(htmlCode));
@@ -55,6 +58,9 @@ public class DifyController {
     }
 
     @ApiOperation("发布HtmlCode")
+    @ApiImplicitParams({
+            @ApiImplicitParam(name = "id", value = "HtmlCode记录id")
+    })
     @RequestMapping(value = "/htmlCode/publish/{id}", method = RequestMethod.GET)
     public Response publishHtmlCode(@PathVariable long id) {
         String simpleUUID = difyService.publishHtmlCode(id);
@@ -67,19 +73,28 @@ public class DifyController {
         return Response.ok(difyService.getListHtmlCode(htmlCode));
     }
 
-    @ApiOperation("HtmlCode详情")
+    @ApiOperation("获取HtmlCode详情")
+    @ApiImplicitParams({
+            @ApiImplicitParam(name = "id", value = "HtmlCode记录id")
+    })
     @RequestMapping(value = "/htmlCode/{id}", method = RequestMethod.GET)
     public Response getHtmlCode(@PathVariable long id) {
         return Response.ok(difyService.getHtmlCode(id));
     }
 
     @ApiOperation("执行workflow")
+    @ApiImplicitParams({
+            @ApiImplicitParam(name = "difyTypeId", value = "dify类型id")
+    })
     @RequestMapping(value = "/workflow/run/{difyTypeId}", method = RequestMethod.POST)
     public Response workFlowRun(@PathVariable long difyTypeId, @RequestBody Map<String, Object> inputs) {
         return Response.ok(difyService.workFlowRun(difyTypeId, inputs));
     }
 
     @ApiOperation("获取workflow执行情况")
+    @ApiImplicitParams({
+            @ApiImplicitParam(name = "simpleUUID", value = "workflow自动生成的UUID")
+    })
     @RequestMapping(value = "/workflow/{simpleUUID}", method = RequestMethod.GET)
     public Response getWorkFlow(@PathVariable String simpleUUID) {
         return Response.ok(difyService.getWorkFlow(simpleUUID));
@@ -93,12 +108,18 @@ public class DifyController {
 
     @ApiOperation("执行completion")
     @RequestMapping(value = "/completion/run/{difyTypeId}", method = RequestMethod.POST)
+    @ApiImplicitParams({
+            @ApiImplicitParam(name = "difyTypeId", value = "dify类型id")
+    })
     public Response completionRun(@PathVariable long difyTypeId, @RequestBody Map<String, Object> inputs) {
         return Response.ok(difyService.completionRun(difyTypeId, inputs));
     }
 
     @ApiOperation("获取completion执行情况")
     @RequestMapping(value = "/completion/{simpleUUID}", method = RequestMethod.GET)
+    @ApiImplicitParams({
+            @ApiImplicitParam(name = "simpleUUID", value = "completion自动生成的UUID")
+    })
     public Response getCompletion(@PathVariable String simpleUUID) {
         return Response.ok(difyService.getCompletion(simpleUUID));
     }
@@ -111,23 +132,35 @@ public class DifyController {
 
     @ApiOperation("执行对话型Chat")
     @RequestMapping(value = "/chat/run/{difyTypeId}", method = RequestMethod.POST)
+    @ApiImplicitParams({
+            @ApiImplicitParam(name = "difyTypeId", value = "dify类型id")
+    })
     public Response chatRun(@PathVariable long difyTypeId, @RequestBody Map<String, Object> inputs) {
         return Response.ok(difyService.chatRun(difyTypeId, inputs));
     }
 
     @ApiOperation("获取对话型Chat执行情况")
     @RequestMapping(value = "/chat/{simpleUUID}", method = RequestMethod.GET)
+    @ApiImplicitParams({
+            @ApiImplicitParam(name = "simpleUUID", value = "chat自动生成的UUID")
+    })
     public Response getChat(@PathVariable String simpleUUID) {
         return Response.ok(difyService.getChat(simpleUUID));
     }
 
     @ApiOperation("获取会话历史消息")
+    @ApiImplicitParams({
+            @ApiImplicitParam(name = "conversationId", value = "chat会话id")
+    })
     @RequestMapping(value = "/chat/message/{conversationId}", method = RequestMethod.GET)
     public Response chatMessageList(@PathVariable String conversationId) {
         return Response.ok(difyService.messageList(conversationId));
     }
 
     @ApiOperation("获取会话列表")
+    @ApiImplicitParams({
+            @ApiImplicitParam(name = "difyTypeId", value = "dify类型id")
+    })
     @RequestMapping(value = "/chat/conversations/{difyTypeId}", method = RequestMethod.GET)
     public Response chatConversations(@PathVariable long difyTypeId) {
         return Response.ok(difyService.conversations(difyTypeId));
@@ -135,10 +168,94 @@ public class DifyController {
 
     @ApiOperation("删除会话")
     @RequestMapping(value = "/chat/conversation/{conversationId}", method = RequestMethod.DELETE)
+    @ApiImplicitParams({
+            @ApiImplicitParam(name = "conversationId", value = "chat会话id")
+    })
     public Response deleteConversation(@PathVariable String conversationId) {
         difyService.deleteConversation(conversationId);
         return Response.ok();
     }
 
+    @Autowired
+    DifyDatasetService difyDatasetService;
+
+    @ApiOperation("获取知识库")
+    @RequestMapping(value = "/datasets/list", method = RequestMethod.POST)
+    public Response datasetList(@RequestBody DifyDataset difyDataset) {
+        return Response.ok(difyDatasetService.getList(difyDataset));
+    }
+
+    @ApiOperation("创建知识库")
+    @RequestMapping(value = "/dataset", method = RequestMethod.POST)
+    public Response createDataset(@RequestBody DifyDataset difyDataset) {
+        difyDatasetService.createDataset(difyDataset);
+        return Response.ok();
+    }
+
+    @ApiOperation("删除知识库")
+    @RequestMapping(value = "/datasets/{datasetId}", method = RequestMethod.DELETE)
+    @ApiImplicitParams({
+            @ApiImplicitParam(name = "datasetId", value = "知识库id")
+    })
+    public Response tearDown(@PathVariable String datasetId) {
+        difyDatasetService.tearDown(datasetId);
+        return Response.ok();
+    }
+
+    @ApiOperation("获取文档列表")
+    @RequestMapping(value = "/datasets/file/{datasetId}", method = RequestMethod.GET)
+    @ApiImplicitParams({
+            @ApiImplicitParam(name = "datasetId", value = "知识库id")
+    })
+    public Response getFileList(@PathVariable String datasetId) {
+        return Response.ok(difyDatasetService.getDocument(datasetId));
+    }
+
+    @ApiOperation("删除文档")
+    @RequestMapping(value = "/datasets/file/{documentId}", method = RequestMethod.DELETE)
+    @ApiImplicitParams({
+            @ApiImplicitParam(name = "documentId", value = "文档id")
+    })
+    public Response deleteFile(@PathVariable String documentId) {
+        difyDatasetService.deleteDocument(documentId);
+        return Response.ok();
+    }
+
+    private static final List<String> ALLOWED_TYPES = Arrays.asList("txt", "markdown", "md", "mdx", "pdf", "html", "xlsx", "xls", "docx", "csv", "vtt", "properties", "htm");
+
+    @ApiOperation("新增文档")
+    @RequestMapping(value = "/dataset/file/{datasetId}", method = RequestMethod.POST)
+    @ApiImplicitParams({
+            @ApiImplicitParam(name = "datasetId", value = "知识库id")
+    })
+    public Response createDocumentByFile(@ApiParam(name = "file", required = true) MultipartFile file, @PathVariable String datasetId) {
+        String fileName = file.getOriginalFilename();
+        String suffix = fileName.substring(fileName.lastIndexOf(".") + 1).toLowerCase();
+        // 验证文件类型
+        if (!ALLOWED_TYPES.contains(suffix)) {
+            return Response.fail(Constant.CODE_BAD_REQUEST, "文件格式不支持");
+        }
+
+        // 验证文件大小(15MB限制)
+        if (file.getSize() > 15 * 1024 * 1024) {
+            return Response.fail(Constant.CODE_BAD_REQUEST, "文件大小不能超过15MB");
+        }
+        InputStream inputStream = null;
+        try {
+            inputStream = file.getInputStream();
+            difyDatasetService.createDocumentByFile(inputStream, file.getOriginalFilename(), datasetId);
+            return Response.ok();
+        } catch (IOException e) {
+            return Response.fail(Constant.CODE_BAD_REQUEST, Constant.RET_INPUT_ERROR);
+        } finally {
+            if (inputStream != null) {
+                try {
+                    inputStream.close();
+                } catch (IOException e) {
+                }
+            }
+        }
+    }
+
 
 }

+ 20 - 0
virgo.api/src/main/java/com/bosshand/virgo/api/workark/dao/DifyDatasetDao.java

@@ -0,0 +1,20 @@
+package com.bosshand.virgo.api.workark.dao;
+
+import com.bosshand.virgo.api.workark.model.DifyDataset;
+import org.apache.ibatis.annotations.Mapper;
+
+import java.util.List;
+
+@Mapper
+public interface DifyDatasetDao {
+
+    void save(DifyDataset difyDataset);
+
+    void update(DifyDataset difyDataset);
+
+    List<DifyDataset> getList(DifyDataset difyDataset);
+
+    DifyDataset getDatasetId(String datasetId);
+
+    void delete(String datasetId);
+}

+ 20 - 0
virgo.api/src/main/java/com/bosshand/virgo/api/workark/dao/DifyDatasetDocumentDao.java

@@ -0,0 +1,20 @@
+package com.bosshand.virgo.api.workark.dao;
+
+import com.bosshand.virgo.api.workark.model.DifyDatasetDocument;
+import org.apache.ibatis.annotations.Mapper;
+
+import java.util.List;
+
+@Mapper
+public interface DifyDatasetDocumentDao {
+
+    void save(DifyDatasetDocument difyDatasetDocument);
+
+    List<DifyDatasetDocument> getDatasetId(String datasetId);
+
+    void delete(String documentId);
+
+    DifyDatasetDocument getDocumentId(String documentId);
+
+    void deleteDatasetId(String datasetId);
+}

+ 97 - 0
virgo.api/src/main/java/com/bosshand/virgo/api/workark/model/DifyDataset.java

@@ -0,0 +1,97 @@
+package com.bosshand.virgo.api.workark.model;
+
+import com.fasterxml.jackson.annotation.JsonFormat;
+
+import java.util.Date;
+
+/**
+ * dify 知识库
+ */
+public class DifyDataset {
+
+    private long id;
+
+    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
+    private Date date;
+
+    /**
+     * 知识库id
+     */
+    private String datasetId;
+
+    /**
+     * 知识库名称
+     */
+    private String name;
+
+    /**
+     * 知识库描述
+     */
+    private String description;
+
+    /**
+     * 用户id
+     */
+    private long userId;
+
+    /**
+     * 组织id
+     */
+    private long organizationId;
+
+    public long getId() {
+        return id;
+    }
+
+    public void setId(long id) {
+        this.id = id;
+    }
+
+    public Date getDate() {
+        return date;
+    }
+
+    public void setDate(Date date) {
+        this.date = date;
+    }
+
+    public String getDatasetId() {
+        return datasetId;
+    }
+
+    public void setDatasetId(String datasetId) {
+        this.datasetId = datasetId;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public String getDescription() {
+        return description;
+    }
+
+    public void setDescription(String description) {
+        this.description = description;
+    }
+
+    public long getUserId() {
+        return userId;
+    }
+
+    public void setUserId(long userId) {
+        this.userId = userId;
+    }
+
+    public long getOrganizationId() {
+        return organizationId;
+    }
+
+    public void setOrganizationId(long organizationId) {
+        this.organizationId = organizationId;
+    }
+}

+ 71 - 0
virgo.api/src/main/java/com/bosshand/virgo/api/workark/model/DifyDatasetDocument.java

@@ -0,0 +1,71 @@
+package com.bosshand.virgo.api.workark.model;
+
+import com.fasterxml.jackson.annotation.JsonFormat;
+
+import java.util.Date;
+
+/**
+ * dify 知识库文件
+ */
+public class DifyDatasetDocument {
+
+    private long id;
+
+    /**
+     * 知识库id
+     */
+    private String datasetId;
+
+    /**
+     * 文档id
+     */
+    private String documentId;
+
+    /**
+     * 文档名称
+     */
+    private String name;
+
+    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
+    private Date date;
+
+    public long getId() {
+        return id;
+    }
+
+    public void setId(long id) {
+        this.id = id;
+    }
+
+    public String getDatasetId() {
+        return datasetId;
+    }
+
+    public void setDatasetId(String datasetId) {
+        this.datasetId = datasetId;
+    }
+
+    public String getDocumentId() {
+        return documentId;
+    }
+
+    public void setDocumentId(String documentId) {
+        this.documentId = documentId;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public Date getDate() {
+        return date;
+    }
+
+    public void setDate(Date date) {
+        this.date = date;
+    }
+}

+ 207 - 0
virgo.api/src/main/java/com/bosshand/virgo/api/workark/service/DifyDatasetService.java

@@ -0,0 +1,207 @@
+package com.bosshand.virgo.api.workark.service;
+
+import com.bosshand.virgo.api.workark.dao.DifyDatasetDao;
+import com.bosshand.virgo.api.workark.dao.DifyDatasetDocumentDao;
+import com.bosshand.virgo.api.workark.model.DifyDataset;
+import com.bosshand.virgo.api.workark.model.DifyDatasetDocument;
+import io.github.imfangs.dify.client.DifyClientFactory;
+import io.github.imfangs.dify.client.DifyDatasetsClient;
+import io.github.imfangs.dify.client.exception.DifyApiException;
+import io.github.imfangs.dify.client.model.datasets.*;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.List;
+
+@Service
+public class DifyDatasetService {
+
+    @Autowired
+    DifyDatasetDao difyDatasetDao;
+
+    @Autowired
+    DifyDatasetDocumentDao difyDatasetDocumentDao;
+
+    private DifyDatasetsClient getClient() {
+        return DifyClientFactory.createDatasetsClient("http://203.110.233.149:9000/v1", "dataset-SWjJp6FOFqT85n7KxxyCFPSS");
+    }
+
+    /**
+     * 获取知识库列表
+     */
+    public List<DifyDataset> getList(DifyDataset difyDataset) {
+        return difyDatasetDao.getList(difyDataset);
+    }
+
+    /**
+     * 删除知识库
+     */
+    public void tearDown(String datasetId) {
+        if (datasetId != null) {
+            try {
+                getClient().deleteDataset(datasetId);
+                difyDatasetDao.delete(datasetId);
+                difyDatasetDocumentDao.deleteDatasetId(datasetId);
+                System.out.println("删除测试知识库成功,ID: " + datasetId);
+            } catch (Exception e) {
+                System.err.println("删除测试知识库失败: " + e.getMessage());
+            }
+        }
+    }
+
+    /**
+     * 创建知识库
+     */
+    public void createDataset(DifyDataset difyDataset) {
+        // 创建知识库请求
+        CreateDatasetRequest request = CreateDatasetRequest.builder()
+                .name(difyDataset.getName())
+                .description(difyDataset.getDescription())
+                .indexingTechnique("high_quality")
+                .permission("only_me")
+                .provider("vendor")
+                .build();
+
+        // 发送请求
+        try {
+            DatasetResponse response = getClient().createDataset(request);
+            difyDataset.setDatasetId(response.getId());
+            difyDatasetDao.save(difyDataset);
+        } catch (IOException e) {
+            e.printStackTrace();
+        } catch (DifyApiException e) {
+            e.printStackTrace();
+        }
+    }
+
+    /**
+     * 获取知识库详情
+     */
+    public void getDataset(String datasetId) throws IOException, DifyApiException {
+        // 获取知识库详情
+        DatasetResponse response = getClient().getDataset(datasetId);
+
+        // 打印知识库详情
+        System.out.println("知识库详情:");
+        System.out.println("  ID: " + response.getId());
+        System.out.println("  名称: " + response.getName());
+        System.out.println("  描述: " + response.getDescription());
+        System.out.println("  权限: " + response.getPermission());
+        System.out.println("  索引技术: " + response.getIndexingTechnique());
+        System.out.println("  文档数量: " + response.getDocumentCount());
+        System.out.println("  字数: " + response.getWordCount());
+        System.out.println("  嵌入模型: " + response.getEmbeddingModel());
+        System.out.println("  嵌入模型提供商: " + response.getEmbeddingModelProvider());
+
+        if (response.getRetrievalModelDict() != null) {
+            System.out.println("  检索模型:");
+            System.out.println("    搜索方法: " + response.getRetrievalModelDict().getSearchMethod());
+            System.out.println("    Top-K: " + response.getRetrievalModelDict().getTopK());
+            System.out.println("    重排序启用: " + response.getRetrievalModelDict().getRerankingEnable());
+        }
+    }
+
+    /**
+     * 更新知识库
+     */
+    public void updateDataset(DifyDataset difyDataset) throws IOException, DifyApiException {
+        // 构建更新请求
+        UpdateDatasetRequest.RetrievalModel retrievalModel = UpdateDatasetRequest.RetrievalModel.builder()
+                .searchMethod("semantic_search")
+                .rerankingEnable(false)
+                .topK(3)
+                .scoreThresholdEnabled(false)
+                .build();
+
+        UpdateDatasetRequest request = UpdateDatasetRequest.builder()
+                .name(difyDataset.getName())
+                .indexingTechnique("high_quality")
+                .permission("only_me")
+                .retrievalModel(retrievalModel)
+                .partialMemberList(java.util.Arrays.asList())
+                .build();
+
+        // 发送更新请求
+        DatasetResponse response = getClient().updateDataset(difyDataset.getDatasetId(), request);
+
+        difyDatasetDao.update(difyDataset);
+
+        // 打印更新结果
+        System.out.println("知识库更新成功:");
+        System.out.println("  ID: " + response.getId());
+        System.out.println("  新名称: " + response.getName());
+        System.out.println("  索引技术: " + response.getIndexingTechnique());
+        System.out.println("  权限: " + response.getPermission());
+
+        if (response.getRetrievalModelDict() != null) {
+            System.out.println("  检索模型已更新:");
+            System.out.println("    搜索方法: " + response.getRetrievalModelDict().getSearchMethod());
+            System.out.println("    Top-K: " + response.getRetrievalModelDict().getTopK());
+        }
+    }
+
+    /**
+     * 通过文件创建文档
+     */
+    public void createDocumentByFile(InputStream inputStream, String fileName, String datasetId) {
+        RetrievalModel retrievalModel = new RetrievalModel();
+        retrievalModel.setSearchMethod("hybrid_search");
+        retrievalModel.setRerankingEnable(false);
+        retrievalModel.setTopK(2);
+        retrievalModel.setScoreThresholdEnabled(false);
+
+        // 创建文档请求
+        CreateDocumentByFileRequest request = CreateDocumentByFileRequest.builder()
+                .indexingTechnique("economy")
+                .docForm("text_model")
+                // 1.1.3 invalid_param (400) - Must not be null! 【doc_language】
+                .docLanguage("Chinese")
+                // 1.1.3 invalid_param (400) - Must not be null! 【retrieval_model】
+                .retrievalModel(retrievalModel)
+                // 没有这里的设置,会500报错,服务器内部错误
+                .processRule(ProcessRule.builder().mode("automatic").build())
+                .build();
+
+        // 发送请求
+        try {
+            DocumentResponse response = getClient().createDocumentByFile(datasetId, request, inputStream, fileName);
+            // 保存文档ID
+            String documentId = response.getDocument().getId();
+            DifyDatasetDocument difyDatasetDocument = new DifyDatasetDocument();
+            difyDatasetDocument.setDatasetId(datasetId);
+            difyDatasetDocument.setDocumentId(documentId);
+            difyDatasetDocument.setName(fileName);
+            difyDatasetDocumentDao.save(difyDatasetDocument);
+            System.out.println("创建测试文档成功,ID: " + documentId);
+        } catch (IOException e) {
+            e.printStackTrace();
+        } catch (DifyApiException e) {
+            e.printStackTrace();
+        }
+    }
+
+    /**
+     * 删除文档
+     */
+    public void deleteDocument(String documentId) {
+        DifyDatasetDocument document = difyDatasetDocumentDao.getDocumentId(documentId);
+        try {
+            getClient().deleteDocument(document.getDatasetId(), documentId);
+            difyDatasetDocumentDao.delete(documentId);
+        } catch (IOException e) {
+            e.printStackTrace();
+        } catch (DifyApiException e) {
+            e.printStackTrace();
+        }
+    }
+
+    /**
+     * 获取文档列表
+     */
+    public List<DifyDatasetDocument> getDocument(String datasetId) {
+        return difyDatasetDocumentDao.getDatasetId(datasetId);
+    }
+
+}

+ 33 - 0
virgo.api/src/main/resources/mapper/DifyDatasetDocumentMapper.xml

@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
+<mapper namespace="com.bosshand.virgo.api.workark.dao.DifyDatasetDocumentDao">
+
+    <resultMap type="com.bosshand.virgo.api.workark.model.DifyDatasetDocument" id="result">
+        <id column="id" property="id"/>
+        <result column="datasetId" property="datasetId"/>
+        <result column="documentId" property="documentId"/>
+        <result column="name" property="name"/>
+        <result column="date" property="date"/>
+    </resultMap>
+
+    <insert id="save" parameterType="com.bosshand.virgo.api.workark.model.DifyDatasetDocument" useGeneratedKeys="true" keyProperty="id">
+        INSERT INTO dify_dataset_document(`datasetId`, `documentId`, `name`, `date`) VALUES (#{datasetId}, #{documentId}, #{name}, now())
+    </insert>
+
+    <select id="getDatasetId" resultMap="result">
+        select * from dify_dataset_document where datasetId = #{datasetId}
+    </select>
+
+    <select id="getDocumentId" resultMap="result">
+        select * from dify_dataset_document where documentId = #{documentId}
+    </select>
+
+    <delete id="delete">
+        delete from dify_dataset_document where documentId = #{documentId}
+    </delete>
+
+    <delete id="deleteDatasetId">
+        delete from dify_dataset_document where datasetId = #{datasetId}
+    </delete>
+
+</mapper>

+ 48 - 0
virgo.api/src/main/resources/mapper/DifyDatasetMapper.xml

@@ -0,0 +1,48 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
+<mapper namespace="com.bosshand.virgo.api.workark.dao.DifyDatasetDao">
+
+    <resultMap type="com.bosshand.virgo.api.workark.model.DifyDataset" id="result">
+        <id column="id" property="id"/>
+        <result column="date" property="date"/>
+        <result column="datasetId" property="datasetId"/>
+        <result column="name" property="name"/>
+        <result column="description" property="description"/>
+        <result column="userId" property="userId"/>
+        <result column="organizationId" property="organizationId"/>
+    </resultMap>
+
+    <insert id="save" parameterType="com.bosshand.virgo.api.workark.model.DifyDataset" useGeneratedKeys="true" keyProperty="id">
+        INSERT INTO dify_dataset(`date`, `datasetId`, `name`, `description`, `userId`, `organizationId`) VALUES (now(), #{datasetId}, #{name}, #{description}, #{userId}, #{organizationId})
+    </insert>
+
+    <update id="update" parameterType="com.bosshand.virgo.api.workark.model.DifyDataset">
+        UPDATE dify_dataset
+        <trim prefix="set" suffixOverrides=",">
+            <if test="name != null">name = #{name},</if>
+            <if test="description != null">description = #{description},</if>
+        </trim>
+        WHERE id=#{id}
+    </update>
+
+    <select id="getList" resultMap="result">
+        select * from dify_dataset
+        <where>
+        <if test="userId != 0">
+            and userId = #{userId}
+        </if>
+            <if test="organizationId != 0">
+                and organizationId = #{organizationId}
+            </if>
+        </where>
+    </select>
+
+    <select id="getDatasetId" resultMap="result">
+        select * from dify_dataset where datasetId =#{datasetId}
+    </select>
+
+    <delete id="delete">
+        delete from dify_dataset where datasetId = #{datasetId}
+    </delete>
+
+</mapper>

+ 2 - 2
virgo.core/pom.xml

@@ -49,13 +49,13 @@
 		<dependency>
 			<groupId>io.springfox</groupId>
 			<artifactId>springfox-swagger2</artifactId>
-			<version>2.4.0</version>
+			<version>2.9.2</version>
 		</dependency>
 
 		<dependency>
 			<groupId>io.springfox</groupId>
 			<artifactId>springfox-swagger-ui</artifactId>
-			<version>2.4.0</version>
+			<version>2.9.2</version>
 		</dependency>
 
 		<!-- springboot,mybatis 整合包 -->

+ 26 - 0
virgo.core/src/main/java/com/bosshand/virgo/core/CorsConfig.java

@@ -0,0 +1,26 @@
+package com.bosshand.virgo.core;
+
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.web.cors.CorsConfiguration;
+import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
+import org.springframework.web.filter.CorsFilter;
+
+@Configuration
+public class CorsConfig {
+	private CorsConfiguration buildConfig() {
+		CorsConfiguration corsConfiguration = new CorsConfiguration();
+		corsConfiguration.addAllowedOrigin("*");
+		corsConfiguration.addAllowedHeader("*");
+		corsConfiguration.addAllowedMethod("*");
+		return corsConfiguration;
+	}
+
+	@Bean
+	public CorsFilter corsFilter() {
+		UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
+		source.registerCorsConfiguration("/**", buildConfig());
+		return new CorsFilter(source);
+	}
+
+}

+ 26 - 0
virgo.file/src/main/java/com/bosshand/virgo/file/CorsConfig.java

@@ -0,0 +1,26 @@
+package com.bosshand.virgo.file;
+
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.web.cors.CorsConfiguration;
+import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
+import org.springframework.web.filter.CorsFilter;
+
+@Configuration
+public class CorsConfig {
+	private CorsConfiguration buildConfig() {
+		CorsConfiguration corsConfiguration = new CorsConfiguration();
+		corsConfiguration.addAllowedOrigin("*");
+		corsConfiguration.addAllowedHeader("*");
+		corsConfiguration.addAllowedMethod("*");
+		return corsConfiguration;
+	}
+
+	@Bean
+	public CorsFilter corsFilter() {
+		UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
+		source.registerCorsConfiguration("/**", buildConfig());
+		return new CorsFilter(source);
+	}
+
+}