Beispiel #1
0
 def getSelfOnlineFunction(self):
     data = {
         'database': self.company_db,
         'fields': [
             'guid',
             'device_guid_id',
             'control_channel_guid_id',
         ],
         'eq': {
             'is_delete': False,
             'device_guid_id': self.guid,
         },
     }
     msg = yield mysqlClient.tornadoSelectOnly('d_device_online_channel',
                                               data)
     if msg['ret'] != '0':
         yield logClient.tornadoErrorLog(
             '数据库查询失败:{}'.format('d_device_online_channel'))
         return
     if msg['lenght'] == 0:
         yield logClient.tornadoWarningLog(
             '会议室:({}),设备({})没有定义在线状态通道'.format(self.meeting_room_name,
                                                self.name))
         return
     self.online_channel_guid = msg['msg'][0]['control_channel_guid_id']
    def initMeetingRoom(self):
        for DATABASE in DATABASES:
            db = DATABASE['name']
            # 获取公司名称
            if db == 'aura':
                db_name = 'default'
            else:
                db_name = db
            data = {
                'database': 'aura',
                'fields': ['name'],
                'eq': {
                    'database_name': db_name
                }
            }
            msg = yield mysqlClient.tornadoSelectOnly('d_company', data)
            if msg['ret'] == '0' and msg['lenght'] == 1:
                company_name = msg['msg'][0]['name']
            else:
                yield logClient.tornadoErrorLog('数据库:{},查询错误:({})'.format(
                    db, 'd_company'))
                continue

            data = {
                'database':
                db,
                'fields': [
                    'guid',
                    'room_name',
                    'sin_minute',
                    'status_group_guid_id as schedule_status',
                ],
                'eq': {
                    'is_delete': False,
                    # 'guid':'ec5eadb8-9744-11e9-922b-5254002d0365',
                },
            }
            msg = yield mysqlClient.tornadoSelectAll('d_meeting_room', data)
            if msg['ret'] == '0':
                room_list = msg['msg']
            else:
                yield logClient.tornadoErrorLog('获取数据库:排程信息失败')
                continue
            for room_info in room_list:
                room_info['company_db'] = db
                room_info['company_name'] = company_name
                room_info['publish_function'] = self.myPublish
                meeting_room_object = MeetingRoom(**room_info)
                self.meetingRoomDict[
                    meeting_room_object.guid] = meeting_room_object
        else:
            yield logClient.tornadoDebugLog('会议室更新完成,开始分钟事件')
            self.ioloop.add_timeout(self.ioloop.time(), self.minuteTask)
 def userName(self,user_id,company_db):
     # 获取所有会议室
     data = {
         'database': company_db,
         'fields': ['username'],
         'eq': {
             'is_delete': False,
             'guid':user_id
         },
     }
     msg = yield mysqlClient.tornadoSelectOnly('user', data)
     if msg['ret'] == '0' and msg['lenght'] == 1:
         return  msg['msg'][0]['username']
     else:
         return ''
 def deviceAuthorizationInfo(self,device_sn,company_db):
     data = {
         'database': company_db,
         'fields': ['authorization_status'],
         'eq': {
             'is_delete': False,
             'sn': device_sn,
         },
     }
     msg = yield mysqlClient.tornadoSelectOnly('d_device', data)
     if msg['ret'] != '0':
         return False
     else:
         if msg['lenght'] == 1:
             return msg['msg'][0]
         else:
             return {'guid':'','authorization_status':0}
 def userLoginTokenCheck(self, user_id, token, company_db):
     # 数据库查询token,tken存在,且创建时间在十分钟内
     data = {
         'database': company_db,
         'fields': ['user_id'],
         'eq': {
             'is_delete': False,
             'token': token,
             'user_id': user_id,
         },
         'gte': {
             'update_time': datetime.datetime.now() - datetime.timedelta(days=1),  # 最迟是五分钟前的数据
         },
         'lte': {
             'update_time': datetime.datetime.now() + datetime.timedelta(seconds=30),  # 小于等于当前时间
         },
     }
     msg = yield mysqlClient.tornadoSelectOnly('user_token', data)
     if msg['ret'] != '0' and msg['lenght'] == 1:
         return False
     else:
         return True
    def initAllMeetingRoom(self):
        '''获取所有的会议室,更新全局变量meeting_room_list'''
        yield self.getAllocateChannelGuid()
        # 获取所有的会议室
        for DATABASE in DATABASES:
            db = DATABASE['name']
            # 获取公司名称
            if db == 'aura':
                db_name = 'default'
            else:
                db_name = db
            data = {
                'database': db,
                # 'database':'aura',
                'fields': ['name'],
                'eq': {
                    'database_name': db_name,
                }
            }
            msg = yield mysqlClient.tornadoSelectOnly('d_company', data)
            if msg['ret'] == '0' and msg['lenght'] == 1:
                company_name = msg['msg'][0]['name']
            else:
                yield logClient.tornadoErrorLog('数据库:{},查询错误:({})'.format(
                    db, 'd_company'))
                continue

            data = {
                'database':
                db,
                'fields': [
                    'guid',
                    'room_name',
                    'status_group_guid_id as schedule_status',
                ],
                'eq': {
                    'is_delete': False,
                    # 'guid':'ec5eadb8-9744-11e9-922b-5254002d0365',
                    'virtual_guid': '',
                },
            }
            msg = yield mysqlClient.tornadoSelectAll('d_meeting_room', data)

            if msg['ret'] == '0':
                meeting_rooms = msg['msg']
            else:
                yield logClient.tornadoErrorLog(
                    '数据库查询错误:({})'.format('d_meeting_room'))
                continue
            for meeting_room in meeting_rooms:
                meeting_room['company_name'] = company_name
                # 把每一个会议室转换为会议室对象
                meeting_room_ = MeetingRoom(db,
                                            mosquitto_object=self,
                                            **meeting_room)
                self.meeting_room_list.append(meeting_room_)
                # 添加会议室guid和mqtt_name的转换对象
                self.GuidToMeetingRoom[meeting_room_.guid] = meeting_room_

            # 获取虚拟会议室
            data = {
                'database':
                db,
                'fields': [
                    'guid',
                    'room_name',
                    'status_group_guid_id as schedule_status',
                ],
                'eq': {
                    'is_delete': False,
                    'virtual_guid': 'virtual',
                },
            }
            msg = yield mysqlClient.tornadoSelectAll('d_meeting_room', data)
            if msg['ret'] == '0':
                meeting_rooms = msg['msg']
            else:
                yield logClient.tornadoErrorLog(
                    '数据库查询错误:({})'.format('d_meeting_room'))
                continue
            for meeting_room in meeting_rooms:
                meeting_room['company_db'] = db
                meeting_room['company_name'] = company_name
                virtual_meeting_room_guid = meeting_room.get('guid')
                # 获取虚拟会议室下的会议室
                data = {
                    'database': db,
                    'fields': [
                        'guid',
                        'real_meeting_room_guid_id',
                    ],
                    'eq': {
                        'is_delete': False,
                        'virtual_meeting_room_guid_id':
                        virtual_meeting_room_guid,
                    },
                }
                msg = yield mysqlClient.tornadoSelectAll(
                    'd_virtual_meeting_room', data)
                if msg['ret'] == '0':
                    meeting_room['real_meeting_room_guid_list'] = [
                        x['real_meeting_room_guid_id'] for x in msg['msg']
                    ]
                else:
                    yield logClient.tornadoErrorLog(
                        '数据库查询错误:({})'.format('d_meeting_room'))
                    meeting_room['real_meeting_room_guid_list'] = []
                self.virtual_meeting_room_list.append(meeting_room)
                self.GuidToVirtualMeetingRoom[
                    virtual_meeting_room_guid] = meeting_room
        # 获取分房会议室
        '''
        分房会议室结构:
        self.separate_meeting_room_list = [
            {
                'real_meeting_room_guid':
                'separate_mode':0/1,
                'meeting_room_info':[
                    {
                        'guid':'',
                        'room_name':'',
                        'schedule_status':'',
                        'company':'',
                        'company_name':'',
                    }
                ]
            }
        ]
        '''
        for meeting_room_object in self.meeting_room_list:
            real_meeting_room_guid = meeting_room_object.guid
            company_db = meeting_room_object.company_db
            data = {
                'database': company_db,
                'fields': ['separate_meeting_room_guid_id'],
                'eq': {
                    'real_meeting_room_guid_id': real_meeting_room_guid,
                    'is_delete': False
                }
            }
            msg = yield mysqlClient.tornadoSelectAll('d_separate_meeting_room',
                                                     data)
            if msg['ret'] == '0':
                separete_meeting_room_guid_list = [
                    x['separate_meeting_room_guid_id'] for x in msg['msg']
                ]
            else:
                yield logClient.tornadoErrorLog(
                    '数据库查询错误:({})'.format('d_meeting_room'))
                continue
            if separete_meeting_room_guid_list == []:
                continue
            separete_group_info = {}
            separete_group_info[
                'real_meeting_room_guid'] = real_meeting_room_guid
            separete_group_info['separate_mode'] = 0
            separete_group_info['meeting_room_info'] = []
            for separete_meeting_room_guid in separete_meeting_room_guid_list:
                data = {
                    'database':
                    company_db,
                    'fields': [
                        'guid',
                        'room_name',
                        'status_group_guid_id as schedule_status',
                    ],
                    'eq': {
                        'is_delete': False,
                        'virtual_guid': 'separate',
                        'guid': separete_meeting_room_guid,
                    },
                }
                msg = yield mysqlClient.tornadoSelectOnly(
                    'd_meeting_room', data)
                if msg['ret'] == '0' and msg['lenght'] == 1:
                    separete_info = msg['msg'][0]
                    separete_info['company_db'] = company_db
                else:
                    continue
                separete_group_info['meeting_room_info'].append(separete_info)
            self.separate_meeting_room_list.append(separete_group_info)
        else:
            pass
 def getSeparateInfo(self, meeting_room_guid, company_db):
     # 判断传入会议室guid是实体会议室还是分房会议室
     data = {
         'database': company_db,
         'fields': ['virtual_guid'],
         'eq': {
             'is_delete': False,
             'guid': meeting_room_guid,
         }
     }
     msg = yield mysqlClient.tornadoSelectOnly('d_meeting_room', data)
     if msg['ret'] == '0' and msg['lenght'] == 1:
         virtual_guid = msg['msg'][0]['virtual_guid']
     else:
         return False
     if virtual_guid == '':
         # 实体会议室
         real_meeting_room_guid_list = [meeting_room_guid]
     elif virtual_guid == 'separate':
         # 获取分房会议室所在的实体会议室
         data = {
             'database': company_db,
             'fields': ['real_meeting_room_guid_id'],
             'eq': {
                 'is_delete': False,
                 'separate_meeting_room_guid_id': meeting_room_guid
             },
         }
         msg = yield mysqlClient.tornadoSelectAll('d_separate_meeting_room', data)
         if msg['ret'] == '0':
             real_meeting_room_guid_list = [x['real_meeting_room_guid_id'] for x in msg['msg']]
         else:
             return False
     else:
         return False
     separate_info_list = []
     for real_meeting_room_guid in real_meeting_room_guid_list:
         data = {
             'database': company_db,
             'fields': ['guid as real_meeting_room_guid_id', 'room_name'],
             'eq': {
                 'guid': real_meeting_room_guid
             }
         }
         msg = yield mysqlClient.tornadoSelectAll('d_meeting_room', data)
         if msg['ret'] == '0':
             separate_info_list += msg['msg']
         else:
             return False
         # 分房会议室
         data = {
             'database': company_db,
             'fields': ['d_separate_meeting_room.separate_meeting_room_guid_id',
                        'd_meeting_room.room_name'],
             'eq': {
                 'd_separate_meeting_room.is_delete': False,
                 'd_meeting_room.is_delete': False,
                 'd_separate_meeting_room.separate_meeting_room_guid_id': {'key': 'd_meeting_room.guid'},
                 'real_meeting_room_guid_id': real_meeting_room_guid
             },
         }
         # 获取所有会议室
         msg = yield mysqlClient.tornadoSelectAll('d_separate_meeting_room,d_meeting_room', data)
         if msg['ret'] == '0':
             separate_info_list += msg['msg']
         else:
             return False
     return separate_info_list
