From 02ddb27ca86c022f584689c94fb4abbb8587c234 Mon Sep 17 00:00:00 2001 From: martsforever Date: Tue, 14 Oct 2025 21:47:09 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=9B=B4=E6=96=B0=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=E9=BB=98=E8=AE=A4=E5=B0=B1=E6=98=AF=E6=8C=89=E7=85=A7=E5=AD=97?= =?UTF-8?q?=E6=AE=B5=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .env.example | 5 +++-- app/config/env.py | 1 + app/general/general_utils/sql_service.py | 5 +++++ 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/.env.example b/.env.example index ce0aab0..16f4678 100644 --- a/.env.example +++ b/.env.example @@ -37,5 +37,6 @@ JWT_REFRESH_TOKEN_EXPIRE_SECONDS = 604800 # JWT刷新令牌默认 JWT_GLOBAL_ENABLE = false # 是否开启全局JWT认证 JWT_WHITE_LIST = ["/token", "/login", "/refresh", "/registry", "/verify", "/async_delay", "/", "/redoc", "/docs", "/static/swagger-ui.min.css", "/static/swagger-ui-bundle.min.js", "/openapi.json", "/static/redoc.standalone.js"] # JWT认证白名单接口,不需要认证的接口 -FILE_SAVE_PATH=/www/wwwroot/web/web/upload_file/ -FILE_PUBLIC_PATH=/web/upload_file/ +FILE_SAVE_PATH=/www/wwwroot/web/web/upload_file/ # 文件保存在服务器上的路径 +FILE_PUBLIC_PATH=/web/upload_file/ # 文件在浏览器上的访问路径 +DEFAULT_UPDATE_BY_FIELDS=true # 更新接口是否默认按字段更新(按需更新字段值) diff --git a/app/config/env.py b/app/config/env.py index fda8272..6ff6368 100644 --- a/app/config/env.py +++ b/app/config/env.py @@ -47,6 +47,7 @@ class Settings(BaseSettings): file_save_path: str = Field(..., env='FILE_SAVE_PATH') file_public_path: str = Field(..., env='FILE_PUBLIC_PATH') + default_update_by_fields: bool = Field(..., env='DEFAULT_UPDATE_BY_FIELDS') class Config: env_file = ".env" diff --git a/app/general/general_utils/sql_service.py b/app/general/general_utils/sql_service.py index 1d3bc58..5c3aec6 100644 --- a/app/general/general_utils/sql_service.py +++ b/app/general/general_utils/sql_service.py @@ -1,5 +1,6 @@ import traceback +from app.config.env import env from app.general.general_utils.build_delete_sql import build_delete_sql from app.general.general_utils.build_insert_sql import build_insert_sql from app.general.general_utils.build_query_sql import build_query_sql @@ -201,6 +202,7 @@ async def update(session: AsyncSessionDep, query_config, module_config, debug_da conn = await session.connection() row = get_value(query_config, 'row', None) + update_by_fields = get_value(query_config, 'updateByFields', env.default_update_by_fields) update_fields = get_value(query_config, 'updateFields', None) if row is None: @@ -208,6 +210,9 @@ async def update(session: AsyncSessionDep, query_config, module_config, debug_da "error": "row parameter is missing", } + if update_by_fields: + update_fields = row.keys() + row_id = get_value(row, 'id', None) if row_id is None: