fix: 修复学员端成长路径按用户岗位匹配的逻辑,支持多岗位
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
@@ -20,6 +20,7 @@ from app.models.growth_path import (
|
|||||||
)
|
)
|
||||||
from app.models.user_course_progress import UserCourseProgress, ProgressStatus
|
from app.models.user_course_progress import UserCourseProgress, ProgressStatus
|
||||||
from app.models.position import Position
|
from app.models.position import Position
|
||||||
|
from app.models.position_member import PositionMember
|
||||||
from app.schemas.growth_path import (
|
from app.schemas.growth_path import (
|
||||||
GrowthPathCreate,
|
GrowthPathCreate,
|
||||||
GrowthPathUpdate,
|
GrowthPathUpdate,
|
||||||
@@ -335,6 +336,20 @@ class GrowthPathService:
|
|||||||
如果指定了岗位ID,返回该岗位的成长路径
|
如果指定了岗位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(
|
query = select(GrowthPath).where(
|
||||||
and_(
|
and_(
|
||||||
@@ -342,12 +357,38 @@ class GrowthPathService:
|
|||||||
GrowthPath.is_active == True
|
GrowthPath.is_active == True
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
if position_id:
|
|
||||||
query = query.where(GrowthPath.position_id == position_id)
|
# 按 sort_order 排序获取所有激活的成长路径
|
||||||
|
query = query.order_by(GrowthPath.sort_order)
|
||||||
query = query.order_by(GrowthPath.sort_order).limit(1)
|
|
||||||
result = await db.execute(query)
|
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:
|
if not growth_path:
|
||||||
return None
|
return None
|
||||||
|
|||||||
Reference in New Issue
Block a user