fix(课程管理):CourseCatalog.vue:删除客户端权限复算(服务端 scope=catalog 是唯一权威口径);目录加载失败时空态明确提示「课程目录加载失败…请联系管理员检查服务版本与数据库迁移」,不再静默显示“暂无课程”。
deploy-hxtesting / build-and-deploy (push) Successful in 1m13s
deploy-hxtesting / build-and-deploy (push) Successful in 1m13s
后端权限 SQL:部门命中增加部门名回退(调用方部门名与权限部门按 org_depts 反查同名即命中,仍是同部门,无越权)。 迁移 000164 增补存量回填:旧版本时代“已审核+已有课件”但停在待发布的课程自动补发布(新流程没有发布按钮,这批课不回填会永远卡住)。 前端 onPublish:授课时间/地点校验改为“课程级字段 或 场次排期值”任一存在即放行(新增 firstUsableSession,与列表列同一取值逻辑)。 后端 PublishCourse:同样在校验前以 FirstCourseSession(新增仓储方法,排期中优先)兜底,防止前端放过、后端仍拦截。
This commit is contained in:
1 parent
6defb1f2c6
commit
a448598df5
7 files changed
+112
-38
No files matched your search
@@ -99,7 +99,7 @@
|
||||
<t-empty
|
||||
v-if="!loading && !visibleCards.length"
|
||||
class="catalog-empty"
|
||||
:description="filter === 'mine' ? '暂无与我相关的课程' : '暂无已发布课程(课程管理发布后在此展示)'"
|
||||
:description="emptyText"
|
||||
/>
|
||||
<!-- 共用分页(000163):课程卡片默认每页 15 条 -->
|
||||
<TrainingPagination v-model:current="cardPage" v-model:page-size="cardPageSize" :total="cardTotal" />
|
||||
@@ -265,37 +265,26 @@ const FILTERS = [
|
||||
// 工作台进目录默认落在「我的培训」(与我相关的课优先展示)
|
||||
const filter = ref<string>('mine')
|
||||
const keyword = ref('')
|
||||
// 和信课程目录加载失败标记:目录查询异常(如服务版本与数据库迁移不一致)时
|
||||
// 空态给出明确提示,不再静默显示「暂无课程」误导排查方向
|
||||
const catalogLoadFailed = ref(false)
|
||||
// 目录空态文案:按页签与加载状态区分(加载失败时优先提示)
|
||||
const emptyText = computed(() => {
|
||||
if (filter.value !== 'mine' && filter.value !== 'exam' && catalogLoadFailed.value) {
|
||||
return '课程目录加载失败,请刷新重试;若持续出现请联系管理员检查服务版本与数据库迁移'
|
||||
}
|
||||
return filter.value === 'mine' ? '暂无与我相关的课程' : '暂无已发布课程(课程管理发布后在此展示)'
|
||||
})
|
||||
|
||||
// 目录页面向全体员工:仅展示已发布课程(草稿/待审在「培训课程」维护)
|
||||
const publishedCourses = computed(() => courses.value.filter((c) => c.status === 'published'))
|
||||
|
||||
// 「和信课程」(000160):已发布 + 课程权限覆盖查看人。000163 权限口径:
|
||||
// perm_dept_ids 含我的部门 id 或 perm_user_ids 含我的用户 id 即可见;perm 两列
|
||||
// 为空的存量课程沿用适合人员老口径 —— 「全部」全员可见,000159 多部门口径按
|
||||
// 「、」拆分(逗号/分号兼容归一)后与我的部门名成员匹配;未设置适合人员的
|
||||
// 存量课程沿用原部门范围口径(所属部门为空 = 全员,否则须与我的部门一致)。
|
||||
// 后端 scope=catalog 已按同口径过滤,此处保留客户端兜底。
|
||||
const myDeptId = computed(() => myProfile.value?.dept_id || '')
|
||||
const myDeptName = computed(() => (myProfile.value?.dept_name || '').trim())
|
||||
const myPermUserId = computed(() => myProfile.value?.user_id || '')
|
||||
const splitNames = (v: string) =>
|
||||
(v || '').split(/[、,,;;]/).map((s) => s.trim()).filter(Boolean)
|
||||
const inPermIds = (ids: string, want: string) =>
|
||||
Boolean(want) && ids.split(',').map((s) => s.trim()).includes(want)
|
||||
// 「和信课程」(000160):已发布课程目录。课程权限(000163)由后端 scope=catalog
|
||||
// 按调用方部门/人员统一过滤,此处只保留发布状态过滤 —— 不再做客户端权限复算:
|
||||
// 此前按我的档案部门/用户 id 复算,调用方档案缺部门(或 id 口径不一致)时会把
|
||||
// 服务端已授权的课程误杀,表现为「审核通过后和信课程看不到」(2026-11-26 复测修复)。
|
||||
const hexinCourses = computed<TrainingLibraryCourse[]>(() =>
|
||||
libraryItems.value.filter((c) => {
|
||||
if (c.publish_status !== 'published') return false
|
||||
// 新口径(000163):perm 任一列非空按 id 精确匹配
|
||||
if ((c.perm_dept_ids || '').trim() || (c.perm_user_ids || '').trim()) {
|
||||
return inPermIds(c.perm_dept_ids || '', myDeptId.value) || inPermIds(c.perm_user_ids || '', myPermUserId.value)
|
||||
}
|
||||
// 存量老口径:suitable_members 文本 / 所属部门兜底
|
||||
const suitableNames = splitNames(c.suitable_members || '')
|
||||
if (suitableNames.length) {
|
||||
return suitableNames.includes('全部') || (!!myDeptName.value && suitableNames.includes(myDeptName.value))
|
||||
}
|
||||
return !c.owner_dept_id || !myDeptId.value || c.owner_dept_id === myDeptId.value
|
||||
}),
|
||||
libraryItems.value.filter((c) => c.publish_status === 'published'),
|
||||
)
|
||||
|
||||
const statsText = computed(() => {
|
||||
@@ -595,6 +584,7 @@ watch([examRows, visibleCards, filter], () => {
|
||||
|
||||
const loadAll = async () => {
|
||||
loading.value = true
|
||||
catalogLoadFailed.value = false
|
||||
try {
|
||||
// 讲师/管理角色额外拉维护视角课程(纯讲师=自己名下含草稿;管理=全部,下方按讲师 id 过滤),
|
||||
// 供「我的培训」展示我主讲(含未发布)课程与「待维护」统计;纯学员无此视角,跳过。
|
||||
@@ -606,9 +596,14 @@ const loadAll = async () => {
|
||||
listSessions({ year: 0, month: 0, scope: 'student' }).catch(() => null),
|
||||
getMyProfile().catch(() => null),
|
||||
needMaintainView ? listCourses({ page_size: 100 }).catch(() => null) : Promise.resolve(null),
|
||||
// 和信课程目录(000160):scope=catalog —— 已发布 + 适合人员覆盖查看人
|
||||
// (全部/本部门;未设置沿用部门范围口径),不按维护角色收窄,全体员工同源
|
||||
listCourseLibrary({ page_size: 500, scope: 'catalog' }).catch(() => null),
|
||||
// 和信课程目录(000160):scope=catalog —— 已发布 + 课程权限覆盖查看人
|
||||
// (000163 部门/人员 id 精确匹配;存量课程沿用老口径),后端按权限过滤
|
||||
listCourseLibrary({ page_size: 500, scope: 'catalog' }).catch(() => {
|
||||
// 目录查询失败不再静默吞成「暂无课程」(此前服务版本与数据库迁移不一致
|
||||
// 时表现为「审核通过后和信课程看不到」且无任何提示,2026-11-26 复测修复)
|
||||
catalogLoadFailed.value = true
|
||||
return null
|
||||
}),
|
||||
// 我的考试记录(000154)
|
||||
listMyExamRecords().catch(() => null),
|
||||
// 我经场次学员名单报名的课程 id(「我参加」判定;旧后端无此接口时回退空集)
|
||||
|
||||
@@ -1345,6 +1345,16 @@ const courseLocation = (row: TrainingCourse) => {
|
||||
// 回退课程自身地点(来自需求确认同步落库的 course.location)
|
||||
return nearest?.location || row.location || ''
|
||||
}
|
||||
// 最靠前的有效场次(带授课时间或地点):发布前置校验与列表展示同口径用
|
||||
// (课程级授课时间/地点为空的存量草稿,场次已排期即视为已维护,2026-11-26)
|
||||
const firstUsableSession = (row: TrainingCourse) => {
|
||||
const list = courseSessions.value[row.id] || []
|
||||
return (
|
||||
list.find((s) => s.status === 'scheduled' && (s.start_at || s.location)) ||
|
||||
list.find((s) => s.start_at || s.location) ||
|
||||
null
|
||||
)
|
||||
}
|
||||
// 授课时间展示:期望月份默认值(YYYY-MM)→「2026/11」;具体时间 → 北京时间无秒;线上课默认「长期」
|
||||
const teachTimeText = (row: TrainingCourse) => {
|
||||
if (row.mode === 'online') return row.teach_time ? teachTimeDisplay(row.teach_time) : '长期'
|
||||
@@ -1582,11 +1592,15 @@ const onPublish = async (row: TrainingCourse) => {
|
||||
MessagePlugin.warning(`「${row.name}」是线下计划,发布前需先在「调整」中指定讲师`)
|
||||
return
|
||||
}
|
||||
if (!row.teach_time) {
|
||||
// 授课时间/地点与列表展示同口径(场次排期优先,课程级字段兜底):存量草稿
|
||||
// 课程级字段为空但场次已排期时不再误报「未设置」(2026-11-26 复测修复,
|
||||
// 后端 PublishCourse 同口径兜底)
|
||||
const session = firstUsableSession(row)
|
||||
if (!row.teach_time && !session?.start_at) {
|
||||
MessagePlugin.warning(`「${row.name}」是线下计划,发布前需先在「调整」中设置授课时间`)
|
||||
return
|
||||
}
|
||||
if (!row.location) {
|
||||
if (!courseLocation(row)) {
|
||||
MessagePlugin.warning(`「${row.name}」是线下计划,发布前需先在「调整」中设置授课地点`)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -14,13 +14,19 @@ import (
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
// courseLibraryPermissionMatchSQL 课程权限覆盖判定(000163):
|
||||
// - perm_dept_ids 含调用方部门 id,或 perm_user_ids 含调用方用户 id → 可见;
|
||||
// - perm_dept_ids 含调用方部门 id → 可见;或调用方部门名与 perm 列表中某部门
|
||||
// (org_depts 按 id 反查)同名 → 可见(2026-11-26 复测加固:个别环境员工
|
||||
// 档案 dept_id 与部门选择器落库的 id 口径不一致时,同部门仍按名命中);
|
||||
// - perm_user_ids 含调用方用户 id → 可见;
|
||||
// - perm 两列为空的存量课程沿用 suitable_members 老口径:'全部' 全员可见 /
|
||||
// 部门名成员匹配(逗号/分号归一为「、」)/ 所属部门兜底(空=全员)。
|
||||
//
|
||||
// 参数顺序:PermDeptID×2, PermUserID×2, '全部', 调用方部门名×2, 调用方部门 id×2。
|
||||
const courseLibraryPermissionMatchSQL = "tr_course_library.perm_dept_ids <> '' AND ? <> '' AND ? = ANY(string_to_array(tr_course_library.perm_dept_ids, ',')) " +
|
||||
"OR tr_course_library.perm_user_ids <> '' AND ? <> '' AND ? = ANY(string_to_array(tr_course_library.perm_user_ids, ',')) " +
|
||||
// 参数顺序:PermDeptID×2, CatalogDeptName×2, PermUserID×2,
|
||||
// '全部', CatalogDeptName×2, CatalogDeptID×2。
|
||||
const courseLibraryPermissionMatchSQL = "(tr_course_library.perm_dept_ids <> '' AND ((? <> '' AND ? = ANY(string_to_array(tr_course_library.perm_dept_ids, ','))) " +
|
||||
"OR (? <> '' AND EXISTS (SELECT 1 FROM org_depts pd WHERE pd.tenant_id = tr_course_library.tenant_id AND pd.deleted_at IS NULL " +
|
||||
"AND pd.name = ? AND pd.id = ANY(string_to_array(tr_course_library.perm_dept_ids, ',')))))) " +
|
||||
"OR (tr_course_library.perm_user_ids <> '' AND ? <> '' AND ? = ANY(string_to_array(tr_course_library.perm_user_ids, ','))) " +
|
||||
"OR (tr_course_library.perm_dept_ids = '' AND tr_course_library.perm_user_ids = '' AND (" +
|
||||
"tr_course_library.suitable_members = ? " +
|
||||
"OR (? <> '' AND ? = ANY(string_to_array(replace(replace(replace(replace(tr_course_library.suitable_members, ',', '、'), ',', '、'), ';', '、'), ';', '、'), '、'))) " +
|
||||
@@ -33,6 +39,7 @@ func courseLibraryPermissionCond(q *interfaces.TrainingListQuery) (string, []int
|
||||
cond := courseLibraryPermissionMatchSQL
|
||||
args := []interface{}{
|
||||
q.PermDeptID, q.PermDeptID,
|
||||
q.CatalogDeptName, q.CatalogDeptName,
|
||||
q.PermUserID, q.PermUserID,
|
||||
"全部", q.CatalogDeptName, q.CatalogDeptName, q.CatalogDeptID, q.CatalogDeptID,
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package repository
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"academy/internal/types"
|
||||
@@ -442,9 +443,39 @@ func (r *trainingRepository) ListSessions(ctx context.Context, tenantID uint64,
|
||||
return items, err
|
||||
}
|
||||
|
||||
// FirstCourseSession 取课程最靠前的有效场次(2026-11-26 复测:发布校验的授课
|
||||
// 时间/地点与列表展示同口径 —— 场次排期优先;存量计划课程级字段为空但场次已
|
||||
// 排期时不误报「未设置」)。优先排期中且带时间/地点的场次,其次任一带时间或
|
||||
// 地点的场次,最后回退第一场;无场次返回 nil。
|
||||
func (r *trainingRepository) FirstCourseSession(ctx context.Context, tenantID uint64, courseID string) (*types.TrainingCourseSession, error) {
|
||||
var items []*types.TrainingCourseSession
|
||||
if err := r.db.WithContext(ctx).
|
||||
Where("tenant_id = ? AND course_id = ?", tenantID, courseID).
|
||||
Order("start_at ASC NULLS LAST").
|
||||
Find(&items).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(items) == 0 {
|
||||
return nil, nil
|
||||
}
|
||||
usable := func(s *types.TrainingCourseSession) bool {
|
||||
return (s.StartAt != nil && !s.StartAt.IsZero()) || strings.TrimSpace(s.Location) != ""
|
||||
}
|
||||
for _, s := range items {
|
||||
if s.Status == "scheduled" && usable(s) {
|
||||
return s, nil
|
||||
}
|
||||
}
|
||||
for _, s := range items {
|
||||
if usable(s) {
|
||||
return s, nil
|
||||
}
|
||||
}
|
||||
return items[0], nil
|
||||
}
|
||||
|
||||
// GetSession fetches one course session.
|
||||
func (r *trainingRepository) GetSession(ctx context.Context, tenantID uint64, id string) (*types.TrainingCourseSession, error) {
|
||||
var s types.TrainingCourseSession
|
||||
func (r *trainingRepository) GetSession(ctx context.Context, tenantID uint64, id string) (*types.TrainingCourseSession, error) { var s types.TrainingCourseSession
|
||||
if err := r.db.WithContext(ctx).
|
||||
Where("tenant_id = ? AND id = ?", tenantID, id).First(&s).Error; err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -476,6 +476,20 @@ func (s *trainingService) PublishCourse(ctx context.Context, tenantID uint64, id
|
||||
}
|
||||
}
|
||||
if course.Mode != types.TrainingCourseModeOnline {
|
||||
// 授课时间/地点与列表展示同口径(场次排期优先,2026-11-26 复测修复):
|
||||
// 列表「授课时间/地点」列在课程级字段为空时展示场次排期值,校验若只读
|
||||
// 课程级字段会把「场次已排期的存量草稿」误报为未设置 —— 课程级字段为空
|
||||
// 时以最靠前的有效场次兜底(仅用于校验,不回写)。
|
||||
if strings.TrimSpace(course.TeachTime) == "" || strings.TrimSpace(course.Location) == "" {
|
||||
if session, sessErr := s.repo.FirstCourseSession(ctx, tenantID, course.ID); sessErr == nil && session != nil {
|
||||
if strings.TrimSpace(course.TeachTime) == "" && session.StartAt != nil {
|
||||
course.TeachTime = session.StartAt.Format("2006-01-02 15:04")
|
||||
}
|
||||
if strings.TrimSpace(course.Location) == "" {
|
||||
course.Location = session.Location
|
||||
}
|
||||
}
|
||||
}
|
||||
if strings.TrimSpace(course.TeachTime) == "" {
|
||||
return nil, errors.NewBadRequestError("发布前需先设置授课时间")
|
||||
}
|
||||
|
||||
@@ -140,6 +140,9 @@ type TrainingRepository interface {
|
||||
|
||||
ListSessions(ctx context.Context, tenantID uint64, q *TrainingListQuery) ([]*types.TrainingCourseSession, error)
|
||||
GetSession(ctx context.Context, tenantID uint64, id string) (*types.TrainingCourseSession, error)
|
||||
// FirstCourseSession 取课程最靠前的有效场次(发布校验授课时间/地点的场次
|
||||
// 兜底,2026-11-26;无场次返回 nil,不视为错误)。
|
||||
FirstCourseSession(ctx context.Context, tenantID uint64, courseID string) (*types.TrainingCourseSession, error)
|
||||
CreateSession(ctx context.Context, session *types.TrainingCourseSession) error
|
||||
UpdateSession(ctx context.Context, session *types.TrainingCourseSession) error
|
||||
|
||||
|
||||
@@ -25,4 +25,14 @@ WHERE deleted_at IS NULL
|
||||
AND materials = '[]'::jsonb
|
||||
AND (COALESCE(file_key, '') <> '' OR COALESCE(knowledge_id, '') <> '');
|
||||
|
||||
-- 「审核即发布」存量回填(2026-11-26 复测):旧版本时代已审核确认且已有课件的
|
||||
-- 课程,新流程已移除「发布」按钮(审核通过即自动发布),此批课程需补齐发布
|
||||
-- 状态,否则将永远停留在「待发布」且无发布入口。
|
||||
UPDATE tr_course_library
|
||||
SET publish_status = 'published'
|
||||
WHERE deleted_at IS NULL
|
||||
AND verify_status = 'confirmed'
|
||||
AND publish_status = 'draft'
|
||||
AND (COALESCE(file_key, '') <> '' OR COALESCE(knowledge_id, '') <> '' OR materials <> '[]'::jsonb);
|
||||
|
||||
COMMENT ON COLUMN tr_course_library.materials IS 'Course library materials (000164 multi-courseware JSON array, append-only); primary file columns mirror the latest entry';
|
||||
Reference in new issue
Block a user