Authored by hugufei

fix

@@ -2,13 +2,13 @@ package com.yoho.search.models; @@ -2,13 +2,13 @@ package com.yoho.search.models;
2 2
3 import java.io.Serializable; 3 import java.io.Serializable;
4 4
5 -public class VipDiscount implements Serializable { 5 +public class SupplierVipDiscount implements Serializable {
6 private static final long serialVersionUID = -6115990542999416193L; 6 private static final long serialVersionUID = -6115990542999416193L;
7 private double vip1Discount; 7 private double vip1Discount;
8 private double vip2Discount; 8 private double vip2Discount;
9 private double vip3Discount; 9 private double vip3Discount;
10 10
11 - public VipDiscount(double vip1Discount, double vip2Discount, double vip3Discount) { 11 + public SupplierVipDiscount(double vip1Discount, double vip2Discount, double vip3Discount) {
12 this.vip1Discount = vip1Discount; 12 this.vip1Discount = vip1Discount;
13 this.vip2Discount = vip2Discount; 13 this.vip2Discount = vip2Discount;
14 this.vip3Discount = vip3Discount; 14 this.vip3Discount = vip3Discount;
@@ -116,6 +116,7 @@ public class ProductListHelper { @@ -116,6 +116,7 @@ public class ProductListHelper {
116 116
117 /** 117 /**
118 * 从es返回的列表,生成返回列表 118 * 从es返回的列表,生成返回列表
  119 + * 以下方法的顺序不要乱动。
119 */ 120 */
120 public List<Map<String, Object>> buildReturnInfoByEsSourceList(List<Map<String, Object>> productEsSourceList) { 121 public List<Map<String, Object>> buildReturnInfoByEsSourceList(List<Map<String, Object>> productEsSourceList) {
121 List<Map<String, Object>> productReturnInfoList = productIndexBaseService.buildProductReturnInfoList(productEsSourceList); 122 List<Map<String, Object>> productReturnInfoList = productIndexBaseService.buildProductReturnInfoList(productEsSourceList);
@@ -36,7 +36,6 @@ public class CutpriceConfigIndexBaseService { @@ -36,7 +36,6 @@ public class CutpriceConfigIndexBaseService {
36 @Autowired 36 @Autowired
37 private SearchCommonService searchCommonService; 37 private SearchCommonService searchCommonService;
38 38
39 - private static final String PRODUCTINDEX_FIELD_POOLIDS = "pool_ids";  
40 private final Logger logger = LoggerFactory.getLogger(this.getClass()); 39 private final Logger logger = LoggerFactory.getLogger(this.getClass());
41 private static final String CACHE_KEY = "cutpriceConfigCacheKey"; 40 private static final String CACHE_KEY = "cutpriceConfigCacheKey";
42 41
@@ -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 }