|
|
package com.yoho.search.service.base.index;
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
|
|
|
import javax.annotation.PostConstruct;
|
|
|
|
|
|
import org.apache.commons.collections.MapUtils;
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
import com.yoho.search.base.utils.ProductIndexEsField;
|
|
|
|
|
|
@Service
|
|
|
public class WebProductIndexBaseService {
|
|
|
|
|
|
@Autowired
|
|
|
private ProductPricePlanIndexBaseService productPricePlanIndexBaseService;
|
|
|
|
|
|
// 获取从source中不返回的字段定义,用以节省带宽
|
|
|
private List<String> productIndexIncludeFields = new ArrayList<String>();
|
|
|
|
|
|
@PostConstruct
|
|
|
void init() {
|
|
|
productIndexIncludeFields.add(ProductIndexEsField.productName);
|
|
|
productIndexIncludeFields.add(ProductIndexEsField.productSkn);
|
|
|
|
|
|
productIndexIncludeFields.add(ProductIndexEsField.shopId);
|
|
|
productIndexIncludeFields.add(ProductIndexEsField.shopName);
|
|
|
productIndexIncludeFields.add(ProductIndexEsField.shopDomain);
|
|
|
|
|
|
productIndexIncludeFields.add(ProductIndexEsField.salesPrice);
|
|
|
productIndexIncludeFields.add(ProductIndexEsField.marketPrice);
|
|
|
productIndexIncludeFields.add(ProductIndexEsField.vipPrice);
|
|
|
productIndexIncludeFields.add(ProductIndexEsField.vip1Price);
|
|
|
productIndexIncludeFields.add(ProductIndexEsField.vip2Price);
|
|
|
productIndexIncludeFields.add(ProductIndexEsField.vip3Price);
|
|
|
productIndexIncludeFields.add(ProductIndexEsField.vipDiscountType);
|
|
|
|
|
|
productIndexIncludeFields.add(ProductIndexEsField.defaultImages);
|
|
|
productIndexIncludeFields.add(ProductIndexEsField.firstShelveTime);
|
|
|
|
|
|
productIndexIncludeFields.add(ProductIndexEsField.gender);
|
|
|
productIndexIncludeFields.add(ProductIndexEsField.status);
|
|
|
productIndexIncludeFields.add(ProductIndexEsField.goodsList);
|
|
|
|
|
|
productIndexIncludeFields.add(ProductIndexEsField.isnew);
|
|
|
productIndexIncludeFields.add(ProductIndexEsField.isAdvance);
|
|
|
productIndexIncludeFields.add(ProductIndexEsField.isDepositAdvance);
|
|
|
productIndexIncludeFields.add(ProductIndexEsField.islimited);
|
|
|
productIndexIncludeFields.add(ProductIndexEsField.isDiscount);
|
|
|
productIndexIncludeFields.add(ProductIndexEsField.isSoonSoldOut);
|
|
|
|
|
|
productIndexIncludeFields.add(ProductIndexEsField.bundleType);
|
|
|
productIndexIncludeFields.add(ProductIndexEsField.yohoodId);
|
|
|
|
|
|
productIndexIncludeFields.add(ProductIndexEsField.isGlobal);
|
|
|
productIndexIncludeFields.add(ProductIndexEsField.tblBrandId);
|
|
|
productIndexIncludeFields.add(ProductIndexEsField.tblCountryId);
|
|
|
productIndexIncludeFields.add(ProductIndexEsField.tblCountryName);
|
|
|
}
|
|
|
|
|
|
public List<String> getWebProductIndexIncludeFields() {
|
|
|
List<String> results = new ArrayList<String>();
|
|
|
results.addAll(productIndexIncludeFields);
|
|
|
return results;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* pc商品列表返回的字段
|
|
|
*
|
|
|
* @param map
|
|
|
* @return
|
|
|
*/
|
|
|
private Map<String, Object> getPcProductMapFromEsSource(Map<String, Object> map) {
|
|
|
Map<String, Object> productMap = new HashMap<String, Object>();
|
|
|
productMap.put("product_name", MapUtils.getString(map, ProductIndexEsField.productName, ""));
|
|
|
productMap.put("product_skn", MapUtils.getIntValue(map, ProductIndexEsField.productSkn, 0));
|
|
|
|
|
|
productMap.put("shop_id", MapUtils.getIntValue(map, ProductIndexEsField.shopId, 0));
|
|
|
productMap.put("shop_name", MapUtils.getString(map, ProductIndexEsField.shopName, ""));
|
|
|
productMap.put("shop_domain", MapUtils.getString(map, ProductIndexEsField.shopDomain, ""));
|
|
|
|
|
|
productMap.put("sales_price", MapUtils.getDoubleValue(map, ProductIndexEsField.salesPrice, 0));
|
|
|
productMap.put("market_price", MapUtils.getDoubleValue(map, ProductIndexEsField.marketPrice, 0));
|
|
|
productMap.put("vip_price", MapUtils.getDoubleValue(map, ProductIndexEsField.vipPrice, 0));
|
|
|
productMap.put("vip1_price", MapUtils.getDoubleValue(map, ProductIndexEsField.vip1Price, 0));
|
|
|
productMap.put("vip2_price", MapUtils.getDoubleValue(map, ProductIndexEsField.vip2Price, 0));
|
|
|
productMap.put("vip3_price", MapUtils.getDoubleValue(map, ProductIndexEsField.vip3Price, 0));
|
|
|
productMap.put("vip_discount_type", MapUtils.getIntValue(map, ProductIndexEsField.vipDiscountType, 1));
|
|
|
|
|
|
productMap.put("default_images", MapUtils.getString(map, ProductIndexEsField.defaultImages, ""));
|
|
|
productMap.put("first_shelve_time", MapUtils.getIntValue(map, ProductIndexEsField.firstShelveTime));
|
|
|
|
|
|
productMap.put("gender", MapUtils.getString(map, ProductIndexEsField.gender, ""));
|
|
|
productMap.put("status", MapUtils.getIntValue(map, ProductIndexEsField.status, 0));
|
|
|
productMap.put("goods_list", MapUtils.getObject(map, ProductIndexEsField.goodsList, new JSONArray()));
|
|
|
|
|
|
productMap.put("is_new", MapUtils.getString(map, ProductIndexEsField.isnew, "N"));
|
|
|
productMap.put("is_advance", MapUtils.getString(map, ProductIndexEsField.isAdvance, "N"));
|
|
|
productMap.put("is_deposit_advance", MapUtils.getString(map, ProductIndexEsField.isDepositAdvance, "N"));
|
|
|
productMap.put("is_limited", MapUtils.getString(map, ProductIndexEsField.islimited, "N"));
|
|
|
productMap.put("is_discount", MapUtils.getString(map, ProductIndexEsField.isDiscount, "N"));
|
|
|
productMap.put("is_soon_sold_out", MapUtils.getString(map, ProductIndexEsField.isSoonSoldOut, "N"));
|
|
|
|
|
|
// 套餐
|
|
|
productMap.put("bundle_type", MapUtils.getIntValue(map, ProductIndexEsField.bundleType, 0));
|
|
|
|
|
|
// yohoodId
|
|
|
String yohoodId = MapUtils.getString(map, ProductIndexEsField.yohoodId, "");
|
|
|
productMap.put("yohood_id", StringUtils.isNotBlank(yohoodId) ? yohoodId : null);
|
|
|
|
|
|
// 全球购相关
|
|
|
productMap.put("is_global", MapUtils.getString(map, ProductIndexEsField.isGlobal, "N"));
|
|
|
int tbl_country_id = MapUtils.getIntValue(map, ProductIndexEsField.tblCountryId, 0);
|
|
|
productMap.put("tbl_country_id", tbl_country_id);
|
|
|
productMap.put("tbl_brand_id", MapUtils.getIntValue(map, ProductIndexEsField.tblBrandId, 0));
|
|
|
productMap.put("tbl_country_name", MapUtils.getString(map, ProductIndexEsField.tblCountryName, ""));
|
|
|
productMap.put("tbl_plane", (tbl_country_id > 0 && tbl_country_id != 86) ? "Y" : "N");
|
|
|
|
|
|
return productMap;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 获取商品列表[并返回变价计划]
|
|
|
*
|
|
|
* @return
|
|
|
*/
|
|
|
public List<Map<String, Object>> getProductListWithPricePlan(List<Map<String, Object>> productEsSourceList) {
|
|
|
if (productEsSourceList == null || productEsSourceList.isEmpty()) {
|
|
|
return new ArrayList<Map<String, Object>>();
|
|
|
}
|
|
|
// 获取搜索结果的skn,根据它们来获取product_price_plan
|
|
|
String[] sknStr = new String[productEsSourceList.size()];
|
|
|
for (int i = 0; i < productEsSourceList.size(); i++) {
|
|
|
sknStr[i] = MapUtils.getString(productEsSourceList.get(i), "productSkn", "");
|
|
|
}
|
|
|
List<Map<String, Object>> results = new ArrayList<Map<String, Object>>();
|
|
|
Map<String, List<Map<String, Object>>> productPricePlanMap = productPricePlanIndexBaseService.searchProductPricePlan(sknStr);
|
|
|
for (Map<String, Object> productEsSource : productEsSourceList) {
|
|
|
Map<String, Object> productMap = this.getPcProductMapFromEsSource(productEsSource);
|
|
|
if (productMap != null) {
|
|
|
productMap.put("product_price_plan_list", productPricePlanMap.get(MapUtils.getString(productEsSource, "productSkn", "")));
|
|
|
}
|
|
|
results.add(productMap);
|
|
|
}
|
|
|
return results;
|
|
|
}
|
|
|
|
|
|
} |
...
|
...
|
|