Browse Source

20250415 dify功能修改

lrj 4 months ago
parent
commit
a806688e54

+ 23 - 11
pom.xml

@@ -23,7 +23,7 @@
         <google.code.gson.version>2.7</google.code.gson.version>
         <hutool.version>5.6.5</hutool.version>
         <okhttps.version>4.10.0</okhttps.version>
-        <poi.version>4.1.2</poi.version>
+        <poi.version>5.2.5</poi.version>
         <poi-tl.version>1.10.3</poi-tl.version>
         <druid.version>1.1.20</druid.version>
         <fastjson.version>2.0.12</fastjson.version>
@@ -68,16 +68,16 @@
             <artifactId>fastjson</artifactId>
             <version>${fastjson.version}</version>
         </dependency>
-        <dependency>
-            <groupId>org.apache.commons</groupId>
-            <artifactId>commons-compress</artifactId>
-            <version>1.21</version>
-        </dependency>
-        <dependency>
-            <groupId>commons-io</groupId>
-            <artifactId>commons-io</artifactId>
-            <version>2.6</version>
-        </dependency>
+<!--        <dependency>-->
+<!--            <groupId>org.apache.commons</groupId>-->
+<!--            <artifactId>commons-compress</artifactId>-->
+<!--            <version>1.21</version>-->
+<!--        </dependency>-->
+<!--        <dependency>-->
+<!--            <groupId>commons-io</groupId>-->
+<!--            <artifactId>commons-io</artifactId>-->
+<!--            <version>2.6</version>-->
+<!--        </dependency>-->
         <dependency>
             <groupId>io.jsonwebtoken</groupId>
             <artifactId>jjwt</artifactId>
@@ -289,6 +289,13 @@
             <artifactId>flexmark-all</artifactId>
             <version>0.64.8</version>
         </dependency>
+
+        <dependency>
+            <groupId>com.aspose</groupId>
+            <artifactId>aspose-words</artifactId>
+            <version>22.10</version> <!-- 替换为最新版本 -->
+            <classifier>jdk17</classifier>
+        </dependency>
     </dependencies>
 
     <build>
@@ -339,6 +346,11 @@
     <!--阿里云镜像源(因需要提交到GithubActions,会引起依赖下载过慢的问题)-->
     <repositories>
         <repository>
+            <id>AsposeJavaAPI</id>
+            <name>Aspose Java API Repository</name>
+            <url>https://repository.aspose.com/repo/</url>
+        </repository>
+        <repository>
             <id>nexus-aliyun</id>
             <name>nexus-aliyun</name>
             <url>http://maven.aliyun.com/nexus/content/groups/public/</url>

+ 15 - 0
src/main/java/cn/cslg/pas/common/model/poi/PoiRemarkVO.java

@@ -0,0 +1,15 @@
+package cn.cslg.pas.common.model.poi;
+
+import lombok.Data;
+
+import java.math.BigInteger;
+
+@Data
+public class PoiRemarkVO {
+    private BigInteger commentId;
+    private Integer index;
+    private String trueContent;
+    private Integer remarkType;
+    private String type;
+    private String reason;
+}

+ 17 - 0
src/main/java/cn/cslg/pas/common/model/poi/PoiWordRunVO.java

@@ -0,0 +1,17 @@
+package cn.cslg.pas.common.model.poi;
+
+import lombok.Data;
+
+@Data
+public class PoiWordRunVO {
+    private Integer index;
+
+    private Integer lastIndex;
+    private String content;//原文内容
+
+    private String trueContent;
+
+    private Boolean ifRemark;
+    private String type;
+    private String reason;
+}

+ 1 - 1
src/main/java/cn/cslg/pas/common/utils/ExcelUtils.java

