新开/web/productList接口给PC用
Showing
1 changed file
with
154 additions
and
0 deletions
1 | +package com.yoho.search.service.base.index; | ||
2 | + | ||
3 | +import java.util.ArrayList; | ||
4 | +import java.util.HashMap; | ||
5 | +import java.util.List; | ||
6 | +import java.util.Map; | ||
7 | + | ||
8 | +import javax.annotation.PostConstruct; | ||
9 | + | ||
10 | +import org.apache.commons.collections.MapUtils; | ||
11 | +import org.apache.commons.lang.StringUtils; | ||
12 | +import org.springframework.beans.factory.annotation.Autowired; | ||
13 | +import org.springframework.stereotype.Service; | ||
14 | + | ||
15 | +import com.alibaba.fastjson.JSONArray; | ||
16 | +import com.yoho.search.base.utils.ProductIndexEsField; | ||
17 | + | ||
18 | +@Service | ||
19 | +public class WebProductIndexBaseService { | ||
20 | + | ||
21 | + @Autowired | ||
22 | + private ProductPricePlanIndexBaseService productPricePlanIndexBaseService; | ||
23 | + | ||
24 | + // 获取从source中不返回的字段定义,用以节省带宽 | ||
25 | + private List<String> productIndexIncludeFields = new ArrayList<String>(); | ||
26 | + | ||
27 | + @PostConstruct | ||
28 | + void init() { | ||
29 | + productIndexIncludeFields.add(ProductIndexEsField.productName); | ||
30 | + productIndexIncludeFields.add(ProductIndexEsField.productSkn); | ||
31 | + | ||
32 | + productIndexIncludeFields.add(ProductIndexEsField.shopId); | ||
33 | + productIndexIncludeFields.add(ProductIndexEsField.shopName); | ||
34 | + productIndexIncludeFields.add(ProductIndexEsField.shopDomain); | ||
35 | + | ||
36 | + productIndexIncludeFields.add(ProductIndexEsField.salesPrice); | ||
37 | + productIndexIncludeFields.add(ProductIndexEsField.marketPrice); | ||
38 | + productIndexIncludeFields.add(ProductIndexEsField.vipPrice); | ||
39 | + productIndexIncludeFields.add(ProductIndexEsField.vip1Price); | ||
40 | + productIndexIncludeFields.add(ProductIndexEsField.vip2Price); | ||
41 | + productIndexIncludeFields.add(ProductIndexEsField.vip3Price); | ||
42 | + productIndexIncludeFields.add(ProductIndexEsField.vipDiscountType); | ||
43 | + | ||
44 | + productIndexIncludeFields.add(ProductIndexEsField.defaultImages); | ||
45 | + productIndexIncludeFields.add(ProductIndexEsField.firstShelveTime); | ||
46 | + | ||
47 | + productIndexIncludeFields.add(ProductIndexEsField.gender); | ||
48 | + productIndexIncludeFields.add(ProductIndexEsField.status); | ||
49 | + productIndexIncludeFields.add(ProductIndexEsField.goodsList); | ||
50 | + | ||
51 | + productIndexIncludeFields.add(ProductIndexEsField.isnew); | ||
52 | + productIndexIncludeFields.add(ProductIndexEsField.isAdvance); | ||
53 | + productIndexIncludeFields.add(ProductIndexEsField.isDepositAdvance); | ||
54 | + productIndexIncludeFields.add(ProductIndexEsField.islimited); | ||
55 | + productIndexIncludeFields.add(ProductIndexEsField.isDiscount); | ||
56 | + productIndexIncludeFields.add(ProductIndexEsField.isSoonSoldOut); | ||
57 | + | ||
58 | + productIndexIncludeFields.add(ProductIndexEsField.bundleType); | ||
59 | + productIndexIncludeFields.add(ProductIndexEsField.yohoodId); | ||
60 | + | ||
61 | + productIndexIncludeFields.add(ProductIndexEsField.isGlobal); | ||
62 | + productIndexIncludeFields.add(ProductIndexEsField.tblBrandId); | ||
63 | + productIndexIncludeFields.add(ProductIndexEsField.tblCountryId); | ||
64 | + productIndexIncludeFields.add(ProductIndexEsField.tblCountryName); | ||
65 | + } | ||
66 | + | ||
67 | + public List<String> getWebProductIndexIncludeFields() { | ||
68 | + List<String> results = new ArrayList<String>(); | ||
69 | + results.addAll(productIndexIncludeFields); | ||
70 | + return results; | ||
71 | + } | ||
72 | + | ||
73 | + /** | ||
74 | + * pc商品列表返回的字段 | ||
75 | + * | ||
76 | + * @param map | ||
77 | + * @return | ||
78 | + */ | ||
79 | + private Map<String, Object> getPcProductMapFromEsSource(Map<String, Object> map) { | ||
80 | + Map<String, Object> productMap = new HashMap<String, Object>(); | ||
81 | + productMap.put("product_name", MapUtils.getString(map, ProductIndexEsField.productName, "")); | ||
82 | + productMap.put("product_skn", MapUtils.getIntValue(map, ProductIndexEsField.productSkn, 0)); | ||
83 | + | ||
84 | + productMap.put("shop_id", MapUtils.getIntValue(map, ProductIndexEsField.shopId, 0)); | ||
85 | + productMap.put("shop_name", MapUtils.getString(map, ProductIndexEsField.shopName, "")); | ||
86 | + productMap.put("shop_domain", MapUtils.getString(map, ProductIndexEsField.shopDomain, "")); | ||
87 | + | ||
88 | + productMap.put("sales_price", MapUtils.getDoubleValue(map, ProductIndexEsField.salesPrice, 0)); | ||
89 | + productMap.put("market_price", MapUtils.getDoubleValue(map, ProductIndexEsField.marketPrice, 0)); | ||
90 | + productMap.put("vip_price", MapUtils.getDoubleValue(map, ProductIndexEsField.vipPrice, 0)); | ||
91 | + productMap.put("vip1_price", MapUtils.getDoubleValue(map, ProductIndexEsField.vip1Price, 0)); | ||
92 | + productMap.put("vip2_price", MapUtils.getDoubleValue(map, ProductIndexEsField.vip2Price, 0)); | ||
93 | + productMap.put("vip3_price", MapUtils.getDoubleValue(map, ProductIndexEsField.vip3Price, 0)); | ||
94 | + productMap.put("vip_discount_type", MapUtils.getIntValue(map, ProductIndexEsField.vipDiscountType, 1)); | ||
95 | + | ||
96 | + productMap.put("default_images", MapUtils.getString(map, ProductIndexEsField.defaultImages, "")); | ||
97 | + productMap.put("first_shelve_time", MapUtils.getIntValue(map, ProductIndexEsField.firstShelveTime)); | ||
98 | + | ||
99 | + productMap.put("gender", MapUtils.getString(map, ProductIndexEsField.gender, "")); | ||
100 | + productMap.put("status", MapUtils.getIntValue(map, ProductIndexEsField.status, 0)); | ||
101 | + productMap.put("goods_list", MapUtils.getObject(map, ProductIndexEsField.goodsList, new JSONArray())); | ||
102 | + | ||
103 | + productMap.put("is_new", MapUtils.getString(map, ProductIndexEsField.isnew, "N")); | ||
104 | + productMap.put("is_advance", MapUtils.getString(map, ProductIndexEsField.isAdvance, "N")); | ||
105 | + productMap.put("is_deposit_advance", MapUtils.getString(map, ProductIndexEsField.isDepositAdvance, "N")); | ||
106 | + productMap.put("is_limited", MapUtils.getString(map, ProductIndexEsField.islimited, "N")); | ||
107 | + productMap.put("is_discount", MapUtils.getString(map, ProductIndexEsField.isDiscount, "N")); | ||
108 | + productMap.put("is_soon_sold_out", MapUtils.getString(map, ProductIndexEsField.isSoonSoldOut, "N")); | ||
109 | + | ||
110 | + // 套餐 | ||
111 | + productMap.put("bundle_type", MapUtils.getIntValue(map, ProductIndexEsField.bundleType, 0)); | ||
112 | + | ||
113 | + // yohoodId | ||
114 | + String yohoodId = MapUtils.getString(map, ProductIndexEsField.yohoodId, ""); | ||
115 | + productMap.put("yohood_id", StringUtils.isNotBlank(yohoodId) ? yohoodId : null); | ||
116 | + | ||
117 | + // 全球购相关 | ||
118 | + productMap.put("is_global", MapUtils.getString(map, ProductIndexEsField.isGlobal, "N")); | ||
119 | + int tbl_country_id = MapUtils.getIntValue(map, ProductIndexEsField.tblCountryId, 0); | ||
120 | + productMap.put("tbl_country_id", tbl_country_id); | ||
121 | + productMap.put("tbl_brand_id", MapUtils.getIntValue(map, ProductIndexEsField.tblBrandId, 0)); | ||
122 | + productMap.put("tbl_country_name", MapUtils.getString(map, ProductIndexEsField.tblCountryName, "")); | ||
123 | + productMap.put("tbl_plane", (tbl_country_id > 0 && tbl_country_id != 86) ? "Y" : "N"); | ||
124 | + | ||
125 | + return productMap; | ||
126 | + } | ||
127 | + | ||
128 | + /** | ||
129 | + * 获取商品列表[并返回变价计划] | ||
130 | + * | ||
131 | + * @return | ||
132 | + */ | ||
133 | + public List<Map<String, Object>> getProductListWithPricePlan(List<Map<String, Object>> productEsSourceList) { | ||
134 | + if (productEsSourceList == null || productEsSourceList.isEmpty()) { | ||
135 | + return new ArrayList<Map<String, Object>>(); | ||
136 | + } | ||
137 | + // 获取搜索结果的skn,根据它们来获取product_price_plan | ||
138 | + String[] sknStr = new String[productEsSourceList.size()]; | ||
139 | + for (int i = 0; i < productEsSourceList.size(); i++) { | ||
140 | + sknStr[i] = MapUtils.getString(productEsSourceList.get(i), "productSkn", ""); | ||
141 | + } | ||
142 | + List<Map<String, Object>> results = new ArrayList<Map<String, Object>>(); | ||
143 | + Map<String, List<Map<String, Object>>> productPricePlanMap = productPricePlanIndexBaseService.searchProductPricePlan(sknStr); | ||
144 | + for (Map<String, Object> productEsSource : productEsSourceList) { | ||
145 | + Map<String, Object> productMap = this.getPcProductMapFromEsSource(productEsSource); | ||
146 | + if (productMap != null) { | ||
147 | + productMap.put("product_price_plan_list", productPricePlanMap.get(MapUtils.getString(productEsSource, "productSkn", ""))); | ||
148 | + } | ||
149 | + results.add(productMap); | ||
150 | + } | ||
151 | + return results; | ||
152 | + } | ||
153 | + | ||
154 | +} |
-
Please register or login to post a comment