소스 검색

20250922-生成专利申请文档

lrj 5 일 전
부모
커밋
f23ec89277

+ 9 - 0
src/main/java/cn/cslg/pas/common/model/dify/chaxing/KeyWordVo.java

@@ -0,0 +1,9 @@
+package cn.cslg.pas.common.model.dify.chaxing;
+
+import lombok.Data;
+
+@Data
+public class KeyWordVo {
+    private String keyword;
+    private String ifCore;
+}

+ 2 - 2
src/main/java/cn/cslg/pas/service/business/CommonService.java

@@ -43,8 +43,8 @@ public class CommonService {
             //获取 applicationHome 内的路径 ...\target\classes 到这一层级下
             File fileTem = ah.getSource();
             //获取 file的parentFile 即最后一级之前的所有层级路径(包括盘符) 这里能获得到的最终层级为  ...\target 后续用FILE_SEPARATOR(系统路径分割通配符 即 "\") 以及fileName拼接生成存放文件的目录层级 即为根目录 root
-           String rootPath = fileTem.getParentFile().toString() + FileUtils.FILE_SEPARATOR+"jsons/";
-//            String rootPath =  "D:/PAS/target/"+"jsons/";
+//           String rootPath = fileTem.getParentFile().toString() + FileUtils.FILE_SEPARATOR+"jsons/";
+            String rootPath =  "D:/PAS_nBase/target/"+"jsons/";
 //            String filePath = fileUtils.getPath("/11.docx");
             File file = new File(rootPath + fileName);
             Reader reader = new InputStreamReader(new FileInputStream(file), "utf-8");

+ 7 - 0
src/main/java/cn/cslg/pas/service/common/ExcelService.java

@@ -0,0 +1,7 @@
+package cn.cslg.pas.service.common;
+
+import org.springframework.stereotype.Service;
+
+@Service
+public class ExcelService {
+}

+ 213 - 0
src/main/java/cn/cslg/pas/service/dify/chaxing/ChaXingService.java

@@ -0,0 +1,213 @@
+package cn.cslg.pas.service.dify.chaxing;
+
+import cn.cslg.pas.common.dto.PatentStarListDTO;
+import cn.cslg.pas.common.model.dify.DifyChatMessageDTO;
+import cn.cslg.pas.common.model.dify.chaxing.KeyWordVo;
+import cn.cslg.pas.common.model.dify.generateDiscoveryResult.DiscoryResultVO;
+import cn.cslg.pas.common.utils.StringUtils;
+import cn.cslg.pas.common.vo.StarPatentVO;
+import cn.cslg.pas.service.common.DifyService;
+import cn.cslg.pas.service.common.PatentStarApiService;
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson2.JSONObject;
+import org.apache.poi.ss.usermodel.Cell;
+import org.apache.poi.ss.usermodel.Row;
+import org.apache.poi.ss.usermodel.Sheet;
+import org.apache.poi.ss.usermodel.Workbook;
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.stereotype.Service;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.util.*;
+
+@Service
+public class ChaXingService {
+    @Autowired
+    private DifyService difyService;
+    @Value("app-1h8h1wm1bw9RMrynYVuiI1ym")
+    private String key;
+    @Autowired
+    private PatentStarApiService patentStarApiService;
+
+    public List<KeyWordVo> getKeyWord(String InventionPoint, DifyChatMessageDTO difyChatMessageDTO) throws Exception {
+        difyChatMessageDTO.setUser("lrj");
+        difyChatMessageDTO.setResponseMode("blocking");
+        difyChatMessageDTO.setQuery(InventionPoint);
+        Map<String, Object> map = new HashMap<>();
+        map.put("operate_type", "1");
+        difyChatMessageDTO.setInputs(map);
+        Integer cycle = 0;
+        Boolean flag = false;
+        String re = "";
+        String answer = "";
+        String conversionId = "";
+        List<KeyWordVo> keyWordVos = new ArrayList<>();
+        while (cycle < 5 && flag == false) {
+            re = difyService.chatMessage(difyChatMessageDTO, key);
+            JSONObject jsonObject = JSONObject.parseObject(re);
+            Object status = jsonObject.get("status");
+            if (status != null) {
+                cycle++;
+            } else {
+                try {
+                    answer = jsonObject.get("answer").toString();
+                    conversionId = jsonObject.get("conversation_id").toString();
+                    if (difyChatMessageDTO.getConversationId() == null) {
+                        difyChatMessageDTO.setConversationId(conversionId);
+                    }
+                    keyWordVos = JSONArray.parseArray(answer, KeyWordVo.class);
+                } catch (Exception e) {
+                    cycle++;
+                }
+
+                System.out.println(answer);
+                flag = true;
+            }
+
+        }
+        return keyWordVos;
+    }
+
+    public List<String> getSynonym(String keyword, DifyChatMessageDTO difyChatMessageDTO) throws Exception {
+        difyChatMessageDTO.setUser("lrj");
+        difyChatMessageDTO.setResponseMode("blocking");
+        difyChatMessageDTO.setQuery("生成同义词");
+        Map<String, Object> map = new HashMap<>();
+        map.put("operate_type", "2");
+        map.put("keyword", keyword);
+        difyChatMessageDTO.setInputs(map);
+        Integer cycle = 0;
+        Boolean flag = false;
+        String re = "";
+        String answer = "";
+        String conversionId = "";
+        List<String> synonyms = new ArrayList<>();
+        while (cycle < 5 && flag == false) {
+            re = difyService.chatMessage(difyChatMessageDTO, key);
+            JSONObject jsonObject = JSONObject.parseObject(re);
+            Object status = jsonObject.get("status");
+            if (status != null) {
+                cycle++;
+            } else {
+                try {
+                    answer = jsonObject.get("answer").toString();
+                    conversionId = jsonObject.get("conversation_id").toString();
+                    if (difyChatMessageDTO.getConversationId() == null) {
+                        difyChatMessageDTO.setConversationId(conversionId);
+                    }
+                    synonyms = JSONArray.parseArray(answer, String.class);
+                } catch (Exception e) {
+                    cycle++;
+                }
+
+                System.out.println(answer);
+                flag = true;
+            }
+
+        }
+        return synonyms;
+    }
+
+    public void compare(String path, String outPath) throws Exception {
+        String readPath = "E:\\20240716-工作记录文件\\功能文件\\小世系统\\20250929-查新检索-lrj-v1\\test.xlsx";
+        List<Map<String, String>> map = new ArrayList<>();
+        FileInputStream inputStream = new FileInputStream(new File(readPath));
+
+        //1.创建工作簿,使用excel能操作的这边都看看操作
+        Workbook workbook = new XSSFWorkbook(inputStream);
+        Sheet sheet = workbook.getSheetAt(0);
+        int rowNum = sheet.getLastRowNum() + 1;
+        DifyChatMessageDTO difyChatMessageDTO = new DifyChatMessageDTO();
+        difyChatMessageDTO.setUser("lrj");
+        difyChatMessageDTO.setResponseMode("blocking");
+        List<String> res = new ArrayList<>();
+        for (int i = 1; i < rowNum; i++) {
+            Row row = sheet.getRow(i);
+            Cell cell = row.getCell(1);
+            String inventionPoint = cell.getStringCellValue();
+            difyChatMessageDTO.setQuery(inventionPoint);
+            List<KeyWordVo> keyWordVos = this.getKeyWord(inventionPoint, difyChatMessageDTO);
+            for (KeyWordVo keyWordVo : keyWordVos) {
+                if (keyWordVo.getIfCore() != null && keyWordVo.getIfCore().equals("true")) {
+                    String keyword = keyWordVo.getKeyword();
+                    List<String> synonyms = this.getSynonym(keyword, difyChatMessageDTO);
+                    synonyms.add(keyword);
+                    synonyms = this.formQueryKey(synonyms);
+                    String re = "(" + StringUtils.join(synonyms, " OR ") + ")";
+                    res.add(re);
+                }
+            }
+            String query = this.getQueryKey(res);
+            PatentStarListDTO patentStarListDTO = new PatentStarListDTO();
+            patentStarListDTO.setCurrentQuery(query);
+            patentStarListDTO.setDBType("CN");
+            patentStarListDTO.setOrderBy("AD");
+            patentStarListDTO.setOrderByType("DESC");
+            patentStarListDTO.setPageNum(1);
+            patentStarListDTO.setRowCount(10);
+            Map<String, Object> searchApiMap = patentStarApiService.patentStarSearchApi(patentStarListDTO);
+            Integer total=-1;
+            if(searchApiMap!=null) {
+                total = Integer.parseInt(searchApiMap.get("total").toString());
+           }
+            Cell cell2 = row.getCell(2);
+            String value = cell2.getStringCellValue();
+            value = value.trim();
+            List<String> patentNos = Arrays.asList(value.split("\n"));
+            value = value.replaceAll("\n", " OR ");
+            query = query + " AND " + "PN=(" + value + ") OR GN=(" + value + ")";
+            patentStarListDTO.setCurrentQuery(query);
+            patentStarListDTO.setFormed(null);
+            searchApiMap = patentStarApiService.patentStarSearchApi(patentStarListDTO);
+            List<StarPatentVO> starPatentVOS=new ArrayList<>();
+            if(searchApiMap!=null) {
+            starPatentVOS = (List<StarPatentVO>) searchApiMap.get("records");
+            }
+            List<String> result = new ArrayList<>();
+            starPatentVOS.forEach(item -> {
+                if (patentNos.contains(item.getPN())) {
+                    result.add(item.getPN());
+                } else if (patentNos.contains(item.getGN())) {
+                    result.add(item.getGN());
+                }
+            });
+            starPatentVOS.forEach(item -> {
+            });
+            String reText = "总数:" + total + "\n" + "结果:" + StringUtils.join(result, "\n");
+            Cell cell3 = row.createCell(3);
+            cell3.setCellValue(reText);
+            Cell cell4 = row.createCell(4);
+            String re = "";
+            if (result.size() == 0) {
+                re = "无";
+            } else if (result.size() == patentNos.size()) {
+                re = "完全检索";
+            } else {
+                re = "部分检索";
+            }
+            cell4.setCellValue(re);
+            Cell cell5 = row.createCell(5);
+            cell5.setCellValue(query);
+        }
+        inputStream.close();
+        FileOutputStream fileOutputStream = new FileOutputStream(new File(outPath));
+        workbook.write(fileOutputStream);
+    }
+
+    public String getQueryKey(List<String> res) {
+        String query = "TX=" + StringUtils.join(res, " AND TX=");
+        return query;
+    }
+
+    public List<String> formQueryKey(List<String> keys) {
+        for (int i=0;i<keys.size();i++){
+            keys.set(i,"\"" + keys.get(i) + "\"");
+        }
+        return keys;
+    }
+
+}

+ 2 - 1
src/main/resources/application-dev.yml

@@ -91,7 +91,8 @@ DIFY:
   OAApiKey: app-NvKwdHvEK2UmJdmjTGDR0xu6
   checkApiKey: aa
   cliamKey: app-jF3akhYKgljPLdpeIpTNbs6f
-  gInstructionKey: app-7ImBmlr7kvBTSvBj1mTvgKyp
+  #gInstructionKey: app-7ImBmlr7kvBTSvBj1mTvgKyp
+  gInstructionKey:   app-YfoUDlED4oJNO9hVk6hfdKSw
   discoveryResultKey: app-G5gnZ4s7GlMEIft79fk7hUR7
   aiPatentResultKey: app-KLneZ6O7qXL2DjKm169ltxJI
   url: http://192.168.2.24/v1/

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

@@ -14,6 +14,7 @@ import cn.cslg.pas.domain.dify.GetInstructAnswerDTO;
 import cn.cslg.pas.service.common.DifyService;
 import cn.cslg.pas.service.dify.GenerateDiscoveryResultService;
 import cn.cslg.pas.service.dify.GenerateInstructionService;
+import cn.cslg.pas.service.dify.chaxing.ChaXingService;
 import com.alibaba.fastjson.JSONObject;
 import com.alibaba.fastjson2.JSON;
 import org.apache.poi.ss.usermodel.Cell;
@@ -41,6 +42,8 @@ public class DifyTest {
     private GenerateInstructionService generateInstructionService;
     @Autowired
     private DifyService difyService;
+    @Autowired
+    private ChaXingService chaXingService;
  @Autowired
  private GenerateDiscoveryResultService generateDiscoveryResultService;
     @Test
@@ -278,5 +281,11 @@ public class DifyTest {
 
       System.out.println(cleanText);
     }
+@Test
+    public void test4() throws Exception{
+    String path="E:\\20240716-工作记录文件\\功能文件\\小世系统\\20250929-查新检索-lrj-v1\\test.xlsx";
+    String outPath="E:\\20240716-工作记录文件\\功能文件\\小世系统\\20250929-查新检索-lrj-v1\\test1.xlsx";
+    chaXingService.compare(path,outPath);
 
 }
+}