Authored by unknown

修复增量更新时的价格问题

@@ -2,6 +2,7 @@ package com.yoho.search.consumer.index.increment.productIndex; @@ -2,6 +2,7 @@ package com.yoho.search.consumer.index.increment.productIndex;
2 2
3 import java.util.ArrayList; 3 import java.util.ArrayList;
4 import java.util.List; 4 import java.util.List;
  5 +import java.util.Map;
5 6
6 import org.apache.commons.collections.CollectionUtils; 7 import org.apache.commons.collections.CollectionUtils;
7 import org.slf4j.Logger; 8 import org.slf4j.Logger;
@@ -82,7 +83,7 @@ public class ProductMqListener extends AbstractIndexMqListener { @@ -82,7 +83,7 @@ public class ProductMqListener extends AbstractIndexMqListener {
82 83
83 private void updateProductDataToEs(final Integer productId, Integer productSkn, boolean isUpdate) { 84 private void updateProductDataToEs(final Integer productId, Integer productSkn, boolean isUpdate) {
84 CostStatistics costStatistics = new CostStatistics(); 85 CostStatistics costStatistics = new CostStatistics();
85 - // 3、获取数据 86 + // 1、获取数据
86 List<Integer> ids = new ArrayList<>(); 87 List<Integer> ids = new ArrayList<>();
87 ids.add(productId); 88 ids.add(productId);
88 List<ProductIBO> productIBOs = productIndexIndexBuilder.getProductIBOs(ids); 89 List<ProductIBO> productIBOs = productIndexIndexBuilder.getProductIBOs(ids);
@@ -90,24 +91,24 @@ public class ProductMqListener extends AbstractIndexMqListener { @@ -90,24 +91,24 @@ public class ProductMqListener extends AbstractIndexMqListener {
90 return; 91 return;
91 } 92 }
92 ProductIBO productIBO = productIBOs.get(0); 93 ProductIBO productIBO = productIBOs.get(0);
93 - // 处理isNew(规则:首次上架7天内展示且折扣率小于88折)  
94 - productIBO.setIsnew("N"); 94 + logger.info("[step1=getProductIBO][productId={}][cost={}ms]", productId, costStatistics.getCost());
  95 +
  96 + // 2、构建ProductPrice
95 ProductPrice productPrice = productPriceService.getBySkn(productSkn); 97 ProductPrice productPrice = productPriceService.getBySkn(productSkn);
96 - if (productPrice != null && productPriceBuilder.isNew(productIBO.getFirstShelveTime(), productPrice.getRetailPrice(), productPrice.getSalesPrice())) {  
97 - productIBO.setIsnew("Y");  
98 - }  
99 - logger.info("[step3=getProductI][productId={}][cost={}ms]", productId, costStatistics.getCost()); 98 + Map<String, Object> productPriceModelMap = productPriceBuilder.getProductPriceModelMap(productId, productIBO.getFirstShelveTime(), productPrice);
  99 + logger.info("[step2=getProductPrice][productId={}][cost={}ms]", productId, costStatistics.getCost());
100 100
101 - // 4、更新到ES 101 + // 3、更新到ES
102 try { 102 try {
103 JSONObject jsonObject = (JSONObject) JSON.toJSON(productIBO); 103 JSONObject jsonObject = (JSONObject) JSON.toJSON(productIBO);
104 if (!isUpdate) { 104 if (!isUpdate) {
105 jsonObject.put("salesNum", 0); 105 jsonObject.put("salesNum", 0);
106 } 106 }
  107 + jsonObject.putAll(productPriceModelMap);
107 this.updateProductIndexWithDataMap(jsonObject, productId); 108 this.updateProductIndexWithDataMap(jsonObject, productId);
108 - logger.info("[step4=updateToEs][productId={}][cost={}ms]", productId, costStatistics.getCost()); 109 + logger.info("[step3=updateToEs][productId={}][cost={}ms]", productId, costStatistics.getCost());
109 } catch (Exception e) { 110 } catch (Exception e) {
110 - logger.error("[step4=updateToEs][productId={}][cost={}ms][execption={}]", productId, costStatistics.getCost(), e.getMessage()); 111 + logger.error("[step3=updateToEs][productId={}][cost={}ms][execption={}]", productId, costStatistics.getCost(), e.getMessage());
111 productIndexMqListener.sendProductIndexMessage(productId); 112 productIndexMqListener.sendProductIndexMessage(productId);
112 } 113 }
113 } 114 }
1 package com.yoho.search.consumer.index.increment.productIndex; 1 package com.yoho.search.consumer.index.increment.productIndex;
2 2
3 -import java.math.BigDecimal;  
4 import java.util.HashMap; 3 import java.util.HashMap;
5 import java.util.Map; 4 import java.util.Map;
6 5
@@ -17,7 +16,6 @@ import com.yoho.search.base.utils.ProductIndexEsField; @@ -17,7 +16,6 @@ import com.yoho.search.base.utils.ProductIndexEsField;
17 import com.yoho.search.consumer.index.increment.AbstractIndexMqListener; 16 import com.yoho.search.consumer.index.increment.AbstractIndexMqListener;
18 import com.yoho.search.consumer.service.base.ProductPriceService; 17 import com.yoho.search.consumer.service.base.ProductPriceService;
19 import com.yoho.search.consumer.service.base.ProductService; 18 import com.yoho.search.consumer.service.base.ProductService;
20 -import com.yoho.search.consumer.service.bo.ProductPriceBO;  
21 import com.yoho.search.consumer.service.logic.SpecialDealLogicService; 19 import com.yoho.search.consumer.service.logic.SpecialDealLogicService;
22 import com.yoho.search.consumer.service.logic.productIndex.viewBuilder.ProductPriceBuilder; 20 import com.yoho.search.consumer.service.logic.productIndex.viewBuilder.ProductPriceBuilder;
23 import com.yoho.search.dal.model.Product; 21 import com.yoho.search.dal.model.Product;
@@ -75,51 +73,20 @@ public class ProductPriceMqListener extends AbstractIndexMqListener { @@ -75,51 +73,20 @@ public class ProductPriceMqListener extends AbstractIndexMqListener {
75 73
76 // 2、更新ProductIndex 74 // 2、更新ProductIndex
77 begin = System.currentTimeMillis(); 75 begin = System.currentTimeMillis();
78 - Integer productId = productService.selectProductIdBySkn(productPrice.getProductSkn());  
79 - this.updateProductIndex(productId, productPrice); 76 + this.updateProductIndex(productPrice.getProductSkn(), productPrice);
80 logger.info("[func=updateData][step=updateProductIndex][productSkn={}][cost={}ms]", productPrice.getProductSkn(), this.getCost(begin)); 77 logger.info("[func=updateData][step=updateProductIndex][productSkn={}][cost={}ms]", productPrice.getProductSkn(), this.getCost(begin));
81 } 78 }
82 79
83 - private double getDoubleFromBigDecimal(BigDecimal bigDecimal) {  
84 - if (bigDecimal == null) {  
85 - return 0d;  
86 - }  
87 - return bigDecimal.doubleValue();  
88 - }  
89 -  
90 - private void updateProductIndex(Integer productId, ProductPrice pp) {  
91 - Map<String, Object> indexData = new HashMap<String, Object>();  
92 -  
93 - // 构造ProductPriceBO  
94 - ProductPriceBO productPriceBO = new ProductPriceBO(pp);  
95 - productPriceBuilder.buildProductPriceBO(productPriceBO);  
96 - indexData.put("productId", productId);  
97 - indexData.put("marketPrice", this.getDoubleFromBigDecimal(productPriceBO.getMarketPrice()));  
98 - indexData.put("salesPrice", this.getDoubleFromBigDecimal(productPriceBO.getSalesPrice()));  
99 - indexData.put("vipPrice", this.getDoubleFromBigDecimal(productPriceBO.getVipPrice()));  
100 - indexData.put("vipDiscountType", productPriceBO.getVipDiscountType());  
101 - indexData.put("vip1Price", this.getDoubleFromBigDecimal(productPriceBO.getVip1Price()));  
102 - indexData.put("vip2Price", this.getDoubleFromBigDecimal(productPriceBO.getVip2Price()));  
103 - indexData.put("vip3Price", this.getDoubleFromBigDecimal(productPriceBO.getVip3Price()));  
104 - indexData.put("studentPrice", this.getDoubleFromBigDecimal(productPriceBO.getStudentPrice()));  
105 -  
106 - indexData.put("isDiscount", productPriceBO.getIsDiscount());  
107 - indexData.put("specialoffer", productPriceBO.getSpecialoffer());  
108 - indexData.put("promotionDiscountInt", productPriceBO.getPromotionDiscountInt());  
109 - indexData.put("promotionDiscount", this.getDoubleFromBigDecimal(productPriceBO.getPromotionDiscount()));  
110 - indexData.put("isStudentPrice", productPriceBO.getIsStudentPrice());  
111 - indexData.put("isstudentrebate", productPriceBO.getIsstudentrebate());  
112 - indexData.put("vipLevels", productPriceBO.getVipLevels());  
113 - indexData.put("priceUpdateTime", productPriceBO.getUpdateTime());  
114 - Product product = productService.getById(productId);  
115 - if (product != null) {  
116 - indexData.put("isnew", productPriceBuilder.isNew(product.getFirstShelveTime(), productPriceBO.getMarketPrice(), productPriceBO.getSalesPrice()));  
117 - } else {  
118 - indexData.put("isnew", "N"); 80 + private void updateProductIndex(Integer productSkn, ProductPrice pp) {
  81 + Product product = productService.getBySkn(productSkn);
  82 + if (product == null) {
  83 + logger.warn("[func=updateData][step=updateProductIndex fail ][product is null ][productSkn is {}]", productSkn);
  84 + return;
119 } 85 }
120 - indexData.put(ProductIndexEsField.specialSearchFieldPrice, specialSearchFieldLogicService.getSpecialSearchFieldPrice(productPriceBO)); 86 + // 构造增量的建到Pi索引里的数据
  87 + Map<String, Object> indexData = productPriceBuilder.getProductPriceModelMap(product.getId(), product.getFirstShelveTime(), pp);
121 // 更新商品索引 88 // 更新商品索引
122 - this.updateProductIndexWithDataMap(indexData, productId); 89 + this.updateProductIndexWithDataMap(indexData, product.getId());
123 } 90 }
124 91
125 /** 92 /**
@@ -128,14 +95,14 @@ public class ProductPriceMqListener extends AbstractIndexMqListener { @@ -128,14 +95,14 @@ public class ProductPriceMqListener extends AbstractIndexMqListener {
128 private void updateProductIndexByClearPrice(Integer productId) { 95 private void updateProductIndexByClearPrice(Integer productId) {
129 Map<String, Object> indexData = new HashMap<String, Object>(30); 96 Map<String, Object> indexData = new HashMap<String, Object>(30);
130 indexData.put("productId", productId); 97 indexData.put("productId", productId);
131 - indexData.put("marketPrice", null);  
132 - indexData.put("salesPrice", null);  
133 - indexData.put("vipPrice", null);  
134 - indexData.put("vipDiscountType", null);  
135 - indexData.put("vip1Price", null);  
136 - indexData.put("vip2Price", null);  
137 - indexData.put("vip3Price", null);  
138 - indexData.put("studentPrice", null); 98 + indexData.put("marketPrice", 0);
  99 + indexData.put("salesPrice", 0);
  100 + indexData.put("vipPrice", 0);
  101 + indexData.put("vipDiscountType", 0);
  102 + indexData.put("vip1Price", 0);
  103 + indexData.put("vip2Price", 0);
  104 + indexData.put("vip3Price", 0);
  105 + indexData.put("studentPrice", 0);
139 // others 106 // others
140 indexData.put("isDiscount", "N"); 107 indexData.put("isDiscount", "N");
141 indexData.put("specialoffer", "N"); 108 indexData.put("specialoffer", "N");
1 package com.yoho.search.consumer.service.logic.productIndex.viewBuilder; 1 package com.yoho.search.consumer.service.logic.productIndex.viewBuilder;
2 2
  3 +import java.math.BigDecimal;
  4 +import java.math.RoundingMode;
  5 +import java.text.DecimalFormat;
  6 +import java.util.Date;
  7 +import java.util.HashMap;
  8 +import java.util.List;
  9 +import java.util.Map;
  10 +import java.util.stream.Collectors;
  11 +
  12 +import org.slf4j.Logger;
  13 +import org.slf4j.LoggerFactory;
  14 +import org.springframework.beans.factory.annotation.Autowired;
  15 +import org.springframework.stereotype.Component;
  16 +
3 import com.yoho.search.base.utils.DateUtil; 17 import com.yoho.search.base.utils.DateUtil;
4 import com.yoho.search.base.utils.MathUtils; 18 import com.yoho.search.base.utils.MathUtils;
  19 +import com.yoho.search.base.utils.ProductIndexEsField;
5 import com.yoho.search.consumer.service.bo.ProductIndexBO; 20 import com.yoho.search.consumer.service.bo.ProductIndexBO;
6 import com.yoho.search.consumer.service.bo.ProductPriceBO; 21 import com.yoho.search.consumer.service.bo.ProductPriceBO;
7 import com.yoho.search.consumer.service.logic.SpecialDealLogicService; 22 import com.yoho.search.consumer.service.logic.SpecialDealLogicService;
8 import com.yoho.search.consumer.service.logic.VipPriceLogicService; 23 import com.yoho.search.consumer.service.logic.VipPriceLogicService;
9 import com.yoho.search.dal.ProductPriceMapper; 24 import com.yoho.search.dal.ProductPriceMapper;
10 import com.yoho.search.dal.model.ProductPrice; 25 import com.yoho.search.dal.model.ProductPrice;
11 -import org.slf4j.Logger;  
12 -import org.slf4j.LoggerFactory;  
13 -import org.springframework.beans.factory.annotation.Autowired;  
14 -import org.springframework.stereotype.Component;  
15 -  
16 -import java.math.BigDecimal;  
17 -import java.math.RoundingMode;  
18 -import java.text.DecimalFormat;  
19 -import java.util.Date;  
20 -import java.util.List;  
21 -import java.util.Map;  
22 -import java.util.stream.Collectors;  
23 26
24 /** 27 /**
25 * Created by wangnan on 2017/1/6. 28 * Created by wangnan on 2017/1/6.
@@ -27,150 +30,183 @@ import java.util.stream.Collectors; @@ -27,150 +30,183 @@ import java.util.stream.Collectors;
27 @Component 30 @Component
28 public class ProductPriceBuilder implements ViewBuilder { 31 public class ProductPriceBuilder implements ViewBuilder {
29 32
30 - private final Logger logger = LoggerFactory.getLogger(ProductPriceBuilder.class); 33 + private final Logger logger = LoggerFactory.getLogger(ProductPriceBuilder.class);
31 34
32 - @Autowired  
33 - private ProductPriceMapper productPriceMapper;  
34 - @Autowired  
35 - private VipPriceLogicService vipPriceLogicService;  
36 - @Autowired  
37 - private SpecialDealLogicService specialSearchFieldLogicService; 35 + @Autowired
  36 + private ProductPriceMapper productPriceMapper;
  37 + @Autowired
  38 + private VipPriceLogicService vipPriceLogicService;
  39 + @Autowired
  40 + private SpecialDealLogicService specialSearchFieldLogicService;
38 41
39 - @Override  
40 - public void build(List<ProductIndexBO> productIndexBOs, List<Integer> ids, List<Integer> sknList) {  
41 - List<ProductPrice> productPrices = productPriceMapper.selectBySknList(sknList);  
42 - Map<Integer, ProductPrice> productPricesMap = productPrices.stream().collect(Collectors.toMap(ProductPrice::getProductSkn, (p) -> p));  
43 - for (ProductIndexBO productIndexBO : productIndexBOs) {  
44 - try {  
45 - // 如果该skn对应价格对象不存在,直接跳过  
46 - ProductPrice productPrice = productPricesMap.get(productIndexBO.getProductSkn());  
47 - if (productPrice == null) {  
48 - continue;  
49 - }  
50 - // 构造ProductPriceBO  
51 - ProductPriceBO productPriceBO = new ProductPriceBO(productPrice);  
52 - this.buildProductPriceBO(productPriceBO);  
53 - // 构造ProductIndexBO  
54 - this.buildProductIndexBO(productIndexBO, productPriceBO);  
55 - } catch (Exception e) {  
56 - logger.error(e.getMessage(), e);  
57 - }  
58 - }  
59 - } 42 + @Override
  43 + public void build(List<ProductIndexBO> productIndexBOs, List<Integer> ids, List<Integer> sknList) {
  44 + List<ProductPrice> productPrices = productPriceMapper.selectBySknList(sknList);
  45 + Map<Integer, ProductPrice> productPricesMap = productPrices.stream().collect(Collectors.toMap(ProductPrice::getProductSkn, (p) -> p));
  46 + for (ProductIndexBO productIndexBO : productIndexBOs) {
  47 + try {
  48 + // 如果该skn对应价格对象不存在,直接跳过
  49 + ProductPrice productPrice = productPricesMap.get(productIndexBO.getProductSkn());
  50 + if (productPrice == null) {
  51 + continue;
  52 + }
  53 + // 构造ProductPriceBO
  54 + ProductPriceBO productPriceBO = new ProductPriceBO(productPrice);
  55 + this.buildProductPriceBO(productPriceBO);
  56 + // 构造ProductIndexBO
  57 + this.buildProductIndexBO(productIndexBO, productPriceBO);
  58 + } catch (Exception e) {
  59 + logger.error(e.getMessage(), e);
  60 + }
  61 + }
  62 + }
60 63
61 - /**  
62 - * 增量+全量都调用  
63 - */  
64 - public void buildProductPriceBO(ProductPriceBO productPriceBO) {  
65 - // 1、计算并重设vip相关价格  
66 - vipPriceLogicService.fillProductPriceVipPrice(productPriceBO);  
67 - // 2、计算折扣相关  
68 - double salesPrice = this.getDoubleFromBigDecimal(productPriceBO.getSalesPrice());  
69 - double marketPrice = this.getDoubleFromBigDecimal(productPriceBO.getMarketPrice()); 64 + /**
  65 + * 增量+全量都调用
  66 + */
  67 + public void buildProductPriceBO(ProductPriceBO productPriceBO) {
  68 + // 1、计算并重设vip相关价格
  69 + vipPriceLogicService.fillProductPriceVipPrice(productPriceBO);
  70 + // 2、计算折扣相关
  71 + double salesPrice = this.getDoubleFromBigDecimal(productPriceBO.getSalesPrice());
  72 + double marketPrice = this.getDoubleFromBigDecimal(productPriceBO.getMarketPrice());
70 productPriceBO.setIsDiscount(salesPrice < marketPrice ? "Y" : "N"); 73 productPriceBO.setIsDiscount(salesPrice < marketPrice ? "Y" : "N");
71 - double specialOffer = this.divide(1, productPriceBO.getSalesPrice(), productPriceBO.getMarketPrice());  
72 - if (specialOffer <= 0.5) {  
73 - productPriceBO.setSpecialoffer("Y");  
74 - } else {  
75 - productPriceBO.setSpecialoffer("N");  
76 - }  
77 - double promotionDiscountInt = this.divide(1, productPriceBO.getSalesPrice().multiply(new BigDecimal(10)), productPriceBO.getMarketPrice());  
78 - productPriceBO.setPromotionDiscountInt((long) promotionDiscountInt);  
79 - double promotionDiscount = this.divide(3, productPriceBO.getSalesPrice(), productPriceBO.getMarketPrice());  
80 - productPriceBO.setPromotionDiscount(this.getBigDecimalFromDouble(promotionDiscount));  
81 - // 3、设置学生价相关属性  
82 - productPriceBO.setIsStudentPrice(productPriceBO.getStudentPrice() != null ? "Y" : "N");  
83 - productPriceBO.setIsstudentrebate(productPriceBO.getStudentCoinRate() == null || productPriceBO.getStudentCoinRate().compareTo(BigDecimal.ZERO) == 0 ? "N" : "Y");  
84 - } 74 + double specialOffer = this.divide(1, productPriceBO.getSalesPrice(), productPriceBO.getMarketPrice());
  75 + if (specialOffer <= 0.5) {
  76 + productPriceBO.setSpecialoffer("Y");
  77 + } else {
  78 + productPriceBO.setSpecialoffer("N");
  79 + }
  80 + double promotionDiscountInt = this.divide(1, productPriceBO.getSalesPrice().multiply(new BigDecimal(10)), productPriceBO.getMarketPrice());
  81 + productPriceBO.setPromotionDiscountInt((long) promotionDiscountInt);
  82 + double promotionDiscount = this.divide(3, productPriceBO.getSalesPrice(), productPriceBO.getMarketPrice());
  83 + productPriceBO.setPromotionDiscount(this.getBigDecimalFromDouble(promotionDiscount));
  84 + // 3、设置学生价相关属性
  85 + productPriceBO.setIsStudentPrice(productPriceBO.getStudentPrice() != null ? "Y" : "N");
  86 + productPriceBO.setIsstudentrebate(productPriceBO.getStudentCoinRate() == null || productPriceBO.getStudentCoinRate().compareTo(BigDecimal.ZERO) == 0 ? "N" : "Y");
  87 + }
  88 +
  89 + private void buildProductIndexBO(ProductIndexBO productIndexBO, ProductPriceBO productPriceBO) {
  90 + productIndexBO.setIsDiscount("N");
  91 + productIndexBO.setSpecialoffer("N");
  92 + productIndexBO.setPromotionDiscount(new BigDecimal(1));
  93 + productIndexBO.setPromotionDiscountInt(10L);
  94 + productIndexBO.setIsStudentPrice("N");
  95 + productIndexBO.setIsStudentRebate("N");
  96 + productIndexBO.setIsnew("N");
  97 + productIndexBO.setMarketPrice(productPriceBO.getMarketPrice());
  98 + productIndexBO.setVipDiscountType(productPriceBO.getVipDiscountType());
  99 + productIndexBO.setSalesPrice(productPriceBO.getSalesPrice());
  100 + productIndexBO.setVipPrice(productPriceBO.getVipPrice());
  101 + productIndexBO.setVip1Price(productPriceBO.getVip1Price());
  102 + productIndexBO.setVip2Price(productPriceBO.getVip2Price());
  103 + productIndexBO.setVip3Price(productPriceBO.getVip3Price());
  104 + productIndexBO.setStudentPrice(productPriceBO.getStudentPrice());
  105 + // 折扣相关
  106 + productIndexBO.setIsDiscount(productPriceBO.getIsDiscount());
  107 + productIndexBO.setSpecialoffer(productPriceBO.getSpecialoffer());
  108 + productIndexBO.setPromotionDiscountInt(productPriceBO.getPromotionDiscountInt());
  109 + productIndexBO.setPromotionDiscount(productPriceBO.getPromotionDiscount());
  110 + // 学生价相关字段
  111 + productIndexBO.setIsStudentPrice(productPriceBO.getIsStudentPrice());
  112 + productIndexBO.setIsStudentRebate(productPriceBO.getIsstudentrebate());
  113 + // 设置vipLevels
  114 + productIndexBO.setVipLevels(productPriceBO.getVipLevels());
  115 + // 设置价格更新时间
  116 + productIndexBO.setPriceUpdateTime(productPriceBO.getUpdateTime());
  117 + // 设置最后一次降价时间
  118 + productIndexBO.setLastReducePriceTime(productPriceBO.getLastReducePriceTime());
  119 + // 计算isNew(规则:首次上架7天内展示且折扣率大于等于88折)
  120 + productIndexBO.setIsnew("N");
  121 + if (this.isNew(productIndexBO.getFirstShelveTime(), productIndexBO.getMarketPrice(), productIndexBO.getSalesPrice())) {
  122 + productIndexBO.setIsnew("Y");
  123 + }
  124 + // 计算specialSearchFieldPrice
  125 + productIndexBO.setSpecialSearchFieldPrice(specialSearchFieldLogicService.getSpecialSearchFieldPrice(productPriceBO));
  126 + }
85 127
86 - private void buildProductIndexBO(ProductIndexBO productIndexBO, ProductPriceBO productPriceBO) {  
87 - productIndexBO.setIsDiscount("N");  
88 - productIndexBO.setSpecialoffer("N");  
89 - productIndexBO.setPromotionDiscount(new BigDecimal(1));  
90 - productIndexBO.setPromotionDiscountInt(10L);  
91 - productIndexBO.setIsStudentPrice("N");  
92 - productIndexBO.setIsStudentRebate("N");  
93 - productIndexBO.setIsnew("N");  
94 - productIndexBO.setMarketPrice(productPriceBO.getMarketPrice());  
95 - productIndexBO.setVipDiscountType(productPriceBO.getVipDiscountType());  
96 - productIndexBO.setSalesPrice(productPriceBO.getSalesPrice());  
97 - productIndexBO.setVipPrice(productPriceBO.getVipPrice());  
98 - productIndexBO.setVip1Price(productPriceBO.getVip1Price());  
99 - productIndexBO.setVip2Price(productPriceBO.getVip2Price());  
100 - productIndexBO.setVip3Price(productPriceBO.getVip3Price());  
101 - productIndexBO.setStudentPrice(productPriceBO.getStudentPrice());  
102 - // 折扣相关  
103 - productIndexBO.setIsDiscount(productPriceBO.getIsDiscount());  
104 - productIndexBO.setSpecialoffer(productPriceBO.getSpecialoffer());  
105 - productIndexBO.setPromotionDiscountInt(productPriceBO.getPromotionDiscountInt());  
106 - productIndexBO.setPromotionDiscount(productPriceBO.getPromotionDiscount());  
107 - // 学生价相关字段  
108 - productIndexBO.setIsStudentPrice(productPriceBO.getIsStudentPrice());  
109 - productIndexBO.setIsStudentRebate(productPriceBO.getIsstudentrebate());  
110 - // 设置vipLevels  
111 - productIndexBO.setVipLevels(productPriceBO.getVipLevels());  
112 - // 设置价格更新时间  
113 - productIndexBO.setPriceUpdateTime(productPriceBO.getUpdateTime());  
114 - // 设置最后一次降价时间  
115 - productIndexBO.setLastReducePriceTime(productPriceBO.getLastReducePriceTime());  
116 - // 计算isNew(规则:首次上架7天内展示且折扣率大于等于88折)  
117 - productIndexBO.setIsnew("N");  
118 - if (this.isNew(productIndexBO.getFirstShelveTime(), productIndexBO.getMarketPrice(), productIndexBO.getSalesPrice())) {  
119 - productIndexBO.setIsnew("Y");  
120 - }  
121 - // 计算specialSearchFieldPrice  
122 - productIndexBO.setSpecialSearchFieldPrice(specialSearchFieldLogicService.getSpecialSearchFieldPrice(productPriceBO));  
123 - } 128 + public Map<String, Object> getProductPriceModelMap(Integer productId, Integer firstShelveTime, ProductPrice pp) {
  129 + Map<String, Object> indexData = new HashMap<String, Object>();
  130 + indexData.put("isnew", "N");
  131 + if (pp == null) {
  132 + return indexData;
  133 + }
  134 + // 构造ProductPriceBO
  135 + ProductPriceBO productPriceBO = new ProductPriceBO(pp);
  136 + this.buildProductPriceBO(productPriceBO);
  137 + indexData.put("productId", productId);
  138 + indexData.put("marketPrice", this.getDoubleFromBigDecimal(productPriceBO.getMarketPrice()));
  139 + indexData.put("salesPrice", this.getDoubleFromBigDecimal(productPriceBO.getSalesPrice()));
  140 + indexData.put("vipPrice", this.getDoubleFromBigDecimal(productPriceBO.getVipPrice()));
  141 + indexData.put("vipDiscountType", productPriceBO.getVipDiscountType());
  142 + indexData.put("vip1Price", this.getDoubleFromBigDecimal(productPriceBO.getVip1Price()));
  143 + indexData.put("vip2Price", this.getDoubleFromBigDecimal(productPriceBO.getVip2Price()));
  144 + indexData.put("vip3Price", this.getDoubleFromBigDecimal(productPriceBO.getVip3Price()));
  145 + indexData.put("studentPrice", this.getDoubleFromBigDecimal(productPriceBO.getStudentPrice()));
124 146
  147 + indexData.put("isDiscount", productPriceBO.getIsDiscount());
  148 + indexData.put("specialoffer", productPriceBO.getSpecialoffer());
  149 + indexData.put("promotionDiscountInt", productPriceBO.getPromotionDiscountInt());
  150 + indexData.put("promotionDiscount", this.getDoubleFromBigDecimal(productPriceBO.getPromotionDiscount()));
  151 + indexData.put("isStudentPrice", productPriceBO.getIsStudentPrice());
  152 + indexData.put("isstudentrebate", productPriceBO.getIsstudentrebate());
  153 + indexData.put("vipLevels", productPriceBO.getVipLevels());
  154 + indexData.put("priceUpdateTime", productPriceBO.getUpdateTime());
  155 + if (firstShelveTime != null) {
  156 + indexData.put("isnew", this.isNew(firstShelveTime, productPriceBO.getMarketPrice(), productPriceBO.getSalesPrice()));
  157 + }
  158 + indexData.put(ProductIndexEsField.specialSearchFieldPrice, specialSearchFieldLogicService.getSpecialSearchFieldPrice(productPriceBO));
  159 + return indexData;
  160 + }
125 161
126 - /**  
127 - * isNew 标签逻辑  
128 - */  
129 - public boolean isNew(Integer firstShelveTime, BigDecimal marketPrice, BigDecimal salesPrice) {  
130 - try {  
131 - if (firstShelveTime == null || firstShelveTime <= 0 || salesPrice == null || marketPrice == null) {  
132 - return false;  
133 - }  
134 - long dateCount = DateUtil.daysBetween(new Date(firstShelveTime * 1000L), new Date());  
135 - if (dateCount > 7) {  
136 - return false;  
137 - }  
138 - // 计算折扣  
139 - Double discount = MathUtils.getDevideValue(salesPrice, marketPrice, 2, RoundingMode.DOWN);  
140 - if (discount >= 0.88) {  
141 - return true;  
142 - }  
143 - return false;  
144 - } catch (Exception e) {  
145 - return false;  
146 - }  
147 - } 162 + /**
  163 + * isNew 标签逻辑
  164 + */
  165 + public boolean isNew(Integer firstShelveTime, BigDecimal marketPrice, BigDecimal salesPrice) {
  166 + try {
  167 + if (firstShelveTime == null || firstShelveTime <= 0 || salesPrice == null || marketPrice == null) {
  168 + return false;
  169 + }
  170 + long dateCount = DateUtil.daysBetween(new Date(firstShelveTime * 1000L), new Date());
  171 + if (dateCount > 7) {
  172 + return false;
  173 + }
  174 + // 计算折扣
  175 + Double discount = MathUtils.getDevideValue(salesPrice, marketPrice, 2, RoundingMode.DOWN);
  176 + if (discount >= 0.88) {
  177 + return true;
  178 + }
  179 + return false;
  180 + } catch (Exception e) {
  181 + return false;
  182 + }
  183 + }
148 184
149 - private double divide(int scale, BigDecimal a, BigDecimal b) {  
150 - if (b == null || b.compareTo(BigDecimal.ZERO) == 0) {  
151 - return 0;  
152 - }  
153 - StringBuilder sb = new StringBuilder("0.0");  
154 - for (int i = 1; i < scale; i++) {  
155 - sb.append('0');  
156 - }  
157 - BigDecimal divideResult = a.divide(b, scale, RoundingMode.DOWN);  
158 - DecimalFormat decimalFormat = new DecimalFormat(sb.toString());  
159 - String result = decimalFormat.format(divideResult);  
160 - return Double.parseDouble(result);  
161 - } 185 + private double divide(int scale, BigDecimal a, BigDecimal b) {
  186 + if (b == null || b.compareTo(BigDecimal.ZERO) == 0) {
  187 + return 0;
  188 + }
  189 + StringBuilder sb = new StringBuilder("0.0");
  190 + for (int i = 1; i < scale; i++) {
  191 + sb.append('0');
  192 + }
  193 + BigDecimal divideResult = a.divide(b, scale, RoundingMode.DOWN);
  194 + DecimalFormat decimalFormat = new DecimalFormat(sb.toString());
  195 + String result = decimalFormat.format(divideResult);
  196 + return Double.parseDouble(result);
  197 + }
162 198
163 - private double getDoubleFromBigDecimal(BigDecimal bigDecimal) {  
164 - if (bigDecimal == null) {  
165 - return 0d;  
166 - }  
167 - return bigDecimal.doubleValue();  
168 - } 199 + private double getDoubleFromBigDecimal(BigDecimal bigDecimal) {
  200 + if (bigDecimal == null) {
  201 + return 0d;
  202 + }
  203 + return bigDecimal.doubleValue();
  204 + }
169 205
170 - private BigDecimal getBigDecimalFromDouble(Double d) {  
171 - if (d == null) {  
172 - return new BigDecimal(0);  
173 - }  
174 - return new BigDecimal(d);  
175 - } 206 + private BigDecimal getBigDecimalFromDouble(Double d) {
  207 + if (d == null) {
  208 + return new BigDecimal(0);
  209 + }
  210 + return new BigDecimal(d);
  211 + }
176 } 212 }