...
|
...
|
@@ -9,6 +9,8 @@ import java.util.stream.Collectors; |
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
import com.google.common.collect.Lists;
|
|
|
import com.yohoufo.common.cache.Cachable;
|
|
|
import com.yohoufo.common.caller.UfoServiceCaller;
|
|
|
import com.yohoufo.common.helper.ImageUrlAssist;
|
|
|
import com.yohoufo.common.utils.UfoStringUtils;
|
|
|
import com.yohoufo.dal.product.ProductMapper;
|
...
|
...
|
@@ -37,8 +39,10 @@ import org.springframework.stereotype.Service; |
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.yoho.core.rest.client.ServiceCaller;
|
|
|
import com.yoho.core.rest.exception.ServiceNotAvaibleException;
|
|
|
import com.yoho.error.exception.ServiceException;
|
|
|
import com.yohoufo.product.service.ProductSearchService;
|
|
|
import org.springframework.util.CollectionUtils;
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
|
|
|
@Service
|
|
|
public class ProductSearchServiceImpl implements ProductSearchService {
|
...
|
...
|
@@ -50,6 +54,9 @@ public class ProductSearchServiceImpl implements ProductSearchService { |
|
|
|
|
|
@Autowired
|
|
|
private ServiceCaller serviceCaller;
|
|
|
|
|
|
@Autowired
|
|
|
private UfoServiceCaller ufoServiceCaller;
|
|
|
|
|
|
@Autowired
|
|
|
private ProductSortMapper productSortMapper;
|
...
|
...
|
@@ -70,6 +77,10 @@ public class ProductSearchServiceImpl implements ProductSearchService { |
|
|
|
|
|
|
|
|
public static final String PRODUCT_RECOMMEND_LIST_URL = "/yohosearch/ufo/recommendList.json";
|
|
|
|
|
|
|
|
|
public static final String SALE_CALENDAR_LIST_URL = "/yohosearch/ufo/saleCalendarProductList.json";
|
|
|
public static final String HOT_SALE_LIST_URL = "/yohosearch/ufo/hotSaleProductList.json";
|
|
|
|
|
|
private JSONObject search(Map<String, Object> searchParams, String url) {
|
|
|
logger.info("begin invoke search.productList, param is:{}, url is :{}", searchParams, url);
|
...
|
...
|
@@ -131,6 +142,47 @@ public class ProductSearchServiceImpl implements ProductSearchService { |
|
|
product.replace("default_images", default_images);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@SuppressWarnings("unchecked")
|
|
|
@Override
|
|
|
public void processUserFavoriteProductList(JSONObject productJSON, Integer uid) {
|
|
|
JSONArray productList = productJSON.getJSONArray("product_list");
|
|
|
if (CollectionUtils.isEmpty(productList) || uid == null || uid < 1) {
|
|
|
return;
|
|
|
}
|
|
|
List<Integer> productIdList = new ArrayList<>();
|
|
|
// 遍历商品列表
|
|
|
for (int i = 0; i < productList.size(); i++) {
|
|
|
JSONObject product = productList.getJSONObject(i);
|
|
|
if (null == product) {
|
|
|
continue;
|
|
|
}
|
|
|
productIdList.add(MapUtils.getInteger(product, "id", 0));
|
|
|
}
|
|
|
try {
|
|
|
List<Integer> favorite = ufoServiceCaller.call("ufo.user.selectFavoriteList", List.class, uid,
|
|
|
productIdList);
|
|
|
if(org.apache.commons.collections.CollectionUtils.isEmpty(favorite)) {
|
|
|
return;
|
|
|
}
|
|
|
// 遍历商品列表
|
|
|
for (int i = 0; i < productList.size(); i++) {
|
|
|
JSONObject product = productList.getJSONObject(i);
|
|
|
if (null == product) {
|
|
|
continue;
|
|
|
}
|
|
|
// 处理图片,封面图设置
|
|
|
Integer productId = MapUtils.getInteger(product, "id", 0);
|
|
|
if (productId != 0 && favorite.contains(productId)) {
|
|
|
product.put("isFavorite", 1);
|
|
|
} else {
|
|
|
product.put("isFavorite", 0);
|
|
|
}
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
|
logger.error("销售日历,处理用户收藏出错!", e);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
private static String fillProductImgUrl(String imgUrl) {
|
|
|
if (StringUtils.isBlank(imgUrl)) {
|
...
|
...
|
@@ -332,4 +384,29 @@ public class ProductSearchServiceImpl implements ProductSearchService { |
|
|
}
|
|
|
return respList;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@Cachable(expire=180)
|
|
|
public JSONObject searchSaleCalendar(Integer page, Integer limit) {
|
|
|
ProductSearchReq req = new ProductSearchReq().setViewNum(limit).setPage(page);
|
|
|
SearchParam searchParam = new SearchParam().buildPageSearchParam(req);
|
|
|
JSONObject data = search(searchParam.getParam(), SALE_CALENDAR_LIST_URL);
|
|
|
// 将图片的相对路径转成绝对路径
|
|
|
if (null != data) {
|
|
|
processProductList(data.getJSONArray("product_list"));
|
|
|
}
|
|
|
return data;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public JSONObject searchHotSale(Integer page, Integer limit) {
|
|
|
ProductSearchReq req = new ProductSearchReq().setViewNum(limit).setPage(page);
|
|
|
SearchParam searchParam = new SearchParam().buildPageSearchParam(req);
|
|
|
JSONObject data = search(searchParam.getParam(), HOT_SALE_LIST_URL);
|
|
|
// 将图片的相对路径转成绝对路径
|
|
|
if (null != data) {
|
|
|
processProductList(data.getJSONArray("product_list"));
|
|
|
}
|
|
|
return data;
|
|
|
}
|
|
|
} |
...
|
...
|
|