|
@@ -1128,13 +1128,29 @@ class SerialNumberView(View):
|
|
|
if not serial:
|
|
|
return response.json(444)
|
|
|
try:
|
|
|
- baidu_big_model_license_qs = BaiduBigModelLicense.objects.filter(serial='').values('license')
|
|
|
- if not baidu_big_model_license_qs.exists():
|
|
|
- return response.json(173)
|
|
|
+ # 同个序列号返回相同license
|
|
|
+ baidu_big_model_license_qs = BaiduBigModelLicense.objects.filter(serial=serial).values('license')
|
|
|
+ if baidu_big_model_license_qs.exists():
|
|
|
+ baidu_license = baidu_big_model_license_qs[0]['license']
|
|
|
+ else:
|
|
|
+ # 查询未被使用的license,使用事务和行锁避免并发问题
|
|
|
+ with transaction.atomic():
|
|
|
+ baidu_big_model_license_qs = BaiduBigModelLicense.objects.filter(
|
|
|
+ serial=''
|
|
|
+ ).select_for_update().order_by('id').first()
|
|
|
+ if not baidu_big_model_license_qs:
|
|
|
+ return response.json(173)
|
|
|
+ baidu_license = baidu_big_model_license_qs.license
|
|
|
+ # 更新数据为已使用
|
|
|
+ now_time = int(time.time())
|
|
|
+ baidu_big_model_license_qs.serial = serial
|
|
|
+ baidu_big_model_license_qs.updated_time = now_time
|
|
|
+ baidu_big_model_license_qs.save()
|
|
|
+
|
|
|
res = {
|
|
|
- 'license': baidu_big_model_license_qs[0]['license']
|
|
|
+ 'license': baidu_license
|
|
|
}
|
|
|
- baidu_big_model_license_qs.update(serial=serial)
|
|
|
+
|
|
|
return response.json(0, res)
|
|
|
except Exception as e:
|
|
|
return response.json(500, 'error_line:{}, error_msg:{}'.format(e.__traceback__.tb_lineno, repr(e)))
|