currentvipdiscounttype需求
Showing
8 changed files
with
423 additions
and
417 deletions
@@ -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 | } |
@@ -6,220 +6,229 @@ import java.math.BigDecimal; | @@ -6,220 +6,229 @@ import java.math.BigDecimal; | ||
6 | 6 | ||
7 | public class ProductPriceBO { | 7 | public class ProductPriceBO { |
8 | 8 | ||
9 | - private BigDecimal marketPrice; | ||
10 | - private BigDecimal salesPrice; | ||
11 | - private BigDecimal vipPrice; | ||
12 | - private Integer vipDiscountType; | ||
13 | - private BigDecimal vip1Price; | ||
14 | - private BigDecimal vip2Price; | ||
15 | - private BigDecimal vip3Price; | ||
16 | - private BigDecimal studentPrice; | ||
17 | - private BigDecimal studentCoinRate; | ||
18 | - private Integer updateTime; | ||
19 | - private Integer lastReducePriceTime; | ||
20 | - private BigDecimal basicPrice; | ||
21 | - private Integer productVipStatus; | ||
22 | - private BigDecimal vipDiscount; | ||
23 | - | ||
24 | - // others | ||
25 | - private String isDiscount; | ||
26 | - private String specialoffer; | ||
27 | - private Long promotionDiscountInt; | ||
28 | - private BigDecimal promotionDiscount; | ||
29 | - private String isStudentPrice; | ||
30 | - private String isstudentrebate; | ||
31 | - private String vipLevels; | ||
32 | - | ||
33 | - public ProductPriceBO(ProductPrice productPrice) { | ||
34 | - super(); | ||
35 | - this.marketPrice = productPrice.getRetailPrice();// 吊牌价 | ||
36 | - | ||
37 | - BigDecimal currentPrice = productPrice.getCurrentPrice();// 综合了变价计划和商品售价的结果,生成的逻辑完全由后台控制。 | ||
38 | - if (currentPrice != null && currentPrice.compareTo(BigDecimal.ZERO) == 1) { | ||
39 | - this.salesPrice = currentPrice; | ||
40 | - } else { | ||
41 | - this.salesPrice = productPrice.getSalesPrice();// 兜底方案 | ||
42 | - } | ||
43 | - this.vipPrice = productPrice.getVipPrice(); | ||
44 | - this.vipDiscountType = productPrice.getVipDiscountType(); | ||
45 | - this.vip1Price = productPrice.getVip1Price(); | ||
46 | - this.vip2Price = productPrice.getVip2Price(); | ||
47 | - this.vip3Price = productPrice.getVip3Price(); | ||
48 | - this.studentPrice = productPrice.getStudentPrice(); | ||
49 | - this.studentCoinRate = productPrice.getStudentCoinRate(); | ||
50 | - this.updateTime = productPrice.getUpdateTime(); | ||
51 | - this.lastReducePriceTime = productPrice.getLastReducePriceTime(); | ||
52 | - this.basicPrice = productPrice.getBasicPrice(); | ||
53 | - this.productVipStatus = productPrice.getProductVipStatus(); | ||
54 | - this.vipDiscount = productPrice.getVipDiscount(); | ||
55 | - } | ||
56 | - | ||
57 | - public BigDecimal getVipDiscount() { | ||
58 | - return vipDiscount; | ||
59 | - } | ||
60 | - | ||
61 | - public void setVipDiscount(BigDecimal vipDiscount) { | ||
62 | - this.vipDiscount = vipDiscount; | ||
63 | - } | ||
64 | - | ||
65 | - public Integer getLastReducePriceTime() { | ||
66 | - return lastReducePriceTime; | ||
67 | - } | ||
68 | - | ||
69 | - public void setLastReducePriceTime(Integer lastReducePriceTime) { | ||
70 | - this.lastReducePriceTime = lastReducePriceTime; | ||
71 | - } | ||
72 | - | ||
73 | - public BigDecimal getMarketPrice() { | ||
74 | - return marketPrice; | ||
75 | - } | ||
76 | - | ||
77 | - public void setMarketPrice(BigDecimal marketPrice) { | ||
78 | - this.marketPrice = marketPrice; | ||
79 | - } | ||
80 | - | ||
81 | - public BigDecimal getSalesPrice() { | ||
82 | - return salesPrice; | ||
83 | - } | ||
84 | - | ||
85 | - public void setSalesPrice(BigDecimal salesPrice) { | ||
86 | - this.salesPrice = salesPrice; | ||
87 | - } | ||
88 | - | ||
89 | - public BigDecimal getVipPrice() { | ||
90 | - return vipPrice; | ||
91 | - } | ||
92 | - | ||
93 | - public void setVipPrice(BigDecimal vipPrice) { | ||
94 | - this.vipPrice = vipPrice; | ||
95 | - } | ||
96 | - | ||
97 | - public Integer getVipDiscountType() { | ||
98 | - return vipDiscountType; | ||
99 | - } | ||
100 | - | ||
101 | - public void setVipDiscountType(Integer vipDiscountType) { | ||
102 | - this.vipDiscountType = vipDiscountType; | ||
103 | - } | ||
104 | - | ||
105 | - public BigDecimal getVip1Price() { | ||
106 | - return vip1Price; | ||
107 | - } | ||
108 | - | ||
109 | - public void setVip1Price(BigDecimal vip1Price) { | ||
110 | - this.vip1Price = vip1Price; | ||
111 | - } | ||
112 | - | ||
113 | - public BigDecimal getVip2Price() { | ||
114 | - return vip2Price; | ||
115 | - } | ||
116 | - | ||
117 | - public void setVip2Price(BigDecimal vip2Price) { | ||
118 | - this.vip2Price = vip2Price; | ||
119 | - } | ||
120 | - | ||
121 | - public BigDecimal getVip3Price() { | ||
122 | - return vip3Price; | ||
123 | - } | ||
124 | - | ||
125 | - public void setVip3Price(BigDecimal vip3Price) { | ||
126 | - this.vip3Price = vip3Price; | ||
127 | - } | ||
128 | - | ||
129 | - public BigDecimal getStudentPrice() { | ||
130 | - return studentPrice; | ||
131 | - } | ||
132 | - | ||
133 | - public void setStudentPrice(BigDecimal studentPrice) { | ||
134 | - this.studentPrice = studentPrice; | ||
135 | - } | ||
136 | - | ||
137 | - public BigDecimal getStudentCoinRate() { | ||
138 | - return studentCoinRate; | ||
139 | - } | ||
140 | - | ||
141 | - public void setStudentCoinRate(BigDecimal studentCoinRate) { | ||
142 | - this.studentCoinRate = studentCoinRate; | ||
143 | - } | ||
144 | - | ||
145 | - public String getIsDiscount() { | ||
146 | - return isDiscount; | ||
147 | - } | ||
148 | - | ||
149 | - public void setIsDiscount(String isDiscount) { | ||
150 | - this.isDiscount = isDiscount; | ||
151 | - } | ||
152 | - | ||
153 | - public String getSpecialoffer() { | ||
154 | - return specialoffer; | ||
155 | - } | 9 | + private BigDecimal marketPrice; |
10 | + private BigDecimal salesPrice; | ||
11 | + private BigDecimal vipPrice; | ||
12 | + private Integer vipDiscountType; | ||
13 | + private BigDecimal vip1Price; | ||
14 | + private BigDecimal vip2Price; | ||
15 | + private BigDecimal vip3Price; | ||
16 | + private BigDecimal studentPrice; | ||
17 | + private BigDecimal studentCoinRate; | ||
18 | + private Integer updateTime; | ||
19 | + private Integer lastReducePriceTime; | ||
20 | + private BigDecimal basicPrice; | ||
21 | + private Integer productVipStatus; | ||
22 | + private BigDecimal vipDiscount; | ||
23 | + private Integer currentVipDiscountType; | ||
24 | + | ||
25 | + // others | ||
26 | + private String isDiscount; | ||
27 | + private String specialoffer; | ||
28 | + private Long promotionDiscountInt; | ||
29 | + private BigDecimal promotionDiscount; | ||
30 | + private String isStudentPrice; | ||
31 | + private String isstudentrebate; | ||
32 | + private String vipLevels; | ||
33 | + | ||
34 | + public ProductPriceBO(ProductPrice productPrice) { | ||
35 | + super(); | ||
36 | + this.marketPrice = productPrice.getRetailPrice();// 吊牌价 | ||
37 | + BigDecimal currentPrice = productPrice.getCurrentPrice();// 综合了变价计划和商品售价的结果,生成的逻辑完全由后台控制。 | ||
38 | + if (currentPrice != null && currentPrice.compareTo(BigDecimal.ZERO) == 1) { | ||
39 | + this.salesPrice = currentPrice; | ||
40 | + } else { | ||
41 | + this.salesPrice = productPrice.getSalesPrice();// 兜底方案 | ||
42 | + } | ||
43 | + this.vipPrice = productPrice.getVipPrice(); | ||
44 | + this.vipDiscountType = productPrice.getVipDiscountType(); | ||
45 | + this.vip1Price = productPrice.getVip1Price(); | ||
46 | + this.vip2Price = productPrice.getVip2Price(); | ||
47 | + this.vip3Price = productPrice.getVip3Price(); | ||
48 | + this.studentPrice = productPrice.getStudentPrice(); | ||
49 | + this.studentCoinRate = productPrice.getStudentCoinRate(); | ||
50 | + this.updateTime = productPrice.getUpdateTime(); | ||
51 | + this.lastReducePriceTime = productPrice.getLastReducePriceTime(); | ||
52 | + this.basicPrice = productPrice.getBasicPrice(); | ||
53 | + this.productVipStatus = productPrice.getProductVipStatus(); | ||
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; | ||
64 | + } | ||
65 | + | ||
66 | + public BigDecimal getVipDiscount() { | ||
67 | + return vipDiscount; | ||
68 | + } | ||
69 | + | ||
70 | + public void setVipDiscount(BigDecimal vipDiscount) { | ||
71 | + this.vipDiscount = vipDiscount; | ||
72 | + } | ||
73 | + | ||
74 | + public Integer getLastReducePriceTime() { | ||
75 | + return lastReducePriceTime; | ||
76 | + } | ||
77 | + | ||
78 | + public void setLastReducePriceTime(Integer lastReducePriceTime) { | ||
79 | + this.lastReducePriceTime = lastReducePriceTime; | ||
80 | + } | ||
81 | + | ||
82 | + public BigDecimal getMarketPrice() { | ||
83 | + return marketPrice; | ||
84 | + } | ||
85 | + | ||
86 | + public void setMarketPrice(BigDecimal marketPrice) { | ||
87 | + this.marketPrice = marketPrice; | ||
88 | + } | ||
89 | + | ||
90 | + public BigDecimal getSalesPrice() { | ||
91 | + return salesPrice; | ||
92 | + } | ||
93 | + | ||
94 | + public void setSalesPrice(BigDecimal salesPrice) { | ||
95 | + this.salesPrice = salesPrice; | ||
96 | + } | ||
97 | + | ||
98 | + public BigDecimal getVipPrice() { | ||
99 | + return vipPrice; | ||
100 | + } | ||
101 | + | ||
102 | + public void setVipPrice(BigDecimal vipPrice) { | ||
103 | + this.vipPrice = vipPrice; | ||
104 | + } | ||
105 | + | ||
106 | + public Integer getVipDiscountType() { | ||
107 | + return vipDiscountType; | ||
108 | + } | ||
109 | + | ||
110 | + public void setVipDiscountType(Integer vipDiscountType) { | ||
111 | + this.vipDiscountType = vipDiscountType; | ||
112 | + } | ||
113 | + | ||
114 | + public BigDecimal getVip1Price() { | ||
115 | + return vip1Price; | ||
116 | + } | ||
117 | + | ||
118 | + public void setVip1Price(BigDecimal vip1Price) { | ||
119 | + this.vip1Price = vip1Price; | ||
120 | + } | ||
121 | + | ||
122 | + public BigDecimal getVip2Price() { | ||
123 | + return vip2Price; | ||
124 | + } | ||
125 | + | ||
126 | + public void setVip2Price(BigDecimal vip2Price) { | ||
127 | + this.vip2Price = vip2Price; | ||
128 | + } | ||
129 | + | ||
130 | + public BigDecimal getVip3Price() { | ||
131 | + return vip3Price; | ||
132 | + } | ||
133 | + | ||
134 | + public void setVip3Price(BigDecimal vip3Price) { | ||
135 | + this.vip3Price = vip3Price; | ||
136 | + } | ||
137 | + | ||
138 | + public BigDecimal getStudentPrice() { | ||
139 | + return studentPrice; | ||
140 | + } | ||
141 | + | ||
142 | + public void setStudentPrice(BigDecimal studentPrice) { | ||
143 | + this.studentPrice = studentPrice; | ||
144 | + } | ||
145 | + | ||
146 | + public BigDecimal getStudentCoinRate() { | ||
147 | + return studentCoinRate; | ||
148 | + } | ||
149 | + | ||
150 | + public void setStudentCoinRate(BigDecimal studentCoinRate) { | ||
151 | + this.studentCoinRate = studentCoinRate; | ||
152 | + } | ||
153 | + | ||
154 | + public String getIsDiscount() { | ||
155 | + return isDiscount; | ||
156 | + } | ||
156 | 157 | ||
157 | - public void setSpecialoffer(String specialoffer) { | ||
158 | - this.specialoffer = specialoffer; | ||
159 | - } | 158 | + public void setIsDiscount(String isDiscount) { |
159 | + this.isDiscount = isDiscount; | ||
160 | + } | ||
160 | 161 | ||
161 | - public Long getPromotionDiscountInt() { | ||
162 | - return promotionDiscountInt; | ||
163 | - } | 162 | + public String getSpecialoffer() { |
163 | + return specialoffer; | ||
164 | + } | ||
164 | 165 | ||
165 | - public void setPromotionDiscountInt(Long promotionDiscountInt) { | ||
166 | - this.promotionDiscountInt = promotionDiscountInt; | ||
167 | - } | 166 | + public void setSpecialoffer(String specialoffer) { |
167 | + this.specialoffer = specialoffer; | ||
168 | + } | ||
168 | 169 | ||
169 | - public BigDecimal getPromotionDiscount() { | ||
170 | - return promotionDiscount; | ||
171 | - } | 170 | + public Long getPromotionDiscountInt() { |
171 | + return promotionDiscountInt; | ||
172 | + } | ||
172 | 173 | ||
173 | - public void setPromotionDiscount(BigDecimal promotionDiscount) { | ||
174 | - this.promotionDiscount = promotionDiscount; | ||
175 | - } | 174 | + public void setPromotionDiscountInt(Long promotionDiscountInt) { |
175 | + this.promotionDiscountInt = promotionDiscountInt; | ||
176 | + } | ||
176 | 177 | ||
177 | - public String getIsStudentPrice() { | ||
178 | - return isStudentPrice; | ||
179 | - } | 178 | + public BigDecimal getPromotionDiscount() { |
179 | + return promotionDiscount; | ||
180 | + } | ||
180 | 181 | ||
181 | - public void setIsStudentPrice(String isStudentPrice) { | ||
182 | - this.isStudentPrice = isStudentPrice; | ||
183 | - } | 182 | + public void setPromotionDiscount(BigDecimal promotionDiscount) { |
183 | + this.promotionDiscount = promotionDiscount; | ||
184 | + } | ||
184 | 185 | ||
185 | - public String getIsstudentrebate() { | ||
186 | - return isstudentrebate; | ||
187 | - } | 186 | + public String getIsStudentPrice() { |
187 | + return isStudentPrice; | ||
188 | + } | ||
188 | 189 | ||
189 | - public void setIsstudentrebate(String isstudentrebate) { | ||
190 | - this.isstudentrebate = isstudentrebate; | ||
191 | - } | 190 | + public void setIsStudentPrice(String isStudentPrice) { |
191 | + this.isStudentPrice = isStudentPrice; | ||
192 | + } | ||
192 | 193 | ||
193 | - public String getVipLevels() { | ||
194 | - return vipLevels; | ||
195 | - } | 194 | + public String getIsstudentrebate() { |
195 | + return isstudentrebate; | ||
196 | + } | ||
196 | 197 | ||
197 | - public void setVipLevels(String vipLevels) { | ||
198 | - this.vipLevels = vipLevels; | ||
199 | - } | 198 | + public void setIsstudentrebate(String isstudentrebate) { |
199 | + this.isstudentrebate = isstudentrebate; | ||
200 | + } | ||
200 | 201 | ||
201 | - public Integer getUpdateTime() { | ||
202 | - return updateTime; | ||
203 | - } | 202 | + public String getVipLevels() { |
203 | + return vipLevels; | ||
204 | + } | ||
204 | 205 | ||
205 | - public void setUpdateTime(Integer updateTime) { | ||
206 | - this.updateTime = updateTime; | ||
207 | - } | 206 | + public void setVipLevels(String vipLevels) { |
207 | + this.vipLevels = vipLevels; | ||
208 | + } | ||
208 | 209 | ||
209 | - public BigDecimal getBasicPrice() { | ||
210 | - return basicPrice; | ||
211 | - } | 210 | + public Integer getUpdateTime() { |
211 | + return updateTime; | ||
212 | + } | ||
212 | 213 | ||
213 | - public void setBasicPrice(BigDecimal basicPrice) { | ||
214 | - this.basicPrice = basicPrice; | ||
215 | - } | 214 | + public void setUpdateTime(Integer updateTime) { |
215 | + this.updateTime = updateTime; | ||
216 | + } | ||
216 | 217 | ||
217 | - public Integer getProductVipStatus() { | ||
218 | - return productVipStatus; | ||
219 | - } | 218 | + public BigDecimal getBasicPrice() { |
219 | + return basicPrice; | ||
220 | + } | ||
220 | 221 | ||
221 | - public void setProductVipStatus(Integer productVipStatus) { | ||
222 | - this.productVipStatus = productVipStatus; | ||
223 | - } | 222 | + public void setBasicPrice(BigDecimal basicPrice) { |
223 | + this.basicPrice = basicPrice; | ||
224 | + } | ||
225 | + | ||
226 | + public Integer getProductVipStatus() { | ||
227 | + return productVipStatus; | ||
228 | + } | ||
229 | + | ||
230 | + public void setProductVipStatus(Integer productVipStatus) { | ||
231 | + this.productVipStatus = productVipStatus; | ||
232 | + } | ||
224 | 233 | ||
225 | } | 234 | } |
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"); | ||
47 | + } | ||
48 | + if (vip3Price > 0 && vip3Price < salesPrice) { | ||
49 | + vipLevels.add("3"); | ||
50 | + } | ||
51 | + productPriceBO.setVipLevels(StringUtils.join(vipLevels, ",")); | ||
52 | + | ||
36 | } | 53 | } |
37 | - | 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. |
@@ -30,174 +27,150 @@ import com.yoho.search.dal.model.ProductPrice; | @@ -30,174 +27,150 @@ import com.yoho.search.dal.model.ProductPrice; | ||
30 | @Component | 27 | @Component |
31 | public class ProductPriceBuilder implements ViewBuilder { | 28 | public class ProductPriceBuilder implements ViewBuilder { |
32 | 29 | ||
33 | - private final Logger logger = LoggerFactory.getLogger(ProductPriceBuilder.class); | ||
34 | - | ||
35 | - @Autowired | ||
36 | - private ProductPriceMapper productPriceMapper; | ||
37 | - @Autowired | ||
38 | - private VipPriceLogicServie vipPriceLogicServie; | ||
39 | - @Autowired | ||
40 | - private SpecialDealLogicService specialSearchFieldLogicService; | ||
41 | - | ||
42 | - @Override | ||
43 | - public void build(List<ProductIndexBO> productIndexBOs, List<Integer> ids, List<Integer> sknList) { | ||
44 | - List<ProductPrice> productPrices = productPriceMapper.selectBySkns(sknList); | ||
45 | - 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 | - | ||
57 | - try { | ||
58 | - // 如果价格不存在,则直接返回 | ||
59 | - ProductPrice productPrice = productPricesMap.get(pi.getProductSkn()); | ||
60 | - if (productPrice == null) { | ||
61 | - continue; | ||
62 | - } | ||
63 | - | ||
64 | - // 构造ProductPriceBO | ||
65 | - ProductPriceBO productPriceBO = new ProductPriceBO(productPrice); | ||
66 | - this.fillProductPriceBO(productPriceBO); | ||
67 | - | ||
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()); | ||
76 | - | ||
77 | - // 折扣相关 | ||
78 | - pi.setIsDiscount(productPriceBO.getIsDiscount()); | ||
79 | - pi.setSpecialoffer(productPriceBO.getSpecialoffer()); | ||
80 | - pi.setPromotionDiscountInt(productPriceBO.getPromotionDiscountInt()); | ||
81 | - pi.setPromotionDiscount(productPriceBO.getPromotionDiscount()); | ||
82 | - | ||
83 | - // 学生价相关字段 | ||
84 | - pi.setIsStudentPrice(productPriceBO.getIsStudentPrice()); | ||
85 | - pi.setIsStudentRebate(productPriceBO.getIsstudentrebate()); | ||
86 | - | ||
87 | - // 设置vipLevels | ||
88 | - pi.setVipLevels(productPriceBO.getVipLevels()); | ||
89 | - | ||
90 | - // 设置价格更新时间 | ||
91 | - pi.setPriceUpdateTime(productPriceBO.getUpdateTime()); | ||
92 | - | ||
93 | - // 设置最后一次降价时间 | ||
94 | - pi.setLastReducePriceTime(productPriceBO.getLastReducePriceTime()); | ||
95 | - | ||
96 | - // 计算isNew(规则:首次上架7天内展示且折扣率大于等于88折) | ||
97 | - pi.setIsnew("N"); | ||
98 | - if (this.isNew(pi.getFirstShelveTime(), pi.getMarketPrice(), pi.getSalesPrice())) { | ||
99 | - pi.setIsnew("Y"); | ||
100 | - } | ||
101 | - // 计算specialsearchfieldPrice | ||
102 | - pi.setSpecialSearchFieldPrice(specialSearchFieldLogicService.getSpecialSearchFieldPrice(productPriceBO)); | ||
103 | - } catch (Exception e) { | ||
104 | - logger.error(e.getMessage(), e); | ||
105 | - } | ||
106 | - | ||
107 | - } | ||
108 | - } | ||
109 | - | ||
110 | - /** | ||
111 | - * isNew 标签逻辑 | ||
112 | - * | ||
113 | - * @return | ||
114 | - */ | ||
115 | - public boolean isNew(Integer firstShelveTime, BigDecimal marketPrice, BigDecimal salesPrice) { | ||
116 | - try { | ||
117 | - if (firstShelveTime == null || firstShelveTime <= 0 || salesPrice == null || marketPrice == null) { | ||
118 | - return false; | ||
119 | - } | ||
120 | - long dateCount = DateUtil.daysBetween(new Date(firstShelveTime * 1000L), new Date()); | ||
121 | - if (dateCount > 7) { | ||
122 | - return false; | ||
123 | - } | ||
124 | - // 计算折扣 | ||
125 | - Double discount = MathUtils.getDevideValue(salesPrice, marketPrice, 2, RoundingMode.DOWN); | ||
126 | - if (discount >= 0.88) { | ||
127 | - return true; | ||
128 | - } | ||
129 | - return false; | ||
130 | - } catch (Exception e) { | ||
131 | - return false; | ||
132 | - } | ||
133 | - } | ||
134 | - | ||
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) { | ||
176 | - if (b == null || b.compareTo(BigDecimal.ZERO) == 0) { | ||
177 | - return 0; | ||
178 | - } | ||
179 | - StringBuilder sb = new StringBuilder("0.0"); | ||
180 | - for (int i = 1; i < scale; i++) { | ||
181 | - sb.append('0'); | ||
182 | - } | ||
183 | - BigDecimal divideResult = a.divide(b, scale, RoundingMode.DOWN); | ||
184 | - DecimalFormat decimalFormat = new DecimalFormat(sb.toString()); | ||
185 | - String result = decimalFormat.format(divideResult); | ||
186 | - return Double.parseDouble(result); | ||
187 | - } | ||
188 | - | ||
189 | - private double getDoubleFromBigDecimal(BigDecimal bigDecimal) { | ||
190 | - if (bigDecimal == null) { | ||
191 | - return 0d; | ||
192 | - } | ||
193 | - return bigDecimal.doubleValue(); | ||
194 | - } | ||
195 | - | ||
196 | - private BigDecimal getBigDecimalFromDouble(Double d) { | ||
197 | - if (d == null) { | ||
198 | - return new BigDecimal(0); | ||
199 | - } | ||
200 | - return new BigDecimal(d); | ||
201 | - } | ||
202 | - | 30 | + private final Logger logger = LoggerFactory.getLogger(ProductPriceBuilder.class); |
31 | + | ||
32 | + @Autowired | ||
33 | + private ProductPriceMapper productPriceMapper; | ||
34 | + @Autowired | ||
35 | + private VipPriceLogicService vipPriceLogicService; | ||
36 | + @Autowired | ||
37 | + private SpecialDealLogicService specialSearchFieldLogicService; | ||
38 | + | ||
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 | + } | ||
60 | + | ||
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 | + } | ||
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()); | ||
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 | + } | ||
124 | + | ||
125 | + | ||
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 | + } | ||
148 | + | ||
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 | + } | ||
162 | + | ||
163 | + private double getDoubleFromBigDecimal(BigDecimal bigDecimal) { | ||
164 | + if (bigDecimal == null) { | ||
165 | + return 0d; | ||
166 | + } | ||
167 | + return bigDecimal.doubleValue(); | ||
168 | + } | ||
169 | + | ||
170 | + private BigDecimal getBigDecimalFromDouble(Double d) { | ||
171 | + if (d == null) { | ||
172 | + return new BigDecimal(0); | ||
173 | + } | ||
174 | + return new BigDecimal(d); | ||
175 | + } | ||
203 | } | 176 | } |
-
Please register or login to post a comment