Browse Source

fixed essearch

zero 1 year ago
parent
commit
cd0374e12b

+ 4 - 1
src/main/java/com/example/xiaoshiweixinback/business/common/ResponseEnum.java

@@ -20,7 +20,10 @@ public enum ResponseEnum {
     PATENT_PDF_EXPORT_TASK(604,"导出PDF首页"),
     PATENT_PDF_EXPORT_TASK_DONE(605,"导出PDF首页完成"),
     LOGIN_ERROR(606,"登录错误"),
-    BUSINESS_ERROR(607,"业务错误");
+    BUSINESS_ERROR(607,"业务错误"),
+
+    //es检索业务错误异常
+    THE_RETRIEVAL_ERROR(608,"检索式错误");
 
     private Integer code;
     private String message;

+ 1 - 0
src/main/java/com/example/xiaoshiweixinback/business/exception/BusinessException.java

@@ -1,6 +1,7 @@
 package com.example.xiaoshiweixinback.business.exception;
 
 
+import com.example.xiaoshiweixinback.business.common.ResponseEnum;
 import lombok.Getter;
 
 /**

+ 4 - 5
src/main/java/com/example/xiaoshiweixinback/controller/PatentController.java

@@ -59,7 +59,7 @@ public class PatentController {
     @GetMapping(value = "/importPatent")
     public Response queryPatent(@RequestBody ImportTaskAMVO importTaskAMVO) {
         try {
-           importFromWebToEsService.ImportTask(importTaskAMVO);
+            importFromWebToEsService.ImportTask(importTaskAMVO);
         } catch (Exception e) {
             e.printStackTrace();
         }
@@ -88,11 +88,10 @@ public class PatentController {
         }
         Records records = null;
         try {
-           records = esDenseVectorService.getPatentVectors(esPatentVectorDTO, file);
+            records = esDenseVectorService.getPatentVectors(esPatentVectorDTO, file);
+        } catch (BusinessException e) {
+            return Response.error(e.getErrorCode(), e.getMessage());
         }
- catch (BusinessException e){
-            return  Response.error(e.getErrorCode(),e.getMessage());
- }
         return Response.success(records);
     }
 

+ 10 - 10
src/main/java/com/example/xiaoshiweixinback/service/LoginService.java

@@ -8,6 +8,7 @@ import cn.hutool.core.img.ImgUtil;
 import cn.hutool.core.util.IdUtil;
 import com.alibaba.fastjson2.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.example.xiaoshiweixinback.business.common.ResponseEnum;
 import com.example.xiaoshiweixinback.business.common.log.LogHelper;
 import com.example.xiaoshiweixinback.business.exception.BusinessException;
 import com.example.xiaoshiweixinback.business.exception.ExceptionEnum;
@@ -426,28 +427,27 @@ public class LoginService {
         queryWrapper.eq(Person::getPhoneNum, account).or().eq(Person::getUserName, account)
                 .or().eq(Person::getEmail, account);
         Person person = personService.getOne(queryWrapper, false);
-        if(person==null){
-        throw new BusinessException("606","账号错误");
+        if (person == null) {
+            throw new BusinessException("606", "账号错误");
         }
-        if(person.getUserPassword()==null){
-            throw new BusinessException("606","非账号登录用户");
+        if (person.getUserPassword() == null) {
+            throw new BusinessException("606", "非账号登录用户");
         }
         if (!person.getUserPassword().equals(password)) {
-             throw new BusinessException("606","密码错误");
+            throw new BusinessException("606", "密码错误");
         }
 
         //将用户信息数据存入Redis
         PersonnelVO personnelVO = new PersonnelVO();
         BeanUtil.copy(person, personnelVO);
-        String token="";
+        String token = "";
         try {
             token = jwtTokenUtil.createToken();
 
+        } catch (Exception e) {
+            throw new BusinessException("606", "生成token错误");
         }
-        catch (Exception e){
-            throw new BusinessException("606","生成token错误");
-        }
-        BeanUtil.copy(person,loginVO);
+        BeanUtil.copy(person, loginVO);
         loginVO.setToken(token);
         cacheUtil.setLoginUser(personnelVO, token);
         return loginVO;

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

@@ -13,8 +13,10 @@ 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.example.xiaoshiweixinback.business.common.ResponseEnum;
 import com.example.xiaoshiweixinback.business.common.base.Records;
 import com.example.xiaoshiweixinback.business.common.base.RedisConf;
+import com.example.xiaoshiweixinback.business.exception.BusinessException;
 import com.example.xiaoshiweixinback.business.redis.RedisService;
 import com.example.xiaoshiweixinback.business.utils.BeanUtil;
 import com.example.xiaoshiweixinback.business.utils.JSONUtil;
@@ -112,6 +114,9 @@ public class EsDenseVectorService {
             //2. 从es中检索数据
             q = formatQueryService.EsQueryToQuery((operateNode) tree, "patentVector", null);
         }
+        if (q == null) {
+            throw new BusinessException("608","检索式错误,请重新输入");
+        }
         //获取图片向量
         List<Float> imageList = new ArrayList<>();
         List<String> stringList = new ArrayList<>();
@@ -251,7 +256,9 @@ public class EsDenseVectorService {
             Date beforeDate = calendar.getTime();
             String agoFormat = format1.format(beforeDate) + "0101";
             String s = agoFormat + "~" + nowFormat;
-            searchCondition = searchCondition + " AND " + "AD = " + "(" + s + ")";
+            if (StringUtils.isNotEmpty(searchCondition)) {
+                searchCondition = searchCondition + " AND " + "AD = " + "(" + s + ")";
+            }
         }
         if (StringUtils.isNotEmpty(appCountry)) {
             String s = this.appendStr(appCountry);

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

@@ -10,7 +10,7 @@
         left join asso_product_category as apc on p.id =product_id
         left join person as pe on p.create_id =pe.uuid
         <where>
-            p.if_hot = true and p.if_show =true
+            p.if_hot = true and p.if_show = true and p.search_condition IS NOT NULL and p.search_condition != ''
             <if test="getProductDTO.name!=null and getProductDTO.name!=''">
                 and p.name like CONCAT('%',#{getProductDTO.name},'%')
             </if>
@@ -33,7 +33,7 @@
         asso_product_category as apc on p.id =product_id
         left join person as pe on p.create_id =pe.uuid
         <where>
-            p.if_hot = true and p.if_show =true
+            p.if_hot = true and p.if_show =true and p.search_condition IS NOT NULL and p.search_condition != ''
             <if test="getProductDTO.name!=null and getProductDTO.name!=''">
                 and p.name like CONCAT('%',#{getProductDTO.name},'%')
             </if>