fix遗留的取cover_1,cover_2的方式
Showing
5 changed files
with
30 additions
and
73 deletions
1 | -package com.yoho.search.service.helper; | ||
2 | - | ||
3 | -import com.alibaba.fastjson.JSONObject; | ||
4 | -import org.apache.commons.lang3.StringUtils; | ||
5 | -import org.springframework.stereotype.Component; | ||
6 | -import org.springframework.util.CollectionUtils; | ||
7 | - | ||
8 | -import java.lang.reflect.Method; | ||
9 | -import java.util.List; | ||
10 | - | ||
11 | -@Component | ||
12 | -public class SknImgHelper<Response> { | ||
13 | - | ||
14 | - public void genImage(List<JSONObject> goodsList, Response response) { | ||
15 | - if(CollectionUtils.isEmpty(goodsList)){ | ||
16 | - return; | ||
17 | - } | ||
18 | - JSONObject firstGood = null; | ||
19 | - for (JSONObject good : goodsList) { | ||
20 | - if ("Y".equals(good.getString("is_default")) && StringUtils.isNotEmpty(good.getString("images_url"))) { | ||
21 | - genImage(good, response); | ||
22 | - return; | ||
23 | - } | ||
24 | - // 有可能,goodlist中的所有good都没有cover1或者cover2,最终就采用第一个good | ||
25 | - if(null == firstGood && StringUtils.isNotEmpty(good.getString("images_url"))){ | ||
26 | - firstGood = good; | ||
27 | - } | ||
28 | - } | ||
29 | - if (firstGood != null) { | ||
30 | - genImage(firstGood, response); | ||
31 | - } | ||
32 | - } | ||
33 | - | ||
34 | - private void genImage(JSONObject good, Response response) { | ||
35 | - String images_url = good.getString("images_url"); | ||
36 | - String conver_1 = good.getString("cover_1"); | ||
37 | - String conver_2 = good.getString("cover_2"); | ||
38 | - try { | ||
39 | - Method[] methods = response.getClass().getDeclaredMethods(); | ||
40 | - // 循环查找想要的方法 | ||
41 | - for(Method method : methods) { | ||
42 | - if("setCover_1".equals(method.getName())) { | ||
43 | - method.invoke(response, (StringUtils.isEmpty(conver_1) ? images_url : conver_1)); | ||
44 | - } | ||
45 | - if("setCover_2".equals(method.getName())) { | ||
46 | - method.invoke(response, (StringUtils.isEmpty(conver_2) ? images_url : conver_2)); | ||
47 | - } | ||
48 | - } | ||
49 | - | ||
50 | - } catch (Exception e) { | ||
51 | - } | ||
52 | - } | ||
53 | - | ||
54 | - | ||
55 | - | ||
56 | -} |
@@ -11,7 +11,6 @@ import com.yoho.search.core.es.model.SearchResult; | @@ -11,7 +11,6 @@ import com.yoho.search.core.es.model.SearchResult; | ||
11 | import com.yoho.search.common.SearchCommonService; | 11 | import com.yoho.search.common.SearchCommonService; |
12 | import com.yoho.search.service.index.BrandIndexBaseService; | 12 | import com.yoho.search.service.index.BrandIndexBaseService; |
13 | import com.yoho.search.service.helper.ProductListHelper; | 13 | import com.yoho.search.service.helper.ProductListHelper; |
14 | -import com.yoho.search.service.helper.SknImgHelper; | ||
15 | import org.apache.commons.collections.MapUtils; | 14 | import org.apache.commons.collections.MapUtils; |
16 | import org.springframework.beans.factory.annotation.Autowired; | 15 | import org.springframework.beans.factory.annotation.Autowired; |
17 | import org.springframework.stereotype.Component; | 16 | import org.springframework.stereotype.Component; |
@@ -26,8 +25,6 @@ public class HrShopProductCacheBean extends AbstractCacheBean<HrShopProductReque | @@ -26,8 +25,6 @@ public class HrShopProductCacheBean extends AbstractCacheBean<HrShopProductReque | ||
26 | @Autowired | 25 | @Autowired |
27 | private SearchCommonService searchCommonService; | 26 | private SearchCommonService searchCommonService; |
28 | @Autowired | 27 | @Autowired |
29 | - private SknImgHelper sknImgHelper; | ||
30 | - @Autowired | ||
31 | private BrandIndexBaseService brandIndexBaseService; | 28 | private BrandIndexBaseService brandIndexBaseService; |
32 | @Autowired | 29 | @Autowired |
33 | private ProductListHelper productListHelper; | 30 | private ProductListHelper productListHelper; |
@@ -109,6 +106,8 @@ public class HrShopProductCacheBean extends AbstractCacheBean<HrShopProductReque | @@ -109,6 +106,8 @@ public class HrShopProductCacheBean extends AbstractCacheBean<HrShopProductReque | ||
109 | shopProduct.setGender(MapUtils.getString(productInfo, "gender", "1,3")); | 106 | shopProduct.setGender(MapUtils.getString(productInfo, "gender", "1,3")); |
110 | shopProduct.setSales_price(MapUtils.getDouble(productInfo, "sales_price", 0.0)); | 107 | shopProduct.setSales_price(MapUtils.getDouble(productInfo, "sales_price", 0.0)); |
111 | shopProduct.setDefault_images(MapUtils.getString(productInfo, "default_images", "")); | 108 | shopProduct.setDefault_images(MapUtils.getString(productInfo, "default_images", "")); |
109 | + shopProduct.setCover_1(MapUtils.getString(productInfo, "cover_1", "")); | ||
110 | + shopProduct.setCover_2(MapUtils.getString(productInfo, "cover_2", "")); | ||
112 | String brandId = MapUtils.getString(productInfo, "brand_id", ""); | 111 | String brandId = MapUtils.getString(productInfo, "brand_id", ""); |
113 | Map<String, Object> brand = brandMap.get(brandId); | 112 | Map<String, Object> brand = brandMap.get(brandId); |
114 | if (brand != null) { | 113 | if (brand != null) { |
@@ -116,8 +115,6 @@ public class HrShopProductCacheBean extends AbstractCacheBean<HrShopProductReque | @@ -116,8 +115,6 @@ public class HrShopProductCacheBean extends AbstractCacheBean<HrShopProductReque | ||
116 | shopProduct.setBrand_ico(MapUtils.getString(brand, "brand_ico", "")); | 115 | shopProduct.setBrand_ico(MapUtils.getString(brand, "brand_ico", "")); |
117 | } | 116 | } |
118 | shopProduct.setProduct_price_plan_list(MapUtils.getObject(productInfo, "product_price_plan_list", Collections.emptyList())); | 117 | shopProduct.setProduct_price_plan_list(MapUtils.getObject(productInfo, "product_price_plan_list", Collections.emptyList())); |
119 | - List<JSONObject> goodsList = JSON.parseObject(JSON.toJSONString(productInfo.get("goods_list")), new TypeReference<List<JSONObject>>() {}); | ||
120 | - sknImgHelper.genImage(goodsList, shopProduct); | ||
121 | shopProductList.add(shopProduct); | 118 | shopProductList.add(shopProduct); |
122 | } | 119 | } |
123 | } | 120 | } |
@@ -16,7 +16,19 @@ import java.util.Arrays; | @@ -16,7 +16,19 @@ import java.util.Arrays; | ||
16 | import java.util.List; | 16 | import java.util.List; |
17 | 17 | ||
18 | public class HrShopProductRequest implements ICacheRequest { | 18 | public class HrShopProductRequest implements ICacheRequest { |
19 | - private static final List<String> includeFields = Arrays.asList(ProductIndexEsField.productSkn, ProductIndexEsField.productName, ProductIndexEsField.shopId, ProductIndexEsField.shopName, ProductIndexEsField.defaultImages, ProductIndexEsField.goodsList, ProductIndexEsField.salesPrice,ProductIndexEsField.gender, ProductIndexEsField.brandId); | 19 | + private static final List<String> includeFields = |
20 | + Arrays.asList(ProductIndexEsField.productSkn, | ||
21 | + ProductIndexEsField.productName, | ||
22 | + ProductIndexEsField.shopId, | ||
23 | + ProductIndexEsField.shopName, | ||
24 | + ProductIndexEsField.defaultImages, | ||
25 | + ProductIndexEsField.cover_1, | ||
26 | + ProductIndexEsField.cover_2, | ||
27 | + ProductIndexEsField.salesPrice, | ||
28 | + ProductIndexEsField.gender, | ||
29 | + ProductIndexEsField.brandId); | ||
30 | + | ||
31 | + | ||
20 | private ParamQueryFilter paramQueryFilter; | 32 | private ParamQueryFilter paramQueryFilter; |
21 | private Integer shopId; | 33 | private Integer shopId; |
22 | private RedisKeyBuilder redisKeyBuilder; | 34 | private RedisKeyBuilder redisKeyBuilder; |
1 | package com.yoho.search.service.scene.sknimg; | 1 | package com.yoho.search.service.scene.sknimg; |
2 | 2 | ||
3 | -import com.alibaba.fastjson.JSON; | ||
4 | -import com.alibaba.fastjson.JSONObject; | ||
5 | -import com.alibaba.fastjson.TypeReference; | ||
6 | import com.yoho.search.base.utils.ISearchConstants; | 3 | import com.yoho.search.base.utils.ISearchConstants; |
7 | import com.yoho.search.base.utils.ProductIndexEsField; | 4 | import com.yoho.search.base.utils.ProductIndexEsField; |
8 | import com.yoho.search.cache.beans.AbstractCacheBean; | 5 | import com.yoho.search.cache.beans.AbstractCacheBean; |
6 | +import com.yoho.search.common.SearchCommonService; | ||
9 | import com.yoho.search.core.es.model.SearchParam; | 7 | import com.yoho.search.core.es.model.SearchParam; |
10 | import com.yoho.search.core.es.model.SearchResult; | 8 | import com.yoho.search.core.es.model.SearchResult; |
11 | -import com.yoho.search.common.SearchCommonService; | ||
12 | -import com.yoho.search.service.helper.SknImgHelper; | ||
13 | import org.apache.commons.collections.CollectionUtils; | 9 | import org.apache.commons.collections.CollectionUtils; |
14 | import org.apache.commons.collections.MapUtils; | 10 | import org.apache.commons.collections.MapUtils; |
15 | import org.elasticsearch.index.query.QueryBuilders; | 11 | import org.elasticsearch.index.query.QueryBuilders; |
16 | import org.springframework.beans.factory.annotation.Autowired; | 12 | import org.springframework.beans.factory.annotation.Autowired; |
17 | import org.springframework.stereotype.Component; | 13 | import org.springframework.stereotype.Component; |
18 | 14 | ||
19 | -import java.util.*; | 15 | +import java.util.ArrayList; |
16 | +import java.util.HashMap; | ||
17 | +import java.util.List; | ||
18 | +import java.util.Map; | ||
20 | 19 | ||
21 | @Component | 20 | @Component |
22 | public class SknImgsCacheBean extends AbstractCacheBean<SknImgsResquest, SknImgsResponse, SknImgsRequestResponse> { | 21 | public class SknImgsCacheBean extends AbstractCacheBean<SknImgsResquest, SknImgsResponse, SknImgsRequestResponse> { |
23 | 22 | ||
24 | @Autowired | 23 | @Autowired |
25 | private SearchCommonService searchCommonService; | 24 | private SearchCommonService searchCommonService; |
26 | - @Autowired | ||
27 | - private SknImgHelper sknImgHelper; | ||
28 | 25 | ||
29 | @Override | 26 | @Override |
30 | protected boolean useEhCache() { | 27 | protected boolean useEhCache() { |
@@ -75,8 +72,8 @@ public class SknImgsCacheBean extends AbstractCacheBean<SknImgsResquest, SknImgs | @@ -75,8 +72,8 @@ public class SknImgsCacheBean extends AbstractCacheBean<SknImgsResquest, SknImgs | ||
75 | response.setDefault_images(MapUtils.getString(product, ProductIndexEsField.defaultImages, "")); | 72 | response.setDefault_images(MapUtils.getString(product, ProductIndexEsField.defaultImages, "")); |
76 | response.setSkn_default_img(MapUtils.getString(product, ProductIndexEsField.sknDefaultImg, "")); | 73 | response.setSkn_default_img(MapUtils.getString(product, ProductIndexEsField.sknDefaultImg, "")); |
77 | response.setGender(MapUtils.getString(product, ProductIndexEsField.gender, "")); | 74 | response.setGender(MapUtils.getString(product, ProductIndexEsField.gender, "")); |
78 | - List<JSONObject> goodsList = JSON.parseObject(JSON.toJSONString(product.get(ProductIndexEsField.goodsList)), new TypeReference<List<JSONObject>>() {}); | ||
79 | - sknImgHelper.genImage(goodsList, response); | 75 | + response.setCover_1(MapUtils.getString(product, ProductIndexEsField.cover_1, "")); |
76 | + response.setCover_2(MapUtils.getString(product, ProductIndexEsField.cover_2, "")); | ||
80 | defaultImgTempMap.put(MapUtils.getString(product,ProductIndexEsField.productSkn,""), response); | 77 | defaultImgTempMap.put(MapUtils.getString(product,ProductIndexEsField.productSkn,""), response); |
81 | } | 78 | } |
82 | for (SknImgsRequestResponse requestResponse : missCacheRequests) { | 79 | for (SknImgsRequestResponse requestResponse : missCacheRequests) { |
@@ -9,7 +9,14 @@ import java.util.Arrays; | @@ -9,7 +9,14 @@ import java.util.Arrays; | ||
9 | import java.util.List; | 9 | import java.util.List; |
10 | 10 | ||
11 | public class SknImgsResquest implements ICacheRequest { | 11 | public class SknImgsResquest implements ICacheRequest { |
12 | - private static final List<String> includeFields = Arrays.asList(ProductIndexEsField.productSkn,ProductIndexEsField.defaultImages, ProductIndexEsField.sknDefaultImg, ProductIndexEsField.goodsList,ProductIndexEsField.gender); | 12 | + private static final List<String> includeFields = Arrays.asList( |
13 | + ProductIndexEsField.productSkn, | ||
14 | + ProductIndexEsField.defaultImages, | ||
15 | + ProductIndexEsField.sknDefaultImg, | ||
16 | + ProductIndexEsField.cover_1, | ||
17 | + ProductIndexEsField.cover_2, | ||
18 | + ProductIndexEsField.gender); | ||
19 | + | ||
13 | private Integer productSkn; | 20 | private Integer productSkn; |
14 | 21 | ||
15 | public SknImgsResquest(Integer productSkn){ | 22 | public SknImgsResquest(Integer productSkn){ |
-
Please register or login to post a comment