|
@@ -201,12 +201,12 @@ public class SearchIndexServiceImpl implements SearchIndexService {
|
|
if (null != product) {
|
|
if (null != product) {
|
|
// 定义星范商品数据
|
|
// 定义星范商品数据
|
|
List<DocumentDTO<MallProductDO>> mallProductList = new ArrayList<>();
|
|
List<DocumentDTO<MallProductDO>> mallProductList = new ArrayList<>();
|
|
- // 星范商品设值,【必须先于商品文档设值】
|
|
|
|
- Integer mallId = setMallProductDocument(mallProductList, productId);
|
|
|
|
|
|
+// // 星范商品设值,【必须先于商品文档设值】
|
|
|
|
+// Integer mallId = setMallProductDocument(mallProductList, productId);
|
|
// 定义商品文档数据
|
|
// 定义商品文档数据
|
|
List<DocumentDTO<ProductDO>> productList = new ArrayList<>();
|
|
List<DocumentDTO<ProductDO>> productList = new ArrayList<>();
|
|
// 商品文档设值
|
|
// 商品文档设值
|
|
- setProductDocument(productList, product, mallId);
|
|
|
|
|
|
+ setProductDocument(productList, product, null);
|
|
// 定义主文档入口数据
|
|
// 定义主文档入口数据
|
|
List<DocumentDTO<MainDO>> mainList = new ArrayList<>();
|
|
List<DocumentDTO<MainDO>> mainList = new ArrayList<>();
|
|
// 主文档设值
|
|
// 主文档设值
|
|
@@ -214,21 +214,17 @@ public class SearchIndexServiceImpl implements SearchIndexService {
|
|
if (mainId == -1) {
|
|
if (mainId == -1) {
|
|
mainId = searchQueryService.getIdByDocId("", null);
|
|
mainId = searchQueryService.getIdByDocId("", null);
|
|
mainId = mainId == -1 ? 0 : mainId+1;
|
|
mainId = mainId == -1 ? 0 : mainId+1;
|
|
|
|
+ // 新增主文档, 商品:type=1
|
|
|
|
+ setMainDocument(1, mainList, mainId, productId);
|
|
}
|
|
}
|
|
- // 商品文档 type=1
|
|
|
|
- setMainDocument(1, mainList, mainId, productId);
|
|
|
|
try {
|
|
try {
|
|
// 查询商品数量是否唯一,不唯一则删除后更新索引
|
|
// 查询商品数量是否唯一,不唯一则删除后更新索引
|
|
Integer count = searchQueryService.getCountByDocId("product", productId);
|
|
Integer count = searchQueryService.getCountByDocId("product", productId);
|
|
if (count > 1) {
|
|
if (count > 1) {
|
|
- log.info("商品重复,重复商品id>>>>>>>>>>>" + productId);
|
|
|
|
- if (mainId > 0) {
|
|
|
|
- // 删除主文档记录
|
|
|
|
- deleteDocByTypeId("id", mainId, "search_main");
|
|
|
|
- return updateProductIndexById(productId);
|
|
|
|
- }
|
|
|
|
- // 主文档不存在,删除商品文档
|
|
|
|
- return deleteProductIndexById(productId);
|
|
|
|
|
|
+ log.info("商品重复,重复商品>>>>>>>>>>>" + productId +"重复数量:" + count);
|
|
|
|
+ // 删除主文档记录
|
|
|
|
+ deleteDocByTypeId("id", mainId, "search_main");
|
|
|
|
+ return updateProductIndexById(productId);
|
|
} else {
|
|
} else {
|
|
// 推送到阿里云
|
|
// 推送到阿里云
|
|
pushProductDocument(mainList, productList, mallProductList);
|
|
pushProductDocument(mainList, productList, mallProductList);
|
|
@@ -269,21 +265,17 @@ public class SearchIndexServiceImpl implements SearchIndexService {
|
|
if (mainId == -1) {
|
|
if (mainId == -1) {
|
|
mainId = searchQueryService.getIdByDocId("", null);
|
|
mainId = searchQueryService.getIdByDocId("", null);
|
|
mainId = mainId == -1 ? 0 : mainId+1;
|
|
mainId = mainId == -1 ? 0 : mainId+1;
|
|
|
|
+ // 新增主文档, 供应商:type=2
|
|
|
|
+ setMainDocument(2, mainList, mainId, shopId);
|
|
}
|
|
}
|
|
- // 供应商文档 type=2
|
|
|
|
- setMainDocument(2, mainList, mainId, shopId);
|
|
|
|
try {
|
|
try {
|
|
// 查询供应商是否唯一,不唯一则删除后重新更新索引
|
|
// 查询供应商是否唯一,不唯一则删除后重新更新索引
|
|
Integer count = searchQueryService.getCountByDocId("shop", shopId);
|
|
Integer count = searchQueryService.getCountByDocId("shop", shopId);
|
|
if (count > 1) {
|
|
if (count > 1) {
|
|
- log.info("供应商重复,重复供应商id>>>>>>>>>>>" + shopId);
|
|
|
|
- if (mainId > 0) {
|
|
|
|
- // 删除主文档记录
|
|
|
|
- deleteDocByTypeId("id", mainId, "search_main");
|
|
|
|
- return updateSupplierIndexById(shopId);
|
|
|
|
- }
|
|
|
|
- // 主文档不存在,删除供应商文档
|
|
|
|
- return deleteSupplierIndexById(shopId);
|
|
|
|
|
|
+ log.info("供应商重复,重复供应商>>>>>>>>>>>" + shopId +"重复数量:" + count);;
|
|
|
|
+ // 删除主文档记录
|
|
|
|
+ deleteDocByTypeId("id", mainId, "search_main");
|
|
|
|
+ return updateSupplierIndexById(shopId);
|
|
} else {
|
|
} else {
|
|
// 将文档列表转换成Json串,并推送到阿里云
|
|
// 将文档列表转换成Json串,并推送到阿里云
|
|
pushSupplierDocument(mainList, supplierList);
|
|
pushSupplierDocument(mainList, supplierList);
|
|
@@ -324,21 +316,17 @@ public class SearchIndexServiceImpl implements SearchIndexService {
|
|
if (mainId == -1) {
|
|
if (mainId == -1) {
|
|
mainId = searchQueryService.getIdByDocId("", null);
|
|
mainId = searchQueryService.getIdByDocId("", null);
|
|
mainId = mainId == -1 ? 0 : mainId+1;
|
|
mainId = mainId == -1 ? 0 : mainId+1;
|
|
|
|
+ // 新增主文档, 项目仪器:type=3
|
|
|
|
+ setMainDocument(3, mainList, mainId, equipmentId);
|
|
}
|
|
}
|
|
- // 项目仪器文档 type=3
|
|
|
|
- setMainDocument(3, mainList, mainId, equipmentId);
|
|
|
|
try {
|
|
try {
|
|
// 查询项目仪器数量是否唯一,不唯一则删除后重新更新索引
|
|
// 查询项目仪器数量是否唯一,不唯一则删除后重新更新索引
|
|
Integer count = searchQueryService.getCountByDocId("equipment", equipmentId);
|
|
Integer count = searchQueryService.getCountByDocId("equipment", equipmentId);
|
|
if (count > 1) {
|
|
if (count > 1) {
|
|
- log.info("项目仪器重复,重复项目仪器id>>>>>>>>>>>" + equipmentId);
|
|
|
|
- if (mainId > 0) {
|
|
|
|
- // 删除主文档记录
|
|
|
|
- deleteDocByTypeId("id", mainId, "search_main");
|
|
|
|
- return updateEquipmentIndexById(equipmentId);
|
|
|
|
- }
|
|
|
|
- // 主文档不存在,删除项目仪器文档
|
|
|
|
- return deleteEquipmentIndexById(equipmentId);
|
|
|
|
|
|
+ log.info("项目仪器重复,重复项目仪器>>>>>>>>>>>" + equipmentId+"重复数量:" + count);
|
|
|
|
+ // 删除主文档记录
|
|
|
|
+ deleteDocByTypeId("id", mainId, "search_main");
|
|
|
|
+ return updateEquipmentIndexById(equipmentId);
|
|
} else {
|
|
} else {
|
|
// 将文档列表转换成Json串,并推送到阿里云
|
|
// 将文档列表转换成Json串,并推送到阿里云
|
|
pushEquipmentDocument(mainList, equipmentList);
|
|
pushEquipmentDocument(mainList, equipmentList);
|
|
@@ -379,26 +367,23 @@ public class SearchIndexServiceImpl implements SearchIndexService {
|
|
if (mainId == -1) {
|
|
if (mainId == -1) {
|
|
mainId = searchQueryService.getIdByDocId("", null);
|
|
mainId = searchQueryService.getIdByDocId("", null);
|
|
mainId = mainId == -1 ? 0 : mainId+1;
|
|
mainId = mainId == -1 ? 0 : mainId+1;
|
|
|
|
+ // 新增主文档, 文章 type=4
|
|
|
|
+ setMainDocument(4, mainList, mainId, articleId);
|
|
}
|
|
}
|
|
- // 文章文档 type=4
|
|
|
|
- setMainDocument(4, mainList, mainId, articleId);
|
|
|
|
|
|
+
|
|
try {
|
|
try {
|
|
// 查询文章数量是否唯一,不唯一则删除后重新更新索引
|
|
// 查询文章数量是否唯一,不唯一则删除后重新更新索引
|
|
Integer count = searchQueryService.getCountByDocId("article", articleId);
|
|
Integer count = searchQueryService.getCountByDocId("article", articleId);
|
|
if (count > 1) {
|
|
if (count > 1) {
|
|
- log.info("文章重复,重复文章id>>>>>>>>>>>" + articleId);
|
|
|
|
- if (mainId > 0) {
|
|
|
|
- // 删除主文档记录
|
|
|
|
- deleteDocByTypeId("id", mainId, "search_main");
|
|
|
|
- return updateArticleIndexById(articleId);
|
|
|
|
- }
|
|
|
|
- // 主文档不存在,删除文章文档
|
|
|
|
- return deleteArticleIndexById(articleId);
|
|
|
|
|
|
+ log.info("文章重复,重复文章>>>>>>>>>>>" + articleId +"重复数量:" + count);
|
|
|
|
+ // 删除主文档记录
|
|
|
|
+ deleteDocByTypeId("id", mainId, "search_main");
|
|
|
|
+ return updateArticleIndexById(articleId);
|
|
} else {
|
|
} else {
|
|
// 将主文档列表转换成Json串,并推送到阿里云
|
|
// 将主文档列表转换成Json串,并推送到阿里云
|
|
pushArticleDocument(mainList, articleList);
|
|
pushArticleDocument(mainList, articleList);
|
|
// 返回结果
|
|
// 返回结果
|
|
- return ResponseJson.success(mainList.size());
|
|
|
|
|
|
+ return ResponseJson.success(articleList.size());
|
|
}
|
|
}
|
|
} catch (OpenSearchClientException | OpenSearchException | JSONException e) {
|
|
} catch (OpenSearchClientException | OpenSearchException | JSONException e) {
|
|
log.error("添加文章文档异常:" + e);
|
|
log.error("添加文章文档异常:" + e);
|
|
@@ -615,10 +600,10 @@ public class SearchIndexServiceImpl implements SearchIndexService {
|
|
|
|
|
|
int productMainId;
|
|
int productMainId;
|
|
for (ProductDO product : dbList) {
|
|
for (ProductDO product : dbList) {
|
|
- // 星范商品设值,【必须先于商品文档设值】
|
|
|
|
- Integer mallId = setMallProductDocument(mallProductList, product.getP_id());
|
|
|
|
|
|
+// // 星范商品设值,【必须先于商品文档设值】
|
|
|
|
+// Integer mallId = setMallProductDocument(mallProductList, product.getP_id());
|
|
// 商品文档设值
|
|
// 商品文档设值
|
|
- setProductDocument(productList, product, mallId);
|
|
|
|
|
|
+ setProductDocument(productList, product, null);
|
|
// 主文档设值
|
|
// 主文档设值
|
|
Integer productId = product.getP_id();
|
|
Integer productId = product.getP_id();
|
|
if(initFlag){
|
|
if(initFlag){
|
|
@@ -661,14 +646,22 @@ public class SearchIndexServiceImpl implements SearchIndexService {
|
|
* @throws OpenSearchException exp
|
|
* @throws OpenSearchException exp
|
|
*/
|
|
*/
|
|
private void pushProductDocument(List<DocumentDTO<MainDO>> mainList, List<DocumentDTO<ProductDO>> productList, List<DocumentDTO<MallProductDO>> mallProductList) throws OpenSearchClientException, OpenSearchException {
|
|
private void pushProductDocument(List<DocumentDTO<MainDO>> mainList, List<DocumentDTO<ProductDO>> productList, List<DocumentDTO<MallProductDO>> mallProductList) throws OpenSearchClientException, OpenSearchException {
|
|
- // 将主文档列表转换成Json串,并推送到阿里云
|
|
|
|
- String mainDocStr = new JSONArray(mainList).toString();
|
|
|
|
- String mainResult = searchOpenService.pushDocument(mainDocStr, "search_main");
|
|
|
|
- log.info(">>>>>>>>>>>>>>>add document: 【search_main(" + mainList.size() + "):" + mainResult + "】" + mainList.toString());
|
|
|
|
|
|
+ if (mainList.size()>0) {
|
|
|
|
+ // 将主文档列表转换成Json串,并推送到阿里云
|
|
|
|
+ String mainDocStr = new JSONArray(mainList).toString();
|
|
|
|
+ String mainResult = searchOpenService.pushDocument(mainDocStr, "search_main");
|
|
|
|
+ log.info(">>>>>>>>>>>>>>>add document: 【search_main(" + mainList.size() + "个):" + mainResult + "】" + mainList.toString());
|
|
|
|
+ }
|
|
// 将商品文档推送到阿里云
|
|
// 将商品文档推送到阿里云
|
|
String productDocStr = new JSONArray(productList).toString();
|
|
String productDocStr = new JSONArray(productList).toString();
|
|
String productResult = searchOpenService.pushDocument(productDocStr, "search_product");
|
|
String productResult = searchOpenService.pushDocument(productDocStr, "search_product");
|
|
- log.info(">>>>>>>>>>>>>>>add document: 【search_product(" + productList.size() + "):" + productResult + "】");
|
|
|
|
|
|
+ if (mainList.size()>0) {
|
|
|
|
+ // 新增
|
|
|
|
+ log.info(">>>>>>>>>>>>>>>add document: 【search_product(" + productList.size() + "个):" + productResult + "】");
|
|
|
|
+ } else {
|
|
|
|
+ // 更新
|
|
|
|
+ log.info(">>>>>>>>>>>>>>>update document: 【search_product(" + productList.size() + "个):" + productResult + "】");
|
|
|
|
+ }
|
|
// 将星范商品推送到阿里云
|
|
// 将星范商品推送到阿里云
|
|
if (mallProductList.size()>0) {
|
|
if (mallProductList.size()>0) {
|
|
String mallProductStr = new JSONArray(mallProductList).toString();
|
|
String mallProductStr = new JSONArray(mallProductList).toString();
|
|
@@ -785,14 +778,22 @@ public class SearchIndexServiceImpl implements SearchIndexService {
|
|
* @throws OpenSearchException exp
|
|
* @throws OpenSearchException exp
|
|
*/
|
|
*/
|
|
private void pushSupplierDocument(List<DocumentDTO<MainDO>> mainList, List<DocumentDTO<SupplierDO>> supplierList) throws OpenSearchClientException, OpenSearchException {
|
|
private void pushSupplierDocument(List<DocumentDTO<MainDO>> mainList, List<DocumentDTO<SupplierDO>> supplierList) throws OpenSearchClientException, OpenSearchException {
|
|
- // 将主文档列表转换成Json串,并推送到阿里云
|
|
|
|
- String mainDocStr = new JSONArray(mainList).toString();
|
|
|
|
- String mainResult = searchOpenService.pushDocument(mainDocStr, "search_main");
|
|
|
|
- log.info(">>>>>>>>>>>>>>>add document: 【search_main(" + mainList.size() + "):" + mainResult + "】" + mainList.toString());
|
|
|
|
|
|
+ if (mainList.size()>0) {
|
|
|
|
+ // 将主文档列表转换成Json串,并推送到阿里云
|
|
|
|
+ String mainDocStr = new JSONArray(mainList).toString();
|
|
|
|
+ String mainResult = searchOpenService.pushDocument(mainDocStr, "search_main");
|
|
|
|
+ log.info(">>>>>>>>>>>>>>>add document: 【search_main(" + mainList.size() + "个):" + mainResult + "】" + mainList.toString());
|
|
|
|
+ }
|
|
// 将商品文档推送到阿里云
|
|
// 将商品文档推送到阿里云
|
|
String supplierDocStr = new JSONArray(supplierList).toString();
|
|
String supplierDocStr = new JSONArray(supplierList).toString();
|
|
String supplierResult = searchOpenService.pushDocument(supplierDocStr, "search_supplier");
|
|
String supplierResult = searchOpenService.pushDocument(supplierDocStr, "search_supplier");
|
|
- log.info(">>>>>>>>>>>>>>>add document: 【search_supplier(" + supplierList.size() + "):" + supplierResult + "】");
|
|
|
|
|
|
+ if (mainList.size()>0) {
|
|
|
|
+ // 新增
|
|
|
|
+ log.info(">>>>>>>>>>>>>>>add document: 【search_supplier(" + supplierList.size() + "个):" + supplierResult + "】");
|
|
|
|
+ } else {
|
|
|
|
+ // 更新
|
|
|
|
+ log.info(">>>>>>>>>>>>>>>update document: 【search_supplier(" + supplierList.size() + "个):" + supplierResult + "】");
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -903,14 +904,22 @@ public class SearchIndexServiceImpl implements SearchIndexService {
|
|
* @throws OpenSearchException exp
|
|
* @throws OpenSearchException exp
|
|
*/
|
|
*/
|
|
private void pushEquipmentDocument(List<DocumentDTO<MainDO>> mainList, List<DocumentDTO<EquipmentDO>> equipmentList) throws OpenSearchClientException, OpenSearchException {
|
|
private void pushEquipmentDocument(List<DocumentDTO<MainDO>> mainList, List<DocumentDTO<EquipmentDO>> equipmentList) throws OpenSearchClientException, OpenSearchException {
|
|
- // 将主文档列表转换成Json串,并推送到阿里云
|
|
|
|
- String mainDocStr = new JSONArray(mainList).toString();
|
|
|
|
- String mainResult = searchOpenService.pushDocument(mainDocStr, "search_main");
|
|
|
|
- log.info(">>>>>>>>>>>>>>>add document: 【search_main(" + mainList.size() + "):" + mainResult + "】" + mainList.toString());
|
|
|
|
|
|
+ if (mainList.size()>0) {
|
|
|
|
+ // 将主文档列表转换成Json串,并推送到阿里云
|
|
|
|
+ String mainDocStr = new JSONArray(mainList).toString();
|
|
|
|
+ String mainResult = searchOpenService.pushDocument(mainDocStr, "search_main");
|
|
|
|
+ log.info(">>>>>>>>>>>>>>>add document: 【search_main(" + mainList.size() + "个):" + mainResult + "】" + mainList.toString());
|
|
|
|
+ }
|
|
// 将商品文档推送到阿里云
|
|
// 将商品文档推送到阿里云
|
|
String equipmentDocStr = new JSONArray(equipmentList).toString();
|
|
String equipmentDocStr = new JSONArray(equipmentList).toString();
|
|
String equipmentResult = searchOpenService.pushDocument(equipmentDocStr, "search_equipment");
|
|
String equipmentResult = searchOpenService.pushDocument(equipmentDocStr, "search_equipment");
|
|
- log.info(">>>>>>>>>>>>>>>add document: 【search_equipment(" + equipmentList.size() + "):" + equipmentResult + "】");
|
|
|
|
|
|
+ if (mainList.size()>0) {
|
|
|
|
+ // 新增
|
|
|
|
+ log.info(">>>>>>>>>>>>>>>add document: 【search_equipment(" + equipmentList.size() + "个):" + equipmentResult + "】");
|
|
|
|
+ } else {
|
|
|
|
+ // 更新
|
|
|
|
+ log.info(">>>>>>>>>>>>>>>update document: 【search_equipment(" + equipmentList.size() + "个):" + equipmentResult + "】");
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -1021,14 +1030,22 @@ public class SearchIndexServiceImpl implements SearchIndexService {
|
|
* @throws OpenSearchException exp
|
|
* @throws OpenSearchException exp
|
|
*/
|
|
*/
|
|
private void pushArticleDocument(List<DocumentDTO<MainDO>> mainList, List<DocumentDTO<ArticleDO>> articleList) throws OpenSearchClientException, OpenSearchException {
|
|
private void pushArticleDocument(List<DocumentDTO<MainDO>> mainList, List<DocumentDTO<ArticleDO>> articleList) throws OpenSearchClientException, OpenSearchException {
|
|
- // 将主文档列表转换成Json串,并推送到阿里云
|
|
|
|
- String mainDocStr = new JSONArray(mainList).toString();
|
|
|
|
- String mainResult = searchOpenService.pushDocument(mainDocStr, "search_main");
|
|
|
|
- log.info(">>>>>>>>>>>>>>>add document: 【search_main(" + mainList.size() + "):" + mainResult + "】" + mainList.toString());
|
|
|
|
|
|
+ if (mainList.size()>0) {
|
|
|
|
+ // 将主文档列表转换成Json串,并推送到阿里云
|
|
|
|
+ String mainDocStr = new JSONArray(mainList).toString();
|
|
|
|
+ String mainResult = searchOpenService.pushDocument(mainDocStr, "search_main");
|
|
|
|
+ log.info(">>>>>>>>>>>>>>>add document: 【search_main(" + mainList.size() + "个):" + mainResult + "】" + mainList.toString());
|
|
|
|
+ }
|
|
// 将商品文档推送到阿里云
|
|
// 将商品文档推送到阿里云
|
|
String articleDocStr = new JSONArray(articleList).toString();
|
|
String articleDocStr = new JSONArray(articleList).toString();
|
|
String articleResult = searchOpenService.pushDocument(articleDocStr, "search_article");
|
|
String articleResult = searchOpenService.pushDocument(articleDocStr, "search_article");
|
|
- log.info(">>>>>>>>>>>>>>>add document: 【search_article(" + articleList.size() + "):" + articleResult + "】");
|
|
|
|
|
|
+ if (mainList.size()>0) {
|
|
|
|
+ // 新增
|
|
|
|
+ log.info(">>>>>>>>>>>>>>>add document: 【search_article(" + articleList.size() + "个):" + articleResult + "】");
|
|
|
|
+ } else {
|
|
|
|
+ // 更新
|
|
|
|
+ log.info(">>>>>>>>>>>>>>>update document: 【search_article(" + articleList.size() + "个):" + articleResult + "】");
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|