三方token 不过期

This commit is contained in:
曹前明 2022-10-04 21:20:40 +08:00
parent 7aa6f5ccea
commit e8ae55606f
5 changed files with 13 additions and 21 deletions

View File

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

View File

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

View File

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

View File

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

View File

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