|
@@ -196,9 +196,6 @@ class VPGView(View):
|
|
|
@csrf_exempt
|
|
|
def do_upload_uid(request):
|
|
|
# 上传UID,需要request.FILES,单独提取出来
|
|
|
- # perm = ModelService.check_perm_uid_manage(userID, 0)
|
|
|
- # if not perm:
|
|
|
- # return response.json(309)
|
|
|
|
|
|
request.encoding = 'utf-8'
|
|
|
response = uidManageResponseObject()
|
|
@@ -210,33 +207,24 @@ def do_upload_uid(request):
|
|
|
return response.json(444)
|
|
|
file = request.FILES.get('file', None)
|
|
|
vpg_id = request_dict.get('vpg_id', None)
|
|
|
+ p2p_type = request_dict.get('p2p_type', None)
|
|
|
platform = request_dict.get('platform', '')
|
|
|
init_string = request_dict.get('init_string', '')
|
|
|
init_string_app = request_dict.get('init_string_app', '')
|
|
|
|
|
|
- if not vpg_id:
|
|
|
+ if not all([vpg_id, p2p_type]):
|
|
|
return response.json(444)
|
|
|
|
|
|
- bulk = []
|
|
|
- add_time = update_time = int(time.time())
|
|
|
- # MAC = MacModel.objects.filter().values('id', 'value', 'is_active')[0] # 获取最新可用的mac
|
|
|
- # current_mac = MAC['value']
|
|
|
- # if (not MAC['is_active']) or (current_mac[-8:] == 'FF.FF.FF'):
|
|
|
- # return response.json(175)
|
|
|
-
|
|
|
- area = 1 if vpg_id != '1' else 0
|
|
|
- # path = '/'.join((BASE_DIR, 'static/uid')).replace('\\', '/') + '/'
|
|
|
- # if not os.path.exists(path):
|
|
|
- # os.makedirs(path)
|
|
|
- # full_path = path + str(file)
|
|
|
- # with open(full_path, 'wb+') as uid_file:
|
|
|
try:
|
|
|
+ bulk = []
|
|
|
+ p2p_type = int(p2p_type)
|
|
|
+ # 尚云必须输入平台和初始化字符
|
|
|
+ if p2p_type == 1 and (not platform or not platform or not init_string_app):
|
|
|
+ return response.json(444)
|
|
|
+ p2p = '尚云' if p2p_type == 1 else 'tutk'
|
|
|
+ area = 1 if vpg_id != '1' else 0 # vpg_id为'1':国内
|
|
|
+ add_time = update_time = int(time.time())
|
|
|
for chunk in file.chunks():
|
|
|
- # str_chunk = str(chunk)
|
|
|
- # print('str(chunk):', str_chunk)
|
|
|
- # str_chunk = re.findall("b\'(.*)\'", str_chunk)[0]
|
|
|
- # str_chunk = str_chunk.split('\\r\\n')
|
|
|
- # print('str(chunk):', str_chunk)
|
|
|
uid_list = re.findall("b\'(.*)\'", str(chunk))[0].split('\\r\\n')
|
|
|
for uid in uid_list:
|
|
|
UID = UIDModel(
|
|
@@ -247,29 +235,17 @@ def do_upload_uid(request):
|
|
|
update_time=update_time,
|
|
|
area=area, # 关联vgp表已有区域信息,可以考虑去掉
|
|
|
vpg_id=vpg_id,
|
|
|
+ p2p_type=p2p_type,
|
|
|
platform=platform,
|
|
|
init_string=init_string,
|
|
|
init_string_app=init_string_app
|
|
|
)
|
|
|
- if len(uid) == 14: # 宸云
|
|
|
- UID.p2p_type = 1
|
|
|
- UID.uid = uid
|
|
|
- elif len(uid) == 20: # tutk
|
|
|
- UID.p2p_type = 2
|
|
|
- UID.uid = uid
|
|
|
- elif len(uid) == 23: # 宸云完整uid
|
|
|
- a = uid.split('-')
|
|
|
- new_uid = a[0] + a[1] + a[2].split(',')[0]
|
|
|
- UID.p2p_type = 1
|
|
|
- UID.uid = new_uid
|
|
|
+ if '-' in uid: # 尚云完整uid,eg.ACN-000005-FHCGR,VRWEDU -> ACN000005FHCGR
|
|
|
UID.full_uid_code = uid
|
|
|
+ uid_split = uid.split('-')
|
|
|
+ uid = uid_split[0] + uid_split[1] + uid_split[2].split(',')[0]
|
|
|
+ UID.uid = uid
|
|
|
bulk.append(UID)
|
|
|
- # temp_mac = CommonService.updateMac(current_mac) # mac地址值+1;后3个字节为FF时返回None
|
|
|
- # if temp_mac:
|
|
|
- # current_mac = temp_mac # 更新赋值写入uid表
|
|
|
- # else:
|
|
|
- # temp_mac = current_mac # 赋值为FF写入mac表
|
|
|
- # break
|
|
|
|
|
|
ip = CommonService.get_ip_address(request)
|
|
|
content = json.loads(json.dumps(request_dict))
|
|
@@ -280,7 +256,7 @@ def do_upload_uid(request):
|
|
|
'time': add_time,
|
|
|
'url': 'vpgUid/uid',
|
|
|
'content': json.dumps(content),
|
|
|
- 'operation': '上传{}个uid到VPG ID {}'.format(len(uid_list), vpg_id),
|
|
|
+ 'operation': '上传{}个{}uid到VPG ID {}'.format(len(uid_list), p2p, vpg_id),
|
|
|
}
|
|
|
|
|
|
with transaction.atomic():
|
|
@@ -288,8 +264,7 @@ def do_upload_uid(request):
|
|
|
UIDModel.objects.bulk_create(bulk) # 批量写入uid数据
|
|
|
uid_count = UIDModel.objects.filter(vpg_id=vpg_id).count() # 获取族群下uid的数量
|
|
|
VPGModel.objects.filter(id=vpg_id).update(uid_count=uid_count) # 更新vgp表的uid_count
|
|
|
- # MacModel.objects.filter().update(value=temp_mac) # 更新mac表的mac地址值
|
|
|
return response.json(0)
|
|
|
except Exception as e:
|
|
|
print(e)
|
|
|
- return response.json(500, repr(e))
|
|
|
+ return response.json(500, repr(e))
|