增加目标追踪的模块
This commit is contained in:
@ -5,19 +5,16 @@
|
||||
# @IDE : PyCharm
|
||||
# @desc : 主要接口文件
|
||||
|
||||
from redis.asyncio import Redis
|
||||
from fastapi import APIRouter, Depends, Body
|
||||
from motor.motor_asyncio import AsyncIOMotorDatabase
|
||||
from core.database import redis_getter, mongo_getter
|
||||
from utils.response import SuccessResponse, ErrorResponse
|
||||
from utils.sms.code import CodeSMS
|
||||
from fastapi import APIRouter, Depends, Body, Request
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
from core.database import db_getter
|
||||
from utils.response import SuccessResponse
|
||||
from . import schemas, crud
|
||||
from core.dependencies import IdList
|
||||
from apps.vadmin.auth.utils.current import AllUserAuth, OpenAuth
|
||||
from apps.vadmin.auth.utils.current import AllUserAuth, FullAdminAuth, OpenAuth
|
||||
from apps.vadmin.auth.utils.validation.auth import Auth
|
||||
from .params import DictTypeParams, DictDetailParams, TaskParams
|
||||
from apps.vadmin.auth import crud as vadmin_auth_crud
|
||||
from .params.task import TaskRecordParams
|
||||
from .params import DictTypeParams, DictDetailParams
|
||||
|
||||
|
||||
app = APIRouter()
|
||||
|
||||
@ -99,96 +96,39 @@ async def get_dict_detail(data_id: int, auth: Auth = Depends(AllUserAuth())):
|
||||
|
||||
|
||||
###########################################################
|
||||
# 短信服务管理
|
||||
# 系统配置管理
|
||||
###########################################################
|
||||
@app.post("/sms/send", summary="发送短信验证码(阿里云服务)")
|
||||
async def sms_send(telephone: str, rd: Redis = Depends(redis_getter), auth: Auth = Depends(OpenAuth())):
|
||||
user = await vadmin_auth_crud.UserDal(auth.db).get_data(telephone=telephone, v_return_none=True)
|
||||
if not user:
|
||||
return ErrorResponse("手机号不存在!")
|
||||
sms = CodeSMS(telephone, rd)
|
||||
return SuccessResponse(await sms.main_async())
|
||||
@app.post("/settings/tabs", summary="获取系统配置标签列表")
|
||||
async def get_settings_tabs(classifys: list[str] = Body(...), auth: Auth = Depends(FullAdminAuth())):
|
||||
return SuccessResponse(await crud.SettingsTabDal(auth.db).get_datas(limit=0, classify=("in", classifys)))
|
||||
|
||||
|
||||
###########################################################
|
||||
# 定时任务管理
|
||||
###########################################################
|
||||
@app.get("/tasks", summary="获取定时任务列表")
|
||||
async def get_tasks(
|
||||
p: TaskParams = Depends(),
|
||||
db: AsyncIOMotorDatabase = Depends(mongo_getter),
|
||||
auth: Auth = Depends(AllUserAuth())
|
||||
@app.get("/settings/tabs/values", summary="获取系统配置标签下的信息")
|
||||
async def get_settings_tabs_values(tab_id: int, auth: Auth = Depends(FullAdminAuth())):
|
||||
return SuccessResponse(await crud.SettingsDal(auth.db).get_tab_values(tab_id=tab_id))
|
||||
|
||||
|
||||
@app.put("/settings/tabs/values", summary="更新系统配置信息")
|
||||
async def put_settings_tabs_values(
|
||||
request: Request,
|
||||
datas: dict = Body(...),
|
||||
auth: Auth = Depends(FullAdminAuth())
|
||||
):
|
||||
datas, count = await crud.TaskDal(db).get_tasks(**p.dict())
|
||||
return SuccessResponse(datas, count=count)
|
||||
return SuccessResponse(await crud.SettingsDal(auth.db).update_datas(datas, request))
|
||||
|
||||
|
||||
@app.post("/tasks", summary="添加定时任务")
|
||||
async def post_tasks(
|
||||
data: schemas.Task,
|
||||
db: AsyncIOMotorDatabase = Depends(mongo_getter),
|
||||
rd: Redis = Depends(redis_getter),
|
||||
auth: Auth = Depends(AllUserAuth())
|
||||
):
|
||||
return SuccessResponse(await crud.TaskDal(db).create_task(rd, data))
|
||||
@app.get("/settings/base/config", summary="获取系统基础配置", description="每次进入系统中时使用")
|
||||
async def get_setting_base_config(db: AsyncSession = Depends(db_getter)):
|
||||
return SuccessResponse(await crud.SettingsDal(db).get_base_config())
|
||||
|
||||
|
||||
@app.put("/tasks", summary="更新定时任务")
|
||||
async def put_tasks(
|
||||
_id: str,
|
||||
data: schemas.Task,
|
||||
db: AsyncIOMotorDatabase = Depends(mongo_getter),
|
||||
rd: Redis = Depends(redis_getter),
|
||||
auth: Auth = Depends(AllUserAuth())
|
||||
):
|
||||
return SuccessResponse(await crud.TaskDal(db).put_task(rd, _id, data))
|
||||
@app.get("/settings/privacy", summary="获取隐私协议")
|
||||
async def get_settings_privacy(auth: Auth = Depends(OpenAuth())):
|
||||
return SuccessResponse((await crud.SettingsDal(auth.db).get_data(config_key="web_privacy")).config_value)
|
||||
|
||||
|
||||
@app.delete("/tasks", summary="删除单个定时任务")
|
||||
async def delete_task(
|
||||
_id: str,
|
||||
db: AsyncIOMotorDatabase = Depends(mongo_getter),
|
||||
auth: Auth = Depends(AllUserAuth())
|
||||
):
|
||||
return SuccessResponse(await crud.TaskDal(db).delete_task(_id))
|
||||
@app.get("/settings/agreement", summary="获取用户协议")
|
||||
async def get_settings_agreement(auth: Auth = Depends(OpenAuth())):
|
||||
return SuccessResponse((await crud.SettingsDal(auth.db).get_data(config_key="web_agreement")).config_value)
|
||||
|
||||
|
||||
@app.get("/task", summary="获取定时任务详情")
|
||||
async def get_task(
|
||||
_id: str,
|
||||
db: AsyncIOMotorDatabase = Depends(mongo_getter),
|
||||
auth: Auth = Depends(AllUserAuth())
|
||||
):
|
||||
return SuccessResponse(await crud.TaskDal(db).get_task(_id, v_schema=schemas.TaskSimpleOut))
|
||||
|
||||
|
||||
@app.post("/task", summary="执行一次定时任务")
|
||||
async def run_once_task(
|
||||
_id: str,
|
||||
db: AsyncIOMotorDatabase = Depends(mongo_getter),
|
||||
rd: Redis = Depends(redis_getter),
|
||||
auth: Auth = Depends(AllUserAuth())
|
||||
):
|
||||
return SuccessResponse(await crud.TaskDal(db).run_once_task(rd, _id))
|
||||
|
||||
|
||||
###########################################################
|
||||
# 定时任务分组管理
|
||||
###########################################################
|
||||
@app.get("/task/group/options", summary="获取定时任务分组选择项列表")
|
||||
async def get_task_group_options(db: AsyncIOMotorDatabase = Depends(mongo_getter), auth: Auth = Depends(AllUserAuth())):
|
||||
return SuccessResponse(await crud.TaskGroupDal(db).get_datas(limit=0))
|
||||
|
||||
|
||||
###########################################################
|
||||
# 定时任务调度日志
|
||||
###########################################################
|
||||
@app.get("/task/records", summary="获取定时任务调度日志列表")
|
||||
async def get_task_records(
|
||||
p: TaskRecordParams = Depends(),
|
||||
db: AsyncIOMotorDatabase = Depends(mongo_getter),
|
||||
auth: Auth = Depends(AllUserAuth())
|
||||
):
|
||||
count = await crud.TaskRecordDal(db).get_count(**p.to_count())
|
||||
datas = await crud.TaskRecordDal(db).get_datas(**p.dict())
|
||||
return SuccessResponse(datas, count=count)
|
||||
|
Reference in New Issue
Block a user