feat(training): 企业培训迭代:推送深链接与签名下载、课程管理修复与收集模板调整

推送域(000155):
- 广播通知支持 link_url:demand_collect 场景自动签发教育训练需求表模板
  匿名下载直链(HMAC token,20 天有效,免登录路由),企微消息尾部拼
  「下载模板 + 查看更多详情」链接;站内文本保持纯文本不受影响
- 配置中心新增「推送链接基址」(notify_link_base_url,多入口/内外网部署固定
  权威地址,留空跟随推送人访问地址)与「年培训计划收集推送文案」
  (demand_collect_*,{year} 渲染收集年度);空标题/内容按模板回落渲染
- 迁移 000155:tr_training_notifications 增 link_url/link_token 列

课程管理:
- 修复点【发布/下线】报「不支持的操作」:动作取值兼容字面量路由(FullPath
  末段)与 :action 通配两种注册形态
- 列表新增「创建人」列:creator_id 联查 users 带出姓名,导出 Excel 同步;
  新增课程「所属部门」默认当前登录用户所在部门
- 导入加固:表头归一化 + 别名模糊匹配(兼容内置模板/旧口径/自定义模板变体);
  导入与新增行支持按部门名兜底解析为 id(前端名册未命中时传 owner_dept_name)

年培训计划:
- 需求列表新增「创建人/创建时间」列(submitter_id 联查 users 带出姓名)
- 收集模板调整:下载时动态删除「培训费用(RMB)」列(旧版自定义模板同步归一,
  右侧列/合并/下拉随删列平移);备注右侧追加「调研维度/培训策划要求」说明列
  (合并至数据区末行,自动换行带边框,已带说明的自定义模板不覆盖)

开发工具:
- air 热重载适配 Windows:构建收敛到 scripts/air_build.sh(规避 air 经
  PowerShell 执行不支持 bash 命令替换),产物改 .exe 后缀;CGO_CFLAGS 取
  持久化值并集追加,不覆盖 go env -w 的头文件包含路径
This commit is contained in:
runny committed 2026-11-19 17:10:12 +08:00
1 parent 242dd7e1a6
commit 4e25fce9aa
30 files changed
+1150 -143

No files matched your search

