|
@@ -8,6 +8,7 @@ import com.aliyun.opensearch.sdk.generated.commons.OpenSearchClientException;
|
|
|
import com.aliyun.opensearch.sdk.generated.commons.OpenSearchException;
|
|
|
import com.aliyun.opensearch.sdk.generated.document.Command;
|
|
|
import com.aliyun.opensearch.sdk.generated.document.DocumentConstants;
|
|
|
+import com.caimei365.commodity.components.PriceUtilService;
|
|
|
import com.caimei365.commodity.components.SearchOpenService;
|
|
|
import com.caimei365.commodity.mapper.SearchMapper;
|
|
|
import com.caimei365.commodity.model.ResponseJson;
|
|
@@ -15,7 +16,6 @@ import com.caimei365.commodity.model.search.*;
|
|
|
import com.caimei365.commodity.service.SearchIndexService;
|
|
|
import com.caimei365.commodity.service.SearchQueryService;
|
|
|
import com.caimei365.commodity.utils.ImageUtils;
|
|
|
-import com.caimei365.commodity.components.PriceUtilService;
|
|
|
import com.github.pagehelper.PageHelper;
|
|
|
import com.github.pagehelper.util.StringUtil;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
@@ -46,6 +46,7 @@ public class SearchIndexServiceImpl implements SearchIndexService {
|
|
|
private SearchQueryService searchQueryService;
|
|
|
@Resource
|
|
|
private PriceUtilService priceUtilService;
|
|
|
+
|
|
|
/**
|
|
|
* 初始化(添加)所有索引
|
|
|
*
|
|
@@ -61,7 +62,7 @@ public class SearchIndexServiceImpl implements SearchIndexService {
|
|
|
if (productCount > productRecord) {
|
|
|
log.warn("【初始化】批量添加商品文档异常,部分商品未添加。");
|
|
|
}
|
|
|
- log.info(">>>>>>【商品】应加:"+productCount+",实加:"+productRecord);
|
|
|
+ log.info(">>>>>>【商品】应加:" + productCount + ",实加:" + productRecord);
|
|
|
mainId += productRecord;
|
|
|
// 从数据库获取供应商数量
|
|
|
Integer supplierCount = searchMapper.findSupplierCount();
|
|
@@ -69,7 +70,7 @@ public class SearchIndexServiceImpl implements SearchIndexService {
|
|
|
if (supplierCount > supplierRecord) {
|
|
|
log.warn("【初始化】批量添加供应商文档异常,部分供应商未添加。");
|
|
|
}
|
|
|
- log.info(">>>>>>【供应商】应加:"+supplierCount+",实加:"+supplierRecord);
|
|
|
+ log.info(">>>>>>【供应商】应加:" + supplierCount + ",实加:" + supplierRecord);
|
|
|
mainId += supplierRecord;
|
|
|
// 从数据库获取项目仪器数量
|
|
|
Integer equipmentCount = searchMapper.findEquipmentCount();
|
|
@@ -77,7 +78,7 @@ public class SearchIndexServiceImpl implements SearchIndexService {
|
|
|
if (equipmentCount > equipmentRecord) {
|
|
|
log.warn("批量添加项目仪器文档异常,部分项目仪器未添加。");
|
|
|
}
|
|
|
- log.info(">>>>>>【项目仪器】应加:"+equipmentCount+",实加:"+equipmentRecord);
|
|
|
+ log.info(">>>>>>【项目仪器】应加:" + equipmentCount + ",实加:" + equipmentRecord);
|
|
|
mainId += equipmentRecord;
|
|
|
// 从数据库获取文章数量
|
|
|
Integer articleCount = searchMapper.findArticleCount();
|
|
@@ -85,7 +86,7 @@ public class SearchIndexServiceImpl implements SearchIndexService {
|
|
|
if (articleCount > articleRecord) {
|
|
|
log.warn("批量添加文章文档异常,部分文章未添加。");
|
|
|
}
|
|
|
- log.info(">>>>>>【文章】应加:"+articleCount+",实加:"+articleRecord);
|
|
|
+ log.info(">>>>>>【文章】应加:" + articleCount + ",实加:" + articleRecord);
|
|
|
mainId += articleRecord;
|
|
|
|
|
|
log.info(">>>>>>>>>>>>添加总记录:" + mainId);
|
|
@@ -94,6 +95,7 @@ public class SearchIndexServiceImpl implements SearchIndexService {
|
|
|
|
|
|
/**
|
|
|
* 更新所有商品
|
|
|
+ *
|
|
|
* @return json
|
|
|
*/
|
|
|
@Override
|
|
@@ -112,12 +114,13 @@ public class SearchIndexServiceImpl implements SearchIndexService {
|
|
|
if (productCount > productRecord) {
|
|
|
log.warn("批量添加商品文档异常,部分商品未添加。");
|
|
|
}
|
|
|
- log.info(">>>>>>【商品】应加:"+productCount+",实加:"+productRecord);
|
|
|
+ log.info(">>>>>>【商品】应加:" + productCount + ",实加:" + productRecord);
|
|
|
return ResponseJson.success(productRecord);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 更新所有供应商
|
|
|
+ *
|
|
|
* @return json
|
|
|
*/
|
|
|
@Override
|
|
@@ -141,6 +144,7 @@ public class SearchIndexServiceImpl implements SearchIndexService {
|
|
|
|
|
|
/**
|
|
|
* 更新所有项目仪器
|
|
|
+ *
|
|
|
* @return json
|
|
|
*/
|
|
|
@Override
|
|
@@ -165,6 +169,7 @@ public class SearchIndexServiceImpl implements SearchIndexService {
|
|
|
|
|
|
/**
|
|
|
* 更新所有文章
|
|
|
+ *
|
|
|
* @return json
|
|
|
*/
|
|
|
@Override
|
|
@@ -188,16 +193,22 @@ public class SearchIndexServiceImpl implements SearchIndexService {
|
|
|
|
|
|
/**
|
|
|
* 根据商品Id更新
|
|
|
+ *
|
|
|
* @param productId int
|
|
|
* @return json
|
|
|
*/
|
|
|
@Override
|
|
|
- public ResponseJson<Integer> updateProductIndexById(Integer productId){
|
|
|
+ public ResponseJson<Integer> updateProductIndexById(Integer productId) {
|
|
|
if (null == productId) {
|
|
|
log.info(">>>更新商品,商品Id不能为空!");
|
|
|
return ResponseJson.error("商品Id不能为空", null);
|
|
|
}
|
|
|
ProductDO product = searchMapper.searchProductById(productId);
|
|
|
+ List<Integer> promotionIds = searchMapper.findPromotionId(product.getP_id());
|
|
|
+ if (promotionIds != null && promotionIds.size() > 0) {
|
|
|
+ product.setP_promotions_id(promotionIds.get(0));
|
|
|
+ }
|
|
|
+ // product p_promotions_id
|
|
|
if (null != product) {
|
|
|
// 定义星范商品数据
|
|
|
List<DocumentDTO<MallProductDO>> mallProductList = new ArrayList<>();
|
|
@@ -213,7 +224,7 @@ public class SearchIndexServiceImpl implements SearchIndexService {
|
|
|
Integer mainId = searchQueryService.getIdByDocId("product", productId);
|
|
|
if (mainId == -1) {
|
|
|
mainId = searchQueryService.getIdByDocId("", null);
|
|
|
- mainId = mainId == -1 ? 0 : mainId+1;
|
|
|
+ mainId = mainId == -1 ? 0 : mainId + 1;
|
|
|
// 新增主文档, 商品:type=1
|
|
|
setMainDocument(1, mainList, mainId, productId);
|
|
|
}
|
|
@@ -221,7 +232,7 @@ public class SearchIndexServiceImpl implements SearchIndexService {
|
|
|
// 查询商品数量是否唯一,不唯一则删除后更新索引
|
|
|
Integer count = searchQueryService.getCountByDocId("product", productId);
|
|
|
if (count > 1) {
|
|
|
- log.info("商品重复,重复商品>>>>>>>>>>>" + productId +"重复数量:" + count);
|
|
|
+ log.info("商品重复,重复商品>>>>>>>>>>>" + productId + "重复数量:" + count);
|
|
|
// 删除主文档记录
|
|
|
deleteDocByTypeId("id", mainId, "search_main");
|
|
|
return updateProductIndexById(productId);
|
|
@@ -253,8 +264,8 @@ public class SearchIndexServiceImpl implements SearchIndexService {
|
|
|
return ResponseJson.error("供应商Id不能为空", null);
|
|
|
}
|
|
|
SupplierDO supplier = searchMapper.searchSupplierById(shopId);
|
|
|
- if(null != supplier){
|
|
|
- // 定义供应商文档数据
|
|
|
+ if (null != supplier) {
|
|
|
+ // 定义供应商文档数据
|
|
|
List<DocumentDTO<SupplierDO>> supplierList = new ArrayList<>();
|
|
|
// 供应商文档设值
|
|
|
setSupplierDocument(supplierList, supplier);
|
|
@@ -264,7 +275,7 @@ public class SearchIndexServiceImpl implements SearchIndexService {
|
|
|
Integer mainId = searchQueryService.getIdByDocId("shop", shopId);
|
|
|
if (mainId == -1) {
|
|
|
mainId = searchQueryService.getIdByDocId("", null);
|
|
|
- mainId = mainId == -1 ? 0 : mainId+1;
|
|
|
+ mainId = mainId == -1 ? 0 : mainId + 1;
|
|
|
// 新增主文档, 供应商:type=2
|
|
|
setMainDocument(2, mainList, mainId, shopId);
|
|
|
}
|
|
@@ -272,7 +283,8 @@ public class SearchIndexServiceImpl implements SearchIndexService {
|
|
|
// 查询供应商是否唯一,不唯一则删除后重新更新索引
|
|
|
Integer count = searchQueryService.getCountByDocId("shop", shopId);
|
|
|
if (count > 1) {
|
|
|
- log.info("供应商重复,重复供应商>>>>>>>>>>>" + shopId +"重复数量:" + count);;
|
|
|
+ log.info("供应商重复,重复供应商>>>>>>>>>>>" + shopId + "重复数量:" + count);
|
|
|
+ ;
|
|
|
// 删除主文档记录
|
|
|
deleteDocByTypeId("id", mainId, "search_main");
|
|
|
return updateSupplierIndexById(shopId);
|
|
@@ -286,7 +298,7 @@ public class SearchIndexServiceImpl implements SearchIndexService {
|
|
|
log.error("添加供应商文档异常:" + e);
|
|
|
return ResponseJson.error("添加供应商文档异常", null);
|
|
|
}
|
|
|
- }else{
|
|
|
+ } else {
|
|
|
return deleteSupplierIndexById(shopId);
|
|
|
}
|
|
|
}
|
|
@@ -304,7 +316,7 @@ public class SearchIndexServiceImpl implements SearchIndexService {
|
|
|
return ResponseJson.error("项目仪器Id不能为空", null);
|
|
|
}
|
|
|
EquipmentDO equipment = searchMapper.searchEquipmentById(equipmentId);
|
|
|
- if(null != equipment){
|
|
|
+ if (null != equipment) {
|
|
|
// 定义项目仪器文档数据
|
|
|
List<DocumentDTO<EquipmentDO>> equipmentList = new ArrayList<>();
|
|
|
// 项目仪器文档设值
|
|
@@ -315,7 +327,7 @@ public class SearchIndexServiceImpl implements SearchIndexService {
|
|
|
Integer mainId = searchQueryService.getIdByDocId("equipment", equipmentId);
|
|
|
if (mainId == -1) {
|
|
|
mainId = searchQueryService.getIdByDocId("", null);
|
|
|
- mainId = mainId == -1 ? 0 : mainId+1;
|
|
|
+ mainId = mainId == -1 ? 0 : mainId + 1;
|
|
|
// 新增主文档, 项目仪器:type=3
|
|
|
setMainDocument(3, mainList, mainId, equipmentId);
|
|
|
}
|
|
@@ -323,7 +335,7 @@ public class SearchIndexServiceImpl implements SearchIndexService {
|
|
|
// 查询项目仪器数量是否唯一,不唯一则删除后重新更新索引
|
|
|
Integer count = searchQueryService.getCountByDocId("equipment", equipmentId);
|
|
|
if (count > 1) {
|
|
|
- log.info("项目仪器重复,重复项目仪器>>>>>>>>>>>" + equipmentId+"重复数量:" + count);
|
|
|
+ log.info("项目仪器重复,重复项目仪器>>>>>>>>>>>" + equipmentId + "重复数量:" + count);
|
|
|
// 删除主文档记录
|
|
|
deleteDocByTypeId("id", mainId, "search_main");
|
|
|
return updateEquipmentIndexById(equipmentId);
|
|
@@ -337,7 +349,7 @@ public class SearchIndexServiceImpl implements SearchIndexService {
|
|
|
log.error("添加项目仪器文档异常:" + e);
|
|
|
return ResponseJson.error("添加项目仪器文档异常", null);
|
|
|
}
|
|
|
- }else{
|
|
|
+ } else {
|
|
|
return deleteEquipmentIndexById(equipmentId);
|
|
|
}
|
|
|
}
|
|
@@ -355,7 +367,7 @@ public class SearchIndexServiceImpl implements SearchIndexService {
|
|
|
return ResponseJson.error("文章Id不能为空", null);
|
|
|
}
|
|
|
ArticleDO article = searchMapper.searchArticleById(articleId);
|
|
|
- if(null != article){
|
|
|
+ if (null != article) {
|
|
|
// 定义文章文档数据
|
|
|
List<DocumentDTO<ArticleDO>> articleList = new ArrayList<>();
|
|
|
// 文章文档设值
|
|
@@ -366,7 +378,7 @@ public class SearchIndexServiceImpl implements SearchIndexService {
|
|
|
Integer mainId = searchQueryService.getIdByDocId("article", articleId);
|
|
|
if (mainId == -1) {
|
|
|
mainId = searchQueryService.getIdByDocId("", null);
|
|
|
- mainId = mainId == -1 ? 0 : mainId+1;
|
|
|
+ mainId = mainId == -1 ? 0 : mainId + 1;
|
|
|
// 新增主文档, 文章 type=4
|
|
|
setMainDocument(4, mainList, mainId, articleId);
|
|
|
}
|
|
@@ -375,7 +387,7 @@ public class SearchIndexServiceImpl implements SearchIndexService {
|
|
|
// 查询文章数量是否唯一,不唯一则删除后重新更新索引
|
|
|
Integer count = searchQueryService.getCountByDocId("article", articleId);
|
|
|
if (count > 1) {
|
|
|
- log.info("文章重复,重复文章>>>>>>>>>>>" + articleId +"重复数量:" + count);
|
|
|
+ log.info("文章重复,重复文章>>>>>>>>>>>" + articleId + "重复数量:" + count);
|
|
|
// 删除主文档记录
|
|
|
deleteDocByTypeId("id", mainId, "search_main");
|
|
|
return updateArticleIndexById(articleId);
|
|
@@ -389,7 +401,7 @@ public class SearchIndexServiceImpl implements SearchIndexService {
|
|
|
log.error("添加文章文档异常:" + e);
|
|
|
return ResponseJson.error("添加文章文档异常", null);
|
|
|
}
|
|
|
- }else{
|
|
|
+ } else {
|
|
|
return deleteArticleIndexById(articleId);
|
|
|
}
|
|
|
}
|
|
@@ -406,7 +418,7 @@ public class SearchIndexServiceImpl implements SearchIndexService {
|
|
|
// 根据商品ID获取星范ID
|
|
|
Integer mallId = searchMapper.findMallIdByProductId(productId);
|
|
|
try {
|
|
|
- if (null != mallId){
|
|
|
+ if (null != mallId) {
|
|
|
deleteDocByTypeId("m_id", mallId, "search_product_mall");
|
|
|
}
|
|
|
deleteDocByTypeId("p_id", productId, "search_product");
|
|
@@ -505,11 +517,12 @@ public class SearchIndexServiceImpl implements SearchIndexService {
|
|
|
|
|
|
/**
|
|
|
* 根据文档类型key与类型Id删除
|
|
|
- * @param type 类型key
|
|
|
- * @param id 类型Id
|
|
|
+ *
|
|
|
+ * @param type 类型key
|
|
|
+ * @param id 类型Id
|
|
|
* @param table 表名
|
|
|
* @throws OpenSearchClientException exp
|
|
|
- * @throws OpenSearchException exp
|
|
|
+ * @throws OpenSearchException exp
|
|
|
*/
|
|
|
private void deleteDocByTypeId(String type, Integer id, String table) throws OpenSearchClientException, OpenSearchException {
|
|
|
// 删除文档只需要设置需删除文档主键值即可
|
|
@@ -519,19 +532,18 @@ public class SearchIndexServiceImpl implements SearchIndexService {
|
|
|
String deleteJsonStr = setDeleteDocument(deleteDoc);
|
|
|
// 推送到阿里云
|
|
|
String deleteResult = searchOpenService.pushDocument(deleteJsonStr, table);
|
|
|
- log.info(">>>>>>>>>>>>>>>delete document: 【"+ table +"("+ type +":" + id + "):" + deleteResult + "】");
|
|
|
+ log.info(">>>>>>>>>>>>>>>delete document: 【" + table + "(" + type + ":" + id + "):" + deleteResult + "】");
|
|
|
}
|
|
|
|
|
|
|
|
|
-
|
|
|
-
|
|
|
/**
|
|
|
* 批量删除失效商品
|
|
|
+ *
|
|
|
* @param invalidCount int
|
|
|
*/
|
|
|
private void batchDeleteProductDoc(Integer invalidCount) {
|
|
|
// 批量推送,每100条推送一次
|
|
|
- int loop = (int)Math.ceil(invalidCount.doubleValue() / 100);
|
|
|
+ int loop = (int) Math.ceil(invalidCount.doubleValue() / 100);
|
|
|
// 定义返回结果
|
|
|
for (int i = 1; i <= loop; i++) {
|
|
|
PageHelper.startPage(i, 100);
|
|
@@ -551,7 +563,7 @@ public class SearchIndexServiceImpl implements SearchIndexService {
|
|
|
// 根据ID(主键)删除文档
|
|
|
deleteDoc.put("p_id", invalidId);
|
|
|
Integer mainId = searchQueryService.getIdByDocId("product", invalidId);
|
|
|
- if (mainId > -1){
|
|
|
+ if (mainId > -1) {
|
|
|
deleteDoc.put("id", mainId);
|
|
|
}
|
|
|
}
|
|
@@ -568,18 +580,19 @@ public class SearchIndexServiceImpl implements SearchIndexService {
|
|
|
|
|
|
/**
|
|
|
* 设置所有商品数据
|
|
|
- * @param mainId int
|
|
|
+ *
|
|
|
+ * @param mainId int
|
|
|
* @param productCount int
|
|
|
- * @param initFlag int
|
|
|
+ * @param initFlag int
|
|
|
* @return int
|
|
|
*/
|
|
|
private Integer setAllProductData(Integer mainId, Integer productCount, boolean initFlag) {
|
|
|
// 批量推送,每100条推送一次
|
|
|
- int loop = (int)Math.ceil(productCount.doubleValue() / 100);
|
|
|
+ int loop = (int) Math.ceil(productCount.doubleValue() / 100);
|
|
|
Map<Integer, Integer> idsMap = Maps.newLinkedHashMap();
|
|
|
if (!initFlag) {
|
|
|
Integer record = searchQueryService.getRecordByDocType("product");
|
|
|
- int l = (int)Math.ceil(record.doubleValue() / 500);
|
|
|
+ int l = (int) Math.ceil(record.doubleValue() / 500);
|
|
|
for (int i = 1; i <= l; i++) {
|
|
|
Map<Integer, Integer> idsTemp = searchQueryService.getMainIdsByDocType("product", i, 500);
|
|
|
idsMap.putAll(idsTemp);
|
|
@@ -591,6 +604,7 @@ public class SearchIndexServiceImpl implements SearchIndexService {
|
|
|
PageHelper.startPage(i, 100);
|
|
|
// 获取数据库商品列表的分页数据
|
|
|
List<ProductDO> dbList = searchMapper.searchProductList();
|
|
|
+
|
|
|
// 定义星范商品数据
|
|
|
List<DocumentDTO<MallProductDO>> mallProductList = new ArrayList<>();
|
|
|
// 定义商品文档数据
|
|
@@ -606,19 +620,19 @@ public class SearchIndexServiceImpl implements SearchIndexService {
|
|
|
setProductDocument(productList, product, null);
|
|
|
// 主文档设值
|
|
|
Integer productId = product.getP_id();
|
|
|
- if(initFlag){
|
|
|
- productMainId = mainId+1;
|
|
|
- mainId+=1;
|
|
|
- }else{
|
|
|
+ if (initFlag) {
|
|
|
+ productMainId = mainId + 1;
|
|
|
+ mainId += 1;
|
|
|
+ } else {
|
|
|
Integer tempId = idsMap.get(productId);
|
|
|
- if (null==tempId || tempId<=0){
|
|
|
+ if (null == tempId || tempId <= 0) {
|
|
|
tempId = searchQueryService.getIdByDocId("product", productId);
|
|
|
}
|
|
|
- if (null!=tempId && tempId>0) {
|
|
|
+ if (null != tempId && tempId > 0) {
|
|
|
productMainId = tempId;
|
|
|
- }else{
|
|
|
- productMainId = mainId+1;
|
|
|
- mainId+=1;
|
|
|
+ } else {
|
|
|
+ productMainId = mainId + 1;
|
|
|
+ mainId += 1;
|
|
|
}
|
|
|
}
|
|
|
// 商品文档 type=1
|
|
@@ -639,14 +653,15 @@ public class SearchIndexServiceImpl implements SearchIndexService {
|
|
|
|
|
|
/**
|
|
|
* 推送所有商品
|
|
|
- * @param mainList list
|
|
|
- * @param productList list
|
|
|
+ *
|
|
|
+ * @param mainList list
|
|
|
+ * @param productList list
|
|
|
* @param mallProductList list
|
|
|
* @throws OpenSearchClientException exp
|
|
|
- * @throws OpenSearchException exp
|
|
|
+ * @throws OpenSearchException exp
|
|
|
*/
|
|
|
private void pushProductDocument(List<DocumentDTO<MainDO>> mainList, List<DocumentDTO<ProductDO>> productList, List<DocumentDTO<MallProductDO>> mallProductList) throws OpenSearchClientException, OpenSearchException {
|
|
|
- if (mainList.size()>0) {
|
|
|
+ if (mainList.size() > 0) {
|
|
|
// 将主文档列表转换成Json串,并推送到阿里云
|
|
|
String mainDocStr = new JSONArray(mainList).toString();
|
|
|
String mainResult = searchOpenService.pushDocument(mainDocStr, "search_main");
|
|
@@ -655,7 +670,7 @@ public class SearchIndexServiceImpl implements SearchIndexService {
|
|
|
// 将商品文档推送到阿里云
|
|
|
String productDocStr = new JSONArray(productList).toString();
|
|
|
String productResult = searchOpenService.pushDocument(productDocStr, "search_product");
|
|
|
- if (mainList.size()>0) {
|
|
|
+ if (mainList.size() > 0) {
|
|
|
// 新增
|
|
|
log.info(">>>>>>>>>>>>>>>add document: 【search_product(" + productList.size() + "个):" + productResult + "】");
|
|
|
} else {
|
|
@@ -663,7 +678,7 @@ public class SearchIndexServiceImpl implements SearchIndexService {
|
|
|
log.info(">>>>>>>>>>>>>>>update document: 【search_product(" + productList.size() + "个):" + productResult + "】");
|
|
|
}
|
|
|
// 将星范商品推送到阿里云
|
|
|
- if (mallProductList.size()>0) {
|
|
|
+ if (mallProductList.size() > 0) {
|
|
|
String mallProductStr = new JSONArray(mallProductList).toString();
|
|
|
String mallProductResult = searchOpenService.pushDocument(mallProductStr, "search_product_mall");
|
|
|
log.info(">>>>>>>>>>>>>>>add document: 【search_product_mall(" + mallProductList.size() + "):" + mallProductResult + "】");
|
|
@@ -672,11 +687,12 @@ public class SearchIndexServiceImpl implements SearchIndexService {
|
|
|
|
|
|
/**
|
|
|
* 批量删除失效供应商
|
|
|
+ *
|
|
|
* @param invalidCount int
|
|
|
*/
|
|
|
private void batchDeleteSupplierDoc(Integer invalidCount) {
|
|
|
// 批量推送,每100条推送一次
|
|
|
- int loop = (int)Math.ceil(invalidCount.doubleValue() / 100);
|
|
|
+ int loop = (int) Math.ceil(invalidCount.doubleValue() / 100);
|
|
|
// 定义返回结果
|
|
|
for (int i = 1; i <= loop; i++) {
|
|
|
PageHelper.startPage(i, 100);
|
|
@@ -688,7 +704,7 @@ public class SearchIndexServiceImpl implements SearchIndexService {
|
|
|
// 根据ID(主键)删除文档
|
|
|
deleteDoc.put("s_id", invalidId);
|
|
|
Integer mainId = searchQueryService.getIdByDocId("shop", invalidId);
|
|
|
- if (mainId > -1){
|
|
|
+ if (mainId > -1) {
|
|
|
deleteDoc.put("id", mainId);
|
|
|
}
|
|
|
}
|
|
@@ -705,18 +721,19 @@ public class SearchIndexServiceImpl implements SearchIndexService {
|
|
|
|
|
|
/**
|
|
|
* 设置所有供应商数据
|
|
|
- * @param mainId int
|
|
|
+ *
|
|
|
+ * @param mainId int
|
|
|
* @param supplierCount int
|
|
|
- * @param initFlag int
|
|
|
+ * @param initFlag int
|
|
|
* @return int
|
|
|
*/
|
|
|
private Integer setAllSupplierData(Integer mainId, Integer supplierCount, boolean initFlag) {
|
|
|
// 批量推送,每100条推送一次
|
|
|
- int loop = (int)Math.ceil(supplierCount.doubleValue() / 100);
|
|
|
+ int loop = (int) Math.ceil(supplierCount.doubleValue() / 100);
|
|
|
Map<Integer, Integer> idsMap = Maps.newLinkedHashMap();
|
|
|
if (!initFlag) {
|
|
|
Integer record = searchQueryService.getRecordByDocType("shop");
|
|
|
- int l = (int)Math.ceil(record.doubleValue() / 500);
|
|
|
+ int l = (int) Math.ceil(record.doubleValue() / 500);
|
|
|
for (int i = 1; i <= l; i++) {
|
|
|
Map<Integer, Integer> idsTemp = searchQueryService.getMainIdsByDocType("shop", i, 500);
|
|
|
idsMap.putAll(idsTemp);
|
|
@@ -734,24 +751,24 @@ public class SearchIndexServiceImpl implements SearchIndexService {
|
|
|
List<DocumentDTO<MainDO>> mainList = new ArrayList<>();
|
|
|
|
|
|
int supplierMainId;
|
|
|
- for (SupplierDO supplier: dbList){
|
|
|
+ for (SupplierDO supplier : dbList) {
|
|
|
// 供应商文档设值
|
|
|
setSupplierDocument(supplierList, supplier);
|
|
|
// 主文档设值
|
|
|
Integer shopId = supplier.getS_id();
|
|
|
- if(initFlag){
|
|
|
- supplierMainId = mainId+1;
|
|
|
- mainId+=1;
|
|
|
- }else{
|
|
|
+ if (initFlag) {
|
|
|
+ supplierMainId = mainId + 1;
|
|
|
+ mainId += 1;
|
|
|
+ } else {
|
|
|
Integer tempId = idsMap.get(shopId);
|
|
|
- if (null==tempId || tempId<=0){
|
|
|
+ if (null == tempId || tempId <= 0) {
|
|
|
tempId = searchQueryService.getIdByDocId("shop", shopId);
|
|
|
}
|
|
|
- if (null!=tempId && tempId>0) {
|
|
|
+ if (null != tempId && tempId > 0) {
|
|
|
supplierMainId = tempId;
|
|
|
- }else{
|
|
|
- supplierMainId = mainId+1;
|
|
|
- mainId+=1;
|
|
|
+ } else {
|
|
|
+ supplierMainId = mainId + 1;
|
|
|
+ mainId += 1;
|
|
|
}
|
|
|
}
|
|
|
// 供应商文档 type=2
|
|
@@ -772,13 +789,14 @@ public class SearchIndexServiceImpl implements SearchIndexService {
|
|
|
|
|
|
/**
|
|
|
* 推送所有供应商
|
|
|
- * @param mainList list
|
|
|
+ *
|
|
|
+ * @param mainList list
|
|
|
* @param supplierList list
|
|
|
* @throws OpenSearchClientException exp
|
|
|
- * @throws OpenSearchException exp
|
|
|
+ * @throws OpenSearchException exp
|
|
|
*/
|
|
|
private void pushSupplierDocument(List<DocumentDTO<MainDO>> mainList, List<DocumentDTO<SupplierDO>> supplierList) throws OpenSearchClientException, OpenSearchException {
|
|
|
- if (mainList.size()>0) {
|
|
|
+ if (mainList.size() > 0) {
|
|
|
// 将主文档列表转换成Json串,并推送到阿里云
|
|
|
String mainDocStr = new JSONArray(mainList).toString();
|
|
|
String mainResult = searchOpenService.pushDocument(mainDocStr, "search_main");
|
|
@@ -787,7 +805,7 @@ public class SearchIndexServiceImpl implements SearchIndexService {
|
|
|
// 将商品文档推送到阿里云
|
|
|
String supplierDocStr = new JSONArray(supplierList).toString();
|
|
|
String supplierResult = searchOpenService.pushDocument(supplierDocStr, "search_supplier");
|
|
|
- if (mainList.size()>0) {
|
|
|
+ if (mainList.size() > 0) {
|
|
|
// 新增
|
|
|
log.info(">>>>>>>>>>>>>>>add document: 【search_supplier(" + supplierList.size() + "个):" + supplierResult + "】");
|
|
|
} else {
|
|
@@ -798,11 +816,12 @@ public class SearchIndexServiceImpl implements SearchIndexService {
|
|
|
|
|
|
/**
|
|
|
* 批量删除失效项目仪器
|
|
|
+ *
|
|
|
* @param invalidCount int
|
|
|
*/
|
|
|
private void batchDeleteEquipmentDoc(Integer invalidCount) {
|
|
|
// 批量推送,每100条推送一次
|
|
|
- int loop = (int)Math.ceil(invalidCount.doubleValue() / 100);
|
|
|
+ int loop = (int) Math.ceil(invalidCount.doubleValue() / 100);
|
|
|
// 定义返回结果
|
|
|
for (int i = 1; i <= loop; i++) {
|
|
|
PageHelper.startPage(i, 100);
|
|
@@ -814,7 +833,7 @@ public class SearchIndexServiceImpl implements SearchIndexService {
|
|
|
// 根据ID(主键)删除文档
|
|
|
deleteDoc.put("e_id", invalidId);
|
|
|
Integer mainId = searchQueryService.getIdByDocId("equipment", invalidId);
|
|
|
- if (mainId > -1){
|
|
|
+ if (mainId > -1) {
|
|
|
deleteDoc.put("id", mainId);
|
|
|
}
|
|
|
}
|
|
@@ -831,18 +850,19 @@ public class SearchIndexServiceImpl implements SearchIndexService {
|
|
|
|
|
|
/**
|
|
|
* 设置所有项目仪器数据
|
|
|
- * @param mainId int
|
|
|
+ *
|
|
|
+ * @param mainId int
|
|
|
* @param equipmentCount int
|
|
|
- * @param initFlag int
|
|
|
+ * @param initFlag int
|
|
|
* @return int
|
|
|
*/
|
|
|
private Integer setAllEquipmentData(Integer mainId, Integer equipmentCount, boolean initFlag) {
|
|
|
// 批量推送,每100条推送一次
|
|
|
- int loop = (int)Math.ceil(equipmentCount.doubleValue() / 100);
|
|
|
+ int loop = (int) Math.ceil(equipmentCount.doubleValue() / 100);
|
|
|
Map<Integer, Integer> idsMap = Maps.newLinkedHashMap();
|
|
|
if (!initFlag) {
|
|
|
Integer record = searchQueryService.getRecordByDocType("equipment");
|
|
|
- int l = (int)Math.ceil(record.doubleValue() / 500);
|
|
|
+ int l = (int) Math.ceil(record.doubleValue() / 500);
|
|
|
for (int i = 1; i <= l; i++) {
|
|
|
Map<Integer, Integer> idsTemp = searchQueryService.getMainIdsByDocType("equipment", i, 500);
|
|
|
idsMap.putAll(idsTemp);
|
|
@@ -860,24 +880,24 @@ public class SearchIndexServiceImpl implements SearchIndexService {
|
|
|
List<DocumentDTO<MainDO>> mainList = new ArrayList<>();
|
|
|
|
|
|
int equipmentMainId;
|
|
|
- for (EquipmentDO equipment: dbList){
|
|
|
+ for (EquipmentDO equipment : dbList) {
|
|
|
// 项目仪器文档设值
|
|
|
setEquipmentDocument(equipmentList, equipment);
|
|
|
// 主文档设值
|
|
|
Integer equipmentId = equipment.getE_id();
|
|
|
- if(initFlag){
|
|
|
- equipmentMainId = mainId+1;
|
|
|
- mainId+=1;
|
|
|
- }else{
|
|
|
+ if (initFlag) {
|
|
|
+ equipmentMainId = mainId + 1;
|
|
|
+ mainId += 1;
|
|
|
+ } else {
|
|
|
Integer tempId = idsMap.get(equipmentId);
|
|
|
- if (null==tempId || tempId<=0){
|
|
|
+ if (null == tempId || tempId <= 0) {
|
|
|
tempId = searchQueryService.getIdByDocId("equipment", equipmentId);
|
|
|
}
|
|
|
- if (null!=tempId && tempId>0) {
|
|
|
+ if (null != tempId && tempId > 0) {
|
|
|
equipmentMainId = tempId;
|
|
|
- }else{
|
|
|
- equipmentMainId = mainId+1;
|
|
|
- mainId+=1;
|
|
|
+ } else {
|
|
|
+ equipmentMainId = mainId + 1;
|
|
|
+ mainId += 1;
|
|
|
}
|
|
|
}
|
|
|
// 项目仪器文档 type=3
|
|
@@ -898,13 +918,14 @@ public class SearchIndexServiceImpl implements SearchIndexService {
|
|
|
|
|
|
/**
|
|
|
* 推送所有项目仪器
|
|
|
- * @param mainList list
|
|
|
+ *
|
|
|
+ * @param mainList list
|
|
|
* @param equipmentList list
|
|
|
* @throws OpenSearchClientException exp
|
|
|
- * @throws OpenSearchException exp
|
|
|
+ * @throws OpenSearchException exp
|
|
|
*/
|
|
|
private void pushEquipmentDocument(List<DocumentDTO<MainDO>> mainList, List<DocumentDTO<EquipmentDO>> equipmentList) throws OpenSearchClientException, OpenSearchException {
|
|
|
- if (mainList.size()>0) {
|
|
|
+ if (mainList.size() > 0) {
|
|
|
// 将主文档列表转换成Json串,并推送到阿里云
|
|
|
String mainDocStr = new JSONArray(mainList).toString();
|
|
|
String mainResult = searchOpenService.pushDocument(mainDocStr, "search_main");
|
|
@@ -913,7 +934,7 @@ public class SearchIndexServiceImpl implements SearchIndexService {
|
|
|
// 将商品文档推送到阿里云
|
|
|
String equipmentDocStr = new JSONArray(equipmentList).toString();
|
|
|
String equipmentResult = searchOpenService.pushDocument(equipmentDocStr, "search_equipment");
|
|
|
- if (mainList.size()>0) {
|
|
|
+ if (mainList.size() > 0) {
|
|
|
// 新增
|
|
|
log.info(">>>>>>>>>>>>>>>add document: 【search_equipment(" + equipmentList.size() + "个):" + equipmentResult + "】");
|
|
|
} else {
|
|
@@ -924,11 +945,12 @@ public class SearchIndexServiceImpl implements SearchIndexService {
|
|
|
|
|
|
/**
|
|
|
* 批量删除失效文章
|
|
|
+ *
|
|
|
* @param invalidCount int
|
|
|
*/
|
|
|
private void batchDeleteArticleDoc(Integer invalidCount) {
|
|
|
// 批量推送,每100条推送一次
|
|
|
- int loop = (int)Math.ceil(invalidCount.doubleValue() / 100);
|
|
|
+ int loop = (int) Math.ceil(invalidCount.doubleValue() / 100);
|
|
|
// 定义返回结果
|
|
|
for (int i = 1; i <= loop; i++) {
|
|
|
PageHelper.startPage(i, 100);
|
|
@@ -940,7 +962,7 @@ public class SearchIndexServiceImpl implements SearchIndexService {
|
|
|
// 根据ID(主键)删除文档
|
|
|
deleteDoc.put("a_id", invalidId);
|
|
|
Integer mainId = searchQueryService.getIdByDocId("article", invalidId);
|
|
|
- if (mainId > -1){
|
|
|
+ if (mainId > -1) {
|
|
|
deleteDoc.put("id", mainId);
|
|
|
}
|
|
|
}
|
|
@@ -957,18 +979,19 @@ public class SearchIndexServiceImpl implements SearchIndexService {
|
|
|
|
|
|
/**
|
|
|
* 设置所有文章数据
|
|
|
- * @param mainId int
|
|
|
+ *
|
|
|
+ * @param mainId int
|
|
|
* @param articleCount int
|
|
|
- * @param initFlag int
|
|
|
+ * @param initFlag int
|
|
|
* @return int
|
|
|
*/
|
|
|
private Integer setAllArticleData(Integer mainId, Integer articleCount, boolean initFlag) {
|
|
|
// 批量推送,每100条推送一次
|
|
|
- int loop = (int)Math.ceil(articleCount.doubleValue() / 100);
|
|
|
+ int loop = (int) Math.ceil(articleCount.doubleValue() / 100);
|
|
|
Map<Integer, Integer> idsMap = Maps.newLinkedHashMap();
|
|
|
if (!initFlag) {
|
|
|
Integer record = searchQueryService.getRecordByDocType("article");
|
|
|
- int l = (int)Math.ceil(record.doubleValue() / 500);
|
|
|
+ int l = (int) Math.ceil(record.doubleValue() / 500);
|
|
|
for (int i = 1; i <= l; i++) {
|
|
|
Map<Integer, Integer> idsTemp = searchQueryService.getMainIdsByDocType("article", i, 500);
|
|
|
idsMap.putAll(idsTemp);
|
|
@@ -986,24 +1009,24 @@ public class SearchIndexServiceImpl implements SearchIndexService {
|
|
|
List<DocumentDTO<MainDO>> mainList = new ArrayList<>();
|
|
|
|
|
|
int articleMainId;
|
|
|
- for (ArticleDO article: dbList){
|
|
|
+ for (ArticleDO article : dbList) {
|
|
|
// 文章文档设值
|
|
|
setArticleDocument(articleList, article);
|
|
|
// 主文档设值
|
|
|
Integer articleId = article.getA_id();
|
|
|
- if(initFlag){
|
|
|
- articleMainId = mainId+1;
|
|
|
- mainId+=1;
|
|
|
- }else{
|
|
|
+ if (initFlag) {
|
|
|
+ articleMainId = mainId + 1;
|
|
|
+ mainId += 1;
|
|
|
+ } else {
|
|
|
Integer tempId = idsMap.get(articleId);
|
|
|
- if (null==tempId || tempId<=0){
|
|
|
+ if (null == tempId || tempId <= 0) {
|
|
|
tempId = searchQueryService.getIdByDocId("article", articleId);
|
|
|
}
|
|
|
- if (null!=tempId && tempId>0) {
|
|
|
+ if (null != tempId && tempId > 0) {
|
|
|
articleMainId = tempId;
|
|
|
- }else{
|
|
|
- articleMainId = mainId+1;
|
|
|
- mainId+=1;
|
|
|
+ } else {
|
|
|
+ articleMainId = mainId + 1;
|
|
|
+ mainId += 1;
|
|
|
}
|
|
|
}
|
|
|
// 文章文档 type=4
|
|
@@ -1024,13 +1047,14 @@ public class SearchIndexServiceImpl implements SearchIndexService {
|
|
|
|
|
|
/**
|
|
|
* 推送所有文章数据
|
|
|
- * @param mainList list
|
|
|
+ *
|
|
|
+ * @param mainList list
|
|
|
* @param articleList list
|
|
|
* @throws OpenSearchClientException exp
|
|
|
- * @throws OpenSearchException exp
|
|
|
+ * @throws OpenSearchException exp
|
|
|
*/
|
|
|
private void pushArticleDocument(List<DocumentDTO<MainDO>> mainList, List<DocumentDTO<ArticleDO>> articleList) throws OpenSearchClientException, OpenSearchException {
|
|
|
- if (mainList.size()>0) {
|
|
|
+ if (mainList.size() > 0) {
|
|
|
// 将主文档列表转换成Json串,并推送到阿里云
|
|
|
String mainDocStr = new JSONArray(mainList).toString();
|
|
|
String mainResult = searchOpenService.pushDocument(mainDocStr, "search_main");
|
|
@@ -1039,7 +1063,7 @@ public class SearchIndexServiceImpl implements SearchIndexService {
|
|
|
// 将商品文档推送到阿里云
|
|
|
String articleDocStr = new JSONArray(articleList).toString();
|
|
|
String articleResult = searchOpenService.pushDocument(articleDocStr, "search_article");
|
|
|
- if (mainList.size()>0) {
|
|
|
+ if (mainList.size() > 0) {
|
|
|
// 新增
|
|
|
log.info(">>>>>>>>>>>>>>>add document: 【search_article(" + articleList.size() + "个):" + articleResult + "】");
|
|
|
} else {
|
|
@@ -1050,6 +1074,7 @@ public class SearchIndexServiceImpl implements SearchIndexService {
|
|
|
|
|
|
/**
|
|
|
* 删除文档设值
|
|
|
+ *
|
|
|
* @return docsJson
|
|
|
*/
|
|
|
private String setDeleteDocument(Map<String, Object> deleteDoc) {
|
|
@@ -1066,7 +1091,7 @@ public class SearchIndexServiceImpl implements SearchIndexService {
|
|
|
* 商品星范商品设值
|
|
|
*
|
|
|
* @param mallProductList list
|
|
|
- * @param productId int
|
|
|
+ * @param productId int
|
|
|
*/
|
|
|
private Integer setMallProductDocument(List<DocumentDTO<MallProductDO>> mallProductList, Integer productId) {
|
|
|
// 是否是星范商品
|
|
@@ -1093,9 +1118,10 @@ public class SearchIndexServiceImpl implements SearchIndexService {
|
|
|
|
|
|
/**
|
|
|
* 商品文档设值
|
|
|
- * @param productList list
|
|
|
- * @param product ProductDO
|
|
|
- * @param mallId int
|
|
|
+ *
|
|
|
+ * @param productList list
|
|
|
+ * @param product ProductDO
|
|
|
+ * @param mallId int
|
|
|
*/
|
|
|
private void setProductDocument(List<DocumentDTO<ProductDO>> productList, ProductDO product, Integer mallId) {
|
|
|
String imagePath = ImageUtils.getImageURL("product", product.getP_image(), 0, domain);
|
|
@@ -1106,6 +1132,11 @@ public class SearchIndexServiceImpl implements SearchIndexService {
|
|
|
// 价格等级
|
|
|
product.setP_price_grade(priceUtilService.getPriceGrade(product.getP_price().doubleValue()));
|
|
|
DocumentDTO<ProductDO> productDoc = new DocumentDTO<>();
|
|
|
+ // 设促销id
|
|
|
+ List<Integer> promotionIds = searchMapper.findPromotionId(product.getP_id());
|
|
|
+ if (promotionIds != null && promotionIds.size() > 0) {
|
|
|
+ product.setP_promotions_id(promotionIds.get(0));
|
|
|
+ }
|
|
|
productDoc.setCmd("add");
|
|
|
productDoc.setFields(product);
|
|
|
productList.add(productDoc);
|
|
@@ -1115,7 +1146,7 @@ public class SearchIndexServiceImpl implements SearchIndexService {
|
|
|
* 供应商文档设值
|
|
|
*
|
|
|
* @param supplierList list
|
|
|
- * @param supplier supplierDO
|
|
|
+ * @param supplier supplierDO
|
|
|
*/
|
|
|
private void setSupplierDocument(List<DocumentDTO<SupplierDO>> supplierList, SupplierDO supplier) {
|
|
|
String imagePath = ImageUtils.getImageURL("supplierLogo", supplier.getS_logo(), 0, domain);
|
|
@@ -1132,7 +1163,7 @@ public class SearchIndexServiceImpl implements SearchIndexService {
|
|
|
* 项目仪器文档设值
|
|
|
*
|
|
|
* @param equipmentList list
|
|
|
- * @param equipment EquipmentDO
|
|
|
+ * @param equipment EquipmentDO
|
|
|
*/
|
|
|
private void setEquipmentDocument(List<DocumentDTO<EquipmentDO>> equipmentList, EquipmentDO equipment) {
|
|
|
// 搜索供应商文档数据
|
|
@@ -1147,15 +1178,15 @@ public class SearchIndexServiceImpl implements SearchIndexService {
|
|
|
* 文章文档设值
|
|
|
*
|
|
|
* @param articleList list
|
|
|
- * @param article ArticleDO
|
|
|
+ * @param article ArticleDO
|
|
|
*/
|
|
|
private void setArticleDocument(List<DocumentDTO<ArticleDO>> articleList, ArticleDO article) {
|
|
|
String imagePath = ImageUtils.getImageURL("", article.getA_image(), 0, domain);
|
|
|
// 搜索供应商文档数据
|
|
|
String[] labelTexts = article.getA_label().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);
|
|
|
Integer[] labelIds = labelIdList.toArray(new Integer[labelTexts.length]);
|
|
|
article.setA_label_text(labelTexts);
|
|
@@ -1174,8 +1205,8 @@ public class SearchIndexServiceImpl implements SearchIndexService {
|
|
|
* 商品主文档设值
|
|
|
*
|
|
|
* @param mainList list
|
|
|
- * @param mainId int
|
|
|
- * @param docId int
|
|
|
+ * @param mainId int
|
|
|
+ * @param docId int
|
|
|
*/
|
|
|
private void setMainDocument(Integer type, List<DocumentDTO<MainDO>> mainList, Integer mainId, Integer docId) {
|
|
|
// 搜索主文档数据
|