|
@@ -7,12 +7,16 @@
|
|
|
# @Email : zhangdongming@asj6.wecom.work
|
|
|
# @File : SurveysManageController.py
|
|
|
# @Software: PyCharm
|
|
|
+import json
|
|
|
+import time
|
|
|
|
|
|
+from django.db import transaction
|
|
|
from django.utils.decorators import method_decorator
|
|
|
from django.views.decorators.csrf import csrf_exempt
|
|
|
from django.views.generic.base import View
|
|
|
|
|
|
-from Model.models import CompanyModel, SerialNumberModel, VPGModel, UIDModel, UIDCompanySerialModel, CompanySerialModel
|
|
|
+from Model.models import CompanyModel, SerialNumberModel, VPGModel, UIDModel, UIDCompanySerialModel, CompanySerialModel, \
|
|
|
+ LogModel
|
|
|
from Object.ResponseObject import ResponseObject
|
|
|
from Object.TokenObject import TokenObject
|
|
|
from Service.CommonService import CommonService
|
|
@@ -34,20 +38,97 @@ class SerialView(View):
|
|
|
return self.validation(request.POST, request, operation)
|
|
|
|
|
|
def validation(self, request_dict, request, operation):
|
|
|
- token = TokenObject(request.META.get('HTTP_AUTHORIZATION'))
|
|
|
response = ResponseObject()
|
|
|
- if token.code != 0:
|
|
|
- return response.json(token.code)
|
|
|
- response = ResponseObject(returntype='pc')
|
|
|
- if operation == 'company-page':
|
|
|
- return self.company_page(request_dict, response)
|
|
|
- if operation == 'number/page':
|
|
|
- return self.serial_page(request_dict, response)
|
|
|
- if operation == 'vpg-info/page':
|
|
|
- return self.vpg_page(request_dict, response)
|
|
|
- if operation == 'uid-info/page':
|
|
|
- return self.uid_page(request_dict, response)
|
|
|
- return response.json(0)
|
|
|
+ if operation == 'uploadUid':
|
|
|
+ return self.uploadUid(request, request_dict, response)
|
|
|
+ else:
|
|
|
+ token = TokenObject(request.META.get('HTTP_AUTHORIZATION'))
|
|
|
+ if token.code != 0:
|
|
|
+ return response.json(token.code)
|
|
|
+ response = ResponseObject(returntype='pc')
|
|
|
+ if operation == 'company-page':
|
|
|
+ return self.company_page(request_dict, response)
|
|
|
+ if operation == 'number/page':
|
|
|
+ return self.serial_page(request_dict, response)
|
|
|
+ if operation == 'vpg-info/page':
|
|
|
+ return self.vpg_page(request_dict, response)
|
|
|
+ if operation == 'uid-info/page':
|
|
|
+ return self.uid_page(request_dict, response)
|
|
|
+ return response.json(0)
|
|
|
+
|
|
|
+ @classmethod
|
|
|
+ def uploadUid(cls, request, request_dict, response):
|
|
|
+ uid_list = request_dict.get('uid_list', 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 all([vpg_id, p2p_type]):
|
|
|
+ return response.json(444)
|
|
|
+
|
|
|
+ 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'
|
|
|
+ add_time = update_time = int(time.time())
|
|
|
+
|
|
|
+ try:
|
|
|
+ # 根据vpg关联的region确定area
|
|
|
+ region = VPGModel.objects.filter(id=vpg_id).values('region__name')[0]['region__name']
|
|
|
+ area = 0 if region == '中国' else 1
|
|
|
+ uid_list = uid_list.splitlines() # 按行('\r', '\r\n', \n')切割字符串返回列表
|
|
|
+ bulk = []
|
|
|
+ for uid in uid_list:
|
|
|
+ UID = UIDModel(
|
|
|
+ mac='',
|
|
|
+ uid_extra='',
|
|
|
+ status=0,
|
|
|
+ add_time=add_time,
|
|
|
+ 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
|
|
|
+ )
|
|
|
+ # 尚云完整uid,eg.ACN-000005-FHCGR,VRWEDU -> ACN000005FHCGR,必须包含','
|
|
|
+ if p2p == '尚云':
|
|
|
+ if '-' in uid and ',' in uid:
|
|
|
+ UID.full_uid_code = uid
|
|
|
+ uid_split = uid.split('-')
|
|
|
+ uid = uid_split[0] + uid_split[1] + uid_split[2].split(',')[0]
|
|
|
+ else:
|
|
|
+ return response.json(376)
|
|
|
+ # tutk uid长度为14或20
|
|
|
+ elif len(uid) != 14 and len(uid) != 20:
|
|
|
+ return response.json(376)
|
|
|
+ UID.uid = uid
|
|
|
+ bulk.append(UID)
|
|
|
+
|
|
|
+ ip = CommonService.get_ip_address(request)
|
|
|
+ content = json.loads(json.dumps(request_dict))
|
|
|
+ log = {
|
|
|
+ 'ip': ip,
|
|
|
+ 'user_id': 1,
|
|
|
+ 'status': 200,
|
|
|
+ 'time': add_time,
|
|
|
+ 'url': 'serial/uploadUid',
|
|
|
+ 'content': json.dumps(content),
|
|
|
+ 'operation': '上传{}个{}uid到vpg {}'.format(len(uid_list), p2p, vpg_id),
|
|
|
+ }
|
|
|
+
|
|
|
+ with transaction.atomic():
|
|
|
+ LogModel.objects.create(**log) # 记录操作日志
|
|
|
+ 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
|
|
|
+ return response.json(0)
|
|
|
+ except Exception as e:
|
|
|
+ print(e)
|
|
|
+ return response.json(500, repr(e))
|
|
|
|
|
|
@classmethod
|
|
|
def company_page(cls, request_dict, response):
|