From d4e2db10f10ce8f7090bf825a5d09c4d254ca6fe Mon Sep 17 00:00:00 2001 From: caoqianming Date: Tue, 15 Nov 2022 14:22:08 +0800 Subject: [PATCH] =?UTF-8?q?=E5=90=8C=E6=AD=A5=E9=97=A8=E7=A6=81=E6=97=B6?= =?UTF-8?q?=E9=97=B4=E8=8C=83=E5=9B=B4bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/hrm/serializers.py | 3 ++- apps/hrm/services.py | 10 +++++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/apps/hrm/serializers.py b/apps/hrm/serializers.py index b0a0c39f..4b867100 100755 --- a/apps/hrm/serializers.py +++ b/apps/hrm/serializers.py @@ -4,6 +4,7 @@ from rest_framework import serializers from apps.ecm.service import get_ep_default from apps.hrm.services import HrmService from apps.utils.fields import MyFilePathField +from django.utils import timezone from apps.utils.serializers import CustomModelSerializer @@ -84,7 +85,7 @@ class EmployeeCreateUpdateSerializer(CustomModelSerializer): # 同时去除门禁授权 if settings.DAHUA_ENABLED and dhClient: # 如果是正式员工或相关方且有门禁权限: - now = datetime.now() + now = timezone.now() if instance.type in ['employee', 'remployee']: start_time = None end_time = None diff --git a/apps/hrm/services.py b/apps/hrm/services.py index 8ffa61cc..8b2f422c 100755 --- a/apps/hrm/services.py +++ b/apps/hrm/services.py @@ -119,8 +119,8 @@ class HrmService: if start_time is None: # 如果时间段未提供,跳过更新操作 pass else: - startDate = start_time.strftime("%Y-%m-%d %H:%M:%S") - endDate = end_time.strftime("%Y-%m-%d %H:%M:%S") + startDate = timezone.localtime(start_time).strftime("%Y-%m-%d %H:%M:%S") + endDate = timezone.localtime(end_time).strftime("%Y-%m-%d %H:%M:%S") json_data = { "cardNumber": cardNumber, "startDate": startDate, @@ -133,13 +133,13 @@ class HrmService: _, res = dhClient.request(**dhapis['card_gen_id']) cardId = res['id'] cardNumber = str(ep.id)[3:8] + rannum(5) - now = datetime.now() if start_time is None: # 如果未规定时间范围, 默认1小时 + now = datetime.now() startDate = now.strftime("%Y-%m-%d %H:%M:%S") endDate = (now+timedelta(minutes=60)).strftime("%Y-%m-%d %H:%M:%S") else: - startDate = start_time.strftime("%Y-%m-%d %H:%M:%S") - endDate = end_time.strftime("%Y-%m-%d %H:%M:%S") + startDate = timezone.localtime(start_time).strftime("%Y-%m-%d %H:%M:%S") + endDate = timezone.localtime(end_time).strftime("%Y-%m-%d %H:%M:%S") json_data = { "id": cardId, "cardNumber": cardNumber,