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
@@ -0,0 +1,27 @@
|
||||
package repository
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"academy/internal/types/interfaces"
|
||||
)
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// 培训业务唯一编号(000153)
|
||||
// 计数器表 tr_code_counters(tenant_id, code_key) 主键UPSERT原子递增,
|
||||
// key 形如 AP:2026 / MP:202611 / CRS / QB;存量数据由迁移回填并播种计数器。
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
// NextCodeValue 返回 code_key 下一个流水值(原子递增,并发安全)。
|
||||
func (r *trainingRepository) NextCodeValue(ctx context.Context, tenantID uint64, key string) (int64, error) {
|
||||
var value int64
|
||||
err := r.db.WithContext(ctx).Raw(`
|
||||
INSERT INTO tr_code_counters (tenant_id, code_key, value, updated_at)
|
||||
VALUES (?, ?, 1, CURRENT_TIMESTAMP)
|
||||
ON CONFLICT (tenant_id, code_key)
|
||||
DO UPDATE SET value = tr_code_counters.value + 1, updated_at = CURRENT_TIMESTAMP
|
||||
RETURNING value`, tenantID, key).Scan(&value).Error
|
||||
return value, err
|
||||
}
|
||||
|
||||
var _ interfaces.TrainingRepository = (*trainingRepository)(nil)
|
||||
@@ -21,9 +21,9 @@ func (r *trainingRepository) CreateQuestionBank(ctx context.Context, bank *types
|
||||
|
||||
// ReplaceQuestionBankByName 同名题库重导入即替换:软删同租户同名旧题库及其全部
|
||||
// 题目与试卷(含缓存的 ONLINE 自学卷,重导后按新解析重建),返回旧题库的
|
||||
// 课程关联供新题库继承;无同名旧库时原样返回空串。
|
||||
func (r *trainingRepository) ReplaceQuestionBankByName(ctx context.Context, tenantID uint64, name string) (string, error) {
|
||||
oldCourseID := ""
|
||||
// 课程/课程管理关联供新题库继承;无同名旧库时原样返回空串。
|
||||
func (r *trainingRepository) ReplaceQuestionBankByName(ctx context.Context, tenantID uint64, name string) (string, string, error) {
|
||||
oldCourseID, oldLibraryCourseID := "", ""
|
||||
err := r.db.WithContext(ctx).Transaction(func(tx *gorm.DB) error {
|
||||
var banks []*types.TrainingQuestionBank
|
||||
if err := tx.Where("tenant_id = ? AND name = ? AND deleted_at IS NULL", tenantID, name).
|
||||
@@ -39,6 +39,9 @@ func (r *trainingRepository) ReplaceQuestionBankByName(ctx context.Context, tena
|
||||
if oldCourseID == "" && b.CourseID != "" {
|
||||
oldCourseID = b.CourseID
|
||||
}
|
||||
if oldLibraryCourseID == "" && b.LibraryCourseID != "" {
|
||||
oldLibraryCourseID = b.LibraryCourseID
|
||||
}
|
||||
}
|
||||
now := time.Now()
|
||||
if err := tx.Model(&types.TrainingQuestionBank{}).
|
||||
@@ -55,7 +58,7 @@ func (r *trainingRepository) ReplaceQuestionBankByName(ctx context.Context, tena
|
||||
Where("tenant_id = ? AND bank_id IN ?", tenantID, ids).
|
||||
Update("deleted_at", now).Error
|
||||
})
|
||||
return oldCourseID, err
|
||||
return oldCourseID, oldLibraryCourseID, err
|
||||
}
|
||||
|
||||
// ListQuestionBanks returns a page of question banks.
|
||||
@@ -110,6 +113,38 @@ func (r *trainingRepository) GetQuestionBankByCourse(ctx context.Context, tenant
|
||||
return &b, nil
|
||||
}
|
||||
|
||||
// GetQuestionBankByLibraryCourse 取课程管理条目下的题库列表(试题随课程管理维护,
|
||||
// 000153;updated_at 降序,支持一个课程多个题库)。
|
||||
func (r *trainingRepository) GetQuestionBankByLibraryCourse(ctx context.Context, tenantID uint64, libraryCourseID string) ([]*types.TrainingQuestionBank, error) {
|
||||
var banks []*types.TrainingQuestionBank
|
||||
if err := r.db.WithContext(ctx).
|
||||
Where("tenant_id = ? AND library_course_id = ? AND deleted_at IS NULL", tenantID, libraryCourseID).
|
||||
Order("updated_at DESC").Find(&banks).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return banks, nil
|
||||
}
|
||||
|
||||
// DeleteQuestionBank 软删题库及其全部题目与缓存试卷(000153,试题抽屉删除入口)。
|
||||
func (r *trainingRepository) DeleteQuestionBank(ctx context.Context, tenantID uint64, bankID string) error {
|
||||
return r.db.WithContext(ctx).Transaction(func(tx *gorm.DB) error {
|
||||
now := time.Now()
|
||||
if err := tx.Model(&types.TrainingQuestionBank{}).
|
||||
Where("tenant_id = ? AND id = ?", tenantID, bankID).
|
||||
Update("deleted_at", now).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
if err := tx.Model(&types.TrainingQuestion{}).
|
||||
Where("tenant_id = ? AND bank_id = ?", tenantID, bankID).
|
||||
Update("deleted_at", now).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
return tx.Model(&types.TrainingPaper{}).
|
||||
Where("tenant_id = ? AND bank_id = ?", tenantID, bankID).
|
||||
Update("deleted_at", now).Error
|
||||
})
|
||||
}
|
||||
|
||||
// GetSelfStudyPaperByBank fetches the bank's course self-study paper
|
||||
// (无场次、version=ONLINE,与线下场次组卷区分)。
|
||||
func (r *trainingRepository) GetSelfStudyPaperByBank(ctx context.Context, tenantID uint64, bankID string) (*types.TrainingPaper, error) {
|
||||
@@ -130,6 +165,22 @@ func (r *trainingRepository) UpdateQuestionBankCourse(ctx context.Context, tenan
|
||||
Update("course_id", courseID).Error
|
||||
}
|
||||
|
||||
// RelinkQuestionBankToLibraryCourse 更换课程管理条目的试题(000156):先解除该条目
|
||||
// 下既有题库的挂接,再把所选题库指向该条目(更换即整体替换,其他课程的题库不受影响)。
|
||||
func (r *trainingRepository) RelinkQuestionBankToLibraryCourse(ctx context.Context, tenantID uint64, libraryCourseID, bankID string) error {
|
||||
return r.db.WithContext(ctx).Transaction(func(tx *gorm.DB) error {
|
||||
if err := tx.Model(&types.TrainingQuestionBank{}).
|
||||
Where("tenant_id = ? AND library_course_id = ? AND id <> ? AND deleted_at IS NULL",
|
||||
tenantID, libraryCourseID, bankID).
|
||||
Update("library_course_id", "").Error; err != nil {
|
||||
return err
|
||||
}
|
||||
return tx.Model(&types.TrainingQuestionBank{}).
|
||||
Where("tenant_id = ? AND id = ? AND deleted_at IS NULL", tenantID, bankID).
|
||||
Update("library_course_id", libraryCourseID).Error
|
||||
})
|
||||
}
|
||||
|
||||
// UpdateQuestionBankCount refreshes the denormalized question count.
|
||||
func (r *trainingRepository) UpdateQuestionBankCount(ctx context.Context, tenantID uint64, bankID string, count int) error {
|
||||
return r.db.WithContext(ctx).Model(&types.TrainingQuestionBank{}).
|
||||
@@ -145,6 +196,54 @@ func (r *trainingRepository) BatchCreateQuestions(ctx context.Context, questions
|
||||
return r.db.WithContext(ctx).Create(&questions).Error
|
||||
}
|
||||
|
||||
// CreateQuestion 插入单题(000153,试题抽屉手工新增)。
|
||||
func (r *trainingRepository) CreateQuestion(ctx context.Context, question *types.TrainingQuestion) error {
|
||||
return r.db.WithContext(ctx).Create(question).Error
|
||||
}
|
||||
|
||||
// GetQuestion 取单题。
|
||||
func (r *trainingRepository) GetQuestion(ctx context.Context, tenantID uint64, id string) (*types.TrainingQuestion, error) {
|
||||
var q types.TrainingQuestion
|
||||
if err := r.db.WithContext(ctx).
|
||||
Where("tenant_id = ? AND id = ?", tenantID, id).First(&q).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &q, nil
|
||||
}
|
||||
|
||||
// UpdateQuestion 更新单题(题干/选项/答案/分值等全字段)。
|
||||
func (r *trainingRepository) UpdateQuestion(ctx context.Context, question *types.TrainingQuestion) error {
|
||||
return r.db.WithContext(ctx).Model(&types.TrainingQuestion{}).
|
||||
Where("tenant_id = ? AND id = ?", question.TenantID, question.ID).
|
||||
Updates(map[string]interface{}{
|
||||
"seq_no": question.SeqNo,
|
||||
"type": question.Type,
|
||||
"stem": question.Stem,
|
||||
"options": question.Options,
|
||||
"answer": question.Answer,
|
||||
"score": question.Score,
|
||||
"difficulty": question.Difficulty,
|
||||
"knowledge_point": question.KnowledgePoint,
|
||||
"analysis": question.Analysis,
|
||||
}).Error
|
||||
}
|
||||
|
||||
// DeleteQuestion 软删单题(000153,试题抽屉删除入口)。
|
||||
func (r *trainingRepository) DeleteQuestion(ctx context.Context, tenantID uint64, id string) error {
|
||||
return r.db.WithContext(ctx).Model(&types.TrainingQuestion{}).
|
||||
Where("tenant_id = ? AND id = ?", tenantID, id).
|
||||
Update("deleted_at", time.Now()).Error
|
||||
}
|
||||
|
||||
// CountBankQuestions 统计题库现存未删题目数(增删题目后刷新冗余计数)。
|
||||
func (r *trainingRepository) CountBankQuestions(ctx context.Context, tenantID uint64, bankID string) (int64, error) {
|
||||
var count int64
|
||||
err := r.db.WithContext(ctx).Model(&types.TrainingQuestion{}).
|
||||
Where("tenant_id = ? AND bank_id = ? AND deleted_at IS NULL", tenantID, bankID).
|
||||
Count(&count).Error
|
||||
return count, err
|
||||
}
|
||||
|
||||
// ListQuestions returns all questions of a bank ordered by seq_no.
|
||||
func (r *trainingRepository) ListQuestions(ctx context.Context, tenantID uint64, bankID string) ([]*types.TrainingQuestion, error) {
|
||||
var items []*types.TrainingQuestion
|
||||
|
||||
@@ -0,0 +1,119 @@
|
||||
package repository
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"academy/internal/types"
|
||||
"academy/internal/types/interfaces"
|
||||
)
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// 课程管理(课程资产主数据,tr_course_library,000151)。
|
||||
// 月培训计划的「计划名称」从本表选择,选中后经 tr_courses.library_course_id 关联。
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
// ListCourseLibrary returns a page of course-library items with keyword filter
|
||||
// (分类/类型等前端本地过滤,数据量小全量加载)。
|
||||
func (r *trainingRepository) ListCourseLibrary(ctx context.Context, tenantID uint64, q *interfaces.TrainingListQuery) ([]*types.TrainingCourseLibrary, int64, error) {
|
||||
// 列名统一以 tr_course_library 限定:JOIN users 后 tenant_id/updated_at 等
|
||||
// 同名列不加限定会报 SQLSTATE 42702 歧义(与 ListCourses 同口径)。
|
||||
tx := r.db.WithContext(ctx).Model(&types.TrainingCourseLibrary{}).Where("tr_course_library.tenant_id = ?", tenantID)
|
||||
if q != nil {
|
||||
if q.Keyword != "" {
|
||||
tx = tx.Where("tr_course_library.name ILIKE ?", "%"+q.Keyword+"%")
|
||||
}
|
||||
}
|
||||
var total int64
|
||||
if err := tx.Count(&total).Error; err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
page, pageSize := 1, 100
|
||||
if q != nil {
|
||||
if q.Page > 0 {
|
||||
page = q.Page
|
||||
}
|
||||
if q.PageSize > 0 {
|
||||
pageSize = q.PageSize
|
||||
}
|
||||
}
|
||||
var items []*types.TrainingCourseLibrary
|
||||
// lecturer_name 联查真实姓名(讲师可为任意员工,外部讲师直接落姓名列);
|
||||
// owner_dept_name 联查部门名(所属部门存 org_depts id)。
|
||||
err := tx.Select("tr_course_library.*, COALESCE(NULLIF(lu.display_name, ''), lu.username, '') AS lecturer_name, COALESCE(od.name, '') AS owner_dept_name").
|
||||
Joins("LEFT JOIN users lu ON lu.id = tr_course_library.lecturer_id").
|
||||
Joins("LEFT JOIN org_depts od ON od.id = tr_course_library.owner_dept_id AND od.tenant_id = tr_course_library.tenant_id AND od.deleted_at IS NULL").
|
||||
Order("tr_course_library.updated_at DESC").
|
||||
Offset((page - 1) * pageSize).Limit(pageSize).
|
||||
Find(&items).Error
|
||||
return items, total, err
|
||||
}
|
||||
|
||||
// GetCourseLibraryItem fetches one course-library item.
|
||||
func (r *trainingRepository) GetCourseLibraryItem(ctx context.Context, tenantID uint64, id string) (*types.TrainingCourseLibrary, error) {
|
||||
var item types.TrainingCourseLibrary
|
||||
if err := r.db.WithContext(ctx).
|
||||
Select("tr_course_library.*, COALESCE(NULLIF(lu.display_name, ''), lu.username, '') AS lecturer_name, COALESCE(od.name, '') AS owner_dept_name").
|
||||
Joins("LEFT JOIN users lu ON lu.id = tr_course_library.lecturer_id").
|
||||
Joins("LEFT JOIN org_depts od ON od.id = tr_course_library.owner_dept_id AND od.tenant_id = tr_course_library.tenant_id AND od.deleted_at IS NULL").
|
||||
Where("tr_course_library.tenant_id = ? AND tr_course_library.id = ?", tenantID, id).First(&item).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &item, nil
|
||||
}
|
||||
|
||||
// CreateCourseLibraryItem inserts one course-library item.
|
||||
func (r *trainingRepository) CreateCourseLibraryItem(ctx context.Context, item *types.TrainingCourseLibrary) error {
|
||||
return r.db.WithContext(ctx).Create(item).Error
|
||||
}
|
||||
|
||||
// UpdateCourseLibraryItem updates mutable course-library fields (file columns included:
|
||||
// 课件文件上传后随行更新,清空即置空)。
|
||||
func (r *trainingRepository) UpdateCourseLibraryItem(ctx context.Context, item *types.TrainingCourseLibrary) error {
|
||||
return r.db.WithContext(ctx).Model(&types.TrainingCourseLibrary{}).
|
||||
Where("tenant_id = ? AND id = ?", item.TenantID, item.ID).
|
||||
Updates(map[string]interface{}{
|
||||
"name": item.Name,
|
||||
"owner_dept_id": item.OwnerDeptID,
|
||||
"description": item.Description,
|
||||
"suitable_members": item.SuitableMembers,
|
||||
"category": item.Category,
|
||||
"type": item.Type,
|
||||
"mode": item.Mode,
|
||||
"lecturer_id": item.LecturerID,
|
||||
"lecturer_external": item.LecturerExternal,
|
||||
"hours": item.Hours,
|
||||
"material_name": item.MaterialName,
|
||||
"file_key": item.FileKey,
|
||||
"file_name": item.FileName,
|
||||
"file_size": item.FileSize,
|
||||
// 课件知识库文档 id(上传同步后回填;code 编号列只读不在更新列)。
|
||||
"knowledge_id": item.KnowledgeID,
|
||||
}).Error
|
||||
}
|
||||
|
||||
// UpdateCourseLibraryPublishStatus 更新课程管理条目发布状态(000154):
|
||||
// published 已发布 / offline 已下线,供培训中心「和信课程」目录过滤。
|
||||
func (r *trainingRepository) UpdateCourseLibraryPublishStatus(ctx context.Context, tenantID uint64, id, status string) error {
|
||||
return r.db.WithContext(ctx).Model(&types.TrainingCourseLibrary{}).
|
||||
Where("tenant_id = ? AND id = ?", tenantID, id).
|
||||
Updates(map[string]interface{}{
|
||||
"publish_status": status,
|
||||
"updated_at": time.Now(),
|
||||
}).Error
|
||||
}
|
||||
|
||||
// BatchCreateCourseLibrary inserts course-library items in one batch (Excel 导入)。
|
||||
func (r *trainingRepository) BatchCreateCourseLibrary(ctx context.Context, items []*types.TrainingCourseLibrary) error {
|
||||
if len(items) == 0 {
|
||||
return nil
|
||||
}
|
||||
return r.db.WithContext(ctx).Create(&items).Error
|
||||
}
|
||||
|
||||
// DeleteCourseLibraryItem soft-deletes one course-library item.
|
||||
func (r *trainingRepository) DeleteCourseLibraryItem(ctx context.Context, tenantID uint64, id string) error {
|
||||
return r.db.WithContext(ctx).
|
||||
Where("tenant_id = ? AND id = ?", tenantID, id).
|
||||
Delete(&types.TrainingCourseLibrary{}).Error
|
||||
}
|
||||
@@ -69,6 +69,22 @@ func (r *trainingRepository) ListDemands(ctx context.Context, tenantID uint64, q
|
||||
return items, total, err
|
||||
}
|
||||
|
||||
// ListDemandYears returns distinct demand years of the tenant, latest first
|
||||
// (年度需求收集页年份下拉数据源:列表中所有计划培训实际年份;
|
||||
// deptID 非空时收窄到该部门,与纯课长数据范围口径一致)。
|
||||
func (r *trainingRepository) ListDemandYears(ctx context.Context, tenantID uint64, deptID string) ([]int, error) {
|
||||
var years []int
|
||||
tx := r.db.WithContext(ctx).Model(&types.TrainingDemand{}).
|
||||
Where("tenant_id = ? AND year > 0", tenantID)
|
||||
if deptID != "" {
|
||||
tx = tx.Where("dept_id = ?", deptID)
|
||||
}
|
||||
err := tx.Distinct().
|
||||
Order("year DESC").
|
||||
Pluck("year", &years).Error
|
||||
return years, err
|
||||
}
|
||||
|
||||
// GetDemand fetches one demand.
|
||||
func (r *trainingRepository) GetDemand(ctx context.Context, tenantID uint64, id string) (*types.TrainingDemand, error) {
|
||||
var d types.TrainingDemand
|
||||
@@ -375,6 +391,8 @@ func (r *trainingRepository) UpdateCourse(ctx context.Context, course *types.Tra
|
||||
"session_count": course.SessionCount,
|
||||
"lecturer_external": course.LecturerExternal,
|
||||
"remark": course.Remark,
|
||||
// 课程管理关联(月培训计划「计划名称」来源,000151)。
|
||||
"library_course_id": course.LibraryCourseID,
|
||||
}).Error
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user