浏览代码

es查询接口

chenyi 1 年之前
父节点
当前提交
1418febb80

+ 9 - 0
src/main/java/cn/cslg/pas/common/dto/PatentDTO.java

@@ -0,0 +1,9 @@
+package cn.cslg.pas.common.dto;
+
+import cn.cslg.pas.domain.es.Patent;
+import lombok.Data;
+
+@Data
+public class PatentDTO extends Patent {
+    private Long total;
+}

+ 31 - 0
src/main/java/cn/cslg/pas/controller/PatentController.java

@@ -0,0 +1,31 @@
+package cn.cslg.pas.controller;
+
+import cn.cslg.pas.common.core.base.Constants;
+import cn.cslg.pas.common.model.cronModel.Records;
+import cn.cslg.pas.common.model.request.StringRequest;
+import cn.cslg.pas.common.utils.Response;
+import cn.cslg.pas.factorys.businessFactory.Business;
+import cn.cslg.pas.factorys.businessFactory.BusinessFactory;
+import io.swagger.v3.oas.annotations.Operation;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+@RequestMapping(Constants.API_XiaoSHI + "/patent")
+@RestController
+public class PatentController {
+
+    @Autowired
+    private BusinessFactory businessFactory;
+
+    @Operation(summary = "查询专利")
+    @PostMapping("/queryPatent")
+    public Response queryEvent(@RequestBody StringRequest stringRequest) throws Exception {
+        Business business = businessFactory.getClass("patentService");
+        Records records = (Records) business.queryMessage(stringRequest);
+        return Response.success(records);
+    }
+
+}

+ 37 - 40
src/main/java/cn/cslg/pas/domain/es/Patent.java

