fix(我的培训):「我的培训」的“与我相关”判定(学习任务/讲师/部门范围)不含「参加人员」——线下课不生成学习任务,参加人员只落场次名单与文案,刘义亮(资讯组)被课程部门范围(人事课)拦在页签外。
deploy-hxtesting / build-and-deploy (push) Successful in 20m39s
deploy-hxtesting / build-and-deploy (push) Successful in 20m39s
This commit is contained in:
1 parent
448fbcdaff
commit
11450bdb96
8 files changed
+167
-2
No files matched your search
@@ -970,6 +970,10 @@ export const saveLearningProgress = (taskId: string, materialId: string, positio
|
||||
export const listMyLearningTasks = () =>
|
||||
get<{ success: boolean; data: LearningTask[] }>(`${base}/learning-tasks`)
|
||||
|
||||
/** 我经场次学员名单报名的课程 id 去重集合(我的培训「我参加」判定) */
|
||||
export const listMyEnrolledCourseIds = () =>
|
||||
get<{ success: boolean; data: string[] }>(`${base}/my/enrolled-course-ids`)
|
||||
|
||||
/** 管理端课程学习情况行(全员学习任务 + 员工展示字段) */
|
||||
export interface CourseLearningTask extends LearningTask {
|
||||
employee_no?: string
|
||||
|
||||
@@ -152,6 +152,7 @@ import {
|
||||
getMyProfile,
|
||||
listCourses,
|
||||
listCourseLibrary,
|
||||
listMyEnrolledCourseIds,
|
||||
listMyExamRecords,
|
||||
listMyLearningTasks,
|
||||
listSessions,
|
||||
@@ -241,6 +242,8 @@ const lecturerCourses = ref<TrainingCourse[]>([])
|
||||
const myProfile = ref<TrainingMember | null>(null)
|
||||
const myTasks = ref<LearningTask[]>([])
|
||||
const sessions = ref<TrainingCourseSession[]>([])
|
||||
// 我经场次学员名单报名的课程 id 集合(「我参加」判定;失败回退空集不阻断)
|
||||
const myEnrolledCourseIds = ref<Set<string>>(new Set())
|
||||
// 课程管理资产(000154):「和信课程」目录 = 课程管理已发布且部门范围覆盖查看人的课程
|
||||
const libraryItems = ref<TrainingLibraryCourse[]>([])
|
||||
// 我的考试记录(000154):「我的考试」页签数据源
|
||||
@@ -311,13 +314,16 @@ const myTaskByCourse = computed(() => {
|
||||
|
||||
// 「我的课程」相关性口径(与后端推送口径一致):
|
||||
// ① 我有该课学习任务(线上必修按部门推送);② 我是该课讲师;
|
||||
// ③ 课程部门范围覆盖我(dept_ids 为空 = 全员可见,非空需包含我的部门)。
|
||||
// ③ 课程部门范围覆盖我(dept_ids 为空 = 全员可见,非空需包含我的部门);
|
||||
// ④ 我是该课场次参加人员(学员名单接口,线下课参加人员由此可见——此前参加
|
||||
// 人员只落名单与文案,不进任何"与我相关"判定,被设为参加人员却看不到课)。
|
||||
// 讲师匹配用平台用户 id(user_id)——与后端 course.LecturerID == callerUserID 同口径。
|
||||
const myUserId = computed(() => myProfile.value?.user_id || '')
|
||||
const isMyTeaching = (c: TrainingCourse) => !!myUserId.value && c.lecturer_id === myUserId.value
|
||||
const isMyCourse = (c: TrainingCourse) => {
|
||||
if (myTaskByCourse.value.has(c.id)) return true
|
||||
if (isMyTeaching(c)) return true
|
||||
if (myEnrolledCourseIds.value.has(c.id)) return true
|
||||
const scope = c.dept_ids || []
|
||||
if (!scope.length) return true
|
||||
return !!myProfile.value && scope.includes(myProfile.value.dept_id)
|
||||
@@ -546,7 +552,7 @@ const loadAll = async () => {
|
||||
// 讲师/管理角色额外拉维护视角课程(纯讲师=自己名下含草稿;管理=全部,下方按讲师 id 过滤),
|
||||
// 供「我的培训」展示我主讲(含未发布)课程与「待维护」统计;纯学员无此视角,跳过。
|
||||
const needMaintainView = props.admin || props.roles.some((r) => ['hr', 'supervisor', 'exec', 'lecturer'].includes(r))
|
||||
const [c, t, s, me, lc, lib, exams] = await Promise.all([
|
||||
const [c, t, s, me, lc, lib, exams, enrolled] = await Promise.all([
|
||||
// 学员目录视图:scope=student 统一走已发布课程口径(讲师账号的学习视角不受课程维护范围影响)
|
||||
listCourses({ page_size: 100, scope: 'student' }),
|
||||
listMyLearningTasks().catch(() => null),
|
||||
@@ -558,6 +564,8 @@ const loadAll = async () => {
|
||||
listCourseLibrary({ page_size: 500, scope: 'catalog' }).catch(() => null),
|
||||
// 我的考试记录(000154)
|
||||
listMyExamRecords().catch(() => null),
|
||||
// 我经场次学员名单报名的课程 id(「我参加」判定;旧后端无此接口时回退空集)
|
||||
listMyEnrolledCourseIds().catch(() => null),
|
||||
])
|
||||
courses.value = unwrap(c)?.items || []
|
||||
myTasks.value = (t && unwrap(t)) || []
|
||||
@@ -566,6 +574,7 @@ const loadAll = async () => {
|
||||
lecturerCourses.value = (lc && unwrap(lc)?.items) || []
|
||||
libraryItems.value = (lib && unwrap(lib)?.items) || []
|
||||
myExamRecords.value = (exams && unwrap(exams)) || []
|
||||
myEnrolledCourseIds.value = new Set((enrolled && unwrap(enrolled)) || [])
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
|
||||
@@ -540,6 +540,19 @@ func (r *trainingRepository) CountEnrolledMembersByCourseID(ctx context.Context,
|
||||
return int(cnt), err
|
||||
}
|
||||
|
||||
// ListMyEnrolledCourseIDs 当前成员经场次学员名单报名的课程 id 去重集合
|
||||
// (我的培训「我参加」判定数据源)。名单为软删(ReplaceEnrollments 移除即置
|
||||
// deleted_at),故须过滤 e.deleted_at;场次软删行同样不计。
|
||||
func (r *trainingRepository) ListMyEnrolledCourseIDs(ctx context.Context, tenantID uint64, memberID string) ([]string, error) {
|
||||
ids := []string{}
|
||||
err := r.db.WithContext(ctx).
|
||||
Table("tr_enrollments e").
|
||||
Joins("JOIN tr_course_sessions s ON s.id = e.session_id AND s.tenant_id = e.tenant_id AND s.deleted_at IS NULL").
|
||||
Where("e.tenant_id = ? AND e.member_id = ? AND e.deleted_at IS NULL", tenantID, memberID).
|
||||
Distinct().Pluck("s.course_id", &ids).Error
|
||||
return ids, err
|
||||
}
|
||||
|
||||
// CourseStudyStats 按课程聚合签到/线上学习/考试参与成员(去重成员集合):
|
||||
// 签到走场次联查;学习任务直接带课程;考试支持场次卷与线上自学卷
|
||||
// (session 为空时经 paper→bank→course 兜底)两条路径。
|
||||
|
||||
@@ -1135,6 +1135,18 @@ func (s *trainingService) ListMyLearningTasks(ctx context.Context, tenantID uint
|
||||
return s.repo.ListLearningTasks(ctx, tenantID, member.ID)
|
||||
}
|
||||
|
||||
// ListMyEnrolledCourseIDs 我经场次学员名单报名的课程 id 去重集合(我的培训
|
||||
// 「我参加」判定数据源):参加人员此前只落场次名单与 post_scope 文案,不进
|
||||
// 任何"与我相关"判定,线下课参加人员在「我的培训」看不到课。未建培训档案
|
||||
// 返回空集(与 ListMyLearningTasks 同口径,不报错)。
|
||||
func (s *trainingService) ListMyEnrolledCourseIDs(ctx context.Context, tenantID uint64, userID string) ([]string, error) {
|
||||
member, err := s.repo.GetMemberByUserID(ctx, tenantID, userID)
|
||||
if err != nil {
|
||||
return []string{}, nil
|
||||
}
|
||||
return s.repo.ListMyEnrolledCourseIDs(ctx, tenantID, member.ID)
|
||||
}
|
||||
|
||||
// ListCourseLearningTasks returns all members' learning tasks of one course
|
||||
// (管理端「学习考试」课程学习情况;任务不存在但已发布课程的名单成员由前端按待学习渲染口径,此处按实际任务行返回)。
|
||||
func (s *trainingService) ListCourseLearningTasks(ctx context.Context, tenantID uint64, courseID string) ([]*types.TrainingLearningTask, error) {
|
||||
|
||||
@@ -0,0 +1,107 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"context"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"academy/internal/application/repository"
|
||||
"academy/internal/types"
|
||||
"github.com/stretchr/testify/require"
|
||||
"gorm.io/driver/sqlite"
|
||||
"gorm.io/gorm"
|
||||
"gorm.io/gorm/logger"
|
||||
)
|
||||
|
||||
// newMineEnrolledFixture 构建 sqlite + 真实仓储的 trainingService,专测
|
||||
// ListMyEnrolledCourseIDs(我的培训「我参加」判定数据源)。
|
||||
func newMineEnrolledFixture(t *testing.T) (*trainingService, *gorm.DB, uint64) {
|
||||
t.Helper()
|
||||
db, err := gorm.Open(
|
||||
sqlite.Open(filepath.Join(t.TempDir(), "training_mine_enrolled.db")+"?_busy_timeout=5000&_journal_mode=WAL"),
|
||||
&gorm.Config{Logger: logger.Default.LogMode(logger.Silent)},
|
||||
)
|
||||
require.NoError(t, err)
|
||||
raw, err := db.DB()
|
||||
require.NoError(t, err)
|
||||
t.Cleanup(func() { _ = raw.Close() })
|
||||
require.NoError(t, db.AutoMigrate(
|
||||
&types.OrgEmployee{}, &types.TrainingCourseSession{}, &types.TrainingEnrollment{},
|
||||
))
|
||||
const tenantID = uint64(42)
|
||||
svc := &trainingService{repo: repository.NewTrainingRepository(db), db: db}
|
||||
return svc, db, tenantID
|
||||
}
|
||||
|
||||
// seedMember 建 org_employees 档案(同空间同用户唯一,复用场景自行多次挂名单)。
|
||||
func seedMember(t *testing.T, db *gorm.DB, tenantID uint64, userID string) (memberID string) {
|
||||
t.Helper()
|
||||
member := types.OrgEmployee{ID: trainingNewID(), TenantID: tenantID, UserID: userID, Status: "active"}
|
||||
require.NoError(t, db.Create(&member).Error)
|
||||
return member.ID
|
||||
}
|
||||
|
||||
// seedEnrollment 为指定成员落一条 场次+名单 链路,返回名单行(供软删用例复用)。
|
||||
func seedEnrollment(t *testing.T, db *gorm.DB, tenantID uint64, memberID, courseID string) *types.TrainingEnrollment {
|
||||
t.Helper()
|
||||
sess := types.TrainingCourseSession{ID: trainingNewID(), TenantID: tenantID, CourseID: courseID, Status: "scheduled"}
|
||||
require.NoError(t, db.Create(&sess).Error)
|
||||
row := &types.TrainingEnrollment{ID: trainingNewID(), TenantID: tenantID, SessionID: sess.ID, MemberID: memberID}
|
||||
require.NoError(t, db.Create(row).Error)
|
||||
return row
|
||||
}
|
||||
|
||||
// 我的培训「我参加」:名单命中返回课程 id,跨场次/跨课程去重正确。
|
||||
func TestListMyEnrolledCourseIDs_HitsAndDistinct(t *testing.T) {
|
||||
svc, db, tenantID := newMineEnrolledFixture(t)
|
||||
ctx := context.Background()
|
||||
|
||||
// 课程A两条场次名单(去重为一个 id)+ 课程B一条名单
|
||||
memberID := seedMember(t, db, tenantID, "user-liu")
|
||||
seedEnrollment(t, db, tenantID, memberID, "course-A")
|
||||
seedEnrollment(t, db, tenantID, memberID, "course-A")
|
||||
seedEnrollment(t, db, tenantID, memberID, "course-B")
|
||||
|
||||
ids, err := svc.ListMyEnrolledCourseIDs(ctx, tenantID, "user-liu")
|
||||
require.NoError(t, err)
|
||||
require.ElementsMatch(t, []string{"course-A", "course-B"}, ids)
|
||||
}
|
||||
|
||||
// 排除口径:软删名单/软删场次/他人名单/其他空间名单均不进「我参加」。
|
||||
func TestListMyEnrolledCourseIDs_ExcludesDeletedAndForeign(t *testing.T) {
|
||||
svc, db, tenantID := newMineEnrolledFixture(t)
|
||||
ctx := context.Background()
|
||||
|
||||
// 命中一条基线(course-keep)
|
||||
memberID := seedMember(t, db, tenantID, "user-liu")
|
||||
seedEnrollment(t, db, tenantID, memberID, "course-keep")
|
||||
|
||||
// 软删名单(course-soft-del)
|
||||
rowDel := seedEnrollment(t, db, tenantID, memberID, "course-soft-del")
|
||||
require.NoError(t, db.Delete(rowDel).Error)
|
||||
|
||||
// 场次软删(course-sess-del)
|
||||
rowGone := seedEnrollment(t, db, tenantID, memberID, "course-sess-del")
|
||||
require.NoError(t, db.Model(&types.TrainingCourseSession{}).
|
||||
Where("id = ?", rowGone.SessionID).Delete(&types.TrainingCourseSession{}).Error)
|
||||
|
||||
// 他人名单(course-other-member):同会话名单换人不影响本人判定
|
||||
otherID := seedMember(t, db, tenantID, "user-other")
|
||||
seedEnrollment(t, db, tenantID, otherID, "course-other-member")
|
||||
|
||||
// 其他空间(tenant 43)同名用户名单
|
||||
otherTenantID := seedMember(t, db, tenantID+1, "user-liu")
|
||||
seedEnrollment(t, db, tenantID+1, otherTenantID, "course-other-tenant")
|
||||
|
||||
ids, err := svc.ListMyEnrolledCourseIDs(ctx, tenantID, "user-liu")
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, []string{"course-keep"}, ids)
|
||||
}
|
||||
|
||||
// 无培训档案用户返回空集不报错(与 ListMyLearningTasks 同口径)。
|
||||
func TestListMyEnrolledCourseIDs_NoMemberReturnsEmpty(t *testing.T) {
|
||||
svc, _, tenantID := newMineEnrolledFixture(t)
|
||||
ids, err := svc.ListMyEnrolledCourseIDs(context.Background(), tenantID, "user-without-profile")
|
||||
require.NoError(t, err)
|
||||
require.Empty(t, ids)
|
||||
}
|
||||
@@ -367,6 +367,18 @@ func (h *Handler) ListMyLearningTasks(c *gin.Context) {
|
||||
c.JSON(http.StatusOK, gin.H{"success": true, "data": items})
|
||||
}
|
||||
|
||||
// ListMyEnrolledCourseIds GET /training/my/enrolled-course-ids — 我经场次学员
|
||||
// 名单报名的课程 id 去重集合(我的培训「我参加」判定数据源,前端与学习任务/
|
||||
// 讲师/部门范围口径互补;登录即可查,自身名单本身即个人数据)。
|
||||
func (h *Handler) ListMyEnrolledCourseIds(c *gin.Context) {
|
||||
ids, err := h.svc.ListMyEnrolledCourseIDs(c.Request.Context(), callerTenantID(c), callerUserID(c))
|
||||
if err != nil {
|
||||
_ = c.Error(err)
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, gin.H{"success": true, "data": ids})
|
||||
}
|
||||
|
||||
// ListCourseLearningTasks GET /training/learning-tasks/all?course_id= —
|
||||
// 按课程返回全员学习任务(人事/课长/讲师的「学习考试」课程学习情况视图)。
|
||||
func (h *Handler) ListCourseLearningTasks(c *gin.Context) {
|
||||
|
||||
@@ -168,6 +168,8 @@ func RegisterTrainingRoutes(r *gin.RouterGroup, h *training.Handler, g *rbacGuar
|
||||
trainingGroup.GET("/learning-progress", h.ListMyCourseProgress)
|
||||
trainingGroup.GET("/learning-tasks", h.ListMyLearningTasks)
|
||||
trainingGroup.GET("/learning-tasks/all", h.ListCourseLearningTasks)
|
||||
// my/enrolled-course-ids 我经场次学员名单报名的课程 id 集合(我的培训「我参加」判定)。
|
||||
trainingGroup.GET("/my/enrolled-course-ids", h.ListMyEnrolledCourseIds)
|
||||
trainingGroup.POST("/course-feedbacks", h.SaveFeedback)
|
||||
trainingGroup.POST("/course-feedbacks/:id/reply", g.Contributor(), h.ReplyFeedback)
|
||||
trainingGroup.GET("/course-feedbacks/pending", h.ListPendingFeedbacks)
|
||||
|
||||
@@ -116,6 +116,9 @@ type TrainingRepository interface {
|
||||
CountEnrolledMembersByCourse(ctx context.Context, tenantID uint64) (map[string]int, error)
|
||||
// CountEnrolledMembersByCourseID 单课程场次学员名单人数(发布必填校验,000161)。
|
||||
CountEnrolledMembersByCourseID(ctx context.Context, tenantID uint64, courseID string) (int, error)
|
||||
// ListMyEnrolledCourseIDs 当前成员经场次学员名单报名的课程 id 去重集合
|
||||
// (我的培训「我参加」判定数据源;软删名单/软删场次不计)。
|
||||
ListMyEnrolledCourseIDs(ctx context.Context, tenantID uint64, memberID string) ([]string, error)
|
||||
// CourseStudyStats 按课程聚合签到/线上学习/考试参与成员(课程管理列表学习/考试状态列)。
|
||||
CourseStudyStats(ctx context.Context, tenantID uint64) (map[string]*types.TrainingCourseStudyStats, error)
|
||||
// CourseReporterDeptNames 各课程上报部门名(课程创建人所属部门,联查 org_employees/org_depts)。
|
||||
@@ -444,6 +447,9 @@ type TrainingService interface {
|
||||
// ListMyCourseProgress 当前用户在某课程下各课件的学习进度(学习详情页回读)。
|
||||
ListMyCourseProgress(ctx context.Context, tenantID uint64, userID, courseID string) ([]*types.TrainingLearningProgress, error)
|
||||
ListMyLearningTasks(ctx context.Context, tenantID uint64, userID string) ([]*types.TrainingLearningTask, error)
|
||||
// ListMyEnrolledCourseIDs 我经场次学员名单报名的课程 id 去重集合(我的培训
|
||||
// 「我参加」判定,与学习任务/讲师/部门范围口径互补;线下课参加人员由此可见)。
|
||||
ListMyEnrolledCourseIDs(ctx context.Context, tenantID uint64, userID string) ([]string, error)
|
||||
// ListCourseLearningTasks 按课程返回全员学习任务(人事/讲师课程学习情况)。
|
||||
ListCourseLearningTasks(ctx context.Context, tenantID uint64, courseID string) ([]*types.TrainingLearningTask, error)
|
||||
SaveFeedback(ctx context.Context, tenantID uint64, userID, sessionID string, rating int, comment string) (*types.TrainingCourseFeedback, error)
|
||||
|
||||
Reference in new issue
Block a user