lwhhszx 1 éve
szülő
commit
9c2448d1ed
20 módosított fájl, 680 hozzáadás és 67 törlés
  1. 2 1
      src/main/java/cn/cslg/pas/common/utils/ResponseEnum.java
  2. 112 0
      src/main/java/cn/cslg/pas/common/utils/WebSocketServer.java
  3. 56 2
      src/main/java/cn/cslg/pas/common/vo/ImportTaskAMVO.java
  4. 31 0
      src/main/java/cn/cslg/pas/common/vo/TaskWebSocketDTO.java
  5. 115 0
      src/main/java/cn/cslg/pas/controller/ImportTaskController.java
  6. 45 0
      src/main/java/cn/cslg/pas/domain/business/AssoImportTaskField.java
  7. 2 2
      src/main/java/cn/cslg/pas/domain/business/AssoTaskField.java
  8. 3 0
      src/main/java/cn/cslg/pas/domain/es/Patent.java
  9. 32 0
      src/main/java/cn/cslg/pas/domain/es/PatentJoin.java
  10. 16 0
      src/main/java/cn/cslg/pas/mapper/AssoImportTaskFieldMapper.java
  11. 13 0
      src/main/java/cn/cslg/pas/service/business/AssoImportTaskFieldService.java
  12. 79 25
      src/main/java/cn/cslg/pas/service/business/es/EsService.java
  13. 53 0
      src/main/java/cn/cslg/pas/service/common/MessageService.java
  14. 36 11
      src/main/java/cn/cslg/pas/service/importPatent/GetPatentFromExcelThread.java
  15. 22 0
      src/main/java/cn/cslg/pas/service/importPatent/ImportFromWebToEsService.java
  16. 54 12
      src/main/java/cn/cslg/pas/service/importPatent/SavePatentToEsThread.java
  17. 4 1
      src/main/java/cn/cslg/pas/service/importPatent/SchedulingTaskService.java
  18. 1 8
      src/test/java/cn/cslg/pas/service/CommonServiceTests.java
  19. 4 1
      src/test/java/cn/cslg/pas/service/EsServiceTests.java
  20. 0 4
      src/test/java/cn/cslg/pas/service/EventServiceTests.java

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

