|
@@ -5,6 +5,7 @@ import time
|
|
|
import requests
|
|
|
from bulk_update.helper import bulk_update
|
|
|
from django.db import transaction
|
|
|
+from django.db.models import Count
|
|
|
from django.views import View
|
|
|
|
|
|
from Model.models import SerialNumberModel, UserModel, UserSerialNumberModel, CompanySerialModel, \
|
|
@@ -34,13 +35,13 @@ class SerialNumberView(View):
|
|
|
def validate(self, request_dict, operation, request):
|
|
|
response = ResponseObject()
|
|
|
|
|
|
- if operation == 'getSerial': # 获取序列号
|
|
|
+ if operation == 'getSerial': # 获取序列号
|
|
|
return self.get_serial(request_dict, response)
|
|
|
- elif operation == 'create': # 生成序列号
|
|
|
+ elif operation == 'create': # 生成序列号
|
|
|
return self.do_create(request_dict, response)
|
|
|
- elif operation == 'mac': # 生成mac
|
|
|
+ elif operation == 'mac': # 生成mac
|
|
|
return self.generate_mac(request_dict, response)
|
|
|
- elif operation == 'checkSerial': # 序列号库存数量少于2000,发送邮件通知
|
|
|
+ elif operation == 'checkSerial': # 序列号库存数量少于2000,发送邮件通知
|
|
|
return self.check_serial_number(response)
|
|
|
|
|
|
token = request_dict.get('token', None)
|
|
@@ -50,7 +51,7 @@ class SerialNumberView(View):
|
|
|
|
|
|
if operation == 'quantity': # 查询当前可用的UID的数量
|
|
|
return self.do_quantity(token.userID, response)
|
|
|
- elif operation == 'allot': # 分配序列号
|
|
|
+ elif operation == 'allot': # 分配序列号
|
|
|
return self.do_allot(request_dict, response)
|
|
|
elif operation == 'createSerial': # 生成序列号
|
|
|
return self.create_serial(request_dict, response, request, token.userID)
|
|
@@ -327,28 +328,46 @@ class SerialNumberView(View):
|
|
|
for company in company_qs:
|
|
|
id = company['id']
|
|
|
name = company['name']
|
|
|
- not_used_qs = CompanySerialModel.objects.filter(status=3, company_id=id).count()
|
|
|
+ serial_list = []
|
|
|
+ not_used_qs = CompanySerialModel.objects.filter(status=3, company_id=id).values('serial_number')
|
|
|
res = {
|
|
|
'name': name,
|
|
|
- 'number': not_used_qs
|
|
|
+ 'number': not_used_qs.count(),
|
|
|
+ 'subMember': []
|
|
|
}
|
|
|
+ for serial in not_used_qs:
|
|
|
+ serial_list.append(serial['serial_number'])
|
|
|
+ user_serial_qs = UserSerialNumberModel.objects.filter(
|
|
|
+ serial_number__serial_number__in=serial_list).values('user__username').annotate(
|
|
|
+ count=Count('user__username'))
|
|
|
+ for user in user_serial_qs:
|
|
|
+ res['subMember'].append({'username': user['user__username'], 'count': user['count']})
|
|
|
company_not_used_list.append(res)
|
|
|
|
|
|
for company in company_qs:
|
|
|
id = company['id']
|
|
|
name = company['name']
|
|
|
- count = CompanySerialModel.objects.filter(status=1, company_id=id).count()
|
|
|
- # 获取最后一个序列号
|
|
|
- if count == 0:
|
|
|
- last_serial = ''
|
|
|
+ serial_list = []
|
|
|
+ company_serial_qs = CompanySerialModel.objects.filter(status=1, company_id=id).order_by('id').values(
|
|
|
+ 'serial_number')
|
|
|
+ if company_serial_qs.exists():
|
|
|
+ count = company_serial_qs.count()
|
|
|
+ last_serial = company_serial_qs.last()['serial_number']
|
|
|
+ for serial in company_serial_qs:
|
|
|
+ serial_list.append(serial['serial_number'])
|
|
|
else:
|
|
|
- last_serial = CompanySerialModel.objects.filter(status=1, company_id=id).order_by('-id').values(
|
|
|
- 'serial_number')[:1][0]['serial_number']
|
|
|
+ count = 0
|
|
|
+ last_serial = ''
|
|
|
res = {
|
|
|
'name': name,
|
|
|
'numbers': count,
|
|
|
- 'lastSerial': last_serial
|
|
|
+ 'lastSerial': last_serial,
|
|
|
+ 'subMember': []
|
|
|
}
|
|
|
+ user_serial_qs = UserSerialNumberModel.objects.filter(
|
|
|
+ serial_number__serial_number__in=serial_list).values('user__username').annotate(count=Count('user__username'))
|
|
|
+ for user in user_serial_qs:
|
|
|
+ res['subMember'].append({'username': user['user__username'], 'count': user['count']})
|
|
|
company_serial_list.append(res)
|
|
|
res_data = {'code': 0, 'companyRemainCount': company_not_used_list, 'companyRemain': company_serial_list,
|
|
|
'unused_serial_number_count': unused_serial_number_count,
|
|
@@ -574,10 +593,10 @@ class SerialNumberView(View):
|
|
|
now_time = int(time.time())
|
|
|
with open('mac.txt', 'w') as f:
|
|
|
f.write(mac + '\n')
|
|
|
- for i in range(quantity-1):
|
|
|
+ for i in range(quantity - 1):
|
|
|
next_mac = CommonService.updateMac(mac)
|
|
|
mac = next_mac
|
|
|
- f.write(next_mac+'\n')
|
|
|
+ f.write(next_mac + '\n')
|
|
|
# 保存下个mac
|
|
|
next_mac = CommonService.updateMac(mac)
|
|
|
mac_qs.update(value=next_mac, update_time=now_time)
|