|
|
package com.yohoufo.order.service.impl;
|
|
|
|
|
|
import com.google.common.util.concurrent.RateLimiter;
|
|
|
import com.yoho.error.ServiceError;
|
|
|
import com.yoho.error.exception.ServiceException;
|
|
|
import com.yohobuy.ufo.model.order.bo.GoodsInfo;
|
|
|
import com.yohobuy.ufo.model.order.common.OrderCodeType;
|
|
|
import com.yohobuy.ufo.model.order.common.TabType;
|
|
|
import com.yohobuy.ufo.model.order.resp.OrderDetailInfo;
|
|
|
import com.yohoufo.common.exception.UfoServiceException;
|
|
|
import com.yohoufo.order.service.cache.OrderCacheService;
|
|
|
import com.yohoufo.order.service.support.codegenerator.OrderCodeGenerator;
|
|
|
import com.yohoufo.order.service.support.codegenerator.bean.CodeMeta;
|
...
|
...
|
@@ -15,6 +17,7 @@ import org.springframework.beans.factory.annotation.Autowired; |
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.util.Objects;
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
import java.util.function.Supplier;
|
|
|
|
|
|
@Service
|
...
|
...
|
@@ -70,7 +73,16 @@ public class OrderViewService { |
|
|
return goodsInfo;
|
|
|
}
|
|
|
|
|
|
private final RateLimiter rateLimiter = RateLimiter.create(200D);
|
|
|
|
|
|
public OrderDetailInfo getPayDetail(int uid, long orderCode){
|
|
|
boolean acquireToken = rateLimiter.tryAcquire(1, 10, TimeUnit.MILLISECONDS);
|
|
|
|
|
|
if (!acquireToken){
|
|
|
logger.warn("OrderViewService.getPayDetail trigger rate limit, uid {} orderCode {} rate {}", uid, orderCode, rateLimiter.getRate());
|
|
|
throw new UfoServiceException(400, "支付正在进行中");
|
|
|
}
|
|
|
|
|
|
CodeMeta codeMeta = orderCodeGenerator.expId(orderCode);
|
|
|
if (Objects.isNull(codeMeta)){
|
|
|
logger.warn("payDetail orderCode illegal, orderCode {}", orderCode);
|
...
|
...
|
@@ -79,26 +91,18 @@ public class OrderViewService { |
|
|
OrderCodeType orderCodeType = OrderCodeType.getOrderCodeType(codeMeta.getType());
|
|
|
|
|
|
Supplier<OrderDetailInfo> orderDetailInfoSupplier = null;
|
|
|
TabType tabType;
|
|
|
switch (orderCodeType){
|
|
|
case BUYER_TYPE:
|
|
|
tabType = TabType.BUY;
|
|
|
orderDetailInfoSupplier = () -> buyerOrderDetailService.getPayDetail(uid, orderCode);
|
|
|
break;
|
|
|
case SELLER_TYPE:
|
|
|
tabType = TabType.SELL;
|
|
|
orderDetailInfoSupplier = () -> sellerOrderDetailService.getPayDetail(uid, orderCode);
|
|
|
break;
|
|
|
default:
|
|
|
return null;
|
|
|
}
|
|
|
OrderDetailInfo orderDetailInfo = orderCacheService.getOrderPayDetailInfo(uid, orderCode, tabType);
|
|
|
if (orderDetailInfo == null){
|
|
|
orderDetailInfo = orderDetailInfoSupplier.get();
|
|
|
if (Objects.nonNull(orderDetailInfo)){
|
|
|
orderCacheService.cacheOrderPayDetailInfo(uid, orderCode, tabType, orderDetailInfo);
|
|
|
}
|
|
|
}
|
|
|
OrderDetailInfo orderDetailInfo ;
|
|
|
orderDetailInfo = orderDetailInfoSupplier.get();
|
|
|
return orderDetailInfo;
|
|
|
}
|
|
|
} |
...
|
...
|
|