Authored by wangnan

返回一些推荐用的标志字段

package com.yoho.search.service.base.index;
import com.alibaba.fastjson.JSONArray;
import com.yoho.search.base.utils.DateUtil;
import com.yoho.search.base.utils.ProductIndexEsField;
import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang.StringUtils;
... ... @@ -8,10 +9,8 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.annotation.PostConstruct;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.text.ParseException;
import java.util.*;
@Service
public class ProductIndexBaseService {
... ... @@ -98,6 +97,9 @@ public class ProductIndexBaseService {
productIndexIncludeFields.add(ProductIndexEsField.tblCountryName);
productIndexIncludeFields.add(ProductIndexEsField.customizeTag);
productIndexIncludeFields.add(ProductIndexEsField.matchedPromotions);
productIndexIncludeFields.add(ProductIndexEsField.basePinRatio);
productIndexIncludeFields.add(ProductIndexEsField.breakingRate);
}
public List<String> getProductIndexIncludeFields() {
... ... @@ -176,6 +178,16 @@ public class ProductIndexBaseService {
productMap.put("is_discount", MapUtils.getString(map, ProductIndexEsField.isDiscount, "N"));
productMap.put("is_soon_sold_out", MapUtils.getString(map, ProductIndexEsField.isSoonSoldOut, "N"));
productMap.put("is_promotion", MapUtils.getIntValue(map, ProductIndexEsField.ispromotion, 0));
productMap.put("is_latest_reduce_price", MapUtils.getString(map, ProductIndexEsField.isLatestReducePrice, "N"));
productMap.put("is_breaking", "N");
if (MapUtils.getDoubleValue(map, ProductIndexEsField.basePinRatio, 0) >= 3.5 && MapUtils.getDoubleValue(map, ProductIndexEsField.breakSizePercent, 0) >= 50) {
productMap.put("is_breaking", "Y");
}
productMap.put("is_promotion_active", "N");
boolean promotionActive = getPromotionActive(map);
if (promotionActive) {
productMap.put("is_promotion_active", "Y");
}
productMap.put("bundle_type", MapUtils.getIntValue(map, ProductIndexEsField.bundleType, 0));
... ... @@ -204,6 +216,32 @@ public class ProductIndexBaseService {
return productMap;
}
/**
* 判断是否有正在进行的促销
*
* @param map
* @return
*/
private boolean getPromotionActive(Map<String, Object> map) {
boolean promotionActive = false;
try {
Date date = new Date();
long nowUnixTime = DateUtil.Date2TimeStamp(date);
List<Map<String, Object>> promotionList = (ArrayList) MapUtils.getObject(map, ProductIndexEsField.matchedPromotions, new ArrayList());
for (Map<String, Object> hashMap : promotionList) {
Integer startTime = hashMap.get("startTime") == null ? 0 : (Integer) hashMap.get("startTime");
Integer endTime = hashMap.get("endTime") == null ? 0 : (Integer) hashMap.get("endTime");
if (startTime < nowUnixTime && nowUnixTime < endTime) {
promotionActive = true;
}
}
} catch (ParseException e) {
return promotionActive;
}
return promotionActive;
}
/**
* 获取商品列表[不包含变价计划]
*
... ... @@ -223,8 +261,8 @@ public class ProductIndexBaseService {
* @return
*/
public List<Map<String, Object>> getProductListWithPricePlan(List<Map<String, Object>> productEsSourceList) {
if(productEsSourceList==null|| productEsSourceList.isEmpty()){
return new ArrayList<Map<String,Object>>();
if (productEsSourceList == null || productEsSourceList.isEmpty()) {
return new ArrayList<Map<String, Object>>();
}
// 获取搜索结果的skn,根据它们来获取product_price_plan
String[] sknStr = new String[productEsSourceList.size()];
... ...