Showing
1 changed file
with
44 additions
and
6 deletions
1 | package com.yoho.search.service.base.index; | 1 | package com.yoho.search.service.base.index; |
2 | 2 | ||
3 | import com.alibaba.fastjson.JSONArray; | 3 | import com.alibaba.fastjson.JSONArray; |
4 | +import com.yoho.search.base.utils.DateUtil; | ||
4 | import com.yoho.search.base.utils.ProductIndexEsField; | 5 | import com.yoho.search.base.utils.ProductIndexEsField; |
5 | import org.apache.commons.collections.MapUtils; | 6 | import org.apache.commons.collections.MapUtils; |
6 | import org.apache.commons.lang.StringUtils; | 7 | import org.apache.commons.lang.StringUtils; |
@@ -8,10 +9,8 @@ import org.springframework.beans.factory.annotation.Autowired; | @@ -8,10 +9,8 @@ import org.springframework.beans.factory.annotation.Autowired; | ||
8 | import org.springframework.stereotype.Service; | 9 | import org.springframework.stereotype.Service; |
9 | 10 | ||
10 | import javax.annotation.PostConstruct; | 11 | import javax.annotation.PostConstruct; |
11 | -import java.util.ArrayList; | ||
12 | -import java.util.HashMap; | ||
13 | -import java.util.List; | ||
14 | -import java.util.Map; | 12 | +import java.text.ParseException; |
13 | +import java.util.*; | ||
15 | 14 | ||
16 | @Service | 15 | @Service |
17 | public class ProductIndexBaseService { | 16 | public class ProductIndexBaseService { |
@@ -98,6 +97,9 @@ public class ProductIndexBaseService { | @@ -98,6 +97,9 @@ public class ProductIndexBaseService { | ||
98 | productIndexIncludeFields.add(ProductIndexEsField.tblCountryName); | 97 | productIndexIncludeFields.add(ProductIndexEsField.tblCountryName); |
99 | 98 | ||
100 | productIndexIncludeFields.add(ProductIndexEsField.customizeTag); | 99 | productIndexIncludeFields.add(ProductIndexEsField.customizeTag); |
100 | + productIndexIncludeFields.add(ProductIndexEsField.matchedPromotions); | ||
101 | + productIndexIncludeFields.add(ProductIndexEsField.basePinRatio); | ||
102 | + productIndexIncludeFields.add(ProductIndexEsField.breakingRate); | ||
101 | } | 103 | } |
102 | 104 | ||
103 | public List<String> getProductIndexIncludeFields() { | 105 | public List<String> getProductIndexIncludeFields() { |
@@ -176,6 +178,16 @@ public class ProductIndexBaseService { | @@ -176,6 +178,16 @@ public class ProductIndexBaseService { | ||
176 | productMap.put("is_discount", MapUtils.getString(map, ProductIndexEsField.isDiscount, "N")); | 178 | productMap.put("is_discount", MapUtils.getString(map, ProductIndexEsField.isDiscount, "N")); |
177 | productMap.put("is_soon_sold_out", MapUtils.getString(map, ProductIndexEsField.isSoonSoldOut, "N")); | 179 | productMap.put("is_soon_sold_out", MapUtils.getString(map, ProductIndexEsField.isSoonSoldOut, "N")); |
178 | productMap.put("is_promotion", MapUtils.getIntValue(map, ProductIndexEsField.ispromotion, 0)); | 180 | productMap.put("is_promotion", MapUtils.getIntValue(map, ProductIndexEsField.ispromotion, 0)); |
181 | + productMap.put("is_latest_reduce_price", MapUtils.getString(map, ProductIndexEsField.isLatestReducePrice, "N")); | ||
182 | + productMap.put("is_breaking", "N"); | ||
183 | + if (MapUtils.getDoubleValue(map, ProductIndexEsField.basePinRatio, 0) >= 3.5 && MapUtils.getDoubleValue(map, ProductIndexEsField.breakSizePercent, 0) >= 50) { | ||
184 | + productMap.put("is_breaking", "Y"); | ||
185 | + } | ||
186 | + productMap.put("is_promotion_active", "N"); | ||
187 | + boolean promotionActive = getPromotionActive(map); | ||
188 | + if (promotionActive) { | ||
189 | + productMap.put("is_promotion_active", "Y"); | ||
190 | + } | ||
179 | 191 | ||
180 | productMap.put("bundle_type", MapUtils.getIntValue(map, ProductIndexEsField.bundleType, 0)); | 192 | productMap.put("bundle_type", MapUtils.getIntValue(map, ProductIndexEsField.bundleType, 0)); |
181 | 193 | ||
@@ -204,6 +216,32 @@ public class ProductIndexBaseService { | @@ -204,6 +216,32 @@ public class ProductIndexBaseService { | ||
204 | return productMap; | 216 | return productMap; |
205 | } | 217 | } |
206 | 218 | ||
219 | + | ||
220 | + /** | ||
221 | + * 判断是否有正在进行的促销 | ||
222 | + * | ||
223 | + * @param map | ||
224 | + * @return | ||
225 | + */ | ||
226 | + private boolean getPromotionActive(Map<String, Object> map) { | ||
227 | + boolean promotionActive = false; | ||
228 | + try { | ||
229 | + Date date = new Date(); | ||
230 | + long nowUnixTime = DateUtil.Date2TimeStamp(date); | ||
231 | + List<Map<String, Object>> promotionList = (ArrayList) MapUtils.getObject(map, ProductIndexEsField.matchedPromotions, new ArrayList()); | ||
232 | + for (Map<String, Object> hashMap : promotionList) { | ||
233 | + Integer startTime = hashMap.get("startTime") == null ? 0 : (Integer) hashMap.get("startTime"); | ||
234 | + Integer endTime = hashMap.get("endTime") == null ? 0 : (Integer) hashMap.get("endTime"); | ||
235 | + if (startTime < nowUnixTime && nowUnixTime < endTime) { | ||
236 | + promotionActive = true; | ||
237 | + } | ||
238 | + } | ||
239 | + } catch (ParseException e) { | ||
240 | + return promotionActive; | ||
241 | + } | ||
242 | + return promotionActive; | ||
243 | + } | ||
244 | + | ||
207 | /** | 245 | /** |
208 | * 获取商品列表[不包含变价计划] | 246 | * 获取商品列表[不包含变价计划] |
209 | * | 247 | * |
@@ -223,8 +261,8 @@ public class ProductIndexBaseService { | @@ -223,8 +261,8 @@ public class ProductIndexBaseService { | ||
223 | * @return | 261 | * @return |
224 | */ | 262 | */ |
225 | public List<Map<String, Object>> getProductListWithPricePlan(List<Map<String, Object>> productEsSourceList) { | 263 | public List<Map<String, Object>> getProductListWithPricePlan(List<Map<String, Object>> productEsSourceList) { |
226 | - if(productEsSourceList==null|| productEsSourceList.isEmpty()){ | ||
227 | - return new ArrayList<Map<String,Object>>(); | 264 | + if (productEsSourceList == null || productEsSourceList.isEmpty()) { |
265 | + return new ArrayList<Map<String, Object>>(); | ||
228 | } | 266 | } |
229 | // 获取搜索结果的skn,根据它们来获取product_price_plan | 267 | // 获取搜索结果的skn,根据它们来获取product_price_plan |
230 | String[] sknStr = new String[productEsSourceList.size()]; | 268 | String[] sknStr = new String[productEsSourceList.size()]; |
-
Please register or login to post a comment