1
|
package com.yoho.search.consumer.service.logic.productIndex.viewBuilder;
|
1
|
package com.yoho.search.consumer.service.logic.productIndex.viewBuilder;
|
2
|
|
2
|
|
3
|
-import com.yoho.search.base.utils.DateUtil;
|
|
|
4
|
-import com.yoho.search.base.utils.MathUtils;
|
|
|
5
|
-import com.yoho.search.consumer.service.bo.ProductIndexBO;
|
|
|
6
|
-import com.yoho.search.consumer.service.bo.ProductPriceBO;
|
|
|
7
|
-import com.yoho.search.dal.ProductPriceMapper;
|
|
|
8
|
-import com.yoho.search.dal.model.ProductPrice;
|
|
|
9
|
-import org.apache.commons.lang.StringUtils;
|
|
|
10
|
-import org.slf4j.Logger;
|
|
|
11
|
-import org.slf4j.LoggerFactory;
|
|
|
12
|
-import org.springframework.beans.factory.annotation.Autowired;
|
|
|
13
|
-import org.springframework.stereotype.Component;
|
|
|
14
|
-
|
|
|
15
|
import java.math.BigDecimal;
|
3
|
import java.math.BigDecimal;
|
16
|
import java.math.RoundingMode;
|
4
|
import java.math.RoundingMode;
|
17
|
import java.text.DecimalFormat;
|
5
|
import java.text.DecimalFormat;
|
|
@@ -21,6 +9,20 @@ import java.util.List; |
|
@@ -21,6 +9,20 @@ import java.util.List; |
21
|
import java.util.Map;
|
9
|
import java.util.Map;
|
22
|
import java.util.stream.Collectors;
|
10
|
import java.util.stream.Collectors;
|
23
|
|
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;
|
|
|
19
|
+import com.yoho.search.base.utils.MathUtils;
|
|
|
20
|
+import com.yoho.search.consumer.service.bo.ProductIndexBO;
|
|
|
21
|
+import com.yoho.search.consumer.service.bo.ProductPriceBO;
|
|
|
22
|
+import com.yoho.search.consumer.service.logic.VipPriceLogicServie;
|
|
|
23
|
+import com.yoho.search.dal.ProductPriceMapper;
|
|
|
24
|
+import com.yoho.search.dal.model.ProductPrice;
|
|
|
25
|
+
|
24
|
/**
|
26
|
/**
|
25
|
* Created by wangnan on 2017/1/6.
|
27
|
* Created by wangnan on 2017/1/6.
|
26
|
*/
|
28
|
*/
|
|
@@ -31,6 +33,8 @@ public class ProductPriceBuilder implements ViewBuilder { |
|
@@ -31,6 +33,8 @@ public class ProductPriceBuilder implements ViewBuilder { |
31
|
|
33
|
|
32
|
@Autowired
|
34
|
@Autowired
|
33
|
private ProductPriceMapper productPriceMapper;
|
35
|
private ProductPriceMapper productPriceMapper;
|
|
|
36
|
+ @Autowired
|
|
|
37
|
+ private VipPriceLogicServie vipPriceLogicServie;
|
34
|
|
38
|
|
35
|
@Override
|
39
|
@Override
|
36
|
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) {
|
|
@@ -42,7 +46,7 @@ public class ProductPriceBuilder implements ViewBuilder { |
|
@@ -42,7 +46,7 @@ public class ProductPriceBuilder implements ViewBuilder { |
42
|
pi.setSpecialoffer("N");
|
46
|
pi.setSpecialoffer("N");
|
43
|
pi.setPromotionDiscount(new BigDecimal(1));
|
47
|
pi.setPromotionDiscount(new BigDecimal(1));
|
44
|
pi.setPromotionDiscountInt(10L);
|
48
|
pi.setPromotionDiscountInt(10L);
|
45
|
-
|
49
|
+
|
46
|
pi.setIsStudentPrice("N");
|
50
|
pi.setIsStudentPrice("N");
|
47
|
pi.setIsStudentRebate("N");
|
51
|
pi.setIsStudentRebate("N");
|
48
|
pi.setIsnew("N");
|
52
|
pi.setIsnew("N");
|
|
@@ -92,7 +96,7 @@ public class ProductPriceBuilder implements ViewBuilder { |
|
@@ -92,7 +96,7 @@ public class ProductPriceBuilder implements ViewBuilder { |
92
|
pi.setIsnew("Y");
|
96
|
pi.setIsnew("Y");
|
93
|
}
|
97
|
}
|
94
|
} catch (Exception e) {
|
98
|
} catch (Exception e) {
|
95
|
- logger.error(e.getMessage(),e);
|
99
|
+ logger.error(e.getMessage(), e);
|
96
|
}
|
100
|
}
|
97
|
|
101
|
|
98
|
}
|
102
|
}
|
|
@@ -123,84 +127,13 @@ public class ProductPriceBuilder implements ViewBuilder { |
|
@@ -123,84 +127,13 @@ public class ProductPriceBuilder implements ViewBuilder { |
123
|
}
|
127
|
}
|
124
|
}
|
128
|
}
|
125
|
|
129
|
|
126
|
- private double getDoubleFromBigDecimal(BigDecimal bigDecimal) {
|
|
|
127
|
- if (bigDecimal == null) {
|
|
|
128
|
- return 0d;
|
|
|
129
|
- }
|
|
|
130
|
- return bigDecimal.doubleValue();
|
|
|
131
|
- }
|
|
|
132
|
-
|
|
|
133
|
- private BigDecimal getBigDecimalFromDouble(Double d) {
|
|
|
134
|
- if (d == null) {
|
|
|
135
|
- return new BigDecimal(0);
|
|
|
136
|
- }
|
|
|
137
|
- return new BigDecimal(d);
|
|
|
138
|
- }
|
|
|
139
|
-
|
|
|
140
|
- private boolean vipPriceLimit = false;// 是否执行vip价格限制
|
|
|
141
|
-
|
|
|
142
|
public void fillProductPriceBO(ProductPriceBO productPriceBO) {
|
130
|
public void fillProductPriceBO(ProductPriceBO productPriceBO) {
|
143
|
- double marketPrice = this.getDoubleFromBigDecimal(productPriceBO.getMarketPrice());
|
131
|
+ // 1、计算并重设vip相关价格
|
|
|
132
|
+ vipPriceLogicServie.fillProductPriceVipPrice(productPriceBO);
|
|
|
133
|
+
|
|
|
134
|
+ // 2、计算折扣相关
|
144
|
double salesPrice = this.getDoubleFromBigDecimal(productPriceBO.getSalesPrice());
|
135
|
double salesPrice = this.getDoubleFromBigDecimal(productPriceBO.getSalesPrice());
|
145
|
- double vipPrice = vipPriceLimit ? salesPrice : this.getDoubleFromBigDecimal(productPriceBO.getVipPrice());
|
|
|
146
|
- double vip1Price = salesPrice;
|
|
|
147
|
- double vip2Price = salesPrice;
|
|
|
148
|
- double vip3Price = salesPrice;
|
|
|
149
|
-
|
|
|
150
|
- // 判断是否需要计算vip价格
|
|
|
151
|
- boolean needCalVipPrice = productPriceBO.getVipDiscountType() != null;
|
|
|
152
|
- // 如果开启了vip限制,
|
|
|
153
|
- if (vipPriceLimit) {
|
|
|
154
|
- needCalVipPrice = needCalVipPrice && (salesPrice == marketPrice) && (productPriceBO.getProductVipStatus() == 1);
|
|
|
155
|
- }
|
|
|
156
|
- if (needCalVipPrice) {
|
|
|
157
|
- switch (productPriceBO.getVipDiscountType()) {
|
|
|
158
|
- case 1:
|
|
|
159
|
- vip1Price = Double.parseDouble(String.format("%.2f", Math.ceil(salesPrice) * 0.95));
|
|
|
160
|
- vip2Price = Double.parseDouble(String.format("%.2f", Math.ceil(salesPrice) * 0.9));
|
|
|
161
|
- vip3Price = Double.parseDouble(String.format("%.2f", Math.ceil(salesPrice) * 0.88));
|
|
|
162
|
- break;
|
|
|
163
|
- case 2:
|
|
|
164
|
- if(productPriceBO.getVipDiscount()!=null){
|
|
|
165
|
- boolean gt0 = productPriceBO.getVipDiscount().compareTo(BigDecimal.ZERO)==1;
|
|
|
166
|
- boolean lt1 = productPriceBO.getVipDiscount().compareTo(BigDecimal.ONE)==-1;
|
|
|
167
|
- if(gt0&<1){
|
|
|
168
|
- BigDecimal price = productPriceBO.getVipDiscount().multiply(BigDecimal.valueOf(Math.ceil(salesPrice)));
|
|
|
169
|
- vip1Price = Double.parseDouble(String.format("%.2f", price));
|
|
|
170
|
- vip2Price = Double.parseDouble(String.format("%.2f", price));
|
|
|
171
|
- vip3Price = Double.parseDouble(String.format("%.2f", price));
|
|
|
172
|
- }
|
|
|
173
|
- }
|
|
|
174
|
- else{
|
|
|
175
|
- vip1Price = Double.parseDouble(String.format("%.2f", Math.ceil(salesPrice) * 0.95));
|
|
|
176
|
- vip2Price = Double.parseDouble(String.format("%.2f", Math.ceil(salesPrice) * 0.95));
|
|
|
177
|
- vip3Price = Double.parseDouble(String.format("%.2f", Math.ceil(salesPrice) * 0.95));
|
|
|
178
|
- }
|
|
|
179
|
- break;
|
|
|
180
|
- case 3:
|
|
|
181
|
- vip1Price = Double.parseDouble(String.format("%.2f", Math.ceil(salesPrice)));
|
|
|
182
|
- vip2Price = Double.parseDouble(String.format("%.2f", Math.ceil(salesPrice)));
|
|
|
183
|
- vip3Price = Double.parseDouble(String.format("%.2f", Math.ceil(salesPrice)));
|
|
|
184
|
- break;
|
|
|
185
|
- case 4:
|
|
|
186
|
- vip1Price = vipPrice;
|
|
|
187
|
- vip2Price = vipPrice;
|
|
|
188
|
- vip3Price = vipPrice;
|
|
|
189
|
- break;
|
|
|
190
|
- case 5:
|
|
|
191
|
- vip1Price = this.getDoubleFromBigDecimal(productPriceBO.getVip1Price());
|
|
|
192
|
- vip2Price = this.getDoubleFromBigDecimal(productPriceBO.getVip2Price());
|
|
|
193
|
- vip3Price = this.getDoubleFromBigDecimal(productPriceBO.getVip3Price());
|
|
|
194
|
- break;
|
|
|
195
|
- }
|
|
|
196
|
- }
|
|
|
197
|
- productPriceBO.setSalesPrice(this.getBigDecimalFromDouble(salesPrice));
|
|
|
198
|
- productPriceBO.setVipPrice(this.getBigDecimalFromDouble(vipPrice));
|
|
|
199
|
- productPriceBO.setVip1Price(this.getBigDecimalFromDouble(vip1Price));
|
|
|
200
|
- productPriceBO.setVip2Price(this.getBigDecimalFromDouble(vip2Price));
|
|
|
201
|
- productPriceBO.setVip3Price(this.getBigDecimalFromDouble(vip3Price));
|
|
|
202
|
-
|
|
|
203
|
- // 折扣相关
|
136
|
+ double marketPrice = this.getDoubleFromBigDecimal(productPriceBO.getMarketPrice());
|
204
|
productPriceBO.setIsDiscount(salesPrice < marketPrice ? "Y" : "N");
|
137
|
productPriceBO.setIsDiscount(salesPrice < marketPrice ? "Y" : "N");
|
205
|
double specialOffer = this.divide(1, productPriceBO.getSalesPrice(), productPriceBO.getMarketPrice());
|
138
|
double specialOffer = this.divide(1, productPriceBO.getSalesPrice(), productPriceBO.getMarketPrice());
|
206
|
if (specialOffer <= 0.5) {
|
139
|
if (specialOffer <= 0.5) {
|
|
@@ -213,11 +146,14 @@ public class ProductPriceBuilder implements ViewBuilder { |
|
@@ -213,11 +146,14 @@ public class ProductPriceBuilder implements ViewBuilder { |
213
|
double promotionDiscount = this.divide(3, productPriceBO.getSalesPrice(), productPriceBO.getMarketPrice());
|
146
|
double promotionDiscount = this.divide(3, productPriceBO.getSalesPrice(), productPriceBO.getMarketPrice());
|
214
|
productPriceBO.setPromotionDiscount(this.getBigDecimalFromDouble(promotionDiscount));
|
147
|
productPriceBO.setPromotionDiscount(this.getBigDecimalFromDouble(promotionDiscount));
|
215
|
|
148
|
|
216
|
- // 设置学生价相关属性
|
149
|
+ // 3、设置学生价相关属性
|
217
|
productPriceBO.setIsStudentPrice(productPriceBO.getStudentPrice() != null ? "Y" : "N");
|
150
|
productPriceBO.setIsStudentPrice(productPriceBO.getStudentPrice() != null ? "Y" : "N");
|
218
|
productPriceBO.setIsstudentrebate(productPriceBO.getStudentCoinRate() == null || productPriceBO.getStudentCoinRate().compareTo(BigDecimal.ZERO) == 0 ? "N" : "Y");
|
151
|
productPriceBO.setIsstudentrebate(productPriceBO.getStudentCoinRate() == null || productPriceBO.getStudentCoinRate().compareTo(BigDecimal.ZERO) == 0 ? "N" : "Y");
|
219
|
|
152
|
|
220
|
- // 设置vipLevels
|
153
|
+ // 4、设置vipLevels
|
|
|
154
|
+ double vip1Price = productPriceBO.getVip1Price().doubleValue();
|
|
|
155
|
+ double vip2Price = productPriceBO.getVip2Price().doubleValue();
|
|
|
156
|
+ double vip3Price = productPriceBO.getVip3Price().doubleValue();
|
221
|
List<String> vipLevels = new ArrayList<String>();
|
157
|
List<String> vipLevels = new ArrayList<String>();
|
222
|
if (vip1Price > 0 && vip1Price < salesPrice) {
|
158
|
if (vip1Price > 0 && vip1Price < salesPrice) {
|
223
|
vipLevels.add("1");
|
159
|
vipLevels.add("1");
|
|
@@ -229,7 +165,6 @@ public class ProductPriceBuilder implements ViewBuilder { |
|
@@ -229,7 +165,6 @@ public class ProductPriceBuilder implements ViewBuilder { |
229
|
vipLevels.add("3");
|
165
|
vipLevels.add("3");
|
230
|
}
|
166
|
}
|
231
|
productPriceBO.setVipLevels(StringUtils.join(vipLevels, ","));
|
167
|
productPriceBO.setVipLevels(StringUtils.join(vipLevels, ","));
|
232
|
-
|
|
|
233
|
}
|
168
|
}
|
234
|
|
169
|
|
235
|
private double divide(int scale, BigDecimal a, BigDecimal b) {
|
170
|
private double divide(int scale, BigDecimal a, BigDecimal b) {
|
|
@@ -246,4 +181,18 @@ public class ProductPriceBuilder implements ViewBuilder { |
|
@@ -246,4 +181,18 @@ public class ProductPriceBuilder implements ViewBuilder { |
246
|
return Double.parseDouble(result);
|
181
|
return Double.parseDouble(result);
|
247
|
}
|
182
|
}
|
248
|
|
183
|
|
|
|
184
|
+ private double getDoubleFromBigDecimal(BigDecimal bigDecimal) {
|
|
|
185
|
+ if (bigDecimal == null) {
|
|
|
186
|
+ return 0d;
|
|
|
187
|
+ }
|
|
|
188
|
+ return bigDecimal.doubleValue();
|
|
|
189
|
+ }
|
|
|
190
|
+
|
|
|
191
|
+ private BigDecimal getBigDecimalFromDouble(Double d) {
|
|
|
192
|
+ if (d == null) {
|
|
|
193
|
+ return new BigDecimal(0);
|
|
|
194
|
+ }
|
|
|
195
|
+ return new BigDecimal(d);
|
|
|
196
|
+ }
|
|
|
197
|
+
|
249
|
} |
198
|
} |