feat(training): 企业培训迭代:核验权限收窄、课程发布状态与培训中心改版
需求域: - 需求导入修复内/外培训与外部讲师落库;按模板标题年入库(年-月一致) - 核验确认收窄为「需求归属部门+经理职称角色」,越权提示联系部门经理 - 确认转月计划后自动推送讲师/课长维护;导入后自动推送部门经理核验(站内+企微) 课程域: - 课程管理发布状态字段(迁移000154)+发布/下线;培训中心「和信课程」目录 - 需求讲师改选后回写课程管理;确认同步带出适合人员/课件/试题 - 月计划详情课件/试题更换(上传/知识库选择/题库换绑)回写课程管理, 无关联条目的存量计划自动创建课程条目 模板与表单: - 教育训练需求表:适合人员/内-外培训口径;部门联动课程下拉; 适合人员/讲师按所选课程自动带出;在线提报课程下拉(本部门)自动带出分类/讲师/适合人员 页面与权限: - 培训中心页签重组(和信课程/我的培训/我的考试),移除线上/线下页签 - 数据驾驶舱迁侧栏(职称角色之下);职称角色迁至更多工具配置中心之后 - 配置中心/职称角色对经理开放;页签「职称角色」更名「角色权限」 - 修复年度下拉空白(TDesign options 需对象数组)、月计划列表地点兜底 其他: 培训预览端口修正与 dev:training 脚本;tmp-extract-duckdb 加入 gitignore
This commit is contained in:
1 parent
aae041a0b4
commit
242dd7e1a6
47 files changed
+5882
-1134
No files matched your search
@@ -42,6 +42,8 @@ func (s *trainingService) ImportQuestionBank(ctx context.Context, tenantID uint6
|
||||
bank.TenantID = tenantID
|
||||
bank.CreatorID = updaterID
|
||||
bank.QuestionCount = len(questions)
|
||||
// 试题库编号(QB-####,导入/AI 生成统一在此生成,000153)。
|
||||
bank.Code = s.nextQuestionBankCode(ctx, tenantID)
|
||||
if err := s.repo.CreateQuestionBank(ctx, bank); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -70,7 +72,7 @@ func (s *trainingService) ImportQuestionBank(ctx context.Context, tenantID uint6
|
||||
// 模板中的「课程名称」列仅作对照展示,题库与课程的关联以导入弹窗选择的课程为准。
|
||||
// 两种格式均合并解析全部工作表;入库后把原始 Excel 自动同步进系统默认
|
||||
// 「企业培训(题库)」知识库(fail-open),使题库内容支持 AI 对话问答。
|
||||
func (s *trainingService) ImportQuestionBankExcel(ctx context.Context, tenantID uint64, name, deptID, courseID string, fh *multipart.FileHeader, updaterID string) (*types.TrainingQuestionBank, error) {
|
||||
func (s *trainingService) ImportQuestionBankExcel(ctx context.Context, tenantID uint64, name, deptID, courseID, libraryCourseID string, fh *multipart.FileHeader, updaterID string) (*types.TrainingQuestionBank, error) {
|
||||
if fh == nil {
|
||||
return nil, errors.NewBadRequestError("缺少上传文件")
|
||||
}
|
||||
@@ -88,15 +90,18 @@ func (s *trainingService) ImportQuestionBankExcel(ctx context.Context, tenantID
|
||||
return nil, err
|
||||
}
|
||||
// 同名重导入即替换:清掉旧题库的题目与缓存试卷(坏数据/旧 ONLINE 卷一并失效),
|
||||
// 调用方未指定归属课程时继承旧题库的课程关联。
|
||||
oldCourseID, err := s.repo.ReplaceQuestionBankByName(ctx, tenantID, name)
|
||||
// 调用方未指定归属课程/课程管理条目时继承旧题库的关联。
|
||||
oldCourseID, oldLibraryCourseID, err := s.repo.ReplaceQuestionBankByName(ctx, tenantID, name)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if courseID == "" {
|
||||
courseID = oldCourseID
|
||||
}
|
||||
bank := &types.TrainingQuestionBank{Name: name, DeptID: deptID, CourseID: courseID}
|
||||
if libraryCourseID == "" {
|
||||
libraryCourseID = oldLibraryCourseID
|
||||
}
|
||||
bank := &types.TrainingQuestionBank{Name: name, DeptID: deptID, CourseID: courseID, LibraryCourseID: libraryCourseID}
|
||||
// 原始 Excel 同步进「企业培训(题库)」知识库(失败不阻断导入),回填 knowledge_id。
|
||||
bank.KnowledgeID = s.syncExcelToQuestionBankKB(ctx, fh, name)
|
||||
return s.ImportQuestionBank(ctx, tenantID, bank, questions, updaterID)
|
||||
@@ -135,7 +140,7 @@ func (s *trainingService) parseQuestionBankExcel(ctx context.Context, tenantID u
|
||||
// ImportQuestionBankFromKnowledge 从「企业培训(题库)」知识库文档直接导入题库:
|
||||
// 取回 Excel 原件解析建库,文档已在知识库故直接挂接 knowledge_id 不重复上传;
|
||||
// 未指定归属课程时继承同名旧题库的课程关联。
|
||||
func (s *trainingService) ImportQuestionBankFromKnowledge(ctx context.Context, tenantID uint64, knowledgeID, name, courseID, updaterID string) (*types.TrainingQuestionBank, error) {
|
||||
func (s *trainingService) ImportQuestionBankFromKnowledge(ctx context.Context, tenantID uint64, knowledgeID, name, courseID, libraryCourseID, updaterID string) (*types.TrainingQuestionBank, error) {
|
||||
if strings.TrimSpace(knowledgeID) == "" {
|
||||
return nil, errors.NewBadRequestError("缺少知识库文档")
|
||||
}
|
||||
@@ -156,17 +161,113 @@ func (s *trainingService) ImportQuestionBankFromKnowledge(ctx context.Context, t
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
oldCourseID, err := s.repo.ReplaceQuestionBankByName(ctx, tenantID, name)
|
||||
oldCourseID, oldLibraryCourseID, err := s.repo.ReplaceQuestionBankByName(ctx, tenantID, name)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if courseID == "" {
|
||||
courseID = oldCourseID
|
||||
}
|
||||
bank := &types.TrainingQuestionBank{Name: name, CourseID: courseID, KnowledgeID: knowledgeID}
|
||||
if libraryCourseID == "" {
|
||||
libraryCourseID = oldLibraryCourseID
|
||||
}
|
||||
bank := &types.TrainingQuestionBank{Name: name, CourseID: courseID, LibraryCourseID: libraryCourseID, KnowledgeID: knowledgeID}
|
||||
return s.ImportQuestionBank(ctx, tenantID, bank, questions, updaterID)
|
||||
}
|
||||
|
||||
// ListLibraryCourseQuestionBanks 课程管理条目下的题库列表(试题维护抽屉,000153)。
|
||||
func (s *trainingService) ListLibraryCourseQuestionBanks(ctx context.Context, tenantID uint64, libraryCourseID string) ([]*types.TrainingQuestionBank, error) {
|
||||
if libraryCourseID == "" {
|
||||
return nil, errors.NewBadRequestError("缺少课程管理条目")
|
||||
}
|
||||
return s.repo.GetQuestionBankByLibraryCourse(ctx, tenantID, libraryCourseID)
|
||||
}
|
||||
|
||||
// LinkQuestionBankToLibraryCourse 更换课程管理条目的试题(000156):所选题库整体
|
||||
// 替换该条目当前挂接的题库,回写课程管理资产(月计划侧更换入口)。
|
||||
func (s *trainingService) LinkQuestionBankToLibraryCourse(ctx context.Context, tenantID uint64, libraryCourseID, bankID string) error {
|
||||
if libraryCourseID == "" {
|
||||
return errors.NewBadRequestError("缺少课程管理条目")
|
||||
}
|
||||
if _, err := s.repo.GetQuestionBank(ctx, tenantID, bankID); err != nil {
|
||||
return errors.NewNotFoundError("题库不存在")
|
||||
}
|
||||
return s.repo.RelinkQuestionBankToLibraryCourse(ctx, tenantID, libraryCourseID, bankID)
|
||||
}
|
||||
|
||||
// DeleteQuestionBank 删除题库(连带题目与缓存试卷;试题维护抽屉删除入口,000153)。
|
||||
func (s *trainingService) DeleteQuestionBank(ctx context.Context, tenantID uint64, bankID string) error {
|
||||
if _, err := s.repo.GetQuestionBank(ctx, tenantID, bankID); err != nil {
|
||||
return errors.NewNotFoundError("题库不存在")
|
||||
}
|
||||
return s.repo.DeleteQuestionBank(ctx, tenantID, bankID)
|
||||
}
|
||||
|
||||
// SaveQuestion 单题新增/编辑(id 空 = 新增;题库 question_count 同步刷新,000153)。
|
||||
func (s *trainingService) SaveQuestion(ctx context.Context, tenantID uint64, q *types.TrainingQuestion) (*types.TrainingQuestion, error) {
|
||||
q.Stem = strings.TrimSpace(q.Stem)
|
||||
if q.Stem == "" {
|
||||
return nil, errors.NewBadRequestError("题干不能为空")
|
||||
}
|
||||
if q.Type != types.TrainingQuestionMultiple && q.Type != types.TrainingQuestionJudge {
|
||||
q.Type = types.TrainingQuestionSingle
|
||||
}
|
||||
if q.Difficulty <= 0 {
|
||||
q.Difficulty = 3
|
||||
}
|
||||
if _, err := s.repo.GetQuestionBank(ctx, tenantID, q.BankID); err != nil {
|
||||
return nil, errors.NewNotFoundError("题库不存在")
|
||||
}
|
||||
if q.ID == "" {
|
||||
// 新增:题序排在库内已有题目之后。
|
||||
existing, err := s.repo.ListQuestions(ctx, tenantID, q.BankID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
q.ID = trainingNewID()
|
||||
q.TenantID = tenantID
|
||||
q.SeqNo = len(existing) + 1
|
||||
if err := s.repo.CreateQuestion(ctx, q); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
} else {
|
||||
old, err := s.repo.GetQuestion(ctx, tenantID, q.ID)
|
||||
if err != nil {
|
||||
return nil, errors.NewNotFoundError("题目不存在")
|
||||
}
|
||||
q.TenantID = tenantID
|
||||
q.BankID = old.BankID
|
||||
q.SeqNo = old.SeqNo
|
||||
if err := s.repo.UpdateQuestion(ctx, q); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
s.refreshBankQuestionCount(ctx, tenantID, q.BankID)
|
||||
return q, nil
|
||||
}
|
||||
|
||||
// DeleteQuestion 删除单题(题库 question_count 同步刷新,000153)。
|
||||
func (s *trainingService) DeleteQuestion(ctx context.Context, tenantID uint64, questionID string) error {
|
||||
q, err := s.repo.GetQuestion(ctx, tenantID, questionID)
|
||||
if err != nil {
|
||||
return errors.NewNotFoundError("题目不存在")
|
||||
}
|
||||
if err := s.repo.DeleteQuestion(ctx, tenantID, questionID); err != nil {
|
||||
return err
|
||||
}
|
||||
s.refreshBankQuestionCount(ctx, tenantID, q.BankID)
|
||||
return nil
|
||||
}
|
||||
|
||||
// refreshBankQuestionCount 按现存题目数刷新题库冗余计数(fail-open)。
|
||||
func (s *trainingService) refreshBankQuestionCount(ctx context.Context, tenantID uint64, bankID string) {
|
||||
count, err := s.repo.CountBankQuestions(ctx, tenantID, bankID)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
_ = s.repo.UpdateQuestionBankCount(ctx, tenantID, bankID, int(count))
|
||||
}
|
||||
|
||||
// questionTemplateCol holds resolved column indexes of the 题库导入版 template header.
|
||||
type questionTemplateCol struct {
|
||||
stem int
|
||||
@@ -855,9 +956,13 @@ const courseSelfStudyPaperVersion = "ONLINE"
|
||||
// GetCourseExamPaper 线上自学考试入口:确保课程线上卷存在并返回学员视角
|
||||
// 题目(卷不存在时按题库全量题数现场组卷,幂等)。
|
||||
func (s *trainingService) GetCourseExamPaper(ctx context.Context, tenantID uint64, userID, courseID string) (*types.TrainingPaper, []*types.TrainingQuestion, error) {
|
||||
// 绑定题库即默认可答题:只要课程关联了题库就允许取卷答题,
|
||||
// exam_enabled 仅决定详情页是否主动展示考试入口。
|
||||
bank, err := s.repo.GetQuestionBankByCourse(ctx, tenantID, courseID)
|
||||
// 绑定题库即默认可答题:只要课程(或其课程管理条目,000153)关联了题库就允许
|
||||
// 取卷答题,exam_enabled 仅决定详情页是否主动展示考试入口。
|
||||
course, cErr := s.repo.GetCourse(ctx, tenantID, courseID)
|
||||
if cErr != nil || course == nil {
|
||||
return nil, nil, errors.NewNotFoundError("课程不存在")
|
||||
}
|
||||
bank, err := s.courseExamBank(ctx, tenantID, course)
|
||||
if err != nil || bank == nil {
|
||||
return nil, nil, errors.NewNotFoundError("该课程未绑定题库,请联系培训管理员在课程管理中关联题库")
|
||||
}
|
||||
@@ -878,7 +983,11 @@ func (s *trainingService) GetCourseExamPaper(ctx context.Context, tenantID uint6
|
||||
// GetMyCourseExamRecord returns the caller's latest record on the course
|
||||
// self-study paper (nil, false) when未考/未绑题库。
|
||||
func (s *trainingService) GetMyCourseExamRecord(ctx context.Context, tenantID uint64, userID, courseID string) (*types.TrainingExamRecord, bool, error) {
|
||||
bank, err := s.repo.GetQuestionBankByCourse(ctx, tenantID, courseID)
|
||||
course, cErr := s.repo.GetCourse(ctx, tenantID, courseID)
|
||||
if cErr != nil || course == nil {
|
||||
return nil, false, nil
|
||||
}
|
||||
bank, err := s.courseExamBank(ctx, tenantID, course)
|
||||
if err != nil || bank == nil {
|
||||
return nil, false, nil
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user