+36 -36
View File
@@ -112,7 +112,7 @@ func (h *Handler) requireRoles(c *gin.Context, allowed ...string) (ok bool) {
labelParts = append(labelParts, want)
}
}
_ = c.Error(errors.NewForbiddenError("无权执行该操作,需要职称角色: "+strings.Join(labelParts, "/")))
_ = c.Error(errors.NewForbiddenError("无权执行该操作,需要职称角色: " + strings.Join(labelParts, "/")))
return false
}
@@ -423,10 +423,10 @@ type saveDemandRequest struct {
// LecturerExternal 外部讲师姓名(非系统员工;lecturer_id 为空时生效)。
LecturerExternal string `json:"lecturer_external"`
// TrainType 内/外培训(内部/外部,选填;来自需求表模板「內/外培訓」列)。
TrainType string `json:"train_type"`
TargetCount int `json:"target_count"`
Hours float64 `json:"hours"`
ExpectMonth int `json:"expect_month"`
TrainType string `json:"train_type"`
TargetCount int `json:"target_count"`
Hours float64 `json:"hours"`
ExpectMonth int `json:"expect_month"`
// PlannedTime 计划培训时间(YYYY-MM-DD HH:mm 或 YYYY-MM-DD,选填;确认后同步课程)。
PlannedTime string `json:"planned_time"`
Remark string `json:"remark"`
@@ -735,7 +735,7 @@ func (h *Handler) syncDemandParticipants(ctx context.Context, tenantID uint64, c
if startAt := parseFlexibleTime(demand.PlannedTime); startAt != nil {
session.StartAt = startAt
if demand.Hours > 0 {
end := startAt.Add(time.Duration(demand.Hours*float64(time.Hour)))
end := startAt.Add(time.Duration(demand.Hours * float64(time.Hour)))
session.EndAt = &end
}
}
@@ -834,7 +834,7 @@ func (h *Handler) notifyDemandVerify(ctx context.Context, tenantID uint64, deman
"%s 新导入 %d 条年度培训需求(课程:%s)。请登录 AIDO → 企业培训 → 年培训计划,逐条核验并【确认】,确认后将自动转入月培训计划。",
name, len(courses), strings.Join(courses, "、"),
)
n, err := h.svc.BroadcastNotification(ctx, tenantID, recipients, "demand_verify", title, content, "plan", strconv.Itoa(year))
n, err := h.svc.BroadcastNotification(ctx, tenantID, recipients, "demand_verify", title, content, "plan", strconv.Itoa(year), "")
if err != nil {
logger.Error(ctx, "Failed to notify dept managers for demand verify", err)
continue
@@ -870,7 +870,7 @@ func (h *Handler) notifyDemandConfirmed(ctx context.Context, tenantID uint64, op
"%d年度需求「%s」已核验确认并自动转入月培训计划:请讲师维护课程信息(课件/试题),课长安排授课时间/地点与学员名单。入口:AIDO → 企业培训 → 月培训计划。",
demand.Year, demand.CourseName,
)
if _, err := h.svc.BroadcastNotification(ctx, tenantID, final, "demand_confirmed", title, content, "course", demand.ID); err != nil {
if _, err := h.svc.BroadcastNotification(ctx, tenantID, final, "demand_confirmed", title, content, "course", demand.ID, ""); err != nil {
logger.Error(ctx, "Failed to notify lecturer and supervisors after demand confirm", err)
}
}
@@ -1000,13 +1000,13 @@ func (h *Handler) ListMonthPlans(c *gin.Context) {
// saveMonthPlanRequest is the body of POST /training/month-plans.
type saveMonthPlanRequest struct {
ID string `json:"id"`
Year int `json:"year"`
Month int `json:"month"`
DeptID string `json:"dept_id"`
Title string `json:"title" binding:"required"`
StartAt string `json:"start_at"` // RFC3339 / "2006-01-02 15:04"
Location string `json:"location"`
ID string `json:"id"`
Year int `json:"year"`
Month int `json:"month"`
DeptID string `json:"dept_id"`
Title string `json:"title" binding:"required"`
StartAt string `json:"start_at"` // RFC3339 / "2006-01-02 15:04"
Location string `json:"location"`
LecturerID string `json:"lecturer_id"`
}
@@ -1123,23 +1123,23 @@ func (h *Handler) GetCourse(c *gin.Context) {
// saveCourseRequest is the body of POST /training/courses.
type saveCourseRequest struct {
ID string `json:"id"`
Code string `json:"code"`
Name string `json:"name" binding:"required"`
Mode string `json:"mode"`
Type string `json:"type"`
LecturerID string `json:"lecturer_id"`
Hours float64 `json:"hours"`
Credits float64 `json:"credits"`
ExamEnabled bool `json:"exam_enabled"`
DeptIDs []string `json:"dept_ids"`
PostScope string `json:"post_scope"`
Description string `json:"description"`
MaterialIDs []string `json:"material_ids"`
TeachTime string `json:"teach_time"`
ID string `json:"id"`
Code string `json:"code"`
Name string `json:"name" binding:"required"`
Mode string `json:"mode"`
Type string `json:"type"`
LecturerID string `json:"lecturer_id"`
Hours float64 `json:"hours"`
Credits float64 `json:"credits"`
ExamEnabled bool `json:"exam_enabled"`
DeptIDs []string `json:"dept_ids"`
PostScope string `json:"post_scope"`
Description string `json:"description"`
MaterialIDs []string `json:"material_ids"`
TeachTime string `json:"teach_time"`
// PlannedTime 计划培训时间(需求确认同步的课程携带;前端编辑时原样回传保留)。
PlannedTime string `json:"planned_time"`
QuestionBankID string `json:"question_bank_id"`
PlannedTime string `json:"planned_time"`
QuestionBankID string `json:"question_bank_id"`
// 以下为需求确认同步字段(前端编辑时原样回传保留,防止被零值覆盖)。
TrainType string `json:"train_type"`
Plant string `json:"plant"`
@@ -1632,12 +1632,12 @@ func (h *Handler) GetSignCode(c *gin.Context) {
// CheckinRequest is the body of POST /training/sign-records/checkin.
type CheckinRequest struct {
Token string `json:"token" binding:"required"`
Lat float64 `json:"lat"`
Lng float64 `json:"lng"`
Channel string `json:"channel"`
Token string `json:"token" binding:"required"`
Lat float64 `json:"lat"`
Lng float64 `json:"lng"`
Channel string `json:"channel"`
// MemberID 可选:讲师/课长/人事现场代扫码/补录。
MemberID string `json:"member_id"`
MemberID string `json:"member_id"`
}
// Checkin POST /training/sign-records/checkin — 学员扫码签到(带定位校验);
+18 -7
View File
@@ -3,6 +3,7 @@ package training
import (
"fmt"
"net/http"
"path"
"academy/internal/errors"
"academy/internal/filetransport"
@@ -21,9 +22,12 @@ import (
// saveCourseLibraryRequest is the body of POST /training/course-library.
type saveCourseLibraryRequest struct {
ID string `json:"id"`
Name string `json:"name" binding:"required"`
OwnerDeptID string `json:"owner_dept_id"`
ID string `json:"id"`
Name string `json:"name" binding:"required"`
OwnerDeptID string `json:"owner_dept_id"`
// OwnerDeptName 所属部门名(导入兜底:前端未匹配到部门 id 时只传名,
// 服务端按组织架构名册解析;与只读展示列 owner_dept_name 同名字段复用)。
OwnerDeptName string `json:"owner_dept_name"`
Description string `json:"description"`
SuitableMembers string `json:"suitable_members"`
Category string `json:"category"`
@@ -43,6 +47,7 @@ func toCourseLibrary(req saveCourseLibraryRequest) *types.TrainingCourseLibrary
ID: req.ID,
Name: req.Name,
OwnerDeptID: req.OwnerDeptID,
OwnerDeptName: req.OwnerDeptName,
Description: req.Description,
SuitableMembers: req.SuitableMembers,
Category: req.Category,
@@ -96,15 +101,21 @@ func (h *Handler) DeleteCourseLibraryItem(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{"success": true})
}
// SetCourseLibraryPublishStatus POST /training/course-library/:id/:action
// — 课程条目发布/下线(000154;action=publish|offline,人事/课长/讲师)。
// 发布后课程进入培训中心「和信课程」目录;下线即从目录撤回。
// SetCourseLibraryPublishStatus POST /training/course-library/:id/publish|offline
// — 课程条目发布/下线(000154,人事/课长/讲师)。发布后课程进入培训中心
// 「和信课程」目录;下线即从目录撤回。动作取值兼容两种路由注册:字面量
// /course-library/:id/publish|offline(现网注册,FullPath 末段)与
// /course-library/:id/:action 通配(Param),任一命中即执行。
func (h *Handler) SetCourseLibraryPublishStatus(c *gin.Context) {
if !h.requireRoles(c, types.TrainingRoleHR, types.TrainingRoleSupervisor, types.TrainingRoleLecturer) {
return
}
action := c.Param("action")
if action == "" {
action = path.Base(c.FullPath())
}
status := ""
switch c.Param("action") {
switch action {
case "publish":
status = "published"
case "offline":
+27 -1
View File
@@ -12,6 +12,7 @@ import (
"academy/internal/errors"
"academy/internal/types"
"academy/internal/utils"
"github.com/gin-gonic/gin"
)
@@ -575,6 +576,7 @@ func (h *Handler) MarkNotificationsRead(c *gin.Context) {
// BroadcastNotification POST /training/notifications/broadcast — 培训运营向指定人员批量推送通知
// (收集下年度计划等场景);通知 ref_type 用于前端铃铛点击跳转定位。
// link_url 传前端 origin:demand_collect 场景企微消息尾部拼模板下载与详情链接。
func (h *Handler) BroadcastNotification(c *gin.Context) {
ctx := c.Request.Context()
if !h.requireRoles(c, types.TrainingRoleHR, types.TrainingRoleSupervisor) {
@@ -587,12 +589,13 @@ func (h *Handler) BroadcastNotification(c *gin.Context) {
Content string `json:"content"`
RefType string `json:"ref_type"`
RefID string `json:"ref_id"`
LinkURL string `json:"link_url"`
}
if err := c.ShouldBindJSON(&req); err != nil {
_ = c.Error(errors.NewBadRequestError("请求参数不合法").WithDetails(err.Error()))
return
}
sent, err := h.svc.BroadcastNotification(ctx, callerTenantID(c), req.UserIDs, req.Scene, req.Title, req.Content, req.RefType, req.RefID)
sent, err := h.svc.BroadcastNotification(ctx, callerTenantID(c), req.UserIDs, req.Scene, req.Title, req.Content, req.RefType, req.RefID, req.LinkURL)
if err != nil {
_ = c.Error(err)
return
@@ -699,6 +702,29 @@ func (h *Handler) DownloadTrainingTemplate(c *gin.Context) {
_ = c.Error(err)
return
}
serveTemplateFile(c, data, fileName)
}
// DownloadTrainingTemplateSigned GET /training/templates/signed-file?token=…
// — 免登录签名下载(2026-11 需求:企微推送消息内点击即下载教育训练需求表
// 模板)。token 为 broadcast 入箱时签发的 HMAC(tenant+模板+过期,20 天),
// 租户与模板键均取自 token 载荷,不接受调用方指定;匿名路由(见 noAuthAPI)。
func (h *Handler) DownloadTrainingTemplateSigned(c *gin.Context) {
payload, err := utils.VerifyTrainingTemplateToken(c.Query("token"))
if err != nil {
_ = c.Error(errors.NewBadRequestError("下载链接无效或已过期").WithDetails(err.Error()))
return
}
data, fileName, err := h.svc.TrainingTemplateFile(c.Request.Context(), payload.TenantID, payload.TemplateKey)
if err != nil {
_ = c.Error(err)
return
}
serveTemplateFile(c, data, fileName)
}
// serveTemplateFile 模板文件响应(附件下载,中文文件名 RFC 5987 透传)。
func serveTemplateFile(c *gin.Context, data []byte, fileName string) {
contentType := "application/octet-stream"
if ct, ok := templateContentTypes[templateExtOf(fileName)]; ok {
contentType = ct