feat(training): 企业培训迭代:核验权限收窄、课程发布状态与培训中心改版

需求域:
- 需求导入修复内/外培训与外部讲师落库;按模板标题年入库(年-月一致)
- 核验确认收窄为「需求归属部门+经理职称角色」,越权提示联系部门经理
- 确认转月计划后自动推送讲师/课长维护;导入后自动推送部门经理核验(站内+企微)

课程域:
- 课程管理发布状态字段(迁移000154)+发布/下线;培训中心「和信课程」目录
- 需求讲师改选后回写课程管理;确认同步带出适合人员/课件/试题
- 月计划详情课件/试题更换(上传/知识库选择/题库换绑)回写课程管理,
  无关联条目的存量计划自动创建课程条目

模板与表单:
- 教育训练需求表:适合人员/内-外培训口径;部门联动课程下拉;
  适合人员/讲师按所选课程自动带出;在线提报课程下拉(本部门)自动带出分类/讲师/适合人员

页面与权限:
- 培训中心页签重组(和信课程/我的培训/我的考试),移除线上/线下页签
- 数据驾驶舱迁侧栏(职称角色之下);职称角色迁至更多工具配置中心之后
- 配置中心/职称角色对经理开放;页签「职称角色」更名「角色权限」
- 修复年度下拉空白(TDesign options 需对象数组)、月计划列表地点兜底

其他: 培训预览端口修正与 dev:training 脚本;tmp-extract-duckdb 加入 gitignore
This commit is contained in:
runny committed 2026-11-19 01:49:17 +08:00
1 parent aae041a0b4
commit 242dd7e1a6
47 files changed
+5882 -1134

No files matched your search

