|
|
package com.yoho.search.consumer.index.increment.productIndex;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.Map;
|
|
|
|
...
|
...
|
@@ -17,7 +16,6 @@ import com.yoho.search.base.utils.ProductIndexEsField; |
|
|
import com.yoho.search.consumer.index.increment.AbstractIndexMqListener;
|
|
|
import com.yoho.search.consumer.service.base.ProductPriceService;
|
|
|
import com.yoho.search.consumer.service.base.ProductService;
|
|
|
import com.yoho.search.consumer.service.bo.ProductPriceBO;
|
|
|
import com.yoho.search.consumer.service.logic.SpecialDealLogicService;
|
|
|
import com.yoho.search.consumer.service.logic.productIndex.viewBuilder.ProductPriceBuilder;
|
|
|
import com.yoho.search.dal.model.Product;
|
...
|
...
|
@@ -75,51 +73,20 @@ public class ProductPriceMqListener extends AbstractIndexMqListener { |
|
|
|
|
|
// 2、更新ProductIndex
|
|
|
begin = System.currentTimeMillis();
|
|
|
Integer productId = productService.selectProductIdBySkn(productPrice.getProductSkn());
|
|
|
this.updateProductIndex(productId, productPrice);
|
|
|
this.updateProductIndex(productPrice.getProductSkn(), productPrice);
|
|
|
logger.info("[func=updateData][step=updateProductIndex][productSkn={}][cost={}ms]", productPrice.getProductSkn(), this.getCost(begin));
|
|
|
}
|
|
|
|
|
|
private double getDoubleFromBigDecimal(BigDecimal bigDecimal) {
|
|
|
if (bigDecimal == null) {
|
|
|
return 0d;
|
|
|
}
|
|
|
return bigDecimal.doubleValue();
|
|
|
}
|
|
|
|
|
|
private void updateProductIndex(Integer productId, ProductPrice pp) {
|
|
|
Map<String, Object> indexData = new HashMap<String, Object>();
|
|
|
|
|
|
// 构造ProductPriceBO
|
|
|
ProductPriceBO productPriceBO = new ProductPriceBO(pp);
|
|
|
productPriceBuilder.buildProductPriceBO(productPriceBO);
|
|
|
indexData.put("productId", productId);
|
|
|
indexData.put("marketPrice", this.getDoubleFromBigDecimal(productPriceBO.getMarketPrice()));
|
|
|
indexData.put("salesPrice", this.getDoubleFromBigDecimal(productPriceBO.getSalesPrice()));
|
|
|
indexData.put("vipPrice", this.getDoubleFromBigDecimal(productPriceBO.getVipPrice()));
|
|
|
indexData.put("vipDiscountType", productPriceBO.getVipDiscountType());
|
|
|
indexData.put("vip1Price", this.getDoubleFromBigDecimal(productPriceBO.getVip1Price()));
|
|
|
indexData.put("vip2Price", this.getDoubleFromBigDecimal(productPriceBO.getVip2Price()));
|
|
|
indexData.put("vip3Price", this.getDoubleFromBigDecimal(productPriceBO.getVip3Price()));
|
|
|
indexData.put("studentPrice", this.getDoubleFromBigDecimal(productPriceBO.getStudentPrice()));
|
|
|
|
|
|
indexData.put("isDiscount", productPriceBO.getIsDiscount());
|
|
|
indexData.put("specialoffer", productPriceBO.getSpecialoffer());
|
|
|
indexData.put("promotionDiscountInt", productPriceBO.getPromotionDiscountInt());
|
|
|
indexData.put("promotionDiscount", this.getDoubleFromBigDecimal(productPriceBO.getPromotionDiscount()));
|
|
|
indexData.put("isStudentPrice", productPriceBO.getIsStudentPrice());
|
|
|
indexData.put("isstudentrebate", productPriceBO.getIsstudentrebate());
|
|
|
indexData.put("vipLevels", productPriceBO.getVipLevels());
|
|
|
indexData.put("priceUpdateTime", productPriceBO.getUpdateTime());
|
|
|
Product product = productService.getById(productId);
|
|
|
if (product != null) {
|
|
|
indexData.put("isnew", productPriceBuilder.isNew(product.getFirstShelveTime(), productPriceBO.getMarketPrice(), productPriceBO.getSalesPrice()));
|
|
|
} else {
|
|
|
indexData.put("isnew", "N");
|
|
|
private void updateProductIndex(Integer productSkn, ProductPrice pp) {
|
|
|
Product product = productService.getBySkn(productSkn);
|
|
|
if (product == null) {
|
|
|
logger.warn("[func=updateData][step=updateProductIndex fail ][product is null ][productSkn is {}]", productSkn);
|
|
|
return;
|
|
|
}
|
|
|
indexData.put(ProductIndexEsField.specialSearchFieldPrice, specialSearchFieldLogicService.getSpecialSearchFieldPrice(productPriceBO));
|
|
|
// 构造增量的建到Pi索引里的数据
|
|
|
Map<String, Object> indexData = productPriceBuilder.getProductPriceModelMap(product.getId(), product.getFirstShelveTime(), pp);
|
|
|
// 更新商品索引
|
|
|
this.updateProductIndexWithDataMap(indexData, productId);
|
|
|
this.updateProductIndexWithDataMap(indexData, product.getId());
|
|
|
}
|
|
|
|
|
|
/**
|
...
|
...
|
@@ -128,14 +95,14 @@ public class ProductPriceMqListener extends AbstractIndexMqListener { |
|
|
private void updateProductIndexByClearPrice(Integer productId) {
|
|
|
Map<String, Object> indexData = new HashMap<String, Object>(30);
|
|
|
indexData.put("productId", productId);
|
|
|
indexData.put("marketPrice", null);
|
|
|
indexData.put("salesPrice", null);
|
|
|
indexData.put("vipPrice", null);
|
|
|
indexData.put("vipDiscountType", null);
|
|
|
indexData.put("vip1Price", null);
|
|
|
indexData.put("vip2Price", null);
|
|
|
indexData.put("vip3Price", null);
|
|
|
indexData.put("studentPrice", null);
|
|
|
indexData.put("marketPrice", 0);
|
|
|
indexData.put("salesPrice", 0);
|
|
|
indexData.put("vipPrice", 0);
|
|
|
indexData.put("vipDiscountType", 0);
|
|
|
indexData.put("vip1Price", 0);
|
|
|
indexData.put("vip2Price", 0);
|
|
|
indexData.put("vip3Price", 0);
|
|
|
indexData.put("studentPrice", 0);
|
|
|
// others
|
|
|
indexData.put("isDiscount", "N");
|
|
|
indexData.put("specialoffer", "N");
|
...
|
...
|
|