浏览代码

20250415 dify功能修改

lrj 4 月之前
父节点
当前提交
b5b41a813d

+ 4 - 0
src/main/java/cn/cslg/pas/common/dto/ImportTaskDTO.java

@@ -88,4 +88,8 @@ public class ImportTaskDTO {
     private List<String> patentNos;
     private Integer productId;
     private String updateCycle;
+    /**
+     * 操作类型 0取消 1增加 2覆盖
+     */
+    Integer optionType;
 }

+ 14 - 0
src/main/java/cn/cslg/pas/common/model/dify/confessionSession/AddConfessionSessionDTO.java

@@ -2,7 +2,21 @@ package cn.cslg.pas.common.model.dify.confessionSession;
 
 import lombok.Data;
 
+import java.util.Date;
+
 @Data
 public class AddConfessionSessionDTO {
     private String fileGuid;
+
+    private String conversationId;
+
+    private String conversationName;
+
+    private String inventionPoint;
+    private String content;
+    private String createId;
+
+    private String guid;
+
+    private Integer type;
 }

+ 1 - 0
src/main/java/cn/cslg/pas/common/model/dify/confessionSession/QueryConfessionSessionDTO.java

@@ -7,4 +7,5 @@ public class QueryConfessionSessionDTO {
     private Integer confessionSessionId;
     private long current;
     private long size;
+    private Integer type;
 }

+ 1 - 0
src/main/java/cn/cslg/pas/common/model/dify/confessionSession/QueryConfessionSessionVO.java

@@ -14,4 +14,5 @@ public class QueryConfessionSessionVO {
     private String inventionPoint;
     private String createId;
     private Date createTime;
+    private String content;
 }

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

@@ -1,5 +1,6 @@
 package cn.cslg.pas.common.utils;
 
+import cn.cslg.pas.common.utils.commonUtils.BusinessUtil;
 import cn.cslg.pas.common.vo.PatentData;
 import cn.cslg.pas.domain.es.Patent;
 import org.apache.poi.hssf.usermodel.*;
