Authored by 胡古飞

fix shops interfaces

@@ -22,65 +22,64 @@ import com.yoho.search.service.vo.SearchApiResult; @@ -22,65 +22,64 @@ import com.yoho.search.service.vo.SearchApiResult;
22 @Controller 22 @Controller
23 public class ShopsController { 23 public class ShopsController {
24 24
25 - @Autowired  
26 - private IShopsService shopsService;  
27 - @Autowired  
28 - private IShopListService shopListService; 25 + @Autowired
  26 + private IShopsService shopsService;
  27 + @Autowired
  28 + private IShopListService shopListService;
29 29
30 - /**  
31 - * 搜索店铺与品牌  
32 - *  
33 - * @param request  
34 - * @return  
35 - */  
36 - @DownGradeAble(key = "shopsNew")  
37 - @RequestMapping(method = RequestMethod.GET, value = "/shopsNew")  
38 - @ResponseBody  
39 - public SearchApiResult searchShopsNew(HttpServletRequest request) {  
40 - Map<String, String> paramMap = HttpServletRequestUtils.transParamType(request);  
41 - return shopsService.searchShopsNew(paramMap);  
42 - }  
43 -  
44 - /**  
45 - * 按关键字搜出一个符合条件的品牌  
46 - *  
47 - * @param request  
48 - * @return  
49 - */  
50 - @DownGradeAble(key = "shops")  
51 - @RequestMapping(method = RequestMethod.GET, value = "/shops")  
52 - @ResponseBody  
53 - public SearchApiResult searchShops(HttpServletRequest request) {  
54 - Map<String, String> paramMap = HttpServletRequestUtils.transParamType(request);  
55 - return shopsService.searchShops(paramMap);  
56 - } 30 + /**
  31 + * 按shopId聚合一些商品[目前好像没在调]
  32 + *
  33 + * @param request
  34 + * @return
  35 + */
  36 + @DownGradeAble(key = "group_shops")
  37 + @RequestMapping(method = RequestMethod.GET, value = "/group_shops")
  38 + @ResponseBody
  39 + public SearchApiResult group_shops(HttpServletRequest request) {
  40 + Map<String, String> paramMap = HttpServletRequestUtils.transParamType(request);
  41 + return shopsService.group_shops(paramMap);
  42 + }
57 43
58 - /**  
59 - * 按shopId聚合一些商品[目前好像没在调]  
60 - *  
61 - * @param request  
62 - * @return  
63 - */  
64 - @DownGradeAble(key = "group_shops")  
65 - @RequestMapping(method = RequestMethod.GET, value = "/group_shops")  
66 - @ResponseBody  
67 - public SearchApiResult group_shops(HttpServletRequest request) {  
68 - Map<String, String> paramMap = HttpServletRequestUtils.transParamType(request);  
69 - return shopsService.group_shops(paramMap);  
70 - }  
71 -  
72 -  
73 - /**  
74 - * 按关键字搜出一堆店铺  
75 - *  
76 - * @param request  
77 - * @return  
78 - */  
79 - @DownGradeAble(key = "shopList")  
80 - @RequestMapping(method = RequestMethod.GET, value = "/shopList")  
81 - @ResponseBody  
82 - public SearchApiResult shopList(HttpServletRequest request) {  
83 - Map<String, String> paramMap = HttpServletRequestUtils.transParamType(request);  
84 - return shopListService.searchShopList(paramMap);  
85 - } 44 + /**
  45 + * 按关键字搜出一个符合条件的品牌
  46 + *
  47 + * @param request
  48 + * @return
  49 + */
  50 + @DownGradeAble(key = "shops")
  51 + @RequestMapping(method = RequestMethod.GET, value = "/shops")
  52 + @ResponseBody
  53 + public SearchApiResult searchShops(HttpServletRequest request) {
  54 + Map<String, String> paramMap = HttpServletRequestUtils.transParamType(request);
  55 + return shopsService.searchYohoBrand(paramMap);
  56 + }
  57 +
  58 + /**
  59 + * 搜索店铺与品牌
  60 + *
  61 + * @param request
  62 + * @return
  63 + */
  64 + @DownGradeAble(key = "shopsNew")
  65 + @RequestMapping(method = RequestMethod.GET, value = "/shopsNew")
  66 + @ResponseBody
  67 + public SearchApiResult searchShopsNew(HttpServletRequest request) {
  68 + Map<String, String> paramMap = HttpServletRequestUtils.transParamType(request);
  69 + return shopsService.searchShopsNew(paramMap);
  70 + }
  71 +
  72 + /**
  73 + * 按关键字搜出一堆店铺
  74 + *
  75 + * @param request
  76 + * @return
  77 + */
  78 + @DownGradeAble(key = "shopList")
  79 + @RequestMapping(method = RequestMethod.GET, value = "/shopList")
  80 + @ResponseBody
  81 + public SearchApiResult shopList(HttpServletRequest request) {
  82 + Map<String, String> paramMap = HttpServletRequestUtils.transParamType(request);
  83 + return shopListService.searchShopList(paramMap);
  84 + }
86 } 85 }
1 package com.yoho.search.service.servicenew.impl; 1 package com.yoho.search.service.servicenew.impl;
2 2
3 -import java.io.UnsupportedEncodingException;  
4 -import java.net.URLDecoder;  
5 import java.util.ArrayList; 3 import java.util.ArrayList;
6 import java.util.Collections; 4 import java.util.Collections;
7 import java.util.Comparator; 5 import java.util.Comparator;
@@ -46,7 +44,6 @@ import com.yoho.search.service.service.helper.SearchCommonHelper; @@ -46,7 +44,6 @@ import com.yoho.search.service.service.helper.SearchCommonHelper;
46 import com.yoho.search.service.service.helper.SearchServiceHelper; 44 import com.yoho.search.service.service.helper.SearchServiceHelper;
47 import com.yoho.search.service.servicenew.IShopListService; 45 import com.yoho.search.service.servicenew.IShopListService;
48 import com.yoho.search.service.utils.SearchKeyWordUtils; 46 import com.yoho.search.service.utils.SearchKeyWordUtils;
49 -import com.yoho.search.service.utils.SearchRequestParams;  
50 import com.yoho.search.service.vo.SearchApiResult; 47 import com.yoho.search.service.vo.SearchApiResult;
51 import com.yoho.search.service.vo.SearchSort; 48 import com.yoho.search.service.vo.SearchSort;
52 49
@@ -13,7 +13,6 @@ import org.elasticsearch.index.query.BoolQueryBuilder; @@ -13,7 +13,6 @@ import org.elasticsearch.index.query.BoolQueryBuilder;
13 import org.elasticsearch.index.query.MatchQueryBuilder; 13 import org.elasticsearch.index.query.MatchQueryBuilder;
14 import org.elasticsearch.index.query.MultiMatchQueryBuilder; 14 import org.elasticsearch.index.query.MultiMatchQueryBuilder;
15 import org.elasticsearch.index.query.QueryBuilders; 15 import org.elasticsearch.index.query.QueryBuilders;
16 -import org.elasticsearch.index.query.TermQueryBuilder;  
17 import org.elasticsearch.search.SearchHit; 16 import org.elasticsearch.search.SearchHit;
18 import org.elasticsearch.search.SearchHits; 17 import org.elasticsearch.search.SearchHits;
19 import org.elasticsearch.search.aggregations.AbstractAggregationBuilder; 18 import org.elasticsearch.search.aggregations.AbstractAggregationBuilder;
@@ -122,6 +121,7 @@ public class ShopsServiceImpl extends BaseService implements IShopsService, Appl @@ -122,6 +121,7 @@ public class ShopsServiceImpl extends BaseService implements IShopsService, Appl
122 // 5)查询shops索引,获取shopsInfo 121 // 5)查询shops索引,获取shopsInfo
123 SearchApiResult searchResultShops = getShopsInfo(paramMap); 122 SearchApiResult searchResultShops = getShopsInfo(paramMap);
124 JSONObject jsonObject = (JSONObject) searchResultShops.getData(); 123 JSONObject jsonObject = (JSONObject) searchResultShops.getData();
  124 + @SuppressWarnings("unchecked")
