chao před 4 roky
rodič
revize
837c96fc6c

+ 56 - 3
src/main/java/com/caimei365/commodity/controller/SearchProductApi.java

@@ -62,8 +62,8 @@ public class SearchProductApi {
      */
     @ApiOperation("根据分类Id搜索商品")
     @ApiImplicitParams({
-        @ApiImplicitParam(required = false, name = "id", value = "bigTypeID/smallTypeID/tinyTypeID"),
-        @ApiImplicitParam(required = false, name = "idType", value = "id类型:1一级分类,2二级分类,3三级分类"),
+        @ApiImplicitParam(required = true, name = "id", value = "bigTypeID/smallTypeID/tinyTypeID"),
+        @ApiImplicitParam(required = true, name = "idType", value = "id类型:1一级分类,2二级分类,3三级分类"),
         @ApiImplicitParam(required = false, name = "identity", value = "用户身份: 0个人,1协销,2会员机构,3供应商,4普通机构"),
         @ApiImplicitParam(required = false, name = "pageNum", value = "页码"),
         @ApiImplicitParam(required = false, name = "pageSize", value = "每页数量"),
@@ -71,7 +71,7 @@ public class SearchProductApi {
         @ApiImplicitParam(required = false, name = "sortType", value = "排序规则:1降序,其他升序")
     })
     @GetMapping("product/type")
-    public ResponseJson<String>  queryProductByType(Integer id, Integer idType,
+    public ResponseJson<String> queryProductByType(Integer id, Integer idType,
                                             @RequestParam(value = "identity", defaultValue = "0") Integer identity,
                                             @RequestParam(value = "pageNum", defaultValue = "1") int pageNum,
                                             @RequestParam(value = "pageSize", defaultValue = "20") int pageSize,
@@ -79,4 +79,57 @@ public class SearchProductApi {
         return searchProductService.queryProductByType(id, idType, identity, pageNum, pageSize, sortField, sortType);
     }
 
+    /**
+     * 根据小程序运营分类Id搜索商品
+     *
+     * spi旧接口:/search/query/product/classify
+     *
+     * @param id        运营级分类Id
+     * @param identity  用户身份 1:协销, 2:会员机构
+     */
+    @ApiOperation("根据小程序运营分类Id搜索商品")
+    @ApiImplicitParams({
+        @ApiImplicitParam(required = true, name = "id", value = "运营级分类Id"),
+        @ApiImplicitParam(required = false, name = "identity", value = "用户身份: 0个人,1协销,2会员机构,3供应商,4普通机构"),
+        @ApiImplicitParam(required = false, name = "pageNum", value = "页码"),
+        @ApiImplicitParam(required = false, name = "pageSize", value = "每页数量"),
+        @ApiImplicitParam(required = false, name = "sortField", value = "排序字段:价格price,销量sales,人气favorite"),
+        @ApiImplicitParam(required = false, name = "sortType", value = "排序规则:1降序,其他升序")
+    })
+    @GetMapping("product/classify")
+    public ResponseJson<String> queryProductByClassify(Integer id,
+                                            @RequestParam(value = "identity", defaultValue = "0") Integer identity,
+                                            @RequestParam(value = "pageNum", defaultValue = "1") int pageNum,
+                                            @RequestParam(value = "pageSize", defaultValue = "20") int pageSize,
+                                            String sortField, Integer sortType) {
+        return searchProductService.queryProductByClassify(id, identity, pageNum, pageSize, sortField, sortType);
+    }
+
+    /**
+     * 根据供应商Id搜索商品(商铺内搜索)
+     *
+     * spi旧接口:/search/query/product/supplier
+     *
+     * @param id       供应商Id
+     * @param keyword  搜索关键字
+     */
+    @ApiOperation("根据供应商Id搜索商品(商铺内搜索)")
+    @ApiImplicitParams({
+        @ApiImplicitParam(required = true, name = "id", value = "供应商Id"),
+        @ApiImplicitParam(required = false, name = "keyword", value = "搜索关键字"),
+        @ApiImplicitParam(required = false, name = "identity", value = "用户身份: 0个人,1协销,2会员机构,3供应商,4普通机构"),
+        @ApiImplicitParam(required = false, name = "pageNum", value = "页码"),
+        @ApiImplicitParam(required = false, name = "pageSize", value = "每页数量"),
+        @ApiImplicitParam(required = false, name = "sortField", value = "排序字段:价格price,销量sales,人气favorite"),
+        @ApiImplicitParam(required = false, name = "sortType", value = "排序规则:1降序,其他升序")
+    })
+    @GetMapping("product/shop")
+    public ResponseJson<String> querySupplierProduct(Integer id, String keyword,
+                                           @RequestParam(value = "identity", defaultValue = "0") Integer identity,
+                                           @RequestParam(value = "pageNum", defaultValue = "1") int pageNum,
+                                           @RequestParam(value = "pageSize", defaultValue = "20") int pageSize,
+                                           String sortField, Integer sortType) {
+        return searchProductService.querySupplierProduct(id, keyword, identity, pageNum, pageSize, sortField, sortType);
+    }
+
 }

+ 22 - 1
src/main/java/com/caimei365/commodity/controller/SearchQueryApi.java

@@ -1,5 +1,6 @@
 package com.caimei365.commodity.controller;
 
+import com.caimei365.commodity.model.ResponseJson;
 import com.caimei365.commodity.service.SearchQueryService;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiImplicitParam;
@@ -88,5 +89,25 @@ public class SearchQueryApi {
         return searchQueryService.getCountByDocId(docType, docId);
     }
 
-
+    /**
+     * 根据关键词搜索供应商
+     *
+     * spi旧接口:/search/query/supplier
+     *
+     * @param keyword 搜索关键字
+     */
+    @ApiOperation("根据关键词搜索供应商")
+    @ApiImplicitParams({
+        @ApiImplicitParam(required = false, name = "keyword", value = "搜索关键字"),
+        @ApiImplicitParam(required = false, name = "identity", value = "用户身份: 0个人,1协销,2会员机构,3供应商,4普通机构"),
+        @ApiImplicitParam(required = false, name = "pageNum", value = "页码"),
+        @ApiImplicitParam(required = false, name = "pageSize", value = "每页数量")
+    })
+    @GetMapping("shop")
+    public ResponseJson<String> querySupplierByKeyword(String keyword,
+                                                       @RequestParam(value = "identity", defaultValue = "0") Integer identity,
+                                                       @RequestParam(value = "pageNum", defaultValue = "1") int pageNum,
+                                                       @RequestParam(value = "pageSize", defaultValue = "10") int pageSize) {
+        return searchQueryService.querySupplierByKeyword(keyword, identity, pageNum, pageSize);
+    }
 }

+ 10 - 6
src/main/java/com/caimei365/commodity/mapper/SearchMapper.java

@@ -2,6 +2,7 @@ package com.caimei365.commodity.mapper;
 
 import com.caimei365.commodity.model.search.*;
 import com.caimei365.commodity.model.vo.ProductListVo;
+import com.caimei365.commodity.model.vo.ShopListVo;
 import org.apache.ibatis.annotations.Mapper;
 import org.apache.ibatis.annotations.Param;
 
@@ -127,8 +128,6 @@ public interface SearchMapper {
      * 获取失效文章IDs
      */
     List<Integer> findArticleInvalidIds();
-
-
     /**
      * 获取数据库商品
      * @param identity  用户身份
@@ -137,9 +136,10 @@ public interface SearchMapper {
      * @param bigTypeId 一级分类id
      * @param smallTypeId 二级分类id
      * @param tinyTypeId 三级分类id
+     * @param classifyId 运营分类id
      * @param sortField 排序类型
      * @param sortType  排序顺序
-     * @return
+     * @return list
      */
     List<ProductListVo> queryProduct(@Param("identity") Integer identity,
                                      @Param("keyword") String keyword,
@@ -147,11 +147,15 @@ public interface SearchMapper {
                                      @Param("bigTypeId") Integer bigTypeId,
                                      @Param("smallTypeId") Integer smallTypeId,
                                      @Param("tinyTypeId") Integer tinyTypeId,
+                                     @Param("classifyId") Integer classifyId,
                                      @Param("sortField") String sortField,
                                      @Param("sortType") Integer sortType);
-
-
-
+    /**
+     * 获取数据库供应商
+     * @param keyword   关键词
+     * @return list
+     */
+    List<ShopListVo> querySupplier(@Param("keyword")  String keyword);
 
 
 

+ 1 - 1
src/main/java/com/caimei365/commodity/model/vo/ProductListVo.java

@@ -5,7 +5,7 @@ import lombok.Data;
 import java.io.Serializable;
 
 /**
- * 阿里云商品表(search_product)
+ * 商品
  *
  * @author : Charles
  * @date : 2020/5/13

+ 34 - 0
src/main/java/com/caimei365/commodity/model/vo/ShopListVo.java

@@ -0,0 +1,34 @@
+package com.caimei365.commodity.model.vo;
+
+import lombok.Data;
+
+import java.io.Serializable;
+import java.util.List;
+
+/**
+ * 供应商列表
+ *
+ * @author : Charles
+ * @date : 2021/4/8
+ */
+@Data
+public class ShopListVo implements Serializable {
+    /** 索引Id */
+    private Integer id;
+    /** 供应商Id */
+    private Integer shopId;
+    /** 名称name */
+    private String name;
+    /** 供应商logo */
+    private String logo;
+    /** 供应商牌照 */
+    private String license;
+    /** 经营品项 */
+    private String business;
+    /** 所在省市地址 */
+    private String address;
+    /** 供应商下商品 */
+    private List<ProductListVo> products;
+
+    private static final long serialVersionUID = 1L;
+}

+ 27 - 0
src/main/java/com/caimei365/commodity/service/SearchProductService.java

@@ -35,4 +35,31 @@ public interface SearchProductService {
      * @return JsonStr(list)
      */
     ResponseJson<String> queryProductByType(Integer id, Integer idType, Integer identity, int pageNum, int pageSize, String sortField, Integer sortType);
+
+    /**
+     * 根据小程序运营分类Id搜索商品
+     *
+     * @param id        运营级分类Id
+     * @param identity  用户身份 1:协销, 2:会员机构
+     * @param pageNum   页码
+     * @param pageSize  每页数量
+     * @param sortField 排序字段
+     * @param sortType  升降序0/1
+     * @return JsonStr(list)
+     */
+    ResponseJson<String> queryProductByClassify(Integer id, Integer identity, int pageNum, int pageSize, String sortField, Integer sortType);
+
+    /**
+     * 根据供应商Id搜索商品(商铺内搜索)
+     *
+     * @param id       供应商Id
+     * @param keyword  搜索关键字
+     * @param identity  用户身份 1:协销, 2:会员机构
+     * @param pageNum   页码
+     * @param pageSize  每页数量
+     * @param sortField 排序字段
+     * @param sortType  升降序0/1
+     * @return JsonStr(list)
+     */
+    ResponseJson<String> querySupplierProduct(Integer id, String keyword, Integer identity, int pageNum, int pageSize, String sortField, Integer sortType);
 }

+ 12 - 0
src/main/java/com/caimei365/commodity/service/SearchQueryService.java

@@ -1,6 +1,8 @@
 package com.caimei365.commodity.service;
 
 
+import com.caimei365.commodity.model.ResponseJson;
+
 import java.util.Map;
 
 /**
@@ -41,4 +43,14 @@ public interface SearchQueryService {
      */
     Integer getCountByDocId(String docType, Integer docId);
 
+    /**
+     * 根据关键词搜索供应商
+     *
+     * @param keyword  搜索关键字
+     * @param identity  用户身份 1:协销, 2:会员机构
+     * @param pageNum   页码
+     * @param pageSize  每页数量
+     * @return JsonStr(list)
+     */
+    ResponseJson<String> querySupplierByKeyword(String keyword, Integer identity, int pageNum, int pageSize);
 }

+ 85 - 7
src/main/java/com/caimei365/commodity/service/impl/SearchProductServiceImpl.java

@@ -64,7 +64,7 @@ public class SearchProductServiceImpl implements SearchProductService {
             return result;
         } else {
             // 阿里云搜索失败,再次从数据库搜索
-            return queryProductFromDatabase(pageNum, pageSize, identity, keyword, null, null, null, null, sortField, sortType);
+            return queryProductFromDatabase(pageNum, pageSize, identity, keyword, null, null, null, null, null, sortField, sortType);
         }
     }
 
@@ -105,15 +105,85 @@ public class SearchProductServiceImpl implements SearchProductService {
         } else {
             // 阿里云搜索失败,再次从数据库搜索
             if (idType == 1) {
-                return queryProductFromDatabase(pageNum, pageSize, identity, null, null, id, null, null, sortField, sortType);
+                return queryProductFromDatabase(pageNum, pageSize, identity, null, null, id, null, null, null, sortField, sortType);
             } else if (idType == 2) {
-                return queryProductFromDatabase(pageNum, pageSize, identity, null, null, null, id, null, sortField, sortType);
+                return queryProductFromDatabase(pageNum, pageSize, identity, null, null, null, id, null, null, sortField, sortType);
             } else {
-                return queryProductFromDatabase(pageNum, pageSize, identity, null, null, null, null, id, sortField, sortType);
+                return queryProductFromDatabase(pageNum, pageSize, identity, null, null, null, null, id, null, sortField, sortType);
             }
         }
     }
 
+    /**
+     * 根据小程序运营分类Id搜索商品
+     *
+     * @param id        运营级分类Id
+     * @param identity  用户身份 1:协销, 2:会员机构
+     * @param pageNum   页码
+     * @param pageSize  每页数量
+     * @param sortField 排序字段
+     * @param sortType  升降序0/1
+     * @return JsonStr(list)
+     */
+    @Override
+    public ResponseJson<String> queryProductByClassify(Integer id, Integer identity, int pageNum, int pageSize, String sortField, Integer sortType) {
+        String queryStr = "p_classify:'" + id + "'";
+        int requestSize = pageNum*pageSize;
+        int requestPageSize = requestSize;
+        if (requestSize > SEARCH_MAX_NUM){
+            requestPageSize = (int) Math.floor(SEARCH_MAX_NUM/pageSize) * pageSize;
+        }
+        SearchParams searchParams = searchOpenService.getScrollProductParams(queryStr, identity, requestPageSize, sortField, sortType);
+        // 阿里云搜索(滚动查询)
+        ResponseJson<String> result = deepPagingForParams(searchParams, queryStr, pageNum, pageSize, requestSize, requestPageSize);
+        if (0 == result.getCode()) {
+            return result;
+        } else {
+            // 阿里云搜索失败,再次从数据库搜索
+            return queryProductFromDatabase(pageNum, pageSize, identity, null, null, null, null, null, id, sortField, sortType);
+        }
+    }
+
+    /**
+     * 根据供应商Id搜索商品(商铺内搜索)
+     *
+     * @param id        供应商Id
+     * @param keyword   搜索关键字
+     * @param identity  用户身份 1:协销, 2:会员机构
+     * @param pageNum   页码
+     * @param pageSize  每页数量
+     * @param sortField 排序字段
+     * @param sortType  升降序0/1
+     * @return JsonStr(list)
+     */
+    @Override
+    public ResponseJson<String> querySupplierProduct(Integer id, String keyword, Integer identity, int pageNum, int pageSize, String sortField, Integer sortType) {
+        if (null == id){
+            return ResponseJson.error("请提供供应商id" ,null);
+        }
+        ResponseJson<String> result;
+        if (StringUtils.isEmpty(keyword)) {
+            String queryStr = "p_supplier:'" + id + "'";
+            int requestSize = pageNum*pageSize;
+            int requestPageSize = requestSize;
+            if (requestSize > SEARCH_MAX_NUM){
+                requestPageSize = (int) Math.floor(SEARCH_MAX_NUM/pageSize) * pageSize;
+            }
+            SearchParams searchParams = searchOpenService.getScrollProductParams(queryStr, identity, requestPageSize, sortField, sortType);
+            result = deepPagingForParams(searchParams, queryStr, pageNum, pageSize, requestSize, requestPageSize);
+        } else {
+            String queryStr = "product:'" + keyword + "'";
+            String filter = "p_supplier_id=" + id;
+            result = queryProduct(queryStr, filter, identity, pageNum, pageSize, sortField, sortType);
+        }
+        if (0 == result.getCode()) {
+            return result;
+        } else {
+            // 阿里云搜索失败,再次从数据库搜索
+            return queryProductFromDatabase(pageNum, pageSize, identity, keyword, id, null, null, null, null, sortField, sortType);
+        }
+    }
+
     /**
      * 获取数据库商品
      *
@@ -125,13 +195,14 @@ public class SearchProductServiceImpl implements SearchProductService {
      * @param bigTypeId 一级分类id
      * @param smallTypeId 二级分类id
      * @param tinyTypeId 三级分类id
+     * @param classifyId 小程序运营分类id
      * @param sortField 排序类型
      * @param sortType  排序顺序
      */
     private ResponseJson<String> queryProductFromDatabase(int num, int size, Integer identity, String keyword, Integer shopId,
-                             Integer bigTypeId, Integer smallTypeId, Integer tinyTypeId, String sortField, Integer sortType){
+                             Integer bigTypeId, Integer smallTypeId, Integer tinyTypeId, Integer classifyId, String sortField, Integer sortType){
         PageHelper.startPage(num, size);
-        List<ProductListVo> productList = searchMapper.queryProduct(identity, keyword, shopId, bigTypeId, smallTypeId, tinyTypeId, sortField, sortType);
+        List<ProductListVo> productList = searchMapper.queryProduct(identity, keyword, shopId, bigTypeId, smallTypeId, tinyTypeId, classifyId, sortField, sortType);
         productList.forEach(product -> {
             product.setPriceGrade(PriceUtil.getpriceGrade(product.getPrice()));
             product.setPrice(0d);
@@ -149,6 +220,11 @@ public class SearchProductServiceImpl implements SearchProductService {
         }
     }
 
+
+
+
+
+
     /**
      * 查询商品(阿里云搜索)
      *
@@ -304,9 +380,11 @@ public class SearchProductServiceImpl implements SearchProductService {
                         }
                     }
                 }
+                // 阿里云查询出json转换成商品pojo
+                List<ProductListVo> productList = Json2PojoUtil.toProductList(pageData);
                 JSONObject pageObj = new JSONObject();
                 pageObj.put("total", total);
-                pageObj.put("items", pageData);
+                pageObj.put("items", productList);
                 log.info(">>>>>>pageResult("+queryStr+"): pageSize(" + pageSize +"),pageNum("+pageNum+"),total("+total+")");
                 return ResponseJson.success(pageObj.toString());
             } else {

+ 152 - 0
src/main/java/com/caimei365/commodity/service/impl/SearchQueryServiceImpl.java

@@ -10,12 +10,21 @@ import com.aliyun.opensearch.sdk.generated.commons.OpenSearchException;
 import com.aliyun.opensearch.sdk.generated.search.*;
 import com.caimei365.commodity.components.SearchOpenService;
 import com.caimei365.commodity.mapper.SearchMapper;
+import com.caimei365.commodity.model.ResponseJson;
+import com.caimei365.commodity.model.vo.PageVo;
+import com.caimei365.commodity.model.vo.ProductListVo;
+import com.caimei365.commodity.model.vo.ShopListVo;
 import com.caimei365.commodity.service.SearchQueryService;
+import com.caimei365.commodity.utils.Json2PojoUtil;
+import com.github.pagehelper.PageHelper;
 import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang.StringUtils;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
 
 import javax.annotation.Resource;
+import java.util.ArrayList;
+import java.util.List;
 import java.util.Map;
 
 /**
@@ -286,5 +295,148 @@ public class SearchQueryServiceImpl implements SearchQueryService {
         }
     }
 
+    /**
+     * 根据关键词搜索供应商
+     *
+     * @param keyword  搜索关键字
+     * @param identity 用户身份 1:协销, 2:会员机构
+     * @param pageNum  页码
+     * @param pageSize 每页数量
+     * @return JsonStr(list)
+     */
+    @Override
+    public ResponseJson<String> querySupplierByKeyword(String keyword, Integer identity, int pageNum, int pageSize) {
+        String queryStr = "supplier:'" + keyword + "'";
+        if (StringUtils.isEmpty(keyword)) {
+            queryStr = "s_all:'1'";
+        }
+        // 阿里云搜索
+        ResponseJson<String> result = querySupplier(queryStr, identity, pageNum, pageSize);
+        if (0 == result.getCode()) {
+            return result;
+        } else {
+            // 阿里云搜索失败,再次从数据库搜索
+            return querySupplierFromDatabase(pageNum, pageSize, identity, keyword);
+        }
+    }
+
+    /**
+     * 获取供应商(数据库)
+     *
+     * @param num       页码
+     * @param size      每页数量
+     * @param identity  用户身份
+     * @param keyword   关键词
+     */
+    private ResponseJson<String> querySupplierFromDatabase(int num, int size, Integer identity, String keyword) {
+        PageHelper.startPage(num, size);
+        List<ShopListVo> shopList = searchMapper.querySupplier(keyword);
+        shopList.forEach(shop -> {
+            PageHelper.startPage(1, 3);
+            List<ProductListVo> productList = searchMapper.queryProduct(identity, null, shop.getShopId(), null, null, null, null, null, null);
+            shop.setProducts(productList);
+        });
+        PageVo<ShopListVo> pageData = new PageVo<>(shopList);
+        int total = pageData.getTotalRecord();
+        JSONObject pageObj = new JSONObject();
+        pageObj.put("total", total);
+        pageObj.put("items", shopList);
+        log.info(">>>>>>数据库容错查询: pageSize(" + size +"),pageNum("+size+"),total("+total+")");
+        if (shopList.size()>0) {
+            return ResponseJson.success(pageObj.toString());
+        } else {
+            return ResponseJson.error("未查询到文档记录(数据库)", null);
+        }
+    }
+
+    /**
+     * 查询供应商(阿里云搜索)
+     *
+     * @param queryStr  查询类型及参数
+     * @param identity 用户身份 1:协销, 2:会员机构
+     * @param pageNum  页码
+     * @param pageSize 每页数量
+     */
+    private ResponseJson<String> querySupplier(String queryStr, Integer identity, int pageNum, int pageSize) {
+        ArrayList<String> fetchFields = Lists.newArrayList("id", "s_id", "s_name", "s_logo", "s_business", "s_address", "s_license");
+        // 由于阿里云搜索机制问题(分页数据重复),搜索500条以内数据手动分页。
+        SearchParams searchParams;
+        int requestSize = pageNum*pageSize;
+        if (requestSize > SEARCH_MAX_NUM){
+            searchParams = searchOpenService.getSearchParams(queryStr, fetchFields, null, "supplier", pageNum, pageSize, "s_sort", 1);
+        } else {
+            searchParams = searchOpenService.getSearchParams(queryStr, fetchFields, null, "supplier", 1, requestSize, "s_sort", 1);
+        }
+        // 查询推送
+        try {
+            String jsonStr = searchOpenService.pushQueryDocument(searchParams);
+            // 处理查询结果
+            JSONObject jsonObj = new JSONObject(jsonStr);
+            String status = jsonObj.getString("status");
+            String requestId = jsonObj.getString("request_id");
+            String tracer = jsonObj.getString("tracer");
+            JSONObject result = jsonObj.getJSONObject("result");
+            JSONArray errors = jsonObj.getJSONArray("errors");
+            log.info(">>>>>>query("+queryStr+"): " + status + ",request_id=" +requestId+ ",errors=" + errors.toString() + ",tracer="+tracer);
+            if ("OK".equals(status)) {
+                int total = result.getInt("total");
+                int totalPage = (int) Math.ceil( (double)total/pageSize);
+                JSONArray resultArr = result.getJSONArray("items");
+                JSONArray pageData = new JSONArray();
+                if (requestSize > SEARCH_MAX_NUM) {
+                    pageData = resultArr;
+                } else {
+                    if (resultArr.length()>0) {
+                        int baseNum = (pageNum - 1) * pageSize;
+                        for (int i = 0; i < pageSize; i++) {
+                            int index = baseNum + i;
+                            int currentTotal = requestSize;
+                            if (totalPage == pageNum) {
+                                currentTotal = total;
+                            }
+                            if (index < currentTotal) {
+                                JSONObject item = resultArr.getJSONObject(index);
+                                pageData.put(i, item);
+                            } else {
+                                break;
+                            }
+                        }
+                    }
+                }
+                for (int i = 0; i < pageData.length(); i++) {
+                    JSONObject supplier = pageData.getJSONObject(i);
+                    int supplierId = supplier.getInt("s_id");
+                    String productQuery = "p_supplier:'" + supplierId + "'";
+                    SearchParams productSearchParams = searchOpenService.getProductParams(productQuery, "", identity, 1, 3, "", null);
+                    String productStr = searchOpenService.pushQueryDocument(productSearchParams);
+                    // 处理查询结果
+                    JSONObject productObj = new JSONObject(productStr);
+                    String pStatus = productObj.getString("status");
+                    String pRequestId = productObj.getString("request_id");
+                    String pTracer = productObj.getString("tracer");
+                    JSONObject pResult = productObj.getJSONObject("result");
+                    JSONArray pErrors = productObj.getJSONArray("errors");
+                    log.info(">>>>>>query("+productQuery+"): " + pStatus + ",request_id=" +pRequestId+ ",errors=" + pErrors.toString() + ",tracer="+pTracer);
+                    if ("OK".equals(pStatus)) {
+                        JSONArray productArr = pResult.getJSONArray("items");
+                        supplier.put("products", productArr);
+                    }
+                }
+                // 阿里云查询出json转换成供应商pojo
+                List<ShopListVo> shopList = Json2PojoUtil.toShopList(pageData);
+                JSONObject pageObj = new JSONObject();
+                pageObj.put("total", total);
+                pageObj.put("items", shopList);
+                log.info(">>>>>>pageResult("+queryStr+"): pageSize(" + pageSize +"),pageNum("+pageNum+"),total("+total+")");
+                return ResponseJson.success(pageObj.toString());
+            } else {
+                return ResponseJson.error("未查询到文档记录", null);
+            }
+        } catch (OpenSearchClientException | OpenSearchException | JSONException e) {
+            log.error("查询文档异常:" + e.getMessage());
+            return ResponseJson.error("查询文档异常:" + e.getMessage(), null);
+        }
+    }
+
 
 }

+ 42 - 1
src/main/java/com/caimei365/commodity/utils/Json2PojoUtil.java

@@ -3,6 +3,7 @@ package com.caimei365.commodity.utils;
 import com.aliyun.opensearch.sdk.dependencies.org.json.JSONArray;
 import com.aliyun.opensearch.sdk.dependencies.org.json.JSONObject;
 import com.caimei365.commodity.model.vo.ProductListVo;
+import com.caimei365.commodity.model.vo.ShopListVo;
 
 import java.util.ArrayList;
 import java.util.List;
@@ -14,12 +15,17 @@ import java.util.List;
  * @date : 2021/4/7
  */
 public class Json2PojoUtil {
+    /**
+     * 阿里云查询出json转换成商品pojo
+     * @param jsonArray json
+     * @return ProductListVo
+     */
     public static List<ProductListVo> toProductList(JSONArray jsonArray) {
         List<ProductListVo> productList = new ArrayList<>();
         ProductListVo product = new ProductListVo();
         for (int i=0; i<jsonArray.length(); i++) {
             JSONObject json = jsonArray.getJSONObject(i);
-
+            /* 主键Id */
             product.setId(json.getInt("id"));
             /* 商品Id */
             product.setProductId(json.getInt("p_id"));
@@ -48,4 +54,39 @@ public class Json2PojoUtil {
         }
         return productList;
     }
+
+    /**
+     * 阿里云查询出json转换成供应商pojo
+     * @param jsonArray json
+     * @return ShopListVo
+     */
+    public static List<ShopListVo> toShopList(JSONArray jsonArray) {
+        List<ShopListVo> shopList = new ArrayList<>();
+        ShopListVo shop = new ShopListVo();
+        for (int i=0; i<jsonArray.length(); i++) {
+            JSONObject json = jsonArray.getJSONObject(i);
+            /* 主键Id */
+            shop.setId(json.getInt("id"));
+            /* 供应商Id */
+            shop.setShopId(json.getInt("s_id"));
+            /* 供应商名称name */
+            shop.setName(json.getString("s_name"));
+            /* 供应商logo */
+            shop.setLogo(json.getString("s_logo"));
+            /* 供应商牌照 */
+            shop.setLicense(json.getString("s_license"));
+            /* 经营品项 */
+            shop.setBusiness(json.getString("s_business"));
+            /* 所在省市地址 */
+            shop.setAddress(json.getString("s_address"));
+            /* 供应商下商品 */
+            JSONArray productArr = json.getJSONArray("products");
+            List<ProductListVo> productList = toProductList(productArr);
+            shop.setProducts(productList);
+
+            shopList.add(shop);
+        }
+        return shopList;
+
+    }
 }

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

@@ -273,7 +273,7 @@
             p.price1 as price,
             p.shopID as shopId,
             p.searchKey as keyword,
-            p.price8Text as p_act_flag
+            p.price8Text as actFlag
         from product p
         left join cm_brand as br on p.brandID = br.id
         where p.productCategory = 1
@@ -303,6 +303,9 @@
         <if test="tinyTypeId != null and tinyTypeId != ''">
             and p.tinyTypeID = #{tinyTypeId}
         </if>
+        <if test="classifyId != null and classifyId != ''">
+            and p.classifyId = #{classifyId}
+        </if>
         <if test="keyword != null and keyword != ''">
             and p.name like concat('%',#{keyword},'%')
         </if>
@@ -336,6 +339,30 @@
             </otherwise>
         </choose>
     </select>
+    <!-- 搜索容错 供应商列表 -->
+    <select id="querySupplier" resultType="com.caimei365.commodity.model.vo.ShopListVo">
+        select
+        s.shopID as shopId,
+        s.name as name,
+        s.logo as logo,
+        s.authorizationCertificateImage as license,
+        s.businessScope as business,
+        CONCAT(p.name, c.name) as address
+        from shop as s
+        left join town as t on s.townId = t.townID
+        left join city as c on t.cityID = c.cityID
+        left join province as p on c.provinceID = p.provinceID
+        where (status = 90 or status = 9)
+        and shopID != 1252
+        and s.name like concat('%',#{keyword},'%')
+    </select>
+
+
+
+
+
+
+
 
 
 
@@ -466,4 +493,5 @@
             </otherwise>
         </choose>
     </select>
+
 </mapper>