Browse Source

检索接口

lwhhszx 2 years ago
parent
commit
61ae754aad

+ 6 - 0
PAS/src/main/java/cn/cslg/pas/common/model/dto/RetrieveRecordDTO.java

@@ -13,6 +13,10 @@ public class RetrieveRecordDTO {
      * 检索式
      */
     private String conditions;
+    /**
+     * 数据库类型
+     */
+    private String dbType;
 
     /**
      * 检索时间
@@ -23,4 +27,6 @@ public class RetrieveRecordDTO {
      * 更新时间
      */
     private Date updateTime;
+
+    private Integer totalNum;
 }

+ 47 - 0
PAS/src/main/java/cn/cslg/pas/common/model/outApi/PatentStarDto.java

@@ -0,0 +1,47 @@
+package cn.cslg.pas.common.model.outApi;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+import lombok.Data;
+import lombok.experimental.Accessors;
+
+/**
+ * 专利之星检索dto类
+ *
+ * @author 李仁杰
+ */
+
+@Accessors(chain = true)
+@Data
+public class PatentStarDto {
+    /**
+     * 检索式
+     */
+    @JsonProperty(value = "CurrentQuery")
+    private String CurrentQuery;
+    /**
+     * 表示检索中文库或世界库(CN中文专利库 WD世界专利库)
+     */
+    @JsonProperty(value = "DBType")
+    private String DBType;
+    /**
+     * 当前页,最多 200 页
+     */
+    @JsonProperty(value = "PageNum")
+    private Integer PageNum;
+    /**
+     * 每页条数,最多 50 条
+     */
+    @JsonProperty(value = "RowCount")
+    private Integer RowCount;
+    /**
+     * 排序字段:“AD”,“PD”,“GD”, “ID”
+     */
+    @JsonProperty(value = "OrderBy")
+    private String OrderBy;
+    /**
+     * 排序方式:“ASC”,“DESC”
+     */
+    @JsonProperty(value = "OrderByType")
+    private String OrderByType;
+
+}

+ 1 - 2
PAS/src/main/java/cn/cslg/pas/common/model/outApi/PatentStarListDto.java