125 Map<String, Map<String, Object>> shopInfoMap = (Map<String, Map<String, Object>>) jsonObject.get("shopInfo"); 125 Map<String, Map<String, Object>> shopInfoMap = (Map<String, Map<String, Object>>) jsonObject.get("shopInfo");
126 126
127 // 5)、构建返回结果并将结果存进缓存 127 // 5)、构建返回结果并将结果存进缓存
@@ -142,6 +142,65 @@ public class ShopsServiceImpl extends BaseService implements IShopsService, Appl @@ -142,6 +142,65 @@ public class ShopsServiceImpl extends BaseService implements IShopsService, Appl
142 } 142 }
143 } 143 }
144 144
  145 + private Map<String, Object> getGroupShopResponseMap(MultiBucketsAggregation aggregation, Map<String, Map<String, Object>> shopInfoMap, int size) {
  146 + Iterator<? extends Bucket> itAgg = aggregation.getBuckets().iterator();
  147 + Map<String, Object> dataMap = new HashMap<String, Object>();
  148 + Map<String, List<Map<String, Object>>> dataListMap = new HashMap<String, List<Map<String, Object>>>();
  149 + Map<String, Map<String, Object>> dataMapMap = new HashMap<String, Map<String, Object>>();
  150 + Map<String, Object> map;
  151 + List<Map<String, Object>> dataList;
  152 + List<String> sknStr = new ArrayList<String>();
  153 + while (itAgg.hasNext()) {
  154 + Bucket lt = itAgg.next();
  155 + map = new HashMap<String, Object>();
  156 + map.put("count", lt.getDocCount());
  157 + if (size != 0) {
  158 + dataList = new ArrayList<Map<String, Object>>();
  159 + if (lt.getAggregations().getAsMap().containsKey("product")) {
  160 + TopHits topHits = lt.getAggregations().get("product");
  161 + SearchHits hits = topHits.getHits();
  162 + for (SearchHit hit : hits.getHits()) {
  163 + sknStr.add("" + hit.getSource().get("productSkn"));
  164 + dataList.add(hit.getSource());
  165 + }
  166 + dataListMap.put(lt.getKeyAsString(), dataList);
  167 + }
  168 + }
  169 + dataMapMap.put(lt.getKeyAsString(), map);
  170 + // 处理品牌信息
  171 + Map<String, Object> shopDataMap = new HashMap<String, Object>();
  172 + Map<String, Object> shopsInfo = shopInfoMap.get(lt.getKeyAsString());
  173 + if (shopsInfo != null) {
  174 + shopDataMap.put("shop_id", shopsInfo.get("shopsId"));
  175 + shopDataMap.put("shop_name", shopsInfo.get("shopName") == null ? "" : shopsInfo.get("shopName"));
  176 + shopDataMap.put("shop_logo", shopsInfo.get("shopLogo") == null ? "" : shopsInfo.get("shopLogo"));
  177 + shopDataMap.put("shop_domain", shopsInfo.get("shopDomain") == null ? "" : shopsInfo.get("shopDomain"));
  178 + shopDataMap.put("shop_type", shopsInfo.get("shopsType") == null ? "" : shopsInfo.get("shopsType"));
  179 + shopDataMap.put("decorator_template_type", shopsInfo.get("decoratorTemplateType") == null ? "" : shopsInfo.get("decoratorTemplateType"));
  180 + }
  181 + map.put("info", shopDataMap);
  182 + dataMapMap.put(lt.getKeyAsString(), map);
  183 + }
  184 + try {
  185 + Map<String, List<Map<String, Object>>> productPricePlanMap = searchServiceHelper.searchProductPricePlan((String[]) sknStr.toArray(new String[sknStr.size()]));
  186 + dataMapMap.forEach((k, m) -> {
  187 + List<Map<String, Object>> productList = dataListMap.get(k);
  188 + if (productList == null) {
  189 + productList = new ArrayList<Map<String, Object>>();
  190 + }
  191 + List<Map<String, Object>> newProductList = new ArrayList<Map<String, Object>>();
  192 + for (Map<String, Object> mm : productList) {
  193 + newProductList.add(searchServiceHelper.getProductMapWithPricePlan(mm, productPricePlanMap));
  194 + }
  195 + m.put("product_list", newProductList);
  196 + dataMap.put(k, m);
  197 + });
  198 + } catch (Exception e) {
  199 + logger.error("[func=getGroupShopResponseMap]" + e.getMessage(), e);
  200 + }
  201 + return dataMap;
  202 + }
  203 +
