|
@@ -61,7 +61,7 @@ public class SearchQueryServiceImpl implements SearchQueryService {
|
|
|
* @return int
|
|
|
*/
|
|
|
@Override
|
|
|
- public Integer getIdByDocId(String docType, Integer docId) {
|
|
|
+ public Integer getIdByDocId(String docType, Integer docId) {
|
|
|
// 定义Config对象,用于设定config子句参数,指定应用名,分页,数据返回格式等等
|
|
|
Config config = new Config(Lists.newArrayList(searchOpenService.getAppName()));
|
|
|
config.setStart(0);
|
|
@@ -73,16 +73,16 @@ public class SearchQueryServiceImpl implements SearchQueryService {
|
|
|
// 创建参数对象
|
|
|
SearchParams searchParams = new SearchParams(config);
|
|
|
if (null != docId) {
|
|
|
- if("product".equals(docType)) {
|
|
|
+ if ("product".equals(docType)) {
|
|
|
// 根据商品Id获取阿里云索引Id
|
|
|
searchParams.setQuery("p_id:'" + docId + "'");
|
|
|
- } else if("shop".equals(docType)) {
|
|
|
+ } else if ("shop".equals(docType)) {
|
|
|
// 根据供应商Id获取阿里云索引Id
|
|
|
searchParams.setQuery("s_id:'" + docId + "'");
|
|
|
- } else if("equipment".equals(docType)) {
|
|
|
+ } else if ("equipment".equals(docType)) {
|
|
|
// 根据项目仪器Id获取阿里云索引Id
|
|
|
searchParams.setQuery("e_id:'" + docId + "'");
|
|
|
- } else if("article".equals(docType)) {
|
|
|
+ } else if ("article".equals(docType)) {
|
|
|
// 根据文章Id获取阿里云索引Id
|
|
|
searchParams.setQuery("a_id:'" + docId + "'");
|
|
|
}
|
|
@@ -98,8 +98,8 @@ public class SearchQueryServiceImpl implements SearchQueryService {
|
|
|
}
|
|
|
try {
|
|
|
// 查询推送
|
|
|
- JSONObject result = searchOpenService.getResultJsonObject("id:"+docType, searchParams);
|
|
|
- if (1 == result.getInt("status") && result.getJSONArray("items").length()>0) {
|
|
|
+ JSONObject result = searchOpenService.getResultJsonObject("id:" + docType, searchParams);
|
|
|
+ if (1 == result.getInt("status") && result.getJSONArray("items").length() > 0) {
|
|
|
return result.getJSONArray("items").getJSONObject(0).getInt("id");
|
|
|
} else {
|
|
|
return -1;
|
|
@@ -114,8 +114,8 @@ public class SearchQueryServiceImpl implements SearchQueryService {
|
|
|
* 根据文档类型获取阿里云索引Id集合
|
|
|
*
|
|
|
* @param docType 文档类型
|
|
|
- * @param pageNum 页码
|
|
|
- * @param pageSize 每页数量
|
|
|
+ * @param pageNum 页码
|
|
|
+ * @param pageSize 每页数量
|
|
|
* @return map
|
|
|
*/
|
|
|
@Override
|
|
@@ -123,16 +123,16 @@ public class SearchQueryServiceImpl implements SearchQueryService {
|
|
|
String queryStr;
|
|
|
String idName;
|
|
|
Map<Integer, Integer> idMap = Maps.newLinkedHashMap();
|
|
|
- if("product".equals(docType)) {
|
|
|
+ if ("product".equals(docType)) {
|
|
|
queryStr = "p_all:'1'";
|
|
|
idName = "p_id";
|
|
|
- } else if("shop".equals(docType)) {
|
|
|
+ } else if ("shop".equals(docType)) {
|
|
|
queryStr = "s_all:'1'";
|
|
|
idName = "s_id";
|
|
|
- } else if("equipment".equals(docType)) {
|
|
|
+ } else if ("equipment".equals(docType)) {
|
|
|
queryStr = "e_all:'1'";
|
|
|
idName = "e_id";
|
|
|
- } else if("article".equals(docType)) {
|
|
|
+ } else if ("article".equals(docType)) {
|
|
|
queryStr = "a_all:'1'";
|
|
|
idName = "a_id";
|
|
|
} else {
|
|
@@ -140,7 +140,7 @@ public class SearchQueryServiceImpl implements SearchQueryService {
|
|
|
}
|
|
|
// 定义Config对象,用于设定config子句参数,指定应用名,分页,数据返回格式等等
|
|
|
Config config = new Config(Lists.newArrayList(searchOpenService.getAppName()));
|
|
|
- config.setStart(pageNum-1);
|
|
|
+ config.setStart(pageNum - 1);
|
|
|
config.setHits(pageSize);
|
|
|
// 设置搜索结果返回应用中哪些字段
|
|
|
config.setFetchFields(Lists.newArrayList("id", idName));
|
|
@@ -151,7 +151,7 @@ public class SearchQueryServiceImpl implements SearchQueryService {
|
|
|
searchParams.setQuery(queryStr);
|
|
|
try {
|
|
|
// 查询推送
|
|
|
- JSONObject result = searchOpenService.getResultJsonObject("idMap:"+idName, searchParams);
|
|
|
+ JSONObject result = searchOpenService.getResultJsonObject("idMap:" + idName, searchParams);
|
|
|
if (1 == result.getInt("status")) {
|
|
|
JSONArray jsonArray = result.getJSONArray("items");
|
|
|
for (int i = 0; i < jsonArray.length(); i++) {
|
|
@@ -183,13 +183,13 @@ public class SearchQueryServiceImpl implements SearchQueryService {
|
|
|
config.setSearchFormat(SearchFormat.JSON);
|
|
|
// 创建参数对象
|
|
|
SearchParams searchParams = new SearchParams(config);
|
|
|
- if("product".equals(docType)) {
|
|
|
+ if ("product".equals(docType)) {
|
|
|
searchParams.setQuery("p_all:'1'");
|
|
|
- } else if("shop".equals(docType)) {
|
|
|
+ } else if ("shop".equals(docType)) {
|
|
|
searchParams.setQuery("s_all:'1'");
|
|
|
- } else if("equipment".equals(docType)) {
|
|
|
+ } else if ("equipment".equals(docType)) {
|
|
|
searchParams.setQuery("e_all:'1'");
|
|
|
- } else if("article".equals(docType)) {
|
|
|
+ } else if ("article".equals(docType)) {
|
|
|
searchParams.setQuery("a_all:'1'");
|
|
|
} else {
|
|
|
return 0;
|
|
@@ -203,10 +203,10 @@ public class SearchQueryServiceImpl implements SearchQueryService {
|
|
|
searchParams.addToAggregates(agg);
|
|
|
try {
|
|
|
// 查询推送
|
|
|
- JSONObject result = searchOpenService.getResultJsonObject("count:"+docType, searchParams);
|
|
|
+ JSONObject result = searchOpenService.getResultJsonObject("count:" + docType, searchParams);
|
|
|
if (1 == result.getInt("status")) {
|
|
|
return result.getJSONArray("facet").getJSONObject(0)
|
|
|
- .getJSONArray("items").getJSONObject(0).getInt("count");
|
|
|
+ .getJSONArray("items").getJSONObject(0).getInt("count");
|
|
|
} else {
|
|
|
return -1;
|
|
|
}
|
|
@@ -236,13 +236,13 @@ public class SearchQueryServiceImpl implements SearchQueryService {
|
|
|
// 创建参数对象
|
|
|
SearchParams searchParams = new SearchParams(config);
|
|
|
if (null != docId) {
|
|
|
- if("product".equals(docType)) {
|
|
|
+ if ("product".equals(docType)) {
|
|
|
searchParams.setQuery("p_id:'" + docId + "'");
|
|
|
- } else if("shop".equals(docType)) {
|
|
|
+ } else if ("shop".equals(docType)) {
|
|
|
searchParams.setQuery("s_id:'" + docId + "'");
|
|
|
- } else if("equipment".equals(docType)) {
|
|
|
+ } else if ("equipment".equals(docType)) {
|
|
|
searchParams.setQuery("e_id:'" + docId + "'");
|
|
|
- } else if("article".equals(docType)) {
|
|
|
+ } else if ("article".equals(docType)) {
|
|
|
searchParams.setQuery("a_id:'" + docId + "'");
|
|
|
} else {
|
|
|
return 0;
|
|
@@ -259,8 +259,8 @@ public class SearchQueryServiceImpl implements SearchQueryService {
|
|
|
}
|
|
|
try {
|
|
|
// 查询推送
|
|
|
- JSONObject result = searchOpenService.getResultJsonObject("count:"+docType, searchParams);
|
|
|
- if (1 == result.getInt("status") && result.getInt("total")>=0) {
|
|
|
+ JSONObject result = searchOpenService.getResultJsonObject("count:" + docType, searchParams);
|
|
|
+ if (1 == result.getInt("status") && result.getInt("total") >= 0) {
|
|
|
return result.getInt("total");
|
|
|
} else {
|
|
|
return -1;
|
|
@@ -329,7 +329,7 @@ public class SearchQueryServiceImpl implements SearchQueryService {
|
|
|
* @return JsonStr(list)
|
|
|
*/
|
|
|
@Override
|
|
|
- public ResponseJson<String> queryArticleByKeyword(String keyword, int pageNum, int pageSize,Integer status) {
|
|
|
+ public ResponseJson<String> queryArticleByKeyword(String keyword, int pageNum, int pageSize, Integer status) {
|
|
|
String queryStr = "article:'" + keyword + "'";
|
|
|
if (StringUtils.isEmpty(keyword)) {
|
|
|
queryStr = "a_all:'1'";
|
|
@@ -345,16 +345,17 @@ public class SearchQueryServiceImpl implements SearchQueryService {
|
|
|
summaryField2.put("field", "a_intro");
|
|
|
summaryList.add(summaryField2);
|
|
|
// 阿里云搜索
|
|
|
- ResponseJson<String> result = queryArticleForParams(queryStr, fetchFields, summaryList, pageNum, pageSize, null, 1);
|
|
|
+ String sort = 2 == status ? "a_publish_date" : null;
|
|
|
+ ResponseJson<String> result = queryArticleForParams(queryStr, fetchFields, summaryList, pageNum, pageSize, sort, 1);
|
|
|
if (0 == result.getCode()) {
|
|
|
return result;
|
|
|
} else {
|
|
|
// 阿里云搜索失败,再次从数据库搜索
|
|
|
//1.2.8版本新加根据时间排序
|
|
|
- if(status==1){
|
|
|
+ if (status == 1) {
|
|
|
//综合排序
|
|
|
return queryArticleFromDatabase(pageNum, pageSize, keyword, null, null, null);
|
|
|
- }else {
|
|
|
+ } else {
|
|
|
//根据时间排序
|
|
|
return queryArticleFromDatabaseByProDate(pageNum, pageSize, keyword, null, null, null);
|
|
|
}
|
|
@@ -421,24 +422,24 @@ public class SearchQueryServiceImpl implements SearchQueryService {
|
|
|
// if (0 == result.getCode()) {
|
|
|
// return result;
|
|
|
// } else {
|
|
|
- // 阿里云搜索失败,再次从数据库搜索
|
|
|
- return queryArticleFromDatabase(pageNum, pageSize, null, null, null, id);
|
|
|
+ // 阿里云搜索失败,再次从数据库搜索
|
|
|
+ return queryArticleFromDatabase(pageNum, pageSize, null, null, null, id);
|
|
|
// }
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 文章查询(数据库)
|
|
|
*
|
|
|
- * @param keyword 关键词
|
|
|
- * @param articleId 文章Id
|
|
|
- * @param typeId 分类Id
|
|
|
- * @param labelId 标签Id
|
|
|
- * @param num 页码
|
|
|
- * @param size 每页数量
|
|
|
+ * @param keyword 关键词
|
|
|
+ * @param articleId 文章Id
|
|
|
+ * @param typeId 分类Id
|
|
|
+ * @param labelId 标签Id
|
|
|
+ * @param num 页码
|
|
|
+ * @param size 每页数量
|
|
|
*/
|
|
|
private ResponseJson<String> queryArticleFromDatabase(int num, int size, String keyword, Integer articleId, Integer typeId, Integer labelId) {
|
|
|
String labelText = null;
|
|
|
- if (null != labelId){
|
|
|
+ if (null != labelId) {
|
|
|
labelText = searchMapper.findLabelNameById(labelId);
|
|
|
}
|
|
|
PageHelper.startPage(num, size);
|
|
@@ -448,15 +449,15 @@ public class SearchQueryServiceImpl implements SearchQueryService {
|
|
|
article.setImage(imagePath);
|
|
|
// 搜索供应商文档数据
|
|
|
String[] labelTexts = article.getLabelText().split(",");
|
|
|
- if(labelTexts.length > 0){
|
|
|
+ if (labelTexts.length > 0) {
|
|
|
boolean notEmpty = StringUtil.isNotEmpty(labelTexts[0]);
|
|
|
- if(notEmpty){
|
|
|
+ if (notEmpty) {
|
|
|
List<Integer> labelIdList = searchMapper.findLabelIdsByName(labelTexts);
|
|
|
StringBuilder labelIds = new StringBuilder();
|
|
|
labelIdList.forEach(id -> {
|
|
|
labelIds.append(",").append(id);
|
|
|
});
|
|
|
- article.setLabelIds(labelIds.toString().replaceFirst(",",""));
|
|
|
+ article.setLabelIds(labelIds.toString().replaceFirst(",", ""));
|
|
|
}
|
|
|
}
|
|
|
});
|
|
@@ -465,26 +466,28 @@ public class SearchQueryServiceImpl implements SearchQueryService {
|
|
|
JSONObject pageObj = new JSONObject();
|
|
|
pageObj.put("total", total);
|
|
|
pageObj.put("items", articleList);
|
|
|
- log.info(">>>>>>数据库容错查询: pageSize(" + size +"),pageNum("+size+"),total("+total+")");
|
|
|
- if (articleList.size()>0) {
|
|
|
+ log.info(">>>>>>数据库容错查询: pageSize(" + size + "),pageNum(" + size + "),total(" + total + ")");
|
|
|
+ if (articleList.size() > 0) {
|
|
|
return ResponseJson.success(pageObj.toString());
|
|
|
} else {
|
|
|
return ResponseJson.error("未查询到文档记录(数据库)", null);
|
|
|
}
|
|
|
}
|
|
|
- /**1.2.8新加发布时间排序
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 1.2.8新加发布时间排序
|
|
|
* 文章查询(数据库)
|
|
|
*
|
|
|
- * @param keyword 关键词
|
|
|
- * @param articleId 文章Id
|
|
|
- * @param typeId 分类Id
|
|
|
- * @param labelId 标签Id
|
|
|
- * @param num 页码
|
|
|
- * @param size 每页数量
|
|
|
+ * @param keyword 关键词
|
|
|
+ * @param articleId 文章Id
|
|
|
+ * @param typeId 分类Id
|
|
|
+ * @param labelId 标签Id
|
|
|
+ * @param num 页码
|
|
|
+ * @param size 每页数量
|
|
|
*/
|
|
|
private ResponseJson<String> queryArticleFromDatabaseByProDate(int num, int size, String keyword, Integer articleId, Integer typeId, Integer labelId) {
|
|
|
String labelText = null;
|
|
|
- if (null != labelId){
|
|
|
+ if (null != labelId) {
|
|
|
labelText = searchMapper.findLabelNameById(labelId);
|
|
|
}
|
|
|
PageHelper.startPage(num, size);
|
|
@@ -494,15 +497,15 @@ public class SearchQueryServiceImpl implements SearchQueryService {
|
|
|
article.setImage(imagePath);
|
|
|
// 搜索供应商文档数据
|
|
|
String[] labelTexts = article.getLabelText().split(",");
|
|
|
- if(labelTexts.length > 0){
|
|
|
+ if (labelTexts.length > 0) {
|
|
|
boolean notEmpty = StringUtil.isNotEmpty(labelTexts[0]);
|
|
|
- if(notEmpty){
|
|
|
+ if (notEmpty) {
|
|
|
List<Integer> labelIdList = searchMapper.findLabelIdsByName(labelTexts);
|
|
|
StringBuilder labelIds = new StringBuilder();
|
|
|
labelIdList.forEach(id -> {
|
|
|
labelIds.append(",").append(id);
|
|
|
});
|
|
|
- article.setLabelIds(labelIds.toString().replaceFirst(",",""));
|
|
|
+ article.setLabelIds(labelIds.toString().replaceFirst(",", ""));
|
|
|
}
|
|
|
}
|
|
|
});
|
|
@@ -511,8 +514,8 @@ public class SearchQueryServiceImpl implements SearchQueryService {
|
|
|
JSONObject pageObj = new JSONObject();
|
|
|
pageObj.put("total", total);
|
|
|
pageObj.put("items", articleList);
|
|
|
- log.info(">>>>>>数据库容错查询: pageSize(" + size +"),pageNum("+size+"),total("+total+")");
|
|
|
- if (articleList.size()>0) {
|
|
|
+ log.info(">>>>>>数据库容错查询: pageSize(" + size + "),pageNum(" + size + "),total(" + total + ")");
|
|
|
+ if (articleList.size() > 0) {
|
|
|
return ResponseJson.success(pageObj.toString());
|
|
|
} else {
|
|
|
return ResponseJson.error("未查询到文档记录(数据库)", null);
|
|
@@ -530,9 +533,9 @@ public class SearchQueryServiceImpl implements SearchQueryService {
|
|
|
*/
|
|
|
private ResponseJson<String> queryArticleForParams(String queryStr, ArrayList<String> fetchFields, List<Map<String, String>> summaryFields, int num, int size, String sortField, Integer sortType) {
|
|
|
SearchParams searchParams;
|
|
|
- int requestSize = num*size;
|
|
|
+ int requestSize = num * size;
|
|
|
// 由于阿里云搜索机制问题(分页数据重复),搜索500条以内数据手动分页。
|
|
|
- if (requestSize > SEARCH_MAX_NUM){
|
|
|
+ if (requestSize > SEARCH_MAX_NUM) {
|
|
|
searchParams = searchOpenService.getSearchParams(queryStr, fetchFields, summaryFields, "article", num, size, sortField, sortType);
|
|
|
} else {
|
|
|
searchParams = searchOpenService.getSearchParams(queryStr, fetchFields, summaryFields, "article", 1, requestSize, sortField, sortType);
|
|
@@ -542,21 +545,21 @@ public class SearchQueryServiceImpl implements SearchQueryService {
|
|
|
JSONObject result = searchOpenService.getResultJsonObject(queryStr, searchParams);
|
|
|
if (1 == result.getInt("status")) {
|
|
|
int total = result.getInt("total");
|
|
|
- int totalPage = (int) Math.ceil( (double)total/size);
|
|
|
+ int totalPage = (int) Math.ceil((double) total / size);
|
|
|
JSONArray resultArr = result.getJSONArray("items");
|
|
|
JSONArray pageData = new JSONArray();
|
|
|
if (requestSize > SEARCH_MAX_NUM) {
|
|
|
pageData = resultArr;
|
|
|
} else {
|
|
|
- if (resultArr.length()>0){
|
|
|
- int baseNum = (num-1)*size;
|
|
|
- for (int i=0; i<size; i++) {
|
|
|
+ if (resultArr.length() > 0) {
|
|
|
+ int baseNum = (num - 1) * size;
|
|
|
+ for (int i = 0; i < size; i++) {
|
|
|
int index = baseNum + i;
|
|
|
int currentTotal = requestSize;
|
|
|
- if (totalPage == num){
|
|
|
+ if (totalPage == num) {
|
|
|
currentTotal = total;
|
|
|
}
|
|
|
- if (index<currentTotal){
|
|
|
+ if (index < currentTotal) {
|
|
|
JSONObject item = resultArr.getJSONObject(index);
|
|
|
pageData.put(i, item);
|
|
|
} else {
|
|
@@ -570,7 +573,7 @@ public class SearchQueryServiceImpl implements SearchQueryService {
|
|
|
JSONObject pageObj = new JSONObject();
|
|
|
pageObj.put("total", total);
|
|
|
pageObj.put("items", articleList);
|
|
|
- log.info(">>>>>>pageResult("+queryStr+"): pageSize(" + size +"),pageNum("+num+"),total("+total+")");
|
|
|
+ log.info(">>>>>>pageResult(" + queryStr + "): pageSize(" + size + "),pageNum(" + num + "),total(" + total + ")");
|
|
|
return ResponseJson.success(pageObj.toString());
|
|
|
} else {
|
|
|
return ResponseJson.error("未查询到文档记录", null);
|
|
@@ -585,22 +588,22 @@ public class SearchQueryServiceImpl implements SearchQueryService {
|
|
|
* 滚动查询文章数据
|
|
|
*
|
|
|
* @param queryStr 查询类型及参数
|
|
|
- * @param pageNum 页码
|
|
|
- * @param pageSize 每页数量
|
|
|
+ * @param pageNum 页码
|
|
|
+ * @param pageSize 每页数量
|
|
|
* @param sortField 排序字段
|
|
|
* @param sortType 升降序
|
|
|
*/
|
|
|
private ResponseJson<String> scrollArticleForParams(String queryStr, ArrayList<String> fetchFields, int pageNum, int pageSize, String sortField, Integer sortType) {
|
|
|
- int requestSize = pageNum*pageSize;
|
|
|
+ int requestSize = pageNum * pageSize;
|
|
|
int requestPageSize = requestSize;
|
|
|
- if (requestSize > SEARCH_MAX_NUM){
|
|
|
- requestPageSize = (int) Math.floor(SEARCH_MAX_NUM/pageSize) * pageSize;
|
|
|
+ if (requestSize > SEARCH_MAX_NUM) {
|
|
|
+ requestPageSize = (int) Math.floor(SEARCH_MAX_NUM / pageSize) * pageSize;
|
|
|
}
|
|
|
SearchParams searchParams = searchOpenService.getScrollParams(queryStr, fetchFields, requestPageSize, sortField, sortType);
|
|
|
ResponseJson<String> result;
|
|
|
try {
|
|
|
JSONObject pageObj = searchOpenService.deepPagingForParams(searchParams, queryStr, SEARCH_MAX_NUM, requestPageSize, pageNum, pageSize);
|
|
|
- if (1 == pageObj.getInt("status")){
|
|
|
+ if (1 == pageObj.getInt("status")) {
|
|
|
JSONArray pageData = pageObj.getJSONArray("items");
|
|
|
// 阿里云查询出json转换成商品pojo
|
|
|
List<ArticleListVo> articleList = Json2PojoUtil.toArticleList(pageData);
|
|
@@ -619,9 +622,9 @@ public class SearchQueryServiceImpl implements SearchQueryService {
|
|
|
/**
|
|
|
* 获取项目仪器(数据库)
|
|
|
*
|
|
|
- * @param num 页码
|
|
|
- * @param size 每页数量
|
|
|
- * @param keyword 关键词
|
|
|
+ * @param num 页码
|
|
|
+ * @param size 每页数量
|
|
|
+ * @param keyword 关键词
|
|
|
*/
|
|
|
private ResponseJson<String> queryEquipmentFromDatabase(int num, int size, String keyword) {
|
|
|
PageHelper.startPage(num, size);
|
|
@@ -631,8 +634,8 @@ public class SearchQueryServiceImpl implements SearchQueryService {
|
|
|
JSONObject pageObj = new JSONObject();
|
|
|
pageObj.put("total", total);
|
|
|
pageObj.put("items", equipmentList);
|
|
|
- log.info(">>>>>>数据库容错查询: pageSize(" + size +"),pageNum("+size+"),total("+total+")");
|
|
|
- if (equipmentList.size()>0) {
|
|
|
+ log.info(">>>>>>数据库容错查询: pageSize(" + size + "),pageNum(" + size + "),total(" + total + ")");
|
|
|
+ if (equipmentList.size() > 0) {
|
|
|
return ResponseJson.success(pageObj.toString());
|
|
|
} else {
|
|
|
return ResponseJson.error("未查询到文档记录(数据库)", null);
|
|
@@ -642,7 +645,7 @@ public class SearchQueryServiceImpl implements SearchQueryService {
|
|
|
/**
|
|
|
* 查询项目仪器(阿里云搜索)
|
|
|
*
|
|
|
- * @param queryStr 查询类型及参数
|
|
|
+ * @param queryStr 查询类型及参数
|
|
|
* @param pageNum 页码
|
|
|
* @param pageSize 每页数量
|
|
|
*/
|
|
@@ -655,8 +658,8 @@ public class SearchQueryServiceImpl implements SearchQueryService {
|
|
|
summaryList.add(summaryField);
|
|
|
// 由于阿里云搜索机制问题(分页数据重复),搜索500条以内数据手动分页。
|
|
|
SearchParams searchParams;
|
|
|
- int requestSize = pageNum*pageSize;
|
|
|
- if (requestSize > SEARCH_MAX_NUM){
|
|
|
+ int requestSize = pageNum * pageSize;
|
|
|
+ if (requestSize > SEARCH_MAX_NUM) {
|
|
|
searchParams = searchOpenService.getSearchParams(queryStr, fetchFields, summaryList, "equipment", pageNum, pageSize, null, null);
|
|
|
} else {
|
|
|
searchParams = searchOpenService.getSearchParams(queryStr, fetchFields, summaryList, "equipment", 1, requestSize, null, null);
|
|
@@ -668,19 +671,19 @@ public class SearchQueryServiceImpl implements SearchQueryService {
|
|
|
JSONArray resultArr = result.getJSONArray("items");
|
|
|
JSONArray pageData = new JSONArray();
|
|
|
int total = result.getInt("total");
|
|
|
- int totalPage = (int) Math.ceil( (double)total/pageSize);
|
|
|
+ int totalPage = (int) Math.ceil((double) total / pageSize);
|
|
|
if (requestSize > SEARCH_MAX_NUM) {
|
|
|
pageData = resultArr;
|
|
|
} else {
|
|
|
- if (resultArr.length()>0){
|
|
|
- int baseNum = (pageNum-1)*pageSize;
|
|
|
- for (int i=0; i<pageSize; i++) {
|
|
|
+ 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){
|
|
|
+ if (totalPage == pageNum) {
|
|
|
currentTotal = total;
|
|
|
}
|
|
|
- if (index<currentTotal){
|
|
|
+ if (index < currentTotal) {
|
|
|
JSONObject item = resultArr.getJSONObject(index);
|
|
|
pageData.put(i, item);
|
|
|
} else {
|
|
@@ -694,7 +697,7 @@ public class SearchQueryServiceImpl implements SearchQueryService {
|
|
|
JSONObject pageObj = new JSONObject();
|
|
|
pageObj.put("total", total);
|
|
|
pageObj.put("items", equipmentList);
|
|
|
- log.info(">>>>>>pageResult("+queryStr+"): pageSize(" + pageSize +"),pageNum("+pageNum+"),total("+total+")");
|
|
|
+ log.info(">>>>>>pageResult(" + queryStr + "): pageSize(" + pageSize + "),pageNum(" + pageNum + "),total(" + total + ")");
|
|
|
return ResponseJson.success(pageObj.toString());
|
|
|
} else {
|
|
|
return ResponseJson.error("未查询到文档记录", null);
|
|
@@ -708,10 +711,10 @@ public class SearchQueryServiceImpl implements SearchQueryService {
|
|
|
/**
|
|
|
* 获取供应商(数据库)
|
|
|
*
|
|
|
- * @param num 页码
|
|
|
- * @param size 每页数量
|
|
|
- * @param identity 用户身份
|
|
|
- * @param 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);
|
|
@@ -726,8 +729,8 @@ public class SearchQueryServiceImpl implements SearchQueryService {
|
|
|
JSONObject pageObj = new JSONObject();
|
|
|
pageObj.put("total", total);
|
|
|
pageObj.put("items", shopList);
|
|
|
- log.info(">>>>>>数据库容错查询: pageSize(" + size +"),pageNum("+size+"),total("+total+")");
|
|
|
- if (shopList.size()>0) {
|
|
|
+ log.info(">>>>>>数据库容错查询: pageSize(" + size + "),pageNum(" + size + "),total(" + total + ")");
|
|
|
+ if (shopList.size() > 0) {
|
|
|
return ResponseJson.success(pageObj.toString());
|
|
|
} else {
|
|
|
return ResponseJson.error("未查询到文档记录(数据库)", null);
|
|
@@ -737,7 +740,7 @@ public class SearchQueryServiceImpl implements SearchQueryService {
|
|
|
/**
|
|
|
* 查询供应商(阿里云搜索)
|
|
|
*
|
|
|
- * @param queryStr 查询类型及参数
|
|
|
+ * @param queryStr 查询类型及参数
|
|
|
* @param identity 用户身份 1:协销, 2:会员机构
|
|
|
* @param pageNum 页码
|
|
|
* @param pageSize 每页数量
|
|
@@ -746,8 +749,8 @@ public class SearchQueryServiceImpl implements SearchQueryService {
|
|
|
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){
|
|
|
+ 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);
|
|
@@ -757,13 +760,13 @@ public class SearchQueryServiceImpl implements SearchQueryService {
|
|
|
JSONObject result = searchOpenService.getResultJsonObject(queryStr, searchParams);
|
|
|
if (1 == result.getInt("status")) {
|
|
|
int total = result.getInt("total");
|
|
|
- int totalPage = (int) Math.ceil( (double)total/pageSize);
|
|
|
+ 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) {
|
|
|
+ if (resultArr.length() > 0) {
|
|
|
int baseNum = (pageNum - 1) * pageSize;
|
|
|
for (int i = 0; i < pageSize; i++) {
|
|
|
int index = baseNum + i;
|
|
@@ -797,7 +800,7 @@ public class SearchQueryServiceImpl implements SearchQueryService {
|
|
|
JSONObject pageObj = new JSONObject();
|
|
|
pageObj.put("total", total);
|
|
|
pageObj.put("items", shopList);
|
|
|
- log.info(">>>>>>pageResult("+queryStr+"): pageSize(" + pageSize +"),pageNum("+pageNum+"),total("+total+")");
|
|
|
+ log.info(">>>>>>pageResult(" + queryStr + "): pageSize(" + pageSize + "),pageNum(" + pageNum + "),total(" + total + ")");
|
|
|
return ResponseJson.success(pageObj.toString());
|
|
|
} else {
|
|
|
return ResponseJson.error("未查询到文档记录", null);
|
|
@@ -811,7 +814,7 @@ public class SearchQueryServiceImpl implements SearchQueryService {
|
|
|
@Override
|
|
|
public ResponseJson<PaginationVo<BaikeProductVo>> queryBaikeProductByKeyword(String keyword, int pageNum, int pageSize) {
|
|
|
if (StringUtils.isEmpty(keyword)) {
|
|
|
- return ResponseJson.error("参数异常",null);
|
|
|
+ return ResponseJson.error("参数异常", null);
|
|
|
}
|
|
|
PageHelper.startPage(pageNum, pageSize);
|
|
|
List<BaikeProductVo> baikeProducts = pageMapper.getBaikeProducts(null, keyword, null);
|