@@ -10,7 +10,8 @@ public enum ResponseEnum {
     ERROR(0, "请求失败"),
     NO_PERMISSION(201,"无权限"),
     PARAMS_ERROR(202,"参数错误"),
-    CONDITION_ERROR(203, "检索式错误")
+    CONDITION_ERROR(203, "检索式错误"),
+    PATENT_IMPORT_TASK_SUCCESS(903, "WebSocket请求成功")
     ;
 
     private Integer code;

+ 112 - 0
src/main/java/cn/cslg/pas/common/utils/WebSocketServer.java

@@ -0,0 +1,112 @@
+package cn.cslg.pas.common.utils;
+
+import cn.cslg.pas.common.core.base.Constants;
+import jakarta.websocket.*;
+import jakarta.websocket.server.PathParam;
+import jakarta.websocket.server.ServerEndpoint;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.stereotype.Component;
+
+import java.io.IOException;
+import java.util.concurrent.CopyOnWriteArraySet;
+
+@Slf4j
+@Component
+@ServerEndpoint(Constants.API_XiaoSHI + "/ws/{sid}")
+public class WebSocketServer {
+
+    //静态变量,用来记录当前在线连接数。应该把它设计成线程安全的。
+    private static int onlineCount = 0;
+    //concurrent包的线程安全Set,用来存放每个客户端对应的MyWebSocket对象。
+    private static CopyOnWriteArraySet<WebSocketServer> webSocketSet
+            = new CopyOnWriteArraySet<WebSocketServer>();
+    //与某个客户端的连接会话,需要通过它来给客户端发送数据
+    private Session session;
+    //接收sid
+    private String sid = "";
+
+    /**
+     * 连接建立成功调用的方法
+     */
+    @OnOpen
+    public void onOpen(Session session, @PathParam("sid") String sid) {
+        this.session = session;
+        webSocketSet.add(this);     //加入set中
+        addOnlineCount();           //在线数加1
+        log.info("有新窗口开始监听:" + sid + ",当前在线人数为" + getOnlineCount());
+        this.sid = sid;
+        try {
+            sendMessage(Response.success("连接成功").toString());
+        } catch (IOException e) {
+            log.error("websocket IO异常");
+        }
+    }
+
+    /**
+     * 连接关闭调用的方法
+     */
+    @OnClose
+    public void onClose() {
+        webSocketSet.remove(this);  //从set中删除
+        subOnlineCount();           //在线数减1
+        log.info("有一连接关闭!当前在线人数为" + getOnlineCount());
+    }
+
+    /**
+     * 收到客户端消息后调用的方法
+     *
+     * @param message 客户端发送过来的消息
+     */
+    @OnMessage
+    public void onMessage(String message, Session session) {
+        log.info("收到来自窗口" + sid + "的信息:" + message);
+        //群发消息
+        for (WebSocketServer item : webSocketSet) {
+            try {
+                item.sendMessage(message);
+            } catch (IOException e) {
+                e.printStackTrace();
+            }
+        }
+    }
+
+    @OnError
+    public void onError(Session session, Throwable error) {
+        log.error("发生错误");
+        error.printStackTrace();
+    }
+
+    //实现服务器主动推送
+    public synchronized void sendMessage(String message) throws IOException {
+        this.session.getBasicRemote().sendText(message);
+    }
+
+    //群发自定义消息
+    public synchronized static void sendInfo(String message, @PathParam("sid") String sid) {
+        log.info("推送消息到窗口" + sid + ",推送内容:" + message);
+        for (WebSocketServer item : webSocketSet) {
+            try {
+                //这里可以设定只推送给这个sid的,为null则全部推送
+                if (sid == null || "null".equals(sid)) {
+                    item.sendMessage(message);
+                } else if (item.sid.equals(sid)) {
+                    item.sendMessage(message);
+                }
+            } catch (IOException e) {
+                continue;
+            }
+        }
+    }
+
+    public static synchronized int getOnlineCount() {
+        return onlineCount;
+    }
+
+    public static synchronized void addOnlineCount() {
+        WebSocketServer.onlineCount++;
+    }
+
+    public static synchronized void subOnlineCount() {
+        WebSocketServer.onlineCount--;
+    }
+}

+ 56 - 2
src/main/java/cn/cslg/pas/common/vo/ImportTaskAMVO.java

@@ -1,5 +1,6 @@
 package cn.cslg.pas.common.vo;
 
+import com.baomidou.mybatisplus.annotation.TableField;
 import lombok.Data;
 
 import java.util.List;
@@ -9,11 +10,64 @@ import java.util.List;
  */
 @Data
 public class ImportTaskAMVO {
+    /**
+     * 查询条件
+     */
+    private String condition;
+    /**
+     * 任务id
+     */
     private Integer id;
     private String fileGuid;
-    private Integer type;
+
+    /**
+     * 导入总条数
+     */
     private Integer allNum;
+
+    /**
+     * 进度
+     */
+    private Double progress;
+
+    /**
+     * 完成条数
+     */
     private Integer successNum;
-    private Integer   sourceId;
+
+    /**
+     * 失败条数
+     */
+    private Integer defaultNum;
+    /**
+     * 任务类型
+     * 1.excel导入 2.专利号导入 3.专利号文件导入 4.检索导入 5.pdf文档导入
+     */
+    private Integer type;
+
+    /**
+     * 状态
+     */
+    private Integer state;
+    private Integer sourceId;
+    /**
+     * 报告或数据库id
+     */
+    private Integer projectId;
+
+    /**
+     * 产品id
+     */
+    private Integer productId;
+
+    /**
+     * 若是检索导入/专利号导入则必填
+     * 五位数字
+     * 第1著录项目2附图
+     * 3权利要求,4说明书文本,5pdf文档
+     */
+    private Integer importContent;
+
+    private  Integer status;
 
 }

+ 31 - 0
src/main/java/cn/cslg/pas/common/vo/TaskWebSocketDTO.java

@@ -0,0 +1,31 @@
+package cn.cslg.pas.common.vo;
+
+import lombok.Data;
+import lombok.experimental.Accessors;
+
+@Data
+@Accessors(chain = true)
+public class TaskWebSocketDTO {
+    /**
+     * 专题库id
+     */
+    private Integer projectId;
+    /**
+     * 报告id
+     */
+    private Integer reportId;
+    /**
+     * 产品id
+     */
+    private Integer productId;
+    private Integer total;
+    private Integer index;
+    private Integer taskId;
+    private Integer taskStatus;
+    private Boolean complete;
+    private String url;
+    private String fileName;
+    private Integer taskType;
+    private Long percentage;
+    private String oldName;
+}

+ 115 - 0
src/main/java/cn/cslg/pas/controller/ImportTaskController.java

@@ -0,0 +1,115 @@
+package cn.cslg.pas.controller;
+
+
+import cn.cslg.pas.common.core.base.Constants;
+import cn.cslg.pas.common.dto.AddSelfFieldDTO;
+import cn.cslg.pas.common.model.cronModel.Records;
+import cn.cslg.pas.common.utils.Response;
+import cn.cslg.pas.common.utils.StringUtils;
+import cn.cslg.pas.common.vo.EntityVO;
+import cn.cslg.pas.common.vo.PersonSelfFieldVO;
+import cn.cslg.pas.domain.business.SystemDict;
+import cn.cslg.pas.service.business.AssoScenarioMatterService;
+import cn.cslg.pas.service.business.CommonService;
+import cn.cslg.pas.service.business.ScenarioService;
+import cn.cslg.pas.service.business.SystemDictService;
+import cn.cslg.pas.service.common.PersonFieldService;
+import io.swagger.v3.oas.annotations.Operation;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.*;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+@Slf4j
+@RequestMapping(Constants.API_XiaoSHI + "/importTask")
+@RestController
+public class ImportTaskController {
+    @Autowired
+    private SystemDictService systemDictService;
+    @Autowired
+    private CommonService commonService;
+    @Autowired
+    private ScenarioService scenarioService;
+    @Autowired
+    private AssoScenarioMatterService assoScenarioMatterService;
+
+    @Autowired
+    private PersonFieldService personFieldService;
+    @PostMapping("getParams")
+    @Operation(summary = "获得实体类栏位信息")
+    public Response getQueryConditions(@RequestBody List<String> tables) {
+        List<EntityVO> vos = commonService.getQueryConditions(tables);
+        return Response.success(vos);
+    }
+
+    @GetMapping("data")
+    @Operation(summary = "通用数据")
+    public Object getCommonData(String keys) {
+        List<String> typeList = StringUtils.changeStringToString(keys, ",");
+        List<SystemDict> systemDictList = systemDictService.getSystemDictListByType(typeList);
+        Map<String, Object> map = new HashMap<>();
+        for (String type : typeList) {
+            map.put(type, systemDictList.stream().filter(item -> item.getType().equals(type)).collect(Collectors.toList()));
+        }
+        return Response.success(map);
+    }
+
+
+    @GetMapping("getCustomField")
+    @Operation(summary = "查询个人栏位配置")
+    public Response getCustomField(String tableName) {
+        try {
+          List<PersonSelfFieldVO> personSelfFieldVOS= personFieldService.getCustomField(tableName);
+            Records records =new Records();
+            records.setData(personSelfFieldVOS);
+            return Response.success(records);
+        }
+        catch (Exception e){
+                return Response.error(e.getMessage());
+        }
+
+    }
+
+
+    @PostMapping("setCustomField")
+    @Operation(summary = "设置个人栏位配置")
+    public Response setCustomField(@RequestBody AddSelfFieldDTO addSelfFieldDTO) {
+        try {
+            List<PersonSelfFieldVO> personSelfFieldVOS= personFieldService.setCustomField(addSelfFieldDTO);
+            Records records =new Records();
+            records.setData(personSelfFieldVOS);
+            return Response.success(records);
+        }
+        catch (Exception e){
+            return Response.error(e.getMessage());
+        }
+
+    }
+    @GetMapping("/scenario")
+    @Operation(summary = "查询应用场景")
+    public Response queryAllScenario(){
+        Records records = new Records();
+        records.setData(scenarioService.queryAll());
+        return Response.success(records);
+    }
+
+    @PostMapping("/matter")
+    @Operation(summary = "查询处理事项")
+    public Response queryMatter(@RequestBody List<Integer> scenarioIds){
+        Records records = new Records();
+        records.setData(assoScenarioMatterService.queryMatterIds(scenarioIds));
+        return Response.success(records);
+    }
+
+    @GetMapping("/queryCrons")
+    @Operation(summary = "查找核心结论")
+    public Response queryCrons(Integer reportType){
+        Records records = new Records();
+        records.setData(systemDictService.getCrons(reportType));
+        return Response.success(records);
+    }
+}

+ 45 - 0
src/main/java/cn/cslg/pas/domain/business/AssoImportTaskField.java

@@ -0,0 +1,45 @@
+package cn.cslg.pas.domain.business;
+
+import cn.cslg.pas.domain.BaseEntity;
+import com.baomidou.mybatisplus.annotation.TableField;
+import com.baomidou.mybatisplus.annotation.TableName;
+import lombok.Data;
+
+/**
+ * 任务与栏位关联表
+ * @Author xiexiang
+ * @Date 2023/11/15
+ */
+@Data
+@TableName("asso_task_field")
+public class AssoImportTaskField extends BaseEntity<AssoImportTaskField> {
+    /**
+     * 任务id
+     */
+    @TableField(value = "import_task_id")
+    private Integer importTaskId;
+
+    /**
+     * 专题库/报告/产品id
+     */
+    @TableField(value = "project_id")
+    private Integer projectId;
+
+    /**
+     * 栏位类型
+     */
+    @TableField(value = "field_type")
+    private Integer fieldType;
+
+    /**
+     * 栏位
+     */
+    @TableField(value = "field_id")
+    private Integer fieldId;
+
+    /**
+     * 栏位值id
+     */
+    @TableField(value = "field_value_id")
+    private Integer fieldValueId;
+}

+ 2 - 2
src/main/java/cn/cslg/pas/domain/business/AssoTaskField.java

@@ -16,8 +16,8 @@ public class AssoTaskField extends BaseEntity<AssoTaskField> {
     /**
      * 任务id
      */
-    @TableField(value = "import_task_id")
-    private Integer importTaskId;
+    @TableField(value = "task_id")
+    private Integer taskId;
 
     /**
      * 专题库/报告/产品id

+ 3 - 0
src/main/java/cn/cslg/pas/domain/es/Patent.java

@@ -421,5 +421,8 @@ public class Patent {
      */
     @JsonProperty("markings")
     List<Marking> markings;
+    @JsonProperty("patent_join")
+    PatentJoin patentJoin;
+
 
 }

+ 32 - 0
src/main/java/cn/cslg/pas/domain/es/PatentJoin.java

@@ -0,0 +1,32 @@
+package cn.cslg.pas.domain.es;
+
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+import org.springframework.stereotype.Component;
+
+/**
+ * es关联
+ */
+@Component
+@Data
+@AllArgsConstructor
+@NoArgsConstructor
+public class PatentJoin {
+
+    /**
+     * code码
+     */
+    @JsonProperty("parent")
+    private String parent;
+
+    /**
+     * 名称
+     */
+    @JsonProperty("name")
+    private String name;
+
+
+}

+ 16 - 0
src/main/java/cn/cslg/pas/mapper/AssoImportTaskFieldMapper.java

@@ -0,0 +1,16 @@
+package cn.cslg.pas.mapper;
+
+import cn.cslg.pas.domain.business.AssoEventFile;
+import cn.cslg.pas.domain.business.AssoImportTaskField;
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import org.springframework.stereotype.Repository;
+
+/**
+ * 任务可见栏位表
+ *
+ * @author chenyu
+ * @date 2023/10/20
+ */
+@Repository
+public interface AssoImportTaskFieldMapper extends BaseMapper<AssoImportTaskField> {
+}

+ 13 - 0
src/main/java/cn/cslg/pas/service/business/AssoImportTaskFieldService.java

@@ -0,0 +1,13 @@
+package cn.cslg.pas.service.business;
+
+
+
+import cn.cslg.pas.domain.business.AssoImportTaskField;
+import cn.cslg.pas.mapper.AssoImportTaskFieldMapper;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import org.springframework.stereotype.Service;
+
+@Service
+public class AssoImportTaskFieldService extends ServiceImpl<AssoImportTaskFieldMapper, AssoImportTaskField> {
+
+}

+ 79 - 25
src/main/java/cn/cslg/pas/service/business/es/EsService.java

@@ -1,30 +1,27 @@
 package cn.cslg.pas.service.business.es;
 
 import cn.cslg.pas.common.vo.PatentWithIdVO;
-import cn.cslg.pas.domain.School;
 import cn.cslg.pas.domain.es.Patent;
 import co.elastic.clients.elasticsearch.ElasticsearchClient;
 import co.elastic.clients.elasticsearch._types.SortOrder;
 import co.elastic.clients.elasticsearch._types.query_dsl.BoolQuery;
+import co.elastic.clients.elasticsearch._types.query_dsl.HasChildQuery;
 import co.elastic.clients.elasticsearch.core.*;
 import co.elastic.clients.elasticsearch.core.search.Hit;
-import co.elastic.clients.elasticsearch.core.search.TotalHits;
-import com.github.pagehelper.util.StringUtil;
 import lombok.RequiredArgsConstructor;
 import org.springframework.context.annotation.Lazy;
 import org.springframework.stereotype.Service;
 
 import java.io.IOException;
 import java.util.ArrayList;
-import java.util.HashMap;
 import java.util.List;
-import java.util.Map;
 
 
 @Service
 @RequiredArgsConstructor(onConstructor_ = {@Lazy})
 public class EsService {
     private final ElasticsearchClient client;
+
     /**
      * @param patent
      * @throws Exception
@@ -33,12 +30,26 @@ public class EsService {
         IndexResponse indexResponse = client.index(i -> i
                 .index("patent")
                 //传入user对象
-                .document(patent));
-
+                .document(patent)
+        );
         return indexResponse.id();
 
     }
 
+    /**
+     * @param patent
+     * @throws Exception
+     */
+    public String addChildPatent(Patent patent, String id) throws Exception {
+        IndexResponse indexResponse = client.index(i -> i
+                .index("patent")
+                .routing(id)
+                //传入user对象
+                .document(patent)
+        );
+        return indexResponse.id();
+
+    }
 
     /**
      * 根据专利号获取专利id
@@ -48,7 +59,7 @@ public class EsService {
      * @throws Exception
      */
     public PatentWithIdVO getIdByPatentNo(String patentNo) throws Exception {
-        PatentWithIdVO patentWithIdVO =null;
+        PatentWithIdVO patentWithIdVO = null;
         String id = null;
         SearchResponse<Patent> response = client.search(
                 s -> s.index("patent")
@@ -58,42 +69,50 @@ public class EsService {
                                                 .query(patentNo)
                                 )
                         )
-                ,Patent.class
+                , Patent.class
 
         );
         List<Hit<Patent>> hits = response.hits().hits();
         if (hits != null && hits.size() > 0) {
             id = hits.get(0).id();
-            Patent patent =hits.get(0).source();
-            patentWithIdVO =new PatentWithIdVO();
+            Patent patent = hits.get(0).source();
+            patentWithIdVO = new PatentWithIdVO();
             patentWithIdVO.setPatent(patent);
             patentWithIdVO.setId(id);
         }
         return patentWithIdVO;
     }
 
+    /**
+     * @param key
+     * @param page
+     * @param limit
+     * @return
+     * @throws IOException
+     */
+    public List<Patent> search(String key, Integer page, Integer limit) throws IOException {
 
-    public List<Patent> search(String key,Integer page,Integer limit) throws IOException {
         SearchRequest.Builder builder = new SearchRequest.Builder();
         //设置查询索引
         builder.index("patent");
         //组装查询条件
         BoolQuery.Builder boolQuery = new BoolQuery.Builder();
 
-            boolQuery.should(q -> q.matchPhrasePrefix(m -> m
-                    .query(key)
-                    //字段名
-                    .field("title")
-            ));
-            //多字段匹配
-            boolQuery.should(q->q.matchPhrasePrefix(m->m.query(key).field("content")));
+        boolQuery.should(q -> q.matchPhrasePrefix(m -> m
+                .query(key)
+                //字段名
+                .field("title")
+        ));
 
+        //多字段匹配
+        boolQuery.should(q -> q.matchPhrasePrefix(m -> m.query(key).field("content")));
 
         builder.query(q -> q.bool(boolQuery.build()));
         //分页
-        if(page!=null && limit!=null){
+        if (page != null && limit != null) {
             builder.from(page).size(limit);
         }
+
         //排序
         builder.sort(sortOptionsBuilder -> sortOptionsBuilder
                 .field(fieldSortBuilder -> fieldSortBuilder
@@ -110,19 +129,54 @@ public class EsService {
     }
 
 
-    public Integer updateDocument(Patent patent,String id){
-        UpdateRequest<Patent,Patent> req;
+    public Integer updateDocument(Patent patent, String id) {
+        UpdateRequest<Patent, Patent> req;
         req = UpdateRequest.of(
-                b-> b.index("patent").id(id)
+                b -> b.index("patent").id(id)
                         .doc(patent)
         );
         try {
-            client.update(req,Patent.class);
-            return  1;
+            client.update(req, Patent.class);
+            return 1;
         } catch (IOException e) {
             return -1;
         }
     }
+
+
+    /**
+     * @param key
+     * @param page
+     * @param limit
+     * @return
+     * @throws IOException
+     */
+    public List<Patent> searchChild(String key, Integer page, Integer limit) throws IOException {
+
+        SearchRequest.Builder builder = new SearchRequest.Builder();
+        //设置查询索引
+        builder.index("patent");
+        //组装查询条件
+        HasChildQuery.Builder hasChildQuery = new HasChildQuery.Builder();
+        hasChildQuery.type("project");
+        hasChildQuery.query(q -> q.match(m -> m
+                .query(key)
+                //字段名
+                .field("project_id")
+        ));
+
+
+        builder.query(q -> q.hasChild(hasChildQuery.build()));
+        SearchResponse<Patent> response = client.search(builder.build(), Patent.class);
+        List<Patent> list = new ArrayList<>();
+        List<Hit<Patent>> hits = response.hits().hits();
+        for (Hit<Patent> hit : hits) {
+            Patent esMess = hit.source();
+            list.add(esMess);
+        }
+
+        return list;
+    }
 }
 
 

+ 53 - 0
src/main/java/cn/cslg/pas/service/common/MessageService.java

@@ -0,0 +1,53 @@
+package cn.cslg.pas.service.common;
+
+
+import cn.cslg.pas.common.core.base.Constants;
+
+import cn.cslg.pas.common.utils.Response;
+import cn.cslg.pas.common.utils.ResponseEnum;
+import cn.cslg.pas.common.utils.WebSocketServer;
+import cn.cslg.pas.common.vo.ImportTaskAMVO;
+
+import cn.cslg.pas.common.vo.TaskWebSocketDTO;
+import cn.cslg.pas.domain.business.ImportTask;
+import org.springframework.stereotype.Service;
+
+import java.util.Locale;
+
+/**
+ * 处理消息通知
+ *
+ * @Author 李仁杰
+ */
+@Service
+public class MessageService {
+
+    /**
+     * 通过WebSocket 在每一次循环结束后 向前端发送完成进度
+     *
+     * @param total      专利总数量
+     * @param i          当前专利下标
+     * @param percentage 进度(需要计算)
+     */
+    public void sendWebsocketMessage(ImportTaskAMVO importTaskAMVO, Integer total, Integer i, Long percentage) {
+        //通过WebSocket 在每一次循环结束后 向前端发送完成进度
+        //percentage:total == 0 ? 0 : Math.round((total.equals(i) ? (i * 1D) : (i + 1D)) / total * 100D)
+        //当任务状态为完成时,flag为true
+        boolean flag = importTaskAMVO.getStatus().equals(2);
+        WebSocketServer.sendInfo(Response.websocket(new TaskWebSocketDTO()
+                .setTaskId(importTaskAMVO.getId())
+                .setTaskStatus(importTaskAMVO.getStatus())
+//                .setProjectId(importTaskAMVO.getProjectId())
+//                .setReportId(importTaskAMVO.getReportId())
+//                .setProductId(importTaskAMVO.getProductId())
+                .setComplete(flag)
+                .setIndex(i)
+                .setTaskType(importTaskAMVO.getType())
+                .setPercentage(percentage)
+                .setFileName(importTaskAMVO.getFileGuid())
+                .setOldName("")
+                .setUrl("")
+                .setTotal(total), ResponseEnum.PATENT_IMPORT_TASK_SUCCESS), 1 + "");
+    }
+
+}

+ 36 - 11
src/main/java/cn/cslg/pas/service/importPatent/GetPatentFromExcelThread.java

@@ -7,6 +7,7 @@ import cn.cslg.pas.common.vo.PatentData;
 import cn.cslg.pas.common.vo.UploadParamsVO;
 import cn.cslg.pas.common.vo.UploadSettingVO;
 import cn.cslg.pas.domain.es.Patent;
+import cn.cslg.pas.domain.es.Text;
 import cn.cslg.pas.service.common.ExcuteDataToVOService;
 import cn.cslg.pas.service.common.ExcuteUploadSettingService;
 import cn.cslg.pas.service.common.FileManagerService;
@@ -53,22 +54,21 @@ public class GetPatentFromExcelThread extends Thread {
             Integer lastIndex = importTaskAMVO.getSuccessNum();
             Integer sourceId = importTaskAMVO.getSourceId();
             //解析数据源类,通过数据来源id(如1:智慧芽)解析数据源配置文件,获得数据源配置文件对象jsonData
-            ExcuteDataToVOService excuteDataToVOService =applicationContext.getBean(ExcuteDataToVOService.class);
-            ExcuteUploadSettingService excuteUploadSettingService =applicationContext.getBean(ExcuteUploadSettingService.class);
+            ExcuteDataToVOService excuteDataToVOService = applicationContext.getBean(ExcuteDataToVOService.class);
+            ExcuteUploadSettingService excuteUploadSettingService = applicationContext.getBean(ExcuteUploadSettingService.class);
             List<UploadSettingVO.Column> jsonData = excuteUploadSettingService.ExcuteUploadSetting(sourceId.toString());
             //解析Excel文件获得工作簿
             Sheet sheet = ReadExcelUtils.readExcel(tempFile);
             //遍历专利总数量,在循环中将专利一个一个存入消费者专利队列
             for (int i = lastIndex; i < total; i++) {
-
                 PatentData patentData = ReadExcelUtils.readExcelOneRow(tempFile, sheet, i + 1);
                 //调用装载数据类(根据数据源配置文件对象和专利源数据生成专利数据)
                 UploadParamsVO uploadParamsVO = excuteDataToVOService.fileToPatentVO(patentData, jsonData);
-
-
+                this.loadPatent(uploadParamsVO);
                 //专利丢入消费者队列,并唤醒消费者线程
                 savePatentToEsThread.awakeTask(uploadParamsVO.getPatent());
             }
+            //专利取完通知消费者线程
             savePatentToEsThread.setIfProductAll(true);
             //删除临时文件tempFile
             new File(tempFile.getPath()).delete();
@@ -77,18 +77,43 @@ public class GetPatentFromExcelThread extends Thread {
         }
     }
 
-    public GetPatentFromExcelThread(ImportTaskAMVO importTaskAMVO, SavePatentToEsThread savePatentToEsThread,ApplicationContext applicationContext) {
+    public GetPatentFromExcelThread(ImportTaskAMVO importTaskAMVO, SavePatentToEsThread savePatentToEsThread, ApplicationContext applicationContext) {
         this.importTaskAMVO = importTaskAMVO;
         this.savePatentToEsThread = savePatentToEsThread;
-        this.applicationContext= applicationContext;
+        this.applicationContext = applicationContext;
     }
 
 
-    public void loadPatent(Patent patent) {
-        //如果是中国专利,就将申请号作为专利号
-        if (patent.getPatentNo().contains("CN")) {
-            patent.setPatentNo(patent.getAppNo());  //将申请号设为专利号patentNo
+    public void loadPatent(UploadParamsVO uploadParamsVO) {
+        Patent patent = uploadParamsVO.getPatent();
+        String patentNo =patent.getPatentNo();
+        String contry =patentNo.substring(0,2);
+        if (uploadParamsVO.getTitle() != null) {
+            List<Text> texts = new ArrayList<>();
+            if (uploadParamsVO.getTitle().getName() != null) {
+                Text text = new Text();
+                text.setTextContent(uploadParamsVO.getTitle().getName());
+                text.setIfOrigin(true);
+                text.setLanguage(contry);
+                texts.add(text);
+            }
+            if (uploadParamsVO.getTitle().getNameOut() != null) {
+                Text text = new Text();
+                text.setTextContent(uploadParamsVO.getTitle().getNameOut());
+                text.setIfOrigin(false);
+                text.setLanguage("CN");
+                texts.add(text);
+            }
+            if (texts.size() != 0) {
+                patent.setTitle(texts);
+            }
+
         }
+        //如果是中国专利,就将申请号作为专利号
+//        if (patent.getPatentNo().contains("CN")) {
+//            patent.setPatentNo(patent.getAppNo());  //将申请号设为专利号patentNo
+//        }
+
 
         //装载权利要求
 

+ 22 - 0
src/main/java/cn/cslg/pas/service/importPatent/ImportFromWebToEsService.java

@@ -0,0 +1,22 @@
+package cn.cslg.pas.service.importPatent;
+
+import cn.cslg.pas.factorys.PatentImportFactory.PatentImportImp;
+import org.springframework.context.annotation.Scope;
+import org.springframework.stereotype.Service;
+
+@Scope("prototype")
+@Service
+public class ImportFromWebToEsService implements PatentImportImp {
+private TaskThread taskThread;
+    @Override
+    public void startPatentThread() {
+        SavePatentToEsThread savePatentToEsThread = new SavePatentToEsThread(taskThread,taskThread.getApplicationContext());
+        GetPatentFromExcelThread getPatentFromExcelThread = new GetPatentFromExcelThread(taskThread.getImportTaskAMVO(), savePatentToEsThread,taskThread.getApplicationContext());
+        savePatentToEsThread.start();
+        getPatentFromExcelThread.start();
+    }
+    @Override
+    public void setTaskThread(TaskThread taskThread) {
+        this.taskThread = taskThread;
+    }
+}

+ 54 - 12
src/main/java/cn/cslg/pas/service/importPatent/SavePatentToEsThread.java

@@ -1,9 +1,14 @@
 package cn.cslg.pas.service.importPatent;
 
+import cn.cslg.pas.common.utils.FormatUtil;
 import cn.cslg.pas.common.vo.ImportTaskAMVO;
+import cn.cslg.pas.common.vo.PatentWithIdVO;
 import cn.cslg.pas.domain.es.Patent;
+import cn.cslg.pas.domain.es.PatentJoin;
 import cn.cslg.pas.service.business.es.EsService;
 import cn.cslg.pas.service.common.FileManagerService;
+import cn.cslg.pas.service.common.MessageService;
+import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.context.ApplicationContext;
 
@@ -21,47 +26,84 @@ public class SavePatentToEsThread extends Thread {
     private final Lock taskLock = new ReentrantLock();
     private final Condition taskCondition = taskLock.newCondition();
     private TaskThread taskThread;
-    private Boolean ifProductAll= false;
+    private Boolean ifProductAll = false;
+
     @Override
     public void run() {
-        while (!ifProductAll||patents.size()>0) {
+        while (!ifProductAll || patents.size() > 0) {
             try {
+
                 //判断任务队列是否有任务,若没有则线程等待唤醒
                 if (patents.size() == 0) {
                     taskLock.lock();
                     taskCondition.await();
                 }
-             Patent patent=   patents.remove(0);
+
+                Patent patent = patents.remove(0);
                 //根据专利号查询专利
+                EsService esService = applicationContext.getBean(EsService.class);
+                PatentWithIdVO patentWithIdVO = esService.getIdByPatentNo(patent.getPatentNo());
+
+                String patentId =null;
+                // 若查出专利则更新
+                if (patentWithIdVO != null) {
+                    patentId =patentWithIdVO.getId();
+                    Patent orgPatent = patentWithIdVO.getPatent();
+                    BeanUtils.copyProperties(patent, orgPatent, FormatUtil.getNullPropertyNames(patent));
+                    esService.updateDocument(orgPatent, patentWithIdVO.getId());
+                } else {
+                    PatentJoin patentJoin =new PatentJoin();
+                    patentJoin.setName("patent");
+                    patent.setPatentJoin(patentJoin);
+                    patentId =  esService.addPatent(patent);
+
+                }
+                //判断是否和专题库或报告关联
+                ImportTaskAMVO importTaskAMVO = taskThread.getImportTaskAMVO();
 
-                EsService esService =applicationContext.getBean(EsService.class);
-                esService.addPatent(patent);
-                System.out.println("patent"+patent.getPatentNo()+"done");
+                //和专题库或报告进行关联
+                if (importTaskAMVO.getProjectId() != null) {
+                    if(patentId!=null){
+                        Patent patentChild =new Patent();
+                        PatentJoin patentJoin =new PatentJoin();
+                        patentJoin.setParent(patentId);
+                        patentJoin.setName("project");
+                        patentChild.setPatentJoin(patentJoin);
+                        patentChild.setProjectId(importTaskAMVO.getProjectId());
+                     esService.addChildPatent(patentChild ,patentId);
+
+                    }
+
+                }
+                //导入完成,通知前台
+                MessageService messageService = applicationContext.getBean(MessageService.class);
+
+                messageService.sendWebsocketMessage(importTaskAMVO, 1, 1, Long.parseLong("11"));
+                System.out.println("patent" + patent.getPatentNo() + "done");
             } catch (Exception e) {
                 System.out.println(e);
             }
         }
-      taskThread.awakeTaskThread();
+        taskThread.awakeTaskThread();
     }
 
     public SavePatentToEsThread(TaskThread taskThread, ApplicationContext applicationContext) {
-        this.taskThread=taskThread;
-        this.applicationContext =applicationContext;
+        this.taskThread = taskThread;
+        this.applicationContext = applicationContext;
     }
 
 
     public void awakeTask(Patent patent) {
         patents.add(patent);
         if (taskLock.tryLock()) {
-
             taskCondition.signalAll();
             taskLock.unlock();
         }
     }
 
-    public void setIfProductAll(Boolean ifProductAll){
+    public void setIfProductAll(Boolean ifProductAll) {
 
-        this.ifProductAll=ifProductAll;
+        this.ifProductAll = ifProductAll;
 
     }
 }

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

@@ -57,7 +57,7 @@ public class SchedulingTaskService {
         List<ImportTaskAMVO> importTaskAMVOS = new ArrayList<>();
         List<Integer> taskConditionIds = new ArrayList<>();
         List<ImportTaskCondition> importTaskConditions = new ArrayList<>();
-        taskConditionIds =importTaskList.stream().map(ImportTask::getId).collect(Collectors.toList());
+        taskConditionIds =importTaskList.stream().map(ImportTask::getImportTaskConditionId).collect(Collectors.toList());
         //根据taskid查询taskCondition
         if (taskConditionIds.size() != 0) {
             LambdaQueryWrapper<ImportTaskCondition> queryWrapper = new LambdaQueryWrapper<>();
@@ -72,6 +72,9 @@ public class SchedulingTaskService {
             if(importTaskCondition!=null) {
                 importTaskAMVO.setFileGuid(importTaskCondition.getFileGuid());
                 importTaskAMVO.setSourceId(importTaskCondition.getSourceId());
+                importTaskAMVO.setProjectId(importTaskCondition.getProjectId());
+                importTaskAMVO.setProductId(importTaskCondition.getProductId());
+                importTaskAMVO.setImportContent(importTaskAMVO.getImportContent());
             }
             importTaskAMVOS.add(importTaskAMVO);
 

+ 1 - 8
src/test/java/cn/cslg/pas/service/CommonServiceTests.java

@@ -30,8 +30,6 @@ import java.util.stream.Collectors;
 @SpringBootTest
 public class CommonServiceTests {
     @Autowired
-    private EventController eventController;
-    @Autowired
     private PermissionService permissionService;
     @Autowired
     private CommonController commonController;
@@ -61,9 +59,7 @@ public class CommonServiceTests {
         List<Integer> scenarioIds = new ArrayList<>();
         scenarioIds.add(1);
         scenarioIds.add(2);
-//        scenarioIds.add(3);
-//        List<Matter> matterIds = commonController.queryMatter(scenarioIds);
-//        System.out.println(matterIds);
+
     }
 
     @Test
@@ -75,9 +71,6 @@ public class CommonServiceTests {
      List<DepartmentVO> departmentVOS = JSON.parseArray(json,DepartmentVO.class);
      System.out.println(departmentVOS);
 
-//        scenarioIds.add(3);
-//        List<Matter> matterIds = commonController.queryMatter(scenarioIds);
-//        System.out.println(matterIds);
     }
     @Test
     void testImportTask() throws IOException, InterruptedException {

+ 4 - 1
src/test/java/cn/cslg/pas/service/EsServiceTests.java

@@ -12,6 +12,8 @@ import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.boot.test.context.SpringBootTest;
 
+import java.util.List;
+
 /**
  * @author chenyu
  * @date 2023/9/6
@@ -51,7 +53,8 @@ public class EsServiceTests {
 
     @Test
     void addImportTask() throws  Exception {
-
+        List<Patent> patentList = esService.searchChild("1",1,10);
+        System.out.println(patentList);
         Thread.sleep(1000000);
     }
 }

+ 0 - 4
src/test/java/cn/cslg/pas/service/EventServiceTests.java

@@ -65,12 +65,8 @@ public class EventServiceTests {
         );
         list.add(mulFile);
         eventController.addEvent(json_to_string, list);
-
-
-
     }
 
-
     @Test
     void groupEvent() throws Exception {
         StringGroupRequest queryRequest = new StringGroupRequest();