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