Przeglądaj źródła

Merge remote-tracking branch 'origin/master' into test

# Conflicts:
#	src/main/resources/application.yml
lwhhszx 1 rok temu
rodzic
commit
81e4e47e72

+ 8 - 4
src/main/java/com/example/xiaoshiweixinback/business/utils/FormatUtil.java

@@ -6,10 +6,8 @@ import org.springframework.beans.BeanWrapperImpl;
 
 import java.security.MessageDigest;
 import java.security.NoSuchAlgorithmException;
-import java.util.ArrayList;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
+import java.text.SimpleDateFormat;
+import java.util.*;
 
 public class FormatUtil {
 
@@ -106,4 +104,10 @@ public class FormatUtil {
         return  strs;
     }
 
+
+    public static String getTimeStringYYMMdd(Date startDate){
+        SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMdd");
+        String dateString = formatter.format(startDate);
+        return dateString;
+    }
 }

+ 8 - 4
src/main/java/com/example/xiaoshiweixinback/controller/MonitoringController.java

@@ -14,10 +14,7 @@ import com.example.xiaoshiweixinback.service.MonitorService;
 import io.swagger.v3.oas.annotations.Operation;
 import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
-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;
+import org.springframework.web.bind.annotation.*;
 
 import java.util.List;
 
@@ -63,4 +60,11 @@ public class MonitoringController {
         return Response.success(records);
     }
 
+
+    @Operation(summary = "添加记录")
+    @GetMapping("/add")
+    public Response add() {
+      monitorRecordService.addMonitorRecords();
+        return Response.success("records");
+    }
 }

+ 2 - 1
src/main/java/com/example/xiaoshiweixinback/controller/SearchRecordController.java

