|
@@ -17,6 +17,7 @@ import com.yonge.toolset.base.exception.BizException;
|
|
|
import com.yonge.toolset.utils.web.WebUtil;
|
|
|
import io.swagger.annotations.Api;
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
+import org.redisson.api.RLock;
|
|
|
import org.redisson.api.RedissonClient;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
@@ -112,22 +113,25 @@ public class PaymentController extends BaseController {
|
|
|
payReq.setUserId(user.getId());
|
|
|
payReq.setIpAddress(WebUtil.getRemoteIp(request));
|
|
|
|
|
|
- Future<OrderPayRes> orderPayResFuture = DistributedLock.of(redissonClient)
|
|
|
- .callIfLockCanGet(OrdeerCacherEnmu.LOCK_PAY_ORDER.getRedisKey(user.getId()),
|
|
|
- () -> portalOrderService.orderPay(payReq), 60L, TimeUnit.SECONDS);
|
|
|
-
|
|
|
+ RLock lock = redissonClient.getLock(OrdeerCacherEnmu.LOCK_PAY_ORDER.getRedisKey(user.getId()));
|
|
|
try {
|
|
|
- OrderPayRes orderPayRes = orderPayResFuture.get();
|
|
|
- if (orderPayRes.isStatus()) {
|
|
|
- return succeed(orderPayRes);
|
|
|
- } else {
|
|
|
- return failed(orderPayRes.getMessage());
|
|
|
+ boolean b = lock.tryLock(60, TimeUnit.SECONDS);
|
|
|
+ if (b) {
|
|
|
+ OrderPayRes orderPayRes = portalOrderService.orderPay(payReq);
|
|
|
+ if (orderPayRes.isStatus()) {
|
|
|
+ return succeed(orderPayRes);
|
|
|
+ } else {
|
|
|
+ return failed(orderPayRes.getMessage());
|
|
|
+ }
|
|
|
}
|
|
|
+ return failed("请求超时");
|
|
|
}catch (BizException e) {
|
|
|
return failed(e.getMessage());
|
|
|
- }catch (Exception e) {
|
|
|
+ } catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
return HttpResponseResult.failed("付款失败");
|
|
|
+ }finally {
|
|
|
+ lock.unlock();
|
|
|
}
|
|
|
}
|
|
|
}
|