Beispiel #8
0
 def updateSelfOnlineStatus(self, channel_guid, status):
     # if self.online_channel_guid == None:
     #     return
     # elif channel_guid != self.online_channel_guid:
     #     return
     # elif status not in ['on', 'off']:
     #     return
     # else:
     #     self.online_status = status
     #检查状态值有效性
     # if status not in ['on', 'off']:
     #     return
     self.online_status = status
     yield logClient.tornadoInfoLog('{}:设备({})在线状态更新为:{}'.format(
         self.meeting_room_name, self.name, status))
     yield self.meeting_room_object.updateDeviceOnlineStatus(self)
     if self.online_status == 'off':  # 掉线
         # 判断是否有离线记录,有则不添加
         data = {
             'database': self.company_db,
             'fields': ['guid'],
             'eq': {
                 'is_delete': False,
                 'device_guid_id': self.guid,
                 'status': True
             },
             'sortInfo': [
                 {
                     'update_time': 'ASC'
                 },
             ],
         }
         msg = yield mysqlClient.tornadoSelectOnly(
             'd_device_offline_record', data)
         if msg['ret'] == '0':
             if msg['lenght'] == 0:
                 # 添加离线记录
                 info = {'device_guid_id': self.guid, 'status': True}
                 yield self.mysqlStorage('d_device_offline_record', info)
         if self.off_info == {}:
             yield self.updateSelfSwitchOffStatus(None, 'off', no_channel=1)
     else:  # 上线
         # 判断是否有掉线记录,有则删除
         data = {
             'database': self.company_db,
             'fields': ['guid'],
             'eq': {
                 'is_delete': False,
                 'device_guid_id': self.guid,
                 'status': True
             },
             'sortInfo': [
                 {
                     'update_time': 'ASC'
                 },
             ],
         }
         msg = yield mysqlClient.tornadoSelectOnly(
             'd_device_offline_record', data)
         if msg['ret'] == '0':
             if msg['lenght'] > 0:
                 last_guid = msg['msg'][0]['guid']
                 # 更新上一次离线记录
                 data = {
                     'database': self.company_db,
                     'msg': {
                         'update_time': datetime.datetime.now(),
                         'status': False
                     },
                     'eq': {
                         'guid': last_guid
                     }
                 }
                 msg = yield mysqlClient.tornadoUpdateMany(
                     'd_device_offline_record', data)
                 if msg['ret'] == '0':
                     yield self.meeting_room_object.updateDeviceOnlineStatus(
                         self)
                 else:
                     yield logClient.tornadoErrorLog('修改设备离线记录失败')
             else:
                 # 之前没有离线记录,上线记录不做操作
                 pass
         else:
             yield logClient.tornadoErrorLog('查询设备离线记录失败')
         if self.on_info == {}:
             yield self.updateSelfSwitchOnStatus(None, 'on', no_channel=1)