Authored by hugufei

fix buildGoodsCover

@@ -35,10 +35,8 @@ public class GoodsCoverHelper { @@ -35,10 +35,8 @@ public class GoodsCoverHelper {
35 return; 35 return;
36 } 36 }
37 String imagesUrl = ""; 37 String imagesUrl = "";
38 - String imagesUrlNotNull = "";  
39 String cover1 = ""; 38 String cover1 = "";
40 String cover2 = ""; 39 String cover2 = "";
41 - boolean flag = true;  
42 for (HashMap<String, Object> goodsMap : goodsList) { 40 for (HashMap<String, Object> goodsMap : goodsList) {
43 // 如果此goods是is_default=Y的,用这个goods 41 // 如果此goods是is_default=Y的,用这个goods
44 if ("Y".equals(MapUtils.getString(goodsMap, "is_default"))) { 42 if ("Y".equals(MapUtils.getString(goodsMap, "is_default"))) {
@@ -49,19 +47,17 @@ public class GoodsCoverHelper { @@ -49,19 +47,17 @@ public class GoodsCoverHelper {
49 break; 47 break;
50 } 48 }
51 } 49 }
52 - //找一个不为空的imagesUrl  
53 - if (flag && StringUtils.isNotBlank(MapUtils.getString(goodsMap, "images_url"))) {  
54 - imagesUrlNotNull = MapUtils.getString(goodsMap, "images_url");  
55 - flag = false;  
56 - }  
57 - }  
58 - if (StringUtils.isBlank(imagesUrl)) {  
59 - imagesUrl = imagesUrlNotNull;  
60 } 50 }
61 cover1 = StringUtils.isNotBlank(cover1) ? cover1 : imagesUrl; 51 cover1 = StringUtils.isNotBlank(cover1) ? cover1 : imagesUrl;
62 cover2 = StringUtils.isNotBlank(cover2) ? cover2 : imagesUrl; 52 cover2 = StringUtils.isNotBlank(cover2) ? cover2 : imagesUrl;
63 productMap.put("cover_1", cover1); 53 productMap.put("cover_1", cover1);
64 productMap.put("cover_2", cover2); 54 productMap.put("cover_2", cover2);
  55 +
  56 + //default_images灾备
  57 + if (StringUtils.isBlank(MapUtils.getString(productMap, "default_images"))) {
  58 + String default_images = this.getImageNotNull(goodsList);
  59 + productMap.put("default_images", default_images);
  60 + }
65 } catch (Exception e) { 61 } catch (Exception e) {
66 logger.error(e.getMessage(), e); 62 logger.error(e.getMessage(), e);
67 productMap.put("cover_1", ""); 63 productMap.put("cover_1", "");
@@ -69,4 +65,22 @@ public class GoodsCoverHelper { @@ -69,4 +65,22 @@ public class GoodsCoverHelper {
69 } 65 }
70 } 66 }
71 67
  68 + private String getImageNotNull(List<HashMap<String, Object>> goodsList) {
  69 + for (HashMap<String, Object> goodsMap : goodsList) {
  70 + String imagesUrl = MapUtils.getString(goodsMap, "images_url");
  71 + if (StringUtils.isNotBlank(imagesUrl)) {
  72 + return imagesUrl;
  73 + }
  74 + String cover1 = MapUtils.getString(goodsMap, "cover_1");
  75 + if (StringUtils.isNotBlank(cover1)) {
  76 + return cover1;
  77 + }
  78 + String cover2 = MapUtils.getString(goodsMap, "cover_2");
  79 + if (StringUtils.isNotBlank(cover2)) {
  80 + return cover2;
  81 + }
  82 + }
  83 + return null;
  84 + }
  85 +
72 } 86 }
@@ -143,9 +143,9 @@ public class ProductIndexBaseService { @@ -143,9 +143,9 @@ public class ProductIndexBaseService {
143 productMap.put("is_student_rebate", MapUtils.getString(map, ProductIndexEsField.isstudentrebate, "N")); 143 productMap.put("is_student_rebate", MapUtils.getString(map, ProductIndexEsField.isstudentrebate, "N"));
144 144
145 // 把gateway逻辑抽过来,抽取cover1,cover2 145 // 把gateway逻辑抽过来,抽取cover1,cover2
146 - goodsCoverHelper.buildGoodsCover(map, productMap);  
147 - productMap.put("default_images", MapUtils.getString(map, ProductIndexEsField.defaultImages, ""));  
148 productMap.put("skn_default_img", MapUtils.getString(map, ProductIndexEsField.sknDefaultImg, "")); 146 productMap.put("skn_default_img", MapUtils.getString(map, ProductIndexEsField.sknDefaultImg, ""));
  147 + productMap.put("default_images", MapUtils.getString(map, ProductIndexEsField.defaultImages, ""));
  148 + goodsCoverHelper.buildGoodsCover(map, productMap);
149 149
150 productMap.put("edit_time", MapUtils.getIntValue(map, ProductIndexEsField.editTime)); 150 productMap.put("edit_time", MapUtils.getIntValue(map, ProductIndexEsField.editTime));
151 productMap.put("shelve_time", MapUtils.getIntValue(map, ProductIndexEsField.shelveTime)); 151 productMap.put("shelve_time", MapUtils.getIntValue(map, ProductIndexEsField.shelveTime));
@@ -104,9 +104,9 @@ public class WebProductIndexBaseService { @@ -104,9 +104,9 @@ public class WebProductIndexBaseService {
104 productMap.put("vip_discount_type", MapUtils.getIntValue(map, ProductIndexEsField.vipDiscountType, 1)); 104 productMap.put("vip_discount_type", MapUtils.getIntValue(map, ProductIndexEsField.vipDiscountType, 1));
105 105
106 // 把gateway逻辑抽过来,抽取cover1,cover2 106 // 把gateway逻辑抽过来,抽取cover1,cover2
107 - goodsCoverHelper.buildGoodsCover(map, productMap);  
108 - productMap.put("default_images", MapUtils.getString(map, ProductIndexEsField.defaultImages, ""));  
109 productMap.put("first_shelve_time", MapUtils.getIntValue(map, ProductIndexEsField.firstShelveTime)); 107 productMap.put("first_shelve_time", MapUtils.getIntValue(map, ProductIndexEsField.firstShelveTime));
  108 + productMap.put("default_images", MapUtils.getString(map, ProductIndexEsField.defaultImages, ""));
  109 + goodsCoverHelper.buildGoodsCover(map, productMap);
110 110
111 productMap.put("gender", MapUtils.getString(map, ProductIndexEsField.gender, "")); 111 productMap.put("gender", MapUtils.getString(map, ProductIndexEsField.gender, ""));
112 productMap.put("status", MapUtils.getIntValue(map, ProductIndexEsField.status, 0)); 112 productMap.put("status", MapUtils.getIntValue(map, ProductIndexEsField.status, 0));