hrm 开人脸卡
This commit is contained in:
parent
765f34d5c6
commit
72ee32062f
|
@ -48,27 +48,25 @@ class EmployeeCreateUpdateSerializer(EmployeeBaseSerializer):
|
|||
|
||||
@transaction.atomic
|
||||
def create(self, validated_data):
|
||||
with transaction.atomic():
|
||||
instance = super().create(validated_data)
|
||||
if settings.DAHUA_ENABLED and dhClient:
|
||||
dahua_data = HrmService.sync_dahua_employee(ep=instance)
|
||||
third_info = instance.third_info
|
||||
third_info.update(dahua_data)
|
||||
instance.third_info = third_info
|
||||
instance.save()
|
||||
return instance
|
||||
instance = super().create(validated_data)
|
||||
if settings.DAHUA_ENABLED and dhClient:
|
||||
dahua_data = HrmService.sync_dahua_employee(ep=instance)
|
||||
third_info = instance.third_info
|
||||
third_info.update(dahua_data)
|
||||
instance.third_info = third_info
|
||||
instance.save()
|
||||
return instance
|
||||
|
||||
def update(self, instance, validated_data):
|
||||
with transaction.atomic():
|
||||
old_photo = instance.photo
|
||||
instance = super().update(instance, validated_data)
|
||||
if settings.DAHUA_ENABLED and dhClient:
|
||||
dahua_data = HrmService.sync_dahua_employee(ep=instance, old_photo=old_photo)
|
||||
third_info = instance.third_info
|
||||
third_info.update(dahua_data)
|
||||
instance.third_info = third_info
|
||||
instance.save()
|
||||
return instance
|
||||
old_photo = instance.photo
|
||||
instance = super().update(instance, validated_data)
|
||||
if settings.DAHUA_ENABLED and dhClient:
|
||||
dahua_data = HrmService.sync_dahua_employee(ep=instance, old_photo=old_photo)
|
||||
third_info = instance.third_info
|
||||
third_info.update(dahua_data)
|
||||
instance.third_info = third_info
|
||||
instance.save()
|
||||
return instance
|
||||
|
||||
|
||||
class ChannelAuthoritySerializer(serializers.Serializer):
|
||||
|
|
|
@ -58,25 +58,7 @@ class HrmService:
|
|||
# 开人脸卡 长时间
|
||||
if ep.job_state in [Employee.JOB_ON] and ep.type == 'employee':
|
||||
if not ep.third_info.get('dh_face_card', None):
|
||||
_, res = dhClient.request(**dhapis['card_gen_id'])
|
||||
cardId = res['id']
|
||||
cardNumber = ep.id[3:8] + rannum(5)
|
||||
now = datetime.now()
|
||||
startDate = now.strftime("%Y-%m-%d %H:%M:%S")
|
||||
endDate = (datetime(year=now.year+50,
|
||||
month=now.month, day=1)).strftime("%Y-%m-%d %H:%M:%S")
|
||||
json_data = {
|
||||
"id": cardId,
|
||||
"cardNumber": cardNumber,
|
||||
"category": 0,
|
||||
"cardType": 0,
|
||||
"personId": dh_id,
|
||||
"departmentId": departmentId,
|
||||
"startDate": startDate,
|
||||
"endDate": endDate
|
||||
}
|
||||
_, res = dhClient.request(**dhapis['card_add'], json=json_data)
|
||||
dh_face_card = cardNumber
|
||||
dh_face_card = cls.open_face_card(ep=ep, dh_id=dh_id, departmentId=departmentId)
|
||||
else:
|
||||
_, res = dhClient.request(**dhapis['person_gen_id'])
|
||||
dh_id = res['id']
|
||||
|
@ -113,28 +95,34 @@ class HrmService:
|
|||
)
|
||||
_, res = dhClient.request(**dhapis['person_add'], json=json_data)
|
||||
# 开人脸卡
|
||||
if ep.type == 'employee':
|
||||
_, res = dhClient.request(**dhapis['card_gen_id'])
|
||||
cardId = res['id']
|
||||
cardNumber = ep.id[:8] + rannum(2)
|
||||
now = datetime.now()
|
||||
startDate = now.strftime("%Y-%m-%d %H:%M:%S")
|
||||
endDate = (datetime(year=now.year+50,
|
||||
month=now.month, day=1)).strftime("%Y-%m-%d %H:%M:%S")
|
||||
json_data = {
|
||||
"id": cardId,
|
||||
"cardNumber": cardNumber,
|
||||
"category": 0,
|
||||
"cardType": 0,
|
||||
"personId": dh_id,
|
||||
"departmentId": departmentId,
|
||||
"startDate": startDate,
|
||||
"endDate": endDate
|
||||
}
|
||||
_, res = dhClient.request(**dhapis['card_add'], json=json_data)
|
||||
dh_face_card = res['id']
|
||||
if ep.job_state in [Employee.JOB_ON] and ep.type == 'employee':
|
||||
dh_face_card = cls.open_face_card(ep=ep, dh_id=dh_id, departmentId=departmentId)
|
||||
return {'dh_id': dh_id, 'dh_photo': dh_photo, 'dh_face_card': dh_face_card}
|
||||
|
||||
@classmethod
|
||||
def open_face_card(cls, ep, dh_id, departmentId):
|
||||
"""开人脸卡
|
||||
"""
|
||||
_, res = dhClient.request(**dhapis['card_gen_id'])
|
||||
cardId = res['id']
|
||||
cardNumber = str(ep.id)[3:8] + rannum(5)
|
||||
now = datetime.now()
|
||||
startDate = now.strftime("%Y-%m-%d %H:%M:%S")
|
||||
endDate = (datetime(year=now.year+50,
|
||||
month=now.month, day=1)).strftime("%Y-%m-%d %H:%M:%S")
|
||||
json_data = {
|
||||
"id": cardId,
|
||||
"cardNumber": cardNumber,
|
||||
"category": 0,
|
||||
"cardType": 0,
|
||||
"personId": dh_id,
|
||||
"departmentId": departmentId,
|
||||
"startDate": startDate,
|
||||
"endDate": endDate
|
||||
}
|
||||
_, res = dhClient.request(**dhapis['card_add'], json=json_data)
|
||||
return cardId
|
||||
|
||||
@classmethod
|
||||
def swipe(cls, data: dict):
|
||||
"""
|
||||
|
|
Loading…
Reference in New Issue