|
@@ -46,230 +46,228 @@ import java.util.*; |
|
@@ -46,230 +46,228 @@ import java.util.*; |
46
|
@Service
|
46
|
@Service
|
47
|
public class ShopsServiceImpl extends BaseService implements IShopsService, ApplicationEventPublisherAware {
|
47
|
public class ShopsServiceImpl extends BaseService implements IShopsService, ApplicationEventPublisherAware {
|
48
|
|
48
|
|
49
|
- private static final Logger logger = LoggerFactory.getLogger(ShopsServiceImpl.class);
|
49
|
+ private static final Logger logger = LoggerFactory.getLogger(ShopsServiceImpl.class);
|
50
|
|
50
|
|
51
|
- @Autowired
|
|
|
52
|
- private SearchCommonService searchCommonService;
|
|
|
53
|
- @Autowired
|
|
|
54
|
- private IShopListService shopListService;
|
|
|
55
|
- @Autowired
|
|
|
56
|
- private AggregationService aggregationService;
|
|
|
57
|
- @Autowired
|
|
|
58
|
- private SearchCommonHelper searchCommonHelper;
|
|
|
59
|
- @Autowired
|
|
|
60
|
- private AggregationFactoryService aggregationFactoryService;
|
|
|
61
|
- @Autowired
|
|
|
62
|
- private SearchParamHelper searchParamHelper;
|
51
|
+ @Autowired
|
|
|
52
|
+ private SearchCommonService searchCommonService;
|
|
|
53
|
+ @Autowired
|
|
|
54
|
+ private IShopListService shopListService;
|
|
|
55
|
+ @Autowired
|
|
|
56
|
+ private AggregationService aggregationService;
|
|
|
57
|
+ @Autowired
|
|
|
58
|
+ private SearchCommonHelper searchCommonHelper;
|
|
|
59
|
+ @Autowired
|
|
|
60
|
+ private AggregationFactoryService aggregationFactoryService;
|
|
|
61
|
+ @Autowired
|
|
|
62
|
+ private SearchParamHelper searchParamHelper;
|
63
|
|
63
|
|
64
|
- private ApplicationEventPublisher publisher;
|
64
|
+ private ApplicationEventPublisher publisher;
|
65
|
|
65
|
|
66
|
- @Override
|
|
|
67
|
- public void setApplicationEventPublisher(ApplicationEventPublisher applicationEventPublisher) {
|
|
|
68
|
- this.publisher = applicationEventPublisher;
|
|
|
69
|
- }
|
66
|
+ @Override
|
|
|
67
|
+ public void setApplicationEventPublisher(ApplicationEventPublisher applicationEventPublisher) {
|
|
|
68
|
+ this.publisher = applicationEventPublisher;
|
|
|
69
|
+ }
|
70
|
|
70
|
|
71
|
- @Override
|
|
|
72
|
- @SearchCacheAble(cacheInMinute = 30, cacheName = "GROUP_SHOPS", excludeParams = { "page", "order" })
|
|
|
73
|
- public SearchApiResult group_shops(Map<String, String> paramMap) {
|
|
|
74
|
- try {
|
|
|
75
|
- // 1、获取topHitCount
|
|
|
76
|
- int topHitCount = StringUtils.isBlank(paramMap.get("viewNum")) ? 10 : Integer.parseInt(paramMap.get("viewNum"));
|
|
|
77
|
- // 2、获取聚合的排序规则
|
|
|
78
|
- String topHitOrder = "heatValue:desc";
|
|
|
79
|
- if (topHitCount > 0 && searchCommonHelper.isNeedPersonalSearch(paramMap)) {
|
|
|
80
|
- topHitOrder = "_score:desc";
|
|
|
81
|
- }
|
|
|
82
|
- // 3、获取聚合条件
|
|
|
83
|
- IAggregation groupShopAgg = aggregationFactoryService.getGroupShopAggregation(topHitOrder, topHitCount);
|
|
|
84
|
- // 4、构建searchParam
|
|
|
85
|
- SearchParam searchParam = searchParamHelper.buildWithPersional(paramMap, topHitCount > 0 ? true : false);
|
|
|
86
|
- searchParam.setAggregationBuilders(Arrays.asList(groupShopAgg.getBuilder()));
|
|
|
87
|
- searchParam.setOffset(0);
|
|
|
88
|
- searchParam.setSize(0);
|
|
|
89
|
- // 5、从ES中获取
|
|
|
90
|
- JSONObject aggNameAndResponse = aggregationService.getAggNameAndResponseWithTotal(groupShopAgg, searchParam);
|
|
|
91
|
- if (aggNameAndResponse == null) {
|
|
|
92
|
- return new SearchApiResult().setData(500).setMessage("exception");
|
|
|
93
|
- }
|
|
|
94
|
- // 6、返回生成结果
|
|
|
95
|
- JSONObject realResult = new JSONObject();
|
|
|
96
|
- realResult.put("total", aggNameAndResponse.getOrDefault("total", 0));
|
|
|
97
|
- realResult.put("shops", aggNameAndResponse.getOrDefault(groupShopAgg.aggName(), new JSONObject()));
|
|
|
98
|
- return new SearchApiResult().setData(realResult).setMessage("groupShops new List.");
|
|
|
99
|
- } catch (Exception e) {
|
|
|
100
|
- publisher.publishEvent(new SearchEvent(EventReportEnum.SEARCHCONTROLLER_GROUP_SHOPS.getEventName(), EventReportEnum.SEARCHCONTROLLER_GROUP_SHOPS.getFunctionName(),
|
|
|
101
|
- EventReportEnum.SEARCHCONTROLLER_GROUP_SHOPS.getMoudleName(), "exception", IgnoreSomeException.filterSomeException(e), null));
|
|
|
102
|
- return SearchApiResultUtils.errorSearchApiResult("group_shops", paramMap, e);
|
|
|
103
|
- }
|
|
|
104
|
- }
|
71
|
+ @Override
|
|
|
72
|
+ @SearchCacheAble(cacheInMinute = 30, cacheName = "GROUP_SHOPS", excludeParams = {"page", "order", "uid", "udid"})
|
|
|
73
|
+ public SearchApiResult group_shops(Map<String, String> paramMap) {
|
|
|
74
|
+ try {
|
|
|
75
|
+ // 1、获取topHitCount
|
|
|
76
|
+ int topHitCount = StringUtils.isBlank(paramMap.get("viewNum")) ? 10 : Integer.parseInt(paramMap.get("viewNum"));
|
|
|
77
|
+ // 2、获取聚合的排序规则
|
|
|
78
|
+ String topHitOrder = "heatValue:desc";
|
105
|
|
79
|
|
106
|
- @Override
|
|
|
107
|
- @SearchCacheAble(cacheInMinute = 30, cacheName = "SEARCH_YOHO_BRAND", includeParams = { "keyword", "is_encode"})
|
|
|
108
|
- public SearchApiResult searchYohoBrand(Map<String, String> paramMap) {
|
|
|
109
|
- try {
|
|
|
110
|
- // 1、参数校验
|
|
|
111
|
- String keyword = SearchKeyWordUtils.getParamKeyword(paramMap, SearchRequestParams.PARAM_SEARCH_SHOPS_KEYWORD);
|
|
|
112
|
- if (StringUtils.isBlank(keyword)) {
|
|
|
113
|
- return new SearchApiResult().setCode(400).setMessage("keyword不能为空!");
|
|
|
114
|
- }
|
|
|
115
|
-
|
|
|
116
|
- // 2、配置keyword的查询字段以及权重设置
|
|
|
117
|
- MultiMatchQueryBuilder queryBuilder = QueryBuilders.multiMatchQuery(keyword);
|
|
|
118
|
- queryBuilder.operator(Operator.OR);
|
|
|
119
|
- queryBuilder.field("brandName.brandName_ansj", 100).field("brandName.brandName_pinyin").field("brandNameCn.brandNameCn_ansj").field("brandNameCn.brandNameCn_pinyin")
|
|
|
120
|
- .field("brandNameEn").field("brandDomain", 50);
|
|
|
121
|
- queryBuilder.minimumShouldMatch("100%");
|
80
|
+ // 3、构建searchParam
|
|
|
81
|
+ SearchParam searchParam = searchParamHelper.buildWithPersional(paramMap, topHitCount > 0 ? true : false);
|
|
|
82
|
+ IAggregation groupShopAgg = aggregationFactoryService.getGroupShopAggregation(topHitOrder, topHitCount);
|
|
|
83
|
+ searchParam.setAggregationBuilders(Arrays.asList(groupShopAgg.getBuilder()));
|
|
|
84
|
+ searchParam.setOffset(0);
|
|
|
85
|
+ searchParam.setSize(0);
|
122
|
|
86
|
|
123
|
- // 3、构建SearchParam
|
|
|
124
|
- SearchParam searchParam = new SearchParam();
|
|
|
125
|
- searchParam.setQuery(queryBuilder);
|
|
|
126
|
- BoolQueryBuilder boolFilter = QueryBuilders.boolQuery();
|
|
|
127
|
- boolFilter.must(QueryBuilders.termQuery("status", 1));
|
|
|
128
|
- boolFilter.mustNot(QueryBuilders.termQuery("isGlobal", "Y"));
|
|
|
129
|
- searchParam.setFiter(boolFilter);
|
|
|
130
|
- searchParam.setSize(5);
|
87
|
+ // 4、从ES中获取
|
|
|
88
|
+ JSONObject aggNameAndResponse = aggregationService.getAggNameAndResponseWithTotal(groupShopAgg, searchParam);
|
|
|
89
|
+ if (aggNameAndResponse == null) {
|
|
|
90
|
+ return new SearchApiResult().setData(500).setMessage("exception");
|
|
|
91
|
+ }
|
|
|
92
|
+ // 5、返回生成结果
|
|
|
93
|
+ JSONObject realResult = new JSONObject();
|
|
|
94
|
+ realResult.put("total", aggNameAndResponse.getOrDefault("total", 0));
|
|
|
95
|
+ realResult.put("shops", aggNameAndResponse.getOrDefault(groupShopAgg.aggName(), new JSONObject()));
|
|
|
96
|
+ return new SearchApiResult().setData(realResult).setMessage("groupShops new List.");
|
|
|
97
|
+ } catch (Exception e) {
|
|
|
98
|
+ publisher.publishEvent(new SearchEvent(EventReportEnum.SEARCHCONTROLLER_GROUP_SHOPS.getEventName(), EventReportEnum.SEARCHCONTROLLER_GROUP_SHOPS.getFunctionName(),
|
|
|
99
|
+ EventReportEnum.SEARCHCONTROLLER_GROUP_SHOPS.getMoudleName(), "exception", IgnoreSomeException.filterSomeException(e), null));
|
|
|
100
|
+ return SearchApiResultUtils.errorSearchApiResult("group_shops", paramMap, e);
|
|
|
101
|
+ }
|
|
|
102
|
+ }
|
131
|
|
103
|
|
132
|
- // 4、根据searchParam查询ES
|
|
|
133
|
- SearchResult searchResult = searchCommonService.doSearch(ISearchConstants.INDEX_NAME_BRAND, searchParam);
|
|
|
134
|
- List<String> brandIds = new ArrayList<String>();
|
|
|
135
|
- Map<String, Map<String, Object>> brandInfoMap = new HashMap<String, Map<String, Object>>();
|
|
|
136
|
- if (searchResult != null && searchResult.getResultList() != null && !searchResult.getResultList().isEmpty()) {
|
|
|
137
|
- List<Map<String, Object>> result = searchResult.getResultList();
|
|
|
138
|
- for (Map<String, Object> brandInfo : result) {
|
|
|
139
|
- String brandId = brandInfo.get("id").toString();
|
|
|
140
|
- brandInfoMap.put(brandId, brandInfo);
|
|
|
141
|
- brandIds.add(brandId);
|
|
|
142
|
- }
|
|
|
143
|
- }
|
|
|
144
|
- // 6、判断能否查出符合条件的品牌
|
|
|
145
|
- String brandId = this.getMaxScoreIdFromPi(brandIds, "brandId");
|
|
|
146
|
- JSONObject dataMap = new JSONObject();
|
|
|
147
|
- if (StringUtils.isNotBlank(brandId)) {
|
|
|
148
|
- Map<String, Object> brandInfo = brandInfoMap.get(brandId);
|
|
|
149
|
- dataMap.put("id", brandInfo.getOrDefault("id", 0));
|
|
|
150
|
- dataMap.put("brand_name", brandInfo.getOrDefault("brandName", ""));
|
|
|
151
|
- dataMap.put("brand_ico", brandInfo.getOrDefault("brandIco", ""));
|
|
|
152
|
- dataMap.put("brand_domain", brandInfo.getOrDefault("brandDomain", ""));
|
|
|
153
|
- }
|
|
|
154
|
- return new SearchApiResult().setMessage("shops info").setData(dataMap);
|
|
|
155
|
- } catch (Exception e) {
|
|
|
156
|
- return SearchApiResultUtils.errorSearchApiResult("searchShops", paramMap, e);
|
|
|
157
|
- }
|
|
|
158
|
- }
|
104
|
+ @Override
|
|
|
105
|
+ @SearchCacheAble(cacheInMinute = 30, cacheName = "SEARCH_YOHO_BRAND", includeParams = {"keyword", "is_encode"})
|
|
|
106
|
+ public SearchApiResult searchYohoBrand(Map<String, String> paramMap) {
|
|
|
107
|
+ try {
|
|
|
108
|
+ // 1、参数校验
|
|
|
109
|
+ String keyword = SearchKeyWordUtils.getParamKeyword(paramMap, SearchRequestParams.PARAM_SEARCH_SHOPS_KEYWORD);
|
|
|
110
|
+ if (StringUtils.isBlank(keyword)) {
|
|
|
111
|
+ return new SearchApiResult().setCode(400).setMessage("keyword不能为空!");
|
|
|
112
|
+ }
|
159
|
|
113
|
|
160
|
- @Override
|
|
|
161
|
- @SearchCacheAble(cacheInMinute = 30, cacheName = "SEARCH_SHOP_NEW", includeParams = { "keyword", "is_encode"})
|
|
|
162
|
- public SearchApiResult searchShopsNew(Map<String, String> paramMap) {
|
|
|
163
|
- try {
|
|
|
164
|
- logger.info("[func=searchShops][param={}][begin={}]", paramMap.toString(), System.currentTimeMillis());
|
|
|
165
|
- // 1、参数校验
|
|
|
166
|
- String keyword = SearchKeyWordUtils.getParamKeyword(paramMap, SearchRequestParams.PARAM_SEARCH_SHOPS_KEYWORD);
|
|
|
167
|
- if (StringUtils.isBlank(keyword)) {
|
|
|
168
|
- return new SearchApiResult().setCode(400).setMessage("keyword不能为空!");
|
|
|
169
|
- }
|
|
|
170
|
- // 2、构造返回对象
|
|
|
171
|
- SearchApiResult searchApiResult = new SearchApiResult();
|
|
|
172
|
- JSONObject returnMap = new JSONObject();
|
|
|
173
|
- returnMap.put("shop", null);
|
|
|
174
|
- returnMap.put("brand", null);
|
|
|
175
|
- returnMap.put("tblBrand", null);
|
114
|
+ // 2、配置keyword的查询字段以及权重设置
|
|
|
115
|
+ MultiMatchQueryBuilder queryBuilder = QueryBuilders.multiMatchQuery(keyword);
|
|
|
116
|
+ queryBuilder.operator(Operator.OR);
|
|
|
117
|
+ queryBuilder.field("brandName.brandName_ansj", 100).field("brandName.brandName_pinyin").field("brandNameCn.brandNameCn_ansj").field("brandNameCn.brandNameCn_pinyin")
|
|
|
118
|
+ .field("brandNameEn").field("brandDomain", 50);
|
|
|
119
|
+ queryBuilder.minimumShouldMatch("100%");
|
176
|
|
120
|
|
177
|
- // 3、查询店铺和全球购品牌
|
|
|
178
|
- SearchApiResult shopListApiResult = shopListService.searchShopList(paramMap);
|
|
|
179
|
- if (shopListApiResult != null) {
|
|
|
180
|
- JSONObject jsonObject = (JSONObject) shopListApiResult.getData();
|
|
|
181
|
- JSONArray shop_list = jsonObject.getJSONArray("shop_list");
|
|
|
182
|
- if (shop_list != null && !shop_list.isEmpty()) {
|
|
|
183
|
- for (int i = 0; i < shop_list.size(); i++) {
|
|
|
184
|
- JSONObject shop_info = shop_list.getJSONObject(0);
|
|
|
185
|
- if (shop_info.getJSONObject("yoho_shop") != null) {
|
|
|
186
|
- JSONObject yohoShop = this.getShopDataMapFromMap(shop_info.getJSONObject("yoho_shop"));
|
|
|
187
|
- returnMap.put("shop", yohoShop);
|
|
|
188
|
- return searchApiResult.setData(returnMap);
|
|
|
189
|
- }
|
|
|
190
|
- if (shop_info.getJSONObject("tbl_brand") != null) {
|
|
|
191
|
- JSONObject tblBrand = this.getTblBrandFromMap(shop_info.getJSONObject("tbl_brand"));
|
|
|
192
|
- returnMap.put("tblBrand", tblBrand);
|
|
|
193
|
- return searchApiResult.setData(returnMap);
|
|
|
194
|
- }
|
|
|
195
|
- }
|
|
|
196
|
- }
|
|
|
197
|
- }
|
|
|
198
|
- // 4、否則获取有货品牌信息
|
|
|
199
|
- returnMap.put("brand", this.getYohoBrand(paramMap));
|
121
|
+ // 3、构建SearchParam
|
|
|
122
|
+ SearchParam searchParam = new SearchParam();
|
|
|
123
|
+ searchParam.setQuery(queryBuilder);
|
|
|
124
|
+ BoolQueryBuilder boolFilter = QueryBuilders.boolQuery();
|
|
|
125
|
+ boolFilter.must(QueryBuilders.termQuery("status", 1));
|
|
|
126
|
+ boolFilter.mustNot(QueryBuilders.termQuery("isGlobal", "Y"));
|
|
|
127
|
+ searchParam.setFiter(boolFilter);
|
|
|
128
|
+ searchParam.setSize(5);
|
200
|
|
129
|
|
201
|
- // 5、返回结果
|
|
|
202
|
- return searchApiResult.setData(returnMap);
|
|
|
203
|
- } catch (Exception e) {
|
|
|
204
|
- return SearchApiResultUtils.errorSearchApiResult("searchShopsNew", paramMap, e);
|
|
|
205
|
- }
|
|
|
206
|
- }
|
130
|
+ // 4、根据searchParam查询ES
|
|
|
131
|
+ SearchResult searchResult = searchCommonService.doSearch(ISearchConstants.INDEX_NAME_BRAND, searchParam);
|
|
|
132
|
+ List<String> brandIds = new ArrayList<String>();
|
|
|
133
|
+ Map<String, Map<String, Object>> brandInfoMap = new HashMap<String, Map<String, Object>>();
|
|
|
134
|
+ if (searchResult != null && searchResult.getResultList() != null && !searchResult.getResultList().isEmpty()) {
|
|
|
135
|
+ List<Map<String, Object>> result = searchResult.getResultList();
|
|
|
136
|
+ for (Map<String, Object> brandInfo : result) {
|
|
|
137
|
+ String brandId = brandInfo.get("id").toString();
|
|
|
138
|
+ brandInfoMap.put(brandId, brandInfo);
|
|
|
139
|
+ brandIds.add(brandId);
|
|
|
140
|
+ }
|
|
|
141
|
+ }
|
|
|
142
|
+ // 6、判断能否查出符合条件的品牌
|
|
|
143
|
+ String brandId = this.getMaxScoreIdFromPi(brandIds, "brandId");
|
|
|
144
|
+ JSONObject dataMap = new JSONObject();
|
|
|
145
|
+ if (StringUtils.isNotBlank(brandId)) {
|
|
|
146
|
+ Map<String, Object> brandInfo = brandInfoMap.get(brandId);
|
|
|
147
|
+ dataMap.put("id", brandInfo.getOrDefault("id", 0));
|
|
|
148
|
+ dataMap.put("brand_name", brandInfo.getOrDefault("brandName", ""));
|
|
|
149
|
+ dataMap.put("brand_ico", brandInfo.getOrDefault("brandIco", ""));
|
|
|
150
|
+ dataMap.put("brand_domain", brandInfo.getOrDefault("brandDomain", ""));
|
|
|
151
|
+ }
|
|
|
152
|
+ return new SearchApiResult().setMessage("shops info").setData(dataMap);
|
|
|
153
|
+ } catch (Exception e) {
|
|
|
154
|
+ return SearchApiResultUtils.errorSearchApiResult("searchShops", paramMap, e);
|
|
|
155
|
+ }
|
|
|
156
|
+ }
|
207
|
|
157
|
|
208
|
- private JSONObject getShopDataMapFromMap(Map<String, Object> shopInfo) {
|
|
|
209
|
- JSONObject shopDataMap = new JSONObject();
|
|
|
210
|
- shopDataMap.put("shop_id", shopInfo.getOrDefault("shop_id", 0));
|
|
|
211
|
- shopDataMap.put("shop_name", shopInfo.getOrDefault("shop_name", ""));
|
|
|
212
|
- shopDataMap.put("shop_logo", shopInfo.getOrDefault("shop_logo", ""));
|
|
|
213
|
- shopDataMap.put("shop_domain", shopInfo.getOrDefault("shop_domain", ""));
|
|
|
214
|
- shopDataMap.put("shop_type", shopInfo.getOrDefault("shop_type", 0));
|
|
|
215
|
- shopDataMap.put("decorator_template_type", shopInfo.getOrDefault("decorator_template_type", 0));
|
|
|
216
|
- return shopDataMap;
|
|
|
217
|
- }
|
158
|
+ @Override
|
|
|
159
|
+ @SearchCacheAble(cacheInMinute = 30, cacheName = "SEARCH_SHOP_NEW", includeParams = {"keyword", "is_encode"})
|
|
|
160
|
+ public SearchApiResult searchShopsNew(Map<String, String> paramMap) {
|
|
|
161
|
+ try {
|
|
|
162
|
+ logger.info("[func=searchShops][param={}][begin={}]", paramMap.toString(), System.currentTimeMillis());
|
|
|
163
|
+ // 1、参数校验
|
|
|
164
|
+ String keyword = SearchKeyWordUtils.getParamKeyword(paramMap, SearchRequestParams.PARAM_SEARCH_SHOPS_KEYWORD);
|
|
|
165
|
+ if (StringUtils.isBlank(keyword)) {
|
|
|
166
|
+ return new SearchApiResult().setCode(400).setMessage("keyword不能为空!");
|
|
|
167
|
+ }
|
|
|
168
|
+ // 2、构造返回对象
|
|
|
169
|
+ SearchApiResult searchApiResult = new SearchApiResult();
|
|
|
170
|
+ JSONObject returnMap = new JSONObject();
|
|
|
171
|
+ returnMap.put("shop", null);
|
|
|
172
|
+ returnMap.put("brand", null);
|
|
|
173
|
+ returnMap.put("tblBrand", null);
|
218
|
|
174
|
|
219
|
- private JSONObject getTblBrandFromMap(Map<String, Object> tblBrandInfo) {
|
|
|
220
|
- JSONObject tblBrand = new JSONObject();
|
|
|
221
|
- tblBrand.put("brand_id", tblBrandInfo.getOrDefault("id", 0));
|
|
|
222
|
- tblBrand.put("brand_name", tblBrandInfo.getOrDefault("brand_name", ""));
|
|
|
223
|
- tblBrand.put("brand_logo", tblBrandInfo.getOrDefault("brand_ico", ""));
|
|
|
224
|
- return tblBrand;
|
|
|
225
|
- }
|
175
|
+ // 3、查询店铺和全球购品牌
|
|
|
176
|
+ SearchApiResult shopListApiResult = shopListService.searchShopList(paramMap);
|
|
|
177
|
+ if (shopListApiResult != null) {
|
|
|
178
|
+ JSONObject jsonObject = (JSONObject) shopListApiResult.getData();
|
|
|
179
|
+ JSONArray shop_list = jsonObject.getJSONArray("shop_list");
|
|
|
180
|
+ if (shop_list != null && !shop_list.isEmpty()) {
|
|
|
181
|
+ for (int i = 0; i < shop_list.size(); i++) {
|
|
|
182
|
+ JSONObject shop_info = shop_list.getJSONObject(0);
|
|
|
183
|
+ if (shop_info.getJSONObject("yoho_shop") != null) {
|
|
|
184
|
+ JSONObject yohoShop = this.getShopDataMapFromMap(shop_info.getJSONObject("yoho_shop"));
|
|
|
185
|
+ returnMap.put("shop", yohoShop);
|
|
|
186
|
+ return searchApiResult.setData(returnMap);
|
|
|
187
|
+ }
|
|
|
188
|
+ if (shop_info.getJSONObject("tbl_brand") != null) {
|
|
|
189
|
+ JSONObject tblBrand = this.getTblBrandFromMap(shop_info.getJSONObject("tbl_brand"));
|
|
|
190
|
+ returnMap.put("tblBrand", tblBrand);
|
|
|
191
|
+ return searchApiResult.setData(returnMap);
|
|
|
192
|
+ }
|
|
|
193
|
+ }
|
|
|
194
|
+ }
|
|
|
195
|
+ }
|
|
|
196
|
+ // 4、否則获取有货品牌信息
|
|
|
197
|
+ returnMap.put("brand", this.getYohoBrand(paramMap));
|
226
|
|
198
|
|
227
|
- private JSONObject getYohoBrand(Map<String, String> paramMap) {
|
|
|
228
|
- SearchApiResult searchApiResult = this.searchYohoBrand(paramMap);
|
|
|
229
|
- if (searchApiResult == null || searchApiResult.getData() == null) {
|
|
|
230
|
- return null;
|
|
|
231
|
- }
|
|
|
232
|
- JSONObject yohoBrandInfo = (JSONObject) searchApiResult.getData();
|
|
|
233
|
- return yohoBrandInfo;
|
|
|
234
|
- }
|
199
|
+ // 5、返回结果
|
|
|
200
|
+ return searchApiResult.setData(returnMap);
|
|
|
201
|
+ } catch (Exception e) {
|
|
|
202
|
+ return SearchApiResultUtils.errorSearchApiResult("searchShopsNew", paramMap, e);
|
|
|
203
|
+ }
|
|
|
204
|
+ }
|
|
|
205
|
+
|
|
|
206
|
+ private JSONObject getShopDataMapFromMap(Map<String, Object> shopInfo) {
|
|
|
207
|
+ JSONObject shopDataMap = new JSONObject();
|
|
|
208
|
+ shopDataMap.put("shop_id", shopInfo.getOrDefault("shop_id", 0));
|
|
|
209
|
+ shopDataMap.put("shop_name", shopInfo.getOrDefault("shop_name", ""));
|
|
|
210
|
+ shopDataMap.put("shop_logo", shopInfo.getOrDefault("shop_logo", ""));
|
|
|
211
|
+ shopDataMap.put("shop_domain", shopInfo.getOrDefault("shop_domain", ""));
|
|
|
212
|
+ shopDataMap.put("shop_type", shopInfo.getOrDefault("shop_type", 0));
|
|
|
213
|
+ shopDataMap.put("decorator_template_type", shopInfo.getOrDefault("decorator_template_type", 0));
|
|
|
214
|
+ return shopDataMap;
|
|
|
215
|
+ }
|
|
|
216
|
+
|
|
|
217
|
+ private JSONObject getTblBrandFromMap(Map<String, Object> tblBrandInfo) {
|
|
|
218
|
+ JSONObject tblBrand = new JSONObject();
|
|
|
219
|
+ tblBrand.put("brand_id", tblBrandInfo.getOrDefault("id", 0));
|
|
|
220
|
+ tblBrand.put("brand_name", tblBrandInfo.getOrDefault("brand_name", ""));
|
|
|
221
|
+ tblBrand.put("brand_logo", tblBrandInfo.getOrDefault("brand_ico", ""));
|
|
|
222
|
+ return tblBrand;
|
|
|
223
|
+ }
|
|
|
224
|
+
|
|
|
225
|
+ private JSONObject getYohoBrand(Map<String, String> paramMap) {
|
|
|
226
|
+ SearchApiResult searchApiResult = this.searchYohoBrand(paramMap);
|
|
|
227
|
+ if (searchApiResult == null || searchApiResult.getData() == null) {
|
|
|
228
|
+ return null;
|
|
|
229
|
+ }
|
|
|
230
|
+ JSONObject yohoBrandInfo = (JSONObject) searchApiResult.getData();
|
|
|
231
|
+ return yohoBrandInfo;
|
|
|
232
|
+ }
|
|
|
233
|
+
|
|
|
234
|
+ /**
|
|
|
235
|
+ * 过滤出有库存且有商品上架的店铺id,并且按店铺id排序
|
|
|
236
|
+ *
|
|
|
237
|
+ * @return
|
|
|
238
|
+ */
|
|
|
239
|
+ private String getMaxScoreIdFromPi(List<String> ids, String esFieldName) {
|
|
|
240
|
+ // 查询ProductIndex
|
|
|
241
|
+ SearchParam searchParam = new SearchParam();
|
|
|
242
|
+ BoolQueryBuilder boolFilter = QueryBuilders.boolQuery();
|
|
|
243
|
+ boolFilter.must(QueryBuilders.termsQuery(esFieldName, ids));
|
|
|
244
|
+ boolFilter.must(QueryBuilders.rangeQuery(ProductIndexEsField.storageNum).gte(1));
|
|
|
245
|
+ boolFilter.must(QueryBuilders.termQuery(ProductIndexEsField.status, "1"));
|
|
|
246
|
+ boolFilter.must(QueryBuilders.termQuery(ProductIndexEsField.attribute, "1"));
|
|
|
247
|
+ searchParam.setFiter(boolFilter);
|
|
|
248
|
+ searchParam.setOffset(0);
|
|
|
249
|
+ searchParam.setSize(1);
|
|
|
250
|
+ // 按shopId打分
|
|
|
251
|
+ BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery();
|
|
|
252
|
+ boolQueryBuilder.must(QueryBuilders.matchAllQuery());
|
|
|
253
|
+ double boost = Math.pow(10d, 5d);
|
|
|
254
|
+ for (String id : ids) {
|
|
|
255
|
+ boolQueryBuilder.should(QueryBuilders.termQuery(esFieldName, id).boost((float) boost));
|
|
|
256
|
+ boost = boost / 10;
|
|
|
257
|
+ }
|
|
|
258
|
+ searchParam.setQuery(boolQueryBuilder);
|
|
|
259
|
+ // 按得分排序
|
|
|
260
|
+ List<SortBuilder<?>> sortBuilders = new ArrayList<SortBuilder<?>>();
|
|
|
261
|
+ sortBuilders.add(SortBuilders.scoreSort().order(SortOrder.DESC));
|
|
|
262
|
+ searchParam.setSortBuilders(sortBuilders);
|
|
|
263
|
+ // 结果只返回shopId
|
|
|
264
|
+ searchParam.setIncludeFields(Arrays.asList(esFieldName));
|
|
|
265
|
+ // 查询ES
|
|
|
266
|
+ SearchResult searchResult = searchCommonService.doSearch(ISearchConstants.INDEX_NAME_PRODUCT_INDEX, searchParam);
|
|
|
267
|
+ if (searchResult == null || CollectionUtils.isEmpty(searchResult.getResultList())) {
|
|
|
268
|
+ return null;
|
|
|
269
|
+ }
|
|
|
270
|
+ return searchResult.getResultList().get(0).get(esFieldName).toString();
|
|
|
271
|
+ }
|
235
|
|
272
|
|
236
|
- /**
|
|
|
237
|
- * 过滤出有库存且有商品上架的店铺id,并且按店铺id排序
|
|
|
238
|
- *
|
|
|
239
|
- * @return
|
|
|
240
|
- */
|
|
|
241
|
- private String getMaxScoreIdFromPi(List<String> ids, String esFieldName) {
|
|
|
242
|
- // 查询ProductIndex
|
|
|
243
|
- SearchParam searchParam = new SearchParam();
|
|
|
244
|
- BoolQueryBuilder boolFilter = QueryBuilders.boolQuery();
|
|
|
245
|
- boolFilter.must(QueryBuilders.termsQuery(esFieldName, ids));
|
|
|
246
|
- boolFilter.must(QueryBuilders.rangeQuery(ProductIndexEsField.storageNum).gte(1));
|
|
|
247
|
- boolFilter.must(QueryBuilders.termQuery(ProductIndexEsField.status, "1"));
|
|
|
248
|
- boolFilter.must(QueryBuilders.termQuery(ProductIndexEsField.attribute, "1"));
|
|
|
249
|
- searchParam.setFiter(boolFilter);
|
|
|
250
|
- searchParam.setOffset(0);
|
|
|
251
|
- searchParam.setSize(1);
|
|
|
252
|
- // 按shopId打分
|
|
|
253
|
- BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery();
|
|
|
254
|
- boolQueryBuilder.must(QueryBuilders.matchAllQuery());
|
|
|
255
|
- double boost = Math.pow(10d, 5d);
|
|
|
256
|
- for (String id : ids) {
|
|
|
257
|
- boolQueryBuilder.should(QueryBuilders.termQuery(esFieldName, id).boost((float) boost));
|
|
|
258
|
- boost = boost / 10;
|
|
|
259
|
- }
|
|
|
260
|
- searchParam.setQuery(boolQueryBuilder);
|
|
|
261
|
- // 按得分排序
|
|
|
262
|
- List<SortBuilder<?>> sortBuilders = new ArrayList<SortBuilder<?>>();
|
|
|
263
|
- sortBuilders.add(SortBuilders.scoreSort().order(SortOrder.DESC));
|
|
|
264
|
- searchParam.setSortBuilders(sortBuilders);
|
|
|
265
|
- // 结果只返回shopId
|
|
|
266
|
- searchParam.setIncludeFields(Arrays.asList(esFieldName));
|
|
|
267
|
- // 查询ES
|
|
|
268
|
- SearchResult searchResult = searchCommonService.doSearch(ISearchConstants.INDEX_NAME_PRODUCT_INDEX, searchParam);
|
|
|
269
|
- if (searchResult == null || CollectionUtils.isEmpty(searchResult.getResultList())) {
|
|
|
270
|
- return null;
|
|
|
271
|
- }
|
|
|
272
|
- return searchResult.getResultList().get(0).get(esFieldName).toString();
|
|
|
273
|
- }
|
|
|
274
|
-
|
|
|
275
|
} |
273
|
} |