...
|
...
|
@@ -14,6 +14,7 @@ import com.yoho.core.config.ConfigReader; |
|
|
import com.yohobuy.ufo.model.promotion.response.CouponInfo;
|
|
|
import com.yohoufo.common.ApiResponse;
|
|
|
import com.yohoufo.common.constant.BusinessClientEnum;
|
|
|
import com.yohoufo.common.utils.MathUtil;
|
|
|
import com.yohoufo.dal.product.BrandMapper;
|
|
|
import com.yohoufo.product.constants.ProductSearchConstants;
|
|
|
import org.apache.commons.collections.MapUtils;
|
...
|
...
|
@@ -80,9 +81,6 @@ public class ProductSearchServiceImpl implements ProductSearchService { |
|
|
private BrandMapper brandMapper;
|
|
|
|
|
|
@Autowired
|
|
|
ProductSalesService productSalesService;
|
|
|
|
|
|
@Autowired
|
|
|
private ProductMapper productMapper;
|
|
|
|
|
|
@Autowired
|
...
|
...
|
@@ -92,7 +90,7 @@ public class ProductSearchServiceImpl implements ProductSearchService { |
|
|
private ProductHelpService productHelpService;
|
|
|
|
|
|
@Autowired
|
|
|
private ProductSearchAssistService productSearchAssistService;
|
|
|
private ProductSearchAssistService searchAssistService;
|
|
|
|
|
|
private JSONObject search(Map<String, Object> searchParams, String url) {
|
|
|
logger.info("begin invoke search.productList, param is:{}, url is :{}", searchParams, url);
|
...
|
...
|
@@ -171,8 +169,8 @@ public class ProductSearchServiceImpl implements ProductSearchService { |
|
|
JSONObject data = search(searchParam.getParam(), url);
|
|
|
// 将图片的相对路径转成绝对路径
|
|
|
if (null != data) {
|
|
|
processProductList(data.getJSONArray("product_list"));
|
|
|
processProductSales(data.getJSONArray("product_list"));
|
|
|
searchAssistService.processProductList(data.getJSONArray("product_list"));
|
|
|
searchAssistService.processProductSales(data.getJSONArray("product_list"));
|
|
|
}
|
|
|
|
|
|
return data;
|
...
|
...
|
@@ -186,8 +184,8 @@ public class ProductSearchServiceImpl implements ProductSearchService { |
|
|
JSONObject data = search(searchParam.getParam(), url);
|
|
|
// 将图片的相对路径转成绝对路径
|
|
|
if (null != data) {
|
|
|
processProductList(data.getJSONArray("product_list"));
|
|
|
processProductSales(data.getJSONArray("product_list"));
|
|
|
searchAssistService.processProductList(data.getJSONArray("product_list"));
|
|
|
searchAssistService.processProductSales(data.getJSONArray("product_list"));
|
|
|
}
|
|
|
|
|
|
return data;
|
...
|
...
|
@@ -200,84 +198,8 @@ public class ProductSearchServiceImpl implements ProductSearchService { |
|
|
return data;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 对商品列表的信息进行修改,商品图片地址URL补全
|
|
|
*
|
|
|
*/
|
|
|
protected void processProductList(JSONArray productList) {
|
|
|
if(CollectionUtils.isEmpty(productList)){
|
|
|
return;
|
|
|
}
|
|
|
// 遍历商品列表
|
|
|
for (int i = 0; i < productList.size(); i++) {
|
|
|
JSONObject product = productList.getJSONObject(i);
|
|
|
if(null == product){
|
|
|
continue;
|
|
|
}
|
|
|
// 处理图片,封面图设置
|
|
|
String default_images = fillProductImgUrl(MapUtils.getString(product, "default_images", ""));
|
|
|
product.replace("default_images", default_images);
|
|
|
//处理有货价格
|
|
|
if (StringUtils.equals(product.getString("is_yoho"), "Y")) {
|
|
|
handlerPrice(product);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 对二手商品列表的信息进行修改,商品图片地址URL补全
|
|
|
*
|
|
|
*/
|
|
|
protected void processSecondhandSkupList(JSONArray skupList) {
|
|
|
if(CollectionUtils.isEmpty(skupList)){
|
|
|
return;
|
|
|
}
|
|
|
// 遍历商品列表
|
|
|
for (int i = 0; i < skupList.size(); i++) {
|
|
|
JSONObject product = skupList.getJSONObject(i);
|
|
|
if(null == product){
|
|
|
continue;
|
|
|
}
|
|
|
// 处理图片,封面图设置
|
|
|
String secondhand_image = fillProductImgUrl(MapUtils.getString(product, "secondhand_image", ""));
|
|
|
product.replace("secondhand_image", secondhand_image);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
public static void main(String[] args) {
|
|
|
System.out.println(fillProductImgUrl("https://img12.static.yhbimg.com/goodsimg/2019/04/17/17/021560b1bd437ded9a66dd15c29c81c53d.jpg"));
|
|
|
}
|
|
|
|
|
|
protected void processProductSales(JSONArray productList) {
|
|
|
if(CollectionUtils.isEmpty(productList)){
|
|
|
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(product.getInteger("id"));
|
|
|
}
|
|
|
|
|
|
Map<Integer, Integer> salesMap = productSalesService.selectAmountByProductIdList(productIdList);
|
|
|
|
|
|
// 遍历商品列表
|
|
|
for (int i = 0; i < productList.size(); i++) {
|
|
|
JSONObject product = productList.getJSONObject(i);
|
|
|
if (null == product) {
|
|
|
continue;
|
|
|
}
|
|
|
Integer amount = salesMap.get(product.getInteger("id"));
|
|
|
if (null == amount) {
|
|
|
continue;
|
|
|
}
|
|
|
product.put("sales", amount);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@SuppressWarnings("unchecked")
|
|
|
@Override
|
|
|
public void processUserFavoriteProductList(JSONObject productJSON, Integer uid) {
|
...
|
...
|
@@ -319,19 +241,6 @@ public class ProductSearchServiceImpl implements ProductSearchService { |
|
|
}
|
|
|
}
|
|
|
|
|
|
private static String fillProductImgUrl(String imgUrl) {
|
|
|
if (StringUtils.isBlank(imgUrl)) {
|
|
|
return imgUrl;
|
|
|
}
|
|
|
if (imgUrl.startsWith("http://")) {
|
|
|
return imgUrl;
|
|
|
}
|
|
|
if (imgUrl.startsWith("https://")) {
|
|
|
return imgUrl;
|
|
|
}
|
|
|
return ImageUrlAssist.getAllProductPicUrl(imgUrl, "goodsimg", "center", "d2hpdGU=");
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public SearchProductListFilterResp searchProductListFilter(ProductSearchReq req) {
|
|
|
if (StringUtils.isNotBlank(req.getCouponToken())) {
|
...
|
...
|
@@ -472,7 +381,7 @@ public class ProductSearchServiceImpl implements ProductSearchService { |
|
|
|
|
|
JSONObject data = search(searchParam.getParam(), ProductSearchConstants.PRODUCT_RECOMMEND_LIST_URL);
|
|
|
if(data != null && !CollectionUtils.isEmpty(data.getJSONArray("product_list"))) {
|
|
|
processProductSales(data.getJSONArray("product_list"));
|
|
|
searchAssistService.processProductSales(data.getJSONArray("product_list"));
|
|
|
resp = JSON.toJavaObject(data, SearchProductRecommendResp.class);
|
|
|
|
|
|
// 对品牌的log 进行相对路径转绝对路径
|
...
|
...
|
@@ -596,7 +505,7 @@ public class ProductSearchServiceImpl implements ProductSearchService { |
|
|
JSONObject data = search(searchParam.getParam(), ProductSearchConstants.SALE_CALENDAR_LIST_URL);
|
|
|
// 将图片的相对路径转成绝对路径
|
|
|
if (null != data) {
|
|
|
processProductList(data.getJSONArray("product_list"));
|
|
|
searchAssistService.processProductList(data.getJSONArray("product_list"));
|
|
|
}
|
|
|
return data;
|
|
|
}
|
...
|
...
|
@@ -614,7 +523,7 @@ public class ProductSearchServiceImpl implements ProductSearchService { |
|
|
JSONObject data = search(searchParam.getParam(), ProductSearchConstants.NEW_SALE_CALENDAR_LIST_URL);
|
|
|
// 将图片的相对路径转成绝对路径
|
|
|
if (null != data) {
|
|
|
processProductList(data.getJSONArray("product_list"));
|
|
|
searchAssistService.processProductList(data.getJSONArray("product_list"));
|
|
|
}
|
|
|
return data;
|
|
|
}
|
...
|
...
|
@@ -626,90 +535,11 @@ public class ProductSearchServiceImpl implements ProductSearchService { |
|
|
JSONObject data = search(searchParam.getParam(), ProductSearchConstants.HOT_SALE_LIST_URL);
|
|
|
// 将图片的相对路径转成绝对路径
|
|
|
if (null != data) {
|
|
|
processProductList(data.getJSONArray("product_list"));
|
|
|
processProductSales(data.getJSONArray("product_list"));
|
|
|
searchAssistService.processProductList(data.getJSONArray("product_list"));
|
|
|
searchAssistService.processProductSales(data.getJSONArray("product_list"));
|
|
|
}
|
|
|
return data;
|
|
|
}
|
|
|
|
|
|
public void handlerPrice(JSONObject product) {
|
|
|
product.put("price", getIntCeilPrice(product.getDouble("price")));
|
|
|
JSONArray planList = product.getJSONArray("product_price_plan_list");
|
|
|
if(CollectionUtils.isEmpty(planList)){
|
|
|
return;
|
|
|
}
|
|
|
JSONObject effectPlan = getEffectProductPricePlan(planList);
|
|
|
//没有符合的价格计划,直接返回
|
|
|
if(null==effectPlan){
|
|
|
return;
|
|
|
}
|
|
|
if(null!=effectPlan.get("current_saleprice")){
|
|
|
product.replace("sales_price", getIntCeilPrice(effectPlan.getDouble("current_saleprice")));
|
|
|
}
|
|
|
if(null!=effectPlan.get("vip1_price")){
|
|
|
product.replace("vip1_price", effectPlan.getDouble("vip1_price"));
|
|
|
}
|
|
|
|
|
|
if(null!=effectPlan.get("vip2_price")){
|
|
|
product.replace("vip2_price", effectPlan.getDouble("vip2_price"));
|
|
|
}
|
|
|
|
|
|
if(null!=effectPlan.get("vip3_price")){
|
|
|
product.replace("vip3_price", effectPlan.getDouble("vip3_price"));
|
|
|
}
|
|
|
|
|
|
if(null!=effectPlan.get("vip_discount_type")){
|
|
|
product.replace("vip_discount_type", effectPlan.getInteger("vip_discount_type"));
|
|
|
}
|
|
|
if(null!=effectPlan.get("student_price") && !"Y".equalsIgnoreCase(product.getString("is_student_price"))){
|
|
|
product.replace("student_price", product.getBigDecimal("sales_price").multiply(new BigDecimal("0.9")));
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 获取一个生效的变价计划
|
|
|
* @param list
|
|
|
* @return
|
|
|
*/
|
|
|
private JSONObject getEffectProductPricePlan(JSONArray planList){
|
|
|
if(CollectionUtils.isEmpty(planList)){
|
|
|
return null;
|
|
|
}
|
|
|
//先计算匹配到的价格计划,然后根据匹配到的价格计划求优先级
|
|
|
int currentTime= DateUtil.getCurrentTimeSecond();
|
|
|
logger.info("currentTime: {}", currentTime);
|
|
|
List<JSONObject> fitProductPricePlanList=Lists.newArrayList();
|
|
|
for (int i=0; i < planList.size(); i++) {
|
|
|
JSONObject item = planList.getJSONObject(i);
|
|
|
//当前时间大于等于生效时间且当前时间小于结束时间或没有结束时间的
|
|
|
if(currentTime>=item.getIntValue("effect_time") && (currentTime<=item.getIntValue("end_time")||item.getIntValue("end_time")==0)){
|
|
|
fitProductPricePlanList.add(item);
|
|
|
}
|
|
|
}
|
|
|
if(!CollectionUtils.isEmpty(fitProductPricePlanList)){
|
|
|
//在多个价格计划都满足的情况下,生效时间越大越靠前
|
|
|
Collections.sort(fitProductPricePlanList, new Comparator<JSONObject>() {
|
|
|
@Override
|
|
|
public int compare(JSONObject o1, JSONObject o2) {
|
|
|
if(o2.getInteger("effect_time").compareTo(o1.getInteger("effect_time"))==0
|
|
|
&& null!=o2.getInteger("create_time") && null!=o1.getInteger("create_time")){
|
|
|
return o2.getInteger("create_time").compareTo(o1.getInteger("create_time"));
|
|
|
}
|
|
|
return o2.getInteger("effect_time").compareTo(o1.getInteger("effect_time"));
|
|
|
}
|
|
|
});
|
|
|
return fitProductPricePlanList.get(0);
|
|
|
}
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
//获取取整的价格
|
|
|
public static Integer getIntCeilPrice(Double price){
|
|
|
if(null == price) {
|
|
|
return 0;
|
|
|
}
|
|
|
return Double.valueOf(Math.ceil(price)).intValue();
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public JSONObject searchUvscoreProductList(ProductSearchReq req, Integer regularize) {
|
...
|
...
|
@@ -721,12 +551,12 @@ public class ProductSearchServiceImpl implements ProductSearchService { |
|
|
JSONObject data = search(searchParam.getParam(), url);
|
|
|
// 将图片的相对路径转成绝对路径
|
|
|
if (null != data) {
|
|
|
processProductList(data.getJSONArray("product_list"));
|
|
|
searchAssistService.processProductList(data.getJSONArray("product_list"));
|
|
|
|
|
|
if (REGULARIZE_NFC.equals(regularize)) { // NFC分享页列表 需要返回 3的倍数的列表且不需要销量
|
|
|
regularize(data.getJSONArray("product_list"));
|
|
|
searchAssistService.regularize(data.getJSONArray("product_list"));
|
|
|
} else {
|
|
|
processProductSales(data.getJSONArray("product_list")); // NFC分享页列表不需要销量
|
|
|
searchAssistService.processProductSales(data.getJSONArray("product_list")); // NFC分享页列表不需要销量
|
|
|
}
|
|
|
}
|
|
|
return data;
|
...
|
...
|
@@ -748,7 +578,7 @@ public class ProductSearchServiceImpl implements ProductSearchService { |
|
|
|
|
|
JSONObject data = search(searchParam.getParam(), ProductSearchConstants.PRODUCT_RECOMMEND_BY_SERIESBRAND_LIST_URL);
|
|
|
if(data != null && !CollectionUtils.isEmpty(data.getJSONArray("product_list"))) {
|
|
|
processProductSales(data.getJSONArray("product_list"));
|
|
|
searchAssistService.processProductSales(data.getJSONArray("product_list"));
|
|
|
resp = JSON.toJavaObject(data, SearchProductRecommendResp.class);
|
|
|
|
|
|
// 对品牌的log 进行相对路径转绝对路径
|
...
|
...
|
@@ -769,26 +599,12 @@ public class ProductSearchServiceImpl implements ProductSearchService { |
|
|
JSONObject data = search(searchParam.getParam(), url);
|
|
|
// 将图片的相对路径转成绝对路径
|
|
|
if (null != data) {
|
|
|
processSecondhandSkupList(data.getJSONArray("skup_list"));
|
|
|
searchAssistService.processSecondhandSkupList(data.getJSONArray("skup_list"));
|
|
|
}
|
|
|
|
|
|
return data;
|
|
|
}
|
|
|
|
|
|
// NFC详情分享页列表要保证 3的倍数,这里做最后的保证
|
|
|
private void regularize(JSONArray productList) {
|
|
|
if(CollectionUtils.isEmpty(productList)){
|
|
|
return;
|
|
|
}
|
|
|
logger.info("method regularize in. productList.size() is {}", productList.size());
|
|
|
if (productList.size() % 3 == 1) {
|
|
|
productList.remove(productList.size() - 1);
|
|
|
} else if (productList.size() % 3 == 2) {
|
|
|
productList.remove(productList.size() - 1);
|
|
|
productList.remove(productList.size() - 2);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
private CouponInfo getCouponInfo(String token) {
|
|
|
ApiResponse resp = ufoServiceCaller.call("ufo.coupons.getProductIds", ApiResponse.class, token);
|
|
|
return (CouponInfo) resp.getData();
|
...
|
...
|
|