Authored by WN\wangnan

currentvipdiscounttype需求

@@ -16,7 +16,7 @@ public interface ProductPriceMapper { @@ -16,7 +16,7 @@ public interface ProductPriceMapper {
16 16
17 List<ProductPrice> selectPageLists(@Param(value="offset")Integer offset, @Param(value="pageSize")Integer pageSize); 17 List<ProductPrice> selectPageLists(@Param(value="offset")Integer offset, @Param(value="pageSize")Integer pageSize);
18 18
19 - List<ProductPrice> selectBySkns(List<Integer> skns); 19 + List<ProductPrice> selectBySknList(List<Integer> sknList);
20 20
21 int selectCount(); 21 int selectCount();
22 } 22 }
@@ -9,6 +9,7 @@ @@ -9,6 +9,7 @@
9 <result column="current_price" property="currentPrice" jdbcType="DECIMAL" /> 9 <result column="current_price" property="currentPrice" jdbcType="DECIMAL" />
10 <result column="purchase_price" property="purchasePrice" jdbcType="DECIMAL" /> 10 <result column="purchase_price" property="purchasePrice" jdbcType="DECIMAL" />
11 <result column="vip_discount_type" property="vipDiscountType" jdbcType="INTEGER" /> 11 <result column="vip_discount_type" property="vipDiscountType" jdbcType="INTEGER" />
  12 + <result column="current_vip_discount_type" property="currentVipDiscountType" jdbcType="INTEGER" />
