需求域: - 需求导入修复内/外培训与外部讲师落库;按模板标题年入库(年-月一致) - 核验确认收窄为「需求归属部门+经理职称角色」,越权提示联系部门经理 - 确认转月计划后自动推送讲师/课长维护;导入后自动推送部门经理核验(站内+企微) 课程域: - 课程管理发布状态字段(迁移000154)+发布/下线;培训中心「和信课程」目录 - 需求讲师改选后回写课程管理;确认同步带出适合人员/课件/试题 - 月计划详情课件/试题更换(上传/知识库选择/题库换绑)回写课程管理, 无关联条目的存量计划自动创建课程条目 模板与表单: - 教育训练需求表:适合人员/内-外培训口径;部门联动课程下拉; 适合人员/讲师按所选课程自动带出;在线提报课程下拉(本部门)自动带出分类/讲师/适合人员 页面与权限: - 培训中心页签重组(和信课程/我的培训/我的考试),移除线上/线下页签 - 数据驾驶舱迁侧栏(职称角色之下);职称角色迁至更多工具配置中心之后 - 配置中心/职称角色对经理开放;页签「职称角色」更名「角色权限」 - 修复年度下拉空白(TDesign options 需对象数组)、月计划列表地点兜底 其他: 培训预览端口修正与 dev:training 脚本;tmp-extract-duckdb 加入 gitignore
237 lines
8.8 KiB
Go
237 lines
8.8 KiB
Go
package training
|
|
|
|
import (
|
|
"fmt"
|
|
"net/http"
|
|
|
|
"academy/internal/errors"
|
|
"academy/internal/filetransport"
|
|
"academy/internal/types"
|
|
"academy/internal/utils"
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// 课程管理(课程资产主数据,tr_course_library,000151)。
|
|
// 字段:课程名称/所属部门(org_depts)/说明/适合人员/分类(配置中心
|
|
// course_category_dict 可配,可自定义)/类型(必修课/选修课)/线上或线下/
|
|
// 讲师/时长/课件。月培训计划的「计划名称」从本表选择。
|
|
// 列表 Viewer 可读(月培训计划下拉同源);维护动作限人事/课长/讲师。
|
|
// ---------------------------------------------------------------------------
|
|
|
|
// 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"`
|
|
Description string `json:"description"`
|
|
SuitableMembers string `json:"suitable_members"`
|
|
Category string `json:"category"`
|
|
Type string `json:"type"`
|
|
Mode string `json:"mode"`
|
|
LecturerID string `json:"lecturer_id"`
|
|
LecturerExternal string `json:"lecturer_external"`
|
|
Hours float64 `json:"hours"`
|
|
MaterialName string `json:"material_name"`
|
|
// ClearFile 移除课件文件(前端「移除」按钮;置 true 强制清空 file_* 三列)。
|
|
ClearFile bool `json:"clear_file"`
|
|
}
|
|
|
|
// toCourseLibrary maps the request body onto the domain model.
|
|
func toCourseLibrary(req saveCourseLibraryRequest) *types.TrainingCourseLibrary {
|
|
return &types.TrainingCourseLibrary{
|
|
ID: req.ID,
|
|
Name: req.Name,
|
|
OwnerDeptID: req.OwnerDeptID,
|
|
Description: req.Description,
|
|
SuitableMembers: req.SuitableMembers,
|
|
Category: req.Category,
|
|
Type: req.Type,
|
|
Mode: req.Mode,
|
|
LecturerID: req.LecturerID,
|
|
LecturerExternal: req.LecturerExternal,
|
|
Hours: req.Hours,
|
|
MaterialName: req.MaterialName,
|
|
ClearFile: req.ClearFile,
|
|
}
|
|
}
|
|
|
|
// ListCourseLibrary GET /training/course-library — 课程管理列表(关键字分页)。
|
|
func (h *Handler) ListCourseLibrary(c *gin.Context) {
|
|
items, total, err := h.svc.ListCourseLibraryItems(c.Request.Context(), callerTenantID(c), listQueryFromRequest(c))
|
|
if err != nil {
|
|
_ = c.Error(err)
|
|
return
|
|
}
|
|
c.JSON(http.StatusOK, gin.H{"success": true, "data": gin.H{"items": items, "total": total}})
|
|
}
|
|
|
|
// SaveCourseLibraryItem POST /training/course-library — 新增/编辑(id 空 = 新增)。
|
|
func (h *Handler) SaveCourseLibraryItem(c *gin.Context) {
|
|
if !h.requireRoles(c, types.TrainingRoleHR, types.TrainingRoleSupervisor, types.TrainingRoleLecturer) {
|
|
return
|
|
}
|
|
var req saveCourseLibraryRequest
|
|
if err := c.ShouldBindJSON(&req); err != nil {
|
|
_ = c.Error(errors.NewBadRequestError("请求参数不合法").WithDetails(err.Error()))
|
|
return
|
|
}
|
|
item, err := h.svc.SaveCourseLibraryItem(c.Request.Context(), callerTenantID(c), toCourseLibrary(req), callerUserID(c))
|
|
if err != nil {
|
|
_ = c.Error(err)
|
|
return
|
|
}
|
|
c.JSON(http.StatusOK, gin.H{"success": true, "data": item})
|
|
}
|
|
|
|
// DeleteCourseLibraryItem DELETE /training/course-library/:id — 删除(人事/课长)。
|
|
func (h *Handler) DeleteCourseLibraryItem(c *gin.Context) {
|
|
if !h.requireRoles(c, types.TrainingRoleHR, types.TrainingRoleSupervisor) {
|
|
return
|
|
}
|
|
if err := h.svc.DeleteCourseLibraryItem(c.Request.Context(), callerTenantID(c), c.Param("id")); err != nil {
|
|
_ = c.Error(err)
|
|
return
|
|
}
|
|
c.JSON(http.StatusOK, gin.H{"success": true})
|
|
}
|
|
|
|
// SetCourseLibraryPublishStatus POST /training/course-library/:id/:action
|
|
// — 课程条目发布/下线(000154;action=publish|offline,人事/课长/讲师)。
|
|
// 发布后课程进入培训中心「和信课程」目录;下线即从目录撤回。
|
|
func (h *Handler) SetCourseLibraryPublishStatus(c *gin.Context) {
|
|
if !h.requireRoles(c, types.TrainingRoleHR, types.TrainingRoleSupervisor, types.TrainingRoleLecturer) {
|
|
return
|
|
}
|
|
status := ""
|
|
switch c.Param("action") {
|
|
case "publish":
|
|
status = "published"
|
|
case "offline":
|
|
status = "offline"
|
|
default:
|
|
_ = c.Error(errors.NewBadRequestError("不支持的操作(仅 publish/offline)"))
|
|
return
|
|
}
|
|
if err := h.svc.SetCourseLibraryPublishStatus(c.Request.Context(), callerTenantID(c), c.Param("id"), status); err != nil {
|
|
_ = c.Error(err)
|
|
return
|
|
}
|
|
item, err := h.svc.GetCourseLibraryItem(c.Request.Context(), callerTenantID(c), c.Param("id"))
|
|
if err != nil {
|
|
_ = c.Error(err)
|
|
return
|
|
}
|
|
c.JSON(http.StatusOK, gin.H{"success": true, "data": item})
|
|
}
|
|
|
|
// ImportCourseLibraryRequest is the body of POST /training/course-library/import
|
|
// (前端解析 Excel 后逐行提交,与需求导入同口径)。
|
|
type ImportCourseLibraryRequest struct {
|
|
Items []saveCourseLibraryRequest `json:"items" binding:"required,min=1"`
|
|
}
|
|
|
|
// ImportCourseLibrary POST /training/course-library/import — 批量导入。
|
|
func (h *Handler) ImportCourseLibrary(c *gin.Context) {
|
|
if !h.requireRoles(c, types.TrainingRoleHR, types.TrainingRoleSupervisor) {
|
|
return
|
|
}
|
|
var req ImportCourseLibraryRequest
|
|
if err := c.ShouldBindJSON(&req); err != nil {
|
|
_ = c.Error(errors.NewBadRequestError("请求参数不合法").WithDetails(err.Error()))
|
|
return
|
|
}
|
|
items := make([]*types.TrainingCourseLibrary, 0, len(req.Items))
|
|
for _, row := range req.Items {
|
|
items = append(items, toCourseLibrary(row))
|
|
}
|
|
imported, err := h.svc.ImportCourseLibraryItems(c.Request.Context(), callerTenantID(c), items, callerUserID(c))
|
|
if err != nil {
|
|
_ = c.Error(err)
|
|
return
|
|
}
|
|
c.JSON(http.StatusOK, gin.H{"success": true, "data": gin.H{"imported": imported}})
|
|
}
|
|
|
|
// ExportCourseLibraryRequest is the body of POST /training/course-library/export
|
|
// (ids 空 = 全量导出;当前筛选由前端传当前列表 id)。
|
|
type ExportCourseLibraryRequest struct {
|
|
IDs []string `json:"ids"`
|
|
}
|
|
|
|
// ExportCourseLibrary POST /training/course-library/export — 课程管理 xlsx 下载。
|
|
func (h *Handler) ExportCourseLibrary(c *gin.Context) {
|
|
if !h.requireRoles(c, types.TrainingRoleHR, types.TrainingRoleSupervisor) {
|
|
return
|
|
}
|
|
var req ExportCourseLibraryRequest
|
|
if err := c.ShouldBindJSON(&req); err != nil {
|
|
_ = c.Error(errors.NewBadRequestError("请求参数不合法").WithDetails(err.Error()))
|
|
return
|
|
}
|
|
filename, data, err := h.svc.ExportCourseLibrary(c.Request.Context(), callerTenantID(c), req.IDs)
|
|
if err != nil {
|
|
_ = c.Error(err)
|
|
return
|
|
}
|
|
c.Header("Content-Disposition", "attachment; filename="+filename)
|
|
c.Data(http.StatusOK, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", data)
|
|
}
|
|
|
|
// UploadCourseLibraryMaterial POST /training/course-library/:id/material —
|
|
// 上传课件原始文件(multipart: file)。
|
|
func (h *Handler) UploadCourseLibraryMaterial(c *gin.Context) {
|
|
if !h.requireRoles(c, types.TrainingRoleHR, types.TrainingRoleSupervisor, types.TrainingRoleLecturer) {
|
|
return
|
|
}
|
|
fh, err := c.FormFile("file")
|
|
if err != nil {
|
|
_ = c.Error(errors.NewBadRequestError("缺少上传文件"))
|
|
return
|
|
}
|
|
if fh.Size > utils.GetMaxFileSizeMB()*1024*1024 {
|
|
_ = c.Error(errors.NewBadRequestError(fmt.Sprintf("文件大小不能超过%dMB", utils.GetMaxFileSizeMB())))
|
|
return
|
|
}
|
|
item, err := h.svc.UploadCourseLibraryMaterial(c.Request.Context(), callerTenantID(c), c.Param("id"), fh, callerUserID(c))
|
|
if err != nil {
|
|
_ = c.Error(err)
|
|
return
|
|
}
|
|
c.JSON(http.StatusOK, gin.H{"success": true, "data": item})
|
|
}
|
|
|
|
// AttachCourseLibraryMaterialFromKb POST /training/course-library/:id/material/from-kb
|
|
// — 从知识库「企业培训(课件)」选择已有文档作为课程课件(body: knowledge_id)。
|
|
func (h *Handler) AttachCourseLibraryMaterialFromKb(c *gin.Context) {
|
|
if !h.requireRoles(c, types.TrainingRoleHR, types.TrainingRoleSupervisor, types.TrainingRoleLecturer) {
|
|
return
|
|
}
|
|
var req struct {
|
|
KnowledgeID string `json:"knowledge_id" binding:"required"`
|
|
}
|
|
if err := c.ShouldBindJSON(&req); err != nil {
|
|
_ = c.Error(errors.NewBadRequestError("请求参数不合法").WithDetails(err.Error()))
|
|
return
|
|
}
|
|
item, err := h.svc.AttachCourseLibraryMaterialFromKnowledge(c.Request.Context(), callerTenantID(c), c.Param("id"), req.KnowledgeID, callerUserID(c))
|
|
if err != nil {
|
|
_ = c.Error(err)
|
|
return
|
|
}
|
|
c.JSON(http.StatusOK, gin.H{"success": true, "data": item})
|
|
}
|
|
|
|
// CourseLibraryMaterialFile GET /training/course-library/:id/material/file —
|
|
// 课件原始文件流(下载/在线预览)。
|
|
func (h *Handler) CourseLibraryMaterialFile(c *gin.Context) {
|
|
rc, fileName, err := h.svc.GetCourseLibraryMaterialFile(c.Request.Context(), callerTenantID(c), c.Param("id"))
|
|
if err != nil {
|
|
_ = c.Error(err)
|
|
return
|
|
}
|
|
if err := filetransport.Serve(c.Writer, c.Request, rc, filetransport.Options{Filename: fileName}); err != nil {
|
|
_ = c.Error(err)
|
|
}
|
|
}
|