@@ -59,7 +59,8 @@ public class SearchRecordController {
         try {
             List<Integer> idList = searchRecordService.removeSearchRecords(ids);
             records.setData(idList);
-        } catch (Exception e) {
+        }
+        catch (Exception e) {
             return Response.error(e.getMessage());
         }
 

+ 2 - 0
src/main/java/com/example/xiaoshiweixinback/domain/Monitor.java

@@ -15,6 +15,7 @@ import lombok.Data;
 @TableName(value ="monitor")
 @Data
 public class Monitor extends BaseEntity<Monitor> {
+    private Integer id;
 
     /**
      * 
@@ -35,5 +36,6 @@ public class Monitor extends BaseEntity<Monitor> {
      * 
      */
     private Date createTime;
+    private Boolean ifDelete;
 
 }

+ 2 - 2
src/main/java/com/example/xiaoshiweixinback/domain/MonitorRecord.java

@@ -19,7 +19,7 @@ public class MonitorRecord extends BaseEntity<MonitorRecord> {
     /**
      * 
      */
-    private Integer monitorId;
+    private Integer productId;
 
     /**
      * 
@@ -39,7 +39,7 @@ public class MonitorRecord extends BaseEntity<MonitorRecord> {
     /**
      * 
      */
-    private Integer num;
+    private Long num;
     private String searchCondition;
 
 }

+ 1 - 1
src/main/java/com/example/xiaoshiweixinback/entity/dto/patent/PatentDTO.java

@@ -13,5 +13,5 @@ public class PatentDTO {
 
     private Long pageSize;
 
-//    private List<PatentColumnDTO> patents;
+    private List<PatentColumnDTO> patents;
 }

+ 73 - 1
src/main/java/com/example/xiaoshiweixinback/service/MonitorRecordService.java

@@ -4,10 +4,22 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.example.xiaoshiweixinback.business.common.base.Records;
+import com.example.xiaoshiweixinback.business.utils.FormatUtil;
+import com.example.xiaoshiweixinback.domain.Monitor;
 import com.example.xiaoshiweixinback.domain.MonitorRecord;
+import com.example.xiaoshiweixinback.domain.PatentUpdateRecord;
+import com.example.xiaoshiweixinback.domain.Product;
+import com.example.xiaoshiweixinback.entity.dto.patent.PatentDTO;
+import com.example.xiaoshiweixinback.entity.patent.QueryRequest;
+import com.example.xiaoshiweixinback.entity.patent.StringRequest;
 import com.example.xiaoshiweixinback.mapper.MonitorRecordMapper;
+import com.example.xiaoshiweixinback.service.importPatent.EsPatentService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.scheduling.annotation.Async;
 import org.springframework.stereotype.Service;
 
+import java.util.ArrayList;
+import java.util.Date;
 import java.util.List;
 
 /**
@@ -17,16 +29,76 @@ import java.util.List;
  */
 @Service
 public class MonitorRecordService extends ServiceImpl<MonitorRecordMapper, MonitorRecord> {
+    @Autowired
+    private PatentUpdateRecordService patentUpdateRecordService;
+    @Autowired
+    private MonitorService monitorService;
+    @Autowired
+    private EsPatentService esPatentService;
 
     public Records getMonitorRecords(Integer monitorId) {
+        Monitor monitor = monitorService.getById(monitorId);
+        Integer projectId =monitor.getProductId();
+
         LambdaQueryWrapper<MonitorRecord> queryWrapper = new LambdaQueryWrapper<>();
-        queryWrapper.eq(MonitorRecord::getMonitorId, monitorId);
+        queryWrapper.eq(MonitorRecord::getProductId, projectId)
+                 .ge(MonitorRecord::getStartDate,monitor.getCreateTime());
         Page<MonitorRecord> monitorRecords = this.page(new Page<>(1, 10), queryWrapper);
         Records records = new Records();
         records.setData(monitorRecords.getRecords());
         records.setTotal(monitorRecords.getTotal());
         return records;
     }
+
+    public MonitorRecord getLastMonitorRecord(Integer productId) {
+        LambdaQueryWrapper<MonitorRecord> queryWrapper = new LambdaQueryWrapper<>();
+        queryWrapper.eq(MonitorRecord::getProductId, productId)
+                .orderByDesc(MonitorRecord::getCreateTime);
+        MonitorRecord monitorRecord = this.getOne(queryWrapper, false);
+        return monitorRecord;
+
+    }
+
+
+    public void addMonitorRecords() {
+        //获取最新的更新记录
+        PatentUpdateRecord patentUpdateRecord = patentUpdateRecordService.getLastRecord();
+        //获取所有被监控的产品
+        List<Product> products = monitorService.getAllMonitorProducts();
+        for (Product product : products) {
+            Integer productId = product.getId();
+            MonitorRecord monitorRecord = this.getLastMonitorRecord(product.getId());
+            Date startTime = patentUpdateRecord.getStartTime();
+            Date endTime = patentUpdateRecord.getEndTime();
+            if(monitorRecord!=null){
+                startTime =monitorRecord.getEndDate();
+            }
+            String condition = product.getSearchCondition();
+
+            String newCondition = condition + " AND " + "PD=" + FormatUtil.getTimeStringYYMMdd(startTime) + "~" + FormatUtil.getTimeStringYYMMdd(endTime);
+            StringRequest stringRequest = new StringRequest();
+            stringRequest.setSearchQuery(newCondition);
+            try {
+                PatentDTO patentDTO = esPatentService.esSearch(stringRequest);
+                Long total = patentDTO.getTotal();
+                if (total != null && total > 0) {
+                    MonitorRecord monitorRecord1 = new MonitorRecord();
+                    monitorRecord1.setProductId(productId);
+                    monitorRecord1.setStartDate(startTime);
+                    monitorRecord1.setEndDate(endTime);
+                    monitorRecord1.setSearchCondition(product.getSearchCondition());
+                    monitorRecord1.setNum(total);
+                    monitorRecord1.insert();
+                }
+            } catch (Exception e) {
+                e.printStackTrace();
+
+            }
+        }
+
+    }
+
+
 }
 
 

+ 21 - 5
src/main/java/com/example/xiaoshiweixinback/service/MonitorService.java

@@ -8,6 +8,7 @@ import com.example.xiaoshiweixinback.business.utils.CacheUtil;
 import com.example.xiaoshiweixinback.business.utils.LoginUtils;
 import com.example.xiaoshiweixinback.domain.Monitor;
 
+import com.example.xiaoshiweixinback.domain.Product;
 import com.example.xiaoshiweixinback.entity.dto.AssoPersonProductDTO;
 import com.example.xiaoshiweixinback.entity.dto.GetProductDTO;
 import com.example.xiaoshiweixinback.entity.dto.monitoring.AddMonitoringDTO;
@@ -26,6 +27,7 @@ import org.springframework.context.annotation.Lazy;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
+import java.util.ArrayList;
 import java.util.List;
 import java.util.stream.Collectors;
 
@@ -74,6 +76,8 @@ public class MonitorService extends ServiceImpl<MonitorMapper, Monitor> {
                 .eq(Monitor::getProductId, productId);
         Monitor monitor = this.getOne(queryWrapper, false);
         if (monitor != null) {
+            monitor.setIfDelete(false);
+            monitor.updateById();
             return productId;
         }
         //添加监控
@@ -113,7 +117,11 @@ public class MonitorService extends ServiceImpl<MonitorMapper, Monitor> {
         LambdaQueryWrapper<Monitor> queryWrapper = new LambdaQueryWrapper<>();
         queryWrapper.in(Monitor::getProductId, productIds)
                 .eq(Monitor::getCreateId, personnelVO.getUuid());
-        this.remove(queryWrapper);
+        List<Monitor> monitors = this.list(queryWrapper);
+        monitors.forEach(item -> {
+            item.setIfDelete(true);
+            item.updateById();
+        });
         return productIds;
 
     }
@@ -149,12 +157,20 @@ public class MonitorService extends ServiceImpl<MonitorMapper, Monitor> {
     }
 
 
-    public void getAllMonitor() {
+    public List<Product> getAllMonitorProducts() {
+        List<Product> products = new ArrayList<>();
         LambdaQueryWrapper<Monitor> queryWrapper = new LambdaQueryWrapper<>();
         List<Monitor> monitors = this.list(queryWrapper);
-        List<Integer> productIds = monitors.stream().map(Monitor::getProductId).collect(Collectors.toList());
-
-
+        if (monitors.size() == 0) {
+            return products;
+        }
+        List<Integer> productIds = monitors.stream().map(Monitor::getProductId).distinct().collect(Collectors.toList());
+        if (productIds != null && productIds.size() > 0) {
+            LambdaQueryWrapper<Product> queryWrapper1 = new LambdaQueryWrapper<>();
+            queryWrapper1.in(Product::getId, productIds);
+            products = productService.list(queryWrapper1);
+        }
+        return products;
     }
 }
 

+ 7 - 0
src/main/java/com/example/xiaoshiweixinback/service/PatentUpdateRecordService.java

@@ -34,6 +34,13 @@ public class PatentUpdateRecordService extends ServiceImpl<PatentUpdateRecordMap
         patentUpdateRecord.insert();
         return  patentUpdateRecord;
     }
+
+    public PatentUpdateRecord getLastRecord(){
+        LambdaQueryWrapper<PatentUpdateRecord> queryWrapper =new LambdaQueryWrapper<>();
+        queryWrapper.orderByDesc(PatentUpdateRecord::getEndTime);
+        PatentUpdateRecord patentUpdateRecord =this.getOne(queryWrapper,false);
+         return  patentUpdateRecord;
+    }
 }
 
 