@@ -16,6 +16,7 @@ import javax.validation.constraints.NotNull;
 @Accessors(chain = true)
 @Data
 public class PatentStarListDto {
+    private Integer retrieveRecordId;
     /**
      * 检索式
      */
@@ -47,6 +48,4 @@ public class PatentStarListDto {
     @JsonProperty(value = "OrderByType")
     private String OrderByType;
 
-
-
 }

+ 14 - 0
PAS/src/main/java/cn/cslg/pas/common/model/outApi/RetrieveRecordDeDTO.java

@@ -0,0 +1,14 @@
+package cn.cslg.pas.common.model.outApi;
+
+import com.baomidou.mybatisplus.annotation.TableField;
+import lombok.Data;
+
+import java.util.Date;
+import java.util.List;
+
+@Data
+public class RetrieveRecordDeDTO {
+
+    private List<Integer> ids;
+    private Boolean isAll;
+}

+ 23 - 0
PAS/src/main/java/cn/cslg/pas/common/model/outApi/RetrieveRecordQueryDTO.java

@@ -0,0 +1,23 @@
+package cn.cslg.pas.common.model.outApi;
+
+import lombok.Data;
+
+import java.util.Date;
+
+@Data
+public class RetrieveRecordQueryDTO {
+    /**
+     * 每页条数
+     */
+    private Integer size;
+
+    /**
+     * 当前页数
+     */
+    private Integer current;
+
+    /**
+     * 数据总数
+     */
+    private Integer total;
+}

+ 7 - 6
PAS/src/main/java/cn/cslg/pas/controller/RetrieveRecordController.java

@@ -8,6 +8,8 @@ package cn.cslg.pas.controller;
 
 import cn.cslg.pas.common.core.base.Constants;
 import cn.cslg.pas.common.model.dto.RetrieveRecordDTO;
+import cn.cslg.pas.common.model.outApi.RetrieveRecordDeDTO;
+import cn.cslg.pas.common.model.outApi.RetrieveRecordQueryDTO;
 import cn.cslg.pas.common.utils.Response;
 import cn.cslg.pas.domain.RetrieveRecord;
 import cn.cslg.pas.service.upLoadPatent.RetrieveRecordService;
@@ -40,16 +42,15 @@ public class RetrieveRecordController {
     }
 
     @Operation(summary = "查询检索历史")
-    @GetMapping("/queryRetrieveRecord")
-    public String queryRetrieveRecord(){
-        List<RetrieveRecord> retrieveRecordList = retrieveRecordService.queryRetrieveRecord();
-        return Response.success(retrieveRecordList);
+    @PostMapping("/queryRetrieveRecord")
+    public String queryRetrieveRecord(@RequestBody RetrieveRecordQueryDTO retrieveRecordQueryDTO){
+        return Response.success(retrieveRecordService.queryRetrieveRecord(retrieveRecordQueryDTO));
     }
 
     @Operation(summary = "删除检索历史")
     @PostMapping("/deleteRetrieveRecord")
-    public String deleteRetrieveRecord(@RequestBody List<Integer> ids){
-        retrieveRecordService.deleteRetrieveRecord(ids);
+    public String deleteRetrieveRecord(@RequestBody RetrieveRecordDeDTO retrieveRecordDeDTO){
+        retrieveRecordService.deleteRetrieveRecord(retrieveRecordDeDTO);
         return Response.success("删除成功");
     }
 }

+ 1 - 1
PAS/src/main/java/cn/cslg/pas/controller/outApi/PatentStarController.java

@@ -28,7 +28,7 @@ public class PatentStarController {
     @PostMapping("/select")
     @Operation(summary = "一般检索接口")
     public String getAreaList(@RequestBody @Validated PatentStarListDto patentStarListDto) throws IOException {
-        Map<String, Object> map = patentStarApiService.patentStarSearchApi(patentStarListDto);
+        Map<String, Object> map = patentStarApiService.patentStarSearchLocal(patentStarListDto);
         if (map == null) {
             return Response.error("检索失败,请检查检索式");
         }

+ 7 - 1
PAS/src/main/java/cn/cslg/pas/domain/RetrieveRecord.java

@@ -23,12 +23,18 @@ public class RetrieveRecord extends BaseEntity<RetrieveRecord> {
      */
     @TableField(value = "conditions")
     private String conditions;
-
+    @TableField(value = "db_type")
+    private String dbType;
     /**
      * 租户
      */
     @TableField(value = "tenant_id")
     private Integer tenantId;
+    /**
+     * 总条数
+     */
+    @TableField(value = "total_num")
+    private Integer totalNum;
 
     /**
      * 创建时间

+ 46 - 10
PAS/src/main/java/cn/cslg/pas/service/outApi/PatentStarApiService.java

@@ -1,16 +1,18 @@
 package cn.cslg.pas.service.outApi;
 
 import cn.cslg.pas.common.model.PatentCell;
-import cn.cslg.pas.common.model.dto.GetClaimsInfoParamsDTO;
-import cn.cslg.pas.common.model.dto.GetDescriptionInfoParamsDTO;
-import cn.cslg.pas.common.model.dto.GetFuTuParamsDTO;
-import cn.cslg.pas.common.model.dto.GetSearchBiblioParamsDTO;
+import cn.cslg.pas.common.model.PersonnelVO;
+import cn.cslg.pas.common.model.dto.*;
+import cn.cslg.pas.common.model.outApi.PatentStarDto;
 import cn.cslg.pas.common.model.outApi.PatentStarListDto;
 import cn.cslg.pas.common.model.vo.outApi.StarPatentVO;
+import cn.cslg.pas.common.utils.CacheUtils;
 import cn.cslg.pas.common.utils.FormatUtil;
 import cn.cslg.pas.common.utils.JsonUtils;
+import cn.cslg.pas.common.utils.SecurityUtils.LoginUtils;
 import cn.cslg.pas.common.utils.SecurityUtils.SecurityUtils;
 import cn.cslg.pas.domain.*;
+import cn.cslg.pas.service.upLoadPatent.RetrieveRecordService;
 import cn.hutool.crypto.SecureUtil;
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONArray;
@@ -22,6 +24,7 @@ import lombok.extern.slf4j.Slf4j;
 import okhttp3.*;
 import org.apache.commons.lang3.StringEscapeUtils;
 import org.junit.Test;
+import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
 
@@ -42,7 +45,9 @@ import java.util.regex.Pattern;
 @Service
 
 public class PatentStarApiService {
-
+    private  final RetrieveRecordService retrieveRecordService;
+    private final CacheUtils cacheUtils;
+    private final LoginUtils loginUtils;
     public static String formatValue(String value) {
         return value.replace("~", ">");
     }
@@ -209,17 +214,48 @@ public class PatentStarApiService {
             //法律状态
         });
     }
+public Map<String,Object>patentStarSearchLocal(PatentStarListDto patentStarListDto)throws IOException{
+
+    RetrieveRecord retrieveRecord =new RetrieveRecord();
+    retrieveRecord.setConditions(patentStarListDto.getCurrentQuery());
+    if(patentStarListDto.getRetrieveRecordId()!=null){
+        retrieveRecord=retrieveRecordService.getById(patentStarListDto.getRetrieveRecordId());
+        patentStarListDto.setCurrentQuery(retrieveRecord.getConditions());
+        patentStarListDto.setDBType(retrieveRecord.getDbType());
+    }
+Map<String,Object> map =   this.patentStarSearchApi(patentStarListDto);
+    //记录检索历史
+    retrieveRecord.setRetrieveTime(new Date());
+    retrieveRecord.setTotalNum(Integer.parseInt(map.get("total").toString()));
+    retrieveRecord.setDbType(patentStarListDto.getDBType());
+    if(patentStarListDto.getRetrieveRecordId()==null) {
+        //获取创建人信息
+        PersonnelVO personnelVO = cacheUtils.getLoginUser(loginUtils.getId());
+        retrieveRecord.setCreateTime(new Date());
+        retrieveRecord.setCreateId(personnelVO.getId());
+        retrieveRecord.setTenantId(personnelVO.getTenantId());
+        retrieveRecord.insert();
 
+    }
+    else {
+        retrieveRecord.updateById();
+    }
+    map.put("retrieveRecordId",retrieveRecord.getId());
+        return map ;
+
+}
 
     public Map<String, Object> patentStarSearchApi(PatentStarListDto patentStarListDto) throws IOException {
         try {
-            String formQuery = patentStarListDto.getCurrentQuery();
-            patentStarListDto.setCurrentQuery(PatentStarApiService.formatQuery(formQuery));
+                String formQuery = patentStarListDto.getCurrentQuery();
+                patentStarListDto.setCurrentQuery(PatentStarApiService.formatQuery(formQuery));
+
         } catch (Exception e) {
             return null;
         }
-
-        String json = JSONObject.toJSONString(patentStarListDto);
+        PatentStarDto patentStarDto= new PatentStarDto();
+        BeanUtils.copyProperties(patentStarListDto,patentStarDto);
+        String json = JSONObject.toJSONString(patentStarDto);
         String url = "http://s.patentstar.com.cn/SearchAPI/PatentSearch/ResultGet";
         Long currentTimeMillis = System.currentTimeMillis() / 1000;
         String Sign = "FNYJD7902206FFB741E163BE6536C3689D55" + currentTimeMillis.toString();
@@ -308,6 +344,7 @@ public class PatentStarApiService {
         return "{}";
     }
 
+
     /**
      * @param
      * @return
@@ -439,7 +476,6 @@ public class PatentStarApiService {
      * @author 李仁杰
      * 从专利之星获取中国专利全文图片
      */
-
     public String getCnPdfApi(String appNo) throws IOException {
         String url = "https://api.patentstar.com.cn/api/Patent/CnPdf/" + appNo;
         String appId = "2000041";

+ 34 - 18
PAS/src/main/java/cn/cslg/pas/service/upLoadPatent/RetrieveRecordService.java

@@ -2,18 +2,24 @@ package cn.cslg.pas.service.upLoadPatent;
 
 import cn.cslg.pas.common.model.PersonnelVO;
 import cn.cslg.pas.common.model.dto.RetrieveRecordDTO;
+import cn.cslg.pas.common.model.outApi.RetrieveRecordDeDTO;
+import cn.cslg.pas.common.model.outApi.RetrieveRecordQueryDTO;
 import cn.cslg.pas.common.utils.CacheUtils;
 import cn.cslg.pas.common.utils.Response;
 import cn.cslg.pas.common.utils.SecurityUtils.LoginUtils;
 import cn.cslg.pas.domain.RetrieveRecord;
 import cn.cslg.pas.mapper.RetrieveRecordMapper;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import lombok.RequiredArgsConstructor;
 import org.springframework.beans.BeanUtils;
 import org.springframework.context.annotation.Lazy;
 import org.springframework.stereotype.Service;
 
+import java.util.ArrayList;
+import java.util.Date;
 import java.util.List;
 
 /**
@@ -21,7 +27,7 @@ import java.util.List;
  * 检索记录表
  * </p>
  *
- * @author 李仁杰
+ * @author 谢翔
  * @since 2022-07-9
  */
 @Service
@@ -44,6 +50,9 @@ public class RetrieveRecordService extends ServiceImpl<RetrieveRecordMapper, Ret
             //获取创建人信息
             PersonnelVO personnelVO = cacheUtils.getLoginUser(loginUtils.getId());
             retrieveRecord.setCreateId(personnelVO.getId());
+            retrieveRecord.setDbType(retrieveRecordDTO.getDbType());
+            retrieveRecord.setConditions(retrieveRecordDTO.getConditions());
+            retrieveRecord.setTotalNum(retrieveRecordDTO.getTotalNum());
             retrieveRecord.setTenantId(personnelVO.getTenantId());
             //数据入表
             retrieveRecord.insert();
@@ -64,11 +73,9 @@ public class RetrieveRecordService extends ServiceImpl<RetrieveRecordMapper, Ret
             Integer id = retrieveRecordDTO.getId();
             //根据传入对象的id查询出实体类
             RetrieveRecord retrieveRecord = this.getById(id);
-            //更新数据
-            BeanUtils.copyProperties(retrieveRecordDTO, retrieveRecord);
-            PersonnelVO personnelVO = cacheUtils.getLoginUser(loginUtils.getId());
-            retrieveRecord.setCreateId(personnelVO.getId());
-            retrieveRecord.setTenantId(personnelVO.getTenantId());
+            retrieveRecord.setDbType(retrieveRecordDTO.getDbType());
+            retrieveRecord.setConditions(retrieveRecordDTO.getConditions());
+            retrieveRecord.setUpdateTime(new Date());
             retrieveRecord.updateById();
             return Response.success("更新成功");
         } else {
@@ -78,30 +85,39 @@ public class RetrieveRecordService extends ServiceImpl<RetrieveRecordMapper, Ret
 
     /**
      * 删除检索历史
-     * @param ids
      * @return
      */
-    public String deleteRetrieveRecord(List<Integer> ids){
-        //判空
-        if(ids != null && ids.size() > 0){
-            this.removeByIds(ids);
-            return Response.success("删除成功");
-        } else {
-            return Response.error("删除错误");
-        }
+    public String deleteRetrieveRecord(RetrieveRecordDeDTO retrieveRecordDeDTO){
+       List<Integer> ids = retrieveRecordDeDTO.getIds();
+       Boolean isAll =retrieveRecordDeDTO.getIsAll();
+       if(isAll!=null&& isAll){
+           this.remove(new LambdaQueryWrapper<RetrieveRecord>());
+       }
+       else {
+           //判空
+           if (ids != null && ids.size() > 0) {
+               this.removeByIds(ids);
+               return Response.success("删除成功");
+           } else {
+               return Response.error("删除错误");
+           }
+       }
+        return Response.success("删除成功");
     }
 
     /**
      * 查询检索历史
      * @return
      */
-    public List<RetrieveRecord> queryRetrieveRecord(){
+    public IPage<RetrieveRecord> queryRetrieveRecord( RetrieveRecordQueryDTO retrieveRecordQueryDTO){
         //获取当前登陆人信息
         PersonnelVO personnelVO = cacheUtils.getLoginUser(loginUtils.getId());
         Integer createId = personnelVO.getId();
         LambdaQueryWrapper<RetrieveRecord> queryWrapper = new LambdaQueryWrapper<>();
-        queryWrapper.eq(RetrieveRecord::getCreateId, createId);
-        List<RetrieveRecord> retrieveRecords = this.list(queryWrapper);
+        queryWrapper.eq(RetrieveRecord::getCreateId, createId)
+        .orderByDesc(RetrieveRecord::getUpdateTime);
+        IPage<RetrieveRecord> retrieveRecords = this.page(new Page<>(retrieveRecordQueryDTO.getCurrent(),retrieveRecordQueryDTO.getSize()),queryWrapper);
+        List<RetrieveRecord> retrieveRecordList =retrieveRecords.getRecords();
         return retrieveRecords;
     }
 }

+ 13 - 1
PAS/src/main/resources/mapper/TaskMapper.xml

@@ -83,6 +83,18 @@
     <resultMap id="queryTasksMap" type="cn.cslg.pas.common.model.vo.QueryTaskVO">
 
     </resultMap>
-
+    <select id="queryTask" resultMap="queryTasksMap">
+        select tas.*
+        from os_task tas
+        left join task_condition ass on tas.task_condition_id = ass.id
+        <where>
+            (tas.task_condition_id is null
+            or tas.id in (
+            select a1
+            .id from os_task a1 left join os_task a2 on a1.task_condition_id =a2.task_condition_id and
+            a1.create_time &lt;= a2.create_time group by a1.task_condition_id having count(*)=1)
+            )
+        </where>
+    </select>
 
 </mapper>