|
|
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 java.util.ArrayList;
|
|
|
import java.util.Date;
|
|
|
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.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import javax.annotation.PostConstruct;
|
|
|
|
|
|
import java.text.ParseException;
|
|
|
import java.util.*;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.yoho.search.base.utils.DateUtil;
|
|
|
import com.yoho.search.base.utils.ProductIndexEsField;
|
|
|
|
|
|
@Service
|
|
|
public class ProductIndexBaseService {
|
|
|
|
|
|
@Autowired
|
|
|
private ProductPricePlanIndexBaseService productPricePlanIndexBaseService;
|
|
|
|
|
|
// 获取从source中不返回的字段定义,用以节省带宽
|
|
|
private List<String> productIndexIncludeFields = new ArrayList<String>();
|
|
|
|
|
|
@PostConstruct
|
|
|
void init() {
|
|
|
productIndexIncludeFields.add(ProductIndexEsField.productId);
|
|
|
productIndexIncludeFields.add(ProductIndexEsField.productName);
|
|
|
productIndexIncludeFields.add(ProductIndexEsField.productSkn);
|
|
|
productIndexIncludeFields.add(ProductIndexEsField.cnAlphabet);
|
|
|
|
|
|
productIndexIncludeFields.add(ProductIndexEsField.brandId);
|
|
|
productIndexIncludeFields.add(ProductIndexEsField.brandName);
|
|
|
productIndexIncludeFields.add(ProductIndexEsField.brandDomain);
|
|
|
productIndexIncludeFields.add(ProductIndexEsField.countryId);
|
|
|
|
|
|
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.isStudentPrice);
|
|
|
productIndexIncludeFields.add(ProductIndexEsField.studentPrice);
|
|
|
productIndexIncludeFields.add(ProductIndexEsField.isstudentrebate);
|
|
|
|
|
|
productIndexIncludeFields.add(ProductIndexEsField.defaultImages);
|
|
|
productIndexIncludeFields.add(ProductIndexEsField.sknDefaultImg);
|
|
|
|
|
|
productIndexIncludeFields.add(ProductIndexEsField.editTime);
|
|
|
productIndexIncludeFields.add(ProductIndexEsField.shelveTime);
|
|
|
productIndexIncludeFields.add(ProductIndexEsField.firstShelveTime);
|
|
|
|
|
|
productIndexIncludeFields.add(ProductIndexEsField.maxSortId);
|
|
|
productIndexIncludeFields.add(ProductIndexEsField.middleSortId);
|
|
|
productIndexIncludeFields.add(ProductIndexEsField.smallSortId);
|
|
|
productIndexIncludeFields.add(ProductIndexEsField.smallSort);
|
|
|
|
|
|
productIndexIncludeFields.add(ProductIndexEsField.storageNum);
|
|
|
productIndexIncludeFields.add(ProductIndexEsField.salesNum);
|
|
|
|
|
|
productIndexIncludeFields.add(ProductIndexEsField.gender);
|
|
|
productIndexIncludeFields.add(ProductIndexEsField.ageLevel);
|
|
|
productIndexIncludeFields.add(ProductIndexEsField.salesPhrase);
|
|
|
//productIndexIncludeFields.add(ProductIndexEsField.phrase);
|
|
|
productIndexIncludeFields.add(ProductIndexEsField.status);
|
|
|
productIndexIncludeFields.add(ProductIndexEsField.goodsList);
|
|
|
|
|
|
|
|
|
productIndexIncludeFields.add(ProductIndexEsField.isnew);
|
|
|
productIndexIncludeFields.add(ProductIndexEsField.isAdvance);
|
|
|
productIndexIncludeFields.add(ProductIndexEsField.isDepositAdvance);
|
|
|
productIndexIncludeFields.add(ProductIndexEsField.isSeckill);
|
|
|
productIndexIncludeFields.add(ProductIndexEsField.isLimitbuy);
|
|
|
productIndexIncludeFields.add(ProductIndexEsField.islimited);
|
|
|
productIndexIncludeFields.add(ProductIndexEsField.isOutlets);
|
|
|
productIndexIncludeFields.add(ProductIndexEsField.isSpecial);
|
|
|
productIndexIncludeFields.add(ProductIndexEsField.isDiscount);
|
|
|
productIndexIncludeFields.add(ProductIndexEsField.isSoonSoldOut);
|
|
|
productIndexIncludeFields.add(ProductIndexEsField.ispromotion);
|
|
|
|
|
|
productIndexIncludeFields.add(ProductIndexEsField.bundleType);
|
|
|
productIndexIncludeFields.add(ProductIndexEsField.yohoodId);
|
|
|
|
|
|
productIndexIncludeFields.add(ProductIndexEsField.isFobbiden);
|
|
|
productIndexIncludeFields.add(ProductIndexEsField.storeShowStatus);
|
|
|
|
|
|
productIndexIncludeFields.add(ProductIndexEsField.isGlobal);
|
|
|
productIndexIncludeFields.add(ProductIndexEsField.tblBrandId);
|
|
|
productIndexIncludeFields.add(ProductIndexEsField.tblCountryId);
|
|
|
productIndexIncludeFields.add(ProductIndexEsField.tblCountryName);
|
|
|
|
|
|
productIndexIncludeFields.add(ProductIndexEsField.customizeTags);
|
|
|
productIndexIncludeFields.add(ProductIndexEsField.matchedPromotions);
|
|
|
productIndexIncludeFields.add(ProductIndexEsField.basePinRatio);
|
|
|
productIndexIncludeFields.add(ProductIndexEsField.breakingRate);
|
|
|
}
|
|
|
|
|
|
public List<String> getProductIndexIncludeFields() {
|
|
|
List<String> results = new ArrayList<String>();
|
|
|
results.addAll(productIndexIncludeFields);
|
|
|
return results;
|
|
|
}
|
|
|
|
|
|
@SuppressWarnings("unchecked")
|
|
|
public Map<String, Object> getProductMapFromEsSource(Map<String, Object> map) {
|
|
|
Map<String, Object> productMap = new HashMap<String, Object>();
|
|
|
if (map.containsKey("_highlight") && map.get("_highlight") != null) {
|
|
|
Map<String, Object> highlightMap = (Map<String, Object>) map.get("_highlight");
|
|
|
if (highlightMap.containsKey(ProductIndexEsField.productName_productName_ansj)) {
|
|
|
productMap.put("product_name_highlight", MapUtils.getString(highlightMap, ProductIndexEsField.productName_productName_ansj, ""));
|
|
|
}
|
|
|
}
|
|
|
productMap.put("product_id", MapUtils.getIntValue(map, ProductIndexEsField.productId, 0));
|
|
|
productMap.put("product_name", MapUtils.getString(map, ProductIndexEsField.productName, ""));
|
|
|
productMap.put("product_skn", MapUtils.getIntValue(map, ProductIndexEsField.productSkn, 0));
|
|
|
productMap.put("cn_alphabet", MapUtils.getString(map, ProductIndexEsField.cnAlphabet, ""));
|
|
|
|
|
|
productMap.put("brand_id", MapUtils.getIntValue(map, ProductIndexEsField.brandId, 0));
|
|
|
productMap.put("brand_name", MapUtils.getString(map, ProductIndexEsField.brandName, ""));
|
|
|
productMap.put("brand_domain", MapUtils.getString(map, ProductIndexEsField.brandDomain, ""));
|
|
|
productMap.put("country_id", MapUtils.getIntValue(map, ProductIndexEsField.countryId, 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));
|
|
|
// 学生价和学生返币
|
|
|
String isStudentPrice = MapUtils.getString(map, ProductIndexEsField.isStudentPrice, "N");
|
|
|
productMap.put("is_student_price", isStudentPrice);
|
|
|
productMap.put("student_price", "Y".equalsIgnoreCase(isStudentPrice) ? MapUtils.getDoubleValue(map, ProductIndexEsField.studentPrice) : null);
|
|
|
productMap.put("is_student_rebate", MapUtils.getString(map, ProductIndexEsField.isstudentrebate, "N"));
|
|
|
|
|
|
productMap.put("default_images", MapUtils.getString(map, ProductIndexEsField.defaultImages, ""));
|
|
|
productMap.put("skn_default_img", MapUtils.getString(map, ProductIndexEsField.sknDefaultImg, ""));
|
|
|
|
|
|
productMap.put("edit_time", MapUtils.getIntValue(map, ProductIndexEsField.editTime));
|
|
|
productMap.put("shelve_time", MapUtils.getIntValue(map, ProductIndexEsField.shelveTime));
|
|
|
productMap.put("first_shelve_time", MapUtils.getIntValue(map, ProductIndexEsField.firstShelveTime));
|
|
|
|
|
|
productMap.put("max_sort_id", MapUtils.getIntValue(map, ProductIndexEsField.maxSortId));
|
|
|
productMap.put("middle_sort_id", MapUtils.getIntValue(map, ProductIndexEsField.middleSortId));
|
|
|
productMap.put("small_sort_id", MapUtils.getIntValue(map, ProductIndexEsField.smallSortId));
|
|
|
productMap.put("small_sort_name", MapUtils.getString(map, ProductIndexEsField.smallSort, ""));
|
|
|
|
|
|
productMap.put("stock_number", MapUtils.getIntValue(map, ProductIndexEsField.storageNum, 0));
|
|
|
productMap.put("storage_num", MapUtils.getIntValue(map, ProductIndexEsField.storageNum, 0));
|
|
|
productMap.put("sales_num", MapUtils.getIntValue(map, ProductIndexEsField.salesNum, 0));
|
|
|
|
|
|
productMap.put("gender", MapUtils.getString(map, ProductIndexEsField.gender, ""));
|
|
|
productMap.put("age_level", MapUtils.getString(map, ProductIndexEsField.ageLevel, ""));// 年龄层,逗号隔开的字符串
|
|
|
productMap.put("sales_phrase", MapUtils.getString(map, ProductIndexEsField.salesPhrase, ""));
|
|
|
productMap.put("phrase", MapUtils.getString(map, ProductIndexEsField.phrase, ""));
|
|
|
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_seckill", MapUtils.getString(map, ProductIndexEsField.isSeckill, "N"));
|
|
|
productMap.put("is_limitbuy", MapUtils.getString(map, ProductIndexEsField.isLimitbuy, "N"));
|
|
|
productMap.put("is_limited", MapUtils.getString(map, ProductIndexEsField.islimited, "N"));
|
|
|
productMap.put("is_outlets", MapUtils.getIntValue(map, ProductIndexEsField.isOutlets, 2));
|
|
|
productMap.put("is_special", MapUtils.getString(map, ProductIndexEsField.isSpecial, "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("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));
|
|
|
|
|
|
// yohoodId
|
|
|
String yohoodId = MapUtils.getString(map, ProductIndexEsField.yohoodId, "");
|
|
|
productMap.put("yohood_id", StringUtils.isNotBlank(yohoodId) ? yohoodId : null);
|
|
|
|
|
|
// 屏蔽
|
|
|
productMap.put("is_fobbiden", MapUtils.getIntValue(map, ProductIndexEsField.isFobbiden, 0));
|
|
|
|
|
|
// 店铺屏蔽状态
|
|
|
productMap.put("store_show_status", MapUtils.getIntValue(map, ProductIndexEsField.storeShowStatus, 1));
|
|
|
|
|
|
// 全球购相关
|
|
|
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");
|
|
|
|
|
|
//标签
|
|
|
productMap.put("customize_tag", MapUtils.getObject(map, ProductIndexEsField.customizeTags, new JSONArray()));
|
|
|
productMap.put("promotion_tag", MapUtils.getObject(map, ProductIndexEsField.matchedPromotions, new JSONArray()));
|
|
|
|
|
|
return productMap;
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 判断是否有正在进行的促销
|
|
|
*
|
|
|
* @param map
|
|
|
* @return
|
|
|
*/
|
|
|
@SuppressWarnings({ "rawtypes", "unchecked" })
|
|
|
private static final Logger logger = LoggerFactory.getLogger(ProductIndexBaseService.class);
|
|
|
|
|
|
@Autowired
|
|
|
private ProductPricePlanIndexBaseService productPricePlanIndexBaseService;
|
|
|
|
|
|
// 获取从source中不返回的字段定义,用以节省带宽
|
|
|
private List<String> productIndexIncludeFields = new ArrayList<String>();
|
|
|
|
|
|
@PostConstruct
|
|
|
void init() {
|
|
|
productIndexIncludeFields.add(ProductIndexEsField.productId);
|
|
|
productIndexIncludeFields.add(ProductIndexEsField.productName);
|
|
|
productIndexIncludeFields.add(ProductIndexEsField.productSkn);
|
|
|
productIndexIncludeFields.add(ProductIndexEsField.cnAlphabet);
|
|
|
|
|
|
productIndexIncludeFields.add(ProductIndexEsField.brandId);
|
|
|
productIndexIncludeFields.add(ProductIndexEsField.brandName);
|
|
|
productIndexIncludeFields.add(ProductIndexEsField.brandDomain);
|
|
|
productIndexIncludeFields.add(ProductIndexEsField.countryId);
|
|
|
|
|
|
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.isStudentPrice);
|
|
|
productIndexIncludeFields.add(ProductIndexEsField.studentPrice);
|
|
|
productIndexIncludeFields.add(ProductIndexEsField.isstudentrebate);
|
|
|
|
|
|
productIndexIncludeFields.add(ProductIndexEsField.defaultImages);
|
|
|
productIndexIncludeFields.add(ProductIndexEsField.sknDefaultImg);
|
|
|
|
|
|
productIndexIncludeFields.add(ProductIndexEsField.editTime);
|
|
|
productIndexIncludeFields.add(ProductIndexEsField.shelveTime);
|
|
|
productIndexIncludeFields.add(ProductIndexEsField.firstShelveTime);
|
|
|
|
|
|
productIndexIncludeFields.add(ProductIndexEsField.maxSortId);
|
|
|
productIndexIncludeFields.add(ProductIndexEsField.middleSortId);
|
|
|
productIndexIncludeFields.add(ProductIndexEsField.smallSortId);
|
|
|
productIndexIncludeFields.add(ProductIndexEsField.smallSort);
|
|
|
|
|
|
productIndexIncludeFields.add(ProductIndexEsField.storageNum);
|
|
|
productIndexIncludeFields.add(ProductIndexEsField.salesNum);
|
|
|
|
|
|
productIndexIncludeFields.add(ProductIndexEsField.gender);
|
|
|
productIndexIncludeFields.add(ProductIndexEsField.ageLevel);
|
|
|
productIndexIncludeFields.add(ProductIndexEsField.salesPhrase);
|
|
|
// productIndexIncludeFields.add(ProductIndexEsField.phrase);
|
|
|
productIndexIncludeFields.add(ProductIndexEsField.status);
|
|
|
productIndexIncludeFields.add(ProductIndexEsField.goodsList);
|
|
|
|
|
|
productIndexIncludeFields.add(ProductIndexEsField.isnew);
|
|
|
productIndexIncludeFields.add(ProductIndexEsField.isAdvance);
|
|
|
productIndexIncludeFields.add(ProductIndexEsField.isDepositAdvance);
|
|
|
productIndexIncludeFields.add(ProductIndexEsField.isSeckill);
|
|
|
productIndexIncludeFields.add(ProductIndexEsField.isLimitbuy);
|
|
|
productIndexIncludeFields.add(ProductIndexEsField.islimited);
|
|
|
productIndexIncludeFields.add(ProductIndexEsField.isOutlets);
|
|
|
productIndexIncludeFields.add(ProductIndexEsField.isSpecial);
|
|
|
productIndexIncludeFields.add(ProductIndexEsField.isDiscount);
|
|
|
productIndexIncludeFields.add(ProductIndexEsField.isSoonSoldOut);
|
|
|
productIndexIncludeFields.add(ProductIndexEsField.ispromotion);
|
|
|
|
|
|
productIndexIncludeFields.add(ProductIndexEsField.bundleType);
|
|
|
productIndexIncludeFields.add(ProductIndexEsField.yohoodId);
|
|
|
|
|
|
productIndexIncludeFields.add(ProductIndexEsField.isFobbiden);
|
|
|
productIndexIncludeFields.add(ProductIndexEsField.storeShowStatus);
|
|
|
|
|
|
productIndexIncludeFields.add(ProductIndexEsField.isGlobal);
|
|
|
productIndexIncludeFields.add(ProductIndexEsField.tblBrandId);
|
|
|
productIndexIncludeFields.add(ProductIndexEsField.tblCountryId);
|
|
|
productIndexIncludeFields.add(ProductIndexEsField.tblCountryName);
|
|
|
|
|
|
productIndexIncludeFields.add(ProductIndexEsField.customizeTags);
|
|
|
productIndexIncludeFields.add(ProductIndexEsField.matchedPromotions);
|
|
|
productIndexIncludeFields.add(ProductIndexEsField.basePinRatio);
|
|
|
productIndexIncludeFields.add(ProductIndexEsField.breakingRate);
|
|
|
}
|
|
|
|
|
|
public List<String> getProductIndexIncludeFields() {
|
|
|
List<String> results = new ArrayList<String>();
|
|
|
results.addAll(productIndexIncludeFields);
|
|
|
return results;
|
|
|
}
|
|
|
|
|
|
@SuppressWarnings("unchecked")
|
|
|
public Map<String, Object> getProductMapFromEsSource(Map<String, Object> map) {
|
|
|
Map<String, Object> productMap = new HashMap<String, Object>();
|
|
|
if (map.containsKey("_highlight") && map.get("_highlight") != null) {
|
|
|
Map<String, Object> highlightMap = (Map<String, Object>) map.get("_highlight");
|
|
|
if (highlightMap.containsKey(ProductIndexEsField.productName_productName_ansj)) {
|
|
|
productMap.put("product_name_highlight", MapUtils.getString(highlightMap, ProductIndexEsField.productName_productName_ansj, ""));
|
|
|
}
|
|
|
}
|
|
|
productMap.put("product_id", MapUtils.getIntValue(map, ProductIndexEsField.productId, 0));
|
|
|
productMap.put("product_name", MapUtils.getString(map, ProductIndexEsField.productName, ""));
|
|
|
productMap.put("product_skn", MapUtils.getIntValue(map, ProductIndexEsField.productSkn, 0));
|
|
|
productMap.put("cn_alphabet", MapUtils.getString(map, ProductIndexEsField.cnAlphabet, ""));
|
|
|
|
|
|
productMap.put("brand_id", MapUtils.getIntValue(map, ProductIndexEsField.brandId, 0));
|
|
|
productMap.put("brand_name", MapUtils.getString(map, ProductIndexEsField.brandName, ""));
|
|
|
productMap.put("brand_domain", MapUtils.getString(map, ProductIndexEsField.brandDomain, ""));
|
|
|
productMap.put("country_id", MapUtils.getIntValue(map, ProductIndexEsField.countryId, 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));
|
|
|
// 学生价和学生返币
|
|
|
String isStudentPrice = MapUtils.getString(map, ProductIndexEsField.isStudentPrice, "N");
|
|
|
productMap.put("is_student_price", isStudentPrice);
|
|
|
productMap.put("student_price", "Y".equalsIgnoreCase(isStudentPrice) ? MapUtils.getDoubleValue(map, ProductIndexEsField.studentPrice) : null);
|
|
|
productMap.put("is_student_rebate", MapUtils.getString(map, ProductIndexEsField.isstudentrebate, "N"));
|
|
|
|
|
|
productMap.put("default_images", MapUtils.getString(map, ProductIndexEsField.defaultImages, ""));
|
|
|
productMap.put("skn_default_img", MapUtils.getString(map, ProductIndexEsField.sknDefaultImg, ""));
|
|
|
|
|
|
productMap.put("edit_time", MapUtils.getIntValue(map, ProductIndexEsField.editTime));
|
|
|
productMap.put("shelve_time", MapUtils.getIntValue(map, ProductIndexEsField.shelveTime));
|
|
|
productMap.put("first_shelve_time", MapUtils.getIntValue(map, ProductIndexEsField.firstShelveTime));
|
|
|
|
|
|
productMap.put("max_sort_id", MapUtils.getIntValue(map, ProductIndexEsField.maxSortId));
|
|
|
productMap.put("middle_sort_id", MapUtils.getIntValue(map, ProductIndexEsField.middleSortId));
|
|
|
productMap.put("small_sort_id", MapUtils.getIntValue(map, ProductIndexEsField.smallSortId));
|
|
|
productMap.put("small_sort_name", MapUtils.getString(map, ProductIndexEsField.smallSort, ""));
|
|
|
|
|
|
productMap.put("stock_number", MapUtils.getIntValue(map, ProductIndexEsField.storageNum, 0));
|
|
|
productMap.put("storage_num", MapUtils.getIntValue(map, ProductIndexEsField.storageNum, 0));
|
|
|
productMap.put("sales_num", MapUtils.getIntValue(map, ProductIndexEsField.salesNum, 0));
|
|
|
|
|
|
productMap.put("gender", MapUtils.getString(map, ProductIndexEsField.gender, ""));
|
|
|
productMap.put("age_level", MapUtils.getString(map, ProductIndexEsField.ageLevel, ""));// 年龄层,逗号隔开的字符串
|
|
|
productMap.put("sales_phrase", MapUtils.getString(map, ProductIndexEsField.salesPhrase, ""));
|
|
|
productMap.put("phrase", MapUtils.getString(map, ProductIndexEsField.phrase, ""));
|
|
|
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_seckill", MapUtils.getString(map, ProductIndexEsField.isSeckill, "N"));
|
|
|
productMap.put("is_limitbuy", MapUtils.getString(map, ProductIndexEsField.isLimitbuy, "N"));
|
|
|
productMap.put("is_limited", MapUtils.getString(map, ProductIndexEsField.islimited, "N"));
|
|
|
productMap.put("is_outlets", MapUtils.getIntValue(map, ProductIndexEsField.isOutlets, 2));
|
|
|
productMap.put("is_special", MapUtils.getString(map, ProductIndexEsField.isSpecial, "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("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));
|
|
|
|
|
|
// yohoodId
|
|
|
String yohoodId = MapUtils.getString(map, ProductIndexEsField.yohoodId, "");
|
|
|
productMap.put("yohood_id", StringUtils.isNotBlank(yohoodId) ? yohoodId : null);
|
|
|
|
|
|
// 屏蔽
|
|
|
productMap.put("is_fobbiden", MapUtils.getIntValue(map, ProductIndexEsField.isFobbiden, 0));
|
|
|
|
|
|
// 店铺屏蔽状态
|
|
|
productMap.put("store_show_status", MapUtils.getIntValue(map, ProductIndexEsField.storeShowStatus, 1));
|
|
|
|
|
|
// 全球购相关
|
|
|
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");
|
|
|
|
|
|
// 标签
|
|
|
productMap.put("customize_tag", MapUtils.getObject(map, ProductIndexEsField.customizeTags, new JSONArray()));
|
|
|
productMap.put("promotion_tag", MapUtils.getObject(map, ProductIndexEsField.matchedPromotions, new JSONArray()));
|
|
|
|
|
|
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;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 获取商品列表[不包含变价计划]
|
|
|
*
|
|
|
* @return
|
|
|
*/
|
|
|
public List<Map<String, Object>> getProductListWithOutPricePlan(List<Map<String, Object>> productEsSourceList) {
|
|
|
List<Map<String, Object>> results = new ArrayList<Map<String, Object>>();
|
|
|
for (Map<String, Object> productEsSource : productEsSourceList) {
|
|
|
results.add(this.getProductMapFromEsSource(productEsSource));
|
|
|
}
|
|
|
return results;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 获取商品列表[并返回变价计划]
|
|
|
*
|
|
|
* @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.getProductMapFromEsSource(productEsSource);
|
|
|
if (productMap != null) {
|
|
|
productMap.put("product_price_plan_list", productPricePlanMap.get(MapUtils.getString(productEsSource, "productSkn", "")));
|
|
|
}
|
|
|
results.add(productMap);
|
|
|
}
|
|
|
return results;
|
|
|
}
|
|
|
|
|
|
private Map<String, Object> fillProductMapWithPricePlan(Map<String, Object> productEsSource, Map<String, List<Map<String, Object>>> productPricePlanMap) {
|
|
|
Map<String, Object> result = this.getProductMapFromEsSource(productEsSource);
|
|
|
result.put("product_price_plan_list", productPricePlanMap.get(MapUtils.getString(productEsSource, "productSkn", "")));
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 获取商品列表[并返回变价计划]
|
|
|
*
|
|
|
* @return
|
|
|
*/
|
|
|
public Map<String, Map<String, Object>> getProductMapWithPricePlan(Map<String, Map<String, Object>> productMap) {
|
|
|
List<String> allProductSkns = new ArrayList<String>();
|
|
|
for (Map.Entry<String, Map<String, Object>> entry : productMap.entrySet()) {
|
|
|
allProductSkns.add(MapUtils.getString(entry.getValue(), "productSkn", ""));
|
|
|
}
|
|
|
if (allProductSkns.isEmpty()) {
|
|
|
return productMap;
|
|
|
}
|
|
|
// 每个skn对应的变价计划列表
|
|
|
Map<String, List<Map<String, Object>>> productPricePlanMap = productPricePlanIndexBaseService.searchProductPricePlan((String[]) allProductSkns
|
|
|
.toArray(new String[allProductSkns.size()]));
|
|
|
// 改变List<Map<String, Object>的值
|
|
|
Map<String, Map<String, Object>> results = new HashMap<String, Map<String, Object>>();
|
|
|
for (Map.Entry<String, Map<String, Object>> entry : productMap.entrySet()) {
|
|
|
results.put(entry.getKey(), this.fillProductMapWithPricePlan(entry.getValue(), productPricePlanMap));
|
|
|
}
|
|
|
return results;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 获取商品列表[并返回变价计划]
|
|
|
*
|
|
|
* @return
|
|
|
*/
|
|
|
public Map<String, List<Map<String, Object>>> getProductListWithPricePlan(Map<String, List<Map<String, Object>>> productListMap) {
|
|
|
List<String> allProductSkns = new ArrayList<String>();
|
|
|
for (Map.Entry<String, List<Map<String, Object>>> entry : productListMap.entrySet()) {
|
|
|
for (Map<String, Object> productEsSource : entry.getValue()) {
|
|
|
allProductSkns.add(MapUtils.getString(productEsSource, "productSkn", ""));
|
|
|
}
|
|
|
}
|
|
|
if (allProductSkns.isEmpty()) {
|
|
|
return productListMap;
|
|
|
}
|
|
|
// 每个skn对应的变价计划列表
|
|
|
Map<String, List<Map<String, Object>>> productPricePlanMap = productPricePlanIndexBaseService.searchProductPricePlan((String[]) allProductSkns
|
|
|
.toArray(new String[allProductSkns.size()]));
|
|
|
// 改变List<Map<String, Object>的值
|
|
|
Map<String, List<Map<String, Object>>> results = new HashMap<String, List<Map<String, Object>>>();
|
|
|
for (Map.Entry<String, List<Map<String, Object>>> entry : productListMap.entrySet()) {
|
|
|
List<Map<String, Object>> newResults = new ArrayList<Map<String, Object>>();
|
|
|
for (Map<String, Object> productEsSource : entry.getValue()) {
|
|
|
newResults.add(this.fillProductMapWithPricePlan(productEsSource, productPricePlanMap));
|
|
|
}
|
|
|
results.put(entry.getKey(), newResults);
|
|
|
}
|
|
|
return results;
|
|
|
}
|
|
|
try {
|
|
|
Date date = new Date();
|
|
|
long nowUnixTime = DateUtil.Date2TimeStamp(date);
|
|
|
JSONArray matchedPromotions = JSON.parseArray(MapUtils.getString(map, ProductIndexEsField.matchedPromotions, "[]"));
|
|
|
if (matchedPromotions == null || matchedPromotions.size() == 0) {
|
|
|
return false;
|
|
|
}
|
|
|
for (int i = 0; i < matchedPromotions.size(); i++) {
|
|
|
JSONObject matchedPromotion = matchedPromotions.getJSONObject(i);
|
|
|
int startTime = matchedPromotion.getIntValue("startTime");
|
|
|
int endTime = matchedPromotion.getIntValue("endTime");
|
|
|
if (startTime < nowUnixTime && nowUnixTime < endTime) {
|
|
|
return true;
|
|
|
}
|
|
|
}
|
|
|
return false;
|
|
|
} catch (Exception e) {
|
|
|
logger.error(e.getMessage(), e);
|
|
|
return false;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 获取商品列表[不包含变价计划]
|
|
|
*
|
|
|
* @return
|
|
|
*/
|
|
|
public List<Map<String, Object>> getProductListWithOutPricePlan(List<Map<String, Object>> productEsSourceList) {
|
|
|
List<Map<String, Object>> results = new ArrayList<Map<String, Object>>();
|
|
|
for (Map<String, Object> productEsSource : productEsSourceList) {
|
|
|
results.add(this.getProductMapFromEsSource(productEsSource));
|
|
|
}
|
|
|
return results;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 获取商品列表[并返回变价计划]
|
|
|
*
|
|
|
* @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.getProductMapFromEsSource(productEsSource);
|
|
|
if (productMap != null) {
|
|
|
productMap.put("product_price_plan_list", productPricePlanMap.get(MapUtils.getString(productEsSource, "productSkn", "")));
|
|
|
}
|
|
|
results.add(productMap);
|
|
|
}
|
|
|
return results;
|
|
|
}
|
|
|
|
|
|
private Map<String, Object> fillProductMapWithPricePlan(Map<String, Object> productEsSource, Map<String, List<Map<String, Object>>> productPricePlanMap) {
|
|
|
Map<String, Object> result = this.getProductMapFromEsSource(productEsSource);
|
|
|
result.put("product_price_plan_list", productPricePlanMap.get(MapUtils.getString(productEsSource, "productSkn", "")));
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 获取商品列表[并返回变价计划]
|
|
|
*
|
|
|
* @return
|
|
|
*/
|
|
|
public Map<String, Map<String, Object>> getProductMapWithPricePlan(Map<String, Map<String, Object>> productMap) {
|
|
|
List<String> allProductSkns = new ArrayList<String>();
|
|
|
for (Map.Entry<String, Map<String, Object>> entry : productMap.entrySet()) {
|
|
|
allProductSkns.add(MapUtils.getString(entry.getValue(), "productSkn", ""));
|
|
|
}
|
|
|
if (allProductSkns.isEmpty()) {
|
|
|
return productMap;
|
|
|
}
|
|
|
// 每个skn对应的变价计划列表
|
|
|
Map<String, List<Map<String, Object>>> productPricePlanMap = productPricePlanIndexBaseService.searchProductPricePlan((String[]) allProductSkns
|
|
|
.toArray(new String[allProductSkns.size()]));
|
|
|
// 改变List<Map<String, Object>的值
|
|
|
Map<String, Map<String, Object>> results = new HashMap<String, Map<String, Object>>();
|
|
|
for (Map.Entry<String, Map<String, Object>> entry : productMap.entrySet()) {
|
|
|
results.put(entry.getKey(), this.fillProductMapWithPricePlan(entry.getValue(), productPricePlanMap));
|
|
|
}
|
|
|
return results;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 获取商品列表[并返回变价计划]
|
|
|
*
|
|
|
* @return
|
|
|
*/
|
|
|
public Map<String, List<Map<String, Object>>> getProductListWithPricePlan(Map<String, List<Map<String, Object>>> productListMap) {
|
|
|
List<String> allProductSkns = new ArrayList<String>();
|
|
|
for (Map.Entry<String, List<Map<String, Object>>> entry : productListMap.entrySet()) {
|
|
|
for (Map<String, Object> productEsSource : entry.getValue()) {
|
|
|
allProductSkns.add(MapUtils.getString(productEsSource, "productSkn", ""));
|
|
|
}
|
|
|
}
|
|
|
if (allProductSkns.isEmpty()) {
|
|
|
return productListMap;
|
|
|
}
|
|
|
// 每个skn对应的变价计划列表
|
|
|
Map<String, List<Map<String, Object>>> productPricePlanMap = productPricePlanIndexBaseService.searchProductPricePlan((String[]) allProductSkns
|
|
|
.toArray(new String[allProductSkns.size()]));
|
|
|
// 改变List<Map<String, Object>的值
|
|
|
Map<String, List<Map<String, Object>>> results = new HashMap<String, List<Map<String, Object>>>();
|
|
|
for (Map.Entry<String, List<Map<String, Object>>> entry : productListMap.entrySet()) {
|
|
|
List<Map<String, Object>> newResults = new ArrayList<Map<String, Object>>();
|
|
|
for (Map<String, Object> productEsSource : entry.getValue()) {
|
|
|
newResults.add(this.fillProductMapWithPricePlan(productEsSource, productPricePlanMap));
|
|
|
}
|
|
|
results.put(entry.getKey(), newResults);
|
|
|
}
|
|
|
return results;
|
|
|
}
|
|
|
|
|
|
public static void main(String[] args) {
|
|
|
|
|
|
Map<String, Object> map = new HashMap<String, Object>();
|
|
|
|
|
|
map.put("key", new JSONArray());
|
|
|
map.put("key1", new ArrayList<Integer>());
|
|
|
|
|
|
JSONArray jSONArray = new JSONArray();
|
|
|
|
|
|
Map<String, Object> test1 = new HashMap<String, Object>();
|
|
|
test1.put("a", "a");
|
|
|
test1.put("b", "b");
|
|
|
jSONArray.add(new HashMap<String, Object>(test1));
|
|
|
jSONArray.add(new HashMap<String, Object>(test1));
|
|
|
map.put("key2", jSONArray);
|
|
|
|
|
|
System.out.println(MapUtils.getString(map, "key"));
|
|
|
;
|
|
|
System.out.println(MapUtils.getString(map, "key1"));
|
|
|
;
|
|
|
System.out.println(JSON.parseArray(MapUtils.getString(map, "key2", "[]")));
|
|
|
;
|
|
|
System.out.println(JSON.parseArray(MapUtils.getString(map, "key3", "[]")));
|
|
|
;
|
|
|
}
|
|
|
|
|
|
} |
...
|
...
|
|