|
@@ -37,6 +37,7 @@ import com.yonge.toolset.utils.date.DateUtil;
|
|
import com.yonge.toolset.utils.obj.ObjectUtil;
|
|
import com.yonge.toolset.utils.obj.ObjectUtil;
|
|
import org.apache.commons.collections.CollectionUtils;
|
|
import org.apache.commons.collections.CollectionUtils;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
+import org.redisson.api.RLock;
|
|
import org.redisson.api.RMap;
|
|
import org.redisson.api.RMap;
|
|
import org.redisson.api.RedissonClient;
|
|
import org.redisson.api.RedissonClient;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.Logger;
|
|
@@ -1020,9 +1021,18 @@ public class CourseScheduleServiceImpl extends ServiceImpl<CourseScheduleDao, Co
|
|
public HttpResponseResult<OrderCreateRes> buyPracticeCourse(OrderReq.OrderReqInfo orderReqInfo) {
|
|
public HttpResponseResult<OrderCreateRes> buyPracticeCourse(OrderReq.OrderReqInfo orderReqInfo) {
|
|
ObjectMapper objectMapper = new ObjectMapper();
|
|
ObjectMapper objectMapper = new ObjectMapper();
|
|
PracticeScheduleDto scheduleDto = objectMapper.convertValue(orderReqInfo.getBizContent(), PracticeScheduleDto.class);
|
|
PracticeScheduleDto scheduleDto = objectMapper.convertValue(orderReqInfo.getBizContent(), PracticeScheduleDto.class);
|
|
- return DistributedLock.of(redissonClient)
|
|
|
|
- .runIfLockCanGet(CacheNameEnum.LOCK_EXECUTE_ORDER.getRedisKey("teacherId:" + scheduleDto.getTeacherId())
|
|
|
|
- , () -> this.buyPracticeCourseTran(orderReqInfo), 60L, TimeUnit.SECONDS);
|
|
|
|
|
|
+
|
|
|
|
+ RLock lock = redissonClient.getLock("teacherId:" + scheduleDto.getTeacherId());
|
|
|
|
+ try {
|
|
|
|
+ if (lock.tryLock(10,60, TimeUnit.SECONDS)) {
|
|
|
|
+ return buyPracticeCourseTran(orderReqInfo);
|
|
|
|
+ }
|
|
|
|
+ } catch (InterruptedException e) {
|
|
|
|
+ throw new BizException("创建陪练课失败:{}", e.getMessage());
|
|
|
|
+ } finally {
|
|
|
|
+ lock.unlock();
|
|
|
|
+ }
|
|
|
|
+ return HttpResponseResult.failed();
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|