|
@@ -42,8 +42,6 @@ class SerialNumberView(View):
|
|
|
|
|
|
if operation == 'getUID':
|
|
|
return self.do_get_uid(request_dict, response)
|
|
|
- elif operation == 'getSerial':
|
|
|
- return self.do_get_serial_number(request_dict, response)
|
|
|
elif operation == 'attachUID':
|
|
|
return self.do_attach_uid(request_dict, response, request)
|
|
|
elif operation == 'detachUID':
|
|
@@ -92,59 +90,6 @@ class SerialNumberView(View):
|
|
|
print(e)
|
|
|
return response.json(500, repr(e))
|
|
|
|
|
|
- # 提供给pc端获取序列号
|
|
|
- def do_get_serial_number(self, request_dict, response):
|
|
|
- quantity = request_dict.get('quantity', None)
|
|
|
- company_id = request_dict.get('company_id', None)
|
|
|
- token = request_dict.get('token', None)
|
|
|
- time_stamp = request_dict.get('time_stamp', None)
|
|
|
- p2p_type = request_dict.get('p2p_type', None)
|
|
|
-
|
|
|
- if token and time_stamp and quantity and company_id:
|
|
|
-
|
|
|
- token = int(CommonService.decode_data(token))
|
|
|
- time_stamp = int(time_stamp)
|
|
|
-
|
|
|
- now_time = int(time.time())
|
|
|
- distance = now_time - time_stamp
|
|
|
-
|
|
|
- if token != time_stamp or distance > 60000 or distance < -60000: # 为了全球化时间控制在一天内
|
|
|
- return response.json(404)
|
|
|
-
|
|
|
- redisObject = RedisObject()
|
|
|
- key = 'serial_lock'
|
|
|
- value = redisObject.lpop(key)
|
|
|
- count = 0
|
|
|
- while value is False and count < 5:
|
|
|
- time.sleep(1)
|
|
|
- value = redisObject.lpop(key)
|
|
|
- count += 1
|
|
|
-
|
|
|
- if count == 5 and value is False: # 暂时注释
|
|
|
- return response.json(5)
|
|
|
-
|
|
|
- quantity = int(quantity)
|
|
|
-
|
|
|
- company_serial_qs = CompanySerialModel.objects.filter(company__secret=company_id, status=0, p2p=p2p_type)
|
|
|
- if not company_serial_qs.exists():
|
|
|
- redisObject.rpush(key, value)
|
|
|
- return response.json(373)
|
|
|
-
|
|
|
- # 存在对应的企业
|
|
|
- company_serial_qs = company_serial_qs[0:quantity]
|
|
|
-
|
|
|
- # company_serial_qs = company_serial_qs.values('id', 'serial_number__serial_number', 'company__mark')
|
|
|
- data = []
|
|
|
- ids = []
|
|
|
- for serial in company_serial_qs:
|
|
|
- ids.append(serial.id)
|
|
|
- data.append(serial.serial_number + serial.company.mark)
|
|
|
- CompanySerialModel.objects.filter(id__in=ids).update(status=1)
|
|
|
- redisObject.rpush(key, value)
|
|
|
- return response.json(0, data)
|
|
|
- else:
|
|
|
- return response.json(444)
|
|
|
-
|
|
|
def do_list(self, userID, request_dict, response):
|
|
|
# perm = ModelService.check_perm_uid_manage(userID, 0)
|
|
|
# if not perm:
|