From e8ae55606f4ca2d44f8d8bb2ab0fa1ae8e56b5b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9B=B9=E5=89=8D=E6=98=8E?= <909355014@qq.com> Date: Tue, 4 Oct 2022 21:20:40 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=89=E6=96=B9token=20=E4=B8=8D=E8=BF=87?= =?UTF-8?q?=E6=9C=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/ecm/service.py | 24 +++++++++--------------- apps/third/dahua.py | 4 +--- apps/third/speaker.py | 2 +- apps/third/xunxi.py | 2 +- apps/utils/permission.py | 2 +- 5 files changed, 13 insertions(+), 21 deletions(-) diff --git a/apps/ecm/service.py b/apps/ecm/service.py index 9c3a4cb3..53745426 100644 --- a/apps/ecm/service.py +++ b/apps/ecm/service.py @@ -234,14 +234,14 @@ def create_remind(event: Event, params: dict): def check_not_in_place(opl: Opl): # 检查作业人员未就位事件(直接创建事件) area = opl.operation.area - try: + if 'xx_rail' in area.third_info: railId = area.third_info['xx_rail']['id'] json = { "railId": railId, "type": "" } is_ok, res = xxClient.request(**xxapis['rail_ibeacon_list'], json=json, raise_exception=False) - if is_ok: + if is_ok == 'success': blt_list = res['recordList'] macs = [] # 所有该区域在线标签 for i in blt_list: @@ -264,32 +264,26 @@ def check_not_in_place(opl: Opl): }) notify_event(event) break - except Exception: - myLogger.error('检查作业人员未就位失败', exc_info=True) def check_miss_lcard(ep: Employee, area: Area): # 获取当前区域下的定位卡列表 - try: + if 'xx_rail' in area.third_info: railId = area.third_info['xx_rail']['id'] json = { "railId": railId, "type": "" } is_ok, res = xxClient.request(**xxapis['rail_ibeacon_list'], json=json, raise_exception=False) - if is_ok: + if is_ok == 'success': blt_list = res['recordList'] macs = [] # 所有该区域在线标签 for i in blt_list: macs.append(i['userId']) td = TDevice.objects.filter(type=TDevice.DEVICE_BLT, employee=ep).first() - if td: - if td.code not in macs: - return True - else: - return True - except Exception: - myLogger.error('检查未带定位卡失败', exc_info=True) + if td and td.code in macs: + return False + return True def dispatch_dahua_event(data: dict): @@ -426,7 +420,7 @@ def loc_change(data): ep_loc_dict['time2'] = time2 if area_fix and ep_loc_dict['area_fix_id'] == area_fix['id']: # 如果停留在该区域 - cache.set(key_str, ep_loc_dict) + cache.set(key_str, ep_loc_dict, timeout=None) # 在该固定区域停留时间(分钟) stay_minute = int((ep_loc_dict['time2']-ep_loc_dict['time1'])/60) # 判断停留时间是否合理 @@ -449,7 +443,7 @@ def loc_change(data): else: ep_loc_dict['time1'] = time2 ep_loc_dict['area_fix_id'] = area_fix['id'] if area_fix else None - cache.set(key_str, ep_loc_dict) + cache.set(key_str, ep_loc_dict, timeout=None) return ep_loc_dict diff --git a/apps/third/dahua.py b/apps/third/dahua.py index f56bc659..083145c7 100644 --- a/apps/third/dahua.py +++ b/apps/third/dahua.py @@ -47,7 +47,7 @@ class DhClient: } is_ok, res = self.request(**dhapis['token_login'], params=params, raise_exception=False) if is_ok == 'success': - cache.set('dh_token', res['access_token']) + cache.set('dh_token', res['access_token'], timeout=None) self.isGetingToken = False def request(self, url: str, method: str, params=dict(), json=dict(), timeout=120, @@ -82,8 +82,6 @@ class DhClient: raise ParseError(**err_detail) return 'fail', err_detail # self.handle_log(result='success', response=ret) # 成功的日志就不记录了 - if '/evo-apigw/admin/API/EVO/invoke/DMS' in url: - self.handle_log(result='success', response=ret) return 'success', ret['data'] if 'data' in ret else None self.handle_log(result='error', response=ret) if raise_exception: diff --git a/apps/third/speaker.py b/apps/third/speaker.py index 81061ba8..eb8f4f3b 100644 --- a/apps/third/speaker.py +++ b/apps/third/speaker.py @@ -46,7 +46,7 @@ class SpClient: } is_ok, res = self.request(**spapis['user_login'], json=json_data, raise_exception=False) if is_ok == 'success': - cache.set('sp_token', res['user']['token']) + cache.set('sp_token', res['user']['token'], timeout=None) self.isGetingToken = False def request(self, url: str, method: str, params=dict(), json=dict(), timeout=120, diff --git a/apps/third/xunxi.py b/apps/third/xunxi.py index 75e75d14..6e78e830 100644 --- a/apps/third/xunxi.py +++ b/apps/third/xunxi.py @@ -40,7 +40,7 @@ class XxClient: } is_ok, res = self.request(**xxapis['token_login'], json=json, raise_exception=False) if is_ok == 'success': - cache.set('xx_token', res['token']) + cache.set('xx_token', res['token'], timeout=None) self.isGetingToken = False def request(self, url: str, method: str = 'post', params=dict(), json=dict(), timeout=20, raise_exception=True): diff --git a/apps/utils/permission.py b/apps/utils/permission.py index 983cffdc..5e885284 100755 --- a/apps/utils/permission.py +++ b/apps/utils/permission.py @@ -33,7 +33,7 @@ def get_user_perms_map(user): user_perms_map[code][dept_id] = data_range else: user_perms_map[code] = {dept_id: pr.data_range} - cache.set('perms_' + user.id, user_perms_map, 60*60) + cache.set('perms_' + user.id, user_perms_map, timeout=None) return user_perms_map