Merge branch 'dev' of http://git.yoho.cn/ufo/yohoufo-fore into dev
Showing
16 changed files
with
263 additions
and
83 deletions
@@ -10,11 +10,20 @@ import com.yoho.core.redis.cluster.operations.serializer.RedisKeyBuilder; | @@ -10,11 +10,20 @@ import com.yoho.core.redis.cluster.operations.serializer.RedisKeyBuilder; | ||
10 | */ | 10 | */ |
11 | public enum CacheEnum { | 11 | public enum CacheEnum { |
12 | 12 | ||
13 | - | ||
14 | /** | 13 | /** |
15 | * 获取资源位接口,缓存5分钟 | 14 | * 获取资源位接口,缓存5分钟 |
16 | */ | 15 | */ |
17 | - RESOURCE_GET("yhufo:resources:resources_get", 5 * 60, "resources.cachetime.resources_get"), | 16 | + RESOURCE_GET("yh:ufo:resources:resources_get", 5 * 60, "resources.cachetime.resources_get"), |
17 | + | ||
18 | + /** | ||
19 | + * 商品系列,缓存1分钟 | ||
20 | + */ | ||
21 | + PRODUCT_SERIES_SEARCH("yh:ufo:resources:product_series_search", 1 * 60, "resources.cachetime.product_series_search"), | ||
22 | + | ||
23 | + /** | ||
24 | + * 商品品类,缓存1分钟 | ||
25 | + */ | ||
26 | + PRODUCT_CATEGORY_SEARCH("yh:ufo:resources:product_category_search", 1 * 60, "resources.cachetime.product_category_search"), | ||
18 | 27 | ||
19 | /* | 28 | /* |
20 | * end | 29 | * end |
1 | package com.yohoufo.order.common; | 1 | package com.yohoufo.order.common; |
2 | 2 | ||
3 | +import com.yohoufo.order.model.bo.ButtonShowBo; | ||
4 | + | ||
3 | public enum ButtonShow { | 5 | public enum ButtonShow { |
4 | 6 | ||
5 | CANCEL_ORDER("cancel_order","取消订单"), | 7 | CANCEL_ORDER("cancel_order","取消订单"), |
@@ -18,9 +20,15 @@ public enum ButtonShow { | @@ -18,9 +20,15 @@ public enum ButtonShow { | ||
18 | 20 | ||
19 | String code; | 21 | String code; |
20 | String value; | 22 | String value; |
23 | + private ButtonShowBo bo; | ||
21 | 24 | ||
22 | ButtonShow(String code,String value) { | 25 | ButtonShow(String code,String value) { |
23 | this.code = code; | 26 | this.code = code; |
24 | this.value = value; | 27 | this.value = value; |
28 | + bo = new ButtonShowBo(name(), code, value); | ||
29 | + } | ||
30 | + | ||
31 | + public ButtonShowBo getBo() { | ||
32 | + return bo; | ||
25 | } | 33 | } |
26 | } | 34 | } |
@@ -2,11 +2,13 @@ package com.yohoufo.order.common; | @@ -2,11 +2,13 @@ package com.yohoufo.order.common; | ||
2 | 2 | ||
3 | import com.google.common.collect.Lists; | 3 | import com.google.common.collect.Lists; |
4 | import com.yohoufo.order.constants.OrderDetailDesc; | 4 | import com.yohoufo.order.constants.OrderDetailDesc; |
5 | +import com.yohoufo.order.model.bo.ButtonShowBo; | ||
5 | 6 | ||
6 | import java.util.Arrays; | 7 | import java.util.Arrays; |
7 | import java.util.HashMap; | 8 | import java.util.HashMap; |
8 | import java.util.List; | 9 | import java.util.List; |
9 | import java.util.Map; | 10 | import java.util.Map; |
11 | +import java.util.stream.Collectors; | ||
10 | 12 | ||
11 | public enum OrderStatus { | 13 | public enum OrderStatus { |
12 | 14 | ||
@@ -212,11 +214,11 @@ public enum OrderStatus { | @@ -212,11 +214,11 @@ public enum OrderStatus { | ||
212 | return -1; | 214 | return -1; |
213 | } | 215 | } |
214 | 216 | ||
215 | - public List<ButtonShow> getListButtons(TabType actorType) { | 217 | + public List<ButtonShowBo> getListButtons(TabType actorType) { |
216 | return nodes[getIndex(actorType)].listButtons; | 218 | return nodes[getIndex(actorType)].listButtons; |
217 | } | 219 | } |
218 | 220 | ||
219 | - public List<ButtonShow> getDetailButtons(TabType actorType) { | 221 | + public List<ButtonShowBo> getDetailButtons(TabType actorType) { |
220 | return nodes[getIndex(actorType)].detailButtons; | 222 | return nodes[getIndex(actorType)].detailButtons; |
221 | } | 223 | } |
222 | 224 | ||
@@ -254,12 +256,12 @@ public enum OrderStatus { | @@ -254,12 +256,12 @@ public enum OrderStatus { | ||
254 | /** | 256 | /** |
255 | * 订单列表中的按钮 | 257 | * 订单列表中的按钮 |
256 | */ | 258 | */ |
257 | - List<ButtonShow> listButtons; | 259 | + List<ButtonShowBo> listButtons; |
258 | 260 | ||
259 | /** | 261 | /** |
260 | * 详情的按钮 | 262 | * 详情的按钮 |
261 | */ | 263 | */ |
262 | - List<ButtonShow> detailButtons; | 264 | + List<ButtonShowBo> detailButtons; |
263 | 265 | ||
264 | /** | 266 | /** |
265 | * 详情页状态说明 | 267 | * 详情页状态说明 |
@@ -271,8 +273,12 @@ public enum OrderStatus { | @@ -271,8 +273,12 @@ public enum OrderStatus { | ||
271 | List<ButtonShow> detailButtons, | 273 | List<ButtonShow> detailButtons, |
272 | String detailDesc) { | 274 | String detailDesc) { |
273 | this.statusStr = statusStr; | 275 | this.statusStr = statusStr; |
274 | - this.listButtons = listButtons; | ||
275 | - this.detailButtons = detailButtons; | 276 | + if (listButtons != null && !listButtons.isEmpty()){ |
277 | + this.listButtons = listButtons.parallelStream().map(ButtonShow::getBo).collect(Collectors.toList()); | ||
278 | + } | ||
279 | + if (detailButtons !=null && !detailButtons.isEmpty()){ | ||
280 | + this.detailButtons = detailButtons.parallelStream().map(ButtonShow::getBo).collect(Collectors.toList()); | ||
281 | + }; | ||
276 | this.detailDesc = detailDesc; | 282 | this.detailDesc = detailDesc; |
277 | } | 283 | } |
278 | } | 284 | } |
1 | package com.yohoufo.order.common; | 1 | package com.yohoufo.order.common; |
2 | 2 | ||
3 | import com.yohoufo.order.constants.OrderDetailDesc; | 3 | import com.yohoufo.order.constants.OrderDetailDesc; |
4 | +import com.yohoufo.order.model.bo.ButtonShowBo; | ||
4 | 5 | ||
5 | import java.util.Arrays; | 6 | import java.util.Arrays; |
6 | import java.util.HashMap; | 7 | import java.util.HashMap; |
@@ -17,8 +18,8 @@ public enum SkupStatus { | @@ -17,8 +18,8 @@ public enum SkupStatus { | ||
17 | */ | 18 | */ |
18 | CAN_SELL(1, "可售", | 19 | CAN_SELL(1, "可售", |
19 | new Node( | 20 | new Node( |
20 | - Arrays.asList(ButtonShow.NOT_SOLD, ButtonShow.SHOW_DETAIL), | ||
21 | - Arrays.asList(ButtonShow.NOT_SOLD), | 21 | + Arrays.asList(ButtonShow.NOT_SOLD.getBo(), ButtonShow.SHOW_DETAIL.getBo()), |
22 | + Arrays.asList(ButtonShow.NOT_SOLD.getBo()), | ||
22 | OrderDetailDesc.Seller.PAY_FINISH | 23 | OrderDetailDesc.Seller.PAY_FINISH |
23 | ) | 24 | ) |
24 | ), | 25 | ), |
@@ -27,37 +28,37 @@ public enum SkupStatus { | @@ -27,37 +28,37 @@ public enum SkupStatus { | ||
27 | */ | 28 | */ |
28 | CAN_NOT_SELL(0,"待付保证金", | 29 | CAN_NOT_SELL(0,"待付保证金", |
29 | new Node( | 30 | new Node( |
30 | - Arrays.asList(ButtonShow.NOT_SOLD, ButtonShow.PAY_EARNESTMONEY), | ||
31 | - Arrays.asList(ButtonShow.NOT_SOLD, ButtonShow.PAY_EARNESTMONEY), | 31 | + Arrays.asList(ButtonShow.NOT_SOLD.getBo(), ButtonShow.PAY_EARNESTMONEY.getBo()), |
32 | + Arrays.asList(ButtonShow.NOT_SOLD.getBo(), ButtonShow.PAY_EARNESTMONEY.getBo()), | ||
32 | OrderDetailDesc.Seller.WAIT_PAY | 33 | OrderDetailDesc.Seller.WAIT_PAY |
33 | ) | 34 | ) |
34 | ), | 35 | ), |
35 | 36 | ||
36 | SELF_CANCEL_PAY(20, "上架关闭(卖家取消支付)", | 37 | SELF_CANCEL_PAY(20, "上架关闭(卖家取消支付)", |
37 | new Node( | 38 | new Node( |
38 | - Arrays.asList(ButtonShow.SOLD_AGAIN, ButtonShow.DEL_ORDER, ButtonShow.SHOW_DETAIL), | ||
39 | - Arrays.asList(ButtonShow.DEL_ORDER, ButtonShow.SOLD_AGAIN), | 39 | + Arrays.asList(ButtonShow.SOLD_AGAIN.getBo(), ButtonShow.DEL_ORDER.getBo(), ButtonShow.SHOW_DETAIL.getBo()), |
40 | + Arrays.asList(ButtonShow.DEL_ORDER.getBo(), ButtonShow.SOLD_AGAIN.getBo()), | ||
40 | OrderDetailDesc.Seller.SELF_CANCEL_BEFORE_PAY | 41 | OrderDetailDesc.Seller.SELF_CANCEL_BEFORE_PAY |
41 | ) | 42 | ) |
42 | ), | 43 | ), |
43 | TIMEOUT_CANCEL(21, "上架关闭(卖家支付超时)", | 44 | TIMEOUT_CANCEL(21, "上架关闭(卖家支付超时)", |
44 | new Node( | 45 | new Node( |
45 | - Arrays.asList(ButtonShow.SOLD_AGAIN, ButtonShow.DEL_ORDER, ButtonShow.SHOW_DETAIL), | ||
46 | - Arrays.asList(ButtonShow.DEL_ORDER, ButtonShow.SOLD_AGAIN), | 46 | + Arrays.asList(ButtonShow.SOLD_AGAIN.getBo(), ButtonShow.DEL_ORDER.getBo(), ButtonShow.SHOW_DETAIL.getBo()), |
47 | + Arrays.asList(ButtonShow.DEL_ORDER.getBo(), ButtonShow.SOLD_AGAIN.getBo()), | ||
47 | OrderDetailDesc.Seller.TIME_OUT_CANCEL | 48 | OrderDetailDesc.Seller.TIME_OUT_CANCEL |
48 | ) | 49 | ) |
49 | ), | 50 | ), |
50 | SELLER_CANCEL_SELL(22, "上架关闭(卖家取消出售)", | 51 | SELLER_CANCEL_SELL(22, "上架关闭(卖家取消出售)", |
51 | new Node( | 52 | new Node( |
52 | - Arrays.asList(ButtonShow.SOLD_AGAIN, ButtonShow.DEL_ORDER, ButtonShow.SHOW_DETAIL), | ||
53 | - Arrays.asList(ButtonShow.DEL_ORDER, ButtonShow.SOLD_AGAIN), | 53 | + Arrays.asList(ButtonShow.SOLD_AGAIN.getBo(), ButtonShow.DEL_ORDER.getBo(), ButtonShow.SHOW_DETAIL.getBo()), |
54 | + Arrays.asList(ButtonShow.DEL_ORDER.getBo(), ButtonShow.SOLD_AGAIN.getBo()), | ||
54 | OrderDetailDesc.Seller.SELF_CANCEL_BEFORE_EXIST_BUY | 55 | OrderDetailDesc.Seller.SELF_CANCEL_BEFORE_EXIST_BUY |
55 | ) | 56 | ) |
56 | ), | 57 | ), |
57 | YOHO_CANCEL_SELL(23, "上架关闭(平台取消出售)", | 58 | YOHO_CANCEL_SELL(23, "上架关闭(平台取消出售)", |
58 | new Node( | 59 | new Node( |
59 | - Arrays.asList(ButtonShow.SOLD_AGAIN, ButtonShow.DEL_ORDER, ButtonShow.SHOW_DETAIL), | ||
60 | - Arrays.asList(ButtonShow.DEL_ORDER, ButtonShow.SOLD_AGAIN), | 60 | + Arrays.asList(ButtonShow.SOLD_AGAIN.getBo(), ButtonShow.DEL_ORDER.getBo(), ButtonShow.SHOW_DETAIL.getBo()), |
61 | + Arrays.asList(ButtonShow.DEL_ORDER.getBo(), ButtonShow.SOLD_AGAIN.getBo()), | ||
61 | OrderDetailDesc.Seller.YOHO_CANCEL_BEFORE_EXIST_BUY | 62 | OrderDetailDesc.Seller.YOHO_CANCEL_BEFORE_EXIST_BUY |
62 | ) | 63 | ) |
63 | ) | 64 | ) |
@@ -77,13 +78,13 @@ public enum SkupStatus { | @@ -77,13 +78,13 @@ public enum SkupStatus { | ||
77 | 78 | ||
78 | static class Node{ | 79 | static class Node{ |
79 | 80 | ||
80 | - List<ButtonShow> listButtons; | 81 | + List<ButtonShowBo> listButtons; |
81 | 82 | ||
82 | - List<ButtonShow> detailButtons; | 83 | + List<ButtonShowBo> detailButtons; |
83 | 84 | ||
84 | String detailShowDesc; | 85 | String detailShowDesc; |
85 | 86 | ||
86 | - public Node(List<ButtonShow> listButtons, List<ButtonShow> detailButtons, String desc) { | 87 | + public Node(List<ButtonShowBo> listButtons, List<ButtonShowBo> detailButtons, String desc) { |
87 | this.listButtons = listButtons; | 88 | this.listButtons = listButtons; |
88 | this.detailButtons = detailButtons; | 89 | this.detailButtons = detailButtons; |
89 | this.detailShowDesc = desc; | 90 | this.detailShowDesc = desc; |
@@ -108,15 +109,19 @@ public enum SkupStatus { | @@ -108,15 +109,19 @@ public enum SkupStatus { | ||
108 | } | 109 | } |
109 | 110 | ||
110 | 111 | ||
111 | - public List<ButtonShow> getListButtons() { | 112 | + public List<ButtonShowBo> getListButtons() { |
112 | return node.listButtons; | 113 | return node.listButtons; |
113 | } | 114 | } |
114 | 115 | ||
115 | - public List<ButtonShow> getDetailButtons() { | 116 | + public List<ButtonShowBo> getDetailButtons() { |
116 | return node.detailButtons; | 117 | return node.detailButtons; |
117 | } | 118 | } |
118 | 119 | ||
119 | public String getDetailShowDesc() { | 120 | public String getDetailShowDesc() { |
120 | return node.detailShowDesc; | 121 | return node.detailShowDesc; |
121 | } | 122 | } |
123 | + | ||
124 | + public String getDesc() { | ||
125 | + return desc; | ||
126 | + } | ||
122 | } | 127 | } |
1 | +package com.yohoufo.order.model.bo; | ||
2 | + | ||
3 | +import lombok.AllArgsConstructor; | ||
4 | +import lombok.Data; | ||
5 | +import lombok.NoArgsConstructor; | ||
6 | + | ||
7 | +/** | ||
8 | + * Created by chenchao on 2018/9/20. | ||
9 | + */ | ||
10 | +@Data | ||
11 | +@NoArgsConstructor | ||
12 | +@AllArgsConstructor | ||
13 | +public class ButtonShowBo { | ||
14 | + | ||
15 | + String name; | ||
16 | + String code; | ||
17 | + String text; | ||
18 | + | ||
19 | + | ||
20 | +} |
@@ -5,6 +5,7 @@ import com.yoho.service.model.response.UserAddressRspBO; | @@ -5,6 +5,7 @@ import com.yoho.service.model.response.UserAddressRspBO; | ||
5 | import com.yohobuy.ufo.model.order.bo.PlatformFee; | 5 | import com.yohobuy.ufo.model.order.bo.PlatformFee; |
6 | import com.yohoufo.order.common.ButtonShow; | 6 | import com.yohoufo.order.common.ButtonShow; |
7 | import com.yohoufo.order.model.AddressInfo; | 7 | import com.yohoufo.order.model.AddressInfo; |
8 | +import com.yohoufo.order.model.bo.ButtonShowBo; | ||
8 | import lombok.Data; | 9 | import lombok.Data; |
9 | import lombok.experimental.Builder; | 10 | import lombok.experimental.Builder; |
10 | 11 | ||
@@ -42,7 +43,7 @@ public class OrderDetailInfo { | @@ -42,7 +43,7 @@ public class OrderDetailInfo { | ||
42 | /** | 43 | /** |
43 | * 按钮显示 | 44 | * 按钮显示 |
44 | */ | 45 | */ |
45 | - List<ButtonShow> buttons; | 46 | + List<ButtonShowBo> buttons; |
46 | 47 | ||
47 | 48 | ||
48 | int payment; | 49 | int payment; |
1 | package com.yohoufo.order.model.response; | 1 | package com.yohoufo.order.model.response; |
2 | 2 | ||
3 | import com.yohoufo.order.common.ButtonShow; | 3 | import com.yohoufo.order.common.ButtonShow; |
4 | +import com.yohoufo.order.model.bo.ButtonShowBo; | ||
4 | import lombok.Data; | 5 | import lombok.Data; |
5 | 6 | ||
6 | import java.util.List; | 7 | import java.util.List; |
@@ -38,5 +39,5 @@ public class OrderListInfo { | @@ -38,5 +39,5 @@ public class OrderListInfo { | ||
38 | /** | 39 | /** |
39 | * 按钮显示 | 40 | * 按钮显示 |
40 | */ | 41 | */ |
41 | - List<ButtonShow> buttons; | 42 | + List<ButtonShowBo> buttons; |
42 | } | 43 | } |
@@ -98,7 +98,7 @@ public class SellerOrderListService extends AbsOrderListService implements IOrde | @@ -98,7 +98,7 @@ public class SellerOrderListService extends AbsOrderListService implements IOrde | ||
98 | return null; | 98 | return null; |
99 | } | 99 | } |
100 | 100 | ||
101 | - orderListInfo.setStatuStr(orderStatus.getDetailShowDesc()); | 101 | + orderListInfo.setStatuStr(orderStatus.getDesc()); |
102 | 102 | ||
103 | // 按钮显示 | 103 | // 按钮显示 |
104 | orderListInfo.setButtons(orderStatus.getListButtons()); | 104 | orderListInfo.setButtons(orderStatus.getListButtons()); |
@@ -116,6 +116,7 @@ public class SellerOrderListService extends AbsOrderListService implements IOrde | @@ -116,6 +116,7 @@ public class SellerOrderListService extends AbsOrderListService implements IOrde | ||
116 | goodsInfo.setProductName(sellerOrderGoods.getProductName()); | 116 | goodsInfo.setProductName(sellerOrderGoods.getProductName()); |
117 | goodsInfo.setGoodImg(sellerOrderGoods.getImageUrl()); | 117 | goodsInfo.setGoodImg(sellerOrderGoods.getImageUrl()); |
118 | goodsInfo.setSizeName(sellerOrderGoods.getSizeName()); | 118 | goodsInfo.setSizeName(sellerOrderGoods.getSizeName()); |
119 | + | ||
119 | goodsInfo.setGoodPrice(sellerOrderGoods.getGoodsPrice().toPlainString()); | 120 | goodsInfo.setGoodPrice(sellerOrderGoods.getGoodsPrice().toPlainString()); |
120 | 121 | ||
121 | orderListInfo.setGoodsInfo(goodsInfo); | 122 | orderListInfo.setGoodsInfo(goodsInfo); |
1 | +package com.yohoufo.resource.service; | ||
2 | + | ||
3 | +import com.alibaba.fastjson.JSONArray; | ||
4 | +import com.alibaba.fastjson.JSONObject; | ||
5 | + | ||
6 | +/** | ||
7 | + * Created by yoho on 2015/11/25. | ||
8 | + */ | ||
9 | +public interface IProductQueryService { | ||
10 | + | ||
11 | + JSONArray searchSeries(String params); | ||
12 | + | ||
13 | + JSONObject searchCategory(String params); | ||
14 | + | ||
15 | +} |
1 | +package com.yohoufo.resource.service.impl; | ||
2 | + | ||
3 | +import org.slf4j.Logger; | ||
4 | +import org.slf4j.LoggerFactory; | ||
5 | +import org.springframework.beans.factory.annotation.Autowired; | ||
6 | +import org.springframework.stereotype.Service; | ||
7 | + | ||
8 | +import com.alibaba.fastjson.JSONArray; | ||
9 | +import com.alibaba.fastjson.JSONObject; | ||
10 | +import com.yoho.core.redis.cluster.operations.serializer.RedisKeyBuilder; | ||
11 | +import com.yohoufo.common.ApiResponse; | ||
12 | +import com.yohoufo.common.cache.CacheEnum; | ||
13 | +import com.yohoufo.common.caller.UfoServiceCaller; | ||
14 | +import com.yohoufo.common.redis.NoSyncGracefulRedisTemplate; | ||
15 | +import com.yohoufo.resource.service.IProductQueryService; | ||
16 | + | ||
17 | + | ||
18 | +@Service | ||
19 | +public class ProductQueryServiceImpl implements IProductQueryService { | ||
20 | + | ||
21 | + private static Logger logger = LoggerFactory.getLogger(ProductQueryServiceImpl.class); | ||
22 | + | ||
23 | + @javax.annotation.Resource(name="NoSyncGracefulRedisTemplate") | ||
24 | + private NoSyncGracefulRedisTemplate resourcesRedisCache; | ||
25 | + | ||
26 | + public static final String CATEGORY_METHOD = "ufo.product.sort.template"; | ||
27 | + | ||
28 | + public static final String SERIES_METHOD = "ufo.product.series.template"; | ||
29 | + | ||
30 | + @Autowired | ||
31 | + private UfoServiceCaller ufoServiceCaller; | ||
32 | + | ||
33 | + public JSONArray searchSeries(String params) { | ||
34 | + | ||
35 | + RedisKeyBuilder cacheKey = CacheEnum.PRODUCT_SERIES_SEARCH.generateKey(params); | ||
36 | + JSONArray data = resourcesRedisCache.get(cacheKey, JSONArray.class); | ||
37 | + if (data == null) { | ||
38 | + logger.info("begin invoke ufo.product.series.template, param is:{}", params); | ||
39 | + ApiResponse apiResponse = ufoServiceCaller.call(SERIES_METHOD, ApiResponse.class, params); | ||
40 | + if (null != apiResponse && apiResponse.getCode() == 200) { | ||
41 | + JSONObject productSeriesJSON = (JSONObject) apiResponse.getData(); | ||
42 | + if (null != productSeriesJSON && null != productSeriesJSON.get("list")) { | ||
43 | + data = productSeriesJSON.getJSONArray("list"); | ||
44 | + } | ||
45 | + } | ||
46 | + //获得BackupKey | ||
47 | + RedisKeyBuilder cacheBackupKey = CacheEnum.PRODUCT_SERIES_SEARCH.generateBackupKey(params); | ||
48 | + if (data == null) { | ||
49 | + logger.info("Series search, find Series by {} from backup redis.", cacheKey); | ||
50 | + JSONArray backupData = resourcesRedisCache.get(cacheBackupKey, JSONArray.class); | ||
51 | + if (backupData == null) { | ||
52 | + logger.info("Series search, can not find Series by {} from backup redis.", cacheKey); | ||
53 | + return new JSONArray(); | ||
54 | + } else { | ||
55 | + logger.info("Series search, find Series by {} from backup redis success.", cacheKey); | ||
56 | + return backupData; | ||
57 | + } | ||
58 | + }else { | ||
59 | + logger.info("Series search, search Series by {} success.", cacheKey); | ||
60 | + resourcesRedisCache.setEx(cacheKey, data, CacheEnum.PRODUCT_SERIES_SEARCH.getCacheTime()); | ||
61 | + resourcesRedisCache.setEx(cacheBackupKey, data, CacheEnum.PRODUCT_SERIES_SEARCH.getBackupCacheTime()); | ||
62 | + return data; | ||
63 | + } | ||
64 | + }else { | ||
65 | + logger.info("Series search, find Series by {} from redis success.", cacheKey); | ||
66 | + return data; | ||
67 | + } | ||
68 | + } | ||
69 | + | ||
70 | + /** | ||
71 | + * 查询品类 | ||
72 | + * | ||
73 | + * @see com.yohoufo.resource.service.IProductQueryService#searchCategory(java.lang.String) | ||
74 | + * @author: 胡子成 - ken.hu@yoho.cn | ||
75 | + * @date: Created on 2018年9月20日 下午6:27:23 | ||
76 | + */ | ||
77 | + @Override | ||
78 | + public JSONObject searchCategory(String params) { | ||
79 | + | ||
80 | + RedisKeyBuilder cacheKey = CacheEnum.PRODUCT_CATEGORY_SEARCH.generateKey(params); | ||
81 | + JSONObject data = resourcesRedisCache.get(cacheKey, JSONObject.class); | ||
82 | + if (data == null) { | ||
83 | + logger.info("begin invoke ufo.product.sort.template, param is:{}", params); | ||
84 | + ApiResponse apiResponse = ufoServiceCaller.call(CATEGORY_METHOD, ApiResponse.class, params); | ||
85 | + if (null != apiResponse && apiResponse.getCode() == 200) { | ||
86 | + JSONObject productCategoryJSON = (JSONObject) apiResponse.getData(); | ||
87 | + if (null != productCategoryJSON) { | ||
88 | + data = productCategoryJSON; | ||
89 | + } | ||
90 | + } | ||
91 | + //获得BackupKey | ||
92 | + RedisKeyBuilder cacheBackupKey = CacheEnum.PRODUCT_CATEGORY_SEARCH.generateBackupKey(params); | ||
93 | + if (data == null) { | ||
94 | + logger.info("Category search, find Category by {} from backup redis.", cacheKey); | ||
95 | + JSONObject backupData = resourcesRedisCache.get(cacheBackupKey, JSONObject.class); | ||
96 | + if (backupData == null) { | ||
97 | + logger.info("Category search, can not find Category by {} from backup redis.", cacheKey); | ||
98 | + return new JSONObject(); | ||
99 | + } else { | ||
100 | + logger.info("Category search, find Category by {} from backup redis success.", cacheKey); | ||
101 | + return backupData; | ||
102 | + } | ||
103 | + }else { | ||
104 | + logger.info("Category search, search Category by {} success.", cacheKey); | ||
105 | + resourcesRedisCache.setEx(cacheKey, data, CacheEnum.PRODUCT_CATEGORY_SEARCH.getCacheTime()); | ||
106 | + resourcesRedisCache.setEx(cacheBackupKey, data, CacheEnum.PRODUCT_CATEGORY_SEARCH.getBackupCacheTime()); | ||
107 | + return data; | ||
108 | + } | ||
109 | + }else { | ||
110 | + logger.info("Category search, find Category by {} from redis success.", cacheKey); | ||
111 | + return data; | ||
112 | + } | ||
113 | + } | ||
114 | +} |
1 | package com.yohoufo.resource.service.impl.resource; | 1 | package com.yohoufo.resource.service.impl.resource; |
2 | 2 | ||
3 | import java.io.Serializable; | 3 | import java.io.Serializable; |
4 | -import java.util.List; | ||
5 | 4 | ||
6 | -import org.apache.commons.collections.CollectionUtils; | ||
7 | import org.apache.commons.lang3.StringUtils; | 5 | import org.apache.commons.lang3.StringUtils; |
8 | import org.slf4j.Logger; | 6 | import org.slf4j.Logger; |
9 | import org.slf4j.LoggerFactory; | 7 | import org.slf4j.LoggerFactory; |
@@ -12,11 +10,8 @@ import org.springframework.stereotype.Service; | @@ -12,11 +10,8 @@ import org.springframework.stereotype.Service; | ||
12 | 10 | ||
13 | import com.alibaba.fastjson.JSONArray; | 11 | import com.alibaba.fastjson.JSONArray; |
14 | import com.alibaba.fastjson.JSONObject; | 12 | import com.alibaba.fastjson.JSONObject; |
15 | -import com.yohoufo.common.ApiResponse; | ||
16 | -import com.yohoufo.common.caller.UfoServiceCaller; | ||
17 | -import com.yohoufo.product.model.ProductSortTemplate; | ||
18 | -import com.yohoufo.product.response.ProductSortTemplateResp; | ||
19 | import com.yohoufo.resource.helper.MakeUrlService; | 13 | import com.yohoufo.resource.helper.MakeUrlService; |
14 | +import com.yohoufo.resource.service.IProductQueryService; | ||
20 | import com.yohoufo.resource.service.IResourceParse; | 15 | import com.yohoufo.resource.service.IResourceParse; |
21 | import com.yohoufo.resource.service.Resource; | 16 | import com.yohoufo.resource.service.Resource; |
22 | 17 | ||
@@ -34,7 +29,7 @@ public class CategoryResourceParse implements IResourceParse { | @@ -34,7 +29,7 @@ public class CategoryResourceParse implements IResourceParse { | ||
34 | private MakeUrlService makeUrlService; | 29 | private MakeUrlService makeUrlService; |
35 | 30 | ||
36 | @Autowired | 31 | @Autowired |
37 | - private UfoServiceCaller ufoServiceCaller; | 32 | + private IProductQueryService productQueryService; |
38 | 33 | ||
39 | @Override | 34 | @Override |
40 | public Serializable parse(Resource resource) { | 35 | public Serializable parse(Resource resource) { |
@@ -75,13 +70,7 @@ public class CategoryResourceParse implements IResourceParse { | @@ -75,13 +70,7 @@ public class CategoryResourceParse implements IResourceParse { | ||
75 | categoryJSON.put("more_url", makeUrl(jsonMoreUrl, resource.getClientType())); | 70 | categoryJSON.put("more_url", makeUrl(jsonMoreUrl, resource.getClientType())); |
76 | // 调用品类接口 | 71 | // 调用品类接口 |
77 | if (StringUtils.isNotBlank(productIds)) { | 72 | if (StringUtils.isNotBlank(productIds)) { |
78 | - ApiResponse apiResponse = ufoServiceCaller.call("ufo.product.sort.template", ApiResponse.class, productIds); | ||
79 | - if (null != apiResponse && apiResponse.getCode() == 200) { | ||
80 | - JSONObject productSortJSON = (JSONObject) apiResponse.getData(); | ||
81 | - if (null != productSortJSON ) { | ||
82 | - categoryJSON.putAll(productSortJSON); | ||
83 | - } | ||
84 | - } | 73 | + categoryJSON.putAll(productQueryService.searchCategory(productIds)); |
85 | } | 74 | } |
86 | returnArray.add(categoryJSON); | 75 | returnArray.add(categoryJSON); |
87 | } | 76 | } |
1 | package com.yohoufo.resource.service.impl.resource; | 1 | package com.yohoufo.resource.service.impl.resource; |
2 | 2 | ||
3 | import java.io.Serializable; | 3 | import java.io.Serializable; |
4 | -import java.util.List; | ||
5 | 4 | ||
6 | -import org.apache.commons.collections.CollectionUtils; | ||
7 | import org.apache.commons.lang3.StringUtils; | 5 | import org.apache.commons.lang3.StringUtils; |
8 | import org.slf4j.Logger; | 6 | import org.slf4j.Logger; |
9 | import org.slf4j.LoggerFactory; | 7 | import org.slf4j.LoggerFactory; |
10 | import org.springframework.beans.factory.annotation.Autowired; | 8 | import org.springframework.beans.factory.annotation.Autowired; |
11 | import org.springframework.stereotype.Service; | 9 | import org.springframework.stereotype.Service; |
12 | 10 | ||
13 | -import com.alibaba.fastjson.JSONArray; | ||
14 | import com.alibaba.fastjson.JSONObject; | 11 | import com.alibaba.fastjson.JSONObject; |
15 | -import com.yohoufo.common.ApiResponse; | ||
16 | -import com.yohoufo.common.caller.UfoServiceCaller; | ||
17 | -import com.yohoufo.product.model.ProductSeriesTemplate; | ||
18 | -import com.yohoufo.product.response.ProductSeriesTemplateResp; | 12 | +import com.yohoufo.resource.service.IProductQueryService; |
19 | import com.yohoufo.resource.service.IResourceParse; | 13 | import com.yohoufo.resource.service.IResourceParse; |
20 | import com.yohoufo.resource.service.Resource; | 14 | import com.yohoufo.resource.service.Resource; |
21 | 15 | ||
@@ -30,7 +24,7 @@ public class HotSeriesResourceParse implements IResourceParse { | @@ -30,7 +24,7 @@ public class HotSeriesResourceParse implements IResourceParse { | ||
30 | public static final String TEMPLATE_NAME = "hotSeries"; | 24 | public static final String TEMPLATE_NAME = "hotSeries"; |
31 | 25 | ||
32 | @Autowired | 26 | @Autowired |
33 | - private UfoServiceCaller ufoServiceCaller; | 27 | + private IProductQueryService productQueryService; |
34 | 28 | ||
35 | @Override | 29 | @Override |
36 | public Serializable parse(Resource resource) { | 30 | public Serializable parse(Resource resource) { |
@@ -54,14 +48,7 @@ public class HotSeriesResourceParse implements IResourceParse { | @@ -54,14 +48,7 @@ public class HotSeriesResourceParse implements IResourceParse { | ||
54 | if (StringUtils.isBlank(productIds)) { | 48 | if (StringUtils.isBlank(productIds)) { |
55 | return returnJSON; | 49 | return returnJSON; |
56 | } | 50 | } |
57 | - // 调用系列接口 | ||
58 | - ApiResponse apiResponse = ufoServiceCaller.call("ufo.product.series.template", ApiResponse.class, productIds); | ||
59 | - if (null != apiResponse && apiResponse.getCode() == 200) { | ||
60 | - JSONObject productSeriesJSON = (JSONObject) apiResponse.getData(); | ||
61 | - if (null != productSeriesJSON && null != productSeriesJSON.get("list")) { | ||
62 | - returnJSON.put("data", productSeriesJSON.get("list")); | ||
63 | - } | ||
64 | - } | 51 | + returnJSON.put("data",productQueryService.searchSeries(productIds)); |
65 | return returnJSON; | 52 | return returnJSON; |
66 | } | 53 | } |
67 | } | 54 | } |
@@ -2,6 +2,7 @@ package com.yohoufo.user.controller.favorite; | @@ -2,6 +2,7 @@ package com.yohoufo.user.controller.favorite; | ||
2 | 2 | ||
3 | import com.yoho.error.exception.ServiceException; | 3 | import com.yoho.error.exception.ServiceException; |
4 | import com.yoho.tools.common.beans.ApiResponse; | 4 | import com.yoho.tools.common.beans.ApiResponse; |
5 | +import com.yohoufo.common.caller.UfoServiceCaller; | ||
5 | import com.yohoufo.user.requestVO.FavoriteRequestVO; | 6 | import com.yohoufo.user.requestVO.FavoriteRequestVO; |
6 | import com.yohoufo.user.service.IFavoriteService; | 7 | import com.yohoufo.user.service.IFavoriteService; |
7 | import org.slf4j.Logger; | 8 | import org.slf4j.Logger; |
@@ -29,6 +30,33 @@ public class FavoriteController { | @@ -29,6 +30,33 @@ public class FavoriteController { | ||
29 | @Autowired | 30 | @Autowired |
30 | private IFavoriteService favoriteService; | 31 | private IFavoriteService favoriteService; |
31 | 32 | ||
33 | + @Autowired | ||
34 | + private UfoServiceCaller serviceCaller; | ||
35 | + | ||
36 | + /** | ||
37 | + * 用户收藏list | ||
38 | + * @param vo | ||
39 | + * @return | ||
40 | + * @throws ServiceException | ||
41 | + */ | ||
42 | + @RequestMapping(params = "method=ufo.user.favoriteList") | ||
43 | + public ApiResponse listFavorite(FavoriteRequestVO vo) throws ServiceException { | ||
44 | + logger.info("Begin call ufo.user.favoriteList with param is {}", vo); | ||
45 | + validateRequest(vo,false); | ||
46 | + | ||
47 | + if (vo.getLimit()>20) { | ||
48 | + logger.warn("request page limit can not big than 20"); | ||
49 | + vo.setLimit(20); | ||
50 | + } | ||
51 | + | ||
52 | + //分页获取收藏的商品id, | ||
53 | + List<String> productIds= favoriteService.listFavorite(vo); | ||
54 | + //调用商品接口返回商品list | ||
55 | + ApiResponse productApiResponse = serviceCaller.call("ufo.product.batch.data", | ||
56 | + ApiResponse.class, productIds); | ||
57 | + return productApiResponse; | ||
58 | + } | ||
59 | + | ||
32 | /** | 60 | /** |
33 | * 用户收藏商品数量num | 61 | * 用户收藏商品数量num |
34 | * @param vo | 62 | * @param vo |
@@ -90,22 +118,6 @@ public class FavoriteController { | @@ -90,22 +118,6 @@ public class FavoriteController { | ||
90 | return new ApiResponse.ApiResponseBuilder().message(CANCEL_FAVORITE_SUCCESS).data(null).build(); | 118 | return new ApiResponse.ApiResponseBuilder().message(CANCEL_FAVORITE_SUCCESS).data(null).build(); |
91 | } | 119 | } |
92 | 120 | ||
93 | - /** | ||
94 | - * 用户收藏list | ||
95 | - * @param vo | ||
96 | - * @return | ||
97 | - * @throws ServiceException | ||
98 | - */ | ||
99 | - @RequestMapping(params = "method=ufo.user.favoriteList") | ||
100 | - public ApiResponse listFavorite(FavoriteRequestVO vo) throws ServiceException { | ||
101 | - logger.info("Begin call ufo.user.favoriteList with param is {}", vo); | ||
102 | - validateRequest(vo,false); | ||
103 | - List<String> productIds= favoriteService.listFavorite(vo); | ||
104 | - //组织商品信息返回 | ||
105 | - return null; | ||
106 | - } | ||
107 | - | ||
108 | - | ||
109 | private void validateRequest(FavoriteRequestVO vo,boolean checkProduct) { | 121 | private void validateRequest(FavoriteRequestVO vo,boolean checkProduct) { |
110 | if (null == vo) { | 122 | if (null == vo) { |
111 | logger.warn("validateRequest params is null"); | 123 | logger.warn("validateRequest params is null"); |
1 | package com.yohoufo.user.requestVO; | 1 | package com.yohoufo.user.requestVO; |
2 | 2 | ||
3 | -import com.yohoufo.user.common.BaseVO; | ||
4 | import lombok.Data; | 3 | import lombok.Data; |
5 | 4 | ||
5 | +/** | ||
6 | + * 分页获取 | ||
7 | + */ | ||
6 | @Data | 8 | @Data |
7 | -public class FavoriteRequestVO extends BaseVO { | 9 | +public class FavoriteRequestVO extends PageReqVO { |
8 | private Integer uid; | 10 | private Integer uid; |
9 | //商品skn 单款 | 11 | //商品skn 单款 |
10 | private Integer productId; | 12 | private Integer productId; |
@@ -70,8 +70,10 @@ public class FavoriteServiceImpl implements IFavoriteService { | @@ -70,8 +70,10 @@ public class FavoriteServiceImpl implements IFavoriteService { | ||
70 | public List<String> listFavorite(FavoriteRequestVO vo){ | 70 | public List<String> listFavorite(FavoriteRequestVO vo){ |
71 | List<String> favoriteProducts = new ArrayList<>(); | 71 | List<String> favoriteProducts = new ArrayList<>(); |
72 | int uid = vo.getUid(); | 72 | int uid = vo.getUid(); |
73 | + int startIndex=vo.getLimit()*(vo.getPage()-1); | ||
74 | + int endIndex=vo.getLimit()*vo.getPage(); | ||
73 | // 查询缓存 | 75 | // 查询缓存 |
74 | - Set<String> favoriteProductIds = cacheService.queryAllProductFavoriteByUid(uid, 0, -1); | 76 | + Set<String> favoriteProductIds = cacheService.queryAllProductFavoriteByUid(uid, startIndex, endIndex-1); |
75 | if(CollectionUtils.isNotEmpty(favoriteProductIds)){ | 77 | if(CollectionUtils.isNotEmpty(favoriteProductIds)){ |
76 | favoriteProductIds.remove("0"); | 78 | favoriteProductIds.remove("0"); |
77 | favoriteProducts.addAll(favoriteProductIds); | 79 | favoriteProducts.addAll(favoriteProductIds); |
@@ -80,8 +82,11 @@ public class FavoriteServiceImpl implements IFavoriteService { | @@ -80,8 +82,11 @@ public class FavoriteServiceImpl implements IFavoriteService { | ||
80 | 82 | ||
81 | List<UserFavorite> favoriteList = userFavoriteDao.selectValidFavoriteByUid(getTableIndex(uid), uid); | 83 | List<UserFavorite> favoriteList = userFavoriteDao.selectValidFavoriteByUid(getTableIndex(uid), uid); |
82 | cacheService.batchSetFavoriteProduct(uid, favoriteList); | 84 | cacheService.batchSetFavoriteProduct(uid, favoriteList); |
85 | + int count=0; | ||
83 | for (UserFavorite favorite : favoriteList) { | 86 | for (UserFavorite favorite : favoriteList) { |
84 | - favoriteProducts.add(String.valueOf(favorite.getProductId())); | 87 | + if(count>=startIndex && count<endIndex){ |
88 | + favoriteProducts.add(String.valueOf(favorite.getProductId())); | ||
89 | + } | ||
85 | } | 90 | } |
86 | return favoriteProducts; | 91 | return favoriteProducts; |
87 | } | 92 | } |
@@ -47,12 +47,17 @@ | @@ -47,12 +47,17 @@ | ||
47 | <!-- json转换器 application/json --> | 47 | <!-- json转换器 application/json --> |
48 | <bean id="jsonConverter" class="com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter"> | 48 | <bean id="jsonConverter" class="com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter"> |
49 | <property name="supportedMediaTypes" value="application/json;charset=UTF-8"/> | 49 | <property name="supportedMediaTypes" value="application/json;charset=UTF-8"/> |
50 | - <property name="features"> | ||
51 | - <array value-type="com.alibaba.fastjson.serializer.SerializerFeature"> | ||
52 | - <value>DisableCircularReferenceDetect</value> | ||
53 | - </array> | ||
54 | - </property> | 50 | + <property name="fastJsonConfig" ref="fastJsonConfig" /> |
55 | </bean> | 51 | </bean> |
52 | + | ||
53 | + <bean id="fastJsonConfig" class="com.alibaba.fastjson.support.config.FastJsonConfig"> | ||
54 | + <property name="serializerFeatures"> | ||
55 | + <array value-type="com.alibaba.fastjson.serializer.SerializerFeature"> | ||
56 | + <value>WriteEnumUsingToString</value> | ||
57 | + <value>DisableCircularReferenceDetect</value> | ||
58 | + </array> | ||
59 | + </property> | ||
60 | + </bean> | ||
56 | <bean id="DisableCircularReferenceDetect" class="org.springframework.beans.factory.config.FieldRetrievingFactoryBean"> | 61 | <bean id="DisableCircularReferenceDetect" class="org.springframework.beans.factory.config.FieldRetrievingFactoryBean"> |
57 | <property name="staticField" value="com.alibaba.fastjson.serializer.SerializerFeature.DisableCircularReferenceDetect"></property> | 62 | <property name="staticField" value="com.alibaba.fastjson.serializer.SerializerFeature.DisableCircularReferenceDetect"></property> |
58 | </bean> | 63 | </bean> |
-
Please register or login to post a comment