Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ea0524c445 | ||
|
|
11450bdb96 |
No files matched your search
@@ -970,6 +970,10 @@ export const saveLearningProgress = (taskId: string, materialId: string, positio
|
|||||||
export const listMyLearningTasks = () =>
|
export const listMyLearningTasks = () =>
|
||||||
get<{ success: boolean; data: LearningTask[] }>(`${base}/learning-tasks`)
|
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 {
|
export interface CourseLearningTask extends LearningTask {
|
||||||
employee_no?: string
|
employee_no?: string
|
||||||
|
|||||||
@@ -13,6 +13,10 @@
|
|||||||
</t-tag>
|
</t-tag>
|
||||||
<h2 class="detail-name">{{ course?.name || '课程详情' }}</h2>
|
<h2 class="detail-name">{{ course?.name || '课程详情' }}</h2>
|
||||||
<t-tag v-if="course" theme="default" variant="outline" size="small">{{ typeText }}</t-tag>
|
<t-tag v-if="course" theme="default" variant="outline" size="small">{{ typeText }}</t-tag>
|
||||||
|
<!-- 培训签到:跳「培训签到」页并自动定位本课程场次(SignPanel 读取 courseId 查询参数) -->
|
||||||
|
<t-button v-if="course" variant="outline" theme="primary" size="small" class="detail-signin" @click="goSignin">
|
||||||
|
培训签到
|
||||||
|
</t-button>
|
||||||
</div>
|
</div>
|
||||||
<div class="detail-meta">
|
<div class="detail-meta">
|
||||||
<span v-if="course">学时 {{ course.hours }}<template v-if="course.credits"> · 学分 {{ course.credits }}</template></span>
|
<span v-if="course">学时 {{ course.hours }}<template v-if="course.credits"> · 学分 {{ course.credits }}</template></span>
|
||||||
@@ -348,6 +352,12 @@ const goBack = () => {
|
|||||||
else router.push('/platform/training/dashboard')
|
else router.push('/platform/training/dashboard')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 培训签到:携 courseId 跳「培训签到」页,SignPanel.applyRouteCourse 自动选中
|
||||||
|
// 该课程的进行中/最近场次(与「月培训计划-记录」跳转同一查询参数口径)。
|
||||||
|
const goSignin = () => {
|
||||||
|
router.push({ path: '/platform/training/sign', query: { courseId } })
|
||||||
|
}
|
||||||
|
|
||||||
const loadAll = async () => {
|
const loadAll = async () => {
|
||||||
loading.value = true
|
loading.value = true
|
||||||
try {
|
try {
|
||||||
@@ -404,6 +414,12 @@ onMounted(loadAll)
|
|||||||
flex-shrink: 0;
|
flex-shrink: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 培训签到入口:页头行右对齐(2026-11 需求)
|
||||||
|
.detail-signin {
|
||||||
|
margin-left: auto;
|
||||||
|
flex-shrink: 0;
|
||||||
|
}
|
||||||
|
|
||||||
.detail-name {
|
.detail-name {
|
||||||
margin: 0;
|
margin: 0;
|
||||||
font-size: var(--app-text-xl, 20px);
|
font-size: var(--app-text-xl, 20px);
|
||||||
|
|||||||
@@ -30,6 +30,9 @@
|
|||||||
<template v-if="filter === 'mine'">
|
<template v-if="filter === 'mine'">
|
||||||
<span class="catalog-stats__maintain" :class="{ 'is-alert': maintainCount > 0 }">待维护 {{ maintainCount }} 门</span>
|
<span class="catalog-stats__maintain" :class="{ 'is-alert': maintainCount > 0 }">待维护 {{ maintainCount }} 门</span>
|
||||||
<span class="catalog-stats__pending" :class="{ 'is-info': pendingStartCount > 0 }">待开始 {{ pendingStartCount }} 门</span>
|
<span class="catalog-stats__pending" :class="{ 'is-info': pendingStartCount > 0 }">待开始 {{ pendingStartCount }} 门</span>
|
||||||
|
<!-- 我主讲/我参加统计(2026-11 需求):与卡片角标同口径着色(主讲橙/参加蓝) -->
|
||||||
|
<span class="catalog-stats__teach" :class="{ 'is-teach': teachingCount > 0 }">我主讲 {{ teachingCount }} 门</span>
|
||||||
|
<span class="catalog-stats__attend" :class="{ 'is-attend': attendCount > 0 }">我参加 {{ attendCount }} 门</span>
|
||||||
</template>
|
</template>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -152,6 +155,7 @@ import {
|
|||||||
getMyProfile,
|
getMyProfile,
|
||||||
listCourses,
|
listCourses,
|
||||||
listCourseLibrary,
|
listCourseLibrary,
|
||||||
|
listMyEnrolledCourseIds,
|
||||||
listMyExamRecords,
|
listMyExamRecords,
|
||||||
listMyLearningTasks,
|
listMyLearningTasks,
|
||||||
listSessions,
|
listSessions,
|
||||||
@@ -241,6 +245,8 @@ const lecturerCourses = ref<TrainingCourse[]>([])
|
|||||||
const myProfile = ref<TrainingMember | null>(null)
|
const myProfile = ref<TrainingMember | null>(null)
|
||||||
const myTasks = ref<LearningTask[]>([])
|
const myTasks = ref<LearningTask[]>([])
|
||||||
const sessions = ref<TrainingCourseSession[]>([])
|
const sessions = ref<TrainingCourseSession[]>([])
|
||||||
|
// 我经场次学员名单报名的课程 id 集合(「我参加」判定;失败回退空集不阻断)
|
||||||
|
const myEnrolledCourseIds = ref<Set<string>>(new Set())
|
||||||
// 课程管理资产(000154):「和信课程」目录 = 课程管理已发布且部门范围覆盖查看人的课程
|
// 课程管理资产(000154):「和信课程」目录 = 课程管理已发布且部门范围覆盖查看人的课程
|
||||||
const libraryItems = ref<TrainingLibraryCourse[]>([])
|
const libraryItems = ref<TrainingLibraryCourse[]>([])
|
||||||
// 我的考试记录(000154):「我的考试」页签数据源
|
// 我的考试记录(000154):「我的考试」页签数据源
|
||||||
@@ -311,13 +317,16 @@ const myTaskByCourse = computed(() => {
|
|||||||
|
|
||||||
// 「我的课程」相关性口径(与后端推送口径一致):
|
// 「我的课程」相关性口径(与后端推送口径一致):
|
||||||
// ① 我有该课学习任务(线上必修按部门推送);② 我是该课讲师;
|
// ① 我有该课学习任务(线上必修按部门推送);② 我是该课讲师;
|
||||||
// ③ 课程部门范围覆盖我(dept_ids 为空 = 全员可见,非空需包含我的部门)。
|
// ③ 课程部门范围覆盖我(dept_ids 为空 = 全员可见,非空需包含我的部门);
|
||||||
|
// ④ 我是该课场次参加人员(学员名单接口,线下课参加人员由此可见——此前参加
|
||||||
|
// 人员只落名单与文案,不进任何"与我相关"判定,被设为参加人员却看不到课)。
|
||||||
// 讲师匹配用平台用户 id(user_id)——与后端 course.LecturerID == callerUserID 同口径。
|
// 讲师匹配用平台用户 id(user_id)——与后端 course.LecturerID == callerUserID 同口径。
|
||||||
const myUserId = computed(() => myProfile.value?.user_id || '')
|
const myUserId = computed(() => myProfile.value?.user_id || '')
|
||||||
const isMyTeaching = (c: TrainingCourse) => !!myUserId.value && c.lecturer_id === myUserId.value
|
const isMyTeaching = (c: TrainingCourse) => !!myUserId.value && c.lecturer_id === myUserId.value
|
||||||
const isMyCourse = (c: TrainingCourse) => {
|
const isMyCourse = (c: TrainingCourse) => {
|
||||||
if (myTaskByCourse.value.has(c.id)) return true
|
if (myTaskByCourse.value.has(c.id)) return true
|
||||||
if (isMyTeaching(c)) return true
|
if (isMyTeaching(c)) return true
|
||||||
|
if (myEnrolledCourseIds.value.has(c.id)) return true
|
||||||
const scope = c.dept_ids || []
|
const scope = c.dept_ids || []
|
||||||
if (!scope.length) return true
|
if (!scope.length) return true
|
||||||
return !!myProfile.value && scope.includes(myProfile.value.dept_id)
|
return !!myProfile.value && scope.includes(myProfile.value.dept_id)
|
||||||
@@ -348,6 +357,13 @@ const myCoursesSource = computed<TrainingCourse[]>(() => {
|
|||||||
// 待维护 = 我主讲且「草稿」状态的课程(2026-11 需求:待审/已发布缺课件不再计入统计)
|
// 待维护 = 我主讲且「草稿」状态的课程(2026-11 需求:待审/已发布缺课件不再计入统计)
|
||||||
const maintainCount = computed(() => myTeachingCourses.value.filter((c) => c.status === 'draft').length)
|
const maintainCount = computed(() => myTeachingCourses.value.filter((c) => c.status === 'draft').length)
|
||||||
|
|
||||||
|
// 我主讲/我参加统计(2026-11 需求):我主讲含未发布(与「我的培训」页签同源);
|
||||||
|
// 我参加 = 我在名单中的已发布课程数(纯参加口径,主讲不计,与「我参加」角标一致)
|
||||||
|
const teachingCount = computed(() => myTeachingCourses.value.length)
|
||||||
|
const attendCount = computed(() =>
|
||||||
|
publishedCourses.value.filter((c) => myEnrolledCourseIds.value.has(c.id) && !isMyTeaching(c)).length,
|
||||||
|
)
|
||||||
|
|
||||||
// 置顶排序/维护按钮仍关注未发布(草稿/待审)或已发布但未上传课件的课程
|
// 置顶排序/维护按钮仍关注未发布(草稿/待审)或已发布但未上传课件的课程
|
||||||
const needsMaintain = (c: TrainingCourse) => c.status !== 'published' || !c.material_ids?.length
|
const needsMaintain = (c: TrainingCourse) => c.status !== 'published' || !c.material_ids?.length
|
||||||
|
|
||||||
@@ -485,7 +501,9 @@ const visibleCards = computed<CatalogCard[]>(() => {
|
|||||||
}
|
}
|
||||||
return list
|
return list
|
||||||
.map((c) => {
|
.map((c) => {
|
||||||
const head = [c.post_scope, typeText(c), `${c.hours} 学时`, c.exam_enabled ? '随堂考试' : ''].filter(Boolean).join(' · ')
|
// meta 首段为参加人员文案(post_scope),加「参加:」前缀——裸名字会被误读成讲师名
|
||||||
|
// (讲师身份以「我主讲」角标为准,角标判定口径见 isMyTeaching)。
|
||||||
|
const head = [c.post_scope ? `参加:${c.post_scope}` : '', typeText(c), `${c.hours} 学时`, c.exam_enabled ? '随堂考试' : ''].filter(Boolean).join(' · ')
|
||||||
const maintainable = isMyTeaching(c) && canMaintainCourses.value
|
const maintainable = isMyTeaching(c) && canMaintainCourses.value
|
||||||
const unpublished = c.status !== 'published'
|
const unpublished = c.status !== 'published'
|
||||||
// 「我的培训」角色标记:我主讲(优先) / 我参加,其余视图不标记
|
// 「我的培训」角色标记:我主讲(优先) / 我参加,其余视图不标记
|
||||||
@@ -546,7 +564,7 @@ const loadAll = async () => {
|
|||||||
// 讲师/管理角色额外拉维护视角课程(纯讲师=自己名下含草稿;管理=全部,下方按讲师 id 过滤),
|
// 讲师/管理角色额外拉维护视角课程(纯讲师=自己名下含草稿;管理=全部,下方按讲师 id 过滤),
|
||||||
// 供「我的培训」展示我主讲(含未发布)课程与「待维护」统计;纯学员无此视角,跳过。
|
// 供「我的培训」展示我主讲(含未发布)课程与「待维护」统计;纯学员无此视角,跳过。
|
||||||
const needMaintainView = props.admin || props.roles.some((r) => ['hr', 'supervisor', 'exec', 'lecturer'].includes(r))
|
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 统一走已发布课程口径(讲师账号的学习视角不受课程维护范围影响)
|
// 学员目录视图:scope=student 统一走已发布课程口径(讲师账号的学习视角不受课程维护范围影响)
|
||||||
listCourses({ page_size: 100, scope: 'student' }),
|
listCourses({ page_size: 100, scope: 'student' }),
|
||||||
listMyLearningTasks().catch(() => null),
|
listMyLearningTasks().catch(() => null),
|
||||||
@@ -558,6 +576,8 @@ const loadAll = async () => {
|
|||||||
listCourseLibrary({ page_size: 500, scope: 'catalog' }).catch(() => null),
|
listCourseLibrary({ page_size: 500, scope: 'catalog' }).catch(() => null),
|
||||||
// 我的考试记录(000154)
|
// 我的考试记录(000154)
|
||||||
listMyExamRecords().catch(() => null),
|
listMyExamRecords().catch(() => null),
|
||||||
|
// 我经场次学员名单报名的课程 id(「我参加」判定;旧后端无此接口时回退空集)
|
||||||
|
listMyEnrolledCourseIds().catch(() => null),
|
||||||
])
|
])
|
||||||
courses.value = unwrap(c)?.items || []
|
courses.value = unwrap(c)?.items || []
|
||||||
myTasks.value = (t && unwrap(t)) || []
|
myTasks.value = (t && unwrap(t)) || []
|
||||||
@@ -566,6 +586,7 @@ const loadAll = async () => {
|
|||||||
lecturerCourses.value = (lc && unwrap(lc)?.items) || []
|
lecturerCourses.value = (lc && unwrap(lc)?.items) || []
|
||||||
libraryItems.value = (lib && unwrap(lib)?.items) || []
|
libraryItems.value = (lib && unwrap(lib)?.items) || []
|
||||||
myExamRecords.value = (exams && unwrap(exams)) || []
|
myExamRecords.value = (exams && unwrap(exams)) || []
|
||||||
|
myEnrolledCourseIds.value = new Set((enrolled && unwrap(enrolled)) || [])
|
||||||
} finally {
|
} finally {
|
||||||
loading.value = false
|
loading.value = false
|
||||||
}
|
}
|
||||||
@@ -662,6 +683,26 @@ onMounted(loadAll)
|
|||||||
font-weight: 600;
|
font-weight: 600;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 我主讲统计:与「我主讲」角标同色(warning 橙)
|
||||||
|
&__teach {
|
||||||
|
margin-left: 6px;
|
||||||
|
|
||||||
|
&.is-teach {
|
||||||
|
color: var(--td-warning-color);
|
||||||
|
font-weight: 600;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 我参加统计:与「我参加」角标同色(primary 蓝)
|
||||||
|
&__attend {
|
||||||
|
margin-left: 6px;
|
||||||
|
|
||||||
|
&.is-attend {
|
||||||
|
color: var(--td-brand-color);
|
||||||
|
font-weight: 600;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.catalog-grid-wrap {
|
.catalog-grid-wrap {
|
||||||
|
|||||||
@@ -59,6 +59,15 @@
|
|||||||
<div class="upload-card__hint">{{ uploading ? '上传中…' : '课程实录留证 · 每个 ≤ ' + VIDEO_MAX_MB + 'MB' }}</div>
|
<div class="upload-card__hint">{{ uploading ? '上传中…' : '课程实录留证 · 每个 ≤ ' + VIDEO_MAX_MB + 'MB' }}</div>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
<!-- 培训详情:回跳课程学习详情页(与课程详情页「培训签到」按钮互为出入口) -->
|
||||||
|
<div v-if="selectedCourseId" class="stat-card upload-card" role="button" tabindex="0" @click="goCourseDetail" @keydown.enter="goCourseDetail">
|
||||||
|
<div class="stat-card__label">培训详情</div>
|
||||||
|
<div class="upload-card__main">
|
||||||
|
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round"><path d="M4 19V5a2 2 0 0 1 2-2h12a2 2 0 0 1 2 2v14"/><path d="M2 19h20"/><path d="M8 7h8M8 11h6"/></svg>
|
||||||
|
<span :title="courseName(selectedCourseId)">{{ courseName(selectedCourseId) }}</span>
|
||||||
|
</div>
|
||||||
|
<div class="upload-card__hint">查看课程课件 / 随堂考试详情</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<input ref="photoInput" type="file" accept="image/*" multiple class="visually-hidden-input" @change="onEvidenceFiles($event, 'sign_photo')" />
|
<input ref="photoInput" type="file" accept="image/*" multiple class="visually-hidden-input" @change="onEvidenceFiles($event, 'sign_photo')" />
|
||||||
<input ref="videoInput" type="file" accept="video/*" multiple class="visually-hidden-input" @change="onEvidenceFiles($event, 'training_video')" />
|
<input ref="videoInput" type="file" accept="video/*" multiple class="visually-hidden-input" @change="onEvidenceFiles($event, 'training_video')" />
|
||||||
@@ -151,7 +160,7 @@
|
|||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { computed, onMounted, ref, watch } from 'vue'
|
import { computed, onMounted, ref, watch } from 'vue'
|
||||||
import { useRoute } from 'vue-router'
|
import { useRoute, useRouter } from 'vue-router'
|
||||||
import { MessagePlugin } from 'tdesign-vue-next'
|
import { MessagePlugin } from 'tdesign-vue-next'
|
||||||
import QRCode from 'qrcode'
|
import QRCode from 'qrcode'
|
||||||
import {
|
import {
|
||||||
@@ -182,6 +191,7 @@ import { fmtBeijingTime } from '@/utils/datetime'
|
|||||||
|
|
||||||
const props = defineProps<{ roles: string[]; admin?: boolean }>()
|
const props = defineProps<{ roles: string[]; admin?: boolean }>()
|
||||||
const route = useRoute()
|
const route = useRoute()
|
||||||
|
const router = useRouter()
|
||||||
// 签到复核/代签:人事/课长(roles 已按权限组展开,经理自动命中)
|
// 签到复核/代签:人事/课长(roles 已按权限组展开,经理自动命中)
|
||||||
const canReview = computed(() => props.admin || props.roles.some((r) => r === 'hr' || r === 'supervisor'))
|
const canReview = computed(() => props.admin || props.roles.some((r) => r === 'hr' || r === 'supervisor'))
|
||||||
// 佐证上传/删除:人事/课长/讲师(与课件上传同口径)
|
// 佐证上传/删除:人事/课长/讲师(与课件上传同口径)
|
||||||
@@ -197,6 +207,15 @@ const exportLoading = ref(false)
|
|||||||
const sessions = ref<TrainingCourseSession[]>([])
|
const sessions = ref<TrainingCourseSession[]>([])
|
||||||
const courses = ref<TrainingCourse[]>([])
|
const courses = ref<TrainingCourse[]>([])
|
||||||
const selectedSessionId = ref('')
|
const selectedSessionId = ref('')
|
||||||
|
// 当前选中场次的课程 id:「培训详情」卡片回跳课程学习详情页用(2026-11 需求)
|
||||||
|
const selectedCourseId = computed(
|
||||||
|
() => sessions.value.find((s) => s.id === selectedSessionId.value)?.course_id || '',
|
||||||
|
)
|
||||||
|
// 培训详情:携课程 id 跳「培训签到」页的同源落地页(课程学习详情)。
|
||||||
|
const goCourseDetail = () => {
|
||||||
|
if (!selectedCourseId.value) return
|
||||||
|
router.push({ path: `/platform/training/course/${selectedCourseId.value}` })
|
||||||
|
}
|
||||||
const signCode = ref<TrainingSignCode | null>(null)
|
const signCode = ref<TrainingSignCode | null>(null)
|
||||||
const summary = ref<SignSummary | null>(null)
|
const summary = ref<SignSummary | null>(null)
|
||||||
const records = ref<TrainingSignRecord[]>([])
|
const records = ref<TrainingSignRecord[]>([])
|
||||||
|
|||||||
@@ -540,6 +540,19 @@ func (r *trainingRepository) CountEnrolledMembersByCourseID(ctx context.Context,
|
|||||||
return int(cnt), err
|
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 按课程聚合签到/线上学习/考试参与成员(去重成员集合):
|
// CourseStudyStats 按课程聚合签到/线上学习/考试参与成员(去重成员集合):
|
||||||
// 签到走场次联查;学习任务直接带课程;考试支持场次卷与线上自学卷
|
// 签到走场次联查;学习任务直接带课程;考试支持场次卷与线上自学卷
|
||||||
// (session 为空时经 paper→bank→course 兜底)两条路径。
|
// (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)
|
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
|
// ListCourseLearningTasks returns all members' learning tasks of one course
|
||||||
// (管理端「学习考试」课程学习情况;任务不存在但已发布课程的名单成员由前端按待学习渲染口径,此处按实际任务行返回)。
|
// (管理端「学习考试」课程学习情况;任务不存在但已发布课程的名单成员由前端按待学习渲染口径,此处按实际任务行返回)。
|
||||||
func (s *trainingService) ListCourseLearningTasks(ctx context.Context, tenantID uint64, courseID string) ([]*types.TrainingLearningTask, error) {
|
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})
|
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= —
|
// ListCourseLearningTasks GET /training/learning-tasks/all?course_id= —
|
||||||
// 按课程返回全员学习任务(人事/课长/讲师的「学习考试」课程学习情况视图)。
|
// 按课程返回全员学习任务(人事/课长/讲师的「学习考试」课程学习情况视图)。
|
||||||
func (h *Handler) ListCourseLearningTasks(c *gin.Context) {
|
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-progress", h.ListMyCourseProgress)
|
||||||
trainingGroup.GET("/learning-tasks", h.ListMyLearningTasks)
|
trainingGroup.GET("/learning-tasks", h.ListMyLearningTasks)
|
||||||
trainingGroup.GET("/learning-tasks/all", h.ListCourseLearningTasks)
|
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", h.SaveFeedback)
|
||||||
trainingGroup.POST("/course-feedbacks/:id/reply", g.Contributor(), h.ReplyFeedback)
|
trainingGroup.POST("/course-feedbacks/:id/reply", g.Contributor(), h.ReplyFeedback)
|
||||||
trainingGroup.GET("/course-feedbacks/pending", h.ListPendingFeedbacks)
|
trainingGroup.GET("/course-feedbacks/pending", h.ListPendingFeedbacks)
|
||||||
|
|||||||
@@ -116,6 +116,9 @@ type TrainingRepository interface {
|
|||||||
CountEnrolledMembersByCourse(ctx context.Context, tenantID uint64) (map[string]int, error)
|
CountEnrolledMembersByCourse(ctx context.Context, tenantID uint64) (map[string]int, error)
|
||||||
// CountEnrolledMembersByCourseID 单课程场次学员名单人数(发布必填校验,000161)。
|
// CountEnrolledMembersByCourseID 单课程场次学员名单人数(发布必填校验,000161)。
|
||||||
CountEnrolledMembersByCourseID(ctx context.Context, tenantID uint64, courseID string) (int, error)
|
CountEnrolledMembersByCourseID(ctx context.Context, tenantID uint64, courseID string) (int, error)
|
||||||
|
// ListMyEnrolledCourseIDs 当前成员经场次学员名单报名的课程 id 去重集合
|
||||||
|
// (我的培训「我参加」判定数据源;软删名单/软删场次不计)。
|
||||||
|
ListMyEnrolledCourseIDs(ctx context.Context, tenantID uint64, memberID string) ([]string, error)
|
||||||
// CourseStudyStats 按课程聚合签到/线上学习/考试参与成员(课程管理列表学习/考试状态列)。
|
// CourseStudyStats 按课程聚合签到/线上学习/考试参与成员(课程管理列表学习/考试状态列)。
|
||||||
CourseStudyStats(ctx context.Context, tenantID uint64) (map[string]*types.TrainingCourseStudyStats, error)
|
CourseStudyStats(ctx context.Context, tenantID uint64) (map[string]*types.TrainingCourseStudyStats, error)
|
||||||
// CourseReporterDeptNames 各课程上报部门名(课程创建人所属部门,联查 org_employees/org_depts)。
|
// CourseReporterDeptNames 各课程上报部门名(课程创建人所属部门,联查 org_employees/org_depts)。
|
||||||
@@ -444,6 +447,9 @@ type TrainingService interface {
|
|||||||
// ListMyCourseProgress 当前用户在某课程下各课件的学习进度(学习详情页回读)。
|
// ListMyCourseProgress 当前用户在某课程下各课件的学习进度(学习详情页回读)。
|
||||||
ListMyCourseProgress(ctx context.Context, tenantID uint64, userID, courseID string) ([]*types.TrainingLearningProgress, error)
|
ListMyCourseProgress(ctx context.Context, tenantID uint64, userID, courseID string) ([]*types.TrainingLearningProgress, error)
|
||||||
ListMyLearningTasks(ctx context.Context, tenantID uint64, userID string) ([]*types.TrainingLearningTask, 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 按课程返回全员学习任务(人事/讲师课程学习情况)。
|
||||||
ListCourseLearningTasks(ctx context.Context, tenantID uint64, courseID string) ([]*types.TrainingLearningTask, error)
|
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)
|
SaveFeedback(ctx context.Context, tenantID uint64, userID, sessionID string, rating int, comment string) (*types.TrainingCourseFeedback, error)
|
||||||
|
|||||||
Reference in new issue
Block a user