From 8d3d1934b7ee5d3aa5bac2b6658d29e6c4bdce78 Mon Sep 17 00:00:00 2001 From: caoqianming Date: Mon, 8 May 2023 15:51:05 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20while=20=E5=BE=AA=E7=8E=AF=E5=81=9Acard?= =?UTF-8?q?=5Fdoor=5Fauthority=E7=9A=84=E8=A1=A5=E5=81=BF=E6=9C=BA?= =?UTF-8?q?=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/hrm/services.py | 37 +++++++++++++++++++++---------------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/apps/hrm/services.py b/apps/hrm/services.py index 5658281a..ea7e75db 100755 --- a/apps/hrm/services.py +++ b/apps/hrm/services.py @@ -156,16 +156,16 @@ class HrmService: "startDate": startDate, "endDate": endDate } - _, res = dhClient.request(**dhapis['card_add'], json=json_data) + dhClient.request(**dhapis['card_add'], json=json_data) cls.save(ep, data={'dh_face_card': cardNumber, 'dh_face_card_start': startDate, 'dh_face_card_end': endDate}) - anum = 0 # 尝试次数以确保卡片生成 - while anum < 6: - time.sleep(2) - is_ok, res = dhClient.request(**dhapis['card_detail'], params={'cardNumber': cardNumber}, raise_exception=False) - if is_ok == 'success': - break - anum = anum + 1 + # anum = 0 # 尝试次数以确保卡片生成 + # while anum < 10: + # time.sleep(2) + # is_ok, res = dhClient.request(**dhapis['card_detail'], params={'cardNumber': cardNumber}, raise_exception=False) + # if is_ok == 'success': + # break + # anum = anum + 1 return cardNumber @classmethod @@ -192,14 +192,19 @@ class HrmService: "timeQuantumId": 1, "cardPrivilegeDetails": details } - dhClient.request(**dhapis['card_door_authority'], json=json_data) - # if is_ok == 'fail' and '44999999' in res['code']: - # time.sleep(14) - # dhClient.request(**dhapis['card_door_authority'], json=json_data) - # elif is_ok == 'fail': - # raise ParseError(**res) - # elif is_ok == 'error': - # raise APIException(**DH_REQUEST_ERROR) + ind = 0 + while ind < 6: + time.sleep(5) + is_ok, res = dhClient.request(**dhapis['card_door_authority'], json=json_data, raise_exception=False) + if is_ok == 'success': + break + elif is_ok == 'fail' and '44999999' in res['code']: + ind = ind + 1 + continue + elif is_ok == 'fail': + raise ParseError(**res) + elif is_ok == 'error': + raise APIException(**DH_REQUEST_ERROR) cls.save(ep, data={'dh_dchannels': dh_dchannels}) return dh_dchannels