Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
D
db_gpt
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
linyangyang
db_gpt
Commits
8b0030b8
Commit
8b0030b8
authored
Aug 12, 2024
by
林洋洋
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
字典表添加 接口路由地址修改
parent
7d2c55f2
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
443 additions
and
403 deletions
+443
-403
crud.py
dbgpt/app/apps/system/crud.py
+185
-185
views.py
dbgpt/app/apps/system/views.py
+177
-177
login.py
dbgpt/app/apps/vadmin/auth/utils/login.py
+41
-3
views.py
dbgpt/app/apps/vadmin/auth/views.py
+36
-36
dbgpt_server.py
dbgpt/app/dbgpt_server.py
+4
-2
No files found.
dbgpt/app/apps/system/crud.py
View file @
8b0030b8
#
#
!/usr/bin/python
#!/usr/bin/python
#
#
-*- coding: utf-8 -*-
# -*- coding: utf-8 -*-
#
#
@version : 1.0
# @version : 1.0
#
#
@Create Time : 2021/10/18 22:18
# @Create Time : 2021/10/18 22:18
#
#
@File : crud.py
# @File : crud.py
#
#
@IDE : PyCharm
# @IDE : PyCharm
#
#
@desc : 数据库 增删改查操作
# @desc : 数据库 增删改查操作
#
#
import json
import
json
#
import os
import
os
#
from enum import Enum
from
enum
import
Enum
#
from typing import Any
from
typing
import
Any
#
from redis.asyncio import Redis
from
redis.asyncio
import
Redis
#
from fastapi.encoders import jsonable_encoder
from
fastapi.encoders
import
jsonable_encoder
#
from motor.motor_asyncio import AsyncIOMotorDatabase
from
motor.motor_asyncio
import
AsyncIOMotorDatabase
#
from sqlalchemy import select, update
from
sqlalchemy
import
select
,
update
#
from sqlalchemy.ext.asyncio import AsyncSession
from
sqlalchemy.ext.asyncio
import
AsyncSession
#
from sqlalchemy.orm import joinedload
from
sqlalchemy.orm
import
joinedload
#
from dbgpt.app.apps.config.settings import STATIC_ROOT, SUBSCRIBE
from
dbgpt.app.apps.config.settings
import
STATIC_ROOT
,
SUBSCRIBE
#
from dbgpt.app.apps.core.database import redis_getter
from
dbgpt.app.apps.core.database
import
redis_getter
#
from dbgpt.app.apps.utils.file.file_manage import FileManage
from
dbgpt.app.apps.utils.file.file_manage
import
FileManage
#
from . import models, schemas
from
.
import
models
,
schemas
#
from dbgpt.app.apps.core.crud import DalBase
from
dbgpt.app.apps.core.crud
import
DalBase
#
from dbgpt.app.apps.core.exception import CustomException
from
dbgpt.app.apps.core.exception
import
CustomException
#
from dbgpt.app.apps.utils import status
from
dbgpt.app.apps.utils
import
status
#
from fastapi import Request
from
fastapi
import
Request
#
#
#
class DictTypeDal(DalBase):
class
DictTypeDal
(
DalBase
):
#
#
def __init__(self, db: AsyncSession):
def
__init__
(
self
,
db
:
AsyncSession
):
#
super(DictTypeDal, self).__init__()
super
(
DictTypeDal
,
self
)
.
__init__
()
#
self.db = db
self
.
db
=
db
#
self.model = models.VadminDictType
self
.
model
=
models
.
VadminDictType
#
self.schema = schemas.DictTypeSimpleOut
self
.
schema
=
schemas
.
DictTypeSimpleOut
#
#
async def get_dicts_details(self, dict_types: list[str]) -> dict:
async
def
get_dicts_details
(
self
,
dict_types
:
list
[
str
])
->
dict
:
#
"""
"""
#
获取多个字典类型下的字典元素列表
获取多个字典类型下的字典元素列表
#
"""
"""
#
data = {}
data
=
{}
#
options = [joinedload(self.model.details)]
options
=
[
joinedload
(
self
.
model
.
details
)]
#
objs = await DictTypeDal(self.db).get_datas(
objs
=
await
DictTypeDal
(
self
.
db
)
.
get_datas
(
#
limit=0,
limit
=
0
,
#
v_return_objs=True,
v_return_objs
=
True
,
#
v_options=options,
v_options
=
options
,
#
dict_type=("in", dict_types)
dict_type
=
(
"in"
,
dict_types
)
#
)
)
#
for obj in objs:
for
obj
in
objs
:
#
if not obj:
if
not
obj
:
#
data[obj.dict_type] = []
data
[
obj
.
dict_type
]
=
[]
#
continue
continue
#
else:
else
:
#
data[obj.dict_type] = [schemas.DictDetailsSimpleOut.model_validate(i).model_dump() for i in obj.details]
data
[
obj
.
dict_type
]
=
[
schemas
.
DictDetailsSimpleOut
.
model_validate
(
i
)
.
model_dump
()
for
i
in
obj
.
details
]
#
return data
return
data
#
#
async def get_select_datas(self) -> list:
async
def
get_select_datas
(
self
)
->
list
:
#
"""获取选择数据,全部数据"""
"""获取选择数据,全部数据"""
#
sql = select(self.model)
sql
=
select
(
self
.
model
)
#
queryset = await self.db.execute(sql)
queryset
=
await
self
.
db
.
execute
(
sql
)
#
return [schemas.DictTypeOptionsOut.model_validate(i).model_dump() for i in queryset.scalars().all()]
return
[
schemas
.
DictTypeOptionsOut
.
model_validate
(
i
)
.
model_dump
()
for
i
in
queryset
.
scalars
()
.
all
()]
#
#
#
class DictDetailsDal(DalBase):
class
DictDetailsDal
(
DalBase
):
#
#
def __init__(self, db: AsyncSession):
def
__init__
(
self
,
db
:
AsyncSession
):
#
super(DictDetailsDal, self).__init__()
super
(
DictDetailsDal
,
self
)
.
__init__
()
#
self.db = db
self
.
db
=
db
#
self.model = models.VadminDictDetails
self
.
model
=
models
.
VadminDictDetails
#
self.schema = schemas.DictDetailsSimpleOut
self
.
schema
=
schemas
.
DictDetailsSimpleOut
#
#
#
class SettingsDal(DalBase):
class
SettingsDal
(
DalBase
):
#
#
def __init__(self, db: AsyncSession):
def
__init__
(
self
,
db
:
AsyncSession
):
#
super(SettingsDal, self).__init__()
super
(
SettingsDal
,
self
)
.
__init__
()
#
self.db = db
self
.
db
=
db
#
self.model = models.VadminSystemSettings
self
.
model
=
models
.
VadminSystemSettings
#
self.schema = schemas.SettingsSimpleOut
self
.
schema
=
schemas
.
SettingsSimpleOut
#
#
async def get_tab_values(self, tab_id: int) -> dict:
async
def
get_tab_values
(
self
,
tab_id
:
int
)
->
dict
:
#
"""
"""
#
获取系统配置标签下的信息
获取系统配置标签下的信息
#
"""
"""
#
datas = await self.get_datas(limit=0, tab_id=tab_id, v_return_objs=True)
datas
=
await
self
.
get_datas
(
limit
=
0
,
tab_id
=
tab_id
,
v_return_objs
=
True
)
#
result = {}
result
=
{}
#
for data in datas:
for
data
in
datas
:
#
if not data.disabled:
if
not
data
.
disabled
:
#
result[data.config_key] = data.config_value
result
[
data
.
config_key
]
=
data
.
config_value
#
return result
return
result
#
#
async def update_datas(self, datas: dict, request: Request) -> None:
async
def
update_datas
(
self
,
datas
:
dict
,
request
:
Request
)
->
None
:
#
"""
"""
#
更新系统配置信息
更新系统配置信息
#
#
更新ico图标步骤:先将文件上传到本地,然后点击提交后,获取到文件地址,将上传的新文件覆盖原有文件
更新ico图标步骤:先将文件上传到本地,然后点击提交后,获取到文件地址,将上传的新文件覆盖原有文件
#
原因:ico图标的路径是在前端的index.html中固定的,所以目前只能改变图片,不改变路径
原因:ico图标的路径是在前端的index.html中固定的,所以目前只能改变图片,不改变路径
#
"""
"""
#
for key, value in datas.items():
for
key
,
value
in
datas
.
items
():
#
if key == "web_ico":
if
key
==
"web_ico"
:
#
continue
continue
#
elif key == "web_ico_local_path":
elif
key
==
"web_ico_local_path"
:
#
if not value:
if
not
value
:
#
continue
continue
#
ico = await self.get_data(config_key="web_ico", tab_id=1)
ico
=
await
self
.
get_data
(
config_key
=
"web_ico"
,
tab_id
=
1
)
#
web_ico = datas.get("web_ico")
web_ico
=
datas
.
get
(
"web_ico"
)
#
if ico.config_value == web_ico:
if
ico
.
config_value
==
web_ico
:
#
continue
continue
#
# 将上传的ico路径替换到static/system/favicon.ico文件
# 将上传的ico路径替换到static/system/favicon.ico文件
#
await FileManage.async_copy_file(value, os.path.join(STATIC_ROOT, "system/favicon.ico"))
await
FileManage
.
async_copy_file
(
value
,
os
.
path
.
join
(
STATIC_ROOT
,
"system/favicon.ico"
))
#
sql = update(self.model).where(self.model.config_key == "web_ico").values(config_value=web_ico)
sql
=
update
(
self
.
model
)
.
where
(
self
.
model
.
config_key
==
"web_ico"
)
.
values
(
config_value
=
web_ico
)
#
await self.db.execute(sql)
await
self
.
db
.
execute
(
sql
)
#
else:
else
:
#
sql = update(self.model).where(self.model.config_key == str(key)).values(config_value=value)
sql
=
update
(
self
.
model
)
.
where
(
self
.
model
.
config_key
==
str
(
key
))
.
values
(
config_value
=
value
)
#
await self.db.execute(sql)
await
self
.
db
.
execute
(
sql
)
#
if "wx_server_app_id" in datas :
if
"wx_server_app_id"
in
datas
:
#
rd = redis_getter(request)
rd
=
redis_getter
(
request
)
#
await rd.client().set("wx_server", json.dumps(datas))
await
rd
.
client
()
.
set
(
"wx_server"
,
json
.
dumps
(
datas
))
#
elif "sms_access_key" in datas :
elif
"sms_access_key"
in
datas
:
#
rd = redis_getter(request)
rd
=
redis_getter
(
request
)
#
await rd.client().set('aliyun_sms', json.dumps(datas))
await
rd
.
client
()
.
set
(
'aliyun_sms'
,
json
.
dumps
(
datas
))
#
#
async def get_base_config(self) -> dict:
async
def
get_base_config
(
self
)
->
dict
:
#
"""
"""
#
获取系统基本信息
获取系统基本信息
#
"""
"""
#
ignore_configs = ["wx_server_app_id", "wx_server_app_secret"]
ignore_configs
=
[
"wx_server_app_id"
,
"wx_server_app_secret"
]
#
datas = await self.get_datas(limit=0, tab_id=("in", ["1", "9"]), disabled=False, v_return_objs=True)
datas
=
await
self
.
get_datas
(
limit
=
0
,
tab_id
=
(
"in"
,
[
"1"
,
"9"
]),
disabled
=
False
,
v_return_objs
=
True
)
#
result = {}
result
=
{}
#
for config in datas:
for
config
in
datas
:
#
if config.config_key not in ignore_configs:
if
config
.
config_key
not
in
ignore_configs
:
#
result[config.config_key] = config.config_value
result
[
config
.
config_key
]
=
config
.
config_value
#
return result
return
result
#
#
#
class SettingsTabDal(DalBase):
class
SettingsTabDal
(
DalBase
):
#
#
def __init__(self, db: AsyncSession):
def
__init__
(
self
,
db
:
AsyncSession
):
#
super(SettingsTabDal, self).__init__(db, models.VadminSystemSettingsTab, schemas.SettingsTabSimpleOut)
super
(
SettingsTabDal
,
self
)
.
__init__
(
db
,
models
.
VadminSystemSettingsTab
,
schemas
.
SettingsTabSimpleOut
)
#
#
async def get_classify_tab_values(self, classify: list[str], hidden: bool | None = False) -> dict:
async
def
get_classify_tab_values
(
self
,
classify
:
list
[
str
],
hidden
:
bool
|
None
=
False
)
->
dict
:
#
"""
"""
#
获取系统配置分类下的标签信息
获取系统配置分类下的标签信息
#
"""
"""
#
model = models.VadminSystemSettingsTab
model
=
models
.
VadminSystemSettingsTab
#
options = [joinedload(model.settings)]
options
=
[
joinedload
(
model
.
settings
)]
#
datas = await self.get_datas(
datas
=
await
self
.
get_datas
(
#
limit=0,
limit
=
0
,
#
v_options=options,
v_options
=
options
,
#
classify=("in", classify),
classify
=
(
"in"
,
classify
),
#
disabled=False,
disabled
=
False
,
#
v_return_objs=True,
v_return_objs
=
True
,
#
hidden=hidden
hidden
=
hidden
#
)
)
#
return self.__generate_values(datas)
return
self
.
__generate_values
(
datas
)
#
#
async def get_tab_name_values(self, tab_names: list[str], hidden: bool | None = False) -> dict:
async
def
get_tab_name_values
(
self
,
tab_names
:
list
[
str
],
hidden
:
bool
|
None
=
False
)
->
dict
:
#
"""
"""
#
获取系统配置标签下的标签信息
获取系统配置标签下的标签信息
#
"""
"""
#
model = models.VadminSystemSettingsTab
model
=
models
.
VadminSystemSettingsTab
#
options = [joinedload(model.settings)]
options
=
[
joinedload
(
model
.
settings
)]
#
datas = await self.get_datas(
datas
=
await
self
.
get_datas
(
#
limit=0,
limit
=
0
,
#
v_options=options,
v_options
=
options
,
#
tab_name=("in", tab_names),
tab_name
=
(
"in"
,
tab_names
),
#
disabled=False,
disabled
=
False
,
#
v_return_objs=True,
v_return_objs
=
True
,
#
hidden=hidden
hidden
=
hidden
#
)
)
#
return self.__generate_values(datas)
return
self
.
__generate_values
(
datas
)
#
#
@classmethod
@
classmethod
#
def __generate_values(cls, datas: list[models.VadminSystemSettingsTab]) -> dict:
def
__generate_values
(
cls
,
datas
:
list
[
models
.
VadminSystemSettingsTab
])
->
dict
:
#
"""
"""
#
生成字典值
生成字典值
#
"""
"""
#
return {
return
{
#
tab.tab_name: {
tab
.
tab_name
:
{
#
item.config_key: item.config_value
item
.
config_key
:
item
.
config_value
#
for item in tab.settings
for
item
in
tab
.
settings
#
if not item.disabled
if
not
item
.
disabled
#
}
}
#
for tab in datas
for
tab
in
datas
#
}
}
#
#
#
#
# class TaskDal(MongoManage):
# class TaskDal(MongoManage):
...
...
dbgpt/app/apps/system/views.py
View file @
8b0030b8
#
#
-*- coding: utf-8 -*-
# -*- coding: utf-8 -*-
#
#
@version : 1.0
# @version : 1.0
#
#
@Create Time : 2021/10/24 16:44
# @Create Time : 2021/10/24 16:44
#
#
@File : views.py
# @File : views.py
#
#
@IDE : PyCharm
# @IDE : PyCharm
#
#
@desc : 主要接口文件
# @desc : 主要接口文件
#
#
from redis.asyncio import Redis
from
redis.asyncio
import
Redis
#
from fastapi import APIRouter, Depends, Body, UploadFile, Form, Request
from
fastapi
import
APIRouter
,
Depends
,
Body
,
UploadFile
,
Form
,
Request
#
from motor.motor_asyncio import AsyncIOMotorDatabase
from
motor.motor_asyncio
import
AsyncIOMotorDatabase
#
from sqlalchemy.ext.asyncio import AsyncSession
from
sqlalchemy.ext.asyncio
import
AsyncSession
# from application.settings import ALIYUN_OSS
# from application.settings import ALIYUN_OSS
# from dbgpt.app.apps.core.database import db_getter, redis_getter, mongo
_getter
from
dbgpt.app.apps.core.database
import
db_getter
,
redis
_getter
# from dbgpt.app.apps.utils.file.aliyun_oss import AliyunOSS, BucketConf
# from dbgpt.app.apps.utils.file.aliyun_oss import AliyunOSS, BucketConf
#
from dbgpt.app.apps.utils.file.file_manage import FileManage
from
dbgpt.app.apps.utils.file.file_manage
import
FileManage
#
from dbgpt.app.apps.utils.response import SuccessResponse, ErrorResponse
from
dbgpt.app.apps.utils.response
import
SuccessResponse
,
ErrorResponse
# from dbgpt.app.apps.utils.sms.code import CodeSMS
# from dbgpt.app.apps.utils.sms.code import CodeSMS
#
from . import schemas, crud
from
.
import
schemas
,
crud
#
from dbgpt.app.apps.core.dependencies import IdList
from
dbgpt.app.apps.core.dependencies
import
IdList
# from dbgpt.app.apps
.apps.vadmin.auth.utils.current import AllUserAuth, FullAdminAuth, OpenAuth
from
dbgpt.app
.apps.vadmin.auth.utils.current
import
AllUserAuth
,
FullAdminAuth
,
OpenAuth
# from dbgpt.app.apps
.apps.vadmin.auth.utils.validation.auth import Auth
from
dbgpt.app
.apps.vadmin.auth.utils.validation.auth
import
Auth
#
from .params import DictTypeParams, DictDetailParams, TaskParams
from
.params
import
DictTypeParams
,
DictDetailParams
,
TaskParams
# from dbgpt.app.apps
.apps.vadmin.auth import crud as vadmin_auth_crud
from
dbgpt.app
.apps.vadmin.auth
import
crud
as
vadmin_auth_crud
#
from .params.task import TaskRecordParams
from
.params.task
import
TaskRecordParams
#
# app
= APIRouter()
router
=
APIRouter
()
#
#
#
#
##########################################################
###########################################################
#
#
字典类型管理
# 字典类型管理
#
#
##########################################################
###########################################################
# @app
.get("/dict/types", summary="获取字典类型列表")
@
router
.
get
(
"/dict/types"
,
summary
=
"获取字典类型列表"
)
#
async def get_dict_types(p: DictTypeParams = Depends(), auth: Auth = Depends(AllUserAuth())):
async
def
get_dict_types
(
p
:
DictTypeParams
=
Depends
(),
auth
:
Auth
=
Depends
(
AllUserAuth
())):
#
datas, count = await crud.DictTypeDal(auth.db).get_datas(**p.dict(), v_return_count=True)
datas
,
count
=
await
crud
.
DictTypeDal
(
auth
.
db
)
.
get_datas
(
**
p
.
dict
(),
v_return_count
=
True
)
#
return SuccessResponse(datas, count=count)
return
SuccessResponse
(
datas
,
count
=
count
)
#
#
# @app
.post("/dict/types", summary="创建字典类型")
@
router
.
post
(
"/dict/types"
,
summary
=
"创建字典类型"
)
#
async def create_dict_types(data: schemas.DictType, auth: Auth = Depends(AllUserAuth())):
async
def
create_dict_types
(
data
:
schemas
.
DictType
,
auth
:
Auth
=
Depends
(
AllUserAuth
())):
#
return SuccessResponse(await crud.DictTypeDal(auth.db).create_data(data=data))
return
SuccessResponse
(
await
crud
.
DictTypeDal
(
auth
.
db
)
.
create_data
(
data
=
data
))
#
#
# @app
.delete("/dict/types", summary="批量删除字典类型")
@
router
.
delete
(
"/dict/types"
,
summary
=
"批量删除字典类型"
)
#
async def delete_dict_types(ids: IdList = Depends(), auth: Auth = Depends(AllUserAuth())):
async
def
delete_dict_types
(
ids
:
IdList
=
Depends
(),
auth
:
Auth
=
Depends
(
AllUserAuth
())):
#
await crud.DictTypeDal(auth.db).delete_datas(ids=ids.ids)
await
crud
.
DictTypeDal
(
auth
.
db
)
.
delete_datas
(
ids
=
ids
.
ids
)
#
return SuccessResponse("删除成功")
return
SuccessResponse
(
"删除成功"
)
#
#
# @app
.post("/dict/types/details", summary="获取多个字典类型下的字典元素列表")
@
router
.
post
(
"/dict/types/details"
,
summary
=
"获取多个字典类型下的字典元素列表"
)
#
async def post_dicts_details(
async
def
post_dicts_details
(
#
auth: Auth = Depends(AllUserAuth()),
auth
:
Auth
=
Depends
(
AllUserAuth
()),
#
dict_types: list[str] = Body(None, title="字典元素列表", description="查询字典元素列表")
dict_types
:
list
[
str
]
=
Body
(
None
,
title
=
"字典元素列表"
,
description
=
"查询字典元素列表"
)
#
):
):
#
datas = await crud.DictTypeDal(auth.db).get_dicts_details(dict_types)
datas
=
await
crud
.
DictTypeDal
(
auth
.
db
)
.
get_dicts_details
(
dict_types
)
#
return SuccessResponse(datas)
return
SuccessResponse
(
datas
)
#
#
# @app
.get("/dict/types/options", summary="获取字典类型选择项")
@
router
.
get
(
"/dict/types/options"
,
summary
=
"获取字典类型选择项"
)
#
async def get_dicts_options(auth: Auth = Depends(AllUserAuth())):
async
def
get_dicts_options
(
auth
:
Auth
=
Depends
(
AllUserAuth
())):
#
return SuccessResponse(await crud.DictTypeDal(auth.db).get_select_datas())
return
SuccessResponse
(
await
crud
.
DictTypeDal
(
auth
.
db
)
.
get_select_datas
())
#
#
# @app
.put("/dict/types/{data_id}", summary="更新字典类型")
@
router
.
put
(
"/dict/types/{data_id}"
,
summary
=
"更新字典类型"
)
#
async def put_dict_types(data_id: int, data: schemas.DictType, auth: Auth = Depends(AllUserAuth())):
async
def
put_dict_types
(
data_id
:
int
,
data
:
schemas
.
DictType
,
auth
:
Auth
=
Depends
(
AllUserAuth
())):
#
return SuccessResponse(await crud.DictTypeDal(auth.db).put_data(data_id, data))
return
SuccessResponse
(
await
crud
.
DictTypeDal
(
auth
.
db
)
.
put_data
(
data_id
,
data
))
#
#
# @app
.get("/dict/types/{data_id}", summary="获取字典类型详细")
@
router
.
get
(
"/dict/types/{data_id}"
,
summary
=
"获取字典类型详细"
)
#
async def get_dict_type(data_id: int, auth: Auth = Depends(AllUserAuth())):
async
def
get_dict_type
(
data_id
:
int
,
auth
:
Auth
=
Depends
(
AllUserAuth
())):
#
schema = schemas.DictTypeSimpleOut
schema
=
schemas
.
DictTypeSimpleOut
#
return SuccessResponse(await crud.DictTypeDal(auth.db).get_data(data_id, v_schema=schema))
return
SuccessResponse
(
await
crud
.
DictTypeDal
(
auth
.
db
)
.
get_data
(
data_id
,
v_schema
=
schema
))
#
#
#
#
##########################################################
###########################################################
#
#
字典元素管理
# 字典元素管理
#
#
##########################################################
###########################################################
# @app
.post("/dict/details", summary="创建字典元素")
@
router
.
post
(
"/dict/details"
,
summary
=
"创建字典元素"
)
#
async def create_dict_details(data: schemas.DictDetails, auth: Auth = Depends(AllUserAuth())):
async
def
create_dict_details
(
data
:
schemas
.
DictDetails
,
auth
:
Auth
=
Depends
(
AllUserAuth
())):
#
return SuccessResponse(await crud.DictDetailsDal(auth.db).create_data(data=data))
return
SuccessResponse
(
await
crud
.
DictDetailsDal
(
auth
.
db
)
.
create_data
(
data
=
data
))
#
#
# @app
.get("/dict/details", summary="获取单个字典类型下的字典元素列表,分页")
@
router
.
get
(
"/dict/details"
,
summary
=
"获取单个字典类型下的字典元素列表,分页"
)
#
async def get_dict_details(params: DictDetailParams = Depends(), auth: Auth = Depends(AllUserAuth())):
async
def
get_dict_details
(
params
:
DictDetailParams
=
Depends
(),
auth
:
Auth
=
Depends
(
AllUserAuth
())):
#
datas, count = await crud.DictDetailsDal(auth.db).get_datas(**params.dict(), v_return_count=True)
datas
,
count
=
await
crud
.
DictDetailsDal
(
auth
.
db
)
.
get_datas
(
**
params
.
dict
(),
v_return_count
=
True
)
#
return SuccessResponse(datas, count=count)
return
SuccessResponse
(
datas
,
count
=
count
)
#
#
# @app
.delete("/dict/details", summary="批量删除字典元素", description="硬删除")
@
router
.
delete
(
"/dict/details"
,
summary
=
"批量删除字典元素"
,
description
=
"硬删除"
)
#
async def delete_dict_details(ids: IdList = Depends(), auth: Auth = Depends(AllUserAuth())):
async
def
delete_dict_details
(
ids
:
IdList
=
Depends
(),
auth
:
Auth
=
Depends
(
AllUserAuth
())):
#
await crud.DictDetailsDal(auth.db).delete_datas(ids.ids, v_soft=False)
await
crud
.
DictDetailsDal
(
auth
.
db
)
.
delete_datas
(
ids
.
ids
,
v_soft
=
False
)
#
return SuccessResponse("删除成功")
return
SuccessResponse
(
"删除成功"
)
#
#
# @app
.put("/dict/details/{data_id}", summary="更新字典元素")
@
router
.
put
(
"/dict/details/{data_id}"
,
summary
=
"更新字典元素"
)
#
async def put_dict_details(data_id: int, data: schemas.DictDetails, auth: Auth = Depends(AllUserAuth())):
async
def
put_dict_details
(
data_id
:
int
,
data
:
schemas
.
DictDetails
,
auth
:
Auth
=
Depends
(
AllUserAuth
())):
#
return SuccessResponse(await crud.DictDetailsDal(auth.db).put_data(data_id, data))
return
SuccessResponse
(
await
crud
.
DictDetailsDal
(
auth
.
db
)
.
put_data
(
data_id
,
data
))
#
#
# @app
.get("/dict/details/{data_id}", summary="获取字典元素详情")
@
router
.
get
(
"/dict/details/{data_id}"
,
summary
=
"获取字典元素详情"
)
#
async def get_dict_detail(data_id: int, auth: Auth = Depends(AllUserAuth())):
async
def
get_dict_detail
(
data_id
:
int
,
auth
:
Auth
=
Depends
(
AllUserAuth
())):
#
schema = schemas.DictDetailsSimpleOut
schema
=
schemas
.
DictDetailsSimpleOut
#
return SuccessResponse(await crud.DictDetailsDal(auth.db).get_data(data_id, v_schema=schema))
return
SuccessResponse
(
await
crud
.
DictDetailsDal
(
auth
.
db
)
.
get_data
(
data_id
,
v_schema
=
schema
))
#
#
# ###########################################################
# ###########################################################
# # 文件上传管理
# # 文件上传管理
# ###########################################################
# ###########################################################
# @
app
.post("/upload/image/to/oss", summary="上传图片到阿里云OSS")
# @
router
.post("/upload/image/to/oss", summary="上传图片到阿里云OSS")
# async def upload_image_to_oss(file: UploadFile, path: str = Form(...)):
# async def upload_image_to_oss(file: UploadFile, path: str = Form(...)):
# result = await AliyunOSS(BucketConf(**ALIYUN_OSS)).upload_image(path, file)
# result = await AliyunOSS(BucketConf(**ALIYUN_OSS)).upload_image(path, file)
# return SuccessResponse(result)
# return SuccessResponse(result)
#
#
# @app
.post("/upload/video/to/oss", summary="上传视频到阿里云OSS")
@
router
.
post
(
"/upload/video/to/oss"
,
summary
=
"上传视频到阿里云OSS"
)
#
async def upload_video_to_oss(file: UploadFile, path: str = Form(...)):
async
def
upload_video_to_oss
(
file
:
UploadFile
,
path
:
str
=
Form
(
...
)):
#
result = await AliyunOSS(BucketConf(**ALIYUN_OSS)).upload_video(path, file)
result
=
await
AliyunOSS
(
BucketConf
(
**
ALIYUN_OSS
))
.
upload_video
(
path
,
file
)
#
return SuccessResponse(result)
return
SuccessResponse
(
result
)
#
#
# @app
.post("/upload/file/to/oss", summary="上传文件到阿里云OSS")
@
router
.
post
(
"/upload/file/to/oss"
,
summary
=
"上传文件到阿里云OSS"
)
#
async def upload_file_to_oss(file: UploadFile, path: str = Form(...)):
async
def
upload_file_to_oss
(
file
:
UploadFile
,
path
:
str
=
Form
(
...
)):
#
result = await AliyunOSS(BucketConf(**ALIYUN_OSS)).upload_file(path, file)
result
=
await
AliyunOSS
(
BucketConf
(
**
ALIYUN_OSS
))
.
upload_file
(
path
,
file
)
#
return SuccessResponse(result)
return
SuccessResponse
(
result
)
#
#
# @app
.post("/upload/image/to/local", summary="上传图片到本地")
@
router
.
post
(
"/upload/image/to/local"
,
summary
=
"上传图片到本地"
)
#
async def upload_image_to_local(file: UploadFile, path: str = Form(...)):
async
def
upload_image_to_local
(
file
:
UploadFile
,
path
:
str
=
Form
(
...
)):
#
manage = FileManage(file, path)
manage
=
FileManage
(
file
,
path
)
#
path = await manage.save_image_local()
path
=
await
manage
.
save_image_local
()
#
return SuccessResponse(path)
return
SuccessResponse
(
path
)
#
#
#
#
##########################################################
###########################################################
#
#
短信服务管理
# 短信服务管理
#
#
##########################################################
###########################################################
# @
app
.post("/sms/send", summary="发送短信验证码(阿里云服务)")
# @
router
.post("/sms/send", summary="发送短信验证码(阿里云服务)")
# async def sms_send(telephone: str, rd: Redis = Depends(redis_getter), auth: Auth = Depends(OpenAuth())):
# 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)
# user = await vadmin_auth_crud.UserDal(auth.db).get_data(telephone=telephone, v_return_none=True)
# if not user:
# if not user:
# return ErrorResponse("手机号不存在!")
# return ErrorResponse("手机号不存在!")
# sms = CodeSMS(telephone, rd)
# sms = CodeSMS(telephone, rd)
# return SuccessResponse(await sms.main_async())
# return SuccessResponse(await sms.main_async())
#
#
#
#
##########################################################
###########################################################
#
#
系统配置管理
# 系统配置管理
#
#
##########################################################
###########################################################
# @app
.post("/settings/tabs", summary="获取系统配置标签列表")
@
router
.
post
(
"/settings/tabs"
,
summary
=
"获取系统配置标签列表"
)
#
async def get_settings_tabs(classifys: list[str] = Body(...), auth: Auth = Depends(FullAdminAuth())):
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)))
return
SuccessResponse
(
await
crud
.
SettingsTabDal
(
auth
.
db
)
.
get_datas
(
limit
=
0
,
classify
=
(
"in"
,
classifys
)))
#
#
# @app
.get("/settings/tabs/values", summary="获取系统配置标签下的信息")
@
router
.
get
(
"/settings/tabs/values"
,
summary
=
"获取系统配置标签下的信息"
)
#
async def get_settings_tabs_values(tab_id: int, auth: Auth = Depends(FullAdminAuth())):
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))
return
SuccessResponse
(
await
crud
.
SettingsDal
(
auth
.
db
)
.
get_tab_values
(
tab_id
=
tab_id
))
#
#
# @app
.put("/settings/tabs/values", summary="更新系统配置信息")
@
router
.
put
(
"/settings/tabs/values"
,
summary
=
"更新系统配置信息"
)
#
async def put_settings_tabs_values(
async
def
put_settings_tabs_values
(
#
request: Request,
request
:
Request
,
#
datas: dict = Body(...),
datas
:
dict
=
Body
(
...
),
#
auth: Auth = Depends(FullAdminAuth())
auth
:
Auth
=
Depends
(
FullAdminAuth
())
#
):
):
#
return SuccessResponse(await crud.SettingsDal(auth.db).update_datas(datas, request))
return
SuccessResponse
(
await
crud
.
SettingsDal
(
auth
.
db
)
.
update_datas
(
datas
,
request
))
#
#
# @app
.get("/settings/base/config", summary="获取系统基础配置", description="每次进入系统中时使用")
@
router
.
get
(
"/settings/base/config"
,
summary
=
"获取系统基础配置"
,
description
=
"每次进入系统中时使用"
)
#
async def get_setting_base_config(db: AsyncSession = Depends(db_getter)):
async
def
get_setting_base_config
(
db
:
AsyncSession
=
Depends
(
db_getter
)):
#
return SuccessResponse(await crud.SettingsDal(db).get_base_config())
return
SuccessResponse
(
await
crud
.
SettingsDal
(
db
)
.
get_base_config
())
#
#
# @app
.get("/settings/privacy", summary="获取隐私协议")
@
router
.
get
(
"/settings/privacy"
,
summary
=
"获取隐私协议"
)
#
async def get_settings_privacy(auth: Auth = Depends(OpenAuth())):
async
def
get_settings_privacy
(
auth
:
Auth
=
Depends
(
OpenAuth
())):
#
return SuccessResponse((await crud.SettingsDal(auth.db).get_data(config_key="web_privacy")).config_value)
return
SuccessResponse
((
await
crud
.
SettingsDal
(
auth
.
db
)
.
get_data
(
config_key
=
"web_privacy"
))
.
config_value
)
#
#
# @app
.get("/settings/agreement", summary="获取用户协议")
@
router
.
get
(
"/settings/agreement"
,
summary
=
"获取用户协议"
)
#
async def get_settings_agreement(auth: Auth = Depends(OpenAuth())):
async
def
get_settings_agreement
(
auth
:
Auth
=
Depends
(
OpenAuth
())):
#
return SuccessResponse((await crud.SettingsDal(auth.db).get_data(config_key="web_agreement")).config_value)
return
SuccessResponse
((
await
crud
.
SettingsDal
(
auth
.
db
)
.
get_data
(
config_key
=
"web_agreement"
))
.
config_value
)
#
#
#
# ###########################################################
# ###########################################################
# # 定时任务管理
# # 定时任务管理
# ###########################################################
# ###########################################################
# @
app
.get("/tasks", summary="获取定时任务列表")
# @
router
.get("/tasks", summary="获取定时任务列表")
# async def get_tasks(
# async def get_tasks(
# p: TaskParams = Depends(),
# p: TaskParams = Depends(),
# db: AsyncIOMotorDatabase = Depends(mongo_getter),
# db: AsyncIOMotorDatabase = Depends(mongo_getter),
...
@@ -190,9 +190,9 @@
...
@@ -190,9 +190,9 @@
# ):
# ):
# datas, count = await crud.TaskDal(db).get_tasks(**p.dict())
# datas, count = await crud.TaskDal(db).get_tasks(**p.dict())
# return SuccessResponse(datas, count=count)
# return SuccessResponse(datas, count=count)
#
#
# @
app
.post("/tasks", summary="添加定时任务")
# @
router
.post("/tasks", summary="添加定时任务")
# async def post_tasks(
# async def post_tasks(
# data: schemas.Task,
# data: schemas.Task,
# db: AsyncIOMotorDatabase = Depends(mongo_getter),
# db: AsyncIOMotorDatabase = Depends(mongo_getter),
...
@@ -200,9 +200,9 @@
...
@@ -200,9 +200,9 @@
# auth: Auth = Depends(AllUserAuth())
# auth: Auth = Depends(AllUserAuth())
# ):
# ):
# return SuccessResponse(await crud.TaskDal(db).create_task(rd, data))
# return SuccessResponse(await crud.TaskDal(db).create_task(rd, data))
#
#
# @
app
.put("/tasks", summary="更新定时任务")
# @
router
.put("/tasks", summary="更新定时任务")
# async def put_tasks(
# async def put_tasks(
# _id: str,
# _id: str,
# data: schemas.Task,
# data: schemas.Task,
...
@@ -213,7 +213,7 @@
...
@@ -213,7 +213,7 @@
# return SuccessResponse(await crud.TaskDal(db).put_task(rd, _id, data))
# return SuccessResponse(await crud.TaskDal(db).put_task(rd, _id, data))
#
#
#
#
# @
app
.delete("/tasks", summary="删除单个定时任务")
# @
router
.delete("/tasks", summary="删除单个定时任务")
# async def delete_task(
# async def delete_task(
# _id: str,
# _id: str,
# db: AsyncIOMotorDatabase = Depends(mongo_getter),
# db: AsyncIOMotorDatabase = Depends(mongo_getter),
...
@@ -222,7 +222,7 @@
...
@@ -222,7 +222,7 @@
# return SuccessResponse(await crud.TaskDal(db).delete_task(_id))
# return SuccessResponse(await crud.TaskDal(db).delete_task(_id))
#
#
#
#
# @
app
.get("/task", summary="获取定时任务详情")
# @
router
.get("/task", summary="获取定时任务详情")
# async def get_task(
# async def get_task(
# _id: str,
# _id: str,
# db: AsyncIOMotorDatabase = Depends(mongo_getter),
# db: AsyncIOMotorDatabase = Depends(mongo_getter),
...
@@ -231,7 +231,7 @@
...
@@ -231,7 +231,7 @@
# return SuccessResponse(await crud.TaskDal(db).get_task(_id, v_schema=schemas.TaskSimpleOut))
# return SuccessResponse(await crud.TaskDal(db).get_task(_id, v_schema=schemas.TaskSimpleOut))
#
#
#
#
# @
app
.post("/task", summary="执行一次定时任务")
# @
router
.post("/task", summary="执行一次定时任务")
# async def run_once_task(
# async def run_once_task(
# _id: str,
# _id: str,
# db: AsyncIOMotorDatabase = Depends(mongo_getter),
# db: AsyncIOMotorDatabase = Depends(mongo_getter),
...
@@ -244,7 +244,7 @@
...
@@ -244,7 +244,7 @@
# ###########################################################
# ###########################################################
# # 定时任务分组管理
# # 定时任务分组管理
# ###########################################################
# ###########################################################
# @
app
.get("/task/group/options", summary="获取定时任务分组选择项列表")
# @
router
.get("/task/group/options", summary="获取定时任务分组选择项列表")
# async def get_task_group_options(db: AsyncIOMotorDatabase = Depends(mongo_getter), auth: Auth = Depends(AllUserAuth())):
# 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))
# return SuccessResponse(await crud.TaskGroupDal(db).get_datas(limit=0))
#
#
...
@@ -252,7 +252,7 @@
...
@@ -252,7 +252,7 @@
# ###########################################################
# ###########################################################
# # 定时任务调度日志
# # 定时任务调度日志
# ###########################################################
# ###########################################################
# @
app
.get("/task/records", summary="获取定时任务调度日志列表")
# @
router
.get("/task/records", summary="获取定时任务调度日志列表")
# async def get_task_records(
# async def get_task_records(
# p: TaskRecordParams = Depends(),
# p: TaskRecordParams = Depends(),
# db: AsyncIOMotorDatabase = Depends(mongo_getter),
# db: AsyncIOMotorDatabase = Depends(mongo_getter),
...
...
dbgpt/app/apps/vadmin/auth/utils/login.py
View file @
8b0030b8
...
@@ -40,7 +40,7 @@ import jwt
...
@@ -40,7 +40,7 @@ import jwt
router
=
APIRouter
()
router
=
APIRouter
()
@
router
.
post
(
"/
v2
/login"
,
summary
=
"API 手机号密码登录"
,
description
=
"Swagger API 文档登录认证"
)
@
router
.
post
(
"/
api
/login"
,
summary
=
"API 手机号密码登录"
,
description
=
"Swagger API 文档登录认证"
)
async
def
api_login_for_access_token
(
async
def
api_login_for_access_token
(
request
:
Request
,
request
:
Request
,
data
:
OAuth2PasswordRequestForm
=
Depends
(),
data
:
OAuth2PasswordRequestForm
=
Depends
(),
...
@@ -63,14 +63,52 @@ async def api_login_for_access_token(
...
@@ -63,14 +63,52 @@ async def api_login_for_access_token(
# await VadminLoginRecord.create_login_record(db, record, True, request, resp)
# await VadminLoginRecord.create_login_record(db, record, True, request, resp)
return
resp
return
resp
@
router
.
post
(
"/login"
,
summary
=
"手机号密码登录"
,
description
=
"员工登录通道,限制最多输错次数,达到最大值后将is_active=False"
)
async
def
login_for_access_token
(
request
:
Request
,
data
:
LoginForm
,
manage
:
LoginManage
=
Depends
(),
db
:
AsyncSession
=
Depends
(
db_getter
)
):
try
:
if
data
.
method
==
"0"
:
result
=
await
manage
.
password_login
(
data
,
db
,
request
)
# elif data.method == "1":
# result = await manage.sms_login(data, db, request)
else
:
raise
ValueError
(
"无效参数"
)
if
not
result
.
status
:
raise
ValueError
(
result
.
msg
)
access_token
=
LoginManage
.
create_token
(
{
"sub"
:
result
.
user
.
telephone
,
"is_refresh"
:
False
,
"password"
:
result
.
user
.
password
}
)
expires
=
timedelta
(
minutes
=
settings
.
REFRESH_TOKEN_EXPIRE_MINUTES
)
refresh_token
=
LoginManage
.
create_token
(
payload
=
{
"sub"
:
result
.
user
.
telephone
,
"is_refresh"
:
True
,
"password"
:
result
.
user
.
password
},
expires
=
expires
)
resp
=
{
"access_token"
:
access_token
,
"refresh_token"
:
refresh_token
,
"token_type"
:
"bearer"
,
"is_reset_password"
:
result
.
user
.
is_reset_password
,
"is_wx_server_openid"
:
result
.
user
.
is_wx_server_openid
}
# await VadminLoginRecord.create_login_record(db, data, True, request, resp)
return
SuccessResponse
(
resp
)
except
ValueError
as
e
:
# await VadminLoginRecord.create_login_record(db, data, False, request, {"message": str(e)})
return
ErrorResponse
(
msg
=
str
(
e
))
@
router
.
get
(
"/
v2/
getMenuList"
,
summary
=
"获取当前用户菜单树"
)
@
router
.
get
(
"/getMenuList"
,
summary
=
"获取当前用户菜单树"
)
async
def
get_menu_list
(
auth
:
Auth
=
Depends
(
FullAdminAuth
())):
async
def
get_menu_list
(
auth
:
Auth
=
Depends
(
FullAdminAuth
())):
return
SuccessResponse
(
await
MenuDal
(
auth
.
db
)
.
get_routers
(
auth
.
user
))
return
SuccessResponse
(
await
MenuDal
(
auth
.
db
)
.
get_routers
(
auth
.
user
))
@
router
.
post
(
"/
v2/
token/refresh"
,
summary
=
"刷新Token"
)
@
router
.
post
(
"/token/refresh"
,
summary
=
"刷新Token"
)
async
def
token_refresh
(
refresh
:
str
=
Body
(
...
,
title
=
"刷新Token"
)):
async
def
token_refresh
(
refresh
:
str
=
Body
(
...
,
title
=
"刷新Token"
)):
error_code
=
status
.
HTTP_401_UNAUTHORIZED
error_code
=
status
.
HTTP_401_UNAUTHORIZED
try
:
try
:
...
...
dbgpt/app/apps/vadmin/auth/views.py
View file @
8b0030b8
...
@@ -23,7 +23,7 @@ router = APIRouter()
...
@@ -23,7 +23,7 @@ router = APIRouter()
###########################################################
###########################################################
# 接口测试
# 接口测试
###########################################################
###########################################################
@
router
.
get
(
"/
v2/
test"
,
summary
=
"接口测试"
)
@
router
.
get
(
"/test"
,
summary
=
"接口测试"
)
async
def
test
(
auth
:
Auth
=
Depends
(
OpenAuth
())):
async
def
test
(
auth
:
Auth
=
Depends
(
OpenAuth
())):
return
SuccessResponse
(
await
crud
.
TestDal
(
auth
.
db
)
.
relationship_where_operations_has
())
return
SuccessResponse
(
await
crud
.
TestDal
(
auth
.
db
)
.
relationship_where_operations_has
())
...
@@ -31,7 +31,7 @@ async def test(auth: Auth = Depends(OpenAuth())):
...
@@ -31,7 +31,7 @@ async def test(auth: Auth = Depends(OpenAuth())):
###########################################################
###########################################################
# 用户管理
# 用户管理
###########################################################
###########################################################
@
router
.
get
(
"/
v2/
users"
,
summary
=
"获取用户列表"
)
@
router
.
get
(
"/users"
,
summary
=
"获取用户列表"
)
async
def
get_users
(
async
def
get_users
(
params
:
UserParams
=
Depends
(),
params
:
UserParams
=
Depends
(),
auth
:
Auth
=
Depends
(
FullAdminAuth
(
permissions
=
[
"auth.user.list"
]))
auth
:
Auth
=
Depends
(
FullAdminAuth
(
permissions
=
[
"auth.user.list"
]))
...
@@ -48,12 +48,12 @@ async def get_users(
...
@@ -48,12 +48,12 @@ async def get_users(
return
SuccessResponse
(
datas
,
count
=
count
)
return
SuccessResponse
(
datas
,
count
=
count
)
@
router
.
post
(
"/
v2/
users"
,
summary
=
"创建用户"
)
@
router
.
post
(
"/users"
,
summary
=
"创建用户"
)
async
def
create_user
(
data
:
schemas
.
UserIn
,
auth
:
Auth
=
Depends
(
FullAdminAuth
(
permissions
=
[
"auth.user.create"
]))):
async
def
create_user
(
data
:
schemas
.
UserIn
,
auth
:
Auth
=
Depends
(
FullAdminAuth
(
permissions
=
[
"auth.user.create"
]))):
return
SuccessResponse
(
await
crud
.
UserDal
(
auth
.
db
)
.
create_data
(
data
=
data
))
return
SuccessResponse
(
await
crud
.
UserDal
(
auth
.
db
)
.
create_data
(
data
=
data
))
@
router
.
delete
(
"/
v2/
users"
,
summary
=
"批量删除用户"
,
description
=
"软删除,删除后清空所关联的角色"
)
@
router
.
delete
(
"/users"
,
summary
=
"批量删除用户"
,
description
=
"软删除,删除后清空所关联的角色"
)
async
def
delete_users
(
ids
:
IdList
=
Depends
(),
auth
:
Auth
=
Depends
(
FullAdminAuth
(
permissions
=
[
"auth.user.delete"
]))):
async
def
delete_users
(
ids
:
IdList
=
Depends
(),
auth
:
Auth
=
Depends
(
FullAdminAuth
(
permissions
=
[
"auth.user.delete"
]))):
if
auth
.
user
.
id
in
ids
.
ids
:
if
auth
.
user
.
id
in
ids
.
ids
:
return
ErrorResponse
(
"不能删除当前登录用户"
)
return
ErrorResponse
(
"不能删除当前登录用户"
)
...
@@ -63,7 +63,7 @@ async def delete_users(ids: IdList = Depends(), auth: Auth = Depends(FullAdminAu
...
@@ -63,7 +63,7 @@ async def delete_users(ids: IdList = Depends(), auth: Auth = Depends(FullAdminAu
return
SuccessResponse
(
"删除成功"
)
return
SuccessResponse
(
"删除成功"
)
@
router
.
put
(
"/
v2/
users/{data_id}"
,
summary
=
"更新用户信息"
)
@
router
.
put
(
"/users/{data_id}"
,
summary
=
"更新用户信息"
)
async
def
put_user
(
async
def
put_user
(
data_id
:
int
,
data_id
:
int
,
data
:
schemas
.
UserUpdate
,
data
:
schemas
.
UserUpdate
,
...
@@ -72,7 +72,7 @@ async def put_user(
...
@@ -72,7 +72,7 @@ async def put_user(
return
SuccessResponse
(
await
crud
.
UserDal
(
auth
.
db
)
.
put_data
(
data_id
,
data
))
return
SuccessResponse
(
await
crud
.
UserDal
(
auth
.
db
)
.
put_data
(
data_id
,
data
))
@
router
.
get
(
"/
v2/
users/{data_id}"
,
summary
=
"获取用户信息"
)
@
router
.
get
(
"/users/{data_id}"
,
summary
=
"获取用户信息"
)
async
def
get_user
(
async
def
get_user
(
data_id
:
int
,
data_id
:
int
,
auth
:
Auth
=
Depends
(
FullAdminAuth
(
permissions
=
[
"auth.user.view"
,
"auth.user.update"
]))
auth
:
Auth
=
Depends
(
FullAdminAuth
(
permissions
=
[
"auth.user.view"
,
"auth.user.update"
]))
...
@@ -83,29 +83,29 @@ async def get_user(
...
@@ -83,29 +83,29 @@ async def get_user(
return
SuccessResponse
(
await
crud
.
UserDal
(
auth
.
db
)
.
get_data
(
data_id
,
v_options
=
options
,
v_schema
=
schema
))
return
SuccessResponse
(
await
crud
.
UserDal
(
auth
.
db
)
.
get_data
(
data_id
,
v_options
=
options
,
v_schema
=
schema
))
@
router
.
post
(
"/
v2/
user/current/reset/password"
,
summary
=
"重置当前用户密码"
)
@
router
.
post
(
"/user/current/reset/password"
,
summary
=
"重置当前用户密码"
)
async
def
user_current_reset_password
(
data
:
schemas
.
ResetPwd
,
auth
:
Auth
=
Depends
(
AllUserAuth
())):
async
def
user_current_reset_password
(
data
:
schemas
.
ResetPwd
,
auth
:
Auth
=
Depends
(
AllUserAuth
())):
return
SuccessResponse
(
await
crud
.
UserDal
(
auth
.
db
)
.
reset_current_password
(
auth
.
user
,
data
))
return
SuccessResponse
(
await
crud
.
UserDal
(
auth
.
db
)
.
reset_current_password
(
auth
.
user
,
data
))
@
router
.
post
(
"/
v2/
user/current/update/info"
,
summary
=
"更新当前用户基本信息"
)
@
router
.
post
(
"/user/current/update/info"
,
summary
=
"更新当前用户基本信息"
)
async
def
post_user_current_update_info
(
data
:
schemas
.
UserUpdateBaseInfo
,
auth
:
Auth
=
Depends
(
AllUserAuth
())):
async
def
post_user_current_update_info
(
data
:
schemas
.
UserUpdateBaseInfo
,
auth
:
Auth
=
Depends
(
AllUserAuth
())):
return
SuccessResponse
(
await
crud
.
UserDal
(
auth
.
db
)
.
update_current_info
(
auth
.
user
,
data
))
return
SuccessResponse
(
await
crud
.
UserDal
(
auth
.
db
)
.
update_current_info
(
auth
.
user
,
data
))
@
router
.
post
(
"/
v2/
user/current/update/avatar"
,
summary
=
"更新当前用户头像"
)
@
router
.
post
(
"/user/current/update/avatar"
,
summary
=
"更新当前用户头像"
)
async
def
post_user_current_update_avatar
(
file
:
UploadFile
,
auth
:
Auth
=
Depends
(
AllUserAuth
())):
async
def
post_user_current_update_avatar
(
file
:
UploadFile
,
auth
:
Auth
=
Depends
(
AllUserAuth
())):
return
SuccessResponse
(
await
crud
.
UserDal
(
auth
.
db
)
.
update_current_avatar
(
auth
.
user
,
file
))
return
SuccessResponse
(
await
crud
.
UserDal
(
auth
.
db
)
.
update_current_avatar
(
auth
.
user
,
file
))
@
router
.
get
(
"/
v2/
user/admin/current/info"
,
summary
=
"获取当前管理员信息"
)
@
router
.
get
(
"/user/admin/current/info"
,
summary
=
"获取当前管理员信息"
)
async
def
get_user_admin_current_info
(
auth
:
Auth
=
Depends
(
FullAdminAuth
())):
async
def
get_user_admin_current_info
(
auth
:
Auth
=
Depends
(
FullAdminAuth
())):
result
=
schemas
.
UserOut
.
model_validate
(
auth
.
user
)
.
model_dump
()
result
=
schemas
.
UserOut
.
model_validate
(
auth
.
user
)
.
model_dump
()
result
[
"permissions"
]
=
list
(
FullAdminAuth
.
get_user_permissions
(
auth
.
user
))
result
[
"permissions"
]
=
list
(
FullAdminAuth
.
get_user_permissions
(
auth
.
user
))
return
SuccessResponse
(
result
)
return
SuccessResponse
(
result
)
@
router
.
post
(
"/
v2/
user/export/query/list/to/excel"
,
summary
=
"导出用户查询列表为excel"
)
@
router
.
post
(
"/user/export/query/list/to/excel"
,
summary
=
"导出用户查询列表为excel"
)
async
def
post_user_export_query_list
(
async
def
post_user_export_query_list
(
header
:
list
=
Body
(
...
,
title
=
"表头与对应字段"
),
header
:
list
=
Body
(
...
,
title
=
"表头与对应字段"
),
params
:
UserParams
=
Depends
(),
params
:
UserParams
=
Depends
(),
...
@@ -114,17 +114,17 @@ async def post_user_export_query_list(
...
@@ -114,17 +114,17 @@ async def post_user_export_query_list(
return
SuccessResponse
(
await
crud
.
UserDal
(
auth
.
db
)
.
export_query_list
(
header
,
params
))
return
SuccessResponse
(
await
crud
.
UserDal
(
auth
.
db
)
.
export_query_list
(
header
,
params
))
@
router
.
get
(
"/
v2/
user/download/import/template"
,
summary
=
"下载最新批量导入用户模板"
)
@
router
.
get
(
"/user/download/import/template"
,
summary
=
"下载最新批量导入用户模板"
)
async
def
get_user_download_new_import_template
(
auth
:
Auth
=
Depends
(
AllUserAuth
())):
async
def
get_user_download_new_import_template
(
auth
:
Auth
=
Depends
(
AllUserAuth
())):
return
SuccessResponse
(
await
crud
.
UserDal
(
auth
.
db
)
.
download_import_template
())
return
SuccessResponse
(
await
crud
.
UserDal
(
auth
.
db
)
.
download_import_template
())
@
router
.
post
(
"/
v2/
import/users"
,
summary
=
"批量导入用户"
)
@
router
.
post
(
"/import/users"
,
summary
=
"批量导入用户"
)
async
def
post_import_users
(
file
:
UploadFile
,
auth
:
Auth
=
Depends
(
FullAdminAuth
(
permissions
=
[
"auth.user.import"
]))):
async
def
post_import_users
(
file
:
UploadFile
,
auth
:
Auth
=
Depends
(
FullAdminAuth
(
permissions
=
[
"auth.user.import"
]))):
return
SuccessResponse
(
await
crud
.
UserDal
(
auth
.
db
)
.
import_users
(
file
))
return
SuccessResponse
(
await
crud
.
UserDal
(
auth
.
db
)
.
import_users
(
file
))
@
router
.
post
(
"/
v2/
users/init/password/send/sms"
,
summary
=
"初始化所选用户密码并发送通知短信"
)
@
router
.
post
(
"/users/init/password/send/sms"
,
summary
=
"初始化所选用户密码并发送通知短信"
)
async
def
post_users_init_password
(
async
def
post_users_init_password
(
request
:
Request
,
request
:
Request
,
ids
:
IdList
=
Depends
(),
ids
:
IdList
=
Depends
(),
...
@@ -134,7 +134,7 @@ async def post_users_init_password(
...
@@ -134,7 +134,7 @@ async def post_users_init_password(
return
SuccessResponse
(
await
crud
.
UserDal
(
auth
.
db
)
.
init_password_send_sms
(
ids
.
ids
,
rd
))
return
SuccessResponse
(
await
crud
.
UserDal
(
auth
.
db
)
.
init_password_send_sms
(
ids
.
ids
,
rd
))
@
router
.
post
(
"/
v2/
users/init/password/send/email"
,
summary
=
"初始化所选用户密码并发送通知邮件"
)
@
router
.
post
(
"/users/init/password/send/email"
,
summary
=
"初始化所选用户密码并发送通知邮件"
)
async
def
post_users_init_password_send_email
(
async
def
post_users_init_password_send_email
(
request
:
Request
,
request
:
Request
,
ids
:
IdList
=
Depends
(),
ids
:
IdList
=
Depends
(),
...
@@ -144,7 +144,7 @@ async def post_users_init_password_send_email(
...
@@ -144,7 +144,7 @@ async def post_users_init_password_send_email(
return
SuccessResponse
(
await
crud
.
UserDal
(
auth
.
db
)
.
init_password_send_email
(
ids
.
ids
,
rd
))
return
SuccessResponse
(
await
crud
.
UserDal
(
auth
.
db
)
.
init_password_send_email
(
ids
.
ids
,
rd
))
@
router
.
put
(
"/
v2/
users/wx/server/openid"
,
summary
=
"更新当前用户服务端微信平台openid"
)
@
router
.
put
(
"/users/wx/server/openid"
,
summary
=
"更新当前用户服务端微信平台openid"
)
async
def
put_user_wx_server_openid
(
code
:
str
,
auth
:
Auth
=
Depends
(
AllUserAuth
()),
rd
:
Redis
=
Depends
(
redis_getter
)):
async
def
put_user_wx_server_openid
(
code
:
str
,
auth
:
Auth
=
Depends
(
AllUserAuth
()),
rd
:
Redis
=
Depends
(
redis_getter
)):
result
=
await
crud
.
UserDal
(
auth
.
db
)
.
update_wx_server_openid
(
code
,
auth
.
user
,
rd
)
result
=
await
crud
.
UserDal
(
auth
.
db
)
.
update_wx_server_openid
(
code
,
auth
.
user
,
rd
)
return
SuccessResponse
(
result
)
return
SuccessResponse
(
result
)
...
@@ -153,7 +153,7 @@ async def put_user_wx_server_openid(code: str, auth: Auth = Depends(AllUserAuth(
...
@@ -153,7 +153,7 @@ async def put_user_wx_server_openid(code: str, auth: Auth = Depends(AllUserAuth(
###########################################################
###########################################################
# 角色管理
# 角色管理
###########################################################
###########################################################
@
router
.
get
(
"/
v2/
roles"
,
summary
=
"获取角色列表"
)
@
router
.
get
(
"/roles"
,
summary
=
"获取角色列表"
)
async
def
get_roles
(
async
def
get_roles
(
params
:
RoleParams
=
Depends
(),
params
:
RoleParams
=
Depends
(),
auth
:
Auth
=
Depends
(
FullAdminAuth
(
permissions
=
[
"auth.role.list"
]))
auth
:
Auth
=
Depends
(
FullAdminAuth
(
permissions
=
[
"auth.role.list"
]))
...
@@ -162,12 +162,12 @@ async def get_roles(
...
@@ -162,12 +162,12 @@ async def get_roles(
return
SuccessResponse
(
datas
,
count
=
count
)
return
SuccessResponse
(
datas
,
count
=
count
)
@
router
.
post
(
"/
v2/
roles"
,
summary
=
"创建角色信息"
)
@
router
.
post
(
"/roles"
,
summary
=
"创建角色信息"
)
async
def
create_role
(
role
:
schemas
.
RoleIn
,
auth
:
Auth
=
Depends
(
FullAdminAuth
(
permissions
=
[
"auth.role.create"
]))):
async
def
create_role
(
role
:
schemas
.
RoleIn
,
auth
:
Auth
=
Depends
(
FullAdminAuth
(
permissions
=
[
"auth.role.create"
]))):
return
SuccessResponse
(
await
crud
.
RoleDal
(
auth
.
db
)
.
create_data
(
data
=
role
))
return
SuccessResponse
(
await
crud
.
RoleDal
(
auth
.
db
)
.
create_data
(
data
=
role
))
@
router
.
delete
(
"/
v2/
roles"
,
summary
=
"批量删除角色"
,
description
=
"硬删除, 如果存在用户关联则无法删除"
)
@
router
.
delete
(
"/roles"
,
summary
=
"批量删除角色"
,
description
=
"硬删除, 如果存在用户关联则无法删除"
)
async
def
delete_roles
(
ids
:
IdList
=
Depends
(),
auth
:
Auth
=
Depends
(
FullAdminAuth
(
permissions
=
[
"auth.role.delete"
]))):
async
def
delete_roles
(
ids
:
IdList
=
Depends
(),
auth
:
Auth
=
Depends
(
FullAdminAuth
(
permissions
=
[
"auth.role.delete"
]))):
if
1
in
ids
.
ids
:
if
1
in
ids
.
ids
:
return
ErrorResponse
(
"不能删除管理员角色"
)
return
ErrorResponse
(
"不能删除管理员角色"
)
...
@@ -175,7 +175,7 @@ async def delete_roles(ids: IdList = Depends(), auth: Auth = Depends(FullAdminAu
...
@@ -175,7 +175,7 @@ async def delete_roles(ids: IdList = Depends(), auth: Auth = Depends(FullAdminAu
return
SuccessResponse
(
"删除成功"
)
return
SuccessResponse
(
"删除成功"
)
@
router
.
put
(
"/
v2/
roles/{data_id}"
,
summary
=
"更新角色信息"
)
@
router
.
put
(
"/roles/{data_id}"
,
summary
=
"更新角色信息"
)
async
def
put_role
(
async
def
put_role
(
data_id
:
int
,
data_id
:
int
,
data
:
schemas
.
RoleIn
,
data
:
schemas
.
RoleIn
,
...
@@ -186,12 +186,12 @@ async def put_role(
...
@@ -186,12 +186,12 @@ async def put_role(
return
SuccessResponse
(
await
crud
.
RoleDal
(
auth
.
db
)
.
put_data
(
data_id
,
data
))
return
SuccessResponse
(
await
crud
.
RoleDal
(
auth
.
db
)
.
put_data
(
data_id
,
data
))
@
router
.
get
(
"/
v2/
roles/options"
,
summary
=
"获取角色选择项"
)
@
router
.
get
(
"/roles/options"
,
summary
=
"获取角色选择项"
)
async
def
get_role_options
(
auth
:
Auth
=
Depends
(
FullAdminAuth
(
permissions
=
[
"auth.user.create"
,
"auth.user.update"
]))):
async
def
get_role_options
(
auth
:
Auth
=
Depends
(
FullAdminAuth
(
permissions
=
[
"auth.user.create"
,
"auth.user.update"
]))):
return
SuccessResponse
(
await
crud
.
RoleDal
(
auth
.
db
)
.
get_select_datas
())
return
SuccessResponse
(
await
crud
.
RoleDal
(
auth
.
db
)
.
get_select_datas
())
@
router
.
get
(
"/
v2/
roles/{data_id}"
,
summary
=
"获取角色信息"
)
@
router
.
get
(
"/roles/{data_id}"
,
summary
=
"获取角色信息"
)
async
def
get_role
(
async
def
get_role
(
data_id
:
int
,
data_id
:
int
,
auth
:
Auth
=
Depends
(
FullAdminAuth
(
permissions
=
[
"auth.role.view"
,
"auth.role.update"
]))
auth
:
Auth
=
Depends
(
FullAdminAuth
(
permissions
=
[
"auth.role.view"
,
"auth.role.update"
]))
...
@@ -205,39 +205,39 @@ async def get_role(
...
@@ -205,39 +205,39 @@ async def get_role(
###########################################################
###########################################################
# 菜单管理
# 菜单管理
###########################################################
###########################################################
@
router
.
get
(
"/
v2/
menus"
,
summary
=
"获取菜单列表"
)
@
router
.
get
(
"/menus"
,
summary
=
"获取菜单列表"
)
async
def
get_menus
(
auth
:
Auth
=
Depends
(
FullAdminAuth
(
permissions
=
[
"auth.menu.list"
]))):
async
def
get_menus
(
auth
:
Auth
=
Depends
(
FullAdminAuth
(
permissions
=
[
"auth.menu.list"
]))):
datas
=
await
crud
.
MenuDal
(
auth
.
db
)
.
get_tree_list
(
mode
=
1
)
datas
=
await
crud
.
MenuDal
(
auth
.
db
)
.
get_tree_list
(
mode
=
1
)
return
SuccessResponse
(
datas
)
return
SuccessResponse
(
datas
)
@
router
.
get
(
"/
v2/
menus/tree/options"
,
summary
=
"获取菜单树选择项,添加/修改菜单时使用"
)
@
router
.
get
(
"/menus/tree/options"
,
summary
=
"获取菜单树选择项,添加/修改菜单时使用"
)
async
def
get_menus_options
(
auth
:
Auth
=
Depends
(
FullAdminAuth
(
permissions
=
[
"auth.menu.create"
,
"auth.menu.update"
]))):
async
def
get_menus_options
(
auth
:
Auth
=
Depends
(
FullAdminAuth
(
permissions
=
[
"auth.menu.create"
,
"auth.menu.update"
]))):
datas
=
await
crud
.
MenuDal
(
auth
.
db
)
.
get_tree_list
(
mode
=
2
)
datas
=
await
crud
.
MenuDal
(
auth
.
db
)
.
get_tree_list
(
mode
=
2
)
return
SuccessResponse
(
datas
)
return
SuccessResponse
(
datas
)
@
router
.
get
(
"/
v2/
menus/role/tree/options"
,
summary
=
"获取菜单列表树信息,角色权限使用"
)
@
router
.
get
(
"/menus/role/tree/options"
,
summary
=
"获取菜单列表树信息,角色权限使用"
)
async
def
get_menus_treeselect
(
async
def
get_menus_treeselect
(
auth
:
Auth
=
Depends
(
FullAdminAuth
(
permissions
=
[
"auth.role.create"
,
"auth.role.update"
]))
auth
:
Auth
=
Depends
(
FullAdminAuth
(
permissions
=
[
"auth.role.create"
,
"auth.role.update"
]))
):
):
return
SuccessResponse
(
await
crud
.
MenuDal
(
auth
.
db
)
.
get_tree_list
(
mode
=
3
))
return
SuccessResponse
(
await
crud
.
MenuDal
(
auth
.
db
)
.
get_tree_list
(
mode
=
3
))
@
router
.
post
(
"/
v2/
menus"
,
summary
=
"创建菜单信息"
)
@
router
.
post
(
"/menus"
,
summary
=
"创建菜单信息"
)
async
def
create_menu
(
menu
:
schemas
.
Menu
,
auth
:
Auth
=
Depends
(
FullAdminAuth
(
permissions
=
[
"auth.menu.create"
]))):
async
def
create_menu
(
menu
:
schemas
.
Menu
,
auth
:
Auth
=
Depends
(
FullAdminAuth
(
permissions
=
[
"auth.menu.create"
]))):
if
menu
.
parent_id
:
if
menu
.
parent_id
:
menu
.
alwaysShow
=
False
menu
.
alwaysShow
=
False
return
SuccessResponse
(
await
crud
.
MenuDal
(
auth
.
db
)
.
create_data
(
data
=
menu
))
return
SuccessResponse
(
await
crud
.
MenuDal
(
auth
.
db
)
.
create_data
(
data
=
menu
))
@
router
.
delete
(
"/
v2/
menus"
,
summary
=
"批量删除菜单"
,
description
=
"硬删除, 如果存在角色关联则无法删除"
)
@
router
.
delete
(
"/menus"
,
summary
=
"批量删除菜单"
,
description
=
"硬删除, 如果存在角色关联则无法删除"
)
async
def
delete_menus
(
ids
:
IdList
=
Depends
(),
auth
:
Auth
=
Depends
(
FullAdminAuth
(
permissions
=
[
"auth.menu.delete"
]))):
async
def
delete_menus
(
ids
:
IdList
=
Depends
(),
auth
:
Auth
=
Depends
(
FullAdminAuth
(
permissions
=
[
"auth.menu.delete"
]))):
await
crud
.
MenuDal
(
auth
.
db
)
.
delete_datas
(
ids
.
ids
,
v_soft
=
False
)
await
crud
.
MenuDal
(
auth
.
db
)
.
delete_datas
(
ids
.
ids
,
v_soft
=
False
)
return
SuccessResponse
(
"删除成功"
)
return
SuccessResponse
(
"删除成功"
)
@
router
.
put
(
"/
v2/
menus/{data_id}"
,
summary
=
"更新菜单信息"
)
@
router
.
put
(
"/menus/{data_id}"
,
summary
=
"更新菜单信息"
)
async
def
put_menus
(
async
def
put_menus
(
data_id
:
int
,
data_id
:
int
,
data
:
schemas
.
Menu
,
auth
:
Auth
=
Depends
(
FullAdminAuth
(
permissions
=
[
"auth.menu.update"
]))
data
:
schemas
.
Menu
,
auth
:
Auth
=
Depends
(
FullAdminAuth
(
permissions
=
[
"auth.menu.update"
]))
...
@@ -245,7 +245,7 @@ async def put_menus(
...
@@ -245,7 +245,7 @@ async def put_menus(
return
SuccessResponse
(
await
crud
.
MenuDal
(
auth
.
db
)
.
put_data
(
data_id
,
data
))
return
SuccessResponse
(
await
crud
.
MenuDal
(
auth
.
db
)
.
put_data
(
data_id
,
data
))
@
router
.
get
(
"/
v2/
menus/{data_id}"
,
summary
=
"获取菜单信息"
)
@
router
.
get
(
"/menus/{data_id}"
,
summary
=
"获取菜单信息"
)
async
def
get_menus
(
async
def
get_menus
(
data_id
:
int
,
data_id
:
int
,
auth
:
Auth
=
Depends
(
FullAdminAuth
(
permissions
=
[
"auth.menu.view"
,
"auth.menu.update"
]))
auth
:
Auth
=
Depends
(
FullAdminAuth
(
permissions
=
[
"auth.menu.view"
,
"auth.menu.update"
]))
...
@@ -254,7 +254,7 @@ async def get_menus(
...
@@ -254,7 +254,7 @@ async def get_menus(
return
SuccessResponse
(
await
crud
.
MenuDal
(
auth
.
db
)
.
get_data
(
data_id
,
v_schema
=
schema
))
return
SuccessResponse
(
await
crud
.
MenuDal
(
auth
.
db
)
.
get_data
(
data_id
,
v_schema
=
schema
))
@
router
.
get
(
"/
v2/
role/menus/tree/{role_id}"
,
summary
=
"获取菜单列表树信息以及角色菜单权限ID,角色权限使用"
)
@
router
.
get
(
"/role/menus/tree/{role_id}"
,
summary
=
"获取菜单列表树信息以及角色菜单权限ID,角色权限使用"
)
async
def
get_role_menu_tree
(
async
def
get_role_menu_tree
(
role_id
:
int
,
role_id
:
int
,
auth
:
Auth
=
Depends
(
FullAdminAuth
(
permissions
=
[
"auth.role.create"
,
"auth.role.update"
]))
auth
:
Auth
=
Depends
(
FullAdminAuth
(
permissions
=
[
"auth.role.create"
,
"auth.role.update"
]))
...
@@ -267,7 +267,7 @@ async def get_role_menu_tree(
...
@@ -267,7 +267,7 @@ async def get_role_menu_tree(
###########################################################
###########################################################
# 部门管理
# 部门管理
###########################################################
###########################################################
@
router
.
get
(
"/
v2/
depts"
,
summary
=
"获取部门列表"
)
@
router
.
get
(
"/depts"
,
summary
=
"获取部门列表"
)
async
def
get_depts
(
async
def
get_depts
(
params
:
DeptParams
=
Depends
(),
params
:
DeptParams
=
Depends
(),
auth
:
Auth
=
Depends
(
FullAdminAuth
())
auth
:
Auth
=
Depends
(
FullAdminAuth
())
...
@@ -276,29 +276,29 @@ async def get_depts(
...
@@ -276,29 +276,29 @@ async def get_depts(
return
SuccessResponse
(
datas
)
return
SuccessResponse
(
datas
)
@
router
.
get
(
"/
v2/
dept/tree/options"
,
summary
=
"获取部门树选择项,添加/修改部门时使用"
)
@
router
.
get
(
"/dept/tree/options"
,
summary
=
"获取部门树选择项,添加/修改部门时使用"
)
async
def
get_dept_options
(
auth
:
Auth
=
Depends
(
FullAdminAuth
())):
async
def
get_dept_options
(
auth
:
Auth
=
Depends
(
FullAdminAuth
())):
datas
=
await
crud
.
DeptDal
(
auth
.
db
)
.
get_tree_list
(
mode
=
2
)
datas
=
await
crud
.
DeptDal
(
auth
.
db
)
.
get_tree_list
(
mode
=
2
)
return
SuccessResponse
(
datas
)
return
SuccessResponse
(
datas
)
@
router
.
get
(
"/
v2/
dept/user/tree/options"
,
summary
=
"获取部门树选择项,添加/修改用户时使用"
)
@
router
.
get
(
"/dept/user/tree/options"
,
summary
=
"获取部门树选择项,添加/修改用户时使用"
)
async
def
get_dept_treeselect
(
auth
:
Auth
=
Depends
(
FullAdminAuth
())):
async
def
get_dept_treeselect
(
auth
:
Auth
=
Depends
(
FullAdminAuth
())):
return
SuccessResponse
(
await
crud
.
DeptDal
(
auth
.
db
)
.
get_tree_list
(
mode
=
3
))
return
SuccessResponse
(
await
crud
.
DeptDal
(
auth
.
db
)
.
get_tree_list
(
mode
=
3
))
@
router
.
post
(
"/
v2/
depts"
,
summary
=
"创建部门信息"
)
@
router
.
post
(
"/depts"
,
summary
=
"创建部门信息"
)
async
def
create_dept
(
data
:
schemas
.
Dept
,
auth
:
Auth
=
Depends
(
FullAdminAuth
())):
async
def
create_dept
(
data
:
schemas
.
Dept
,
auth
:
Auth
=
Depends
(
FullAdminAuth
())):
return
SuccessResponse
(
await
crud
.
DeptDal
(
auth
.
db
)
.
create_data
(
data
=
data
))
return
SuccessResponse
(
await
crud
.
DeptDal
(
auth
.
db
)
.
create_data
(
data
=
data
))
@
router
.
delete
(
"/
v2/
depts"
,
summary
=
"批量删除部门"
,
description
=
"硬删除, 如果存在用户关联则无法删除"
)
@
router
.
delete
(
"/depts"
,
summary
=
"批量删除部门"
,
description
=
"硬删除, 如果存在用户关联则无法删除"
)
async
def
delete_depts
(
ids
:
IdList
=
Depends
(),
auth
:
Auth
=
Depends
(
FullAdminAuth
())):
async
def
delete_depts
(
ids
:
IdList
=
Depends
(),
auth
:
Auth
=
Depends
(
FullAdminAuth
())):
await
crud
.
DeptDal
(
auth
.
db
)
.
delete_datas
(
ids
.
ids
,
v_soft
=
False
)
await
crud
.
DeptDal
(
auth
.
db
)
.
delete_datas
(
ids
.
ids
,
v_soft
=
False
)
return
SuccessResponse
(
"删除成功"
)
return
SuccessResponse
(
"删除成功"
)
@
router
.
put
(
"/
v2/
depts/{data_id}"
,
summary
=
"更新部门信息"
)
@
router
.
put
(
"/depts/{data_id}"
,
summary
=
"更新部门信息"
)
async
def
put_dept
(
async
def
put_dept
(
data_id
:
int
,
data_id
:
int
,
data
:
schemas
.
Dept
,
data
:
schemas
.
Dept
,
...
...
dbgpt/app/dbgpt_server.py
View file @
8b0030b8
...
@@ -96,6 +96,7 @@ def mount_routers(app: FastAPI):
...
@@ -96,6 +96,7 @@ def mount_routers(app: FastAPI):
from
dbgpt.serve.agent.app.endpoints
import
router
as
app_v2
from
dbgpt.serve.agent.app.endpoints
import
router
as
app_v2
from
dbgpt.app.apps.vadmin.auth.utils.login
import
router
as
login
from
dbgpt.app.apps.vadmin.auth.utils.login
import
router
as
login
from
dbgpt.app.apps.vadmin.auth.views
import
router
as
views
from
dbgpt.app.apps.vadmin.auth.views
import
router
as
views
from
dbgpt.app.apps.system.views
import
router
as
system_views
app
.
include_router
(
api_v1
,
prefix
=
"/api"
,
tags
=
[
"Chat"
])
app
.
include_router
(
api_v1
,
prefix
=
"/api"
,
tags
=
[
"Chat"
])
app
.
include_router
(
api_v2
,
prefix
=
"/api"
,
tags
=
[
"ChatV2"
])
app
.
include_router
(
api_v2
,
prefix
=
"/api"
,
tags
=
[
"ChatV2"
])
...
@@ -105,8 +106,9 @@ def mount_routers(app: FastAPI):
...
@@ -105,8 +106,9 @@ def mount_routers(app: FastAPI):
app
.
include_router
(
gpts_v1
,
prefix
=
"/api"
,
tags
=
[
"GptsApp"
])
app
.
include_router
(
gpts_v1
,
prefix
=
"/api"
,
tags
=
[
"GptsApp"
])
app
.
include_router
(
app_v2
,
prefix
=
"/api"
,
tags
=
[
"App"
])
app
.
include_router
(
app_v2
,
prefix
=
"/api"
,
tags
=
[
"App"
])
app
.
include_router
(
knowledge_router
,
tags
=
[
"Knowledge"
])
app
.
include_router
(
knowledge_router
,
tags
=
[
"Knowledge"
])
app
.
include_router
(
login
,
prefix
=
"/api"
,
tags
=
[
"System"
])
app
.
include_router
(
login
,
prefix
=
"/api/v2/auth"
,
tags
=
[
"System"
])
app
.
include_router
(
views
,
prefix
=
"/api"
,
tags
=
[
"System"
])
app
.
include_router
(
views
,
prefix
=
"/api/v2/vadmin/auth"
,
tags
=
[
"System"
])
app
.
include_router
(
system_views
,
prefix
=
"/api/v2/vadmin/system"
,
tags
=
[
"System"
])
def
mount_static_files
(
app
:
FastAPI
):
def
mount_static_files
(
app
:
FastAPI
):
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment