Authored by wangnan9279

Merge branch 'master' into wn_tblproduct_new

... ... @@ -77,6 +77,6 @@ fi
JAVA_OPTS=" $JAVA_OPTS $SERVER_BASE_DIR "
#jmx
export JMX_PORT=`expr 9600 + $SERVER_PORT`
export JMX_PORT=`expr 9900 + $SERVER_PORT`
export LOCAL_IP=`/sbin/ifconfig -a|grep inet|grep -v 127.0.0.1|grep -v inet6|awk '{print $2}'|tr -d "addr:"|awk 'NR==1 {print}'`
export CATALINA_OPTS="$CATALINA_OPTS -Djava.rmi.server.hostname=$LOCAL_IP -Dcom.sun.management.jmxremote.port=$JMX_PORT -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false"
... ...
... ... @@ -8,15 +8,14 @@ import com.yoho.search.base.utils.Transfer;
import com.yoho.search.core.es.model.SearchParam;
import com.yoho.search.core.es.model.SearchResult;
import com.yoho.search.models.SearchApiResult;
import com.yoho.search.recall.common.ABUserPartitionUtils;
import com.yoho.search.recall.scene.beans.builder.UserRecallRequestBuilder;
import com.yoho.search.recall.scene.beans.cache.SknReturnInfoCacheBean;
import com.yoho.search.recall.scene.beans.cache.UserRecallCacheBean;
import com.yoho.search.recall.scene.beans.helper.SortBuilderHelper;
import com.yoho.search.recall.scene.beans.strategy.StrategyEnum;
import com.yoho.search.recall.scene.models.common.RecallSknInfo;
import com.yoho.search.recall.scene.models.req.UserRecallRequest;
import com.yoho.search.recall.scene.models.req.UserRecallResponse;
import com.yoho.search.recall.scene.models.common.RecallSknInfo;
import com.yoho.search.service.base.SearchCommonService;
import com.yoho.search.service.base.SearchDynamicConfigService;
import com.yoho.search.service.helper.SearchCommonHelper;
... ... @@ -165,7 +164,7 @@ public class SceneRecallProductListService {
private List<RecallSknInfo> queryProductSknByFilterSkn(UserRecallRequest userRecallRequest, List<RecallSknInfo> recallSknInfos, int realPage, int pageSize) {
long begin = System.currentTimeMillis();
//0、策略区分
StrategyEnum strategyEnum = ABUserPartitionUtils.isAUserComplete(userRecallRequest.getUid(), userRecallRequest.getUdid()) ? StrategyEnum.DEFAULT_HEAT_VALUE : StrategyEnum.DEFAULT_CTR_VALUE;
StrategyEnum strategyEnum = StrategyEnum.DEFAULT_HEAT_VALUE;
//1、设置query
SearchParam searchParam = new SearchParam();
... ... @@ -186,11 +185,7 @@ public class SceneRecallProductListService {
searchParam.setIncludeFields(Arrays.asList(ProductIndexEsField.productSkn));
//5、设置排序
List<SortBuilder<?>> sortBuilders = new ArrayList<>();
if (strategyEnum.equals(StrategyEnum.DEFAULT_HEAT_VALUE)) {
sortBuilders.add(SortBuilderHelper.getHeatValueDescSort());
} else {
sortBuilders.add(SortBuilderHelper.getCtrValueDescSort());
}
sortBuilders.add(SortBuilderHelper.getHeatValueDescSort());
sortBuilders.add(SortBuilderHelper.getSevendayMoneyDescSort());
sortBuilders.add(SortBuilderHelper.getIdDescSort());
searchParam.setSortBuilders(sortBuilders);
... ...
package com.yoho.search.recall.scene.beans.builder;
import com.yoho.search.recall.common.ABUserPartitionUtils;
import com.yoho.search.recall.scene.beans.strategy.impls.*;
import com.yoho.search.recall.scene.constants.SknCountConstants;
import com.yoho.search.recall.scene.models.common.ParamQueryFilter;
... ... @@ -35,11 +34,7 @@ public class CommonRecallRequestBuilder {
//1.4) 流量补偿的召回
requests.add(this.buildAddFlowRequest(paramQueryFilter, SknCountConstants.ADD_FLOW));
//1.5) 页面的兜底召回
if (ABUserPartitionUtils.isAUserComplete(userRecallRequest.getUid(), userRecallRequest.getUdid())) {
requests.add(this.buildCommonHeatValueStrategy(paramQueryFilter, pageSize));
} else {
requests.add(this.buildCommonCtrValueStrategy(paramQueryFilter, pageSize));
}
requests.add(this.buildCommonHeatValueStrategy(paramQueryFilter, pageSize));
return requests;
}
... ...
... ... @@ -55,7 +55,6 @@ public class BrandController {
* @param request
* @return
*/
@PersionalRateLimit(isOrderUseable = false)
@RequestMapping(method = RequestMethod.GET, value = "/group_brands")
@ResponseBody
public SearchApiResult groupBrands(HttpServletRequest request) {
... ...
... ... @@ -36,7 +36,6 @@ public class ShopsController {
* @param request
* @return
*/
@PersionalRateLimit(isOrderUseable = false)
@RequestMapping(method = RequestMethod.GET, value = "/group_shops")
@ResponseBody
public SearchApiResult group_shops(HttpServletRequest request) {
... ...
... ... @@ -85,6 +85,5 @@ public class GroupBrandAggregation extends AbstractAggregation {
dataMap.put(brandId, tempResult);
}
return dataMap;
}
}
... ...
... ... @@ -54,8 +54,6 @@ public class GroupShopAggregation extends AbstractAggregation {
public AbstractAggregationBuilder<?> getBuilder() {
return AggCommonHelper.getTopHitAggregation(Arrays.asList(simpleFieldAgg), this.topHitOrder, this.topHitCount);
}
@Override
public Object getAggregationResponseMap(Map<String, Aggregation> aggMaps) {
... ... @@ -85,6 +83,5 @@ public class GroupShopAggregation extends AbstractAggregation {
dataMap.put(shopId, tempResult);
}
return dataMap;
}
}
... ...
... ... @@ -43,8 +43,6 @@ public class PromotionCondService {
private static final String CACHE_KEY = "CacheKey";
private static final String PROMOTION_COND_LIST_CACHE_KEY = "promotionCondListCacheKey";
private static final String PROMOTION_LIST_CACHE_KEY = "promotionListCacheKey";
private volatile List<PromotionCond> promotionCondList = new ArrayList<>();
private volatile List<PromotionIndexBO> promotionIndexBOList = new ArrayList<>();
//PromotionCondList Guava Cache
LoadingCache<String, JSONObject> promotionCondListCache = CacheBuilder.newBuilder()
... ... @@ -66,11 +64,11 @@ public class PromotionCondService {
try {
JSONObject jsonObject = promotionCondListCache.get(CACHE_KEY);
Assert.isTrue(jsonObject != null, "[cache jsonObject cannot be null][fun=getPromotionCondList]");
promotionCondList = (List<PromotionCond>) jsonObject.get(PROMOTION_COND_LIST_CACHE_KEY);
return (List<PromotionCond>) jsonObject.get(PROMOTION_COND_LIST_CACHE_KEY);
} catch (Exception e) {
logger.error(e.getMessage());
return new ArrayList<>();
}
return promotionCondList;
}
/**
... ... @@ -80,18 +78,18 @@ public class PromotionCondService {
try {
JSONObject jsonObject = promotionCondListCache.get(CACHE_KEY);
Assert.isTrue(jsonObject != null, "[cache jsonObject cannot be null][fun=getPromotionList]");
promotionIndexBOList = (List<PromotionIndexBO>) jsonObject.get(PROMOTION_LIST_CACHE_KEY);
return (List<PromotionIndexBO>) jsonObject.get(PROMOTION_LIST_CACHE_KEY);
} catch (Exception e) {
logger.error(e.getMessage());
return new ArrayList<>();
}
return promotionIndexBOList;
}
/**
* 获取PromotionCondList,加入缓存中
*/
public List<PromotionCond> buildPromotionCondList() {
promotionCondList.clear();
List<PromotionCond> promotionCondList = new ArrayList<>();
//去promotionIndex索引查询所有促销数据
List<PromotionIndexBO> promotionIndexBOList = searchAllPromotion();
for (PromotionIndexBO promotionIndexBO : promotionIndexBOList) {
... ... @@ -106,13 +104,11 @@ public class PromotionCondService {
* 获取PromotionList,加入缓存中
*/
public List<PromotionIndexBO> buildPromotionList() {
promotionIndexBOList.clear();
//去promotionIndex索引查询所有促销数据
List<PromotionIndexBO> promotionIndexBOList = searchAllPromotion();
return promotionIndexBOList;
}
/**
* 去promotionIndex索引查询所有促销数据
*/
... ...
package com.yoho.search.service.list;
import com.yoho.search.models.SearchApiResult;
import com.yoho.search.recall.common.ABUserPartitionUtils;
import com.yoho.search.recall.scene.SceneRecallProductListService;
import com.yoho.search.service.base.SearchDynamicConfigService;
import com.yoho.search.service.helper.SearchCommonHelper;
... ...
... ... @@ -12,6 +12,7 @@ import java.util.Map;
import java.util.Map.Entry;
import com.yoho.search.base.utils.ConvertUtils;
import com.yoho.search.common.cache.aop.SearchCacheAble;
import com.yoho.search.service.helper.ProductListHelper;
import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang.StringUtils;
... ... @@ -269,45 +270,34 @@ public class BrandServiceImpl extends AbstractCacheAbleService implements IBrand
}
@Override
@SearchCacheAble(cacheInMinute = 30, cacheName = "GROUP_BRANDS", excludeParams = {"page", "order", "uid", "udid"})
public SearchApiResult groupBrands(Map<String, String> paramMap) {
try {
logger.info("[func=groupBrands][param={}][begin={}]", paramMap.toString(), System.currentTimeMillis());
// 1、参数检验
if (!paramMap.containsKey("brand")) {
// 0、参数检验
if (!paramMap.containsKey(SearchRequestParams.PARAM_SEARCH_BRAND)) {
return new SearchApiResult().setCode(400).setMessage("没有 brand参数 ");
}
// 2、获取聚合条件
// 1、获取topHitCount
int topHitCount = StringUtils.isBlank(paramMap.get("viewNum")) ? 10 : Integer.parseInt(paramMap.get("viewNum"));
// 3、是否需要个性化
// 2、获取聚合的排序规则
String topHitOrder = "heatValue:desc";
if (topHitCount > 0 && searchCommonHelper.isNeedPersonalSearch(paramMap)) {
topHitOrder = "_score:desc";
}
// 4、构建searchParam
SearchParam searchParam = searchParamHelper.buildWithPersional(paramMap, topHitCount > 0 ? true : false);
// 3、构建searchParam
SearchParam searchParam = searchParamHelper.buildWithPersional(paramMap, false);
IAggregation groupBrandAgg = aggregationFactoryService.getGroupBrandAggregation(topHitOrder, topHitCount);
searchParam.setAggregationBuilders(Arrays.asList(groupBrandAgg.getBuilder()));
searchParam.setOffset(0);
searchParam.setSize(0);
searchParam.setOffset(topHitCount * 2);// justForCache
// 5、从缓存中获取
final String productIndexName = ISearchConstants.INDEX_NAME_PRODUCT_INDEX;
JSONObject groupBrandResult = searchCacheService.getJSONObjectFromCache(this.searchCache, productIndexName, searchParam);
if (groupBrandResult != null) {
SearchCacheMatchLogger.doSearchCacheMatchLog("/productindex/groupBrands.json", paramMap);
return new SearchApiResult().setData(groupBrandResult);
}
// 6、从ES中获取
groupBrandResult = aggregationService.getAggNameAndResponseWithTotal(groupBrandAgg, searchParam);
// 4、从ES中获取
JSONObject groupBrandResult = aggregationService.getAggNameAndResponseWithTotal(groupBrandAgg, searchParam);
if (groupBrandResult == null) {
return new SearchApiResult().setData(500).setMessage("exception");
}
// 7、生成结果并且加入缓存
// 5、返回生成结果
JSONObject realResult = new JSONObject();
realResult.put("total", groupBrandResult.getOrDefault("total", 0));
realResult.put("brands", groupBrandResult.getOrDefault(groupBrandAgg.aggName(), new JSONObject()));
searchCacheService.addJSONObjectToCache(this.searchCache, productIndexName, searchParam, realResult);
return new SearchApiResult().setData(realResult).setMessage("groupBrands new List.");
} catch (Exception e) {
publisher.publishEvent(new SearchEvent(EventReportEnum.SEARCHCONTROLLER_GROUP_BRANDS.getEventName(), EventReportEnum.SEARCHCONTROLLER_GROUP_BRANDS.getFunctionName(),
... ...
... ... @@ -46,230 +46,224 @@ import java.util.*;
@Service
public class ShopsServiceImpl extends BaseService implements IShopsService, ApplicationEventPublisherAware {
private static final Logger logger = LoggerFactory.getLogger(ShopsServiceImpl.class);
private static final Logger logger = LoggerFactory.getLogger(ShopsServiceImpl.class);
@Autowired
private SearchCommonService searchCommonService;
@Autowired
private IShopListService shopListService;
@Autowired
private AggregationService aggregationService;
@Autowired
private SearchCommonHelper searchCommonHelper;
@Autowired
private AggregationFactoryService aggregationFactoryService;
@Autowired
private SearchParamHelper searchParamHelper;
@Autowired
private SearchCommonService searchCommonService;
@Autowired
private IShopListService shopListService;
@Autowired
private AggregationService aggregationService;
@Autowired
private AggregationFactoryService aggregationFactoryService;
@Autowired
private SearchParamHelper searchParamHelper;
private ApplicationEventPublisher publisher;
private ApplicationEventPublisher publisher;
@Override
public void setApplicationEventPublisher(ApplicationEventPublisher applicationEventPublisher) {
this.publisher = applicationEventPublisher;
}
@Override
public void setApplicationEventPublisher(ApplicationEventPublisher applicationEventPublisher) {
this.publisher = applicationEventPublisher;
}
@Override
@SearchCacheAble(cacheInMinute = 30, cacheName = "GROUP_SHOPS", excludeParams = { "page", "order" })
public SearchApiResult group_shops(Map<String, String> paramMap) {
try {
// 1、获取topHitCount
int topHitCount = StringUtils.isBlank(paramMap.get("viewNum")) ? 10 : Integer.parseInt(paramMap.get("viewNum"));
// 2、获取聚合的排序规则
String topHitOrder = "heatValue:desc";
if (topHitCount > 0 && searchCommonHelper.isNeedPersonalSearch(paramMap)) {
topHitOrder = "_score:desc";
}
// 3、获取聚合条件
IAggregation groupShopAgg = aggregationFactoryService.getGroupShopAggregation(topHitOrder, topHitCount);
// 4、构建searchParam
SearchParam searchParam = searchParamHelper.buildWithPersional(paramMap, topHitCount > 0 ? true : false);
searchParam.setAggregationBuilders(Arrays.asList(groupShopAgg.getBuilder()));
searchParam.setOffset(0);
searchParam.setSize(0);
// 5、从ES中获取
JSONObject aggNameAndResponse = aggregationService.getAggNameAndResponseWithTotal(groupShopAgg, searchParam);
if (aggNameAndResponse == null) {
return new SearchApiResult().setData(500).setMessage("exception");
}
// 6、返回生成结果
JSONObject realResult = new JSONObject();
realResult.put("total", aggNameAndResponse.getOrDefault("total", 0));
realResult.put("shops", aggNameAndResponse.getOrDefault(groupShopAgg.aggName(), new JSONObject()));
return new SearchApiResult().setData(realResult).setMessage("groupShops new List.");
} catch (Exception e) {
publisher.publishEvent(new SearchEvent(EventReportEnum.SEARCHCONTROLLER_GROUP_SHOPS.getEventName(), EventReportEnum.SEARCHCONTROLLER_GROUP_SHOPS.getFunctionName(),
EventReportEnum.SEARCHCONTROLLER_GROUP_SHOPS.getMoudleName(), "exception", IgnoreSomeException.filterSomeException(e), null));
return SearchApiResultUtils.errorSearchApiResult("group_shops", paramMap, e);
}
}
@Override
@SearchCacheAble(cacheInMinute = 30, cacheName = "GROUP_SHOPS", excludeParams = {"page", "order", "uid", "udid"})
public SearchApiResult group_shops(Map<String, String> paramMap) {
try {
// 1、获取topHitCount
int topHitCount = StringUtils.isBlank(paramMap.get("viewNum")) ? 10 : Integer.parseInt(paramMap.get("viewNum"));
// 2、获取聚合的排序规则
String topHitOrder = "heatValue:desc";
// 3、构建searchParam
SearchParam searchParam = searchParamHelper.buildWithPersional(paramMap, false);
IAggregation groupShopAgg = aggregationFactoryService.getGroupShopAggregation(topHitOrder, topHitCount);
searchParam.setAggregationBuilders(Arrays.asList(groupShopAgg.getBuilder()));
searchParam.setOffset(0);
searchParam.setSize(0);
// 4、从ES中获取
JSONObject aggNameAndResponse = aggregationService.getAggNameAndResponseWithTotal(groupShopAgg, searchParam);
if (aggNameAndResponse == null) {
return new SearchApiResult().setData(500).setMessage("exception");
}
// 5、返回生成结果
JSONObject realResult = new JSONObject();
realResult.put("total", aggNameAndResponse.getOrDefault("total", 0));
realResult.put("shops", aggNameAndResponse.getOrDefault(groupShopAgg.aggName(), new JSONObject()));
return new SearchApiResult().setData(realResult).setMessage("groupShops new List.");
} catch (Exception e) {
publisher.publishEvent(new SearchEvent(EventReportEnum.SEARCHCONTROLLER_GROUP_SHOPS.getEventName(), EventReportEnum.SEARCHCONTROLLER_GROUP_SHOPS.getFunctionName(),
EventReportEnum.SEARCHCONTROLLER_GROUP_SHOPS.getMoudleName(), "exception", IgnoreSomeException.filterSomeException(e), null));
return SearchApiResultUtils.errorSearchApiResult("group_shops", paramMap, e);
}
}
@Override
@SearchCacheAble(cacheInMinute = 30, cacheName = "SEARCH_YOHO_BRAND", includeParams = { "keyword", "is_encode"})
public SearchApiResult searchYohoBrand(Map<String, String> paramMap) {
try {
// 1、参数校验
String keyword = SearchKeyWordUtils.getParamKeyword(paramMap, SearchRequestParams.PARAM_SEARCH_SHOPS_KEYWORD);
if (StringUtils.isBlank(keyword)) {
return new SearchApiResult().setCode(400).setMessage("keyword不能为空!");
}
// 2、配置keyword的查询字段以及权重设置
MultiMatchQueryBuilder queryBuilder = QueryBuilders.multiMatchQuery(keyword);
queryBuilder.operator(Operator.OR);
queryBuilder.field("brandName.brandName_ansj", 100).field("brandName.brandName_pinyin").field("brandNameCn.brandNameCn_ansj").field("brandNameCn.brandNameCn_pinyin")
.field("brandNameEn").field("brandDomain", 50);
queryBuilder.minimumShouldMatch("100%");
@Override
@SearchCacheAble(cacheInMinute = 30, cacheName = "SEARCH_YOHO_BRAND", includeParams = {"keyword", "is_encode"})
public SearchApiResult searchYohoBrand(Map<String, String> paramMap) {
try {
// 1、参数校验
String keyword = SearchKeyWordUtils.getParamKeyword(paramMap, SearchRequestParams.PARAM_SEARCH_SHOPS_KEYWORD);
if (StringUtils.isBlank(keyword)) {
return new SearchApiResult().setCode(400).setMessage("keyword不能为空!");
}
// 3、构建SearchParam
SearchParam searchParam = new SearchParam();
searchParam.setQuery(queryBuilder);
BoolQueryBuilder boolFilter = QueryBuilders.boolQuery();
boolFilter.must(QueryBuilders.termQuery("status", 1));
boolFilter.mustNot(QueryBuilders.termQuery("isGlobal", "Y"));
searchParam.setFiter(boolFilter);
searchParam.setSize(5);
// 2、配置keyword的查询字段以及权重设置
MultiMatchQueryBuilder queryBuilder = QueryBuilders.multiMatchQuery(keyword);
queryBuilder.operator(Operator.OR);
queryBuilder.field("brandName.brandName_ansj", 100).field("brandName.brandName_pinyin").field("brandNameCn.brandNameCn_ansj").field("brandNameCn.brandNameCn_pinyin")
.field("brandNameEn").field("brandDomain", 50);
queryBuilder.minimumShouldMatch("100%");
// 4、根据searchParam查询ES
SearchResult searchResult = searchCommonService.doSearch(ISearchConstants.INDEX_NAME_BRAND, searchParam);
List<String> brandIds = new ArrayList<String>();
Map<String, Map<String, Object>> brandInfoMap = new HashMap<String, Map<String, Object>>();
if (searchResult != null && searchResult.getResultList() != null && !searchResult.getResultList().isEmpty()) {
List<Map<String, Object>> result = searchResult.getResultList();
for (Map<String, Object> brandInfo : result) {
String brandId = brandInfo.get("id").toString();
brandInfoMap.put(brandId, brandInfo);
brandIds.add(brandId);
}
}
// 6、判断能否查出符合条件的品牌
String brandId = this.getMaxScoreIdFromPi(brandIds, "brandId");
JSONObject dataMap = new JSONObject();
if (StringUtils.isNotBlank(brandId)) {
Map<String, Object> brandInfo = brandInfoMap.get(brandId);
dataMap.put("id", brandInfo.getOrDefault("id", 0));
dataMap.put("brand_name", brandInfo.getOrDefault("brandName", ""));
dataMap.put("brand_ico", brandInfo.getOrDefault("brandIco", ""));
dataMap.put("brand_domain", brandInfo.getOrDefault("brandDomain", ""));
}
return new SearchApiResult().setMessage("shops info").setData(dataMap);
} catch (Exception e) {
return SearchApiResultUtils.errorSearchApiResult("searchShops", paramMap, e);
}
}
// 3、构建SearchParam
SearchParam searchParam = new SearchParam();
searchParam.setQuery(queryBuilder);
BoolQueryBuilder boolFilter = QueryBuilders.boolQuery();
boolFilter.must(QueryBuilders.termQuery("status", 1));
boolFilter.mustNot(QueryBuilders.termQuery("isGlobal", "Y"));
searchParam.setFiter(boolFilter);
searchParam.setSize(5);
@Override
@SearchCacheAble(cacheInMinute = 30, cacheName = "SEARCH_SHOP_NEW", includeParams = { "keyword", "is_encode"})
public SearchApiResult searchShopsNew(Map<String, String> paramMap) {
try {
logger.info("[func=searchShops][param={}][begin={}]", paramMap.toString(), System.currentTimeMillis());
// 1、参数校验
String keyword = SearchKeyWordUtils.getParamKeyword(paramMap, SearchRequestParams.PARAM_SEARCH_SHOPS_KEYWORD);
if (StringUtils.isBlank(keyword)) {
return new SearchApiResult().setCode(400).setMessage("keyword不能为空!");
}
// 2、构造返回对象
SearchApiResult searchApiResult = new SearchApiResult();
JSONObject returnMap = new JSONObject();
returnMap.put("shop", null);
returnMap.put("brand", null);
returnMap.put("tblBrand", null);
// 4、根据searchParam查询ES
SearchResult searchResult = searchCommonService.doSearch(ISearchConstants.INDEX_NAME_BRAND, searchParam);
List<String> brandIds = new ArrayList<String>();
Map<String, Map<String, Object>> brandInfoMap = new HashMap<String, Map<String, Object>>();
if (searchResult != null && searchResult.getResultList() != null && !searchResult.getResultList().isEmpty()) {
List<Map<String, Object>> result = searchResult.getResultList();
for (Map<String, Object> brandInfo : result) {
String brandId = brandInfo.get("id").toString();
brandInfoMap.put(brandId, brandInfo);
brandIds.add(brandId);
}
}
// 6、判断能否查出符合条件的品牌
String brandId = this.getMaxScoreIdFromPi(brandIds, "brandId");
JSONObject dataMap = new JSONObject();
if (StringUtils.isNotBlank(brandId)) {
Map<String, Object> brandInfo = brandInfoMap.get(brandId);
dataMap.put("id", brandInfo.getOrDefault("id", 0));
dataMap.put("brand_name", brandInfo.getOrDefault("brandName", ""));
dataMap.put("brand_ico", brandInfo.getOrDefault("brandIco", ""));
dataMap.put("brand_domain", brandInfo.getOrDefault("brandDomain", ""));
}
return new SearchApiResult().setMessage("shops info").setData(dataMap);
} catch (Exception e) {
return SearchApiResultUtils.errorSearchApiResult("searchShops", paramMap, e);
}
}
// 3、查询店铺和全球购品牌
SearchApiResult shopListApiResult = shopListService.searchShopList(paramMap);
if (shopListApiResult != null) {
JSONObject jsonObject = (JSONObject) shopListApiResult.getData();
JSONArray shop_list = jsonObject.getJSONArray("shop_list");
if (shop_list != null && !shop_list.isEmpty()) {
for (int i = 0; i < shop_list.size(); i++) {
JSONObject shop_info = shop_list.getJSONObject(0);
if (shop_info.getJSONObject("yoho_shop") != null) {
JSONObject yohoShop = this.getShopDataMapFromMap(shop_info.getJSONObject("yoho_shop"));
returnMap.put("shop", yohoShop);
return searchApiResult.setData(returnMap);
}
if (shop_info.getJSONObject("tbl_brand") != null) {
JSONObject tblBrand = this.getTblBrandFromMap(shop_info.getJSONObject("tbl_brand"));
returnMap.put("tblBrand", tblBrand);
return searchApiResult.setData(returnMap);
}
}
}
}
// 4、否則获取有货品牌信息
returnMap.put("brand", this.getYohoBrand(paramMap));
@Override
@SearchCacheAble(cacheInMinute = 30, cacheName = "SEARCH_SHOP_NEW", includeParams = {"keyword", "is_encode"})
public SearchApiResult searchShopsNew(Map<String, String> paramMap) {
try {
logger.info("[func=searchShops][param={}][begin={}]", paramMap.toString(), System.currentTimeMillis());
// 1、参数校验
String keyword = SearchKeyWordUtils.getParamKeyword(paramMap, SearchRequestParams.PARAM_SEARCH_SHOPS_KEYWORD);
if (StringUtils.isBlank(keyword)) {
return new SearchApiResult().setCode(400).setMessage("keyword不能为空!");
}
// 2、构造返回对象
SearchApiResult searchApiResult = new SearchApiResult();
JSONObject returnMap = new JSONObject();
returnMap.put("shop", null);
returnMap.put("brand", null);
returnMap.put("tblBrand", null);
// 5、返回结果
return searchApiResult.setData(returnMap);
} catch (Exception e) {
return SearchApiResultUtils.errorSearchApiResult("searchShopsNew", paramMap, e);
}
}
// 3、查询店铺和全球购品牌
SearchApiResult shopListApiResult = shopListService.searchShopList(paramMap);
if (shopListApiResult != null) {
JSONObject jsonObject = (JSONObject) shopListApiResult.getData();
JSONArray shop_list = jsonObject.getJSONArray("shop_list");
if (shop_list != null && !shop_list.isEmpty()) {
for (int i = 0; i < shop_list.size(); i++) {
JSONObject shop_info = shop_list.getJSONObject(0);
if (shop_info.getJSONObject("yoho_shop") != null) {
JSONObject yohoShop = this.getShopDataMapFromMap(shop_info.getJSONObject("yoho_shop"));
returnMap.put("shop", yohoShop);
return searchApiResult.setData(returnMap);
}
if (shop_info.getJSONObject("tbl_brand") != null) {
JSONObject tblBrand = this.getTblBrandFromMap(shop_info.getJSONObject("tbl_brand"));
returnMap.put("tblBrand", tblBrand);
return searchApiResult.setData(returnMap);
}
}
}
}
// 4、否則获取有货品牌信息
returnMap.put("brand", this.getYohoBrand(paramMap));
private JSONObject getShopDataMapFromMap(Map<String, Object> shopInfo) {
JSONObject shopDataMap = new JSONObject();
shopDataMap.put("shop_id", shopInfo.getOrDefault("shop_id", 0));
shopDataMap.put("shop_name", shopInfo.getOrDefault("shop_name", ""));
shopDataMap.put("shop_logo", shopInfo.getOrDefault("shop_logo", ""));
shopDataMap.put("shop_domain", shopInfo.getOrDefault("shop_domain", ""));
shopDataMap.put("shop_type", shopInfo.getOrDefault("shop_type", 0));
shopDataMap.put("decorator_template_type", shopInfo.getOrDefault("decorator_template_type", 0));
return shopDataMap;
}
// 5、返回结果
return searchApiResult.setData(returnMap);
} catch (Exception e) {
return SearchApiResultUtils.errorSearchApiResult("searchShopsNew", paramMap, e);
}
}
private JSONObject getTblBrandFromMap(Map<String, Object> tblBrandInfo) {
JSONObject tblBrand = new JSONObject();
tblBrand.put("brand_id", tblBrandInfo.getOrDefault("id", 0));
tblBrand.put("brand_name", tblBrandInfo.getOrDefault("brand_name", ""));
tblBrand.put("brand_logo", tblBrandInfo.getOrDefault("brand_ico", ""));
return tblBrand;
}
private JSONObject getShopDataMapFromMap(Map<String, Object> shopInfo) {
JSONObject shopDataMap = new JSONObject();
shopDataMap.put("shop_id", shopInfo.getOrDefault("shop_id", 0));
shopDataMap.put("shop_name", shopInfo.getOrDefault("shop_name", ""));
shopDataMap.put("shop_logo", shopInfo.getOrDefault("shop_logo", ""));
shopDataMap.put("shop_domain", shopInfo.getOrDefault("shop_domain", ""));
shopDataMap.put("shop_type", shopInfo.getOrDefault("shop_type", 0));
shopDataMap.put("decorator_template_type", shopInfo.getOrDefault("decorator_template_type", 0));
return shopDataMap;
}
private JSONObject getYohoBrand(Map<String, String> paramMap) {
SearchApiResult searchApiResult = this.searchYohoBrand(paramMap);
if (searchApiResult == null || searchApiResult.getData() == null) {
return null;
}
JSONObject yohoBrandInfo = (JSONObject) searchApiResult.getData();
return yohoBrandInfo;
}
private JSONObject getTblBrandFromMap(Map<String, Object> tblBrandInfo) {
JSONObject tblBrand = new JSONObject();
tblBrand.put("brand_id", tblBrandInfo.getOrDefault("id", 0));
tblBrand.put("brand_name", tblBrandInfo.getOrDefault("brand_name", ""));
tblBrand.put("brand_logo", tblBrandInfo.getOrDefault("brand_ico", ""));
return tblBrand;
}
private JSONObject getYohoBrand(Map<String, String> paramMap) {
SearchApiResult searchApiResult = this.searchYohoBrand(paramMap);
if (searchApiResult == null || searchApiResult.getData() == null) {
return null;
}
JSONObject yohoBrandInfo = (JSONObject) searchApiResult.getData();
return yohoBrandInfo;
}
/**
* 过滤出有库存且有商品上架的店铺id,并且按店铺id排序
*
* @return
*/
private String getMaxScoreIdFromPi(List<String> ids, String esFieldName) {
// 查询ProductIndex
SearchParam searchParam = new SearchParam();
BoolQueryBuilder boolFilter = QueryBuilders.boolQuery();
boolFilter.must(QueryBuilders.termsQuery(esFieldName, ids));
boolFilter.must(QueryBuilders.rangeQuery(ProductIndexEsField.storageNum).gte(1));
boolFilter.must(QueryBuilders.termQuery(ProductIndexEsField.status, "1"));
boolFilter.must(QueryBuilders.termQuery(ProductIndexEsField.attribute, "1"));
searchParam.setFiter(boolFilter);
searchParam.setOffset(0);
searchParam.setSize(1);
// 按shopId打分
BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery();
boolQueryBuilder.must(QueryBuilders.matchAllQuery());
double boost = Math.pow(10d, 5d);
for (String id : ids) {
boolQueryBuilder.should(QueryBuilders.termQuery(esFieldName, id).boost((float) boost));
boost = boost / 10;
}
searchParam.setQuery(boolQueryBuilder);
// 按得分排序
List<SortBuilder<?>> sortBuilders = new ArrayList<SortBuilder<?>>();
sortBuilders.add(SortBuilders.scoreSort().order(SortOrder.DESC));
searchParam.setSortBuilders(sortBuilders);
// 结果只返回shopId
searchParam.setIncludeFields(Arrays.asList(esFieldName));
// 查询ES
SearchResult searchResult = searchCommonService.doSearch(ISearchConstants.INDEX_NAME_PRODUCT_INDEX, searchParam);
if (searchResult == null || CollectionUtils.isEmpty(searchResult.getResultList())) {
return null;
}
return searchResult.getResultList().get(0).get(esFieldName).toString();
}
/**
* 过滤出有库存且有商品上架的店铺id,并且按店铺id排序
*
* @return
*/
private String getMaxScoreIdFromPi(List<String> ids, String esFieldName) {
// 查询ProductIndex
SearchParam searchParam = new SearchParam();
BoolQueryBuilder boolFilter = QueryBuilders.boolQuery();
boolFilter.must(QueryBuilders.termsQuery(esFieldName, ids));
boolFilter.must(QueryBuilders.rangeQuery(ProductIndexEsField.storageNum).gte(1));
boolFilter.must(QueryBuilders.termQuery(ProductIndexEsField.status, "1"));
boolFilter.must(QueryBuilders.termQuery(ProductIndexEsField.attribute, "1"));
searchParam.setFiter(boolFilter);
searchParam.setOffset(0);
searchParam.setSize(1);
// 按shopId打分
BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery();
boolQueryBuilder.must(QueryBuilders.matchAllQuery());
double boost = Math.pow(10d, 5d);
for (String id : ids) {
boolQueryBuilder.should(QueryBuilders.termQuery(esFieldName, id).boost((float) boost));
boost = boost / 10;
}
searchParam.setQuery(boolQueryBuilder);
// 按得分排序
List<SortBuilder<?>> sortBuilders = new ArrayList<SortBuilder<?>>();
sortBuilders.add(SortBuilders.scoreSort().order(SortOrder.DESC));
searchParam.setSortBuilders(sortBuilders);
// 结果只返回shopId
searchParam.setIncludeFields(Arrays.asList(esFieldName));
// 查询ES
SearchResult searchResult = searchCommonService.doSearch(ISearchConstants.INDEX_NAME_PRODUCT_INDEX, searchParam);
if (searchResult == null || CollectionUtils.isEmpty(searchResult.getResultList())) {
return null;
}
return searchResult.getResultList().get(0).get(esFieldName).toString();
}
}
... ...