Authored by saihide

Merge branch 'hongren' into test

... ... @@ -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);
}
... ...
... ... @@ -72,13 +72,14 @@ public class SknImgsCacheBean extends AbstractCacheBean<SknImgsResquest, SknImgs
if (searchResult != null && CollectionUtils.isNotEmpty(searchResult.getResultList())) {
Map<String, SknImgsResponse> defaultImgTempMap = new HashMap<>();
for (Map<String, Object> image : searchResult.getResultList()) {
for (Map<String, Object> product : searchResult.getResultList()) {
SknImgsResponse response = new SknImgsResponse();
response.setDefault_images(MapUtils.getString(image, "defaultImages", ""));
response.setSkn_default_img(MapUtils.getString(image, "sknDefaultImg", ""));
List<JSONObject> goodsList = JSON.parseObject(JSON.toJSONString(image.get("goodsList")), new TypeReference<List<JSONObject>>() {});
response.setDefault_images(MapUtils.getString(product, ProductIndexEsField.defaultImages, ""));
response.setSkn_default_img(MapUtils.getString(product, ProductIndexEsField.sknDefaultImg, ""));
response.setGender(MapUtils.getString(product, ProductIndexEsField.gender, ""));
List<JSONObject> goodsList = JSON.parseObject(JSON.toJSONString(product.get(ProductIndexEsField.goodsList)), new TypeReference<List<JSONObject>>() {});
sknImgHelper.genImage(goodsList, response);
defaultImgTempMap.put(MapUtils.getString(image,"productSkn",""), response);
defaultImgTempMap.put(MapUtils.getString(product,ProductIndexEsField.productSkn,""), response);
}
for (SknImgsRequestResponse requestResponse : missCacheRequests) {
results.put(requestResponse.getRequest(), defaultImgTempMap.get(requestResponse.getRequest().getProductSkn().toString()));
... ...
... ... @@ -16,7 +16,7 @@ import java.util.Arrays;
import java.util.List;
public class ShopProductRequest implements ICacheRequest {
private static final List<String> includeFields = Arrays.asList(ProductIndexEsField.productSkn, ProductIndexEsField.productName, ProductIndexEsField.shopId, ProductIndexEsField.shopName, ProductIndexEsField.defaultImages, ProductIndexEsField.goodsList, ProductIndexEsField.salesPrice);
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.brandName);
private ParamQueryFilter paramQueryFilter;
private Integer shopId;
private RedisKeyBuilder redisKeyBuilder;
... ... @@ -69,7 +69,7 @@ public class ShopProductRequest implements ICacheRequest {
}
searchParam.setFiter(realFilter);
searchParam.setIncludeFields(includeFields);
searchParam.setSortBuilders(Arrays.asList(SortBuilders.fieldSort(ProductIndexEsField.shelveTime).order(SortOrder.DESC)));
searchParam.setSortBuilders(Arrays.asList(SortBuilders.fieldSort(ProductIndexEsField.heatValue).order(SortOrder.DESC), SortBuilders.fieldSort(ProductIndexEsField.shelveTime).order(SortOrder.DESC)));
searchParam.setOffset(0);
searchParam.setSize(10);
return searchParam;
... ...
... ... @@ -11,10 +11,14 @@ public class ShopProductResponse {
public static class ShopProduct {
private Integer product_skn;
private String product_name;
private String gender;
private String default_images;
private String cover_1;
private String cover_2;
private Double sales_price;
private Object product_price_plan_list;
private String brand_name;
private String brand_ico;
public Integer getProduct_skn() {
return product_skn;
... ... @@ -63,6 +67,38 @@ public class ShopProductResponse {
public void setCover_2(String cover_2) {
this.cover_2 = cover_2;
}
public String getGender() {
return gender;
}
public void setGender(String gender) {
this.gender = gender;
}
public Object getProduct_price_plan_list() {
return product_price_plan_list;
}
public void setProduct_price_plan_list(Object product_price_plan_list) {
this.product_price_plan_list = product_price_plan_list;
}
public String getBrand_name() {
return brand_name;
}
public void setBrand_name(String brand_name) {
this.brand_name = brand_name;
}
public String getBrand_ico() {
return brand_ico;
}
public void setBrand_ico(String brand_ico) {
this.brand_ico = brand_ico;
}
}
public Integer getShop_id() {
... ...
... ... @@ -5,6 +5,7 @@ public class SknImgsResponse {
private String skn_default_img;
private String cover_1;
private String cover_2;
private String gender;
public String getDefault_images() {
return default_images;
... ... @@ -37,4 +38,12 @@ public class SknImgsResponse {
public void setCover_2(String cover_2) {
this.cover_2 = cover_2;
}
public String getGender() {
return gender;
}
public void setGender(String gender) {
this.gender = gender;
}
}
... ...
... ... @@ -9,7 +9,7 @@ import java.util.Arrays;
import java.util.List;
public class SknImgsResquest implements ICacheRequest {
private static final List<String> includeFields = Arrays.asList(ProductIndexEsField.productSkn,ProductIndexEsField.defaultImages, ProductIndexEsField.sknDefaultImg, ProductIndexEsField.goodsList);
private static final List<String> includeFields = Arrays.asList(ProductIndexEsField.productSkn,ProductIndexEsField.defaultImages, ProductIndexEsField.sknDefaultImg, ProductIndexEsField.goodsList,ProductIndexEsField.gender);
private Integer productSkn;
public SknImgsResquest(Integer productSkn){
... ...
... ... @@ -15,7 +15,7 @@ import java.util.Map;
@RestController
@RequestMapping("/hr")
public class HongRenDistributionController {
public class HrDistributionController {
@Autowired
private SearchSortGroupService searchSortGroupService;
... ... @@ -52,13 +52,14 @@ public class HongRenDistributionController {
}
SearchApiResult searchApiResult = searchHongRenService.productList(paramMap);
return searchApiResult;
}
@RequestMapping(method = RequestMethod.GET, value = "/productListForFuzzy")
public SearchApiResult fuzzyProductList(HttpServletRequest request) {
Map<String, String> paramMap = HttpServletRequestUtils.transParamType(request);
if (!checkRequestParam(paramMap)) {
return new SearchApiResult().setCode(400).setMessage("入参缺少poolShopId参数");
return new SearchApiResult().setCode(400).setMessage("入参缺少hrShopId参数");
}
SearchApiResult searchApiResult = searchHongRenService.productListForFuzzy(paramMap);
return searchApiResult;
... ...