@@ -237,26 +238,43 @@ public class ReadExcelUtils {
      * @return
      * @throws IOException
      */
-    public static List<String> getPatentNoFromExcel(Sheet sheet) throws IOException {
-        List<String> patentNos = new ArrayList<>();
+    public static Map<String,List<String>>  getPatentNoFromExcel(Sheet sheet) throws IOException {
+        Map<String,List<String>> map =new HashMap<>();
+
         int rows = sheet.getPhysicalNumberOfRows();
-        Integer cellId = null;
+        Integer PNOCellId = null;
+        Integer ANOCellId = null;
+        List<String> publicNos = new ArrayList<>();
+        List<String> appNos = new ArrayList<>();
         //开始装载专利数据
         Row firstRow = sheet.getRow(0);
 
+
         //查找列
         int columns = firstRow.getLastCellNum();
         for (int t = 0; t < columns; t++) {
-            if (firstRow.getCell(t).toString().equals("专利号")) {
-                cellId = t;
+            if (firstRow.getCell(t).toString().equals("申请号")) {
+                ANOCellId = t;
+            }
+            if (firstRow.getCell(t).toString().equals("公开号")) {
+                PNOCellId = t;
             }
         }
         for (int i = 1; i < rows; i++) {
             Row row = sheet.getRow(i);
-            String patentNo = row.getCell(cellId).toString();
-            patentNos.add(patentNo);
+            if (ANOCellId != null) {
+                String appNo = row.getCell(ANOCellId).toString();
+                appNos.add(appNo);
+            }
+            if(PNOCellId!=null){
+                String publicNo=row.getCell(PNOCellId).toString();
+                publicNos.add(publicNo);
+            }
+
         }
-        return patentNos;
+        map.put(BusinessUtil.APP_NO,appNos);
+        map.put(BusinessUtil.PUBLIC_NO,publicNos);
+        return map;
     }
 
 
@@ -274,8 +292,8 @@ public class ReadExcelUtils {
             }
         }
 
-        if(cellId!=null&&rows==1){
-            cellId=-1;
+        if (cellId != null && rows == 1) {
+            cellId = -1;
         }
         return cellId;
     }

+ 33 - 0
src/main/java/cn/cslg/pas/common/utils/commonUtils/BusinessUtil.java

@@ -0,0 +1,33 @@
+package cn.cslg.pas.common.utils.commonUtils;
+
+import com.alibaba.fastjson.JSONObject;
+
+import java.util.*;
+
+public class BusinessUtil {
+    public static String PUBLIC_NO="publicNo";
+    public static String APP_NO="appNo";
+    public static Map<String, List<String>> getPatentNosMap(String conditions) {
+        Map<String, List<String>> map = new HashMap<>();
+        JSONObject jsonObject = JSONObject.parseObject(conditions);
+        String publicNoStr = null;
+        String appNoStr =null;
+        if(jsonObject.get(PUBLIC_NO)!=null) {
+            publicNoStr= jsonObject.get(PUBLIC_NO).toString();
+        }
+        if(jsonObject.get(APP_NO)!=null) {
+            appNoStr=jsonObject.get(APP_NO).toString();
+        }
+        List<String> publicNos = new ArrayList<>();
+        List<String> appNos = new ArrayList<>();
+        if (publicNoStr != null&&!publicNoStr.trim().equals("")) {
+            publicNos = Arrays.asList(publicNoStr.split("[,|,]"));  //生成专利号集合
+        }
+        if (appNoStr != null&&!appNoStr.trim().equals("")) {
+            appNos = Arrays.asList(appNoStr.split("[,|,]"));
+        }
+        map.put(PUBLIC_NO, publicNos);
+        map.put(APP_NO, appNos);
+        return map;
+    }
+}

+ 7 - 0
src/main/java/cn/cslg/pas/controller/common/ConfessionSessionController.java

@@ -71,4 +71,11 @@ public class ConfessionSessionController {
         return Response.success(ids);
     }
 
+    @RequestMapping(value = "/addSession", method = RequestMethod.POST)
+    @Operation(summary = "添加会话记录")
+    public Response addSession(@RequestBody AddConfessionSessionDTO addConfessionSessionDTO) throws IOException {
+        Integer id = confessionSessionService.addSession(addConfessionSessionDTO);
+        return Response.success(id);
+    }
+
 }

+ 6 - 2
src/main/java/cn/cslg/pas/domain/dify/ConfessionSession.java

@@ -5,16 +5,18 @@ import com.baomidou.mybatisplus.annotation.IdType;
 import com.baomidou.mybatisplus.annotation.TableField;
 import com.baomidou.mybatisplus.annotation.TableId;
 import com.baomidou.mybatisplus.annotation.TableName;
+
 import java.io.Serializable;
 import java.util.Date;
+
 import lombok.Data;
 
 /**
  * @TableName confession_session
  */
-@TableName(value ="confession_session")
+@TableName(value = "confession_session")
 @Data
-public class ConfessionSession extends BaseEntity<DifySession> {
+public class ConfessionSession extends BaseEntity<ConfessionSession> {
     private Integer id;
 
     private String conversationId;
@@ -28,5 +30,7 @@ public class ConfessionSession extends BaseEntity<DifySession> {
     private String guid;
 
     private Date createTime;
+    private Integer type;
+    private String content;
 
 }

+ 11 - 4
src/main/java/cn/cslg/pas/service/business/ImportTaskService.java

@@ -14,6 +14,7 @@ import cn.cslg.pas.common.model.importPDF.AddImportPDFTaskDTO;
 import cn.cslg.pas.common.model.request.GroupRequest;
 import cn.cslg.pas.common.model.request.QueryRequest;
 import cn.cslg.pas.common.utils.*;
+import cn.cslg.pas.common.utils.commonUtils.BusinessUtil;
 import cn.cslg.pas.common.vo.ImportTaskAMVO;
 import cn.cslg.pas.common.vo.StarPatentVO;
 import cn.cslg.pas.common.vo.business.ImportTaskVO;
@@ -220,9 +221,13 @@ public class ImportTaskService extends ServiceImpl<ImportTaskMapper, ImportTask>
                 throw new XiaoShiException("文件错误");
             }
         } else if (importTaskCondition.getType().equals(2) || importTaskCondition.getType().equals(3)) {
-            List<String> patentNos = new ArrayList<>();
+
+            Integer totalNum = 0;
             if (importTaskCondition.getType().equals(2)) {
-                patentNos = Arrays.asList(importTaskCondition.getSearchCondition().split("[,|,]"));
+                Map<String, List<String>> map = BusinessUtil.getPatentNosMap(importTaskCondition.getSearchCondition());
+                totalNum += map.get(BusinessUtil.PUBLIC_NO).size();
+                totalNum += map.get(BusinessUtil.APP_NO).size();
+
             } else if (importTaskCondition.getType().equals(3)) {
                 try {
                     String res = fileManagerService.getSystemFileFromFMS(Arrays.asList(importTaskCondition.getFileGuid()));
@@ -240,11 +245,13 @@ public class ImportTaskService extends ServiceImpl<ImportTaskMapper, ImportTask>
                         IOUtils.copy(inputStream, outputStream); // 将输入流复制到临时文件
                     }
                     Sheet sheet = ReadExcelUtils.readExcel(tempFile);
-                    patentNos = ReadExcelUtils.getPatentNoFromExcel(sheet);
+                    Map<String, List<String>> map = ReadExcelUtils.getPatentNoFromExcel(sheet);
+                    totalNum += map.get(BusinessUtil.PUBLIC_NO).size();
+                    totalNum += map.get(BusinessUtil.APP_NO).size();
                 } catch (Exception e) {
                 }
             }
-            importTask.setAllNum(patentNos.size());
+            importTask.setAllNum(totalNum);
         }
         importTask.setProgress(0.0);
         String taskName = this.setImportTaskName(importTaskCondition, personnelVO.getName());

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

