|
@@ -11,7 +11,7 @@ from django.views import View
|
|
|
from django.views.decorators.csrf import csrf_exempt
|
|
|
from django.db import transaction
|
|
|
|
|
|
-from Model.models import UIDModel, UserUIDModel, UserModel, LogModel, MacModel
|
|
|
+from Model.models import UIDModel, UserUIDModel, UserModel, LogModel, MacModel, OrderTaskModel, OrderUIDModel
|
|
|
from Object.RedisObject import RedisObject
|
|
|
from Object.TokenObject import TokenObject
|
|
|
from Object.ResponseObject import ResponseObject
|
|
@@ -41,8 +41,8 @@ class UploadUIDFileView(View):
|
|
|
area = request_dict.get('area', None)
|
|
|
isReset = request_dict.get('isReset', 0)
|
|
|
content = request_dict.get('fileName', None)
|
|
|
- # print('content')
|
|
|
- # print(content)
|
|
|
+ print('content')
|
|
|
+ print(content)
|
|
|
|
|
|
content = base64.b64decode(content).decode().strip()
|
|
|
content = content[3:(len(content) - 3)]
|
|
@@ -198,10 +198,18 @@ class UploadUIDFileView(View):
|
|
|
def do_update_uid_status(self, uids, area):
|
|
|
uid_qs = UIDModel.objects.filter(uid__in=uids, area=area, status=2)
|
|
|
if uid_qs.exists():
|
|
|
+ uid_ids = []
|
|
|
for uid in uid_qs:
|
|
|
if uid.status == 2:
|
|
|
uid.status = 1
|
|
|
+ uid_ids.append(uid.id)
|
|
|
UIDModel.objects.bulk_update(uid_qs, fields=['status'])
|
|
|
+
|
|
|
+ try:
|
|
|
+ OrderUIDModel.objects.filter(uid__id__in=tuple(uid_ids)).delete()
|
|
|
+ except Exception as e:
|
|
|
+ print(e)
|
|
|
+
|
|
|
return uid_qs.count()
|
|
|
return 0
|
|
|
|
|
@@ -256,6 +264,12 @@ class DownloadUIDFileView(View):
|
|
|
area = request_dict.get('area', None)
|
|
|
quantity = int(request_dict.get('quantity', None))
|
|
|
fileType = request_dict.get('fileType', None)
|
|
|
+ order_number = request_dict.get('order_number', None)
|
|
|
+ board = request_dict.get('board', None)
|
|
|
+ plan = request_dict.get('plan', None)
|
|
|
+ checksum = request_dict.get('checksum', None)
|
|
|
+ ic_model = request_dict.get('ic_model', None)
|
|
|
+ order_quantity = request_dict.get('order_quantity', None)
|
|
|
response = ResponseObject()
|
|
|
|
|
|
# print(area)
|
|
@@ -264,25 +278,44 @@ class DownloadUIDFileView(View):
|
|
|
if token.code != 0:
|
|
|
return response.json(token.code)
|
|
|
|
|
|
- if not area:
|
|
|
- return response.json(444, 'area')
|
|
|
+ if not area or not order_number or not board or not plan or not checksum or not ic_model or not order_quantity or not fileType:
|
|
|
+ return response.json(444)
|
|
|
|
|
|
area = int(area)
|
|
|
|
|
|
if area >= 0 and quantity > 0:
|
|
|
|
|
|
- uid_qs = UserUIDModel.objects.filter(user__id=token.userID, uid__status=1, uid__area=area). \
|
|
|
- values('uid__id', 'uid__uid', 'uid__mac', 'uid__uid_extra', 'uid__add_time', 'uid__update_time', 'uid__area')
|
|
|
- count = uid_qs.count()
|
|
|
+ # 保存订单信息
|
|
|
+ order = {
|
|
|
+ 'order_number': order_number,
|
|
|
+ 'board': board,
|
|
|
+ 'plan': plan,
|
|
|
+ 'checksum': checksum,
|
|
|
+ 'ic_model': ic_model,
|
|
|
+ 'quantity': order_quantity
|
|
|
+ }
|
|
|
+
|
|
|
+ tmp = OrderTaskModel.objects.update_or_create(defaults={'order_number': order_number}, **order)
|
|
|
+ print(tmp)
|
|
|
+
|
|
|
+ order = OrderTaskModel.objects.filter(order_number=order_number)[0]
|
|
|
+
|
|
|
+ uid_qs = UserUIDModel.objects.filter(user__id=token.userID, uid__status=1, uid__area=area)
|
|
|
+
|
|
|
+ uid_values = uid_qs.values('uid__id', 'uid__uid', 'uid__mac', 'uid__uid_extra', 'uid__add_time', 'uid__update_time', 'uid__area')
|
|
|
+
|
|
|
+ count = uid_values.count()
|
|
|
if count < quantity:
|
|
|
return response.json(444, '设备UID不足')
|
|
|
|
|
|
- if uid_qs.exists():
|
|
|
- uid_qs = uid_qs[0:quantity]
|
|
|
+ if uid_values.exists():
|
|
|
+
|
|
|
+ uid_values = uid_values[0:quantity]
|
|
|
+ uid_qs = uid_qs[0: quantity]
|
|
|
if fileType == 'txt':
|
|
|
- return self.download_txt(uid_qs)
|
|
|
+ return self.download_txt(uid_values, uid_qs, order)
|
|
|
elif fileType == 'excel':
|
|
|
- return self.download_excel(uid_qs)
|
|
|
+ return self.download_excel(uid_values)
|
|
|
else:
|
|
|
return response.json(444, 'fileType')
|
|
|
else:
|
|
@@ -290,37 +323,50 @@ class DownloadUIDFileView(View):
|
|
|
else:
|
|
|
return response.json(444, '222')
|
|
|
|
|
|
- def download_txt(self, uid_qs):
|
|
|
+ def download_txt(self, uid_values, uid_qs, order):
|
|
|
updates = []
|
|
|
+ updates_uid = []
|
|
|
content = ''
|
|
|
- for item in uid_qs:
|
|
|
+ now_time = int(time.time())
|
|
|
+ for i in range(len(uid_values)):
|
|
|
# print(item)
|
|
|
+ item = uid_values[i]
|
|
|
mac: str = item['uid__mac']
|
|
|
index = mac.rfind(':')
|
|
|
tmp = mac[0:index] + ' ' + mac[index:]
|
|
|
content += tmp + ' '
|
|
|
content += item['uid__uid']
|
|
|
content += '\r\n'
|
|
|
- updates.append(UIDModel(
|
|
|
+ uidModel = UIDModel(
|
|
|
id=item['uid__id'],
|
|
|
uid=item['uid__uid'],
|
|
|
mac=item['uid__mac'],
|
|
|
uid_extra=item['uid__uid_extra'],
|
|
|
status=2,
|
|
|
add_time=item['uid__add_time'],
|
|
|
- update_time=item['uid__update_time'],
|
|
|
+ update_time=now_time,
|
|
|
area=item['uid__area']
|
|
|
- ))
|
|
|
+ )
|
|
|
+ updates.append(uidModel)
|
|
|
+
|
|
|
+ order_uid = OrderUIDModel(uid=uidModel, order=order, add_time=now_time, update_time=now_time)
|
|
|
+ updates_uid.append(order_uid)
|
|
|
+
|
|
|
if len(updates) % 5000 == 0:
|
|
|
UIDModel.objects.bulk_update(updates, fields=["status"])
|
|
|
+ OrderUIDModel.objects.bulk_create(updates_uid)
|
|
|
updates.clear()
|
|
|
+ updates_uid.clear()
|
|
|
# print(item['uid__uid'])
|
|
|
|
|
|
if len(updates) > 0:
|
|
|
UIDModel.objects.bulk_update(updates, fields=["status"])
|
|
|
+ OrderUIDModel.objects.bulk_create(updates_uid)
|
|
|
updates.clear()
|
|
|
+ updates_uid.clear()
|
|
|
|
|
|
del updates
|
|
|
+ del updates_uid
|
|
|
content = content[0:len(content) - 1]
|
|
|
response = StreamingHttpResponse(content)
|
|
|
response['Content-Type'] = 'application/octet-stream'
|