mirror of
https://github.com/fastapiadmin/FastapiAdmin.git
synced 2026-09-20 20:39:55 +00:00
Merge pull request #250 from 1014TaoTao/2.2.0
refactor: 移除param层并优化用户更新和查询逻辑
This commit is contained in:
+7
-8
@@ -267,14 +267,13 @@ docker compose down
|
|||||||
|
|
||||||
1. **Write the Entity Class Layer**: Create the ORM model for the demo in `backend/app/api/v1/models/demo/example_model.py` (corresponding to the entity class layer in Spring Boot).
|
1. **Write the Entity Class Layer**: Create the ORM model for the demo in `backend/app/api/v1/models/demo/example_model.py` (corresponding to the entity class layer in Spring Boot).
|
||||||
2. **Write the Data Model Layer**: Create the demo data model in `backend/app/api/v1/schemas/demo/example_schema.py` (corresponding to the DTO layer in Spring Boot).
|
2. **Write the Data Model Layer**: Create the demo data model in `backend/app/api/v1/schemas/demo/example_schema.py` (corresponding to the DTO layer in Spring Boot).
|
||||||
3. **Write the Query Parameter Model Layer**: Create the query parameter model for the demo in `backend/app/v1/params/demo/example_param.py` (corresponding to the DTO layer in Spring Boot).
|
3. **Write the Persistence Layer**: Create the demo data layer in `backend/app/api/v1/cruds/demo/example_crud.py` (corresponding to the Mapper or DAO layer in Spring Boot).
|
||||||
4. **Write the Persistence Layer**: Create the demo data layer in `backend/app/api/v1/cruds/demo/example_crud.py` (corresponding to the Mapper or DAO layer in Spring Boot).
|
4. **Write the Business Layer**: Create the demo data layer in `backend/app/api/v1/services/demo/example_service.py` (corresponding to the Service layer in Spring Boot).
|
||||||
5. **Write the Business Layer**: Create the demo data layer in `backend/app/api/v1/services/demo/example_service.py` (corresponding to the Service layer in Spring Boot).
|
5. **Write the Interface Layer**: Create the demo data layer in `backend/app/api/v1/controllers/demo/example_controller.py` (corresponding to the Controller layer in Spring Boot).
|
||||||
6. **Write the Interface Layer**: Create the demo data layer in `backend/app/api/v1/controllers/demo/example_controller.py` (corresponding to the Controller layer in Spring Boot).
|
6. **Register Backend Routes**: Register the demo routes in `backend/app/api/v1/urls/demo_url.py`.
|
||||||
7. **Register Backend Routes**: Register the demo routes in `backend/app/api/v1/urls/demo_url.py`.
|
7. **Register Routes to the FastAPI Service**: Register the routes in `backend/plugin/init_app.py`.
|
||||||
8. **Register Routes to the FastAPI Service**: Register the routes in `backend/plugin/init_app.py`.
|
8. **Add the Demo Module to the System Initialization Script**: Add it in `backend/app/scripts/initialize.py` (if necessary, you can configure the demo menu permissions in `backend/app/scripts/data/system_menu.json` and `backend/app/scripts/data/system_role_menus.json` or from the frontend page menu).
|
||||||
9. **Add the Demo Module to the System Initialization Script**: Add it in `backend/app/scripts/initialize.py` (if necessary, you can configure the demo menu permissions in `backend/app/scripts/data/system_menu.json` and `backend/app/scripts/data/system_role_menus.json` or from the frontend page menu).
|
9. **Add the Demo Module to the Database Migration Script**: Add it in `backend/app/alembic/env.py`.
|
||||||
10. **Add the Demo Module to the Database Migration Script**: Add it in `backend/app/alembic/env.py`.
|
|
||||||
|
|
||||||
### Code Generation Tutorial
|
### Code Generation Tutorial
|
||||||
|
|
||||||
|
|||||||
@@ -325,7 +325,6 @@ docker compose down
|
|||||||
- 数据访问层:`backend/app/api/v1/module_{module_name}/{business_name}/crud.py`
|
- 数据访问层:`backend/app/api/v1/module_{module_name}/{business_name}/crud.py`
|
||||||
- 数据模型层:`backend/app/api/v1/module_{module_name}/{business_name}/model.py`
|
- 数据模型层:`backend/app/api/v1/module_{module_name}/{business_name}/model.py`
|
||||||
- 数据模式层:`backend/app/api/v1/module_{module_name}/{business_name}/schema.py`
|
- 数据模式层:`backend/app/api/v1/module_{module_name}/{business_name}/schema.py`
|
||||||
- 查询参数层:`backend/app/api/v1/module_{module_name}/{business_name}/param.py`
|
|
||||||
|
|
||||||
**前端文件**:
|
**前端文件**:
|
||||||
- API接口文件:`frontend/src/api/module_{module_name}/{business_name}.ts`
|
- API接口文件:`frontend/src/api/module_{module_name}/{business_name}.ts`
|
||||||
|
|||||||
@@ -53,34 +53,34 @@ class {{ class_name }}QueryParam:
|
|||||||
{% endif %}
|
{% endif %}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
{% for column in columns %}
|
{% for column in columns %}
|
||||||
{% if column.query_type == 'EQ' and column.column_name != 'status' %}
|
{% if column.query_type == 'EQ' %}
|
||||||
{{ column.column_name }}: {{ column.python_type }} | None = Query(None, description="{{ column.column_comment }}"),
|
{{ column.column_name }}: {{ column.python_type }} | None = Query(None, description="{{ column.column_comment }}"),
|
||||||
{% elif column.query_type == 'EQ' and column.column_name == 'status' %}
|
|
||||||
{{ column.column_name }}: str | None = Query(None, description="{{ column.column_comment }}"),
|
|
||||||
{% elif table.created_time %}
|
|
||||||
created_time: list[DateTimeStr] | None = Query(None, description="创建时间范围", example=["2025-01-01 00:00:00", "2025-12-31 23:59:59"]),
|
|
||||||
{% elif table.updated_time %}
|
|
||||||
updated_time: list[DateTimeStr] | None = Query(None, description="更新时间范围", example=["2025-01-01 00:00:00", "2025-12-31 23:59:59"]),
|
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
{% if table.created_time %}
|
||||||
|
created_time: list[DateTimeStr] | None = Query(None, description="创建时间范围", example=["2025-01-01 00:00:00", "2025-12-31 23:59:59"]),
|
||||||
|
{% endif %}
|
||||||
|
{% if table.updated_time %}
|
||||||
|
updated_time: list[DateTimeStr] | None = Query(None, description="更新时间范围", example=["2025-01-01 00:00:00", "2025-12-31 23:59:59"]),
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
) -> None:
|
) -> None:
|
||||||
|
|
||||||
# 模糊查询字段
|
|
||||||
{% for column in columns %}
|
{% for column in columns %}
|
||||||
{% if column.query_type == 'LIKE' %}
|
{% if column.query_type == 'LIKE' %}
|
||||||
|
# 模糊查询字段
|
||||||
self.{{ column.column_name }} = ("like", {{ column.column_name }})
|
self.{{ column.column_name }} = ("like", {{ column.column_name }})
|
||||||
|
{% elif column.query_type == 'EQ' and column.column_name %}
|
||||||
# 精确查询字段
|
# 精确查询字段
|
||||||
{% elif column.query_type == 'EQ' %}
|
|
||||||
self.{{ column.column_name }} = {{ column.column_name }}
|
self.{{ column.column_name }} = {{ column.column_name }}
|
||||||
{% elif table.created_time %}
|
{% endif %}
|
||||||
self.created_id = created_id
|
{% endfor %}
|
||||||
|
{% if table.created_time %}
|
||||||
# 时间范围查询
|
# 时间范围查询
|
||||||
if created_time and len(created_time) == 2:
|
if created_time and len(created_time) == 2:
|
||||||
self.created_time = ("between", (created_time[0], created_time[1]))
|
self.created_time = ("between", (created_time[0], created_time[1]))
|
||||||
{% elif table.updated_time %}
|
{% endif %}
|
||||||
self.updated_id = updated_id
|
{% if table.updated_time %}
|
||||||
if updated_time and len(updated_time) == 2:
|
if updated_time and len(updated_time) == 2:
|
||||||
self.updated_time = ("between", (updated_time[0], updated_time[1]))
|
self.updated_time = ("between", (updated_time[0], updated_time[1]))
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endfor %}
|
|
||||||
|
|||||||
@@ -172,14 +172,8 @@ class UserService:
|
|||||||
if not dept.status:
|
if not dept.status:
|
||||||
raise CustomException(msg='部门已被禁用')
|
raise CustomException(msg='部门已被禁用')
|
||||||
|
|
||||||
# 更新密码
|
# 更新用户 - 排除不应被修改的字段, 更新不更新密码
|
||||||
update_dict = {}
|
|
||||||
if data.password:
|
|
||||||
update_dict['password'] = PwdUtil.set_password_hash(password=data.password)
|
|
||||||
|
|
||||||
# 更新用户 - 排除不应被修改的字段
|
|
||||||
user_dict = data.model_dump(exclude_unset=True, exclude={"role_ids", "position_ids", "last_login", "password"})
|
user_dict = data.model_dump(exclude_unset=True, exclude={"role_ids", "position_ids", "last_login", "password"})
|
||||||
user_dict.update(update_dict)
|
|
||||||
new_user = await UserCRUD(auth).update(id=id, data=user_dict)
|
new_user = await UserCRUD(auth).update(id=id, data=user_dict)
|
||||||
|
|
||||||
# 更新角色和岗位
|
# 更新角色和岗位
|
||||||
|
|||||||
@@ -424,13 +424,13 @@ class GenConstant:
|
|||||||
COLUMNNAME_NOT_EDIT_SHOW = ["uuid"]
|
COLUMNNAME_NOT_EDIT_SHOW = ["uuid"]
|
||||||
|
|
||||||
# 页面不需要编辑字段
|
# 页面不需要编辑字段
|
||||||
COLUMNNAME_NOT_EDIT = ["id", "uuid", "description", "created_time", "updated_time"]
|
COLUMNNAME_NOT_EDIT = ["id", "uuid", "created_time", "updated_time"]
|
||||||
|
|
||||||
# 页面不需要显示的列表字段
|
# 页面不需要显示的列表字段
|
||||||
COLUMNNAME_NOT_LIST = ["id", "uuid", "description", "created_time", "updated_time"]
|
COLUMNNAME_NOT_LIST = ["id", "uuid"]
|
||||||
|
|
||||||
# 页面不需要查询字段
|
# 页面不需要查询字段
|
||||||
COLUMNNAME_NOT_QUERY = ["id", "uuid", "description", "created_time", "updated_time"]
|
COLUMNNAME_NOT_QUERY = ["id", "uuid", "description"]
|
||||||
|
|
||||||
# Crud基类字段
|
# Crud基类字段
|
||||||
CRUD_COLUMN_NOT_EDIT = ["create_by", "description", "created_time", "updated_time"]
|
CRUD_COLUMN_NOT_EDIT = ["create_by", "description", "created_time", "updated_time"]
|
||||||
|
|||||||
+14
-20
File diff suppressed because one or more lines are too long
File diff suppressed because it is too large
Load Diff
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user