@@ -167,7 +167,7 @@ public class ExcelUtils {
 
     public static String getValue(Cell cell) {
         if (cell != null) {
-            if (cell.getCellType() == CellType.NUMERIC && HSSFDateUtil.isCellDateFormatted(cell)) {
+            if (cell.getCellType() == CellType.NUMERIC && DateUtil.isCellDateFormatted(cell)) {
                 Date date = cell.getDateCellValue();
                 SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
                 String dateString = dateFormat.format(date);

+ 1 - 1
src/main/java/cn/cslg/pas/common/utils/ReadExcelUtils.java

@@ -220,7 +220,7 @@ public class ReadExcelUtils {
 
     public static String getValue(Cell cell) {
         if (cell != null) {
-            if (cell.getCellType() == CellType.NUMERIC && HSSFDateUtil.isCellDateFormatted(cell)) {
+            if (cell.getCellType() == CellType.NUMERIC && DateUtil.isCellDateFormatted(cell)) {
                 Date date = cell.getDateCellValue();
                 SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
                 String dateString = dateFormat.format(date);

+ 34 - 0
src/main/java/cn/cslg/pas/common/utils/StringUtils.java

@@ -526,4 +526,38 @@ public class StringUtils {
     public static <T> String join(String[] list, String separator) {
         return org.apache.commons.lang3.StringUtils.join(list, separator);
     }
+
+
+    public static List<String> splitChineseText(String text,Integer textNum) {
+        List<String> chunks = new ArrayList<>();
+        int start = 0;
+        int textLength = text.length();
+        if (text.length() < textNum) {
+            chunks.add(text);
+            return chunks;
+        }
+        while (start < textLength) {
+            // 计算当前块的最大可能结束位置
+            int end = Math.min(start + textNum, textLength);
+            int lastSentenceEnd = -1;
+
+            // 从后向前查找最后一个句号
+            for (int i = end - 1; i >= start; i--) {
+                if (text.charAt(i) == '。') {
+                    lastSentenceEnd = i;
+                    break;
+                }
+            }
+
+            if (lastSentenceEnd != -1) {
+                // 切割文本并添加到结果集
+                chunks.add(text.substring(start, lastSentenceEnd + 1));
+                start = lastSentenceEnd + 1;
+            } else {
+                // 异常处理:当前2000字符范围内没有句号
+                throw new RuntimeException("文本位置 " + start + " 至 " + end + " 之间未找到句号,请检查输入文本格式");
+            }
+        }
+        return chunks;
+    }
 }

+ 21 - 0
src/main/java/cn/cslg/pas/controller/outApi/DifyController.java

@@ -15,6 +15,7 @@ import cn.cslg.pas.service.business.ReportProjectService;
 import cn.cslg.pas.service.business.TaskCodeService;
 import cn.cslg.pas.service.business.es.EsPatentVectorService;
 import cn.cslg.pas.service.common.DifyService;
+import cn.cslg.pas.service.common.POIService;
 import cn.cslg.pas.service.dify.DifySessionService;
 import com.alibaba.fastjson2.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
@@ -22,15 +23,22 @@ import com.fasterxml.jackson.databind.JsonNode;
 import com.google.gson.JsonObject;
 import io.swagger.v3.oas.annotations.Operation;
 import io.swagger.v3.oas.annotations.tags.Tag;
+import jakarta.servlet.http.HttpServletRequest;
 import jakarta.servlet.http.HttpServletResponse;
 import lombok.RequiredArgsConstructor;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.context.annotation.Lazy;
+import org.springframework.core.io.InputStreamResource;
 import org.springframework.http.MediaType;
+import org.springframework.http.ResponseEntity;
 import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestMethod;
 import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.context.request.RequestAttributes;
+import org.springframework.web.context.request.RequestContextHolder;
+import org.springframework.web.context.request.ServletRequestAttributes;
+import org.springframework.web.multipart.MultipartFile;
 import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;
 import reactor.core.publisher.Flux;
 
@@ -47,6 +55,7 @@ import java.util.List;
 public class DifyController {
     private final DifyService difyService;
     private final DifySessionService difySessionService;
+    private final POIService poiService;
     @Autowired
     private CacheUtils cacheUtils;
     @Autowired
@@ -86,4 +95,16 @@ public class DifyController {
     public Response generateInventionPoint(@RequestBody ChatMessageDTO chatMessageDTO) throws IOException {
         return Response.success(difyService.generateInventionPoint(chatMessageDTO));
     }
+
+    //
+    @RequestMapping(value = "/getCheckFile", method = RequestMethod.POST)
+    @Operation(summary = "获取质检文件")
+    public ResponseEntity<InputStreamResource> addConfessionSession(MultipartFile file) throws Exception {
+        RequestAttributes ra = RequestContextHolder.getRequestAttributes();
+        ServletRequestAttributes sra = (ServletRequestAttributes) ra;
+        HttpServletRequest httpRequest = sra.getRequest();
+     String a=   httpRequest.getHeader("Content-Type");
+          System.out.println(a);
+        return  poiService.exportCheckFile(file);
+    }
 }

File diff suppressed because it is too large
+ 1417 - 0
src/main/java/cn/cslg/pas/service/TemplateExportService.java


+ 46 - 0
src/main/java/cn/cslg/pas/service/common/DifyService.java

@@ -54,6 +54,9 @@ import java.util.concurrent.TimeUnit;
 public class DifyService {
     @Value("${DIFY.apiKey}")
     private String apiKey;
+
+    @Value("${DIFY.checkApiKey}")
+    private String checkApiKey;
     @Value("${DIFY.url}")
     private String url;
     @Value("${FileDownloadUrl}")
@@ -314,4 +317,47 @@ public class DifyService {
         map1.put("confessionSessionId",confessionSessionId);
         return map1;
     }
+
+
+
+    /**
+     * 调用质检
+     */
+    public String WordErrorWorkFlow(DifyChatMessageDTO difyChatMessageDTO) throws IOException {
+        String param = new Gson().toJson(difyChatMessageDTO);
+        RequestBody requestBody = RequestBody.create(MediaType.parse("application/json"), param);
+        OkHttpClient okHttpClient = new OkHttpClient.Builder()
+                .connectTimeout(600, TimeUnit.SECONDS)
+                .writeTimeout(600, TimeUnit.SECONDS)
+                .readTimeout(600, TimeUnit.SECONDS)
+                .build();
+        Request request = new Request.Builder()
+                .url(url + "workflows/run")
+                .post(requestBody)
+                .addHeader("Authorization", "Bearer " + checkApiKey)
+                .build();
+        return Objects.requireNonNull(okHttpClient.newCall(request).execute().body()).string();
+    }
+    /**
+     * 获取具体实施方式
+     */
+    public String getImplementation(Map<String,Object> map) throws IOException {
+        String param = new Gson().toJson(map);
+        RequestBody requestBody = RequestBody.create(MediaType.parse("application/json"), param);
+        OkHttpClient okHttpClient = new OkHttpClient.Builder()
+                .connectTimeout(60, TimeUnit.SECONDS)
+                .writeTimeout(60, TimeUnit.SECONDS)
+                .readTimeout(60, TimeUnit.SECONDS)
+                .build();
+        Request request = new Request.Builder()
+                .url(url + "chat-messages")
+                .post(requestBody)
+                .addHeader("Authorization", "Bearer " + checkApiKey)
+                .build();
+        return Objects.requireNonNull(okHttpClient.newCall(request).execute().body()).string();
+    }
+
+    /**
+     *
+     */
 }

File diff suppressed because it is too large
+ 391 - 0
src/main/java/cn/cslg/pas/service/common/POIService.java


+ 3 - 3
src/main/java/cn/cslg/pas/service/common/PatentStarApiService.java

@@ -195,9 +195,9 @@ public class PatentStarApiService {
         String signMd5 = FormatUtil.MD5(Sign);
         // 创建一个OkHttpClient对象
         OkHttpClient okHttpClient = new OkHttpClient.Builder()
-                .connectTimeout(5, TimeUnit.SECONDS)
-                .writeTimeout(5, TimeUnit.SECONDS)
-                .readTimeout(5, TimeUnit.SECONDS)
+                .connectTimeout(10, TimeUnit.SECONDS)
+                .writeTimeout(10, TimeUnit.SECONDS)
+                .readTimeout(10, TimeUnit.SECONDS)
                 .addInterceptor(new PatentStarApiService.OkhttpInterceptor(3))
                 .build();
 

+ 5 - 0
src/main/resources/application-dev.yml

@@ -1,4 +1,8 @@
 spring:
+  servlet:
+    multipart:
+      max-file-size: 10MB
+      max-request-size: 10MB
   rabbitmq:
     host: 192.168.2.24
     port: 5672
@@ -87,4 +91,5 @@ management:
       show-details: always
 DIFY:
   apiKey: app-DDGJt4QUmzlc2aFQ5voOAXIj
+  checkApiKey: app-lrLVnigc6GPyJPMLmaqX22BO
   url: http://192.168.2.24/v1/

+ 28 - 0
src/test/java/cn/cslg/pas/DifyTest.java

@@ -0,0 +1,28 @@
+package cn.cslg.pas;
+
+import cn.cslg.pas.common.utils.FileUtils;
+import cn.cslg.pas.service.common.POIService;
+import org.apache.poi.xwpf.usermodel.XWPFDocument;
+import org.junit.jupiter.api.Test;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.context.SpringBootTest;
+
+import java.io.File;
+import java.io.FileOutputStream;
+@SpringBootTest
+public class DifyTest {
+@Autowired
+private POIService poiService;
+
+    @Test
+    public void checkFile() throws Exception {
+//        String path = "E:\\temfile\\poi\\test1.docx";
+//        File file=new File(path);
+//
+//        XWPFDocument doc = poiService.checkPatentFile(path);
+//        FileOutputStream out = new FileOutputStream("E:\\temfile\\poi\\output2.docx");
+//        doc.write(out);
+//        out.close();
+//        doc.close();
+    }
+}