|
@@ -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 {
|