mirror of
https://github.com/fastapiadmin/FastapiAdmin.git
synced 2026-09-20 20:39:55 +00:00
fix(gencode): 修复代码生成模块的多处问题
refactor(backend): 重构代码生成服务层和控制器层逻辑 feat(backend): 添加SQL模板文件后缀 fix(backend): 修复用户服务中的用户名空值检查 style(backend): 优化导入和代码格式 refactor(frontend): 重构代码生成前端组件和API fix(frontend): 修复用户信息表单的可选字段 feat(frontend): 添加Python和SQL图标资源 style(frontend): 调整样式和布局 chore: 更新依赖版本和配置文件 docs: 更新注释和文档内容
This commit is contained in:
@@ -12,7 +12,7 @@ from app.common.request import PaginationService
|
||||
from app.api.v1.module_system.auth.schema import AuthSchema
|
||||
from app.common.constant import RET
|
||||
from .param import GenTableQueryParam
|
||||
from .schema import GenTableDeleteSchema, GenTableSchema, GenTableOutSchema
|
||||
from .schema import GenTableSchema, GenTableOutSchema
|
||||
from .service import GenTableColumnService, GenTableService
|
||||
from app.utils.common_util import bytes2file_response
|
||||
from app.core.logger import logger
|
||||
@@ -47,7 +47,7 @@ async def get_gen_db_table_list_controller(
|
||||
|
||||
@GenRouter.post("/import", summary="导入表结构", description="导入表结构")
|
||||
async def import_gen_table_controller(
|
||||
table_names: List[str] = Query(..., description="表名列表"),
|
||||
table_names: List[str] = Body(..., description="表名列表"),
|
||||
auth: AuthSchema = Depends(AuthPermission(["generator:gencode:import"])),
|
||||
) -> JSONResponse:
|
||||
add_gen_table_list = await GenTableService.get_gen_db_table_list_by_name_service(auth, table_names)
|
||||
@@ -70,7 +70,7 @@ async def gen_table_detail_controller(
|
||||
|
||||
@GenRouter.post("/create", summary="创建表结构", description="创建表结构")
|
||||
async def create_table_controller(
|
||||
sql: str = Query(..., description="SQL语句:CREATE TABLE user_demo (\n id INTEGER NOT NULL PRIMARY KEY,\n username VARCHAR(64) NOT NULL UNIQUE,\n);"),
|
||||
sql: str = Body(..., description="SQL语句:CREATE TABLE user_demo (\n id INTEGER NOT NULL PRIMARY KEY,\n username VARCHAR(64) NOT NULL UNIQUE,\n);"),
|
||||
auth: AuthSchema = Depends(AuthPermission(["generator:gencode:create"])),
|
||||
) -> JSONResponse:
|
||||
result = await GenTableService.create_table_service(auth, sql)
|
||||
@@ -92,17 +92,17 @@ async def update_gen_table_controller(
|
||||
|
||||
@GenRouter.delete("/delete", summary="删除业务表信息", description="删除业务表信息")
|
||||
async def delete_gen_table_controller(
|
||||
data: GenTableDeleteSchema = Body(..., description="业务表ID列表"),
|
||||
ids: List[int] = Body(..., description="业务表ID列表"),
|
||||
auth: AuthSchema = Depends(AuthPermission(["generator:gencode:delete"]))
|
||||
) -> JSONResponse:
|
||||
result = await GenTableService.delete_gen_table_service(auth, data)
|
||||
result = await GenTableService.delete_gen_table_service(auth, ids)
|
||||
logger.info('删除业务表信息成功')
|
||||
return SuccessResponse(msg="删除业务表信息成功", data=result)
|
||||
|
||||
|
||||
@GenRouter.patch("/batch/output", summary="批量生成代码", description="批量生成代码")
|
||||
async def batch_gen_code_controller(
|
||||
table_names: List[str] = Query(..., description="表名列表"),
|
||||
table_names: List[str] = Body(..., description="表名列表"),
|
||||
auth: AuthSchema = Depends(AuthPermission(["generator:gencode:operate"]))
|
||||
) -> StreamResponse:
|
||||
# 检查table_names是否为空
|
||||
|
||||
@@ -15,7 +15,6 @@ from .model import GenTableModel, GenTableColumnModel
|
||||
from .schema import (
|
||||
GenTableSchema,
|
||||
GenTableOutSchema,
|
||||
GenTableDeleteSchema,
|
||||
GenTableColumnSchema,
|
||||
GenTableColumnOutSchema,
|
||||
GenTableColumnDeleteSchema,
|
||||
@@ -137,12 +136,12 @@ class GenTableCRUD(CRUDBase[GenTableModel, GenTableSchema, GenTableSchema]):
|
||||
await self.db.commit()
|
||||
return edit_model
|
||||
|
||||
async def delete_gen_table(self, data: GenTableDeleteSchema) -> None:
|
||||
async def delete_gen_table(self, ids: List[int]) -> None:
|
||||
"""
|
||||
删除
|
||||
"""
|
||||
await self.db.execute(
|
||||
delete(GenTableModel).where(GenTableModel.id.in_(data.table_ids))
|
||||
delete(GenTableModel).where(GenTableModel.id.in_(ids))
|
||||
)
|
||||
await self.db.flush()
|
||||
|
||||
@@ -459,10 +458,10 @@ class GenTableColumnCRUD(CRUDBase[GenTableColumnModel, GenTableColumnSchema, Gen
|
||||
"""更新业务表字段"""
|
||||
return await self.update(id=id, data=data)
|
||||
|
||||
async def delete_gen_table_column_by_table_id_dao(self, data: GenTableDeleteSchema) -> None:
|
||||
async def delete_gen_table_column_by_table_id_dao(self, table_ids: List[int]) -> None:
|
||||
"""根据业务表ID批量删除"""
|
||||
# 先查询出这些表ID对应的所有字段ID
|
||||
query = select(GenTableColumnModel.id).where(GenTableColumnModel.table_id.in_(data.table_ids))
|
||||
query = select(GenTableColumnModel.id).where(GenTableColumnModel.table_id.in_(table_ids))
|
||||
result = await self.db.execute(query)
|
||||
column_ids = [row[0] for row in result.fetchall()]
|
||||
|
||||
|
||||
@@ -108,15 +108,6 @@ class GenTableOutSchema(GenTableSchema, BaseSchema):
|
||||
return values
|
||||
|
||||
|
||||
class GenTableDeleteSchema(BaseModel):
|
||||
"""
|
||||
删除代码生成业务表模型
|
||||
"""
|
||||
model_config = ConfigDict(alias_generator=to_camel)
|
||||
|
||||
table_ids: List[int] = Field(..., description='需要删除的代码生成业务表ID列表')
|
||||
|
||||
|
||||
class GenTableColumnSchema(BaseModel):
|
||||
"""
|
||||
代码生成业务表字段创建模型
|
||||
|
||||
@@ -16,7 +16,7 @@ from app.api.v1.module_system.auth.schema import AuthSchema
|
||||
from app.utils.common_util import CamelCaseUtil
|
||||
from app.utils.gen_util import GenUtils
|
||||
from app.utils.jinja2_template_util import Jinja2TemplateInitializerUtil, Jinja2TemplateUtil
|
||||
from .schema import GenTableSchema, GenTableOutSchema, GenTableOutSchema, GenTableDeleteSchema, GenTableColumnSchema, GenTableColumnOutSchema, GenTableColumnDeleteSchema
|
||||
from .schema import GenTableSchema, GenTableOutSchema, GenTableOutSchema, GenTableColumnSchema, GenTableColumnOutSchema, GenTableColumnDeleteSchema
|
||||
from .param import GenTableQueryParam
|
||||
from .crud import GenTableColumnCRUD, GenTableCRUD
|
||||
|
||||
@@ -211,13 +211,13 @@ class GenTableService:
|
||||
raise CustomException(msg='业务表不存在')
|
||||
|
||||
@classmethod
|
||||
async def delete_gen_table_service(cls, auth: AuthSchema, data: GenTableDeleteSchema) -> None:
|
||||
async def delete_gen_table_service(cls, auth: AuthSchema, ids: List[int]) -> None:
|
||||
"""删除业务表信息"""
|
||||
try:
|
||||
# 先删除相关的字段信息
|
||||
await GenTableColumnCRUD(auth=auth).delete_gen_table_column_by_table_id_dao(data)
|
||||
await GenTableColumnCRUD(auth=auth).delete_gen_table_column_by_table_id_dao(ids)
|
||||
# 再删除表信息
|
||||
await GenTableCRUD(auth=auth).delete_gen_table(data)
|
||||
await GenTableCRUD(auth=auth).delete_gen_table(ids)
|
||||
except Exception as e:
|
||||
raise CustomException(msg=f'删除失败: {str(e)}')
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ from datetime import datetime
|
||||
|
||||
from app.core.base_crud import CRUDBase
|
||||
from .model import UserModel
|
||||
from .schema import UserCreateSchema,UserForgetPasswordSchema,UserUpdateSchema
|
||||
from .schema import UserCreateSchema, UserForgetPasswordSchema, UserUpdateSchema
|
||||
from ..role.crud import RoleCRUD
|
||||
from ..position.crud import PositionCRUD
|
||||
|
||||
|
||||
@@ -65,7 +65,7 @@ class UserCreateSchema(CurrentUserUpdateSchema):
|
||||
"""新增"""
|
||||
model_config = ConfigDict(from_attributes=True)
|
||||
|
||||
username: str = Field(default=..., max_length=32, description="用户名")
|
||||
username: Optional[str] = Field(default=None, max_length=32, description="用户名")
|
||||
password: Optional[str] = Field(default=None, max_length=128, description="密码哈希值")
|
||||
status: bool = Field(default=True, description="是否可用")
|
||||
is_superuser: bool = Field(default=False, description="是否超管")
|
||||
@@ -82,6 +82,7 @@ class UserUpdateSchema(UserCreateSchema):
|
||||
|
||||
last_login: Optional[DateTimeStr] = Field(default=None, description="最后登录时间")
|
||||
|
||||
|
||||
class UserOutSchema(UserCreateSchema, BaseSchema):
|
||||
"""响应"""
|
||||
model_config = ConfigDict(arbitrary_types_allowed=True, from_attributes=True)
|
||||
|
||||
@@ -69,6 +69,8 @@ class UserService:
|
||||
|
||||
@classmethod
|
||||
async def create_user_service(cls, data: UserCreateSchema, auth: AuthSchema) -> Dict:
|
||||
if not data.username:
|
||||
raise CustomException(msg="用户名不能为空")
|
||||
# 检查用户名是否存在
|
||||
user = await UserCRUD(auth).get_by_username_crud(username=data.username)
|
||||
if user:
|
||||
@@ -97,6 +99,8 @@ class UserService:
|
||||
|
||||
@classmethod
|
||||
async def update_user_service(cls, id: int, data: UserUpdateSchema, auth: AuthSchema) -> Dict:
|
||||
if not data.username:
|
||||
raise CustomException(msg="用户名不能为空")
|
||||
# 检查用户是否存在
|
||||
user = await UserCRUD(auth).get_by_id_crud(id=id)
|
||||
if not user:
|
||||
|
||||
Reference in New Issue
Block a user