From 62a177b7731a7d03214d5ae42a9b10f20aba1763 Mon Sep 17 00:00:00 2001 From: zty Date: Fri, 13 Dec 2024 15:29:10 +0800 Subject: [PATCH] =?UTF-8?q?feat:=E7=99=BB=E5=85=A5=20=E8=AE=B0=E5=BD=95IP?= =?UTF-8?q?=20=E5=92=8C=20=E5=A2=9E=E5=8A=A0=E6=AF=8F=E6=97=A5=E7=9A=84?= =?UTF-8?q?=E8=83=BD=E6=BA=90=E7=BB=9F=E8=AE=A1=E5=AE=9A=E6=97=B6=E4=BB=BB?= =?UTF-8?q?=E5=8A=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/auth1/views.py | 6 +++--- apps/enm/tasks.py | 23 +++++++++++++++++++++++ 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/apps/auth1/views.py b/apps/auth1/views.py index 11f29147..ecdfecd8 100755 --- a/apps/auth1/views.py +++ b/apps/auth1/views.py @@ -27,10 +27,10 @@ from apps.auth1.serializers import (CodeLoginSerializer, LoginSerializer, from apps.system.models import User from rest_framework_simplejwt.views import TokenObtainPairView from apps.auth1.authentication import get_user_by_username_or +from apps.utils.mixins import MyLoggingMixin # Create your views here. - def get_tokens_for_user(user: User): refresh = RefreshToken.for_user(user) return { @@ -38,7 +38,7 @@ def get_tokens_for_user(user: User): 'access': str(refresh.access_token), } -class TokenLoginView(CreateAPIView): +class TokenLoginView(MyLoggingMixin, CreateAPIView): """ 账户名/密码获取token @@ -61,7 +61,6 @@ class TokenLoginView(CreateAPIView): user, _ = get_user_by_username_or(vdata.get('username')) if user and cache.get(f"login_attempt_{user.id}", 0) > 3: raise ParseError("登录失败次数过多,请稍后再试") - user = authenticate(username=vdata.get('username'), password=vdata.get('password')) @@ -71,6 +70,7 @@ class TokenLoginView(CreateAPIView): return Response(token_dict) raise ParseError(**USERNAME_OR_PASSWORD_WRONG) + class TokenBlackView(APIView): permission_classes = [IsAuthenticated] diff --git a/apps/enm/tasks.py b/apps/enm/tasks.py index 55cf77d0..5773a600 100644 --- a/apps/enm/tasks.py +++ b/apps/enm/tasks.py @@ -29,6 +29,7 @@ from apps.utils.sql import DbConnection from apps.enm.services import db_insert_mplogx_batch, get_elec_level from apps.enm.xscript import main from django.core.exceptions import ObjectDoesNotExist +from django.utils.timezone import make_aware myLogger = logging.getLogger("log") @@ -130,6 +131,27 @@ def cal_mpointstats_duration(start_time: str, end_time: str, m_code_list=[], cal current_time += datetime.timedelta(hours=1) +@shared_task(base=CustomTask) +def cal_mpointstats_scheduled_tasks(m_code_list=None, cal_attrs=None): + """ + 重跑某一段时间的任务 + """ + if m_code_list is None: + m_code_list = [] + if cal_attrs is None: + cal_attrs = [] + end_time = datetime.datetime.now() + start_time = end_time - datetime.timedelta(hours=24) + start_time = make_aware(start_time) + end_time = make_aware(end_time) + current_time = start_time + while current_time <= end_time: + year, month, day, hour = current_time.year, current_time.month, current_time.day, current_time.hour + cal_mpointstats(0, year, month, day, hour, m_code_list, cal_attrs) + current_time += datetime.timedelta(hours=1) + + + @shared_task(base=CustomTask) def cal_mpointstat_hour(mpointId: str, year: int, month: int, day: int, hour: int, cascade=True, sflog_hours=[]): """ @@ -267,6 +289,7 @@ def cal_mpointstats(is_now=1, year=None, month=None, day=None, hour=None, m_code 计算所有自动采集测点的统计值,默认当前小时, 可手动传入时间和测点编号集 cal_attrs: 需要计算的属性,空列表默认计算所有属性["material", "pcoal", "run_hour"] """ + if year and month and day and hour is not None: pass else: