|
|
package com.yohoufo.order.controller;
|
|
|
|
|
|
import com.yoho.core.redis.cluster.operations.serializer.RedisKeyBuilder;
|
|
|
import com.yohoufo.common.ApiResponse;
|
|
|
import com.yohoufo.common.annotation.IgnoreSession;
|
|
|
import com.yohoufo.common.annotation.IgnoreSignature;
|
|
|
import com.yohoufo.common.annotation.InnerApi;
|
|
|
import com.yohoufo.common.cache.RedisLock;
|
|
|
import com.yohoufo.common.exception.UfoServiceException;
|
|
|
import com.yohoufo.common.utils.RandomUtil;
|
|
|
import com.yohoufo.order.model.QuickDeliverOrderContext;
|
|
|
import com.yohoufo.order.model.request.TransferMoneyRequest;
|
|
|
import com.yohoufo.order.service.impl.TransferService;
|
|
|
import org.apache.commons.lang3.RandomUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.web.bind.annotation.RequestBody;
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
import java.util.UUID;
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
@RestController
|
|
|
@RequestMapping("/erp/order/help")
|
|
|
public class OrderHelpController {
|
...
|
...
|
@@ -18,6 +27,9 @@ public class OrderHelpController { |
|
|
@Autowired
|
|
|
private TransferService transferService;
|
|
|
|
|
|
@Autowired
|
|
|
private RedisLock redisLock;
|
|
|
|
|
|
/**
|
|
|
* 转账
|
|
|
*/
|
...
|
...
|
@@ -32,5 +44,36 @@ public class OrderHelpController { |
|
|
.build();
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 转账
|
|
|
*/
|
|
|
@IgnoreSession
|
|
|
@IgnoreSignature
|
|
|
@InnerApi
|
|
|
@RequestMapping(value = "/lock")
|
|
|
public ApiResponse lock(String key) {
|
|
|
RedisKeyBuilder redisLockKey = RedisKeyBuilder.newInstance()
|
|
|
.appendFixed("ufo:order:lock:test:")
|
|
|
.appendVar(key);
|
|
|
String value = UUID.randomUUID().toString();
|
|
|
String message;
|
|
|
if (redisLock.acquire(redisLockKey, value, 5, TimeUnit.SECONDS)) {
|
|
|
try {
|
|
|
Thread.sleep(RandomUtils.nextInt(10, 50));
|
|
|
message = "ok";
|
|
|
} catch (InterruptedException e) {
|
|
|
message = "ko doing";
|
|
|
} finally {
|
|
|
redisLock.release(redisLockKey, value);
|
|
|
}
|
|
|
} else {
|
|
|
message = "ko acquire";
|
|
|
}
|
|
|
return new ApiResponse.ApiResponseBuilder()
|
|
|
.code(200)
|
|
|
.message(message)
|
|
|
.build();
|
|
|
}
|
|
|
|
|
|
|
|
|
} |
...
|
...
|
|