fix(课程管理):课程管理模块相关调整优化
deploy-hxtesting / build-and-deploy (push) Successful in 1m20s

1.”课程编号、课程名称、所属部门、说明、课程权限、分类、类型、线上/线下、讲师、时长、课件、试题、发布状态、创建时间、创建人“可滑动部分字段从左到右顺序”课程编号、课程名称、讲师、课件、试题、课程权限、分类、类型、线上/线下、时长、发布状态、创建时间、创建人、所属部门、说明“
2.增加一个字段适合人员作为备注字段承接”年培训计划“和”月培训计划“过来的”适合人员“信息只做展示用,支持用户自定义录入,
3.”课程权限“默认当前所示部门,“全部”选项放在下拉列最前面排在部门选项上面
4.列表右侧固定字段“状态”、“操作”宽度再收窄一些
5.审核时要校验“课程名称、所属部门、课程权限、课件”必填!所属部门默认当前录入人员所属部门支持修改,课程权限也是默认当前录入人员所属部门支持修改
This commit is contained in:
runny committed 2026-11-26 23:07:10 +08:00
1 parent 2f1cda34da
commit 0427a60bc3
13 files changed
+179 -49

No files matched your search

+2
View File
@@ -463,6 +463,8 @@ export interface TrainingLibraryCourse {
perm_dept_ids?: string
/** 课程权限-可见人员 id 列表(000163,逗号分隔 users.id) */
perm_user_ids?: string
/** 适合人员备注(000165,自由文本只做展示,不参与权限过滤;承接年/月培训计划的适合人员) */
post_scope?: string
/** 分类(配置中心 course_category_dict 可配,预设之外支持手动输入保存) */
category: string
/** 类型:required 必修课 / elective 选修课 */
@@ -687,6 +687,8 @@ const ensureLibraryCourse = async (): Promise<TrainingLibraryCourse | null> => {
type: editForm.value.type === 'elective' ? 'elective' : 'required',
hours: editForm.value.hours || 0,
description: row.description || '',
// 适合人员备注(000165):计划参加人员名单同步为课程管理「适合人员」展示
post_scope: (row.post_scope || '').slice(0, 500),
})) as TrainingLibraryCourse | null
if (!created) throw new Error('create library course failed')
replaceLibraryCourse(created)
@@ -60,6 +60,13 @@
</t-tooltip>
<span v-else>-</span>
</template>
<!-- 适合人员备注(000165):承接年/月培训计划「适合人员」,只做展示 -->
<template #post_scope="{ row }">
<t-tooltip v-if="row.post_scope" :content="row.post_scope">
<span class="cell-ellipsis">{{ row.post_scope }}</span>
</t-tooltip>
<span v-else>-</span>
</template>
<template #category="{ row }">
<t-tag v-if="row.category" theme="primary" variant="light" size="small">{{ row.category }}</t-tag>
<span v-else>-</span>
@@ -157,11 +164,11 @@
<t-input v-model="form.name" placeholder="请输入课程名称" />
</t-form-item>
<t-form-item label="所属部门">
<!-- 对应需求表「主办单位」:锁定为创建人(当前登录人)所属部门,不可修改
(000160,服务端同口径强制;无部门档案时可手动选择) -->
<!-- 对应需求表「主办单位」:默认创建人(当前登录人)所属部门,支持修改
(000165;审核前必填,审核校验兜底;仅传部门名时服务端按组织架构解析) -->
<t-select
v-model="form.owner_dept_id" :disabled="Boolean(myDeptId)" :clearable="!myDeptId"
filterable :placeholder="myDeptId ? '创建人所属部门(不可修改)' : '从组织架构选择所属部门(选填)'" style="width: 100%"
v-model="form.owner_dept_id" clearable filterable
placeholder="默认当前登录人所属部门,可选其他部门" style="width: 100%"
>
<t-option v-for="d in depts" :key="d.id" :value="d.id" :label="d.name" />
</t-select>
@@ -169,6 +176,14 @@
<t-form-item label="说明">
<t-textarea v-model="form.description" placeholder="课程内容简介(选填)" :autosize="{ minRows: 2 }" />
</t-form-item>
<t-form-item label="适合人员">
<!-- 备注字段(000165):承接年/月培训计划的「适合人员」信息,只做展示,
不参与课程权限过滤;支持自定义录入 -->
<t-textarea
v-model="form.post_scope" placeholder="适合人员备注(选填,仅展示;可见范围请用「课程权限」控制)"
:maxlength="500" :autosize="{ minRows: 2 }"
/>
</t-form-item>
<t-form-item label="课程权限">
<!-- 000163 课程权限(原「适合人员」):默认所属部门;可同时选择部门和
人员,部门与其下人员互斥(选了部门即覆盖其全员,不能再重复选该
@@ -224,7 +239,7 @@
<t-input-number v-model="form.hours" :min="0" :step="0.5" style="width: 100%" />
</t-form-item>
</t-form>
<div class="form-hint">分类选项由配置中心「课程分类」维护,支持手动输入保存;讲师可为员工名册内人员或外部讲师;课程权限默认所属部门,审核通过后仅所选部门和人员可在培训中心「和信课程」、月/年培训计划及课程管理中查看学习该课程;月培训计划「课程名称」将从本页课程中选择并自动带出此处维护的信息(不可修改);课件上传/预览/下载经列表「课件」入口、试题经列表「试题」入口维护。</div>
<div class="form-hint">分类选项由配置中心「课程分类」维护,支持手动输入保存;讲师可为员工名册内人员或外部讲师;所属部门与课程权限默认当前登录人所属部门,均可修改(审核时校验课程名称、所属部门、课程权限、课件必填);「适合人员」为备注字段,承接年/月培训计划的适合人员信息,仅做展示、不影响可见范围;课件上传/预览/下载经列表「课件」入口、试题经列表「试题」入口维护。</div>
<template #footer>
<t-button variant="outline" @click="formVisible = false">取消</t-button>
<t-button theme="primary" :loading="saving" @click="onSave">保存</t-button>
@@ -686,6 +701,12 @@ const parsePermFromRow = (row?: TrainingLibraryCourse): string[] => {
}
out.push(n)
}
// 000165:存量行权限为空时同样默认所属部门(优先行部门,无则当前登录人部门),
// 与「课程权限默认部门」口径一致,编辑补齐后再审核
if (!out.length) {
const fallback = row.owner_dept_id || myDeptId.value
if (fallback) out.push(`dept:${fallback}`)
}
return out
}
@@ -793,29 +814,31 @@ watch(filteredItems, resetItemPage)
const columns = [
// 批量勾选列(000157):配合批量审核/批量删除
{ colKey: 'row-select', type: 'multiple', width: 44 },
// 左侧列不固定(000154):课程编号/课程名称随横向滚动,操作仍固定右侧
// 左侧列不固定(000154),列序 000165 调整:编号/名称/讲师/课件/试题/权限/
// 分类/类型/线上线下/时长/发布状态/创建时间/创建人/所属部门/说明(适合人员备注置尾)
{ colKey: 'code', title: '课程编号', width: 105 },
{ colKey: 'name', title: '课程名称', width: 170 },
{ colKey: 'owner_dept', title: '所属部门', width: 110 },
{ colKey: 'description', title: '说明', width: 200 },
{ colKey: 'lecturer', title: '讲师', width: 110 },
// 课件/试题只展示有/无:有=已上传课件或已关联题库,点击直达对应维护抽屉
{ colKey: 'material', title: '课件', width: 70 },
{ colKey: 'question', title: '试题', width: 70 },
{ colKey: 'suitable_members', title: '课程权限', width: 110 },
{ colKey: 'category', title: '分类', width: 120 },
{ colKey: 'type', title: '类型', width: 84 },
{ colKey: 'mode', title: '线上/线下', width: 92 },
{ colKey: 'lecturer', title: '讲师', width: 110 },
{ colKey: 'hours', title: '时长', width: 84 },
// 课件/试题只展示有/无:有=已上传课件或已关联题库,点击直达对应维护抽屉
{ colKey: 'material', title: '课件', width: 70 },
{ colKey: 'question', title: '试题', width: 70 },
// 发布状态(000154):已发布的课程进入培训中心「和信课程」目录
{ colKey: 'publish_status', title: '发布状态', width: 90 },
{ colKey: 'created_at', title: '创建时间', width: 140 },
// 创建人(联查 users):记录课程录入人员
{ colKey: 'creator_name', title: '创建人', width: 96 },
// 000163 右侧固定区收缩(参考年培训计划页):状态 84,操作收窄至够用,
// 按钮紧凑排布(见下方样式),消除固定区的空白浪费
{ colKey: 'verify_status', title: '状态', width: 84, fixed: 'right' },
{ colKey: 'op', title: '操作', width: 260, fixed: 'right', className: 'op-cell' },
{ colKey: 'owner_dept', title: '所属部门', width: 110 },
{ colKey: 'description', title: '说明', width: 200 },
// 适合人员备注(000165):承接年/月培训计划「适合人员」+ 自定义录入,只做展示
{ colKey: 'post_scope', title: '适合人员', width: 140 },
// 000165 右侧固定区再收窄:状态 72,操作 224(行内至多 5 个文本按钮,紧凑排布见样式)
{ colKey: 'verify_status', title: '状态', width: 72, fixed: 'right' },
{ colKey: 'op', title: '操作', width: 224, fixed: 'right', className: 'op-cell' },
]
const lecturerText = (row: TrainingLibraryCourse) =>
@@ -861,6 +884,8 @@ const form = ref({
// 课程权限(000163):部门/人员 id 列表(逗号分隔),随保存落库
perm_dept_ids: '',
perm_user_ids: '',
// 适合人员备注(000165):承接年/月培训计划「适合人员」,只做展示,支持自定义录入
post_scope: '',
category: '',
type: 'required' as 'required' | 'elective',
// 新增默认「线上」(000162):线上课为常规形态;编辑随原值
@@ -921,13 +946,16 @@ const openForm = (row?: TrainingLibraryCourse) => {
id: row?.id || '',
code: row?.code || '',
name: row?.name || '',
// 新增默认当前登录用户所在部门(锁定不可改);编辑保持原部门
owner_dept_id: row?.owner_dept_id || (row ? '' : myDeptId.value),
// 所属部门默认当前登录人所在部门,支持修改(000165);编辑保持原部门,
// 原部门为空的存量行同样回落默认,便于补齐审核必填项
owner_dept_id: row?.owner_dept_id || myDeptId.value,
description: row?.description || '',
// 课程权限(000163):新增默认所属部门;编辑按 perm 两列回显(存量回退解析)
suitable_members: row?.suitable_members || '',
perm_dept_ids: row?.perm_dept_ids || '',
perm_user_ids: row?.perm_user_ids || '',
// 适合人员备注(000165):编辑回显,新增留空
post_scope: row?.post_scope || '',
category: row?.category || '',
type: row?.type === 'elective' ? 'elective' : 'required',
// 新增默认「线上」(000162);编辑随原值
@@ -970,6 +998,8 @@ const onSave = async () => {
suitable_members: form.value.suitable_members.trim(),
perm_dept_ids: form.value.perm_dept_ids,
perm_user_ids: form.value.perm_user_ids,
// 适合人员备注(000165):随保存落库
post_scope: form.value.post_scope.trim(),
category: form.value.category.trim(),
type: form.value.type,
mode: form.value.mode,
@@ -1012,10 +1042,20 @@ const onDelete = async (row: TrainingLibraryCourse) => {
const selectedKeys = ref<string[]>([])
const batchSaving = ref(false)
// 审核前置校验(000165):课程名称/所属部门/课程权限/课件必填,返回首个未满足项的提示
const verifyBlockerOf = (row: TrainingLibraryCourse): string => {
if (!(row.name || '').trim()) return '未填写课程名称'
if (!(row.owner_dept_id || '').trim()) return '未设置所属部门,请先在「编辑」中设置所属部门'
if (!hasPermSet(row)) return '未设置课程权限,请先在「编辑」中设置课程权限'
if (!hasMaterial(row)) return '未上传课件,请先在列表「课件」入口上传课件'
return ''
}
const onVerify = async (row: TrainingLibraryCourse) => {
// 审核前置(000163):课程权限必填,未设置先去编辑设置
if (!hasPermSet(row)) {
MessagePlugin.warning(`课程「${row.name}」未设置课程权限,请先在「编辑」中设置课程权限后再审核`)
// 审核前置(000165):名称/所属部门/课程权限/课件必填,先补齐再审核
const blocker = verifyBlockerOf(row)
if (blocker) {
MessagePlugin.warning(`课程「${row.name}」${blocker}后再审核`)
return
}
try {
@@ -1043,10 +1083,14 @@ const onBatchVerify = async () => {
MessagePlugin.warning('请先勾选本部门待审核状态的课程')
return
}
// 课程权限必填(000163):未设置权限的行先行拦截并提示
const noPerm = rows.filter((r) => !hasPermSet(r))
if (noPerm.length) {
MessagePlugin.warning(`课程「${noPerm.map((r) => r.name).join('、')}」未设置课程权限,请先设置后再审核`)
// 审核前置(000165):名称/所属部门/课程权限/课件必填,列出不满足的行并拦截
const blockers = rows
.map((r) => ({ name: r.name, reason: verifyBlockerOf(r) }))
.filter((b) => b.reason)
if (blockers.length) {
MessagePlugin.warning(
`${blockers.map((b) => `课程「${b.name}」${b.reason}`).join(';')}。请先补齐后再批量审核`,
)
return
}
batchSaving.value = true
@@ -1939,12 +1983,18 @@ onMounted(loadAll)
// 000163 操作列按钮紧凑排布:缩小左右内边距并固定按钮间距,
// 使右侧固定区(状态 84 + 操作 260)收窄至够用,不再出现大片空白
/* 000165 操作列收窄至 224:行内至多 5 个文本按钮(编辑/课件/试题/审核或下线/删除),
单元格留白与按钮间距同步收紧避免换行 */
.library-panel :deep(.op-cell) {
padding: 4px 6px;
}
.library-panel :deep(.op-cell .t-button) {
padding: 0 5px;
padding: 0 4px;
}
.library-panel :deep(.op-cell .t-button + .t-button) {
margin-left: 8px;
margin-left: 6px;
}
// 批量导入弹窗:模板下载 + Excel 上传一行排布(与培训计划导入同款)
@@ -386,9 +386,11 @@ const onDemandCourseChange = (name: unknown) => {
const course = libraryCourses.value.find((c) => c.name === name)
if (!course) return
demandForm.value.category = course.category || ''
if (course.suitable_members) {
demandForm.value.post_scope = course.suitable_members
demandSuitableList.value = splitSuitable(course.suitable_members)
// 适合人员(000165):优先课程管理备注字段 post_scope,存量课程回退 suitable_members
const suitableValue = course.post_scope || course.suitable_members || ''
if (suitableValue) {
demandForm.value.post_scope = suitableValue
demandSuitableList.value = splitSuitable(suitableValue)
}
const lecturerValue = course.lecturer_id || course.lecturer_external || ''
if (lecturerValue) {
@@ -181,6 +181,8 @@ func (r *trainingRepository) UpdateCourseLibraryItem(ctx context.Context, item *
// 课程权限(000163):部门/人员 id 列表随保存更新。
"perm_dept_ids": item.PermDeptIDs,
"perm_user_ids": item.PermUserIDs,
// 适合人员备注(000165):随保存更新(空值即清空)。
"post_scope": item.PostScope,
"category": item.Category,
"type": item.Type,
"mode": item.Mode,
+4
View File
@@ -457,6 +457,8 @@ func (s *trainingService) SaveDemand(ctx context.Context, tenantID uint64, deman
OwnerDeptID: demand.DeptID,
Category: demand.Category,
SuitableMembers: demand.PostScope,
// 适合人员备注(000165):需求「适合人员」同步落到课程管理备注字段。
PostScope: demand.PostScope,
LecturerID: demand.LecturerID,
LecturerExternal: demand.LecturerExternal,
}
@@ -538,6 +540,8 @@ func (s *trainingService) ImportDemands(ctx context.Context, tenantID uint64, de
OwnerDeptID: demands[i].DeptID,
Category: demands[i].Category,
SuitableMembers: demands[i].PostScope,
// 适合人员备注(000165):批量导入同样同步到课程管理备注字段。
PostScope: demands[i].PostScope,
LecturerID: demands[i].LecturerID,
LecturerExternal: demands[i].LecturerExternal,
}
@@ -53,6 +53,8 @@ func normalizeCourseLibrary(item *types.TrainingCourseLibrary) error {
item.Category = strings.TrimSpace(item.Category)
item.Description = strings.TrimSpace(item.Description)
item.SuitableMembers = strings.TrimSpace(item.SuitableMembers)
// 适合人员备注(000165):截断到列宽,参加人员名单过长时避免落库报错。
item.PostScope = truncatePostScope(item.PostScope)
item.LecturerID = strings.TrimSpace(item.LecturerID)
item.LecturerExternal = strings.TrimSpace(item.LecturerExternal)
item.MaterialName = strings.TrimSpace(item.MaterialName)
@@ -72,6 +74,16 @@ func normalizeCourseLibrary(item *types.TrainingCourseLibrary) error {
return nil
}
// truncatePostScope 适合人员备注截断(000165):列宽 varchar(512),参加人员
// 名单过长时按 rune 截断,避免落库报错阻断保存。
func truncatePostScope(raw string) string {
runes := []rune(strings.TrimSpace(raw))
if len(runes) > 512 {
return string(runes[:512])
}
return string(runes)
}
// normalizePermIDs 课程权限 id 列表归一(000163):逗号/顿号/空白分隔 → 去空白
// 去重 → 「,」连接落库(与 string_to_array(x, ',') 匹配口径一致)。
func normalizePermIDs(raw string) string {
@@ -162,11 +174,9 @@ func (s *trainingService) SaveCourseLibraryItem(ctx context.Context, tenantID ui
item.VerifyStatus = types.CourseLibraryVerifyPending
// 仅传部门名时按组织架构解析为 id(不阻断保存)。
s.resolveCourseLibraryDept(ctx, tenantID, item)
// 所属部门强制为创建人部门(000160):前端表单同口径锁定,服务端兜底
// 覆盖,防止绕过前端改部门。创建人无部门档案时保留原值(可为空)。
if member, err := s.CurrentMember(ctx, tenantID, updaterID); err == nil && member != nil && member.DeptID != "" {
item.OwnerDeptID = member.DeptID
}
// 所属部门默认创建人部门、支持修改(000165):前端表单默认当前登录人
// 部门,不再服务端强制覆盖(000160 的强制口径放开);留空时保持为空,
// 审核前由审核校验兜底拦截。
// 课程编号(CRS-####,创建时由服务端生成;编号列只读,不收前端值)。
item.Code = s.nextCourseLibraryCode(ctx, tenantID)
if err := s.repo.CreateCourseLibraryItem(ctx, item); err != nil {
@@ -187,8 +197,11 @@ func (s *trainingService) SaveCourseLibraryItem(ctx context.Context, tenantID ui
setCourseMaterials(item, nil)
}
refreshPrimaryFromMaterials(item)
// 所属部门不可随编辑修改(000160):恒保持创建时的部门,前端表单同口径锁定。
item.OwnerDeptID = old.OwnerDeptID
// 所属部门支持修改(000165):请求携带新值即按新值更新;未传(空值)时
// 保持创建时的部门,防止全量更新误清(000160 的不可修改口径放开)。
if strings.TrimSpace(item.OwnerDeptID) == "" {
item.OwnerDeptID = old.OwnerDeptID
}
// 编辑即回待审核(000157):内容变更后原审核结论作废,需重新审核。
item.VerifyStatus = types.CourseLibraryVerifyPending
item.ConfirmedBy = ""
@@ -268,6 +281,12 @@ func (s *trainingService) VerifyCourseLibraryItems(ctx context.Context, tenantID
if item.VerifyStatus != types.CourseLibraryVerifyPending {
continue // 已确认行幂等跳过
}
// 所属部门必填(000165 审核校验):先于部门归属判断,空部门行给出
// 明确拦截提示而非静默跳过("没有可审核的课程"难定位)。
if strings.TrimSpace(item.OwnerDeptID) == "" {
return nil, werrors.NewBadRequestError(
fmt.Sprintf("课程《%s》未设置所属部门,请先在课程管理中设置所属部门后再审核", item.Name))
}
if deptScope != "" && item.OwnerDeptID != deptScope {
continue // 课长/经理仅可审核本部门课程
}
@@ -276,6 +295,12 @@ func (s *trainingService) VerifyCourseLibraryItems(ctx context.Context, tenantID
return nil, werrors.NewBadRequestError(
fmt.Sprintf("课程《%s》未设置课程权限,请先在课程管理中设置课程权限后再审核", item.Name))
}
// 课件必填(000165 审核校验):审核即发布,无课件课程不再放行审核,
// 须先在列表「课件」入口上传课件文件(或从知识库选择)。
if !item.HasCourseMaterial() {
return nil, werrors.NewBadRequestError(
fmt.Sprintf("课程《%s》未上传课件,请先在列表「课件」入口上传课件后再审核", item.Name))
}
allowed = append(allowed, id)
if item.HasCourseMaterial() {
publishable = append(publishable, id)
@@ -334,6 +359,7 @@ func (s *trainingService) matchOrCreateLibraryCourse(ctx context.Context, tenant
OwnerDeptID: proto.OwnerDeptID,
Category: strings.TrimSpace(proto.Category),
SuitableMembers: strings.TrimSpace(proto.SuitableMembers),
PostScope: truncatePostScope(proto.PostScope),
LecturerID: proto.LecturerID,
LecturerExternal: strings.TrimSpace(proto.LecturerExternal),
Type: "required",
@@ -127,10 +127,10 @@ func timeNowPtr() *time.Time {
return &v
}
// 审核(000163:核验升级为审核,审核通过即自动发布):
// 审核(000163:核验升级为审核,审核通过即自动发布;000165 补充审核必填校验):
// - 课程权限必填:perm 两列与 suitable_members 均为空的课程整批拒绝;
// - 已传课件的课程审核通过即自动发布(published);
// - 未传课件的课程仅确认通过、不发布,回传课程名提示补传。
// - 课件必填(000165):审核即发布,未传课件的课程整批拒绝;
// - 名称/所属部门/权限/课件齐备的课程审核通过即自动发布(published)。
func TestVerifyCourseLibraryItemsRequiresPermissionAndAutoPublish(t *testing.T) {
svc, db, tenantID := newCourseLibraryFixture(t)
ctx := context.Background()
@@ -138,8 +138,9 @@ func TestVerifyCourseLibraryItemsRequiresPermissionAndAutoPublish(t *testing.T)
noPerm := &types.TrainingCourseLibrary{ID: "cl-noperm", Name: "未设置权限课程", OwnerDeptID: "dept-1", VerifyStatus: types.CourseLibraryVerifyPending, FileKey: "fk-1", FileName: "a.pptx"}
permAndFile := &types.TrainingCourseLibrary{ID: "cl-ok", Name: "权限加课件课程", OwnerDeptID: "dept-1", VerifyStatus: types.CourseLibraryVerifyPending, PermDeptIDs: "dept-1", FileKey: "fk-2", FileName: "b.pptx"}
permNoFile := &types.TrainingCourseLibrary{ID: "cl-nofile", Name: "权限缺课件课程", OwnerDeptID: "dept-1", VerifyStatus: types.CourseLibraryVerifyPending, SuitableMembers: "全部"}
noDept := &types.TrainingCourseLibrary{ID: "cl-nodept", Name: "缺部门课程", VerifyStatus: types.CourseLibraryVerifyPending, PermDeptIDs: "dept-1", FileKey: "fk-3", FileName: "c.pptx"}
otherDept := &types.TrainingCourseLibrary{ID: "cl-other", Name: "别部门课程", OwnerDeptID: "dept-2", VerifyStatus: types.CourseLibraryVerifyPending, PermDeptIDs: "dept-2"}
for _, item := range []*types.TrainingCourseLibrary{noPerm, permAndFile, permNoFile, otherDept} {
for _, item := range []*types.TrainingCourseLibrary{noPerm, permAndFile, permNoFile, noDept, otherDept} {
seedCourseLibraryItem(t, db, tenantID, item)
}
@@ -148,25 +149,36 @@ func TestVerifyCourseLibraryItemsRequiresPermissionAndAutoPublish(t *testing.T)
require.Error(t, err)
require.True(t, strings.Contains(err.Error(), "课程权限"), "应提示未设置课程权限,实际: %s", err.Error())
// 课件必填(000165):权限已设置但未上传课件,整批拒绝并点名课程。
_, err = svc.VerifyCourseLibraryItems(ctx, tenantID, []string{permNoFile.ID}, "u-verifier", "dept-1")
require.Error(t, err)
require.True(t, strings.Contains(err.Error(), "课件"), "应提示未上传课件,实际: %s", err.Error())
// 所属部门必填(000165):部门为空时整批拒绝并点名课程。
_, err = svc.VerifyCourseLibraryItems(ctx, tenantID, []string{noDept.ID}, "u-verifier", "dept-1")
require.Error(t, err)
require.True(t, strings.Contains(err.Error(), "所属部门"), "应提示未设置所属部门,实际: %s", err.Error())
// 部门不匹配:跳过,无可用条目报错。
_, err = svc.VerifyCourseLibraryItems(ctx, tenantID, []string{otherDept.ID}, "u-verifier", "dept-1")
require.Error(t, err)
// 混合批次:权限+课件 → 确认并自动发布;权限缺课件 → 仅确认不发布。
res, err := svc.VerifyCourseLibraryItems(ctx, tenantID, []string{permAndFile.ID, permNoFile.ID, otherDept.ID}, "u-verifier", "dept-1")
// 齐备批次:确认并自动发布;部门不匹配行跳过。
res, err := svc.VerifyCourseLibraryItems(ctx, tenantID, []string{permAndFile.ID, otherDept.ID}, "u-verifier", "dept-1")
require.NoError(t, err)
require.EqualValues(t, 2, res.Verified)
require.EqualValues(t, 1, res.Verified)
require.EqualValues(t, 1, res.Skipped)
require.EqualValues(t, 1, res.AutoPublished)
require.Equal(t, []string{"权限缺课件课程"}, res.UnpublishedNames)
require.Empty(t, res.UnpublishedNames)
stored, err := svc.GetCourseLibraryItem(ctx, tenantID, permAndFile.ID)
require.NoError(t, err)
require.Equal(t, types.CourseLibraryVerifyConfirmed, stored.VerifyStatus)
require.Equal(t, "published", stored.PublishStatus)
// 缺课件行未被审核:仍为待审核/草稿。
storedNoFile, err := svc.GetCourseLibraryItem(ctx, tenantID, permNoFile.ID)
require.NoError(t, err)
require.Equal(t, types.CourseLibraryVerifyConfirmed, storedNoFile.VerifyStatus)
require.Equal(t, types.CourseLibraryVerifyPending, storedNoFile.VerifyStatus)
require.Equal(t, "draft", storedNoFile.PublishStatus)
}
+5 -1
View File
@@ -1085,9 +1085,12 @@ func (h *Handler) syncDemandLecturerToLibrary(ctx context.Context, tenantID uint
category, suitable := trimSpace(d.Category), trimSpace(d.PostScope)
// 仅按需求侧非空字段判断差异(空值=未填,不覆盖课程管理已有值,防止
// 旧行误清讲师/分类);任一非空字段与条目不一致才回写并重置待核验。
// 适合人员备注(000165):需求「适合人员」变更同步到课程管理备注字段,
// 与存量 suitable_members 口径一并比较(老数据备注为空时首改会触发回写)。
changed := (hasLecturer && (item.LecturerID != lecturerID || item.LecturerExternal != lecturerExt)) ||
(category != "" && item.Category != category) ||
(suitable != "" && item.SuitableMembers != suitable)
(suitable != "" && item.SuitableMembers != suitable) ||
(suitable != "" && item.PostScope != suitable)
if !changed {
continue
}
@@ -1101,6 +1104,7 @@ func (h *Handler) syncDemandLecturerToLibrary(ctx context.Context, tenantID uint
}
if suitable != "" {
updated.SuitableMembers = suitable
updated.PostScope = suitable
}
if _, err := h.svc.SaveCourseLibraryItem(ctx, tenantID, &updated, updaterID); err != nil {
logger.Error(ctx, "Failed to sync demand course info to course library", err)
@@ -34,8 +34,11 @@ type saveCourseLibraryRequest struct {
SuitableMembers string `json:"suitable_members"`
// PermDeptIDs/PermUserIDs 课程权限(000163):可见部门/人员 id 列表(逗号
// 分隔);两者与 suitable_members 同时为空的存量课程沿用老口径。
PermDeptIDs string `json:"perm_dept_ids"`
PermUserIDs string `json:"perm_user_ids"`
PermDeptIDs string `json:"perm_dept_ids"`
PermUserIDs string `json:"perm_user_ids"`
// PostScope 适合人员备注(000165):自由文本只做展示,不参与权限过滤;
// 承接年/月培训计划的适合人员信息,并支持用户自定义录入。
PostScope string `json:"post_scope"`
Category string `json:"category"`
Type string `json:"type"`
Mode string `json:"mode"`
@@ -58,6 +61,7 @@ func toCourseLibrary(req saveCourseLibraryRequest) *types.TrainingCourseLibrary
SuitableMembers: req.SuitableMembers,
PermDeptIDs: req.PermDeptIDs,
PermUserIDs: req.PermUserIDs,
PostScope: req.PostScope,
Category: req.Category,
Type: req.Type,
Mode: req.Mode,
+4
View File
@@ -638,6 +638,10 @@ type TrainingCourseLibrary struct {
// PermUserIDs 课程权限-人员(000163):逗号分隔的 users.id,所选人员可见该
// 课程;部门与该部门下人员互斥由前端保证(选了部门无需再选其下人员)。
PermUserIDs string `json:"perm_user_ids" gorm:"type:varchar(1024);default:''"`
// PostScope 适合人员备注(000165):自由文本只做展示,不参与课程权限过滤;
// 承接年/月培训计划(需求 post_scope/参加人员)过来的适合人员信息,并支持
// 用户在编辑弹窗自定义录入。
PostScope string `json:"post_scope" gorm:"type:varchar(512);default:''"`
// Category 分类(配置中心 course_category_dict 可配,预设之外支持手动输入保存)。
Category string `json:"category" gorm:"type:varchar(64);default:''"`
// Type 类型(required 必修课/elective 选修课)。
@@ -0,0 +1,4 @@
-- Migration: 000165_course_library_post_scope (rollback)
DO $$ BEGIN RAISE NOTICE '[Migration 000165] Dropping tr_course_library post_scope column...'; END $$;
ALTER TABLE tr_course_library DROP COLUMN IF EXISTS post_scope;
@@ -0,0 +1,14 @@
-- Migration: 000165_course_library_post_scope
-- 课程管理新增「适合人员」备注字段(测试反馈 2026-11-26):
-- post_scope: 适合人员备注(自由文本,只做展示,不参与课程权限过滤),
-- 承接「年培训计划」「月培训计划」过来的适合人员/参加人员信息,并支持
-- 用户在课程管理编辑弹窗自定义录入。
-- 与 000163 课程权限列(perm_dept_ids/perm_user_ids/存量 suitable_members)互不干扰。
-- ADD COLUMN IF NOT EXISTS,迁移幂等可重放。
DO $$ BEGIN RAISE NOTICE '[Migration 000165] Adding tr_course_library post_scope column...'; END $$;
ALTER TABLE tr_course_library
ADD COLUMN IF NOT EXISTS post_scope VARCHAR(512) NOT NULL DEFAULT '';
COMMENT ON COLUMN tr_course_library.post_scope IS 'Suitable personnel remark (display-only free text carried over from annual/monthly training plans; not used for permission filtering)';