|
@@ -89,6 +89,8 @@ public class SearchProductServiceImpl implements SearchProductService {
|
|
|
queryStr = "p_smalltype:'" + id + "'";
|
|
|
} else if (idType == 3) {
|
|
|
queryStr = "p_tinytype:'" + id + "'";
|
|
|
+ } else {
|
|
|
+ return ResponseJson.error("idType参数错误", null);
|
|
|
}
|
|
|
int requestSize = pageNum*pageSize;
|
|
|
int requestPageSize = requestSize;
|
|
@@ -102,8 +104,48 @@ public class SearchProductServiceImpl implements SearchProductService {
|
|
|
return result;
|
|
|
} else {
|
|
|
// 阿里云搜索失败,再次从数据库搜索
|
|
|
- //return queryProductFromDatabase(pageNum, pageSize, identity, keyword, null, null, null, null, sortField, sortType);
|
|
|
- return null;
|
|
|
+ if (idType == 1) {
|
|
|
+ return queryProductFromDatabase(pageNum, pageSize, identity, null, null, id, null, null, sortField, sortType);
|
|
|
+ } else if (idType == 2) {
|
|
|
+ return queryProductFromDatabase(pageNum, pageSize, identity, null, null, null, id, null, sortField, sortType);
|
|
|
+ } else {
|
|
|
+ return queryProductFromDatabase(pageNum, pageSize, identity, null, null, null, null, id, sortField, sortType);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取数据库商品
|
|
|
+ *
|
|
|
+ * @param num 页码
|
|
|
+ * @param size 每页数量
|
|
|
+ * @param identity 用户身份
|
|
|
+ * @param keyword 关键词
|
|
|
+ * @param shopId 供应商id
|
|
|
+ * @param bigTypeId 一级分类id
|
|
|
+ * @param smallTypeId 二级分类id
|
|
|
+ * @param tinyTypeId 三级分类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){
|
|
|
+ PageHelper.startPage(num, size);
|
|
|
+ List<ProductListVo> productList = searchMapper.queryProduct(identity, keyword, shopId, bigTypeId, smallTypeId, tinyTypeId, sortField, sortType);
|
|
|
+ productList.forEach(product -> {
|
|
|
+ product.setPriceGrade(PriceUtil.getpriceGrade(product.getPrice()));
|
|
|
+ product.setPrice(0d);
|
|
|
+ });
|
|
|
+ PageVo<ProductListVo> pageData = new PageVo<>(productList);
|
|
|
+ int total = pageData.getTotalRecord();
|
|
|
+ JSONObject pageObj = new JSONObject();
|
|
|
+ pageObj.put("total", total);
|
|
|
+ pageObj.put("items", productList);
|
|
|
+ log.info(">>>>>>数据库容错查询: pageSize(" + size +"),pageNum("+size+"),total("+total+")");
|
|
|
+ if (productList.size()>0) {
|
|
|
+ return ResponseJson.success(pageObj.toString());
|
|
|
+ } else {
|
|
|
+ return ResponseJson.error("未查询到文档记录(数据库)", null);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -177,41 +219,6 @@ public class SearchProductServiceImpl implements SearchProductService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 获取数据库商品
|
|
|
- *
|
|
|
- * @param num 页码
|
|
|
- * @param size 每页数量
|
|
|
- * @param identity 用户身份
|
|
|
- * @param keyword 关键词
|
|
|
- * @param shopId 供应商id
|
|
|
- * @param bigTypeId 一级分类id
|
|
|
- * @param smallTypeId 二级分类id
|
|
|
- * @param tinyTypeId 三级分类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){
|
|
|
- PageHelper.startPage(num, size);
|
|
|
- List<ProductListVo> productList = searchMapper.queryProduct(identity, keyword, shopId, bigTypeId, smallTypeId, tinyTypeId, sortField, sortType);
|
|
|
- productList.forEach(product -> {
|
|
|
- product.setPriceGrade(PriceUtil.getpriceGrade(product.getPrice()));
|
|
|
- product.setPrice(0d);
|
|
|
- });
|
|
|
- PageVo<ProductListVo> pageData = new PageVo<>(productList);
|
|
|
- int total = pageData.getTotalRecord();
|
|
|
- JSONObject pageObj = new JSONObject();
|
|
|
- pageObj.put("total", total);
|
|
|
- pageObj.put("items", productList);
|
|
|
- log.info(">>>>>>数据库容错查询: pageSize(" + size +"),pageNum("+size+"),total("+total+")");
|
|
|
- if (productList.size()>0) {
|
|
|
- return ResponseJson.success(pageObj.toString());
|
|
|
- } else {
|
|
|
- return ResponseJson.error("未查询到文档记录(数据库)", null);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
/**
|
|
|
* 滚动查询
|
|
|
*
|