From 1f60012a97d9c4e4d80f060257ca72fdf7ba6214 Mon Sep 17 00:00:00 2001 From: yuliang_guo Date: Fri, 30 Jan 2026 18:20:18 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E5=AD=A6=E5=91=98?= =?UTF-8?q?=E7=AB=AF=E6=88=90=E9=95=BF=E8=B7=AF=E5=BE=84=E6=8C=89=E7=94=A8?= =?UTF-8?q?=E6=88=B7=E5=B2=97=E4=BD=8D=E5=8C=B9=E9=85=8D=E7=9A=84=E9=80=BB?= =?UTF-8?q?=E8=BE=91=EF=BC=8C=E6=94=AF=E6=8C=81=E5=A4=9A=E5=B2=97=E4=BD=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/app/services/growth_path_service.py | 51 +++++++++++++++++++-- 1 file changed, 46 insertions(+), 5 deletions(-) diff --git a/backend/app/services/growth_path_service.py b/backend/app/services/growth_path_service.py index c9a9415..4a4e5dc 100644 --- a/backend/app/services/growth_path_service.py +++ b/backend/app/services/growth_path_service.py @@ -20,6 +20,7 @@ from app.models.growth_path import ( ) from app.models.user_course_progress import UserCourseProgress, ProgressStatus from app.models.position import Position +from app.models.position_member import PositionMember from app.schemas.growth_path import ( GrowthPathCreate, GrowthPathUpdate, @@ -335,6 +336,20 @@ class GrowthPathService: 如果指定了岗位ID,返回该岗位的成长路径 否则根据用户岗位自动匹配 """ + # 如果没有指定岗位,获取用户的岗位列表 + user_position_ids = [] + if not position_id: + pos_result = await db.execute( + select(PositionMember.position_id).where( + and_( + PositionMember.user_id == user_id, + PositionMember.is_deleted == False + ) + ) + ) + user_position_ids = [row[0] for row in pos_result.fetchall()] + logger.info(f"用户 {user_id} 的岗位列表: {user_position_ids}") + # 查找成长路径 query = select(GrowthPath).where( and_( @@ -342,12 +357,38 @@ class GrowthPathService: GrowthPath.is_active == True ) ) - if position_id: - query = query.where(GrowthPath.position_id == position_id) - - query = query.order_by(GrowthPath.sort_order).limit(1) + + # 按 sort_order 排序获取所有激活的成长路径 + query = query.order_by(GrowthPath.sort_order) result = await db.execute(query) - growth_path = result.scalar_one_or_none() + all_paths = result.scalars().all() + + growth_path = None + + if position_id: + # 如果指定了岗位ID,查找匹配的路径 + for path in all_paths: + # 检查 position_ids (多岗位) 或 position_id (单岗位) + path_position_ids = path.position_ids or [] + if path.position_id: + path_position_ids = list(set(path_position_ids + [path.position_id])) + if position_id in path_position_ids: + growth_path = path + break + elif user_position_ids: + # 根据用户岗位匹配 + for path in all_paths: + path_position_ids = path.position_ids or [] + if path.position_id: + path_position_ids = list(set(path_position_ids + [path.position_id])) + # 检查用户岗位是否与路径岗位有交集 + if any(pid in path_position_ids for pid in user_position_ids): + growth_path = path + logger.info(f"匹配到成长路径: {path.id}, 路径岗位: {path_position_ids}") + break + else: + # 没有岗位限制,返回第一个 + growth_path = all_paths[0] if all_paths else None if not growth_path: return None