Przeglądaj źródła

Merge remote-tracking branch 'origin/test'

locky 3 lat temu
rodzic
commit
cd74ba9fed
3 zmienionych plików z 32 dodań i 62 usunięć
  1. 0 19
      Controller/SerialNumberController.py
  2. 17 42
      Controller/VPGController.py
  3. 15 1
      Model/models.py

+ 0 - 19
Controller/SerialNumberController.py

@@ -132,7 +132,6 @@ class SerialNumberView(View):
         company_id = request_dict.get('company_id', None)
         token = request_dict.get('token', None)
         time_stamp = request_dict.get('time_stamp', None)
-        DeviceSubType = request_dict.get('DeviceSubType', None)
         p2ptype = request_dict.get('p2ptype', 1)
         if not all([serial_number, company_id, token, time_stamp]):
             return response.json(444)
@@ -179,22 +178,6 @@ class SerialNumberView(View):
 
                         uid = uid_qs[0]
 
-                        if DeviceSubType:
-                            # 获取最新的mac,判断分配到哪里,且进行绑定
-                            mac = MacModel.objects.filter().values('id', 'value', 'is_active')[0]
-                            if not mac['is_active']:
-                                return response.json(175)
-                            current_mac = mac['value']
-                            UIDModel.objects.filter(id=uid.id).update(mac=current_mac)  # uid表写入mac值
-                            # 绑定mac地址成功后更新mac表
-                            temp_mac = CommonService.updateMac(current_mac)  # mac地址值+1;后3个字节为FF时返回None
-                            if temp_mac:
-                                MacModel.objects.filter().update(value=temp_mac, update_time=now_time)  # 更新mac表的mac地址值
-                            else:
-                                MacModel.objects.filter().update(is_active=False, update_time=now_time)
-                        else:
-                            current_mac = ''
-
                         result = UIDModel.objects.filter(id=uid.id, status=0).update(status=2, update_time=now_time)
                         if int(result) <= 0:    # 更新失败
                             count += 1
@@ -218,7 +201,6 @@ class SerialNumberView(View):
                         res = {
                             'full_uid_code': CommonService.encode_data(full_uid_code),
                             'uid': CommonService.encode_data(uid.uid),
-                            'mac': CommonService.encode_data(current_mac),
                             'extra': uid.uid_extra,
                             'platform': uid.platform,
                             'initString': uid.init_string,
@@ -253,7 +235,6 @@ class SerialNumberView(View):
                 res = {
                     'full_uid_code': CommonService.encode_data(full_uid_code),
                     'uid': CommonService.encode_data(uid['uid__uid']),
-                    'mac': CommonService.encode_data(uid['uid__mac']),
                     'extra': uid['uid__uid_extra'],
                     'platform': uid['uid__platform'],
                     'initString': uid['uid__init_string'],

+ 17 - 42
Controller/VPGController.py

@@ -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))

+ 15 - 1
Model/models.py

@@ -1138,7 +1138,7 @@ class AppLogModel(models.Model):
     user = models.ForeignKey(Device_User, to_field='userID', on_delete=models.CASCADE, verbose_name='关联设备用户表')
     uid = models.CharField(max_length=20, default='', verbose_name='设备uid')
     average_delay = models.CharField(max_length=32, default='', verbose_name='最高平均延时')
-    status = models.SmallIntegerField(default=0, verbose_name='失败状态')
+    status = models.SmallIntegerField(default=0, verbose_name='失败状态')   # 0: 成功,1: 失败
     filename = models.CharField(max_length=120, default='', verbose_name='文件名')
     add_time = models.IntegerField(default=0, verbose_name='日期')
 
@@ -1148,6 +1148,20 @@ class AppLogModel(models.Model):
         verbose_name_plural = verbose_name
 
 
+class DeviceLogModel(models.Model):
+    id = models.AutoField(primary_key=True)
+    ip = models.CharField(default='', max_length=32, verbose_name='ip')
+    uid = models.CharField(max_length=32, default='', verbose_name='设备uid')
+    status = models.SmallIntegerField(default=0, verbose_name='上传状态')   # 0: 成功,1: 失败
+    filename = models.CharField(max_length=120, default='', verbose_name='文件名')
+    add_time = models.DateTimeField(blank=True, auto_now_add=True, verbose_name=u'添加时间')
+
+    class Meta:
+        db_table = 'device_log'
+        verbose_name = '设备日志表'
+        verbose_name_plural = verbose_name
+
+
 class EquipmentInfoExStatisticsModel(models.Model):
     id = models.AutoField(primary_key=True)
     push_type = models.SmallIntegerField(default=0, verbose_name='第三方推送服务器标志。0:APNS推送,1:谷歌推送,2:极光推送')