Эх сурвалжийг харах

新增同步通道数记录

zhangdongming 2 жил өмнө
parent
commit
8e001d0ed9

+ 2 - 0
Controller/UserDevice/UserDeviceShareController.py

@@ -15,6 +15,7 @@ from django.views import View
 from Model.models import DeviceSharePermission, DeviceChannelUserSet, DeviceChannelUserPermission, UidChannelSetModel
 from Model.models import DeviceSharePermission, DeviceChannelUserSet, DeviceChannelUserPermission, UidChannelSetModel
 from Object.ResponseObject import ResponseObject
 from Object.ResponseObject import ResponseObject
 from Object.TokenObject import TokenObject
 from Object.TokenObject import TokenObject
+from Service.UserDeviceService import UserDeviceService
 
 
 LOGGER = logging.getLogger('info')
 LOGGER = logging.getLogger('info')
 
 
@@ -149,6 +150,7 @@ class UserDeviceShareView(View):
             channel_qs = UidChannelSetModel.objects.filter(uid__uid=uid).values('channel')
             channel_qs = UidChannelSetModel.objects.filter(uid__uid=uid).values('channel')
             if not channel_qs.exists():
             if not channel_qs.exists():
                 return False
                 return False
+            UserDeviceService.update_device_channel(uid)
             channel_list = [str(val['channel']) for val in channel_qs]
             channel_list = [str(val['channel']) for val in channel_qs]
             channel_str = ','.join(channel_list)
             channel_str = ','.join(channel_list)
             with transaction.atomic():
             with transaction.atomic():

+ 27 - 0
Service/UserDeviceService.py

@@ -286,3 +286,30 @@ class UserDeviceService:
         except Exception as e:
         except Exception as e:
             LOGGER.info('异常详情,errLine:{}, errMsg:{}'.format(e.__traceback__.tb_lineno, repr(e)))
             LOGGER.info('异常详情,errLine:{}, errMsg:{}'.format(e.__traceback__.tb_lineno, repr(e)))
             return channels
             return channels
+
+    @staticmethod
+    def update_device_channel(uid):
+        """
+        UID通道同步更新
+        @param uid: 设备UID
+        @return: True | False
+        """
+        uid_set_qs = UidSetModel.objects.filter(uid=uid).values('id', 'channel')
+        if not uid_set_qs.exists():
+            return False
+        uid_set_id = uid_set_qs[0]['id']
+        channel_index = uid_set_qs[0]['channel']
+        uid_channel_qs = UidChannelSetModel.objects.filter(uid_id=uid_set_id)
+        if uid_channel_qs.exists() and uid_channel_qs.count() != channel_index:
+            uid_channel_list = []
+            channels = [val['channel'] for val in uid_channel_qs]
+            for i in range(1, channel_index + 1):
+                if i in channels:
+                    continue
+                channel_name = 'channel' + str(i)  # channel1,channel2...
+                UidChannelSet = UidChannelSetModel(uid_id=uid_set_id, channel=i, channel_name=channel_name)
+                uid_channel_list.append(UidChannelSet)
+            if not uid_channel_list:
+                return True
+            UidChannelSetModel.objects.bulk_create(uid_channel_list)
+        return True