correct_card_time

This commit is contained in:
caoqianming 2022-11-15 15:51:56 +08:00
parent d4e2db10f1
commit 09b6d7b182
3 changed files with 50 additions and 3 deletions

View File

@ -164,7 +164,7 @@ class TestViewSet(CustomGenericViewSet):
serializer.is_valid(raise_exception=True)
vdata = serializer.validated_data
ret = {}
task = show.delay(*vdata.get('args', []), **vdata.get('kwargs', {}))
# task = show.delay(*vdata.get('args', []), **vdata.get('kwargs', {}))
ret['task_id'] = task.task_id
# from celery.app.control import Control
# from server.celery import app
@ -382,6 +382,13 @@ class TestViewSet(CustomGenericViewSet):
res = wxClient.send_tem_msg(data=data)
return Response(res)
# @action(methods=['post'], detail=False, serializer_class=Serializer, permission_classes=[])
# @transaction.atomic
# def correct_face_card(self, request, pk=None):
# from apps.hrm.tasks import correct_card_time
# correct_card_time()
# return Response()
@action(methods=['post'], detail=False, serializer_class=Serializer, permission_classes=[])
@transaction.atomic
def correct_data(self, request, pk=None):

View File

@ -128,6 +128,7 @@ class HrmService:
"departmentId": departmentId,
}
_, res = dhClient.request(**dhapis['card_update'], json=json_data)
cls.save(ep, data={'dh_face_card_start': startDate, 'dh_face_card_end': endDate})
return cardNumber
else:
_, res = dhClient.request(**dhapis['card_gen_id'])
@ -152,7 +153,7 @@ class HrmService:
}
_, res = dhClient.request(**dhapis['card_add'], json=json_data)
time.sleep(6) # 等待确保生成卡片
cls.save(ep, data={'dh_face_card': cardNumber})
cls.save(ep, data={'dh_face_card': cardNumber, 'dh_face_card_start': startDate, 'dh_face_card_end': endDate})
return cardNumber
@classmethod

View File

@ -2,6 +2,12 @@ from __future__ import absolute_import, unicode_literals
from celery import shared_task
from apps.hrm.models import Employee
from dateutil import tz
from datetime import datetime, timedelta
from apps.third.dahua import dhClient
from apps.third.tapis import dhapis
from apps.hrm.services import HrmService
import time
@shared_task
@ -17,4 +23,37 @@ def correct_swip_task(start_time, end_time):
from apps.hrm.services import HrmService
lgs = DrfRequestLog.objects.filter(path='/api/third/dahua/c_swip/', requested_at__gte=start_time, requested_at__lte=end_time)
for i in lgs:
HrmService.swipe(data=eval(i.data))
HrmService.swipe(data=eval(i.data))
@shared_task
def correct_card_time():
tzinfo = tz.gettz('Asia/Shanghai')
s_time_f = datetime.strptime("2022-11-15 14:20:20", "%Y-%m-%d %H:%M:%S").replace(tzinfo=tzinfo)
eps = Employee.objects.filter(update_time__lte = s_time_f)
print(eps)
for ep in eps:
dh_face_card = ep.third_info.get('dh_face_card', None)
dh_face_card_end = ep.third_info.get('dh_face_card_end', None)
if dh_face_card and dh_face_card_end is None:
departmentId = 1
if ep.belong_dept:
try:
departmentId = ep.belong_dept.third_info['dh_id']
except Exception:
pass
# 获取卡片时间
_, res = dhClient.request(**dhapis['card_detail'], params={'cardNumber': dh_face_card})
time.sleep(1)
start_time_str, end_time_str = res['startDate'], res['endDate']
end_time_new = datetime.strptime(end_time_str, "%Y-%m-%d %H:%M:%S") + timedelta(hours=8)
end_time_new_str = end_time_new.strftime("%Y-%m-%d %H:%M:%S")
json_data = {
"cardNumber": dh_face_card,
"startDate": start_time_str,
"endDate": end_time_new_str,
"departmentId": departmentId,
}
_, res = dhClient.request(**dhapis['card_update'], json=json_data)
HrmService.save(ep, {'dh_face_card_start': start_time_str, 'dh_face_card_end': end_time_new_str})
print('已更新-' + ep.name + '-' + dh_face_card + '-' + end_time_new_str)
time.sleep(1)