Преглед на файлове

封装根据uid查询返回完整序列号函数

locky преди 3 години
родител
ревизия
05224d4f6a
променени са 3 файла, в които са добавени 37 реда и са изтрити 16 реда
  1. 18 9
      Controller/CloudStorage.py
  2. 2 6
      Controller/EquipmentManagerV2.py
  3. 17 1
      Service/CommonService.py

+ 18 - 9
Controller/CloudStorage.py

@@ -42,7 +42,8 @@ from Ansjer.config import OSS_STS_ACCESS_KEY, OSS_STS_ACCESS_SECRET, OSS_ROLE_AR
 from Controller.CheckUserData import DataValid
 from Model.models import Device_Info, Order_Model, Store_Meal, VodHlsModel, OssCrdModel, UID_Bucket, StsCrdModel, \
     ExperienceContextModel, Pay_Type, CDKcontextModel, Device_User, SysMassModel, SysMsgModel, UidPushModel, \
-    Unused_Uid_Meal, UIDMainUser, UserModel, PromotionRuleModel, VideoPlaybackTimeModel, CloudLogModel, CouponModel, VodBucketModel
+    Unused_Uid_Meal, UIDMainUser, UserModel, PromotionRuleModel, VideoPlaybackTimeModel, CloudLogModel, CouponModel, \
+    VodBucketModel, UIDModel
 from Object.AWS.S3Email import S3Email
 from Object.AliPayObject import AliPayObject
 from Object.AliSmsObject import AliSmsObject
@@ -1452,7 +1453,7 @@ class CloudStorageView(View):
         uid = request_dict.get('uid', None)
         lang = request_dict.get('lang', 'en')
         dv_qs = Device_Info.objects.filter(userID_id=userID, UID=uid, isShare=False, isExist=1) \
-            .values('vodPrimaryUserID')
+            .values('vodPrimaryUserID', 'serial_number', 'Type')
         if not dv_qs.exists() or dv_qs[0]['vodPrimaryUserID'] != userID:
             return response.json(12)
         now_time = int(time.time())
@@ -1462,6 +1463,14 @@ class CloudStorageView(View):
                                                                     "use_status","endTime","has_unused","bucket__id")
         if not uid_bucket:
             return response.json(10030)
+
+        # 如果存在序列号返回完整序列号
+        device_id = uid
+        serial_number = dv_qs[0]['serial_number']
+        if serial_number:
+            device_id = CommonService.get_full_serial_number(uid, serial_number, dv_qs[0]['Type'])
+
+        uid_bucket[0]['uid'] = device_id
         uid_bucket[0]['storage'] = 0
         has_unused = uid_bucket[0]['has_unused']
         del uid_bucket[0]['has_unused']
@@ -1477,13 +1486,13 @@ class CloudStorageView(View):
                     month += 's'
                 storage = "{storage_time}{month}".format(storage_time=storage_time, month=month)
                 unused_dict = {
-                    "id":ub['unused_id'],
-                    "uid":ub['uid'],
-                    "bucket__content":ub['bucket__content'],
-                    "use_status":0,
-                    "endTime":0,
-                    "bucket__id":ub['bucket__id'],
-                    "storage":storage,
+                    "id": ub['unused_id'],
+                    "uid": device_id,
+                    "bucket__content": ub['bucket__content'],
+                    "use_status": 0,
+                    "endTime": 0,
+                    "bucket__id": ub['bucket__id'],
+                    "storage": storage,
                 }
                 store_list.append(unused_dict)
                 bucket_id_list.append(ub['bucket__id'])

+ 2 - 6
Controller/EquipmentManagerV2.py

@@ -325,13 +325,9 @@ class EquipmentManagerV2(View):
             uv_dict[us['uid']]['channels'] = channels
 
         for p in dvls:
-            # 如果存在序列号组织序列号数据返回
+            # 如果存在序列号返回完整序列号
             if p['serial_number']:
-                p2p_type = str(UIDModel.objects.filter(uid=p['UID']).values('p2p_type')[0]['p2p_type'])
-                # 设备类型转为16进制并补齐4位
-                device_type = hex(p['Type'])[2:]
-                device_type = (4-len(device_type)) * '0' + device_type
-                p['UID'] = p['serial_number'] + p2p_type + device_type
+                p['UID'] = CommonService.get_full_serial_number(p['UID'], p['serial_number'], p['Type'])
             # 新增IOT
             p['iot'] = []
             for iot in iotqs:

+ 17 - 1
Service/CommonService.py

@@ -17,7 +17,7 @@ from pyipip import IPIPDatabase
 
 from Ansjer.config import BASE_DIR, SERVER_DOMAIN_SSL, CONFIG_INFO, CONFIG_TEST, CONFIG_CN
 from Controller.CheckUserData import RandomStr
-from Model.models import iotdeviceInfoModel, Device_Info, CountryModel, RegionModel
+from Model.models import iotdeviceInfoModel, Device_Info, CountryModel, RegionModel, UIDModel
 
 
 class CommonService:
@@ -588,6 +588,22 @@ GCqvlyw5dfxNA+EtxNE2wCW/LW7ENJlACgcfgPlBZtpLheWoZB/maw4=
                 return uid
         return serial_number
 
+    @staticmethod
+    def get_full_serial_number(uid, serial_number, device_type):
+        """
+        根据uid查询返回完整序列号
+        @param uid: uid
+        @param serial_number: 序列号
+        @param device_type: 设备类型
+        @return: full_serial_number
+        """
+        p2p_type = str(UIDModel.objects.filter(uid=uid).values('p2p_type')[0]['p2p_type'])
+        # 设备类型转为16进制并补齐4位
+        device_type = hex(device_type)[2:]
+        device_type = (4 - len(device_type)) * '0' + device_type
+        full_serial_number = serial_number + p2p_type + device_type
+        return full_serial_number
+
     # 根据企业标识返回物品名
     @staticmethod
     def get_thing_name(company_mark, thing_name_suffix):