hrm 开人脸卡
This commit is contained in:
parent
765f34d5c6
commit
72ee32062f
|
@ -48,27 +48,25 @@ class EmployeeCreateUpdateSerializer(EmployeeBaseSerializer):
|
||||||
|
|
||||||
@transaction.atomic
|
@transaction.atomic
|
||||||
def create(self, validated_data):
|
def create(self, validated_data):
|
||||||
with transaction.atomic():
|
instance = super().create(validated_data)
|
||||||
instance = super().create(validated_data)
|
if settings.DAHUA_ENABLED and dhClient:
|
||||||
if settings.DAHUA_ENABLED and dhClient:
|
dahua_data = HrmService.sync_dahua_employee(ep=instance)
|
||||||
dahua_data = HrmService.sync_dahua_employee(ep=instance)
|
third_info = instance.third_info
|
||||||
third_info = instance.third_info
|
third_info.update(dahua_data)
|
||||||
third_info.update(dahua_data)
|
instance.third_info = third_info
|
||||||
instance.third_info = third_info
|
instance.save()
|
||||||
instance.save()
|
return instance
|
||||||
return instance
|
|
||||||
|
|
||||||
def update(self, instance, validated_data):
|
def update(self, instance, validated_data):
|
||||||
with transaction.atomic():
|
old_photo = instance.photo
|
||||||
old_photo = instance.photo
|
instance = super().update(instance, validated_data)
|
||||||
instance = super().update(instance, validated_data)
|
if settings.DAHUA_ENABLED and dhClient:
|
||||||
if settings.DAHUA_ENABLED and dhClient:
|
dahua_data = HrmService.sync_dahua_employee(ep=instance, old_photo=old_photo)
|
||||||
dahua_data = HrmService.sync_dahua_employee(ep=instance, old_photo=old_photo)
|
third_info = instance.third_info
|
||||||
third_info = instance.third_info
|
third_info.update(dahua_data)
|
||||||
third_info.update(dahua_data)
|
instance.third_info = third_info
|
||||||
instance.third_info = third_info
|
instance.save()
|
||||||
instance.save()
|
return instance
|
||||||
return instance
|
|
||||||
|
|
||||||
|
|
||||||
class ChannelAuthoritySerializer(serializers.Serializer):
|
class ChannelAuthoritySerializer(serializers.Serializer):
|
||||||
|
|
|
@ -58,25 +58,7 @@ class HrmService:
|
||||||
# 开人脸卡 长时间
|
# 开人脸卡 长时间
|
||||||
if ep.job_state in [Employee.JOB_ON] and ep.type == 'employee':
|
if ep.job_state in [Employee.JOB_ON] and ep.type == 'employee':
|
||||||
if not ep.third_info.get('dh_face_card', None):
|
if not ep.third_info.get('dh_face_card', None):
|
||||||
_, res = dhClient.request(**dhapis['card_gen_id'])
|
dh_face_card = cls.open_face_card(ep=ep, dh_id=dh_id, departmentId=departmentId)
|
||||||
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
|
|
||||||
else:
|
else:
|
||||||
_, res = dhClient.request(**dhapis['person_gen_id'])
|
_, res = dhClient.request(**dhapis['person_gen_id'])
|
||||||
dh_id = res['id']
|
dh_id = res['id']
|
||||||
|
@ -113,28 +95,34 @@ class HrmService:
|
||||||
)
|
)
|
||||||
_, res = dhClient.request(**dhapis['person_add'], json=json_data)
|
_, res = dhClient.request(**dhapis['person_add'], json=json_data)
|
||||||
# 开人脸卡
|
# 开人脸卡
|
||||||
if ep.type == 'employee':
|
if ep.job_state in [Employee.JOB_ON] and ep.type == 'employee':
|
||||||
_, res = dhClient.request(**dhapis['card_gen_id'])
|
dh_face_card = cls.open_face_card(ep=ep, dh_id=dh_id, departmentId=departmentId)
|
||||||
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']
|
|
||||||
return {'dh_id': dh_id, 'dh_photo': dh_photo, 'dh_face_card': dh_face_card}
|
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
|
@classmethod
|
||||||
def swipe(cls, data: dict):
|
def swipe(cls, data: dict):
|
||||||
"""
|
"""
|
||||||
|
|
Loading…
Reference in New Issue