+106 -2
View File
@@ -97,18 +97,114 @@ func courseExamStatus(expected int, st *types.TrainingCourseStudyStats) string {
}
// GetCourse returns one course.
// courseExamBank 课程考试题库解析(000153):优先取课程直连题库(course_id),
// 未绑定时回退课程管理条目下的题库(library_course_id,试题随课程管理维护)。
func (s *trainingService) courseExamBank(ctx context.Context, tenantID uint64, course *types.TrainingCourse) (*types.TrainingQuestionBank, error) {
if course == nil {
return nil, errors.NewNotFoundError("课程不存在")
}
if bank, err := s.repo.GetQuestionBankByCourse(ctx, tenantID, course.ID); err == nil && bank != nil {
return bank, nil
}
if course.LibraryCourseID == "" {
return nil, errors.NewNotFoundError("题库不存在")
}
banks, err := s.repo.GetQuestionBankByLibraryCourse(ctx, tenantID, course.LibraryCourseID)
if err != nil || len(banks) == 0 {
return nil, errors.NewNotFoundError("题库不存在")
}
return banks[0], nil
}
func (s *trainingService) GetCourse(ctx context.Context, tenantID uint64, id string) (*types.TrainingCourse, error) {
course, err := s.repo.GetCourse(ctx, tenantID, id)
if err != nil {
return nil, errors.NewNotFoundError("课程不存在")
}
// 绑定题库即具备在线考试条件(详情页随堂考试入口与 exam_enabled 开关并联)。
if bank, bankErr := s.repo.GetQuestionBankByCourse(ctx, tenantID, id); bankErr == nil && bank != nil {
// 绑定题库即具备在线考试条件(详情页随堂考试入口与 exam_enabled 开关并联);
// 课程自身未绑定时回退课程管理条目的题库(000153)。
if bank, bankErr := s.courseExamBank(ctx, tenantID, course); bankErr == nil && bank != nil {
course.ExamReady = true
}
return course, nil
}
// applyLibraryCourseBinding 月度计划选择课程管理课程后的信息带出与锁定(000153):
// 课程名称/类型/形式/讲师随课程管理主数据,计划侧不支持修改;新建时学时/课程编号/
// 适用部门(主办单位)/参加人员预填。课程管理条目缺失时按原值保存(fail-open)。
// 返回命中的课程管理条目(无关联返回 nil),供调用方继续带出课件等资料。
func (s *trainingService) applyLibraryCourseBinding(ctx context.Context, tenantID uint64, course *types.TrainingCourse, isCreate bool) *types.TrainingCourseLibrary {
if course.LibraryCourseID == "" {
return nil
}
item, err := s.repo.GetCourseLibraryItem(ctx, tenantID, course.LibraryCourseID)
if err != nil || item == nil {
logger.Error(ctx, "Failed to load library course for plan binding", err, "library_course_id", course.LibraryCourseID)
return nil
}
// 锁定字段:随课程管理主数据,请求侧取值一律覆盖。
course.Name = item.Name
course.Type = item.Type
course.Mode = item.Mode
if item.LecturerID != "" || item.LecturerExternal != "" {
course.LecturerID = item.LecturerID
course.LecturerExternal = item.LecturerExternal
}
if !isCreate {
return item
}
// 预填字段:仅新建时带出,后续学时/学分按月度计划维护口径可调。
if course.Hours <= 0 {
course.Hours = item.Hours
}
if course.Code == "" {
course.Code = item.Code
}
if len(course.DeptIDs) == 0 || string(course.DeptIDs) == "[]" || string(course.DeptIDs) == "null" {
if item.OwnerDeptID != "" {
deptIDs, _ := json.Marshal([]string{item.OwnerDeptID})
course.DeptIDs = types.JSON(deptIDs)
}
}
if course.PostScope == "" {
course.PostScope = item.SuitableMembers
}
return item
}
// attachLibraryCourseMaterial 课程管理课件的计划侧挂接(000153,新建计划时):
// 课程管理条目已维护课件(知识库文档/原始文件/名称登记)时自动创建一条课程课件
// 记录,学员学习页与线上发布校验(线上课必须有课件)沿用既有链路。fail-open。
func (s *trainingService) attachLibraryCourseMaterial(ctx context.Context, tenantID uint64, courseID string, item *types.TrainingCourseLibrary, updaterID string) {
if item == nil {
return
}
name := item.FileName
if name == "" {
name = item.MaterialName
}
if name == "" {
return
}
kind := "doc"
if isVideoMaterialFile("", name) {
kind = "video"
}
material := &types.TrainingMaterial{
CourseID: courseID,
Kind: kind,
Name: name,
}
if item.KnowledgeID != "" {
material.KnowledgeID = item.KnowledgeID
} else {
material.FileKey = item.FileKey
}
if _, err := s.CreateMaterial(ctx, tenantID, material, updaterID); err != nil {
logger.Error(ctx, "Failed to attach library course material to plan", err, "course_id", courseID)
}
}
// SaveCourse creates or updates one course.
func (s *trainingService) SaveCourse(ctx context.Context, tenantID uint64, course *types.TrainingCourse, updaterID string) (*types.TrainingCourse, error) {
if course.Name == "" {
@@ -124,12 +220,20 @@ func (s *trainingService) SaveCourse(ctx context.Context, tenantID uint64, cours
course.ID = trainingNewID()
course.TenantID = tenantID
course.CreatorID = updaterID
// 课程管理信息带出与锁定(000153),课件资料随计划挂接(线上发布/学习页依赖)。
libItem := s.applyLibraryCourseBinding(ctx, tenantID, course, true)
s.attachLibraryCourseMaterial(ctx, tenantID, course.ID, libItem, updaterID)
// 月度计划编号(MP-<YYYYMM>-####,按授课月份分段;解析失败取当前月)。
year, month := monthPlanYearMonth(course.TeachTime, time.Now())
course.PlanCode = s.nextMonthPlanCode(ctx, tenantID, year, month)
if err := s.repo.CreateCourse(ctx, course); err != nil {
return nil, err
}
return course, nil
}
course.TenantID = tenantID
// 课程管理关联存在时锁定带出字段(000153;更新侧同样生效,防止前端篡改)。
s.applyLibraryCourseBinding(ctx, tenantID, course, false)
// 课程信息变更留痕:对比更新前取值,任一字段变化则落一条版本记录(fail-open,不阻断保存)。
old, err := s.repo.GetCourse(ctx, tenantID, course.ID)
if err != nil {