|
@@ -24,6 +24,7 @@ import org.springframework.stereotype.Service;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
import javax.annotation.Resource;
|
|
import java.util.ArrayList;
|
|
import java.util.ArrayList;
|
|
|
|
+import java.util.HashMap;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
|
|
|
|
@@ -89,17 +90,9 @@ public class SearchQueryServiceImpl implements SearchQueryService {
|
|
searchParams.setSort(sorter);
|
|
searchParams.setSort(sorter);
|
|
}
|
|
}
|
|
try {
|
|
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 id("+docType+"): " + status + ",request_id=" +requestId+ ",errors=" + errors.toString() + ",tracer="+tracer);
|
|
|
|
- if ("OK".equals(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");
|
|
return result.getJSONArray("items").getJSONObject(0).getInt("id");
|
|
} else {
|
|
} else {
|
|
return -1;
|
|
return -1;
|
|
@@ -150,17 +143,9 @@ public class SearchQueryServiceImpl implements SearchQueryService {
|
|
SearchParams searchParams = new SearchParams(config);
|
|
SearchParams searchParams = new SearchParams(config);
|
|
searchParams.setQuery(queryStr);
|
|
searchParams.setQuery(queryStr);
|
|
try {
|
|
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 idMap("+idName+"): " + status + ",request_id=" +requestId+ ",errors=" + errors.toString() + ",tracer="+tracer);
|
|
|
|
- if ("OK".equals(status)) {
|
|
|
|
|
|
+ // 查询推送
|
|
|
|
+ JSONObject result = searchOpenService.getResultJsonObject("idMap:"+idName, searchParams);
|
|
|
|
+ if (1 == result.getInt("status")) {
|
|
JSONArray jsonArray = result.getJSONArray("items");
|
|
JSONArray jsonArray = result.getJSONArray("items");
|
|
for (int i = 0; i < jsonArray.length(); i++) {
|
|
for (int i = 0; i < jsonArray.length(); i++) {
|
|
idMap.put(jsonArray.getJSONObject(i).getInt(idName), jsonArray.getJSONObject(i).getInt("id"));
|
|
idMap.put(jsonArray.getJSONObject(i).getInt(idName), jsonArray.getJSONObject(i).getInt("id"));
|
|
@@ -210,17 +195,9 @@ public class SearchQueryServiceImpl implements SearchQueryService {
|
|
//添加Aggregate对象参数
|
|
//添加Aggregate对象参数
|
|
searchParams.addToAggregates(agg);
|
|
searchParams.addToAggregates(agg);
|
|
try {
|
|
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 count("+docType+"): " + status + ",request_id=" +requestId+ ",errors=" + errors.toString() + ",tracer="+tracer);
|
|
|
|
- if ("OK".equals(status)) {
|
|
|
|
|
|
+ // 查询推送
|
|
|
|
+ JSONObject result = searchOpenService.getResultJsonObject("count:"+docType, searchParams);
|
|
|
|
+ if (1 == result.getInt("status")) {
|
|
return result.getJSONArray("facet").getJSONObject(0)
|
|
return result.getJSONArray("facet").getJSONObject(0)
|
|
.getJSONArray("items").getJSONObject(0).getInt("count");
|
|
.getJSONArray("items").getJSONObject(0).getInt("count");
|
|
} else {
|
|
} else {
|
|
@@ -274,17 +251,9 @@ public class SearchQueryServiceImpl implements SearchQueryService {
|
|
searchParams.setSort(sorter);
|
|
searchParams.setSort(sorter);
|
|
}
|
|
}
|
|
try {
|
|
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 count("+docType+"): " + status + ",request_id=" +requestId+ ",errors=" + errors.toString() + ",tracer="+tracer);
|
|
|
|
- if ("OK".equals(status) && result.getJSONArray("items").length()>=0) {
|
|
|
|
|
|
+ // 查询推送
|
|
|
|
+ JSONObject result = searchOpenService.getResultJsonObject("count:"+docType, searchParams);
|
|
|
|
+ if (1 == result.getInt("status") && result.getJSONArray("items").length()>=0) {
|
|
return result.getJSONArray("items").length();
|
|
return result.getJSONArray("items").length();
|
|
} else {
|
|
} else {
|
|
return -1;
|
|
return -1;
|
|
@@ -320,6 +289,83 @@ public class SearchQueryServiceImpl implements SearchQueryService {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * 根据关键词搜索项目仪器
|
|
|
|
+ *
|
|
|
|
+ * @param keyword 搜索关键字
|
|
|
|
+ * @param pageNum 页码
|
|
|
|
+ * @param pageSize 每页数量
|
|
|
|
+ * @return JsonStr(list)
|
|
|
|
+ */
|
|
|
|
+ @Override
|
|
|
|
+ public ResponseJson<String> queryEquipmentByKeyword(String keyword, int pageNum, int pageSize) {
|
|
|
|
+ String queryStr = "equipment:'" + keyword + "'";
|
|
|
|
+ if (StringUtils.isEmpty(keyword)) {
|
|
|
|
+ queryStr = "e_all:'1'";
|
|
|
|
+ }
|
|
|
|
+ return queryEquipment(queryStr, pageNum, pageSize);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private ResponseJson<String> queryEquipment(String queryStr, int pageNum, int pageSize) {
|
|
|
|
+ ArrayList<String> fetchFields = Lists.newArrayList("id", "e_id", "e_name", "e_image");
|
|
|
|
+ List<Map<String, String>> summaryList = new ArrayList<>(1);
|
|
|
|
+ Map<String, String> summaryField = new HashMap<>(2);
|
|
|
|
+ summaryField.put("length", "100");
|
|
|
|
+ summaryField.put("field", "e_name");
|
|
|
|
+ summaryList.add(summaryField);
|
|
|
|
+ // 由于阿里云搜索机制问题(分页数据重复),搜索500条以内数据手动分页。
|
|
|
|
+ SearchParams searchParams;
|
|
|
|
+ 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);
|
|
|
|
+ }
|
|
|
|
+ // 查询推送
|
|
|
|
+ try {
|
|
|
|
+ // 查询推送
|
|
|
|
+ JSONObject result = searchOpenService.getResultJsonObject(queryStr, searchParams);
|
|
|
|
+ if (1 == result.getInt("status")) {
|
|
|
|
+ JSONArray resultArr = result.getJSONArray("items");
|
|
|
|
+ JSONArray pageData = new JSONArray();
|
|
|
|
+ int total = result.getInt("total");
|
|
|
|
+ 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++) {
|
|
|
|
+ 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;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ JSONObject pageObj = new JSONObject();
|
|
|
|
+ pageObj.put("total", total);
|
|
|
|
+ pageObj.put("items", pageData);
|
|
|
|
+ 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);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* 获取供应商(数据库)
|
|
* 获取供应商(数据库)
|
|
*
|
|
*
|
|
@@ -369,16 +415,9 @@ public class SearchQueryServiceImpl implements SearchQueryService {
|
|
}
|
|
}
|
|
// 查询推送
|
|
// 查询推送
|
|
try {
|
|
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)) {
|
|
|
|
|
|
+ // 查询推送
|
|
|
|
+ JSONObject result = searchOpenService.getResultJsonObject(queryStr, searchParams);
|
|
|
|
+ if (1 == result.getInt("status")) {
|
|
int total = result.getInt("total");
|
|
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 resultArr = result.getJSONArray("items");
|
|
@@ -408,16 +447,9 @@ public class SearchQueryServiceImpl implements SearchQueryService {
|
|
int supplierId = supplier.getInt("s_id");
|
|
int supplierId = supplier.getInt("s_id");
|
|
String productQuery = "p_supplier:'" + supplierId + "'";
|
|
String productQuery = "p_supplier:'" + supplierId + "'";
|
|
SearchParams productSearchParams = searchOpenService.getProductParams(productQuery, "", identity, 1, 3, "", null);
|
|
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)) {
|
|
|
|
|
|
+ // 查询商品
|
|
|
|
+ JSONObject pResult = searchOpenService.getResultJsonObject(productQuery, productSearchParams);
|
|
|
|
+ if (1 == pResult.getInt("status")) {
|
|
JSONArray productArr = pResult.getJSONArray("items");
|
|
JSONArray productArr = pResult.getJSONArray("items");
|
|
supplier.put("products", productArr);
|
|
supplier.put("products", productArr);
|
|
}
|
|
}
|