...
|
...
|
@@ -7,7 +7,7 @@ import com.yoho.search.base.utils.ISearchConstants; |
|
|
import com.yoho.search.common.SearchCommonService;
|
|
|
import com.yoho.search.core.es.model.SearchParam;
|
|
|
import com.yoho.search.core.es.model.SearchResult;
|
|
|
import com.yoho.search.models.VipDiscount;
|
|
|
import com.yoho.search.models.SupplierVipDiscount;
|
|
|
import org.apache.commons.collections.CollectionUtils;
|
|
|
import org.apache.commons.collections.MapUtils;
|
|
|
import org.elasticsearch.index.query.BoolQueryBuilder;
|
...
|
...
|
@@ -36,16 +36,16 @@ public class ShopsBrandsIndexBaseService { |
|
|
private static final String SHOPS_BRANDS_SUPPLIER_CACHE_KEY = "SHOPS_BRANDS_SUPPLIER";
|
|
|
|
|
|
//vipDisountCache Guava Cache
|
|
|
LoadingCache<String, Map<String, VipDiscount>> vipDisountCache = CacheBuilder.newBuilder()
|
|
|
LoadingCache<String, Map<String, SupplierVipDiscount>> vipDisountCache = CacheBuilder.newBuilder()
|
|
|
.maximumSize(100).expireAfterWrite(1, TimeUnit.MINUTES)
|
|
|
.build(new CacheLoader<String, Map<String, VipDiscount>>() {
|
|
|
.build(new CacheLoader<String, Map<String, SupplierVipDiscount>>() {
|
|
|
@Override
|
|
|
public Map<String, VipDiscount> load(String key) throws Exception {
|
|
|
public Map<String, SupplierVipDiscount> load(String key) throws Exception {
|
|
|
return buildShopBrandSupplierVipDiscountMap();
|
|
|
}
|
|
|
});
|
|
|
|
|
|
private Map<String, VipDiscount> buildShopBrandSupplierVipDiscountMap() {
|
|
|
private Map<String, SupplierVipDiscount> buildShopBrandSupplierVipDiscountMap() {
|
|
|
SearchParam searchParam = new SearchParam();
|
|
|
BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery();
|
|
|
boolQueryBuilder.must(QueryBuilders.termQuery("status", 1));
|
...
|
...
|
@@ -53,7 +53,7 @@ public class ShopsBrandsIndexBaseService { |
|
|
searchParam.setSortBuilders(Arrays.asList(SortBuilders.fieldSort("id").order(SortOrder.DESC)));
|
|
|
searchParam.setSize(3000);
|
|
|
SearchResult searchResult = searchCommonService.doSearch(ISearchConstants.INDEX_NAME_SHOPSBRANDS, searchParam);
|
|
|
Map<String, VipDiscount> cacheResult = new HashMap<>();
|
|
|
Map<String, SupplierVipDiscount> cacheResult = new HashMap<>();
|
|
|
List<Map<String, Object>> resultList = searchResult.getResultList();
|
|
|
for (Map<String, Object> result : resultList) {
|
|
|
Integer shopId = MapUtils.getInteger(result, "shopsId", 0);
|
...
|
...
|
@@ -63,7 +63,7 @@ public class ShopsBrandsIndexBaseService { |
|
|
double vip1Discount = MapUtils.getDouble(result, "vip1Discount", 0.95);
|
|
|
double vip2Discount = MapUtils.getDouble(result, "vip2Discount", 0.9);
|
|
|
double vip3Discount = MapUtils.getDouble(result, "vip3Discount", 0.88);
|
|
|
cacheResult.put(cacheKey, new VipDiscount(vip1Discount, vip2Discount, vip3Discount));
|
|
|
cacheResult.put(cacheKey, new SupplierVipDiscount(vip1Discount, vip2Discount, vip3Discount));
|
|
|
}
|
|
|
return cacheResult;
|
|
|
}
|
...
|
...
|
@@ -76,12 +76,17 @@ public class ShopsBrandsIndexBaseService { |
|
|
return cacheKey.toString();
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 按品牌+供应商的价格填充VIP价格
|
|
|
* @param productReturnInfoList
|
|
|
*/
|
|
|
public void fillVipPrice(List<Map<String, Object>> productReturnInfoList) {
|
|
|
try {
|
|
|
if (CollectionUtils.isEmpty(productReturnInfoList)) {
|
|
|
return;
|
|
|
}
|
|
|
Map<String, VipDiscount> cache = vipDisountCache.get(SHOPS_BRANDS_SUPPLIER_CACHE_KEY);
|
|
|
Map<String, SupplierVipDiscount> cache = vipDisountCache.get(SHOPS_BRANDS_SUPPLIER_CACHE_KEY);
|
|
|
for (Map<String, Object> product : productReturnInfoList) {
|
|
|
try {
|
|
|
//1、判断是否需要计算vip价格
|
...
|
...
|
@@ -103,7 +108,7 @@ public class ShopsBrandsIndexBaseService { |
|
|
Integer brandId = MapUtils.getInteger(product, "brand_id", 0);
|
|
|
Integer supplierId = MapUtils.getInteger(product, "supplier_id", 0);
|
|
|
String cacheKey = this.genCacheCacheKey(shopId, brandId, supplierId);
|
|
|
VipDiscount vipDiscount = cache.get(cacheKey);
|
|
|
SupplierVipDiscount vipDiscount = cache.get(cacheKey);
|
|
|
if (vipDiscount == null || vipDiscount.getVip1Discount() == 0 || vipDiscount.getVip2Discount() == 0 || vipDiscount.getVip3Discount() == 0) {
|
|
|
continue;
|
|
|
}
|
...
|
...
|
|