feat:登入 记录IP 和 增加每日的能源统计定时任务
This commit is contained in:
parent
4791716ec9
commit
62a177b773
|
@ -27,10 +27,10 @@ from apps.auth1.serializers import (CodeLoginSerializer, LoginSerializer,
|
||||||
from apps.system.models import User
|
from apps.system.models import User
|
||||||
from rest_framework_simplejwt.views import TokenObtainPairView
|
from rest_framework_simplejwt.views import TokenObtainPairView
|
||||||
from apps.auth1.authentication import get_user_by_username_or
|
from apps.auth1.authentication import get_user_by_username_or
|
||||||
|
from apps.utils.mixins import MyLoggingMixin
|
||||||
|
|
||||||
# Create your views here.
|
# Create your views here.
|
||||||
|
|
||||||
|
|
||||||
def get_tokens_for_user(user: User):
|
def get_tokens_for_user(user: User):
|
||||||
refresh = RefreshToken.for_user(user)
|
refresh = RefreshToken.for_user(user)
|
||||||
return {
|
return {
|
||||||
|
@ -38,7 +38,7 @@ def get_tokens_for_user(user: User):
|
||||||
'access': str(refresh.access_token),
|
'access': str(refresh.access_token),
|
||||||
}
|
}
|
||||||
|
|
||||||
class TokenLoginView(CreateAPIView):
|
class TokenLoginView(MyLoggingMixin, CreateAPIView):
|
||||||
"""
|
"""
|
||||||
账户名/密码获取token
|
账户名/密码获取token
|
||||||
|
|
||||||
|
@ -61,7 +61,6 @@ class TokenLoginView(CreateAPIView):
|
||||||
user, _ = get_user_by_username_or(vdata.get('username'))
|
user, _ = get_user_by_username_or(vdata.get('username'))
|
||||||
if user and cache.get(f"login_attempt_{user.id}", 0) > 3:
|
if user and cache.get(f"login_attempt_{user.id}", 0) > 3:
|
||||||
raise ParseError("登录失败次数过多,请稍后再试")
|
raise ParseError("登录失败次数过多,请稍后再试")
|
||||||
|
|
||||||
user = authenticate(username=vdata.get('username'),
|
user = authenticate(username=vdata.get('username'),
|
||||||
password=vdata.get('password'))
|
password=vdata.get('password'))
|
||||||
|
|
||||||
|
@ -71,6 +70,7 @@ class TokenLoginView(CreateAPIView):
|
||||||
return Response(token_dict)
|
return Response(token_dict)
|
||||||
raise ParseError(**USERNAME_OR_PASSWORD_WRONG)
|
raise ParseError(**USERNAME_OR_PASSWORD_WRONG)
|
||||||
|
|
||||||
|
|
||||||
class TokenBlackView(APIView):
|
class TokenBlackView(APIView):
|
||||||
permission_classes = [IsAuthenticated]
|
permission_classes = [IsAuthenticated]
|
||||||
|
|
||||||
|
|
|
@ -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.services import db_insert_mplogx_batch, get_elec_level
|
||||||
from apps.enm.xscript import main
|
from apps.enm.xscript import main
|
||||||
from django.core.exceptions import ObjectDoesNotExist
|
from django.core.exceptions import ObjectDoesNotExist
|
||||||
|
from django.utils.timezone import make_aware
|
||||||
myLogger = logging.getLogger("log")
|
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)
|
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)
|
@shared_task(base=CustomTask)
|
||||||
def cal_mpointstat_hour(mpointId: str, year: int, month: int, day: int, hour: int, cascade=True, sflog_hours=[]):
|
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"]
|
cal_attrs: 需要计算的属性,空列表默认计算所有属性["material", "pcoal", "run_hour"]
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if year and month and day and hour is not None:
|
if year and month and day and hour is not None:
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
|
|
Loading…
Reference in New Issue