+ 2 - 1
src/main/java/com/example/xiaoshiweixinback/service/ProductService.java

@@ -132,7 +132,8 @@ public class ProductService extends ServiceImpl<ProductMapper, Product> {
             if (personnelVO != null) {
                 LambdaQueryWrapper<Monitor> monitorLambdaQueryWrapper = new LambdaQueryWrapper<>();
                 monitorLambdaQueryWrapper.in(Monitor::getProductId, ids)
-                        .eq(Monitor::getCreateId, personnelVO.getUuid());
+                        .eq(Monitor::getCreateId, personnelVO.getUuid())
+                        .eq(Monitor::getIfDelete,false);
                 monitors = monitorService.list(monitorLambdaQueryWrapper);
             }
         }

+ 64 - 1
src/main/java/com/example/xiaoshiweixinback/service/importPatent/EsDenseVectorService.java

@@ -97,7 +97,7 @@ public class EsDenseVectorService {
     @Value("${ES.patent}")
     private String patentMapName;
 
-    /**
+    /**R
      * 根据图片排序获取列表
      *
      * @param dto
@@ -367,4 +367,67 @@ public class EsDenseVectorService {
         return s;
     }
 
+
+    @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Throwable.class)
+    public Records getPatents(EsPatentVectorDTO dto) throws Exception {
+        Long pageNum = dto.getPageNum();
+        Long pageSize = dto.getPageSize();
+        Boolean ifAddSearchRecord = dto.getIfAddSearchRecord();
+
+        SearchRequest.Builder builder = new SearchRequest.Builder();
+        //设置查询索引
+        builder.index(patentVectorName);
+        Query q = null;
+        String condition = this.appendCondition(dto.getProductId(), dto.getKey(), dto.getAppCountry(), dto.getCompanyName());
+
+        if (StringUtils.isNotEmpty(condition)) {
+            //1. 解析检索条件
+            treeNode tree = expressManager.getInstance().Parse(condition, false);
+            //2. 从es中检索数据
+            q = formatQueryService.EsQueryToQuery((operateNode) tree, "patentVector", null);
+        }
+
+        if (q == null) {
+            throw new BusinessException("608", "检索式错误,请重新输入");
+        }
+
+        builder.query(q);
+
+        //根据申请号去重
+        FieldCollapse collapse = FieldCollapse.of(i -> i.field("app_no"));
+        builder.collapse(collapse);
+        //统计总数
+        Aggregation aggregation = AggregationBuilders.cardinality(i -> i.field("app_no"));
+        builder.aggregations("count", aggregation);
+
+        //分页
+        if (pageNum != null && pageSize != null && pageNum > 0 && pageSize > 0) {
+            builder.from((pageNum.intValue() - 1) * pageSize.intValue()).size(pageSize.intValue());
+        }
+
+        //解除最大条数限制
+        builder.trackTotalHits(i -> i.enabled(true));
+        SearchResponse<PatentVector> response = client.search(builder.build(), PatentVector.class);
+        List<Hit<PatentVector>> hits = response.hits().hits();
+        List<EsPatentVectorVo> vectorVos = new ArrayList<>();
+        for (Hit<PatentVector> hit : hits) {
+            PatentVector vector = hit.source();
+            EsPatentVectorVo vectorVo = new EsPatentVectorVo();
+            BeanUtil.copy(vector, vectorVo);
+            PatentColumnDTO columnDTO = esPatentService.selectPatentByAppNo(vector.getAppNo());
+            vectorVo.setPatentNo(columnDTO.getPatentNo());
+            vectorVos.add(vectorVo);
+        }
+
+        Aggregate aggregate = response.aggregations().get("count");
+        long total = aggregate.cardinality().value();
+        Records records = new Records();
+        records.setCurrent(pageNum);
+        records.setSize(pageSize);
+        records.setData(vectorVos);
+        records.setTotal(total);
+
+        return records;
+    }
+
 }

+ 97 - 6
src/main/java/com/example/xiaoshiweixinback/service/importPatent/EsPatentService.java

@@ -3,8 +3,9 @@ package com.example.xiaoshiweixinback.service.importPatent;
 import co.elastic.clients.elasticsearch.ElasticsearchClient;
 import co.elastic.clients.elasticsearch._types.InlineScript;
 import co.elastic.clients.elasticsearch._types.Script;
-import co.elastic.clients.elasticsearch._types.aggregations.Aggregation;
-import co.elastic.clients.elasticsearch._types.aggregations.AggregationBuilders;
+import co.elastic.clients.elasticsearch._types.SortOptions;
+import co.elastic.clients.elasticsearch._types.SortOrder;
+import co.elastic.clients.elasticsearch._types.aggregations.*;
 import co.elastic.clients.elasticsearch._types.query_dsl.Query;
 import co.elastic.clients.elasticsearch._types.query_dsl.QueryBuilders;
 import co.elastic.clients.elasticsearch.core.SearchRequest;
@@ -12,6 +13,7 @@ import co.elastic.clients.elasticsearch.core.SearchResponse;
 import co.elastic.clients.elasticsearch.core.search.FieldCollapse;
 import co.elastic.clients.elasticsearch.core.search.Hit;
 import co.elastic.clients.json.JsonData;
+import com.alibaba.fastjson.JSON;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.example.xiaoshiweixinback.business.common.base.Records;
 import com.example.xiaoshiweixinback.business.exception.BusinessException;
@@ -27,6 +29,9 @@ import com.example.xiaoshiweixinback.domain.AssoPersonProduct;
 import com.example.xiaoshiweixinback.domain.es.*;
 import com.example.xiaoshiweixinback.entity.dto.esPicture.EsPictureNoDTO;
 import com.example.xiaoshiweixinback.entity.dto.patent.*;
+import com.example.xiaoshiweixinback.entity.patent.MapRequest;
+import com.example.xiaoshiweixinback.entity.patent.QueryRequest;
+import com.example.xiaoshiweixinback.entity.patent.StringRequest;
 import com.example.xiaoshiweixinback.entity.vo.PersonnelVO;
 import com.example.xiaoshiweixinback.entity.vo.esPicture.EsPatentVectorVo;
 import com.example.xiaoshiweixinback.entity.vo.esPicture.EsPictureNoVo;
@@ -45,13 +50,13 @@ import org.springframework.util.CollectionUtils;
 
 import java.io.File;
 import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
+import java.util.*;
 import java.util.stream.Collectors;
 
 @Service
 @RequiredArgsConstructor(onConstructor_ = {@Lazy})
+
+
 public class EsPatentService {
 
     private final ElasticsearchClient client;
@@ -78,9 +83,10 @@ public class EsPatentService {
     private FormatQueryService formatQueryService;
 
     @Value("${ES.patentVector}")
-    private  String patentVectorName;
+    private String patentVectorName;
     @Value("${ES.patent}")
     private String patentMapName;
+
     /**
      * 收藏专利
      *
@@ -93,9 +99,12 @@ public class EsPatentService {
         Integer productId = patentDTO.getProductId();
         //获取用户
         PersonnelVO personnelVO = cacheUtils.getLoginUser(LoginUtils.getToken());
+
+
         if (ToolUtil.isEmpty(personnelVO)) {
             throw new BusinessException(ExceptionEnum.THE_GET_INFORMATION_TOKEN_INVALID);
         }
+
         String uuid = personnelVO.getUuid();
         //获取人员产品关联表id
         AssoPersonProduct assoPersonProduct = assoPersonProductMapper.selectOne(new LambdaQueryWrapper<AssoPersonProduct>()
@@ -332,6 +341,7 @@ public class EsPatentService {
 
     /**
      * 查询专利(用于导出专利数据)
+     *
      * @param patentDTO
      * @param file
      * @return
@@ -377,6 +387,7 @@ public class EsPatentService {
 
     /**
      * 获取图片专利里的信息
+     *
      * @param patentDTO
      * @param file
      * @return
@@ -456,6 +467,7 @@ public class EsPatentService {
 
     /**
      * 根据申请号查询专利信息
+     *
      * @param appNo
      * @return
      * @throws IOException
@@ -477,4 +489,83 @@ public class EsPatentService {
         return columnDTO;
     }
 
+
+    /**
+     * Es检索
+     *
+     * @param queryRequest 检索条件
+     * @return
+     */
+    public PatentDTO esSearch(QueryRequest queryRequest) throws Exception {
+        PatentDTO dto = new PatentDTO();
+        String searchCondition = "";
+        Integer projectId = queryRequest.getProjectId();
+        Long current = queryRequest.getCurrent();
+        Long size = queryRequest.getSize();
+
+        //判断表达式
+        if (queryRequest instanceof StringRequest) {
+            searchCondition = ((StringRequest) queryRequest).getSearchQuery();
+        } else if (queryRequest instanceof MapRequest) {
+            Map<String, Object> map = ((MapRequest) queryRequest).getSearchQuery();
+            StringBuilder stringBuilder = new StringBuilder();
+            for (String key : map.keySet()) {
+                Object value = map.get(key);
+                if (!"".contentEquals(stringBuilder)) {
+                    stringBuilder = stringBuilder.append(" AND ").append(key).append("=").append(value);
+                } else {
+                    stringBuilder = stringBuilder.append(key).append("=").append(value);
+                }
+            }
+            searchCondition = stringBuilder.toString();
+        }
+
+        String condition = searchCondition;
+
+        SearchRequest.Builder builder = new SearchRequest.Builder();
+        //设置查询索引
+        builder.index("wxpatent");
+        //1. 解析检索条件
+        treeNode tree = expressManager.getInstance().Parse(condition, false);
+        //3. 从es中检索数据
+        Query q = formatQueryService.EsQueryToQuery((operateNode) tree, "patent", projectId);
+        builder.query(q);
+
+        //排序
+//        List<SortOptions> optionsList = new ArrayList<>();
+//
+//            SortOptions sortOptions = SortOptions.of(i -> i.field(j -> j.field("public_date").order(SortOrder.Desc).missing(-1)));
+//            optionsList.add(sortOptions);
+//
+//        builder.sort(optionsList);
+
+//        //分页
+//        if (current != null && size != null && current > 0 && size > 0) {
+//            builder.from((current.intValue() - 1) * size.intValue()).size(size.intValue());
+//        } else {
+//            builder.from(1).size(99999);
+//        }
+
+        //解除最大条数限制
+        builder.trackTotalHits(i -> i.enabled(true));
+        SearchResponse<Patent> response = client.search(builder.build(), Patent.class);
+        List<PatentColumnDTO> list = new ArrayList<>();
+        long total = 0L;
+            List<Hit<Patent>> hits = response.hits().hits();
+            total = response.hits().total().value();
+            for (Hit<Patent> hit : hits) {
+//                String id = hit.id();
+//                Patent esMess = hit.source();
+//                PatentColumnDTO columnDTO = this.getPatentColumnDTO(esMess, projectId, id);
+//                list.add(columnDTO);
+            }
+
+
+        dto.setTotal(total);
+        dto.setPatents(list);
+        dto.setPageNum(current);
+        dto.setPageSize(size);
+        return dto;
+    }
+
 }

+ 1 - 0
src/main/java/com/example/xiaoshiweixinback/service/importPatent/ImportFromWebToEsService.java

@@ -140,6 +140,7 @@ private GetFiguresService getFiguresService;
                 }
 
             }
+            System.out.println("ImportTaskDone");
             return ifHaveGet;
         } catch (Exception e) {
             e.printStackTrace();

+ 2 - 2
src/main/resources/mapper/ProductMapper.xml

@@ -145,7 +145,7 @@
         left join product as p on app.product_id =p.id
         left join person as pe on p.create_id =pe.uuid
         <where>
-            app.create_id  = #{getProductDTO.personUuid}
+            app.create_id  = #{getProductDTO.personUuid} and if_delete=false
             <if test="getProductDTO.name!=null and getProductDTO.name!=''">
                 and p.name like CONCAT('%',#{getProductDTO.name},'%')
             </if>
@@ -174,7 +174,7 @@
         left join product as p on app.product_id =p.id
         left join person as pe on p.create_id =pe.uuid
         <where>
-            app.create_id = #{getProductDTO.personUuid}
+            app.create_id = #{getProductDTO.personUuid} and if_delete=false
             <if test="getProductDTO.name!=null and getProductDTO.name!=''">
                 and p.name like CONCAT('%',#{getProductDTO.name},'%')
             </if>