chao 4 vuotta sitten
vanhempi
commit
e2948fd01d

+ 24 - 16
src/main/java/com/caimei365/commodity/service/impl/SearchIndexServiceImpl.java

@@ -219,11 +219,13 @@ public class SearchIndexServiceImpl implements SearchIndexService {
                 if (count > 1) {
                     log.info("商品重复,重复商品id>>>>>>>>>>>" + productId);
                     deleteProductIndexById(productId);
+                    return updateProductIndexById(productId);
+                } else {
+                    // 推送到阿里云
+                    pushProductDocument(mainList, productList, mallProductList);
+                    // 返回结果
+                    return ResponseJson.success(mainList.size());
                 }
-                // 推送到阿里云
-                pushProductDocument(mainList, productList, mallProductList);
-                // 返回结果
-                return ResponseJson.success(mainList.size());
             } catch (OpenSearchClientException | OpenSearchException | JSONException e) {
                 log.error("添加商品文档异常:" + e);
                 return ResponseJson.error("添加商品文档异常", null);
@@ -263,11 +265,13 @@ public class SearchIndexServiceImpl implements SearchIndexService {
                 if (count > 1) {
                     log.info("供应商重复,重复供应商id>>>>>>>>>>>" + shopId);
                     deleteSupplierIndexById(shopId);
+                    return updateSupplierIndexById(shopId);
+                } else {
+                    // 将文档列表转换成Json串,并推送到阿里云
+                    pushSupplierDocument(mainList, supplierList);
+                    // 返回结果
+                    return ResponseJson.success(mainList.size());
                 }
-                // 将文档列表转换成Json串,并推送到阿里云
-                pushSupplierDocument(mainList, supplierList);
-                // 返回结果
-                return ResponseJson.success(mainList.size());
             } catch (OpenSearchClientException | OpenSearchException | JSONException e) {
                 log.error("添加供应商文档异常:" + e);
                 return ResponseJson.error("添加供应商文档异常", null);
@@ -307,11 +311,13 @@ public class SearchIndexServiceImpl implements SearchIndexService {
                 if (count > 1) {
                     log.info("项目仪器重复,重复项目仪器id>>>>>>>>>>>" + equipmentId);
                     deleteEquipmentIndexById(equipmentId);
+                    return updateEquipmentIndexById(equipmentId);
+                } else {
+                    // 将文档列表转换成Json串,并推送到阿里云
+                    pushEquipmentDocument(mainList, equipmentList);
+                    // 返回结果
+                    return ResponseJson.success(mainList.size());
                 }
-                // 将文档列表转换成Json串,并推送到阿里云
-                pushEquipmentDocument(mainList, equipmentList);
-                // 返回结果
-                return ResponseJson.success(mainList.size());
             } catch (OpenSearchClientException | OpenSearchException | JSONException e) {
                 log.error("添加项目仪器文档异常:" + e);
                 return ResponseJson.error("添加项目仪器文档异常", null);
@@ -351,11 +357,13 @@ public class SearchIndexServiceImpl implements SearchIndexService {
                 if (count > 1) {
                     log.info("文章重复,重复文章id>>>>>>>>>>>" + articleId);
                     deleteArticleIndexById(articleId);
+                    return updateArticleIndexById(articleId);
+                } else {
+                    // 将主文档列表转换成Json串,并推送到阿里云
+                    pushArticleDocument(mainList, articleList);
+                    // 返回结果
+                    return ResponseJson.success(mainList.size());
                 }
-                // 将主文档列表转换成Json串,并推送到阿里云
-                pushArticleDocument(mainList, articleList);
-                // 返回结果
-                return ResponseJson.success(mainList.size());
             } catch (OpenSearchClientException | OpenSearchException | JSONException e) {
                 log.error("添加文章文档异常:" + e);
                 return ResponseJson.error("添加文章文档异常", null);

+ 30 - 10
src/main/java/com/caimei365/commodity/service/impl/SearchQueryServiceImpl.java

@@ -17,8 +17,10 @@ import com.caimei365.commodity.model.search.ProductListVo;
 import com.caimei365.commodity.model.search.ShopListVo;
 import com.caimei365.commodity.model.vo.*;
 import com.caimei365.commodity.service.SearchQueryService;
+import com.caimei365.commodity.utils.ImageUtils;
 import com.caimei365.commodity.utils.Json2PojoUtil;
 import com.github.pagehelper.PageHelper;
+import com.github.pagehelper.util.StringUtil;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang.StringUtils;
 import org.springframework.beans.factory.annotation.Value;
@@ -29,6 +31,7 @@ import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.concurrent.atomic.AtomicReference;
 
 /**
  * Description
@@ -255,8 +258,8 @@ public class SearchQueryServiceImpl implements SearchQueryService {
         try {
             // 查询推送
             JSONObject result = searchOpenService.getResultJsonObject("count:"+docType, searchParams);
-            if (1 == result.getInt("status") && result.getJSONArray("items").length()>=0) {
-                return result.getJSONArray("items").length();
+            if (1 == result.getInt("status") && result.getInt("total")>=0) {
+                return result.getInt("total");
             } else {
                 return -1;
             }
@@ -401,16 +404,16 @@ public class SearchQueryServiceImpl implements SearchQueryService {
      */
     @Override
     public ResponseJson<String> queryArticleByLabel(Integer id, int pageNum, int pageSize) {
-        String queryStr = "a_label:'" + id + "'";
-        ArrayList<String> fetchFields = Lists.newArrayList("id", "a_id", "a_title", "a_image", "a_publisher", "a_publish_date", "a_intro", "a_pv", "a_type_id", "a_type_text", "a_label_ids", "a_label_text");
-        // 阿里云搜索
-        ResponseJson<String> result = scrollArticleForParams(queryStr, fetchFields, pageNum, pageSize, "a_id", 1);
-        if (0 == result.getCode()) {
-            return result;
-        } else {
+//        String queryStr = "a_label:'" + id + "'";
+//        ArrayList<String> fetchFields = Lists.newArrayList("id", "a_id", "a_title", "a_image", "a_publisher", "a_publish_date", "a_intro", "a_pv", "a_type_id", "a_type_text", "a_label_ids", "a_label_text");
+//        // 阿里云搜索
+//        ResponseJson<String> result = scrollArticleForParams(queryStr, fetchFields, pageNum, pageSize, "a_id", 1);
+//        if (0 == result.getCode()) {
+//            return result;
+//        } else {
             // 阿里云搜索失败,再次从数据库搜索
             return queryArticleFromDatabase(pageNum, pageSize, null, null, null, id);
-        }
+//        }
     }
 
     /**
@@ -430,6 +433,23 @@ public class SearchQueryServiceImpl implements SearchQueryService {
         }
         PageHelper.startPage(num, size);
         List<ArticleListVo> articleList = searchMapper.queryArticle(keyword, articleId, typeId, labelText);
+        articleList.forEach(article -> {
+            String imagePath = ImageUtils.getImageURL("", article.getImage(), 0, domain);
+            article.setImage(imagePath);
+            // 搜索供应商文档数据
+            String[] labelTexts = article.getLabelText().split(",");
+            if(labelTexts.length > 0){
+                boolean notEmpty = StringUtil.isNotEmpty(labelTexts[0]);
+                if(notEmpty){
+                    List<Integer> labelIdList = searchMapper.findLabelIdsByName(labelTexts);
+                    StringBuilder labelIds = new StringBuilder();
+                    labelIdList.forEach(id -> {
+                        labelIds.append(",").append(id);
+                    });
+                    article.setLabelIds(labelIds.toString().replaceFirst(",",""));
+                }
+            }
+        });
         PaginationVo<ArticleListVo> pageData = new PaginationVo<>(articleList);
         int total = pageData.getTotalRecord();
         JSONObject pageObj = new JSONObject();

+ 1 - 1
src/main/resources/mapper/SearchMapper.xml

@@ -387,7 +387,7 @@
             (IFNULL(c.pv, 0) +IFNULL(c.num, 0) + IFNULL(a.basePv, 0) + IFNULL(a.basePraise, 0)) as pv,
             a.typeId as typeId,
             b.name as typeText,
-            a.label as labelText,
+            a.label as labelText
         from info as a
 		left join info_type b on a.typeId = b.id
 		left join info_praise c on a.id = c.infoId