feat(training): 课程管理新增核验状态流转与权限细化(000157)
deploy-hxtesting / build-and-deploy (push) Failing after 0s
deploy-hxtesting / build-and-deploy (push) Failing after 0s
核验状态(verify_status,迁移 000157): - 新字段 pending 待核验(初始)/confirmed 已确认,附核验人/核验时间审计列,存量数据回填待核验 - 新增/导入/编辑(含重新上传课件)一律重置为待核验,原核验结论作废 - 发布前置校验:课程发布、月培训计划「发布/保存并发布」关联课程必须已确认,否则友好提示核验入口 核验/删除权限(仅本部门课长/经理): - 新端点 POST /training/course-library/verify 单个/批量共用,越权/已确认行跳过不阻断 - 核验与删除严格按课长身份所在部门收窄,人事/讲师/学员/空间管理员均无跨部门操作权 - 删除仅限待核验状态(已确认课程不可删,须走核验流程) 列表数据范围与页签: - 课程管理列表按角色注入过滤:人事/空间管理员全部,课长/经理本部门,讲师/学员仅「与我相关」(本人创建或本人授课) - 课程管理页签对学员开放;无维护角色用户仅可编辑本人创建/授课课程(不可新增) 前端: - 发布状态「草稿」文案改为「待发布」;新增「状态」列固定右侧置于操作列前 - 列表勾选 + 批量核验/批量删除(仅本部门待核验行提交);发布按钮前置核验校验未核验友好提示;按钮按角色/部门/状态动态显隐
This commit is contained in:
1 parent
168057db78
commit
80deef9c53
13 files changed
+418
-21
No files matched your search
@@ -23,6 +23,14 @@ func (r *trainingRepository) ListCourseLibrary(ctx context.Context, tenantID uin
|
||||
if q.Keyword != "" {
|
||||
tx = tx.Where("tr_course_library.name ILIKE ?", "%"+q.Keyword+"%")
|
||||
}
|
||||
// 数据范围过滤(handler 按调用方角色强制注入,000157):dept_id=课长/经理
|
||||
// 本部门;related_user_id=无维护角色的用户仅见自己创建或授课的课程。
|
||||
if q.DeptID != "" {
|
||||
tx = tx.Where("tr_course_library.owner_dept_id = ?", q.DeptID)
|
||||
}
|
||||
if q.RelatedUserID != "" {
|
||||
tx = tx.Where("tr_course_library.creator_id = ? OR tr_course_library.lecturer_id = ?", q.RelatedUserID, q.RelatedUserID)
|
||||
}
|
||||
}
|
||||
var total int64
|
||||
if err := tx.Count(&total).Error; err != nil {
|
||||
@@ -92,9 +100,30 @@ func (r *trainingRepository) UpdateCourseLibraryItem(ctx context.Context, item *
|
||||
"file_size": item.FileSize,
|
||||
// 课件知识库文档 id(上传同步后回填;code 编号列只读不在更新列)。
|
||||
"knowledge_id": item.KnowledgeID,
|
||||
// 核验状态(000157):编辑/换课件后由服务层重置为待核验并清空核验痕迹。
|
||||
"verify_status": item.VerifyStatus,
|
||||
"confirmed_by": item.ConfirmedBy,
|
||||
"confirmed_at": item.ConfirmedAt,
|
||||
}).Error
|
||||
}
|
||||
|
||||
// ConfirmCourseLibraryItems 批量核验课程条目(000157):仅待核验行置为已确认并
|
||||
// 回填核验人/时间(幂等:已确认行不重复更新),返回实际核验行数。
|
||||
func (r *trainingRepository) ConfirmCourseLibraryItems(ctx context.Context, tenantID uint64, ids []string, verifierID string) (int64, error) {
|
||||
if len(ids) == 0 {
|
||||
return 0, nil
|
||||
}
|
||||
tx := r.db.WithContext(ctx).Model(&types.TrainingCourseLibrary{}).
|
||||
Where("tenant_id = ? AND id IN ? AND verify_status = ?", tenantID, ids, types.CourseLibraryVerifyPending).
|
||||
Updates(map[string]interface{}{
|
||||
"verify_status": types.CourseLibraryVerifyConfirmed,
|
||||
"confirmed_by": verifierID,
|
||||
"confirmed_at": time.Now(),
|
||||
"updated_at": time.Now(),
|
||||
})
|
||||
return tx.RowsAffected, tx.Error
|
||||
}
|
||||
|
||||
// UpdateCourseLibraryPublishStatus 更新课程管理条目发布状态(000154):
|
||||
// published 已发布 / offline 已下线,供培训中心「和信课程」目录过滤。
|
||||
func (r *trainingRepository) UpdateCourseLibraryPublishStatus(ctx context.Context, tenantID uint64, id, status string) error {
|
||||
|
||||
@@ -358,6 +358,17 @@ func (s *trainingService) PublishCourse(ctx context.Context, tenantID uint64, id
|
||||
if course.Status == types.TrainingCoursePublished {
|
||||
return course, nil
|
||||
}
|
||||
// 关联课程管理条目须已核验确认(000157):月培训计划发布/保存并发布共用本端点,
|
||||
// 未核验的课程拦截并友好提示,核验入口在「课程管理」。
|
||||
if course.LibraryCourseID != "" {
|
||||
lib, libErr := s.repo.GetCourseLibraryItem(ctx, tenantID, course.LibraryCourseID)
|
||||
if libErr != nil || lib == nil {
|
||||
return nil, errors.NewBadRequestError("关联的课程管理条目不存在,请先在「课程管理」中确认该课程")
|
||||
}
|
||||
if lib.VerifyStatus != types.CourseLibraryVerifyConfirmed {
|
||||
return nil, errors.NewBadRequestError(fmt.Sprintf("关联课程《%s》尚未核验确认,请先在「课程管理」中由所属部门课长/经理核验后再发布", lib.Name))
|
||||
}
|
||||
}
|
||||
course.Status = types.TrainingCoursePublished
|
||||
if err := s.repo.UpdateCourse(ctx, course); err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -103,6 +103,8 @@ func (s *trainingService) SaveCourseLibraryItem(ctx context.Context, tenantID ui
|
||||
item.ID = trainingNewID()
|
||||
item.TenantID = tenantID
|
||||
item.CreatorID = updaterID
|
||||
// 新增即待核验(000157):由所属部门课长/经理核验后方可发布。
|
||||
item.VerifyStatus = types.CourseLibraryVerifyPending
|
||||
// 仅传部门名时按组织架构解析为 id(不阻断保存)。
|
||||
s.resolveCourseLibraryDept(ctx, tenantID, item)
|
||||
// 课程编号(CRS-####,创建时由服务端生成;编号列只读,不收前端值)。
|
||||
@@ -129,6 +131,10 @@ func (s *trainingService) SaveCourseLibraryItem(ctx context.Context, tenantID ui
|
||||
if item.KnowledgeID == "" {
|
||||
item.KnowledgeID = old.KnowledgeID
|
||||
}
|
||||
// 编辑即回待核验(000157):内容变更后原核验结论作废,需重新核验。
|
||||
item.VerifyStatus = types.CourseLibraryVerifyPending
|
||||
item.ConfirmedBy = ""
|
||||
item.ConfirmedAt = nil
|
||||
item.TenantID = tenantID
|
||||
if err := s.repo.UpdateCourseLibraryItem(ctx, item); err != nil {
|
||||
return nil, err
|
||||
@@ -137,10 +143,19 @@ func (s *trainingService) SaveCourseLibraryItem(ctx context.Context, tenantID ui
|
||||
}
|
||||
|
||||
// DeleteCourseLibraryItem 软删课程管理条目(月培训计划已创建的历史计划不受影响)。
|
||||
func (s *trainingService) DeleteCourseLibraryItem(ctx context.Context, tenantID uint64, id string) error {
|
||||
if _, err := s.repo.GetCourseLibraryItem(ctx, tenantID, id); err != nil {
|
||||
// 000157 收紧:仅「待核验」状态可删(已确认课程须走核验流程,不可绕过);
|
||||
// deptScope 非空(课长/经理)时仅可删除本部门课程。
|
||||
func (s *trainingService) DeleteCourseLibraryItem(ctx context.Context, tenantID uint64, id, deptScope string) error {
|
||||
item, err := s.repo.GetCourseLibraryItem(ctx, tenantID, id)
|
||||
if err != nil || item == nil {
|
||||
return werrors.NewNotFoundError("课程不存在")
|
||||
}
|
||||
if item.VerifyStatus != types.CourseLibraryVerifyPending {
|
||||
return werrors.NewBadRequestError("仅待核验状态的课程可删除,已确认课程不可删除")
|
||||
}
|
||||
if deptScope != "" && item.OwnerDeptID != deptScope {
|
||||
return werrors.NewForbiddenError("仅可删除本部门的课程")
|
||||
}
|
||||
return s.repo.DeleteCourseLibraryItem(ctx, tenantID, id)
|
||||
}
|
||||
|
||||
@@ -155,6 +170,7 @@ func (s *trainingService) GetCourseLibraryItem(ctx context.Context, tenantID uin
|
||||
|
||||
// SetCourseLibraryPublishStatus 课程条目发布/下线(000154):published 已发布 /
|
||||
// offline 已下线;培训中心「和信课程」目录仅展示已发布课程。
|
||||
// 发布前置校验核验状态(000157):仅「已确认」课程可发布。
|
||||
func (s *trainingService) SetCourseLibraryPublishStatus(ctx context.Context, tenantID uint64, id, status string) error {
|
||||
if status != "published" && status != "offline" {
|
||||
return werrors.NewBadRequestError("发布状态不合法(仅支持发布/下线)")
|
||||
@@ -163,9 +179,42 @@ func (s *trainingService) SetCourseLibraryPublishStatus(ctx context.Context, ten
|
||||
if err != nil || item == nil {
|
||||
return werrors.NewNotFoundError("课程不存在")
|
||||
}
|
||||
if status == "published" && item.VerifyStatus != types.CourseLibraryVerifyConfirmed {
|
||||
return werrors.NewBadRequestError(fmt.Sprintf("课程《%s》尚未核验,请先由所属部门课长/经理核验确认后再发布", item.Name))
|
||||
}
|
||||
return s.repo.UpdateCourseLibraryPublishStatus(ctx, tenantID, id, status)
|
||||
}
|
||||
|
||||
// VerifyCourseLibraryItems 批量核验课程条目(000157,单个/批量共用):核验人所在
|
||||
// 部门(deptScope,handler 保证恒非空)必须与课程所属部门一致;已确认行与部门
|
||||
// 不匹配行跳过,返回实际核验数与跳过数,全无效时报错提示。
|
||||
func (s *trainingService) VerifyCourseLibraryItems(ctx context.Context, tenantID uint64, ids []string, verifierID, deptScope string) (int64, int64, error) {
|
||||
allowed := make([]string, 0, len(ids))
|
||||
for _, id := range ids {
|
||||
item, err := s.repo.GetCourseLibraryItem(ctx, tenantID, id)
|
||||
if err != nil || item == nil {
|
||||
continue // 不存在的条目跳过,不阻断其余行
|
||||
}
|
||||
if item.VerifyStatus != types.CourseLibraryVerifyPending {
|
||||
continue // 已确认行幂等跳过
|
||||
}
|
||||
if deptScope != "" && item.OwnerDeptID != deptScope {
|
||||
continue // 课长/经理仅可核验本部门课程
|
||||
}
|
||||
allowed = append(allowed, id)
|
||||
}
|
||||
skipped := int64(len(ids) - len(allowed))
|
||||
if len(allowed) == 0 {
|
||||
return 0, skipped, werrors.NewBadRequestError("没有可核验的课程(仅本部门待核验状态的课程可核验)")
|
||||
}
|
||||
verified, err := s.repo.ConfirmCourseLibraryItems(ctx, tenantID, allowed, verifierID)
|
||||
if err != nil {
|
||||
return 0, 0, err
|
||||
}
|
||||
logger.Infof(ctx, "[Training] course library verified, tenant=%d verified=%d skipped=%d verifier=%s", tenantID, verified, skipped, verifierID)
|
||||
return verified, skipped, nil
|
||||
}
|
||||
|
||||
// ImportCourseLibraryItems 批量导入(前端解析 Excel 后逐行提交,讲师已在
|
||||
// 前端按员工名册解析为 id / 外部姓名,与需求导入同口径)。
|
||||
func (s *trainingService) ImportCourseLibraryItems(ctx context.Context, tenantID uint64, items []*types.TrainingCourseLibrary, updaterID string) (int, error) {
|
||||
@@ -182,6 +231,8 @@ func (s *trainingService) ImportCourseLibraryItems(ctx context.Context, tenantID
|
||||
item.ID = trainingNewID()
|
||||
item.TenantID = tenantID
|
||||
item.CreatorID = updaterID
|
||||
// 导入即待核验(000157):与新增同口径,核验后方可发布。
|
||||
item.VerifyStatus = types.CourseLibraryVerifyPending
|
||||
// 课程编号逐行生成(CRS-####)。
|
||||
item.Code = s.nextCourseLibraryCode(ctx, tenantID)
|
||||
rows = append(rows, item)
|
||||
@@ -290,6 +341,10 @@ func (s *trainingService) UploadCourseLibraryMaterial(ctx context.Context, tenan
|
||||
if strings.TrimSpace(item.MaterialName) == "" {
|
||||
item.MaterialName = fh.Filename
|
||||
}
|
||||
// 换课件即回待核验(000157):课件内容变更后需重新核验。
|
||||
item.VerifyStatus = types.CourseLibraryVerifyPending
|
||||
item.ConfirmedBy = ""
|
||||
item.ConfirmedAt = nil
|
||||
if err := s.repo.UpdateCourseLibraryItem(ctx, item); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -353,6 +408,10 @@ func (s *trainingService) AttachCourseLibraryMaterialFromKnowledge(ctx context.C
|
||||
}
|
||||
item.FileKey, item.FileSize = "", 0
|
||||
item.KnowledgeID = knowledgeID
|
||||
// 换课件即回待核验(000157):课件内容变更后需重新核验。
|
||||
item.VerifyStatus = types.CourseLibraryVerifyPending
|
||||
item.ConfirmedBy = ""
|
||||
item.ConfirmedAt = nil
|
||||
if err := s.repo.UpdateCourseLibraryItem(ctx, item); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user