feat(phase4): 全部业务模块迁移到 modules/(结构迁移)
- 21 个模块目录(auth/system/dictionary/configuration/cms/member/region/link/notice/job/log/upload/index) - 每个模块 router.py(合并模块导出多个 router)/schemas.py/service.py/repository.py/models.py - routers/v1.py 与 routers/__init__.py 改为直接引用 modules,前缀与权限串原样保留 - core/middleware.py 懒加载指向 modules.system.menu / modules.log;core/redis_client.py 指向 modules.job.scheduler - apps/views|services|forms 全部改为 re-export 垫片 - 迁移后 grep 守门通过:modules/core 无 apps/extensions 残留引用 - 实测登录、27+ 模块接口、写操作 commit、操作日志落库均正常 Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -1,48 +1,2 @@
|
||||
from apps.models.user_role import UserRole
|
||||
from apps.models.role import Role
|
||||
from extensions import get_db_session
|
||||
|
||||
|
||||
# 根据用户ID查询角色列表
|
||||
|
||||
def get_user_role_list(userId):
|
||||
db = get_db_session()
|
||||
rows = (
|
||||
db.query(Role.id, Role.name)
|
||||
.join(UserRole, UserRole.role_id == Role.id)
|
||||
.filter(UserRole.user_id == userId, Role.is_delete == 0)
|
||||
.all()
|
||||
)
|
||||
role_list = []
|
||||
if rows:
|
||||
for v in rows:
|
||||
item = {
|
||||
'id': v.id,
|
||||
'name': v.name,
|
||||
}
|
||||
role_list.append(item)
|
||||
return role_list
|
||||
|
||||
|
||||
# 根据用户ID列表批量查询角色,返回 {user_id: [{id, name}, ...]} 字典
|
||||
|
||||
def get_user_role_map(user_ids):
|
||||
if not user_ids:
|
||||
return {}
|
||||
db = get_db_session()
|
||||
# 用ORM查询替代原生SQL,避免tuple单元素/空列表的IN语法问题
|
||||
from apps.models.user_role import UserRole
|
||||
from apps.models.role import Role
|
||||
rows = (
|
||||
db.query(UserRole.user_id, Role.id.label('role_id'), Role.name.label('role_name'))
|
||||
.join(Role, Role.id == UserRole.role_id)
|
||||
.filter(UserRole.user_id.in_(user_ids), Role.is_delete == 0)
|
||||
.all()
|
||||
)
|
||||
role_map = {}
|
||||
for row in rows:
|
||||
uid = row.user_id
|
||||
if uid not in role_map:
|
||||
role_map[uid] = []
|
||||
role_map[uid].append({'id': row.role_id, 'name': row.role_name})
|
||||
return role_map
|
||||
# 兼容垫片:由 modules.system.user.service 迁移
|
||||
from modules.system.user.service import * # noqa: F401,F403
|
||||
|
||||
Reference in New Issue
Block a user