Authored by hugufei

revert

... ... @@ -14,9 +14,7 @@ import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
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;
... ... @@ -104,6 +102,8 @@ public class ProductIndexBaseService {
productIndexIncludeFields.add(ProductIndexEsField.customizeTags);
productIndexIncludeFields.add(ProductIndexEsField.matchedPromotions);
productIndexIncludeFields.add(ProductIndexEsField.basePinRatio);
productIndexIncludeFields.add(ProductIndexEsField.breakingRate);
productIndexIncludeFields.add(ProductIndexEsField.deposit);
productIndexIncludeFields.add(ProductIndexEsField.depositMultiples);
... ... @@ -115,24 +115,29 @@ public class ProductIndexBaseService {
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("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));
... ... @@ -146,31 +151,28 @@ public class ProductIndexBaseService {
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", this.getGoodsList(map));
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"));
... ... @@ -184,6 +186,11 @@ 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("bundle_type", MapUtils.getIntValue(map, ProductIndexEsField.bundleType, 0));
// yohoodId
... ... @@ -207,48 +214,17 @@ public class ProductIndexBaseService {
// 标签
productMap.put("customize_tag", MapUtils.getObject(map, ProductIndexEsField.customizeTags, new JSONArray()));
productMap.put("promotion_tag", this.getPomotionTags(map));// 促销标签
// 定金 定金倍数
productMap.put("deposit", MapUtils.getDoubleValue(map, ProductIndexEsField.deposit, 0));
productMap.put("deposit_multiples", MapUtils.getIntValue(map, ProductIndexEsField.depositMultiples));
// 商品标签-首页弹窗专用
productMap.put("is_promotion_active", "N");// 当前是否有促销正在进行
boolean promotionActive = getPromotionActive(map);
if (promotionActive) {
productMap.put("is_promotion_active", "Y");
}
productMap.put("is_latest_reduce_price", MapUtils.getString(map, ProductIndexEsField.isLatestReducePrice, "N"));// 是否最新降价
return productMap;
}
// 定金 定金倍数
productMap.put("deposit", MapUtils.getDoubleValue(map, ProductIndexEsField.deposit, 0));
productMap.put("deposit_multiples", MapUtils.getIntValue(map, ProductIndexEsField.depositMultiples));
private JSONArray getGoodsList(Map<String, Object> productMap) {
Object goodList = productMap.get(ProductIndexEsField.goodsList);
if (goodList == null) {
return new JSONArray();
}
if (!(goodList instanceof List)) {
return new JSONArray();
}
List<?> list = (List<?>) (goodList);
JSONArray jsonArray = new JSONArray();
for (Object object : list) {
if (!(object instanceof Map)) {
continue;
}
Map<?, ?> good = (Map<?, ?>) object;
JSONObject returnObject = new JSONObject();
returnObject.put("product_skc", MapUtils.getIntValue(good, "product_skc", 0));
returnObject.put("images_url", MapUtils.getString(good, "images_url", ""));
returnObject.put("color_name", MapUtils.getString(good, "color_name", ""));
returnObject.put("cover_1", MapUtils.getString(good, "cover_1", ""));
returnObject.put("cover_2", MapUtils.getString(good, "cover_2", ""));
returnObject.put("is_default", MapUtils.getString(good, "is_default", ""));
returnObject.put("status", MapUtils.getIntValue(good, "status", 0));
jsonArray.add(returnObject);
}
return jsonArray;
return productMap;
}
/**
... ... @@ -269,12 +245,12 @@ public class ProductIndexBaseService {
for (int i = 0; i < matchedPromotionArray.size(); i++) {
Map<?, ?> matchedPromotion = (Map<?, ?>) matchedPromotionArray.get(i);
String name = MapUtils.getString(matchedPromotion, "name", "");
if (StringUtils.isBlank(name)) {
if(StringUtils.isBlank(name)){
continue;
}
int startTime = MapUtils.getIntValue(matchedPromotion, "startTime");
int endTime = MapUtils.getIntValue(matchedPromotion, "endTime");
if (current < startTime || current > endTime) {
if (current < startTime || current > endTime) {
continue;
}
results.add(matchedPromotion);
... ... @@ -414,29 +390,4 @@ public class ProductIndexBaseService {
return results;
}
public static void main(String[] args) {
Map<String, Object> map = new HashMap<String, Object>();
JSONArray js = new JSONArray();
Map<String, Object> test1 = new HashMap<String, Object>();
test1.put("startTime", 1491793200);
test1.put("id", 10692);
test1.put("endTime", 1509465599);
test1.put("type", "Needpaygift");
js.add(test1);
Map<String, Object> test2 = new HashMap<String, Object>();
test2.put("startTime", 1491793200);
test2.put("id", 10692);
test2.put("endTime", 1509465599);
test2.put("type", "Needpaygift");
js.add(test2);
map.put(ProductIndexEsField.matchedPromotions, js);
System.out.println(JSON.parseArray(MapUtils.getString(map, ProductIndexEsField.matchedPromotions, "[]")));
}
}
... ...