Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*.js linguist-language=Python
*.css linguist-language=Python
*.html linguist-language=Python
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ backend/venv
backend/logs
backend/*.db
backend/site
backend/app/alembic/versions/*

frontend/__pycache__
frontend/.vscode
Expand Down

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions backend/app/api/v1/module_generator/gencode/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
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
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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是否为空
Expand Down
9 changes: 4 additions & 5 deletions backend/app/api/v1/module_generator/gencode/crud.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
from .schema import (
GenTableSchema,
GenTableOutSchema,
GenTableDeleteSchema,
GenTableColumnSchema,
GenTableColumnOutSchema,
GenTableColumnDeleteSchema,
Expand Down Expand Up @@ -137,12 +136,12 @@ async def edit_gen_table(self, table_id: int, edit_model: GenTableSchema) -> Gen
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()

Expand Down Expand Up @@ -459,10 +458,10 @@ async def update_gen_table_column_crud(self, id: int, data: GenTableColumnSchema
"""更新业务表字段"""
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()]

Expand Down
9 changes: 0 additions & 9 deletions backend/app/api/v1/module_generator/gencode/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,15 +108,6 @@ def handle_null_values(cls, values):
return values


class GenTableDeleteSchema(BaseModel):
"""
删除代码生成业务表模型
"""
model_config = ConfigDict(alias_generator=to_camel)

table_ids: List[int] = Field(..., description='需要删除的代码生成业务表ID列表')


class GenTableColumnSchema(BaseModel):
"""
代码生成业务表字段创建模型
Expand Down
8 changes: 4 additions & 4 deletions backend/app/api/v1/module_generator/gencode/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
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

Expand Down Expand Up @@ -211,13 +211,13 @@ async def update_gen_table_service(cls, auth: AuthSchema, data: GenTableSchema,
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)}')

Expand Down
2 changes: 1 addition & 1 deletion backend/app/api/v1/module_system/user/crud.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

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

Expand Down
3 changes: 2 additions & 1 deletion backend/app/api/v1/module_system/user/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -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="是否超管")
Expand All @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions backend/app/api/v1/module_system/user/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ async def get_user_list_service(cls, auth: AuthSchema, search: Optional[UserQuer

@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:
Expand Down Expand Up @@ -97,6 +99,8 @@ async def create_user_service(cls, data: UserCreateSchema, auth: AuthSchema) ->

@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:
Expand Down
25 changes: 1 addition & 24 deletions backend/app/config/setting.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,29 +162,6 @@ class Settings(BaseSettings):
GZIP_MIN_SIZE: int = 1000 # 最小压缩大小(字节)
GZIP_COMPRESS_LEVEL: int = 9 # 压缩级别(1-9)

# # ================================================= #
# # ***************** 演示模型配置 ***************** #
# # ================================================= #
# DEMO_ENABLE: bool # 是否开启演示模式
# DEMO_WHITE_LIST_PATH: List[str] = [ # 演示白名单
# "/api/v1/system/auth/login",
# "/api/v1/system/auth/token/refresh",
# "/api/v1/system/auth/captcha/get",
# "/api/v1/system/auth/logout",
# "/api/v1/system/config/info",
# "/api/v1/system/user/current/info",
# "/api/v1/system/notice/available",
# ]
# DEMO_BLACK_LIST_PATH: List[str] = [ # 演示黑名单
# "/auth/login"
# ]
# DEMO_IP_WHITE_LIST: List[str] = [ # 演示白名单IP
# "127.0.0.1",
# "117.10.167.220",
# "223.104.208.30",
# "42.80.102.171"
# ]

# ================================================= #
# ***************** 静态文件配置 ***************** #
# ================================================= #
Expand All @@ -202,7 +179,7 @@ class Settings(BaseSettings):
# ================================================= #
# ***************** 动态文件配置 ***************** #
# ================================================= #
UPLOAD_FILE_PATH: Path = BASE_DIR.joinpath('static/upload') # 上传目录
UPLOAD_FILE_PATH: Path = Path('static/upload') # 上传目录
UPLOAD_MACHINE: str = 'A' # 上传机器标识
ALLOWED_EXTENSIONS: list[str] = [ # 允许的文件类型
# 图片
Expand Down
1 change: 0 additions & 1 deletion backend/app/utils/gen_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
GenTableBaseSchema,
GenTableSchema,
GenTableOutSchema,
GenTableDeleteSchema,
GenTableColumnSchema,
GenTableColumnOutSchema,
GenTableColumnDeleteSchema
Expand Down
2 changes: 1 addition & 1 deletion backend/app/utils/jinja2_template_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ def get_template_list(cls, tpl_category: str, tpl_web_type: str):
# Vue相关模板
f'{use_web_type}/api.ts.j2',
# SQL脚本模板
'sql/sql.j2',
'sql/sql.sql.j2',
]
if category == GenConstant.TPL_CRUD:
templates.append(f'{use_web_type}/index.vue.j2')
Expand Down
2 changes: 1 addition & 1 deletion backend/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ pydantic-settings==2.5.2 # 配置设置
psutil==6.1.0 # 系统信息
python-multipart==0.0.9 # request.form() 对表单进行「解析」时安装
greenlet==3.1.1 # 协程框架
bcrypt==4.0.1 # 密码加密解析
bcrypt==4.3.0 # 密码加密解析
itsdangerous==2.2.0 # 用于安全处理各种数据,如密码、密钥等
aiofiles==24.1.0 # 文件操作
redis==5.2.1 # redis 同步操作数据库(用户celery配套使用)redis 异步操作数据库 redis已经完全具备了aioredis的功能,无需重复安全,且aioredis已经不再维护也不兼容3.10+的版本
Expand Down
File renamed without changes.
Loading