@@ -30,7 +30,6 @@ import org.springframework.beans.factory.annotation.Value;
 import org.springframework.http.HttpHeaders;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
-import org.springframework.web.reactive.function.client.WebClient;
 import reactor.core.publisher.Flux;
 
 import java.io.*;

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

@@ -884,7 +884,14 @@ public class PatentStarApiService {
         return jsonObject;
     }
 
-    public List<PatentStarListDTO> splitPatentNoByType(List<String> originalList, PatentStarListDTO patentStarListDTO) {
+    /**
+     * @param originalList
+     * @param patentStarListDTO
+     * @param type              0申请号 1公开号或公告号 2专利号
+     * @return
+     */
+    public List<PatentStarListDTO> splitPatentNoByType(List<String> originalList, PatentStarListDTO patentStarListDTO, Integer type) {
+        List<PatentStarListDTO> patentStarListDTOS = new ArrayList<>();
         List<String> cnStrings = new ArrayList<>();
         List<String> wdStrings = new ArrayList<>();
         List<List<String>> result = new ArrayList<>();
@@ -894,8 +901,10 @@ public class PatentStarApiService {
         int cnCount = 0;
         // 记录WD类型的字符串数量
         int wdCount = 0;
+        if (originalList == null || originalList.size() == 0) {
+            return patentStarListDTOS;
+        }
 
-        List<PatentStarListDTO> patentStarListDTOS = new ArrayList<>();
         //遍历初始集合
         for (String str : originalList) {
             if (str.startsWith("CN")) {
@@ -930,7 +939,15 @@ public class PatentStarApiService {
                     dbType = "WD";
                 }
                 String join = StringUtils.join(item, " OR ");
-                String conditions = "AN=(" + join + ") OR PN=(" + join + ") OR GN=(" + join + ")";
+                String conditions = "";
+                if (type == 0) {
+                    conditions = "AN=(" + join + ")";
+                } else if (type == 1) {
+                    conditions = " PN=(" + join + ") OR GN=(" + join + ")";
+                } else {
+                    conditions = "AN=(" + join + ") OR PN=(" + join + ") OR GN=(" + join + ")";
+
+                }
                 PatentStarListDTO patentStarListDTO1 = new PatentStarListDTO();
                 patentStarListDTO1.setOrderByType(patentStarListDTO.getOrderByType());
                 patentStarListDTO1.setCurrentQuery(conditions);
@@ -1244,9 +1261,8 @@ public class PatentStarApiService {
                     if (pdfUrlArr[0].contains("?") && pdfUrlArr[1].contains("?")) {
                         pdfUrl1 = pdfUrlArr[0].substring(pdfUrlArr[0].indexOf("http"), pdfUrlArr[0].indexOf("?"));
                         pdfUrl2 = pdfUrlArr[1].substring(pdfUrlArr[1].indexOf("http"), pdfUrlArr[1].indexOf("?"));
-                    } else
-                    {
-                        pdfUrl1 =pdfUrlArr[0];
+                    } else {
+                        pdfUrl1 = pdfUrlArr[0];
                         pdfUrl2 = pdfUrlArr[1];
                     }
                     if (pdfUrl1.contains("0A_CN_0.pdf")) {
@@ -1497,7 +1513,7 @@ public class PatentStarApiService {
         return dto;
     }
 
-    public String getTxtGuid(String rowApplicationNo,String patentNo) throws IOException {
+    public String getTxtGuid(String rowApplicationNo, String patentNo) throws IOException {
         StringBuilder builder = new StringBuilder();
         SelectClaimDTO externalClaim = this.queryExternalClaim(rowApplicationNo);
         if (ObjectUtils.isNotEmpty(externalClaim)) {

+ 24 - 4
src/main/java/cn/cslg/pas/service/dify/ConfessionSessionService.java

@@ -73,22 +73,28 @@ public class ConfessionSessionService extends ServiceImpl<ConfessionSessionMappe
     public List<QueryConfessionSessionVO> queryConfessionSession(QueryConfessionSessionDTO queryConfessionSessionDTO) {
         Integer userId = loginUtils.getId();
         Integer confessionSessionId = queryConfessionSessionDTO.getConfessionSessionId();
+        Integer type = queryConfessionSessionDTO.getType();
         LambdaQueryWrapper<ConfessionSession> queryWrapper = new LambdaQueryWrapper<>();
         queryWrapper.eq(ConfessionSession::getCreateId, userId)
                 .orderByDesc(ConfessionSession::getCreateTime);
         if (confessionSessionId != null) {
             queryWrapper.eq(ConfessionSession::getId, confessionSessionId);
         }
+        if (type != null) {
+            queryWrapper.eq(ConfessionSession::getType, type);
+        }
         List<ConfessionSession> confessionSessions = this.list(queryWrapper);
         List<QueryConfessionSessionVO> queryConfessionSessionVOS = new ArrayList<>();
         if (confessionSessions == null || confessionSessions.size() == 0) {
             return queryConfessionSessionVOS;
         }
-        List<String> fileGuids = confessionSessions.stream().map(ConfessionSession::getGuid).collect(Collectors.toList());
+        List<String> fileGuids = confessionSessions.stream().filter(item->item.getGuid()!=null).map(ConfessionSession::getGuid).collect(Collectors.toList());
         List<SystemFile> systemFiles = new ArrayList<>();
         try {
-            String res = fileManagerService.getSystemFileFromFMS(fileGuids);
+            if (fileGuids != null&&fileGuids.size()>0) {
+                String res = fileManagerService.getSystemFileFromFMS(fileGuids);
             systemFiles = JSONObject.parseArray(res, SystemFile.class);
+            }
         } catch (Exception e) {
             e.printStackTrace();
         }
@@ -96,8 +102,10 @@ public class ConfessionSessionService extends ServiceImpl<ConfessionSessionMappe
             QueryConfessionSessionVO queryConfessionSessionVO = new QueryConfessionSessionVO();
             BeanUtils.copyProperties(confessionSession, queryConfessionSessionVO);
             String guid = confessionSession.getGuid();
-            SystemFile systemFile = systemFiles.stream().filter(item -> item.getGuid().equals(guid)).findFirst().orElse(null);
-            queryConfessionSessionVO.setSystemFile(systemFile);
+            if(systemFiles!=null) {
+                SystemFile systemFile = systemFiles.stream().filter(item -> item.getGuid().equals(guid)).findFirst().orElse(null);
+                queryConfessionSessionVO.setSystemFile(systemFile);
+            }
             queryConfessionSessionVOS.add(queryConfessionSessionVO);
         }
         return queryConfessionSessionVOS;
@@ -108,6 +116,18 @@ public class ConfessionSessionService extends ServiceImpl<ConfessionSessionMappe
         this.removeBatchByIds(ids);
         return ids;
     }
+
+    public Integer addSession(AddConfessionSessionDTO addConfessionSessionDTO) {
+        ConfessionSession confessionSession = new ConfessionSession();
+        confessionSession.setContent(addConfessionSessionDTO.getContent());
+        confessionSession.setConversationId(addConfessionSessionDTO.getConversationId());
+        confessionSession.setConversationName(addConfessionSessionDTO.getConversationName());
+        String createId = loginUtils.getId().toString();
+        confessionSession.setCreateId(createId);
+        confessionSession.setType(addConfessionSessionDTO.getType());
+        confessionSession.insert();
+        return confessionSession.getId();
+    }
 }
 
 

+ 15 - 5
src/main/java/cn/cslg/pas/service/importPatent/ImportFromWebToEsService.java

@@ -7,6 +7,7 @@ import cn.cslg.pas.common.model.cronModel.SystemFile;
 import cn.cslg.pas.common.utils.DateUtils;
 import cn.cslg.pas.common.utils.FormatUtil;
 import cn.cslg.pas.common.utils.ReadExcelUtils;
+import cn.cslg.pas.common.utils.commonUtils.BusinessUtil;
 import cn.cslg.pas.common.vo.ImportTaskAMVO;
 import cn.cslg.pas.common.vo.StarPatentVO;
 import cn.cslg.pas.domain.business.PatentImportErrorLog;
@@ -16,6 +17,7 @@ import cn.cslg.pas.service.business.PatentImportErrorLogService;
 import cn.cslg.pas.service.common.FileManagerService;
 import cn.cslg.pas.service.common.PatentStarApiService;
 import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
 import org.apache.commons.compress.utils.IOUtils;
 import org.apache.poi.ss.usermodel.Sheet;
 import org.springframework.beans.BeanUtils;
@@ -136,7 +138,7 @@ public class ImportFromWebToEsService implements PatentImportImp {
                             .setOrderBy(orderBy)
                             .setOrderByType(orderByType)
                             .setDBType(dbType);
-                    patentStarListDtos = patentStarApiService.splitPatentNoByType(addPatentNos, patentStarListDTO);
+                    patentStarListDtos = patentStarApiService.splitPatentNoByType(addPatentNos, patentStarListDTO, 3);
                 } else {
                     patentStarListDtos = patentStarApiService.getSplitedConditions(new PatentStarListDTO()
                             .setCurrentQuery(conditions)
@@ -153,8 +155,11 @@ public class ImportFromWebToEsService implements PatentImportImp {
                         .setOrderBy(orderBy)
                         .setOrderByType(orderByType)
                         .setDBType(dbType);
-                List<String> patentNos = Arrays.asList(conditions.split("[,|,]"));  //生成专利号集合
-                patentStarListDtos = patentStarApiService.splitPatentNoByType(patentNos, patentStarListDTO);
+                Map<String, List<String>> map = BusinessUtil.getPatentNosMap(conditions);
+                List<PatentStarListDTO> patentStarListDtos1 = patentStarApiService.splitPatentNoByType(map.get(BusinessUtil.PUBLIC_NO), patentStarListDTO, 1);
+                List<PatentStarListDTO> patentStarListDtos2 = patentStarApiService.splitPatentNoByType(map.get(BusinessUtil.APP_NO), patentStarListDTO, 0);
+                patentStarListDtos.addAll(patentStarListDtos1);
+                patentStarListDtos.addAll(patentStarListDtos2);
             }
 
             //当专利为专利号文件导入时
@@ -176,13 +181,18 @@ public class ImportFromWebToEsService implements PatentImportImp {
                     IOUtils.copy(inputStream, outputStream); // 将输入流复制到临时文件
                 }
                 Sheet sheet = ReadExcelUtils.readExcel(tempFile);
-                List<String> patentNos = ReadExcelUtils.getPatentNoFromExcel(sheet);
+                Map<String, List<String>> map = ReadExcelUtils.getPatentNoFromExcel(sheet);
+                List<String> appNos = map.get(BusinessUtil.APP_NO);
+                List<String> publicNos = map.get(BusinessUtil.PUBLIC_NO);
                 PatentStarListDTO patentStarListDTO = new PatentStarListDTO();
                 patentStarListDTO.setCurrentQuery(conditions)
                         .setOrderBy(orderBy)
                         .setOrderByType(orderByType)
                         .setDBType(dbType);
-                patentStarListDtos = patentStarApiService.splitPatentNoByType(patentNos, patentStarListDTO);
+                List<PatentStarListDTO> patentStarListDtos1 = patentStarApiService.splitPatentNoByType(appNos, patentStarListDTO, 0);
+                List<PatentStarListDTO> patentStarListDtos2 = patentStarApiService.splitPatentNoByType(publicNos, patentStarListDTO, 1);
+                patentStarListDtos.addAll(patentStarListDtos1);
+                patentStarListDtos.addAll(patentStarListDtos2);
             }
 
             char ifCataloguing = importTaskAMVO.getIfAddCatalogue();

+ 4 - 1
src/main/java/cn/cslg/pas/service/importPatent/SavePatentToEsThread.java

@@ -208,7 +208,10 @@ public class SavePatentToEsThread extends Thread {
                     for (EsCustomFieldDTO esCustomFieldDTO : importTaskAMVO.getFieldDTOS()
                     ) {
                         esCustomFieldDTO.setPatentId(patentId);
-                        esCustomFieldDTO.setOptionType(2);
+                        if(esCustomFieldDTO.getOptionType()==null){
+                            esCustomFieldDTO.setOptionType(2);
+                        }
+                        esCustomFieldDTO.setOptionType(esCustomFieldDTO.getOptionType());
                         esCustomFieldDTO.setPatentNo(patent.getPatentNo());
                         EsCustomFieldService esCustomFieldService = applicationContext.getBean(EsCustomFieldService.class);
                         esCustomFieldService.addCustomField(esCustomFieldDTO);