...
|
...
|
@@ -8,6 +8,7 @@ import java.util.Comparator; |
|
|
import java.util.Date;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
import java.util.function.Function;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
import org.apache.commons.collections.MapUtils;
|
...
|
...
|
@@ -31,8 +32,10 @@ import com.yohoufo.common.caller.UfoServiceCaller; |
|
|
import com.yohoufo.common.helper.ImageUrlAssist;
|
|
|
import com.yohoufo.common.utils.UfoStringUtils;
|
|
|
import com.yohoufo.dal.product.ProductMapper;
|
|
|
import com.yohoufo.dal.product.ProductSalesMapper;
|
|
|
import com.yohoufo.dal.product.ProductSortMapper;
|
|
|
import com.yohoufo.dal.product.model.Product;
|
|
|
import com.yohoufo.dal.product.model.ProductSales;
|
|
|
import com.yohoufo.dal.product.model.ProductSort;
|
|
|
import com.yohoufo.product.helper.SearchParam;
|
|
|
import com.yohoufo.product.model.FilterItem;
|
...
|
...
|
@@ -62,6 +65,9 @@ public class ProductSearchServiceImpl implements ProductSearchService { |
|
|
|
|
|
@Autowired
|
|
|
private ProductSortMapper productSortMapper;
|
|
|
|
|
|
@Autowired
|
|
|
private ProductSalesMapper productSalesMapper;
|
|
|
|
|
|
@Autowired
|
|
|
private ProductMapper productMapper;
|
...
|
...
|
@@ -144,6 +150,7 @@ public class ProductSearchServiceImpl implements ProductSearchService { |
|
|
// 将图片的相对路径转成绝对路径
|
|
|
if (null != data) {
|
|
|
processProductList(data.getJSONArray("product_list"));
|
|
|
processProductSales(data.getJSONArray("product_list"));
|
|
|
}
|
|
|
|
|
|
return data;
|
...
|
...
|
@@ -173,6 +180,36 @@ public class ProductSearchServiceImpl implements ProductSearchService { |
|
|
}
|
|
|
}
|
|
|
|
|
|
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"));
|
|
|
}
|
|
|
List<ProductSales> salesList = productSalesMapper.selectAmountByProductIdList(productIdList);
|
|
|
Map<Integer, ProductSales> salesMap = salesList.stream()
|
|
|
.collect(Collectors.toMap(ProductSales::getProductId, Function.identity()));
|
|
|
// 遍历商品列表
|
|
|
for (int i = 0; i < productList.size(); i++) {
|
|
|
JSONObject product = productList.getJSONObject(i);
|
|
|
if (null == product) {
|
|
|
continue;
|
|
|
}
|
|
|
ProductSales sale = salesMap.get(product.getInteger("id"));
|
|
|
if (null == sale || null == sale.getAmount()) {
|
|
|
continue;
|
|
|
}
|
|
|
product.put("sales", sale.getAmount());
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@SuppressWarnings("unchecked")
|
|
|
@Override
|
|
|
public void processUserFavoriteProductList(JSONObject productJSON, Integer uid) {
|
...
|
...
|
|