From b1ec172829ed9fb6d2b70b693534bfa24d749861 Mon Sep 17 00:00:00 2001 From: caoqianming Date: Fri, 5 May 2023 09:40:20 +0800 Subject: [PATCH] =?UTF-8?q?refector:=20=E5=B0=9D=E8=AF=95=E8=AE=BF?= =?UTF-8?q?=E9=97=AE=E5=8D=A1=E7=89=87=E4=BB=A5=E7=A1=AE=E4=BF=9D=E5=8D=A1?= =?UTF-8?q?=E7=89=87=E7=94=9F=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/hrm/services.py | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/apps/hrm/services.py b/apps/hrm/services.py index 8c6d7284..5658281a 100755 --- a/apps/hrm/services.py +++ b/apps/hrm/services.py @@ -157,9 +157,15 @@ class HrmService: "endDate": endDate } _, res = dhClient.request(**dhapis['card_add'], json=json_data) - time.sleep(6) # 等待确保生成卡片 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 return cardNumber @classmethod @@ -186,14 +192,14 @@ class HrmService: "timeQuantumId": 1, "cardPrivilegeDetails": details } - is_ok, res = dhClient.request(**dhapis['card_door_authority'], json=json_data, raise_exception=False) - 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) + 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) cls.save(ep, data={'dh_dchannels': dh_dchannels}) return dh_dchannels