|
|
package com.yoho.search.consumer.service.logic.productIndex.viewBuilder;
|
|
|
|
|
|
import com.yoho.search.base.utils.DateUtil;
|
|
|
import com.yoho.search.base.utils.MathUtils;
|
|
|
import com.yoho.search.consumer.service.bo.ProductIndexBO;
|
|
|
import com.yoho.search.consumer.service.bo.ProductPriceBO;
|
|
|
import com.yoho.search.dal.ProductPriceMapper;
|
|
|
import com.yoho.search.dal.model.ProductPrice;
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
import java.math.RoundingMode;
|
|
|
import java.text.DecimalFormat;
|
...
|
...
|
@@ -21,6 +9,20 @@ import java.util.List; |
|
|
import java.util.Map;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
import com.yoho.search.base.utils.DateUtil;
|
|
|
import com.yoho.search.base.utils.MathUtils;
|
|
|
import com.yoho.search.consumer.service.bo.ProductIndexBO;
|
|
|
import com.yoho.search.consumer.service.bo.ProductPriceBO;
|
|
|
import com.yoho.search.consumer.service.logic.VipPriceLogicServie;
|
|
|
import com.yoho.search.dal.ProductPriceMapper;
|
|
|
import com.yoho.search.dal.model.ProductPrice;
|
|
|
|
|
|
/**
|
|
|
* Created by wangnan on 2017/1/6.
|
|
|
*/
|
...
|
...
|
@@ -31,6 +33,8 @@ public class ProductPriceBuilder implements ViewBuilder { |
|
|
|
|
|
@Autowired
|
|
|
private ProductPriceMapper productPriceMapper;
|
|
|
@Autowired
|
|
|
private VipPriceLogicServie vipPriceLogicServie;
|
|
|
|
|
|
@Override
|
|
|
public void build(List<ProductIndexBO> productIndexBOs, List<Integer> ids, List<Integer> sknList) {
|
...
|
...
|
@@ -42,7 +46,7 @@ public class ProductPriceBuilder implements ViewBuilder { |
|
|
pi.setSpecialoffer("N");
|
|
|
pi.setPromotionDiscount(new BigDecimal(1));
|
|
|
pi.setPromotionDiscountInt(10L);
|
|
|
|
|
|
|
|
|
pi.setIsStudentPrice("N");
|
|
|
pi.setIsStudentRebate("N");
|
|
|
pi.setIsnew("N");
|
...
|
...
|
@@ -92,7 +96,7 @@ public class ProductPriceBuilder implements ViewBuilder { |
|
|
pi.setIsnew("Y");
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
|
logger.error(e.getMessage(),e);
|
|
|
logger.error(e.getMessage(), e);
|
|
|
}
|
|
|
|
|
|
}
|
...
|
...
|
@@ -123,84 +127,13 @@ public class ProductPriceBuilder implements ViewBuilder { |
|
|
}
|
|
|
}
|
|
|
|
|
|
private double getDoubleFromBigDecimal(BigDecimal bigDecimal) {
|
|
|
if (bigDecimal == null) {
|
|
|
return 0d;
|
|
|
}
|
|
|
return bigDecimal.doubleValue();
|
|
|
}
|
|
|
|
|
|
private BigDecimal getBigDecimalFromDouble(Double d) {
|
|
|
if (d == null) {
|
|
|
return new BigDecimal(0);
|
|
|
}
|
|
|
return new BigDecimal(d);
|
|
|
}
|
|
|
|
|
|
private boolean vipPriceLimit = false;// 是否执行vip价格限制
|
|
|
|
|
|
public void fillProductPriceBO(ProductPriceBO productPriceBO) {
|
|
|
double marketPrice = this.getDoubleFromBigDecimal(productPriceBO.getMarketPrice());
|
|
|
// 1、计算并重设vip相关价格
|
|
|
vipPriceLogicServie.fillProductPriceVipPrice(productPriceBO);
|
|
|
|
|
|
// 2、计算折扣相关
|
|
|
double salesPrice = this.getDoubleFromBigDecimal(productPriceBO.getSalesPrice());
|
|
|
double vipPrice = vipPriceLimit ? salesPrice : this.getDoubleFromBigDecimal(productPriceBO.getVipPrice());
|
|
|
double vip1Price = salesPrice;
|
|
|
double vip2Price = salesPrice;
|
|
|
double vip3Price = salesPrice;
|
|
|
|
|
|
// 判断是否需要计算vip价格
|
|
|
boolean needCalVipPrice = productPriceBO.getVipDiscountType() != null;
|
|
|
// 如果开启了vip限制,
|
|
|
if (vipPriceLimit) {
|
|
|
needCalVipPrice = needCalVipPrice && (salesPrice == marketPrice) && (productPriceBO.getProductVipStatus() == 1);
|
|
|
}
|
|
|
if (needCalVipPrice) {
|
|
|
switch (productPriceBO.getVipDiscountType()) {
|
|
|
case 1:
|
|
|
vip1Price = Double.parseDouble(String.format("%.2f", Math.ceil(salesPrice) * 0.95));
|
|
|
vip2Price = Double.parseDouble(String.format("%.2f", Math.ceil(salesPrice) * 0.9));
|
|
|
vip3Price = Double.parseDouble(String.format("%.2f", Math.ceil(salesPrice) * 0.88));
|
|
|
break;
|
|
|
case 2:
|
|
|
if(productPriceBO.getVipDiscount()!=null){
|
|
|
boolean gt0 = productPriceBO.getVipDiscount().compareTo(BigDecimal.ZERO)==1;
|
|
|
boolean lt1 = productPriceBO.getVipDiscount().compareTo(BigDecimal.ONE)==-1;
|
|
|
if(gt0&<1){
|
|
|
BigDecimal price = productPriceBO.getVipDiscount().multiply(BigDecimal.valueOf(Math.ceil(salesPrice)));
|
|
|
vip1Price = Double.parseDouble(String.format("%.2f", price));
|
|
|
vip2Price = Double.parseDouble(String.format("%.2f", price));
|
|
|
vip3Price = Double.parseDouble(String.format("%.2f", price));
|
|
|
}
|
|
|
}
|
|
|
else{
|
|
|
vip1Price = Double.parseDouble(String.format("%.2f", Math.ceil(salesPrice) * 0.95));
|
|
|
vip2Price = Double.parseDouble(String.format("%.2f", Math.ceil(salesPrice) * 0.95));
|
|
|
vip3Price = Double.parseDouble(String.format("%.2f", Math.ceil(salesPrice) * 0.95));
|
|
|
}
|
|
|
break;
|
|
|
case 3:
|
|
|
vip1Price = Double.parseDouble(String.format("%.2f", Math.ceil(salesPrice)));
|
|
|
vip2Price = Double.parseDouble(String.format("%.2f", Math.ceil(salesPrice)));
|
|
|
vip3Price = Double.parseDouble(String.format("%.2f", Math.ceil(salesPrice)));
|
|
|
break;
|
|
|
case 4:
|
|
|
vip1Price = vipPrice;
|
|
|
vip2Price = vipPrice;
|
|
|
vip3Price = vipPrice;
|
|
|
break;
|
|
|
case 5:
|
|
|
vip1Price = this.getDoubleFromBigDecimal(productPriceBO.getVip1Price());
|
|
|
vip2Price = this.getDoubleFromBigDecimal(productPriceBO.getVip2Price());
|
|
|
vip3Price = this.getDoubleFromBigDecimal(productPriceBO.getVip3Price());
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
productPriceBO.setSalesPrice(this.getBigDecimalFromDouble(salesPrice));
|
|
|
productPriceBO.setVipPrice(this.getBigDecimalFromDouble(vipPrice));
|
|
|
productPriceBO.setVip1Price(this.getBigDecimalFromDouble(vip1Price));
|
|
|
productPriceBO.setVip2Price(this.getBigDecimalFromDouble(vip2Price));
|
|
|
productPriceBO.setVip3Price(this.getBigDecimalFromDouble(vip3Price));
|
|
|
|
|
|
// 折扣相关
|
|
|
double marketPrice = this.getDoubleFromBigDecimal(productPriceBO.getMarketPrice());
|
|
|
productPriceBO.setIsDiscount(salesPrice < marketPrice ? "Y" : "N");
|
|
|
double specialOffer = this.divide(1, productPriceBO.getSalesPrice(), productPriceBO.getMarketPrice());
|
|
|
if (specialOffer <= 0.5) {
|
...
|
...
|
@@ -213,11 +146,14 @@ public class ProductPriceBuilder implements ViewBuilder { |
|
|
double promotionDiscount = this.divide(3, productPriceBO.getSalesPrice(), productPriceBO.getMarketPrice());
|
|
|
productPriceBO.setPromotionDiscount(this.getBigDecimalFromDouble(promotionDiscount));
|
|
|
|
|
|
// 设置学生价相关属性
|
|
|
// 3、设置学生价相关属性
|
|
|
productPriceBO.setIsStudentPrice(productPriceBO.getStudentPrice() != null ? "Y" : "N");
|
|
|
productPriceBO.setIsstudentrebate(productPriceBO.getStudentCoinRate() == null || productPriceBO.getStudentCoinRate().compareTo(BigDecimal.ZERO) == 0 ? "N" : "Y");
|
|
|
|
|
|
// 设置vipLevels
|
|
|
// 4、设置vipLevels
|
|
|
double vip1Price = productPriceBO.getVip1Price().doubleValue();
|
|
|
double vip2Price = productPriceBO.getVip2Price().doubleValue();
|
|
|
double vip3Price = productPriceBO.getVip3Price().doubleValue();
|
|
|
List<String> vipLevels = new ArrayList<String>();
|
|
|
if (vip1Price > 0 && vip1Price < salesPrice) {
|
|
|
vipLevels.add("1");
|
...
|
...
|
@@ -229,7 +165,6 @@ public class ProductPriceBuilder implements ViewBuilder { |
|
|
vipLevels.add("3");
|
|
|
}
|
|
|
productPriceBO.setVipLevels(StringUtils.join(vipLevels, ","));
|
|
|
|
|
|
}
|
|
|
|
|
|
private double divide(int scale, BigDecimal a, BigDecimal b) {
|
...
|
...
|
@@ -246,4 +181,18 @@ public class ProductPriceBuilder implements ViewBuilder { |
|
|
return Double.parseDouble(result);
|
|
|
}
|
|
|
|
|
|
private double getDoubleFromBigDecimal(BigDecimal bigDecimal) {
|
|
|
if (bigDecimal == null) {
|
|
|
return 0d;
|
|
|
}
|
|
|
return bigDecimal.doubleValue();
|
|
|
}
|
|
|
|
|
|
private BigDecimal getBigDecimalFromDouble(Double d) {
|
|
|
if (d == null) {
|
|
|
return new BigDecimal(0);
|
|
|
}
|
|
|
return new BigDecimal(d);
|
|
|
}
|
|
|
|
|
|
} |
...
|
...
|
|