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

+69 -10
View File
@@ -51,6 +51,62 @@ func NewTrainingService(repo interfaces.TrainingRepository, kbService interfaces
func trainingNewID() string { return uuid.New().String() }
// ---------------------------------------------------------------------------
// 唯一编号(000153,前缀+年月+流水,租户内递增)
// 编号计数器失败时 fail-open(记录日志,编号留空),不阻断主流程。
// ---------------------------------------------------------------------------
// nextTrainingCode 经计数器取下一流水并按 format 拼业务编号。
func (s *trainingService) nextTrainingCode(ctx context.Context, tenantID uint64, key string, format func(int64) string) string {
value, err := s.repo.NextCodeValue(ctx, tenantID, key)
if err != nil {
logger.Error(ctx, "Failed to allocate training code", err, "key", key)
return ""
}
return format(value)
}
// nextDemandCode 年计划编号:AP-<year>-####(按年分段)。
func (s *trainingService) nextDemandCode(ctx context.Context, tenantID uint64, year int) string {
return s.nextTrainingCode(ctx, tenantID, fmt.Sprintf("AP:%d", year), func(v int64) string {
return fmt.Sprintf("AP-%d-%04d", year, v)
})
}
// nextMonthPlanCode 月度计划编号:MP-<YYYYMM>-####(按授课月份分段)。
func (s *trainingService) nextMonthPlanCode(ctx context.Context, tenantID uint64, year, month int) string {
key := fmt.Sprintf("MP:%04d%02d", year, month)
return s.nextTrainingCode(ctx, tenantID, key, func(v int64) string {
return fmt.Sprintf("MP-%04d%02d-%04d", year, month, v)
})
}
// nextCourseLibraryCode 课程编号:CRS-####(租户内流水)。
func (s *trainingService) nextCourseLibraryCode(ctx context.Context, tenantID uint64) string {
return s.nextTrainingCode(ctx, tenantID, "CRS", func(v int64) string {
return fmt.Sprintf("CRS-%04d", v)
})
}
// nextQuestionBankCode 试题库编号:QB-####(租户内流水)。
func (s *trainingService) nextQuestionBankCode(ctx context.Context, tenantID uint64) string {
return s.nextTrainingCode(ctx, tenantID, "QB", func(v int64) string {
return fmt.Sprintf("QB-%04d", v)
})
}
// monthPlanYearMonth 从课程授课时间(teach_time,YYYY-MM 或 YYYY-MM-DD HH:mm)
// 提取计划编号分段年月;解析失败回退当前年月。
func monthPlanYearMonth(teachTime string, now time.Time) (int, int) {
if len(teachTime) >= 7 {
var year, month int
if _, err := fmt.Sscanf(teachTime[:7], "%d-%d", &year, &month); err == nil && year > 0 && month >= 1 && month <= 12 {
return year, month
}
}
return now.Year(), int(now.Month())
}
func trainingJSONFromSlice(items []string) types.JSON {
if len(items) == 0 {
return types.JSON([]byte("[]"))
@@ -260,6 +316,11 @@ func (s *trainingService) ListDemands(ctx context.Context, tenantID uint64, q *i
return s.repo.ListDemands(ctx, tenantID, q)
}
// ListDemandYears returns distinct demand years (desc) for the year filter.
func (s *trainingService) ListDemandYears(ctx context.Context, tenantID uint64, deptID string) ([]int, error) {
return s.repo.ListDemandYears(ctx, tenantID, deptID)
}
// GetDemand fetches one demand.
func (s *trainingService) GetDemand(ctx context.Context, tenantID uint64, id string) (*types.TrainingDemand, error) {
return s.repo.GetDemand(ctx, tenantID, id)
@@ -335,6 +396,7 @@ func (s *trainingService) SaveDemand(ctx context.Context, tenantID uint64, deman
}
// 字段校验(规则引擎):缺项给出可执行提示,AI 语义校验由二期接手。
// 口径对齐需求表模板后,人数/课时不再采集,仅校验部门。
// 核验状态默认「待核验」:填报/编辑不自动通过,统一由经理核验确认。
msgs := []string{}
if demand.DeptID == "" {
msgs = append(msgs, "未指定部门")
@@ -346,11 +408,7 @@ func (s *trainingService) SaveDemand(ctx context.Context, tenantID uint64, deman
}
demand.CheckMsg += m
}
if len(msgs) == 0 {
demand.CheckStatus = types.TrainingCheckPassed
} else {
demand.CheckStatus = types.TrainingCheckPending
}
demand.CheckStatus = types.TrainingCheckPending
if demand.Status == "" {
demand.Status = types.TrainingDemandSubmitted
}
@@ -358,6 +416,8 @@ func (s *trainingService) SaveDemand(ctx context.Context, tenantID uint64, deman
if demand.ID == "" {
demand.ID = trainingNewID()
demand.TenantID = tenantID
// 年计划编号(AP-<year>-####,创建时生成;计数器失败留空不阻断)。
demand.Code = s.nextDemandCode(ctx, tenantID, demand.Year)
if err := s.repo.CreateDemand(ctx, demand); err != nil {
return nil, err
}
@@ -382,21 +442,20 @@ func (s *trainingService) ImportDemands(ctx context.Context, tenantID uint64, de
if demands[i].Year <= 0 {
demands[i].Year = time.Now().Year()
}
// 年计划编号(批量导入逐行生成,同年前缀分段递增)。
demands[i].Code = s.nextDemandCode(ctx, tenantID, demands[i].Year)
if demands[i].Status == "" {
demands[i].Status = types.TrainingDemandSubmitted
}
// 与 SaveDemand 同口径的缺项提示,方便导入后在列表中补齐再确认。
// 口径对齐需求表模板后,人数/课时不再采集,仅校验部门。
// 核验状态默认「待核验」:导入不自动通过,统一由经理核验确认。
msgs := []string{}
if demands[i].DeptID == "" {
msgs = append(msgs, "未指定部门")
}
demands[i].CheckMsg = strings.Join(msgs, ";")
if len(msgs) == 0 {
demands[i].CheckStatus = types.TrainingCheckPassed
} else {
demands[i].CheckStatus = types.TrainingCheckPending
}
demands[i].CheckStatus = types.TrainingCheckPending
}
if err := s.repo.BatchCreateDemands(ctx, demands); err != nil {
return nil, err