...
|
...
|
@@ -4,12 +4,12 @@ import com.alibaba.fastjson.JSON; |
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.alibaba.fastjson.TypeReference;
|
|
|
import com.yoho.search.base.utils.ISearchConstants;
|
|
|
import com.yoho.search.base.utils.ProductIndexEsField;
|
|
|
import com.yoho.search.core.es.model.SearchParam;
|
|
|
import com.yoho.search.core.es.model.SearchResult;
|
|
|
import com.yoho.search.recall.scene.beans.helper.SknImgHelper;
|
|
|
import com.yoho.search.recall.scene.models.req.*;
|
|
|
import com.yoho.search.service.base.SearchCommonService;
|
|
|
import com.yoho.search.service.base.index.ProductIndexBaseService;
|
|
|
import org.apache.commons.collections.MapUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Component;
|
...
|
...
|
@@ -25,6 +25,8 @@ public class ShopProductCacheBean extends AbstractCacheBean<ShopProductRequest, |
|
|
private SearchCommonService searchCommonService;
|
|
|
@Autowired
|
|
|
private SknImgHelper sknImgHelper;
|
|
|
@Autowired
|
|
|
private ProductIndexBaseService productIndexBaseService;
|
|
|
|
|
|
public List<ShopProductResponse> getShopSknByShopId(List<ShopProductRequest> shopSknRequests, String hrShopIds) {
|
|
|
final List<ShopProductRequestResponse> shopSknRequestResponses = new ArrayList<>();
|
...
|
...
|
@@ -58,17 +60,29 @@ public class ShopProductCacheBean extends AbstractCacheBean<ShopProductRequest, |
|
|
}
|
|
|
//2、执行搜索
|
|
|
List<SearchResult> searchResults = searchCommonService.doMutiSearch(ISearchConstants.INDEX_NAME_PRODUCT_INDEX, searchParams);
|
|
|
//获得变价计划
|
|
|
Map<String, List<Map<String, Object>>> shopProductListMap = new HashMap<>();
|
|
|
|
|
|
for (int i = 0; i < missCacheRequests.size(); i++) {
|
|
|
ShopProductRequest request = missCacheRequests.get(i).getRequest();
|
|
|
SearchResult searchResult = searchResults.get(i);
|
|
|
ShopProductResponse response = buildResonse(searchResult, request);
|
|
|
|
|
|
if (request != null && searchResult != null) {
|
|
|
shopProductListMap.put(request.getShopId().toString(), searchResult.getResultList());
|
|
|
}
|
|
|
}
|
|
|
shopProductListMap = productIndexBaseService.getProductListWithPricePlan(shopProductListMap);
|
|
|
|
|
|
for (int i = 0; i < missCacheRequests.size(); i++) {
|
|
|
ShopProductRequest request = missCacheRequests.get(i).getRequest();
|
|
|
List<Map<String, Object>> productList = shopProductListMap.get(request.getShopId().toString());
|
|
|
ShopProductResponse response = buildResonse(productList, request);
|
|
|
results.put(request, response);
|
|
|
}
|
|
|
return results;
|
|
|
}
|
|
|
|
|
|
private ShopProductResponse buildResonse(SearchResult searchResult, ShopProductRequest request) {
|
|
|
List<Map<String, Object>> productList = searchResult.getResultList();
|
|
|
private ShopProductResponse buildResonse(List<Map<String, Object>> productList, ShopProductRequest request) {
|
|
|
ShopProductResponse response = new ShopProductResponse();
|
|
|
List<ShopProductResponse.ShopProduct> shopProductList = new ArrayList<>();
|
|
|
response.setShop_id(request.getShopId());
|
...
|
...
|
@@ -76,15 +90,18 @@ public class ShopProductCacheBean extends AbstractCacheBean<ShopProductRequest, |
|
|
|
|
|
if (!CollectionUtils.isEmpty(productList)) {
|
|
|
Map<String, Object> product = productList.get(0);
|
|
|
response.setShop_name(MapUtils.getString(product, ProductIndexEsField.shopName, ""));
|
|
|
response.setShop_name(MapUtils.getString(product, "shop_name", ""));
|
|
|
//1、构建结果
|
|
|
for (Map<String, Object> productInfo : productList) {
|
|
|
ShopProductResponse.ShopProduct shopProduct = new ShopProductResponse.ShopProduct();
|
|
|
shopProduct.setProduct_skn(MapUtils.getInteger(productInfo, ProductIndexEsField.productSkn, 0));
|
|
|
shopProduct.setProduct_name(MapUtils.getString(productInfo, ProductIndexEsField.productName, ""));
|
|
|
shopProduct.setSales_price(MapUtils.getDouble(productInfo, ProductIndexEsField.salesPrice, 0.0));
|
|
|
shopProduct.setDefault_images(MapUtils.getString(productInfo, ProductIndexEsField.defaultImages, ""));
|
|
|
List<JSONObject> goodsList = JSON.parseObject(JSON.toJSONString(productInfo.get("goodsList")), new TypeReference<List<JSONObject>>() {});
|
|
|
shopProduct.setProduct_skn(MapUtils.getInteger(productInfo, "product_skn", 0));
|
|
|
shopProduct.setProduct_name(MapUtils.getString(productInfo, "product_name", ""));
|
|
|
shopProduct.setGender(MapUtils.getString(productInfo, "gender", "1,3"));
|
|
|
shopProduct.setSales_price(MapUtils.getDouble(productInfo, "sales_price", 0.0));
|
|
|
shopProduct.setDefault_images(MapUtils.getString(productInfo, "default_images", ""));
|
|
|
shopProduct.setBrand_name(MapUtils.getString(productInfo, "brand_name", ""));
|
|
|
shopProduct.setProduct_price_plan_list(MapUtils.getObject(productInfo, "product_price_plan_list", Collections.emptyList()));
|
|
|
List<JSONObject> goodsList = JSON.parseObject(JSON.toJSONString(productInfo.get("goods_list")), new TypeReference<List<JSONObject>>() {});
|
|
|
sknImgHelper.genImage(goodsList, shopProduct);
|
|
|
shopProductList.add(shopProduct);
|
|
|
}
|
...
|
...
|
|