|
@@ -23,9 +23,10 @@ import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
+import java.time.LocalDateTime;
|
|
|
+import java.time.temporal.ChronoUnit;
|
|
|
+import java.util.*;
|
|
|
|
|
|
/**
|
|
|
* Description
|
|
@@ -109,7 +110,7 @@ public class SearchIndexServiceImpl implements SearchIndexService {
|
|
|
// 获取最大文档ID
|
|
|
Integer mainId = searchQueryService.getIdByDocId("", null);
|
|
|
mainId = mainId == -1 ? 0 : mainId;
|
|
|
- // 获取推送记录数
|
|
|
+ // 设置商品文档 并返回推送记录数
|
|
|
Integer productRecord = setAllProductData(mainId, productCount, false);
|
|
|
if (productCount > productRecord) {
|
|
|
log.warn("批量添加商品文档异常,部分商品未添加。");
|
|
@@ -210,8 +211,8 @@ public class SearchIndexServiceImpl implements SearchIndexService {
|
|
|
if (promotionIds != null && promotionIds.size() > 0) {
|
|
|
product.setP_promotions_id(promotionIds.get(0));
|
|
|
}
|
|
|
- // 定义星范商品数据
|
|
|
- List<DocumentDTO<MallProductDO>> mallProductList = new ArrayList<>();
|
|
|
+// // 定义星范商品数据
|
|
|
+// List<DocumentDTO<MallProductDO>> mallProductList = new ArrayList<>();
|
|
|
// // 星范商品设值,【必须先于商品文档设值】
|
|
|
// Integer mallId = setMallProductDocument(mallProductList, productId);
|
|
|
// 定义商品文档数据
|
|
@@ -238,7 +239,7 @@ public class SearchIndexServiceImpl implements SearchIndexService {
|
|
|
return updateProductIndexById(productId);
|
|
|
} else {
|
|
|
// 推送到阿里云
|
|
|
- pushProductDocument(mainList, productList, mallProductList);
|
|
|
+ pushProductDocument(mainList, productList/*, mallProductList*/);
|
|
|
// 返回结果
|
|
|
return ResponseJson.success(mainList.size());
|
|
|
}
|
|
@@ -605,8 +606,8 @@ public class SearchIndexServiceImpl implements SearchIndexService {
|
|
|
// 获取数据库商品列表的分页数据
|
|
|
List<ProductDO> dbList = searchMapper.searchProductList();
|
|
|
|
|
|
- // 定义星范商品数据
|
|
|
- List<DocumentDTO<MallProductDO>> mallProductList = new ArrayList<>();
|
|
|
+// // 定义星范商品数据
|
|
|
+// List<DocumentDTO<MallProductDO>> mallProductList = new ArrayList<>();
|
|
|
// 定义商品文档数据
|
|
|
List<DocumentDTO<ProductDO>> productList = new ArrayList<>();
|
|
|
// 定义主文档入口数据
|
|
@@ -640,7 +641,7 @@ public class SearchIndexServiceImpl implements SearchIndexService {
|
|
|
}
|
|
|
try {
|
|
|
// 推送到阿里云
|
|
|
- pushProductDocument(mainList, productList, mallProductList);
|
|
|
+ pushProductDocument(mainList, productList/*, mallProductList*/);
|
|
|
// 添加到返回结果
|
|
|
productRecord += mainList.size();
|
|
|
} catch (OpenSearchClientException | OpenSearchException | JSONException e) {
|
|
@@ -656,11 +657,11 @@ public class SearchIndexServiceImpl implements SearchIndexService {
|
|
|
*
|
|
|
* @param mainList list
|
|
|
* @param productList list
|
|
|
- * @param mallProductList list
|
|
|
+ * // @param mallProductList list
|
|
|
* @throws OpenSearchClientException 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 {
|
|
|
if (mainList.size() > 0) {
|
|
|
// 将主文档列表转换成Json串,并推送到阿里云
|
|
|
String mainDocStr = new JSONArray(mainList).toString();
|
|
@@ -677,12 +678,12 @@ public class SearchIndexServiceImpl implements SearchIndexService {
|
|
|
// 更新
|
|
|
log.info(">>>>>>>>>>>>>>>update document: 【search_product(" + productList.size() + "个):" + productResult + "】");
|
|
|
}
|
|
|
- // 将星范商品推送到阿里云
|
|
|
- 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 + "】");
|
|
|
- }
|
|
|
+// // 将星范商品推送到阿里云
|
|
|
+// 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 + "】");
|
|
|
+// }
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -1087,34 +1088,34 @@ public class SearchIndexServiceImpl implements SearchIndexService {
|
|
|
return docsJsonArr.toString();
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 商品星范商品设值
|
|
|
- *
|
|
|
- * @param mallProductList list
|
|
|
- * @param productId int
|
|
|
- */
|
|
|
- private Integer setMallProductDocument(List<DocumentDTO<MallProductDO>> mallProductList, Integer productId) {
|
|
|
- // 是否是星范商品
|
|
|
- int mallCount = searchMapper.countMallProduct(productId);
|
|
|
- if (mallCount >= 1) {
|
|
|
- MallProductDO mallProduct = searchMapper.searchMallProductByProductId(productId);
|
|
|
- // 是否有阶梯价
|
|
|
- Integer mallLadderFlag = searchMapper.getMallLadderPriceFlag(productId);
|
|
|
- if (mallLadderFlag == 1) {
|
|
|
- // 阶梯价
|
|
|
- Double mallLadderPrice = searchMapper.getMallLowerLadderPrice(productId);
|
|
|
- mallProduct.setM_price(mallLadderPrice);
|
|
|
- }
|
|
|
- mallProduct.setM_all(1);
|
|
|
- // 搜索星范商品数据
|
|
|
- DocumentDTO<MallProductDO> mallProductDoc = new DocumentDTO<>();
|
|
|
- mallProductDoc.setCmd("add");
|
|
|
- mallProductDoc.setFields(mallProduct);
|
|
|
- mallProductList.add(mallProductDoc);
|
|
|
- return mallProduct.getM_id();
|
|
|
- }
|
|
|
- return 0;
|
|
|
- }
|
|
|
+// /**
|
|
|
+// * 商品星范商品设值
|
|
|
+// *
|
|
|
+// * @param mallProductList list
|
|
|
+// * @param productId int
|
|
|
+// */
|
|
|
+// private Integer setMallProductDocument(List<DocumentDTO<MallProductDO>> mallProductList, Integer productId) {
|
|
|
+// // 是否是星范商品
|
|
|
+// int mallCount = searchMapper.countMallProduct(productId);
|
|
|
+// if (mallCount >= 1) {
|
|
|
+// MallProductDO mallProduct = searchMapper.searchMallProductByProductId(productId);
|
|
|
+// // 是否有阶梯价
|
|
|
+// Integer mallLadderFlag = searchMapper.getMallLadderPriceFlag(productId);
|
|
|
+// if (mallLadderFlag == 1) {
|
|
|
+// // 阶梯价
|
|
|
+// Double mallLadderPrice = searchMapper.getMallLowerLadderPrice(productId);
|
|
|
+// mallProduct.setM_price(mallLadderPrice);
|
|
|
+// }
|
|
|
+// mallProduct.setM_all(1);
|
|
|
+// // 搜索星范商品数据
|
|
|
+// DocumentDTO<MallProductDO> mallProductDoc = new DocumentDTO<>();
|
|
|
+// mallProductDoc.setCmd("add");
|
|
|
+// mallProductDoc.setFields(mallProduct);
|
|
|
+// mallProductList.add(mallProductDoc);
|
|
|
+// return mallProduct.getM_id();
|
|
|
+// }
|
|
|
+// return 0;
|
|
|
+// }
|
|
|
|
|
|
/**
|
|
|
* 商品文档设值
|
|
@@ -1131,12 +1132,26 @@ public class SearchIndexServiceImpl implements SearchIndexService {
|
|
|
product.setP_all(1);
|
|
|
// 价格等级
|
|
|
product.setP_price_grade(priceUtilService.getPriceGrade(product.getP_price().doubleValue()));
|
|
|
- DocumentDTO<ProductDO> productDoc = new DocumentDTO<>();
|
|
|
+ // 统计月销量与月访问量
|
|
|
+ Calendar calendar = Calendar.getInstance();
|
|
|
+ calendar.setTime(new Date());
|
|
|
+ calendar.add(Calendar.DAY_OF_MONTH, -30);
|
|
|
+ calendar.set(Calendar.HOUR_OF_DAY, 0);
|
|
|
+ calendar.set(Calendar.MINUTE, 0);
|
|
|
+ calendar.set(Calendar.SECOND, 0);
|
|
|
+ Date countTime = calendar.getTime();
|
|
|
+ // String dateStr = new SimpleDateFormat("yyyy-MM-dd").format(countTime);
|
|
|
+ int views = searchMapper.countViewsByDate(product.getP_id(), countTime);
|
|
|
+ int sales = searchMapper.countSalesByDate(product.getP_id(), countTime);
|
|
|
+ product.setP_sales(sales);
|
|
|
+ product.setP_favorite(views);
|
|
|
// 设促销id
|
|
|
List<Integer> promotionIds = searchMapper.findPromotionId(product.getP_id());
|
|
|
if (promotionIds != null && promotionIds.size() > 0) {
|
|
|
product.setP_promotions_id(promotionIds.get(0));
|
|
|
}
|
|
|
+ // 文档设值
|
|
|
+ DocumentDTO<ProductDO> productDoc = new DocumentDTO<>();
|
|
|
productDoc.setCmd("add");
|
|
|
productDoc.setFields(product);
|
|
|
productList.add(productDoc);
|