|
@@ -32,10 +32,13 @@ class SerialNumberView(View):
|
|
|
|
|
|
def validate(self, request_dict, operation, request):
|
|
|
response = ResponseObject()
|
|
|
- if operation == 'create':
|
|
|
- return self.do_create(request_dict, response)
|
|
|
- elif operation == 'getSerial': # 获取序列号
|
|
|
+
|
|
|
+ if operation == 'getSerial': # 获取序列号
|
|
|
return self.get_serial(request_dict, response)
|
|
|
+ elif operation == 'create': # 生成序列号
|
|
|
+ return self.do_create(request_dict, response)
|
|
|
+ elif operation == 'mac': # 生成mac
|
|
|
+ return self.generate_mac(request_dict, response)
|
|
|
|
|
|
token = request_dict.get('token', None)
|
|
|
token = TokenObject(token)
|
|
@@ -527,7 +530,7 @@ class SerialNumberView(View):
|
|
|
try:
|
|
|
with transaction.atomic():
|
|
|
# 更新和创建数据
|
|
|
- MacModel.objects.filter().update(**mac_data)
|
|
|
+ mac_qs.update(**mac_data)
|
|
|
SerialNumberModel.objects.filter(serial_number=serial_number).update(use_status=2, add_time=now_time)
|
|
|
CompanySerialModel.objects.filter(serial_number=serial_number).update(status=2, update_time=now_time)
|
|
|
LogModel.objects.create(**log)
|
|
@@ -537,3 +540,31 @@ class SerialNumberView(View):
|
|
|
except Exception as e:
|
|
|
redis_obj.del_data(key=serial_operate_lock_key) # redis解锁
|
|
|
return response.json(500, repr(e))
|
|
|
+
|
|
|
+ @staticmethod
|
|
|
+ def generate_mac(request_dict, response):
|
|
|
+ """
|
|
|
+ 生成mac到mac.txt文件
|
|
|
+ :param request_dict: 请求
|
|
|
+ :param response: 响应
|
|
|
+ :return: response
|
|
|
+ """
|
|
|
+ quantity = int(request_dict.get('quantity', 0))
|
|
|
+ if quantity == 0:
|
|
|
+ return response.json(444)
|
|
|
+
|
|
|
+ mac_qs = MacModel.objects.filter(is_active=True).values('value')
|
|
|
+ if not mac_qs.exists():
|
|
|
+ return response.json(175)
|
|
|
+ mac = mac_qs[0]['value']
|
|
|
+ now_time = int(time.time())
|
|
|
+ with open('mac.txt', 'w') as f:
|
|
|
+ f.write(mac + '\n')
|
|
|
+ for i in range(quantity-1):
|
|
|
+ next_mac = CommonService.updateMac(mac)
|
|
|
+ mac = next_mac
|
|
|
+ f.write(next_mac+'\n')
|
|
|
+ # 保存下个mac
|
|
|
+ next_mac = CommonService.updateMac(mac)
|
|
|
+ mac_qs.update(value=next_mac, update_time=now_time)
|
|
|
+ return response.json(0)
|