145 @Override 204 @Override
146 public SearchApiResult searchYohoBrand(Map<String, String> paramMap) { 205 public SearchApiResult searchYohoBrand(Map<String, String> paramMap) {
147 try { 206 try {
@@ -283,65 +342,6 @@ public class ShopsServiceImpl extends BaseService implements IShopsService, Appl @@ -283,65 +342,6 @@ public class ShopsServiceImpl extends BaseService implements IShopsService, Appl
283 return yohoBrandInfo; 342 return yohoBrandInfo;
284 } 343 }
285 344
286 - private Map<String, Object> getGroupShopResponseMap(MultiBucketsAggregation aggregation, Map<String, Map<String, Object>> shopInfoMap, int size) {  
287 - Iterator<? extends Bucket> itAgg = aggregation.getBuckets().iterator();  
288 - Map<String, Object> dataMap = new HashMap<String, Object>();  
289 - Map<String, List<Map<String, Object>>> dataListMap = new HashMap<String, List<Map<String, Object>>>();  
290 - Map<String, Map<String, Object>> dataMapMap = new HashMap<String, Map<String, Object>>();  
291 - Map<String, Object> map;  
292 - List<Map<String, Object>> dataList;  
293 - List<String> sknStr = new ArrayList<String>();  
294 - while (itAgg.hasNext()) {  
295 - Bucket lt = itAgg.next();  
296 - map = new HashMap<String, Object>();  
297 - map.put("count", lt.getDocCount());  
298 - if (size != 0) {  
299 - dataList = new ArrayList<Map<String, Object>>();  
300 - if (lt.getAggregations().getAsMap().containsKey("product")) {  
301 - TopHits topHits = lt.getAggregations().get("product");  
302 - SearchHits hits = topHits.getHits();  
303 - for (SearchHit hit : hits.getHits()) {  
304 - sknStr.add("" + hit.getSource().get("productSkn"));  
305 - dataList.add(hit.getSource());  
306 - }  
307 - dataListMap.put(lt.getKeyAsString(), dataList);  
308 - }  
309 - }  
310 - dataMapMap.put(lt.getKeyAsString(), map);  
311 - // 处理品牌信息  
312 - Map<String, Object> shopDataMap = new HashMap<String, Object>();  
313 - Map<String, Object> shopsInfo = shopInfoMap.get(lt.getKeyAsString());  
314 - if (shopsInfo != null) {  
315 - shopDataMap.put("shop_id", shopsInfo.get("shopsId"));  
316 - shopDataMap.put("shop_name", shopsInfo.get("shopName") == null ? "" : shopsInfo.get("shopName"));  
317 - shopDataMap.put("shop_logo", shopsInfo.get("shopLogo") == null ? "" : shopsInfo.get("shopLogo"));  
318 - shopDataMap.put("shop_domain", shopsInfo.get("shopDomain") == null ? "" : shopsInfo.get("shopDomain"));  
319 - shopDataMap.put("shop_type", shopsInfo.get("shopsType") == null ? "" : shopsInfo.get("shopsType"));  
320 - shopDataMap.put("decorator_template_type", shopsInfo.get("decoratorTemplateType") == null ? "" : shopsInfo.get("decoratorTemplateType"));  
321 - }  
322 - map.put("info", shopDataMap);  
323 - dataMapMap.put(lt.getKeyAsString(), map);  
324 - }  
325 - try {  
326 - Map<String, List<Map<String, Object>>> productPricePlanMap = searchServiceHelper.searchProductPricePlan((String[]) sknStr.toArray(new String[sknStr.size()]));  
327 - dataMapMap.forEach((k, m) -> {  
328 - List<Map<String, Object>> productList = dataListMap.get(k);  
329 - if (productList == null) {  
330 - productList = new ArrayList<Map<String, Object>>();  
331 - }  
332 - List<Map<String, Object>> newProductList = new ArrayList<Map<String, Object>>();  
333 - for (Map<String, Object> mm : productList) {  
334 - newProductList.add(searchServiceHelper.getProductMapWithPricePlan(mm, productPricePlanMap));  
335 - }  
336 - m.put("product_list", newProductList);  
337 - dataMap.put(k, m);  
338 - });  
339 - } catch (Exception e) {  
340 - logger.error("[func=getGroupShopResponseMap]" + e.getMessage(), e);  
341 - }  
342 - return dataMap;  
343 - }  
344 -  
345 /** 345 /**
346 * 过滤出有库存且有商品上架的店铺id,并且按店铺id排序 346 * 过滤出有库存且有商品上架的店铺id,并且按店铺id排序
347 * 347 *