@@ -129,121 +129,118 @@ public class Patent {
      * IPC分类号(主)
      */
     @JsonProperty("mipc")
-    private PatentClassify mipc ;
+    private PatentClassify mipc;
 
     /**
      * ipc集合
      */
     @JsonProperty("ipc")
-    private List<PatentClassify> ipc ;
+    private List<PatentClassify> ipc;
 
     /**
      * CPC分类号(主)
      */
     @JsonProperty("mcpc")
-    private PatentClassify mcpc ;
+    private PatentClassify mcpc;
 
     /**
      * cpc集合
      */
     @JsonProperty("cpc")
-    private List<PatentClassify> cpc ;
+    private List<PatentClassify> cpc;
 
     /**
      * UPC分类号(主)
      */
     @JsonProperty("mupc")
-    private PatentClassify mupc ;
+    private PatentClassify mupc;
 
 
     /**
      * UPC集合
      */
     @JsonProperty("upc")
-    private List<PatentClassify> upc ;
+    private List<PatentClassify> upc;
 
     /**
      * UPC分类号(主)
      */
     @JsonProperty("mloc")
-    private PatentClassify mloc ;
+    private PatentClassify mloc;
 
 
     /**
      * UPC集合
      */
     @JsonProperty("loc")
-    private List<PatentClassify> loc ;
+    private List<PatentClassify> loc;
 
     /**
      * 专利状态
      */
     @JsonProperty("simple_status")
-    private String simpleStatus ;
+    private String simpleStatus;
 
     /**
      * 类型
      */
     @JsonProperty("patent_type")
-    private String patentType ;
+    private String patentType;
 
 
     /**
      * 权利要求
      */
     @JsonProperty("claim")
-    private List<Text> claim ;
-
-
+    private List<Text> claim;
 
     /**
      * pct申请号
      */
     @JsonProperty("pctappdate")
-    private Integer pctAppDate ;
+    private Integer pctAppDate;
 
     /**
      * pct申请日
      */
     @JsonProperty("pctappno")
-    private String pctAppNo ;
+    private String pctAppNo;
 
     /**
      * pct进入日期
      */
     @JsonProperty("pctenterdate")
-    private Integer pctEnterDate ;
+    private Integer pctEnterDate;
 
     /**
      * pct公开日
      */
     @JsonProperty("pctpubdate")
-    private Integer pctPubDate ;
+    private Integer pctPubDate;
 
     /**
      * pct公开号
      */
     @JsonProperty("pctpubno")
-    private String pctPubNo ;
+    private String pctPubNo;
 
     /**
      * wo指定国
      */
     @JsonProperty("wo")
-    private String wo ;
+    private String wo;
 
     /**
      * ep申请号
      */
     @JsonProperty("ep_no")
-    private String epNo ;
+    private String epNo;
 
     /**
      * ep申请日
      */
     @JsonProperty("ep_date")
-    private String epDate ;
-
+    private String epDate;
 
 
     /**
@@ -274,13 +271,13 @@ public class Patent {
      * 申请人数量
      */
     @JsonProperty("applicants_num")
-    private Integer applicantsNum ;
+    private Integer applicantsNum;
 
     /**
      * 权利人
      */
     @JsonProperty("right_holder")
-    private List<PatentPerson> rightHolder ;
+    private List<PatentPerson> rightHolder;
     /**
      * 标准权利人
      */
@@ -297,13 +294,13 @@ public class Patent {
      * 权利人数量
      */
     @JsonProperty("right_holder_num")
-    private Integer rightHolderNum ;
+    private Integer rightHolderNum;
 
     /**
      * 发明人
      */
     @JsonProperty("inventor")
-    private List<PatentPerson> inventor ;
+    private List<PatentPerson> inventor;
     /**
      * 合并发明人
      */
@@ -315,19 +312,19 @@ public class Patent {
      * 发明人数量
      */
     @JsonProperty("inventor_num")
-    private Integer inventor_num ;
+    private Integer inventor_num;
 
     /**
      * 代理机构
      */
     @JsonProperty("agency")
-    private String agency ;
+    private String agency;
 
     /**
      * 代理机构编号
      */
     @JsonProperty("agency_no")
-    private String agencyNo ;
+    private String agencyNo;
 
     /**
      * 代理人
@@ -339,64 +336,64 @@ public class Patent {
      * 引用专利数量
      */
     @JsonProperty("quote_patent_no_num")
-    private Integer quotePatentNoNum ;
+    private Integer quotePatentNoNum;
 
     /**
      * 被引用专利数量
      */
     @JsonProperty("quoted_patent_no_num")
-    private Integer quotedPatentNoNum ;
+    private Integer quotedPatentNoNum;
 
 
     /**
      * 自定义栏位
      */
     @JsonProperty("custom_field")
-   List<ESCustomField> ESCustomField;
+    List<ESCustomField> ESCustomField;
     /**
      * 扩展同族数量
      */
     @JsonProperty("patsnap_family_num")
-    private Integer patsnapFamilyNum ;
+    private Integer patsnapFamilyNum;
     /**
      * 扩展同族id
      */
     @JsonProperty("patsnap_family_id")
-    private String patsnapFamilyId ;
+    private String patsnapFamilyId;
 
     /**
      * INPADOC同族数量
      */
     @JsonProperty("inpadoc_family_num")
-    private Integer inpadocFamilyNum ;
+    private Integer inpadocFamilyNum;
     /**
      * INPADOC同族id
      */
     @JsonProperty("inpadoc_family_id")
-    private String inpadocFamilyId ;
+    private String inpadocFamilyId;
 
     /**
      * 简单同族数量
      */
     @JsonProperty("simple_family_num")
-    private Integer simpleFamilyNum ;
+    private Integer simpleFamilyNum;
     /**
      * 简单同族id
      */
     @JsonProperty("simple_family_id")
-    private String simpleFamilyId ;
+    private String simpleFamilyId;
 
     /**
      * 专题库或报告id
      */
     @JsonProperty("project_id")
-    private Integer projectId ;
+    private Integer projectId;
 
     /**
      * 专题库或报告id
      */
     @JsonProperty("product_id")
-    private String productId ;
+    private String productId;
 
     /**
      * 专题库或报告的任务

+ 14 - 0
src/main/java/cn/cslg/pas/mapper/PatentMapper.java

@@ -0,0 +1,14 @@
+package cn.cslg.pas.mapper;
+
+import cn.cslg.pas.domain.es.Patent;
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import org.springframework.stereotype.Repository;
+
+/**
+ * es检索
+ * @author:gck
+ * @date:2023/11/28
+ */
+@Repository
+public interface PatentMapper extends BaseMapper<Patent> {
+}

+ 120 - 0
src/main/java/cn/cslg/pas/service/business/PatentService.java

@@ -0,0 +1,120 @@
+package cn.cslg.pas.service.business;
+
+import cn.cslg.pas.common.dto.PatentDTO;
+import cn.cslg.pas.common.dto.business.EventDTO;
+import cn.cslg.pas.common.dto.business.UpdateEventDTO;
+import cn.cslg.pas.common.model.cronModel.*;
+import cn.cslg.pas.common.model.request.GroupRequest;
+import cn.cslg.pas.common.model.request.QueryRequest;
+import cn.cslg.pas.common.model.request.StringRequest;
+import cn.cslg.pas.common.utils.CacheUtils;
+import cn.cslg.pas.common.utils.LoginUtils;
+import cn.cslg.pas.common.vo.business.EventCountVO;
+import cn.cslg.pas.common.vo.business.EventVO;
+import cn.cslg.pas.domain.business.AssoEventFile;
+import cn.cslg.pas.domain.business.Event;
+import cn.cslg.pas.domain.business.SystemDict;
+import cn.cslg.pas.domain.es.Patent;
+import cn.cslg.pas.exception.UnLoginException;
+import cn.cslg.pas.exception.XiaoShiException;
+import cn.cslg.pas.factorys.businessFactory.Business;
+import cn.cslg.pas.factorys.reGroupFactory.QueryGroupFactory;
+import cn.cslg.pas.factorys.reGroupFactory.QueryGroupImp;
+import cn.cslg.pas.mapper.AssoProjectEventMapper;
+import cn.cslg.pas.mapper.EventMapper;
+import cn.cslg.pas.mapper.PatentMapper;
+import cn.cslg.pas.service.business.es.EsService;
+import cn.cslg.pas.service.common.FileManagerService;
+import cn.cslg.pas.service.permissions.PermissionService;
+import cn.cslg.pas.service.query.FormatQueryService;
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONObject;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.BeanUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+import org.springframework.web.multipart.MultipartFile;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.stream.Collectors;
+
+@Service
+@Slf4j
+public class PatentService extends ServiceImpl<PatentMapper, Patent> implements Business {
+
+    @Autowired
+    private EsService esService;
+
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public Object queryMessage(QueryRequest queryRequest) throws Exception {
+        List<PatentDTO> patents = esService.esSearch(queryRequest.getGroupField(), queryRequest.getCurrent().intValue(), queryRequest.getSize().intValue(), null);
+        Records records = new Records();
+        records.setCurrent(queryRequest.getCurrent());
+        records.setSize(queryRequest.getSize());
+        records.setData(patents);
+        records.setTotal(patents.get(0).getTotal());
+        return records;
+    }
+
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public Integer addMessage(Object object, List<MultipartFile> files) {
+     return null;
+    }
+
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public Object deleteMessage(List<Integer> ids) throws IOException {
+return  null;
+    }
+
+    /**
+     * 更新事件接口
+     *
+     * @param object
+     * @param files
+     * @return
+     */
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public Object updateMessage(Object object, List<MultipartFile> files) {
+return null;
+    }
+
+    /**
+     * 查询事件分组信息
+     *
+     * @param groupRequest
+     * @return
+     * @throws Exception
+     */
+    @Transactional(rollbackFor = Exception.class)
+    public Object getGroup(GroupRequest groupRequest,String tableName) throws Exception {
+
+        Records records = new Records();
+        records.setCurrent(groupRequest.getCurrent());
+        return records;
+    }
+
+    @Override
+    public Object addMessage(Object object) {
+        return null;
+    }
+
+    @Override
+    public Object updateMessage(Object object) {
+        return null;
+    }
+
+
+
+
+
+}

+ 12 - 5
src/main/java/cn/cslg/pas/service/business/es/EsService.java

@@ -1,5 +1,6 @@
 package cn.cslg.pas.service.business.es;
 
+import cn.cslg.pas.common.dto.PatentDTO;
 import cn.cslg.pas.common.utils.parseQueryToTree.expressManager;
 import cn.cslg.pas.common.utils.parseQueryToTree.operateNode;
 import cn.cslg.pas.common.utils.parseQueryToTree.treeNode;
@@ -11,7 +12,10 @@ import co.elastic.clients.elasticsearch._types.SortOrder;
 import co.elastic.clients.elasticsearch._types.query_dsl.*;
 import co.elastic.clients.elasticsearch.core.*;
 import co.elastic.clients.elasticsearch.core.search.Hit;
+import co.elastic.clients.elasticsearch.core.search.HitsMetadata;
+import co.elastic.clients.elasticsearch.core.search.TotalHits;
 import lombok.RequiredArgsConstructor;
+import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.context.annotation.Lazy;
 import org.springframework.stereotype.Service;
@@ -99,12 +103,10 @@ public class EsService {
      * @param orderFields     排序字段
      * @return
      */
-    public List<Patent> esSearch(String searchCondition, Integer page, Integer size, List<String> orderFields) throws Exception {
+    public List<PatentDTO> esSearch(String searchCondition, Integer page, Integer size, List<String> orderFields) throws Exception {
         SearchRequest.Builder builder = new SearchRequest.Builder();
         //设置查询索引
         builder.index("patent");
-
-
         //1. 解析检索条件
         treeNode tree = expressManager.getInstance().Parse(searchCondition, false);
         //格式化检索式
@@ -122,11 +124,16 @@ public class EsService {
                         .field("public_date").order(SortOrder.Desc)));
 
         SearchResponse<Patent> response = client.search(builder.build(), Patent.class);
-        List<Patent> list = new ArrayList<>();
+        List<PatentDTO> list = new ArrayList<>();
         List<Hit<Patent>> hits = response.hits().hits();
+
         for (Hit<Patent> hit : hits) {
+            PatentDTO dto = new PatentDTO();
+            long total = response.hits().total().value();
             Patent esMess = hit.source();
-            list.add(esMess);
+            BeanUtils.copyProperties(esMess, dto);
+            dto.setTotal(total);
+            list.add(dto);
         }
 
         return list;

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

@@ -1,5 +1,6 @@
 package cn.cslg.pas.service;
 
+import cn.cslg.pas.common.dto.PatentDTO;
 import cn.cslg.pas.common.utils.FormatUtil;
 import cn.cslg.pas.common.utils.RedisUtil;
 import cn.cslg.pas.common.vo.PatentWithIdVO;
@@ -66,7 +67,7 @@ public class EsServiceTests {
 
     @Test
     void search() throws Exception {
-        List<Patent> list = esService.esSearch("patentNo=CN201199922Y and simpleFamilyNum>1 or simpleFamilyNum=0", 0, 50,null);
+        List<PatentDTO> list = esService.esSearch("patentNo=CN201199922Y and simpleFamilyNum>1 or simpleFamilyNum=0", 0, 50,null);
 //        List<Patent> list = esService.Search("titleTextContent=电子 or projectId=1", 0, 50,null);
 //        List<Patent> list = esService.Search("patentNo=CN201199922Y and simpleFamilyNum>1", 0, 50,null);
 //        List<Patent> list = esService.Search("publicDate=2009-03", 0, 50,null);