Authored by unknown

fix

... ... @@ -20,6 +20,7 @@ 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;
import com.yoho.search.dal.model.ProductPrice;
import com.yoho.search.dal.model.ProductPriceHistory;
@Component
public class ProductPriceMqListener extends AbstractIndexMqListener {
... ... @@ -84,7 +85,8 @@ public class ProductPriceMqListener extends AbstractIndexMqListener {
return;
}
// 构造增量的建到Pi索引里的数据
Map<String, Object> indexData = productPriceBuilder.getProductPriceModelMap(product.getId(), product.getFirstShelveTime(), pp);
ProductPriceHistory productPriceHistory = productPriceService.selectProductPriceHistory(productSkn);
Map<String, Object> indexData = productPriceBuilder.getProductPriceModelMap(product.getId(), product.getFirstShelveTime(), pp,productPriceHistory);
// 更新商品索引
this.updateProductIndexWithDataMap(indexData, product.getId());
}
... ...
... ... @@ -4,13 +4,13 @@ import com.yoho.search.dal.ProductPriceHistoryMapper;
import com.yoho.search.dal.ProductPriceMapper;
import com.yoho.search.dal.model.ProductPrice;
import com.yoho.search.dal.model.ProductPriceHistory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.List;
@Component
//@Transactional
public class ProductPriceService {
@Autowired
... ... @@ -32,6 +32,7 @@ public class ProductPriceService {
public int saveOrUpdate(ProductPrice productPrice) {
int affect = 0;
ProductPrice oldProductPrice = productPriceMapper.selectByPrimaryKey(productPrice.getProductSkn());
if (productPrice.getProductSkn() == null || oldProductPrice == null) {
affect = productPriceMapper.insert(productPrice);
... ... @@ -56,4 +57,17 @@ public class ProductPriceService {
public int count() {
return productPriceMapper.selectCount();
}
public List<ProductPrice> getProductPrices(List<Integer> sknList){
return productPriceMapper.selectBySknList(sknList);
}
public ProductPriceHistory selectProductPriceHistory(Integer skn) {
return productPriceHistoryMapper.selectByPrimaryKey(skn);
}
public List<ProductPriceHistory> selectProductPriceHistorys(List<Integer> sknList) {
// TODO
return null;
}
}
... ...
... ... @@ -9,8 +9,6 @@ import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import com.yoho.search.dal.ProductPriceHistoryMapper;
import com.yoho.search.dal.model.ProductPriceHistory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
... ... @@ -19,12 +17,13 @@ import org.springframework.stereotype.Component;
import com.yoho.search.base.utils.DateUtil;
import com.yoho.search.base.utils.MathUtils;
import com.yoho.search.base.utils.ProductIndexEsField;
import com.yoho.search.consumer.service.base.ProductPriceService;
import com.yoho.search.consumer.service.bo.ProductIndexBO;
import com.yoho.search.consumer.service.bo.ProductPriceBO;
import com.yoho.search.consumer.service.logic.SpecialDealLogicService;
import com.yoho.search.consumer.service.logic.VipPriceLogicService;
import com.yoho.search.dal.ProductPriceMapper;
import com.yoho.search.dal.model.ProductPrice;
import com.yoho.search.dal.model.ProductPriceHistory;
/**
* Created by wangnan on 2017/1/6.
... ... @@ -33,20 +32,21 @@ import com.yoho.search.dal.model.ProductPrice;
public class ProductPriceBuilder implements ViewBuilder {
private final Logger logger = LoggerFactory.getLogger(ProductPriceBuilder.class);
@Autowired
private ProductPriceMapper productPriceMapper;
@Autowired
private ProductPriceHistoryMapper productPriceHistoryMapper;
private ProductPriceService productPriceService;
@Autowired
private VipPriceLogicService vipPriceLogicService;
@Autowired
private SpecialDealLogicService specialSearchFieldLogicService;
@Override
public void build(List<ProductIndexBO> productIndexBOs, List<Integer> ids, List<Integer> sknList) {
List<ProductPrice> productPrices = productPriceMapper.selectBySknList(sknList);
List<ProductPrice> productPrices = productPriceService.getProductPrices(sknList);
Map<Integer, ProductPrice> productPricesMap = productPrices.stream().collect(Collectors.toMap(ProductPrice::getProductSkn, (p) -> p));
List<ProductPriceHistory> productPriceHistorys = productPriceService.selectProductPriceHistorys(sknList);
Map<Integer, ProductPriceHistory> productPriceHistoryMap = productPriceHistorys.stream().collect(Collectors.toMap(ProductPriceHistory::getProductSkn, (p) -> p));
for (ProductIndexBO productIndexBO : productIndexBOs) {
try {
// 如果该skn对应价格对象不存在,直接跳过
... ... @@ -54,9 +54,12 @@ public class ProductPriceBuilder implements ViewBuilder {
if (productPrice == null) {
continue;
}
// 取价格的历史记录
ProductPriceHistory productPriceHistory = productPriceHistoryMap.get(productIndexBO.getProductSkn());
// 构造ProductPriceBO
ProductPriceBO productPriceBO = new ProductPriceBO(productPrice);
this.buildProductPriceBO(productPriceBO, productPrice);
// 构造ProductIndexBO
this.buildProductPriceBO(productPriceBO, productPrice,productPriceHistory);
// 构造ProductIndexBO
this.buildProductIndexBO(productIndexBO, productPriceBO);
} catch (Exception e) {
... ... @@ -68,7 +71,7 @@ public class ProductPriceBuilder implements ViewBuilder {
/**
* 增量+全量都调用
*/
public void buildProductPriceBO(ProductPriceBO productPriceBO, ProductPrice productPrice) {
public void buildProductPriceBO(ProductPriceBO productPriceBO, ProductPrice productPrice,ProductPriceHistory productPriceHistory) {
// 1、计算并重设vip相关价格
vipPriceLogicService.fillProductPriceVipPrice(productPriceBO);
// 2、计算折扣相关
... ... @@ -89,7 +92,8 @@ public class ProductPriceBuilder implements ViewBuilder {
BigDecimal studentPrice = productPriceBO.getStudentPrice();
productPriceBO.setIsStudentPrice(studentPrice== null || studentPrice.compareTo(BigDecimal.ZERO)==0 ? "N" : "Y");
productPriceBO.setIsstudentrebate(productPriceBO.getStudentCoinRate() == null || productPriceBO.getStudentCoinRate().compareTo(BigDecimal.ZERO) == 0 ? "N" : "Y");
productPriceBO.setIsLatestReducePrice(isLatestReducePrice(productPrice.getProductSkn(), productPrice.getCurrentPrice()));
// 4、设置最新降价
productPriceBO.setIsLatestReducePrice(this.isLatestReducePrice(productPrice,productPriceHistory));
}
private void buildProductIndexBO(ProductIndexBO productIndexBO, ProductPriceBO productPriceBO) {
... ... @@ -131,8 +135,8 @@ public class ProductPriceBuilder implements ViewBuilder {
productIndexBO.setSpecialSearchFieldPrice(specialSearchFieldLogicService.getSpecialSearchFieldPrice(productPriceBO));
productIndexBO.setIsLatestReducePrice(productPriceBO.getIsLatestReducePrice());
}
public Map<String, Object> getProductPriceModelMap(Integer productId, Integer firstShelveTime, ProductPrice pp) {
public Map<String, Object> getProductPriceModelMap(Integer productId, Integer firstShelveTime, ProductPrice pp,ProductPriceHistory productPriceHistory) {
Map<String, Object> indexData = new HashMap<String, Object>();
indexData.put("isnew", "N");
if (pp == null) {
... ... @@ -140,7 +144,7 @@ public class ProductPriceBuilder implements ViewBuilder {
}
// 构造ProductPriceBO
ProductPriceBO productPriceBO = new ProductPriceBO(pp);
this.buildProductPriceBO(productPriceBO, pp);
this.buildProductPriceBO(productPriceBO, pp,productPriceHistory);
indexData.put("productId", productId);
indexData.put("marketPrice", this.getDoubleFromBigDecimal(productPriceBO.getMarketPrice()));
indexData.put("salesPrice", this.getDoubleFromBigDecimal(productPriceBO.getSalesPrice()));
... ... @@ -167,20 +171,17 @@ public class ProductPriceBuilder implements ViewBuilder {
return indexData;
}
private String isLatestReducePrice(Integer productSkn, BigDecimal price) {
if (price == null) {
private String isLatestReducePrice(ProductPrice productPrice,ProductPriceHistory productPriceHistory) {
BigDecimal newPrice = productPrice.getCurrentPrice();
if (newPrice == null || productPriceHistory == null) {
return "N";
}
ProductPriceHistory productPriceHistory = productPriceHistoryMapper.selectByPrimaryKey(productSkn);
if (productPriceHistory == null) {
return "N";
if (newPrice.compareTo(productPriceHistory.getCurrentSalesPrice()) == 0) {
return newPrice.compareTo(productPriceHistory.getHistorySalesPrice()) < 0 ? "Y" : "N";
}
if (price.compareTo(productPriceHistory.getCurrentSalesPrice()) == 0) {
return price.compareTo(productPriceHistory.getHistorySalesPrice()) < 0 ? "Y" : "N";
}
return price.compareTo(productPriceHistory.getCurrentSalesPrice()) < 0 ? "Y" : "N";
return newPrice.compareTo(productPriceHistory.getCurrentSalesPrice()) < 0 ? "Y" : "N";
}
/**
* isNew 标签逻辑
*/
... ...