diff --git a/internal/application/service/training_course.go b/internal/application/service/training_course.go index 83e71c0..eb7adf0 100644 --- a/internal/application/service/training_course.go +++ b/internal/application/service/training_course.go @@ -161,7 +161,13 @@ func (s *trainingService) applyLibraryCourseBinding(ctx context.Context, tenantI course.Hours = item.Hours } if course.Code == "" { - course.Code = item.Code + // 000163 根因修复:编号按租户流水独立生成,不再复制课程管理条目编号。 + // tr_courses 有 (tenant_id, code) 唯一索引,复制 CRS-#### 后同一门课程 + // 管理课程创建第二个月度计划必然撞唯一约束(500 duplicate key, + // 2026-11-25 测试环境「暂存草稿」即因此失败);计划行经 library_course_id + // 关联主数据,编号独立生成不影响带出与锁定逻辑。 + // fail-open:计数器失败留空(唯一索引豁免空编号),不阻断保存。 + course.Code = s.nextCourseLibraryCode(ctx, tenantID) } if len(course.DeptIDs) == 0 || string(course.DeptIDs) == "[]" || string(course.DeptIDs) == "null" { if item.OwnerDeptID != "" {