|
@@ -7,7 +7,7 @@ import com.yoho.search.base.utils.ISearchConstants; |
|
@@ -7,7 +7,7 @@ import com.yoho.search.base.utils.ISearchConstants; |
7
|
import com.yoho.search.common.SearchCommonService;
|
7
|
import com.yoho.search.common.SearchCommonService;
|
8
|
import com.yoho.search.core.es.model.SearchParam;
|
8
|
import com.yoho.search.core.es.model.SearchParam;
|
9
|
import com.yoho.search.core.es.model.SearchResult;
|
9
|
import com.yoho.search.core.es.model.SearchResult;
|
10
|
-import com.yoho.search.models.VipDiscount;
|
10
|
+import com.yoho.search.models.SupplierVipDiscount;
|
11
|
import org.apache.commons.collections.CollectionUtils;
|
11
|
import org.apache.commons.collections.CollectionUtils;
|
12
|
import org.apache.commons.collections.MapUtils;
|
12
|
import org.apache.commons.collections.MapUtils;
|
13
|
import org.elasticsearch.index.query.BoolQueryBuilder;
|
13
|
import org.elasticsearch.index.query.BoolQueryBuilder;
|
|
@@ -36,16 +36,16 @@ public class ShopsBrandsIndexBaseService { |
|
@@ -36,16 +36,16 @@ public class ShopsBrandsIndexBaseService { |
36
|
private static final String SHOPS_BRANDS_SUPPLIER_CACHE_KEY = "SHOPS_BRANDS_SUPPLIER";
|
36
|
private static final String SHOPS_BRANDS_SUPPLIER_CACHE_KEY = "SHOPS_BRANDS_SUPPLIER";
|
37
|
|
37
|
|
38
|
//vipDisountCache Guava Cache
|
38
|
//vipDisountCache Guava Cache
|
39
|
- LoadingCache<String, Map<String, VipDiscount>> vipDisountCache = CacheBuilder.newBuilder()
|
39
|
+ LoadingCache<String, Map<String, SupplierVipDiscount>> vipDisountCache = CacheBuilder.newBuilder()
|
40
|
.maximumSize(100).expireAfterWrite(1, TimeUnit.MINUTES)
|
40
|
.maximumSize(100).expireAfterWrite(1, TimeUnit.MINUTES)
|
41
|
- .build(new CacheLoader<String, Map<String, VipDiscount>>() {
|
41
|
+ .build(new CacheLoader<String, Map<String, SupplierVipDiscount>>() {
|
42
|
@Override
|
42
|
@Override
|
43
|
- public Map<String, VipDiscount> load(String key) throws Exception {
|
43
|
+ public Map<String, SupplierVipDiscount> load(String key) throws Exception {
|
44
|
return buildShopBrandSupplierVipDiscountMap();
|
44
|
return buildShopBrandSupplierVipDiscountMap();
|
45
|
}
|
45
|
}
|
46
|
});
|
46
|
});
|
47
|
|
47
|
|
48
|
- private Map<String, VipDiscount> buildShopBrandSupplierVipDiscountMap() {
|
48
|
+ private Map<String, SupplierVipDiscount> buildShopBrandSupplierVipDiscountMap() {
|
49
|
SearchParam searchParam = new SearchParam();
|
49
|
SearchParam searchParam = new SearchParam();
|
50
|
BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery();
|
50
|
BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery();
|
51
|
boolQueryBuilder.must(QueryBuilders.termQuery("status", 1));
|
51
|
boolQueryBuilder.must(QueryBuilders.termQuery("status", 1));
|
|
@@ -53,7 +53,7 @@ public class ShopsBrandsIndexBaseService { |
|
@@ -53,7 +53,7 @@ public class ShopsBrandsIndexBaseService { |
53
|
searchParam.setSortBuilders(Arrays.asList(SortBuilders.fieldSort("id").order(SortOrder.DESC)));
|
53
|
searchParam.setSortBuilders(Arrays.asList(SortBuilders.fieldSort("id").order(SortOrder.DESC)));
|
54
|
searchParam.setSize(3000);
|
54
|
searchParam.setSize(3000);
|
55
|
SearchResult searchResult = searchCommonService.doSearch(ISearchConstants.INDEX_NAME_SHOPSBRANDS, searchParam);
|
55
|
SearchResult searchResult = searchCommonService.doSearch(ISearchConstants.INDEX_NAME_SHOPSBRANDS, searchParam);
|
56
|
- Map<String, VipDiscount> cacheResult = new HashMap<>();
|
56
|
+ Map<String, SupplierVipDiscount> cacheResult = new HashMap<>();
|
57
|
List<Map<String, Object>> resultList = searchResult.getResultList();
|
57
|
List<Map<String, Object>> resultList = searchResult.getResultList();
|
58
|
for (Map<String, Object> result : resultList) {
|
58
|
for (Map<String, Object> result : resultList) {
|
59
|
Integer shopId = MapUtils.getInteger(result, "shopsId", 0);
|
59
|
Integer shopId = MapUtils.getInteger(result, "shopsId", 0);
|
|
@@ -63,7 +63,7 @@ public class ShopsBrandsIndexBaseService { |
|
@@ -63,7 +63,7 @@ public class ShopsBrandsIndexBaseService { |
63
|
double vip1Discount = MapUtils.getDouble(result, "vip1Discount", 0.95);
|
63
|
double vip1Discount = MapUtils.getDouble(result, "vip1Discount", 0.95);
|
64
|
double vip2Discount = MapUtils.getDouble(result, "vip2Discount", 0.9);
|
64
|
double vip2Discount = MapUtils.getDouble(result, "vip2Discount", 0.9);
|
65
|
double vip3Discount = MapUtils.getDouble(result, "vip3Discount", 0.88);
|
65
|
double vip3Discount = MapUtils.getDouble(result, "vip3Discount", 0.88);
|
66
|
- cacheResult.put(cacheKey, new VipDiscount(vip1Discount, vip2Discount, vip3Discount));
|
66
|
+ cacheResult.put(cacheKey, new SupplierVipDiscount(vip1Discount, vip2Discount, vip3Discount));
|
67
|
}
|
67
|
}
|
68
|
return cacheResult;
|
68
|
return cacheResult;
|
69
|
}
|
69
|
}
|
|
@@ -76,12 +76,17 @@ public class ShopsBrandsIndexBaseService { |
|
@@ -76,12 +76,17 @@ public class ShopsBrandsIndexBaseService { |
76
|
return cacheKey.toString();
|
76
|
return cacheKey.toString();
|
77
|
}
|
77
|
}
|
78
|
|
78
|
|
|
|
79
|
+
|
|
|
80
|
+ /**
|
|
|
81
|
+ * 按品牌+供应商的价格填充VIP价格
|
|
|
82
|
+ * @param productReturnInfoList
|
|
|
83
|
+ */
|
79
|
public void fillVipPrice(List<Map<String, Object>> productReturnInfoList) {
|
84
|
public void fillVipPrice(List<Map<String, Object>> productReturnInfoList) {
|
80
|
try {
|
85
|
try {
|
81
|
if (CollectionUtils.isEmpty(productReturnInfoList)) {
|
86
|
if (CollectionUtils.isEmpty(productReturnInfoList)) {
|
82
|
return;
|
87
|
return;
|
83
|
}
|
88
|
}
|
84
|
- Map<String, VipDiscount> cache = vipDisountCache.get(SHOPS_BRANDS_SUPPLIER_CACHE_KEY);
|
89
|
+ Map<String, SupplierVipDiscount> cache = vipDisountCache.get(SHOPS_BRANDS_SUPPLIER_CACHE_KEY);
|
85
|
for (Map<String, Object> product : productReturnInfoList) {
|
90
|
for (Map<String, Object> product : productReturnInfoList) {
|
86
|
try {
|
91
|
try {
|
87
|
//1、判断是否需要计算vip价格
|
92
|
//1、判断是否需要计算vip价格
|
|
@@ -103,7 +108,7 @@ public class ShopsBrandsIndexBaseService { |
|
@@ -103,7 +108,7 @@ public class ShopsBrandsIndexBaseService { |
103
|
Integer brandId = MapUtils.getInteger(product, "brand_id", 0);
|
108
|
Integer brandId = MapUtils.getInteger(product, "brand_id", 0);
|
104
|
Integer supplierId = MapUtils.getInteger(product, "supplier_id", 0);
|
109
|
Integer supplierId = MapUtils.getInteger(product, "supplier_id", 0);
|
105
|
String cacheKey = this.genCacheCacheKey(shopId, brandId, supplierId);
|
110
|
String cacheKey = this.genCacheCacheKey(shopId, brandId, supplierId);
|
106
|
- VipDiscount vipDiscount = cache.get(cacheKey);
|
111
|
+ SupplierVipDiscount vipDiscount = cache.get(cacheKey);
|
107
|
if (vipDiscount == null || vipDiscount.getVip1Discount() == 0 || vipDiscount.getVip2Discount() == 0 || vipDiscount.getVip3Discount() == 0) {
|
112
|
if (vipDiscount == null || vipDiscount.getVip1Discount() == 0 || vipDiscount.getVip2Discount() == 0 || vipDiscount.getVip3Discount() == 0) {
|
108
|
continue;
|
113
|
continue;
|
109
|
}
|
114
|
}
|