下单时对设备上锁
This commit is contained in:
parent
7377d39b19
commit
9ed15965f0
|
@ -21,7 +21,8 @@ public enum RedisLockKey {
|
|||
ADD_DEVICE("add_device", "创建设备"),
|
||||
ADD_TIME_BILL("add_time_bill", "创建时长订单"),
|
||||
PAY_BILL("pay_bill", "支付订单"),
|
||||
PREPAY_DEPOSIT("prepay_deposit", "支付押金");
|
||||
PREPAY_DEPOSIT("prepay_deposit", "支付押金"),
|
||||
ADD_RECHARGE_ORDER("add_recharge_order", "创建充值订单");
|
||||
|
||||
|
||||
private final String key;
|
||||
|
|
|
@ -228,6 +228,12 @@ public class TransactionBillServiceImpl implements TransactionBillService, After
|
|||
|
||||
@Override
|
||||
public String addOrder(RechargeBO bo) {
|
||||
ServiceUtil.assertion(bo == null || bo.getDevice() == null || bo.getDevice().getDeviceId() == null, "设备不存在");
|
||||
Long deviceId = bo.getDevice().getDeviceId();
|
||||
|
||||
// 加锁
|
||||
ServiceUtil.assertion(!redisLock.lock(RedisLockKey.ADD_RECHARGE_ORDER, deviceId), "当前使用该设备人数较多,请稍后再试");
|
||||
try {
|
||||
// 拉取设备信息
|
||||
deviceService.pullDeviceInfo(Collections.singletonList(bo.getDevice().getDeviceId()));
|
||||
|
||||
|
@ -244,6 +250,10 @@ public class TransactionBillServiceImpl implements TransactionBillService, After
|
|||
// 加入延时队列,超时取消
|
||||
billDelayedManager.add(order.getBillNo(), order.getExpireTime().getTime());
|
||||
return order.getBillNo();
|
||||
} finally {
|
||||
// 解锁
|
||||
redisLock.unlock(RedisLockKey.ADD_RECHARGE_ORDER, deviceId);
|
||||
}
|
||||
}
|
||||
|
||||
// 处理充值服务费
|
||||
|
|
Loading…
Reference in New Issue
Block a user