12 <result column="vip_discount" property="vipDiscount" jdbcType="DECIMAL" /> 13 <result column="vip_discount" property="vipDiscount" jdbcType="DECIMAL" />
13 <result column="vip_price" property="vipPrice" jdbcType="DECIMAL" /> 14 <result column="vip_price" property="vipPrice" jdbcType="DECIMAL" />
14 <result column="vip1_price" property="vip1Price" jdbcType="DECIMAL" /> 15 <result column="vip1_price" property="vip1Price" jdbcType="DECIMAL" />
@@ -25,7 +26,7 @@ @@ -25,7 +26,7 @@
25 26
26 <sql id="Base_Column_List"> 27 <sql id="Base_Column_List">
27 product_skn,retail_price, sales_price,current_price, purchase_price, 28 product_skn,retail_price, sales_price,current_price, purchase_price,
28 - vip_discount_type, vip_discount, vip_price, 29 + vip_discount_type, current_vip_discount_type, vip_discount, vip_price,
29 vip1_price, vip2_price, 30 vip1_price, vip2_price,
30 vip3_price,student_price, 31 vip3_price,student_price,
31 update_time,student_coin_rate,lastReducePriceTime, 32 update_time,student_coin_rate,lastReducePriceTime,
@@ -51,13 +52,13 @@ @@ -51,13 +52,13 @@
51 timeout="20000"> 52 timeout="20000">
52 insert ignore into product_price ( 53 insert ignore into product_price (
53 retail_price, sales_price,current_price, purchase_price, 54 retail_price, sales_price,current_price, purchase_price,
54 - vip_discount_type, vip_discount, vip_price, 55 + vip_discount_type, current_vip_discount_type, vip_discount, vip_price,
55 vip1_price, vip2_price, vip3_price,student_price, 56 vip1_price, vip2_price, vip3_price,student_price,
56 product_skn, update_time, student_coin_rate,lastReducePriceTime, 57 product_skn, update_time, student_coin_rate,lastReducePriceTime,
57 product_vip_status,basic_price,purchase_discount 58 product_vip_status,basic_price,purchase_discount
58 )values ( 59 )values (
59 #{retailPrice,jdbcType=DECIMAL},#{salesPrice,jdbcType=DECIMAL},#{currentPrice,jdbcType=DECIMAL}, 60 #{retailPrice,jdbcType=DECIMAL},#{salesPrice,jdbcType=DECIMAL},#{currentPrice,jdbcType=DECIMAL},
60 - #{purchasePrice,jdbcType=DECIMAL},#{vipDiscountType,jdbcType=INTEGER}, 61 + #{purchasePrice,jdbcType=DECIMAL},#{vipDiscountType,jdbcType=INTEGER},#{currentVipDiscountType,jdbcType=INTEGER},
61 #{vipDiscount,jdbcType=DECIMAL}, #{vipPrice,jdbcType=DECIMAL}, 62 #{vipDiscount,jdbcType=DECIMAL}, #{vipPrice,jdbcType=DECIMAL},
62 #{vip1Price,jdbcType=DECIMAL}, 63 #{vip1Price,jdbcType=DECIMAL},
63 #{vip2Price,jdbcType=DECIMAL},#{vip3Price,jdbcType=DECIMAL},#{studentPrice,jdbcType=DECIMAL}, 64 #{vip2Price,jdbcType=DECIMAL},#{vip3Price,jdbcType=DECIMAL},#{studentPrice,jdbcType=DECIMAL},
@@ -86,6 +87,9 @@ @@ -86,6 +87,9 @@
86 <if test="vipDiscountType != null"> 87 <if test="vipDiscountType != null">
87 vip_discount_type = #{vipDiscountType,jdbcType=INTEGER}, 88 vip_discount_type = #{vipDiscountType,jdbcType=INTEGER},
88 </if> 89 </if>
  90 + <if test="currentVipDiscountType != null">
  91 + current_vip_discount_type = #{currentVipDiscountType,jdbcType=INTEGER},
  92 + </if>
89 <if test="vipDiscount != null"> 93 <if test="vipDiscount != null">
90 vip_discount = #{vipDiscount,jdbcType=DECIMAL}, 94 vip_discount = #{vipDiscount,jdbcType=DECIMAL},
91 </if> 95 </if>
@@ -136,7 +140,7 @@ @@ -136,7 +140,7 @@
136 from product_price limit #{offset},#{pageSize} 140 from product_price limit #{offset},#{pageSize}
137 </select> 141 </select>
138 142
139 - <select id="selectBySkns" resultMap="BaseResultMap"> 143 + <select id="selectBySknList" resultMap="BaseResultMap">
140 select 144 select
141 <include refid="Base_Column_List" /> 145 <include refid="Base_Column_List" />
142 from product_price where product_skn in 146 from product_price where product_skn in
@@ -10,7 +10,7 @@ import com.yoho.search.base.utils.ISearchConstants; @@ -10,7 +10,7 @@ import com.yoho.search.base.utils.ISearchConstants;
10 import com.yoho.search.consumer.index.common.IYohoIndexService; 10 import com.yoho.search.consumer.index.common.IYohoIndexService;
11 import com.yoho.search.consumer.index.increment.AbstractIndexMqListener; 11 import com.yoho.search.consumer.index.increment.AbstractIndexMqListener;
12 import com.yoho.search.consumer.service.base.ProductPricePlanService; 12 import com.yoho.search.consumer.service.base.ProductPricePlanService;
13 -import com.yoho.search.consumer.service.logic.VipPriceLogicServie; 13 +import com.yoho.search.consumer.service.logic.VipPriceLogicService;
14 import com.yoho.search.dal.model.ProductPricePlan; 14 import com.yoho.search.dal.model.ProductPricePlan;
15 15
16 @Component 16 @Component
@@ -21,7 +21,7 @@ public class ProductPricePlanMqListener extends AbstractIndexMqListener { @@ -21,7 +21,7 @@ public class ProductPricePlanMqListener extends AbstractIndexMqListener {
21 @Autowired 21 @Autowired
22 private IYohoIndexService indexService; 22 private IYohoIndexService indexService;
23 @Autowired 23 @Autowired
24 - private VipPriceLogicServie vipPriceLogicServie; 24 + private VipPriceLogicService vipPriceLogicService;
25 25
26 @Override 26 @Override
27 public String getIndexName() { 27 public String getIndexName() {
@@ -47,7 +47,7 @@ public class ProductPricePlanMqListener extends AbstractIndexMqListener { @@ -47,7 +47,7 @@ public class ProductPricePlanMqListener extends AbstractIndexMqListener {
47 } 47 }
48 productPricePlanService.saveOrUpdate(productPricePlan); 48 productPricePlanService.saveOrUpdate(productPricePlan);
49 // 填充价格相关参数 49 // 填充价格相关参数
50 - vipPriceLogicServie.fillProductPricePlanVipPrice(productPricePlan); 50 + vipPriceLogicService.fillProductPricePlanVipPrice(productPricePlan);
51 String idValue = String.valueOf(productPricePlan.getId()); 51 String idValue = String.valueOf(productPricePlan.getId());
52 indexService.updateIndexData(this.getIndexName(), idValue, (JSONObject) JSONObject.toJSON(productPricePlan)); 52 indexService.updateIndexData(this.getIndexName(), idValue, (JSONObject) JSONObject.toJSON(productPricePlan));
53 } 53 }
@@ -92,7 +92,7 @@ public class ProductPriceMqListener extends AbstractIndexMqListener { @@ -92,7 +92,7 @@ public class ProductPriceMqListener extends AbstractIndexMqListener {
92 92
93 // 构造ProductPriceBO 93 // 构造ProductPriceBO
94 ProductPriceBO productPriceBO = new ProductPriceBO(pp); 94 ProductPriceBO productPriceBO = new ProductPriceBO(pp);
95 - productPriceBuilder.fillProductPriceBO(productPriceBO); 95 + productPriceBuilder.buildProductPriceBO(productPriceBO);
96 indexData.put("productId", productId); 96 indexData.put("productId", productId);
97 indexData.put("marketPrice", this.getDoubleFromBigDecimal(productPriceBO.getMarketPrice())); 97 indexData.put("marketPrice", this.getDoubleFromBigDecimal(productPriceBO.getMarketPrice()));
98 indexData.put("salesPrice", this.getDoubleFromBigDecimal(productPriceBO.getSalesPrice())); 98 indexData.put("salesPrice", this.getDoubleFromBigDecimal(productPriceBO.getSalesPrice()));
@@ -5,7 +5,7 @@ import java.util.List; @@ -5,7 +5,7 @@ import java.util.List;
5 import org.springframework.beans.factory.annotation.Autowired; 5 import org.springframework.beans.factory.annotation.Autowired;
6 import org.springframework.stereotype.Component; 6 import org.springframework.stereotype.Component;
7 7
8 -import com.yoho.search.consumer.service.logic.VipPriceLogicServie; 8 +import com.yoho.search.consumer.service.logic.VipPriceLogicService;
9 import com.yoho.search.dal.ProductPricePlanMapper; 9 import com.yoho.search.dal.ProductPricePlanMapper;
10 import com.yoho.search.dal.model.ProductPricePlan; 10 import com.yoho.search.dal.model.ProductPricePlan;
11 11
@@ -15,7 +15,7 @@ public class ProductPricePlanService { @@ -15,7 +15,7 @@ public class ProductPricePlanService {
15 @Autowired 15 @Autowired
16 private ProductPricePlanMapper productPricePlanMapper; 16 private ProductPricePlanMapper productPricePlanMapper;
17 @Autowired 17 @Autowired
18 - private VipPriceLogicServie vipPriceLogicServie; 18 + private VipPriceLogicService vipPriceLogicService;
19 19
20 public int count() { 20 public int count() {
21 return productPricePlanMapper.selectCount(); 21 return productPricePlanMapper.selectCount();
@@ -24,7 +24,7 @@ public class ProductPricePlanService { @@ -24,7 +24,7 @@ public class ProductPricePlanService {
24 public List<ProductPricePlan> getPageLists(int offset, int limit) { 24 public List<ProductPricePlan> getPageLists(int offset, int limit) {
25 List<ProductPricePlan> list = productPricePlanMapper.selectPageLists(offset,limit); 25 List<ProductPricePlan> list = productPricePlanMapper.selectPageLists(offset,limit);
26 for(ProductPricePlan p:list){ 26 for(ProductPricePlan p:list){
27 - vipPriceLogicServie.fillProductPricePlanVipPrice(p); 27 + vipPriceLogicService.fillProductPricePlanVipPrice(p);
28 } 28 }
29 return list; 29 return list;
30 } 30 }
@@ -20,6 +20,7 @@ public class ProductPriceBO { @@ -20,6 +20,7 @@ public class ProductPriceBO {
20 private BigDecimal basicPrice; 20 private BigDecimal basicPrice;
21 private Integer productVipStatus; 21 private Integer productVipStatus;
22 private BigDecimal vipDiscount; 22 private BigDecimal vipDiscount;
  23 + private Integer currentVipDiscountType;
23 24
24 // others 25 // others
25 private String isDiscount; 26 private String isDiscount;
@@ -33,7 +34,6 @@ public class ProductPriceBO { @@ -33,7 +34,6 @@ public class ProductPriceBO {
33 public ProductPriceBO(ProductPrice productPrice) { 34 public ProductPriceBO(ProductPrice productPrice) {
34 super(); 35 super();
35 this.marketPrice = productPrice.getRetailPrice();// 吊牌价 36 this.marketPrice = productPrice.getRetailPrice();// 吊牌价
36 -  
37 BigDecimal currentPrice = productPrice.getCurrentPrice();// 综合了变价计划和商品售价的结果,生成的逻辑完全由后台控制。 37 BigDecimal currentPrice = productPrice.getCurrentPrice();// 综合了变价计划和商品售价的结果,生成的逻辑完全由后台控制。
38 if (currentPrice != null && currentPrice.compareTo(BigDecimal.ZERO) == 1) { 38 if (currentPrice != null && currentPrice.compareTo(BigDecimal.ZERO) == 1) {
39 this.salesPrice = currentPrice; 39 this.salesPrice = currentPrice;
@@ -52,6 +52,15 @@ public class ProductPriceBO { @@ -52,6 +52,15 @@ public class ProductPriceBO {
52 this.basicPrice = productPrice.getBasicPrice(); 52 this.basicPrice = productPrice.getBasicPrice();
53 this.productVipStatus = productPrice.getProductVipStatus(); 53 this.productVipStatus = productPrice.getProductVipStatus();
54 this.vipDiscount = productPrice.getVipDiscount(); 54 this.vipDiscount = productPrice.getVipDiscount();
  55 + this.currentVipDiscountType = productPrice.getCurrentVipDiscountType();
  56 + }
  57 +
  58 + public Integer getCurrentVipDiscountType() {
  59 + return currentVipDiscountType;
  60 + }
  61 +
  62 + public void setCurrentVipDiscountType(Integer currentVipDiscountType) {
  63 + this.currentVipDiscountType = currentVipDiscountType;
55 } 64 }
56 65
57 public BigDecimal getVipDiscount() { 66 public BigDecimal getVipDiscount() {
1 package com.yoho.search.consumer.service.logic; 1 package com.yoho.search.consumer.service.logic;
2 2
3 -import java.math.BigDecimal;  
4 -  
5 -import org.springframework.stereotype.Service;  
6 -  
7 import com.yoho.search.consumer.service.bo.ProductPriceBO; 3 import com.yoho.search.consumer.service.bo.ProductPriceBO;
8 import com.yoho.search.consumer.service.bo.VipPriceBO; 4 import com.yoho.search.consumer.service.bo.VipPriceBO;
9 import com.yoho.search.dal.model.ProductPricePlan; 5 import com.yoho.search.dal.model.ProductPricePlan;
  6 +import org.apache.commons.lang.StringUtils;
  7 +import org.springframework.stereotype.Service;
  8 +
  9 +import java.math.BigDecimal;
  10 +import java.util.ArrayList;
  11 +import java.util.List;
10 12
11 @Service 13 @Service
12 -public class VipPriceLogicServie { 14 +public class VipPriceLogicService {
13 15
14 /** 16 /**
15 * 设置计划的vip价格 17 * 设置计划的vip价格
16 - * @param productPricePlan  
17 - * @return  
18 */ 18 */
19 public void fillProductPricePlanVipPrice(ProductPricePlan p){ 19 public void fillProductPricePlanVipPrice(ProductPricePlan p){
20 VipPriceBO vipPriceBO = this.getVipPriceBO(p.getCurrentSaleprice(), p.getVipPrice(), p.getVip1Price(), p.getVip2Price(), p.getVip3Price(), p.getVipDiscountType(), p.getVipDiscount()); 20 VipPriceBO vipPriceBO = this.getVipPriceBO(p.getCurrentSaleprice(), p.getVipPrice(), p.getVip1Price(), p.getVip2Price(), p.getVip3Price(), p.getVipDiscountType(), p.getVipDiscount());
@@ -25,45 +25,65 @@ public class VipPriceLogicServie { @@ -25,45 +25,65 @@ public class VipPriceLogicServie {
25 25
26 /** 26 /**
27 * 计算并重设vip相关价格 27 * 计算并重设vip相关价格
28 - * @param productPriceBO  
29 */ 28 */
30 public void fillProductPriceVipPrice(ProductPriceBO productPriceBO){ 29 public void fillProductPriceVipPrice(ProductPriceBO productPriceBO){
31 - VipPriceBO vipPriceBO = this.getVipPriceBO(productPriceBO.getSalesPrice(), productPriceBO.getVipPrice(), productPriceBO.getVip1Price(), productPriceBO.getVip2Price(), productPriceBO.getVip3Price(), productPriceBO.getVipDiscountType(), 30 + VipPriceBO vipPriceBO = this.getVipPriceBO(productPriceBO.getSalesPrice(), productPriceBO.getVipPrice(), productPriceBO.getVip1Price(), productPriceBO.getVip2Price(), productPriceBO.getVip3Price(), productPriceBO.getCurrentVipDiscountType(),
32 productPriceBO.getVipDiscount()); 31 productPriceBO.getVipDiscount());
33 productPriceBO.setVip1Price(vipPriceBO.getVip1PriceBigDecimal()); 32 productPriceBO.setVip1Price(vipPriceBO.getVip1PriceBigDecimal());
34 productPriceBO.setVip2Price(vipPriceBO.getVip2PriceBigDecimal()); 33 productPriceBO.setVip2Price(vipPriceBO.getVip2PriceBigDecimal());
35 productPriceBO.setVip3Price(vipPriceBO.getVip3PriceBigDecimal()); 34 productPriceBO.setVip3Price(vipPriceBO.getVip3PriceBigDecimal());
  35 +
  36 + //设置vipLevels
  37 + double salesPrice = this.getDoubleFromBigDecimal(productPriceBO.getSalesPrice());
  38 + double vip1Price = productPriceBO.getVip1Price().doubleValue();
  39 + double vip2Price = productPriceBO.getVip2Price().doubleValue();
  40 + double vip3Price = productPriceBO.getVip3Price().doubleValue();
  41 + List<String> vipLevels = new ArrayList<String>();
  42 + if (vip1Price > 0 && vip1Price < salesPrice) {
  43 + vipLevels.add("1");
  44 + }
  45 + if (vip2Price > 0 && vip2Price < salesPrice) {
  46 + vipLevels.add("2");
36 } 47 }
  48 + if (vip3Price > 0 && vip3Price < salesPrice) {
  49 + vipLevels.add("3");
  50 + }
  51 + productPriceBO.setVipLevels(StringUtils.join(vipLevels, ","));
37 52
  53 + }
  54 +
  55 + /**
  56 + * salesPrice等于productPrice表的currentPrice,type是productPrice表的currentVipDiscountType
  57 + */
38 private VipPriceBO getVipPriceBO(BigDecimal salesPrice, BigDecimal vipPrice, BigDecimal vip1Price, BigDecimal vip2Price, BigDecimal vip3Price, Integer type, 58 private VipPriceBO getVipPriceBO(BigDecimal salesPrice, BigDecimal vipPrice, BigDecimal vip1Price, BigDecimal vip2Price, BigDecimal vip3Price, Integer type,
39 BigDecimal vipDiscount) { 59 BigDecimal vipDiscount) {
40 - double salesPricedoubleCeil = Math.ceil(this.getDoubleFromBigDecimal(salesPrice)); 60 + double salesPriceDoubleCeil = Math.ceil(this.getDoubleFromBigDecimal(salesPrice));
41 // 默认取销售价 61 // 默认取销售价
42 - double vip1PriceResult = salesPricedoubleCeil;  
43 - double vip2PriceResult = salesPricedoubleCeil;  
44 - double vip3PriceResult = salesPricedoubleCeil; 62 + double vip1PriceResult = salesPriceDoubleCeil;
  63 + double vip2PriceResult = salesPriceDoubleCeil;
  64 + double vip3PriceResult = salesPriceDoubleCeil;
45 if (type == null) { 65 if (type == null) {
46 return new VipPriceBO(vip1PriceResult, vip2PriceResult, vip3PriceResult); 66 return new VipPriceBO(vip1PriceResult, vip2PriceResult, vip3PriceResult);
47 } 67 }
48 switch (type) { 68 switch (type) {
49 case 1: 69 case 1:
50 - vip1PriceResult = Double.valueOf(String.format("%.2f", salesPricedoubleCeil * 0.95));  
51 - vip2PriceResult = Double.valueOf(String.format("%.2f", salesPricedoubleCeil * 0.9));  
52 - vip3PriceResult = Double.valueOf(String.format("%.2f", salesPricedoubleCeil * 0.88)); 70 + vip1PriceResult = Double.valueOf(String.format("%.2f", salesPriceDoubleCeil * 0.95));
  71 + vip2PriceResult = Double.valueOf(String.format("%.2f", salesPriceDoubleCeil * 0.9));
  72 + vip3PriceResult = Double.valueOf(String.format("%.2f", salesPriceDoubleCeil * 0.88));
53 break; 73 break;
54 case 2: 74 case 2:
55 if (!isVipDiscountLegal(vipDiscount)) { 75 if (!isVipDiscountLegal(vipDiscount)) {
56 vipDiscount = new BigDecimal(0.95); 76 vipDiscount = new BigDecimal(0.95);
57 } 77 }
58 - BigDecimal price = vipDiscount.multiply(BigDecimal.valueOf(salesPricedoubleCeil)); 78 + BigDecimal price = vipDiscount.multiply(BigDecimal.valueOf(salesPriceDoubleCeil));
59 vip1PriceResult = Double.valueOf(String.format("%.2f", price)); 79 vip1PriceResult = Double.valueOf(String.format("%.2f", price));
60 vip2PriceResult = Double.valueOf(String.format("%.2f", price)); 80 vip2PriceResult = Double.valueOf(String.format("%.2f", price));
61 vip3PriceResult = Double.valueOf(String.format("%.2f", price)); 81 vip3PriceResult = Double.valueOf(String.format("%.2f", price));
62 break; 82 break;
63 case 3: 83 case 3:
64 - vip1PriceResult = Double.valueOf(String.format("%.2f", salesPricedoubleCeil));  
65 - vip2PriceResult = Double.valueOf(String.format("%.2f", salesPricedoubleCeil));  
66 - vip3PriceResult = Double.valueOf(String.format("%.2f", salesPricedoubleCeil)); 84 + vip1PriceResult = Double.valueOf(String.format("%.2f", salesPriceDoubleCeil));
  85 + vip2PriceResult = Double.valueOf(String.format("%.2f", salesPriceDoubleCeil));
  86 + vip3PriceResult = Double.valueOf(String.format("%.2f", salesPriceDoubleCeil));
67 break; 87 break;
68 case 4: 88 case 4:
69 vip1PriceResult = this.getDoubleFromBigDecimal(vipPrice); 89 vip1PriceResult = this.getDoubleFromBigDecimal(vipPrice);
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.ArrayList;  
7 -import java.util.Date;  
8 -import java.util.List;  
9 -import java.util.Map;  
10 -import java.util.stream.Collectors;  
11 -  
12 -import org.apache.commons.lang.StringUtils;  
13 -import org.slf4j.Logger;  
14 -import org.slf4j.LoggerFactory;  
15 -import org.springframework.beans.factory.annotation.Autowired;  
16 -import org.springframework.stereotype.Component;  
17 -  
18 import com.yoho.search.base.utils.DateUtil; 3 import com.yoho.search.base.utils.DateUtil;
19 import com.yoho.search.base.utils.MathUtils; 4 import com.yoho.search.base.utils.MathUtils;
20 import com.yoho.search.consumer.service.bo.ProductIndexBO; 5 import com.yoho.search.consumer.service.bo.ProductIndexBO;
21 import com.yoho.search.consumer.service.bo.ProductPriceBO; 6 import com.yoho.search.consumer.service.bo.ProductPriceBO;
22 import com.yoho.search.consumer.service.logic.SpecialDealLogicService; 7 import com.yoho.search.consumer.service.logic.SpecialDealLogicService;
23 -import com.yoho.search.consumer.service.logic.VipPriceLogicServie; 8 +import com.yoho.search.consumer.service.logic.VipPriceLogicService;
24 import com.yoho.search.dal.ProductPriceMapper; 9 import com.yoho.search.dal.ProductPriceMapper;
25 import com.yoho.search.dal.model.ProductPrice; 10 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;
26 23
27 /** 24 /**
28 * Created by wangnan on 2017/1/6. 25 * Created by wangnan on 2017/1/6.
@@ -35,82 +32,99 @@ public class ProductPriceBuilder implements ViewBuilder { @@ -35,82 +32,99 @@ public class ProductPriceBuilder implements ViewBuilder {
35 @Autowired 32 @Autowired
36 private ProductPriceMapper productPriceMapper; 33 private ProductPriceMapper productPriceMapper;
37 @Autowired 34 @Autowired
38 - private VipPriceLogicServie vipPriceLogicServie; 35 + private VipPriceLogicService vipPriceLogicService;
39 @Autowired 36 @Autowired
40 private SpecialDealLogicService specialSearchFieldLogicService; 37 private SpecialDealLogicService specialSearchFieldLogicService;
41 38
42 @Override 39 @Override
43 public void build(List<ProductIndexBO> productIndexBOs, List<Integer> ids, List<Integer> sknList) { 40 public void build(List<ProductIndexBO> productIndexBOs, List<Integer> ids, List<Integer> sknList) {
44 - List<ProductPrice> productPrices = productPriceMapper.selectBySkns(sknList); 41 + List<ProductPrice> productPrices = productPriceMapper.selectBySknList(sknList);
45 Map<Integer, ProductPrice> productPricesMap = productPrices.stream().collect(Collectors.toMap(ProductPrice::getProductSkn, (p) -> p)); 42 Map<Integer, ProductPrice> productPricesMap = productPrices.stream().collect(Collectors.toMap(ProductPrice::getProductSkn, (p) -> p));
46 - for (ProductIndexBO pi : productIndexBOs) {  
47 - // set default  
48 - pi.setIsDiscount("N");  
49 - pi.setSpecialoffer("N");  
50 - pi.setPromotionDiscount(new BigDecimal(1));  
51 - pi.setPromotionDiscountInt(10L);  
52 -  
53 - pi.setIsStudentPrice("N");  
54 - pi.setIsStudentRebate("N");  
55 - pi.setIsnew("N");  
56 - 43 + for (ProductIndexBO productIndexBO : productIndexBOs) {
57 try { 44 try {
58 - // 如果价格不存在,则直接返回  
59 - ProductPrice productPrice = productPricesMap.get(pi.getProductSkn()); 45 + // 如果该skn对应价格对象不存在,直接跳过
  46 + ProductPrice productPrice = productPricesMap.get(productIndexBO.getProductSkn());
60 if (productPrice == null) { 47 if (productPrice == null) {
61 continue; 48 continue;
62 } 49 }
63 -  
64 // 构造ProductPriceBO 50 // 构造ProductPriceBO
65 ProductPriceBO productPriceBO = new ProductPriceBO(productPrice); 51 ProductPriceBO productPriceBO = new ProductPriceBO(productPrice);
66 - this.fillProductPriceBO(productPriceBO); 52 + this.buildProductPriceBO(productPriceBO);
  53 + // 构造ProductIndexBO
  54 + this.buildProductIndexBO(productIndexBO, productPriceBO);
  55 + } catch (Exception e) {
  56 + logger.error(e.getMessage(), e);
  57 + }
  58 + }
  59 + }
67 60
68 - pi.setMarketPrice(productPriceBO.getMarketPrice());  
69 - pi.setVipDiscountType(productPriceBO.getVipDiscountType());  
70 - pi.setSalesPrice(productPriceBO.getSalesPrice());  
71 - pi.setVipPrice(productPriceBO.getVipPrice());  
72 - pi.setVip1Price(productPriceBO.getVip1Price());  
73 - pi.setVip2Price(productPriceBO.getVip2Price());  
74 - pi.setVip3Price(productPriceBO.getVip3Price());  
75 - pi.setStudentPrice(productPriceBO.getStudentPrice()); 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());
  70 + 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 + }
76 85
  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());
77 // 折扣相关 102 // 折扣相关
78 - pi.setIsDiscount(productPriceBO.getIsDiscount());  
79 - pi.setSpecialoffer(productPriceBO.getSpecialoffer());  
80 - pi.setPromotionDiscountInt(productPriceBO.getPromotionDiscountInt());  
81 - pi.setPromotionDiscount(productPriceBO.getPromotionDiscount());  
82 - 103 + productIndexBO.setIsDiscount(productPriceBO.getIsDiscount());
  104 + productIndexBO.setSpecialoffer(productPriceBO.getSpecialoffer());
  105 + productIndexBO.setPromotionDiscountInt(productPriceBO.getPromotionDiscountInt());
  106 + productIndexBO.setPromotionDiscount(productPriceBO.getPromotionDiscount());
83 // 学生价相关字段 107 // 学生价相关字段
84 - pi.setIsStudentPrice(productPriceBO.getIsStudentPrice());  
85 - pi.setIsStudentRebate(productPriceBO.getIsstudentrebate());  
86 - 108 + productIndexBO.setIsStudentPrice(productPriceBO.getIsStudentPrice());
  109 + productIndexBO.setIsStudentRebate(productPriceBO.getIsstudentrebate());
87 // 设置vipLevels 110 // 设置vipLevels
88 - pi.setVipLevels(productPriceBO.getVipLevels());  
89 - 111 + productIndexBO.setVipLevels(productPriceBO.getVipLevels());
90 // 设置价格更新时间 112 // 设置价格更新时间
91 - pi.setPriceUpdateTime(productPriceBO.getUpdateTime());  
92 - 113 + productIndexBO.setPriceUpdateTime(productPriceBO.getUpdateTime());
93 // 设置最后一次降价时间 114 // 设置最后一次降价时间
94 - pi.setLastReducePriceTime(productPriceBO.getLastReducePriceTime());  
95 - 115 + productIndexBO.setLastReducePriceTime(productPriceBO.getLastReducePriceTime());
96 // 计算isNew(规则:首次上架7天内展示且折扣率大于等于88折) 116 // 计算isNew(规则:首次上架7天内展示且折扣率大于等于88折)
97 - pi.setIsnew("N");  
98 - if (this.isNew(pi.getFirstShelveTime(), pi.getMarketPrice(), pi.getSalesPrice())) {  
99 - pi.setIsnew("Y"); 117 + productIndexBO.setIsnew("N");
  118 + if (this.isNew(productIndexBO.getFirstShelveTime(), productIndexBO.getMarketPrice(), productIndexBO.getSalesPrice())) {
  119 + productIndexBO.setIsnew("Y");
100 } 120 }
101 - // 计算specialsearchfieldPrice  
102 - pi.setSpecialSearchFieldPrice(specialSearchFieldLogicService.getSpecialSearchFieldPrice(productPriceBO));  
103 - } catch (Exception e) {  
104 - logger.error(e.getMessage(), e); 121 + // 计算specialSearchFieldPrice
  122 + productIndexBO.setSpecialSearchFieldPrice(specialSearchFieldLogicService.getSpecialSearchFieldPrice(productPriceBO));
105 } 123 }
106 124
107 - }  
108 - }  
109 125
110 /** 126 /**
111 * isNew 标签逻辑 127 * isNew 标签逻辑
112 - *  
113 - * @return  
114 */ 128 */
115 public boolean isNew(Integer firstShelveTime, BigDecimal marketPrice, BigDecimal salesPrice) { 129 public boolean isNew(Integer firstShelveTime, BigDecimal marketPrice, BigDecimal salesPrice) {
116 try { 130 try {
@@ -132,46 +146,6 @@ public class ProductPriceBuilder implements ViewBuilder { @@ -132,46 +146,6 @@ public class ProductPriceBuilder implements ViewBuilder {
132 } 146 }
133 } 147 }
134 148
135 - public void fillProductPriceBO(ProductPriceBO productPriceBO) {  
136 - // 1、计算并重设vip相关价格  
137 - vipPriceLogicServie.fillProductPriceVipPrice(productPriceBO);  
138 -  
139 - // 2、计算折扣相关  
140 - double salesPrice = this.getDoubleFromBigDecimal(productPriceBO.getSalesPrice());  
141 - double marketPrice = this.getDoubleFromBigDecimal(productPriceBO.getMarketPrice());  
142 - productPriceBO.setIsDiscount(salesPrice < marketPrice ? "Y" : "N");  
143 - double specialOffer = this.divide(1, productPriceBO.getSalesPrice(), productPriceBO.getMarketPrice());  
144 - if (specialOffer <= 0.5) {  
145 - productPriceBO.setSpecialoffer("Y");  
146 - } else {  
147 - productPriceBO.setSpecialoffer("N");  
148 - }  
149 - double promotionDiscountInt = this.divide(1, productPriceBO.getSalesPrice().multiply(new BigDecimal(10)), productPriceBO.getMarketPrice());  
150 - productPriceBO.setPromotionDiscountInt((long) promotionDiscountInt);  
151 - double promotionDiscount = this.divide(3, productPriceBO.getSalesPrice(), productPriceBO.getMarketPrice());  
152 - productPriceBO.setPromotionDiscount(this.getBigDecimalFromDouble(promotionDiscount));  
153 -  
154 - // 3、设置学生价相关属性  
155 - productPriceBO.setIsStudentPrice(productPriceBO.getStudentPrice() != null ? "Y" : "N");  
156 - productPriceBO.setIsstudentrebate(productPriceBO.getStudentCoinRate() == null || productPriceBO.getStudentCoinRate().compareTo(BigDecimal.ZERO) == 0 ? "N" : "Y");  
157 -  
158 - // 4、设置vipLevels  
159 - double vip1Price = productPriceBO.getVip1Price().doubleValue();  
160 - double vip2Price = productPriceBO.getVip2Price().doubleValue();  
161 - double vip3Price = productPriceBO.getVip3Price().doubleValue();  
162 - List<String> vipLevels = new ArrayList<String>();  
163 - if (vip1Price > 0 && vip1Price < salesPrice) {  
164 - vipLevels.add("1");  
165 - }  
166 - if (vip2Price > 0 && vip2Price < salesPrice) {  
167 - vipLevels.add("2");  
168 - }  
169 - if (vip3Price > 0 && vip3Price < salesPrice) {  
170 - vipLevels.add("3");  
171 - }  
172 - productPriceBO.setVipLevels(StringUtils.join(vipLevels, ","));  
173 - }  
174 -  
175 private double divide(int scale, BigDecimal a, BigDecimal b) { 149 private double divide(int scale, BigDecimal a, BigDecimal b) {
176 if (b == null || b.compareTo(BigDecimal.ZERO) == 0) { 150 if (b == null || b.compareTo(BigDecimal.ZERO) == 0) {
177 return 0; 151 return 0;
@@ -199,5 +173,4 @@ public class ProductPriceBuilder implements ViewBuilder { @@ -199,5 +173,4 @@ public class ProductPriceBuilder implements ViewBuilder {
199 } 173 }
200 return new BigDecimal(d); 174 return new BigDecimal(d);
201 } 175 }
202 -  
203 } 176 }