From f574831f157274bae67b87a004c7e479fe3d40ee Mon Sep 17 00:00:00 2001 From: GoCo Date: Fri, 25 Jul 2025 16:11:30 +0800 Subject: [PATCH 1/4] =?UTF-8?q?feat:=20=F0=9F=8E=B8=20=E8=AF=BE=E7=A8=8B?= =?UTF-8?q?=E5=88=97=E8=A1=A8&=E8=AF=BE=E7=A8=8B=E8=AF=A6=E6=83=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/api/api/lesson/lesson.go | 16 ++++++++++ server/api/api/lesson/v1/lesson.go | 29 +++++++++++++++++ .../internal/controller/api/lesson/lesson.go | 5 +++ .../controller/api/lesson/lesson_new.go | 15 +++++++++ .../api/lesson/lesson_v1_lesson_detail.go | 27 ++++++++++++++++ .../api/lesson/lesson_v1_lesson_list.go | 31 +++++++++++++++++++ server/internal/router/api.go | 4 ++- 7 files changed, 126 insertions(+), 1 deletion(-) create mode 100644 server/api/api/lesson/lesson.go create mode 100644 server/api/api/lesson/v1/lesson.go create mode 100644 server/internal/controller/api/lesson/lesson.go create mode 100644 server/internal/controller/api/lesson/lesson_new.go create mode 100644 server/internal/controller/api/lesson/lesson_v1_lesson_detail.go create mode 100644 server/internal/controller/api/lesson/lesson_v1_lesson_list.go diff --git a/server/api/api/lesson/lesson.go b/server/api/api/lesson/lesson.go new file mode 100644 index 0000000..5aac3d5 --- /dev/null +++ b/server/api/api/lesson/lesson.go @@ -0,0 +1,16 @@ +// ================================================================================= +// Code generated and maintained by GoFrame CLI tool. DO NOT EDIT. +// ================================================================================= + +package lesson + +import ( + "context" + + "hotgo/api/api/lesson/v1" +) + +type ILessonV1 interface { + LessonList(ctx context.Context, req *v1.LessonListReq) (res *v1.LessonListRes, err error) + LessonDetail(ctx context.Context, req *v1.LessonDetailReq) (res *v1.LessonDetailRes, err error) +} diff --git a/server/api/api/lesson/v1/lesson.go b/server/api/api/lesson/v1/lesson.go new file mode 100644 index 0000000..df5ea1d --- /dev/null +++ b/server/api/api/lesson/v1/lesson.go @@ -0,0 +1,29 @@ +package v1 + +import ( + "hotgo/internal/model/entity" + + "github.com/gogf/gf/v2/frame/g" +) + +// 获取课程列表请求 +type LessonListReq struct { + g.Meta `path:"/lesson/list" method:"get" tags:"课程" summary:"获取课程列表"` +} + +// 获取课程列表响应 +type LessonListRes struct { + List []*entity.Lesson `json:"list" dc:"课程列表"` + Total int `json:"total" dc:"总数"` +} + +// 查看课程详情请求 +type LessonDetailReq struct { + g.Meta `path:"/lesson/detail" method:"get" tags:"课程" summary:"查看课程详情"` + Id int64 `json:"id" v:"required#课程ID必填" dc:"课程ID"` +} + +// 查看课程详情响应 +type LessonDetailRes struct { + Lesson *entity.Lesson `json:"lesson" dc:"课程"` +} diff --git a/server/internal/controller/api/lesson/lesson.go b/server/internal/controller/api/lesson/lesson.go new file mode 100644 index 0000000..6f99448 --- /dev/null +++ b/server/internal/controller/api/lesson/lesson.go @@ -0,0 +1,5 @@ +// ================================================================================= +// This is auto-generated by GoFrame CLI tool only once. Fill this file as you wish. +// ================================================================================= + +package lesson diff --git a/server/internal/controller/api/lesson/lesson_new.go b/server/internal/controller/api/lesson/lesson_new.go new file mode 100644 index 0000000..33a7917 --- /dev/null +++ b/server/internal/controller/api/lesson/lesson_new.go @@ -0,0 +1,15 @@ +// ================================================================================= +// This is auto-generated by GoFrame CLI tool only once. Fill this file as you wish. +// ================================================================================= + +package lesson + +import ( + "hotgo/api/api/lesson" +) + +type ControllerV1 struct{} + +func NewV1() lesson.ILessonV1 { + return &ControllerV1{} +} diff --git a/server/internal/controller/api/lesson/lesson_v1_lesson_detail.go b/server/internal/controller/api/lesson/lesson_v1_lesson_detail.go new file mode 100644 index 0000000..a6fbe79 --- /dev/null +++ b/server/internal/controller/api/lesson/lesson_v1_lesson_detail.go @@ -0,0 +1,27 @@ +package lesson + +import ( + "context" + + "github.com/gogf/gf/v2/errors/gcode" + "github.com/gogf/gf/v2/errors/gerror" + + v1 "hotgo/api/api/lesson/v1" + "hotgo/internal/dao" + "hotgo/internal/model/entity" +) + +func (c *ControllerV1) LessonDetail(ctx context.Context, req *v1.LessonDetailReq) (res *v1.LessonDetailRes, err error) { + lesson := new(entity.Lesson) + err = dao.Lesson.Ctx(ctx).Where("id = ?", req.Id).Scan(lesson) + if err != nil { + return nil, gerror.NewCode(gcode.CodeDbOperationError, "数据库错误") + } + if lesson.Id == 0 { + return nil, gerror.NewCode(gcode.CodeNotFound, "课程不存在") + } + res = &v1.LessonDetailRes{ + Lesson: lesson, + } + return +} diff --git a/server/internal/controller/api/lesson/lesson_v1_lesson_list.go b/server/internal/controller/api/lesson/lesson_v1_lesson_list.go new file mode 100644 index 0000000..ebec340 --- /dev/null +++ b/server/internal/controller/api/lesson/lesson_v1_lesson_list.go @@ -0,0 +1,31 @@ +package lesson + +import ( + "context" + + v1 "hotgo/api/api/lesson/v1" + "hotgo/internal/dao" + "hotgo/internal/model/entity" + + "github.com/gogf/gf/v2/errors/gcode" + "github.com/gogf/gf/v2/errors/gerror" +) + +func (c *ControllerV1) LessonList(ctx context.Context, req *v1.LessonListReq) (res *v1.LessonListRes, err error) { + // 查询课程列表 + var list []*entity.Lesson + err = dao.Lesson.Ctx(ctx).Scan(&list) + if err != nil { + return nil, gerror.NewCode(gcode.CodeDbOperationError, "数据库错误") + } + // 统计总数 + total, err := dao.Lesson.Ctx(ctx).Count() + if err != nil { + return nil, gerror.NewCode(gcode.CodeDbOperationError, "统计总数失败") + } + res = &v1.LessonListRes{ + List: list, + Total: total, + } + return +} diff --git a/server/internal/router/api.go b/server/internal/router/api.go index f01c304..c954785 100644 --- a/server/internal/router/api.go +++ b/server/internal/router/api.go @@ -8,6 +8,7 @@ package router import ( "context" "hotgo/internal/consts" + "hotgo/internal/controller/api/lesson" "hotgo/internal/controller/api/member" "hotgo/internal/controller/api/pay" "hotgo/internal/controller/api/users" @@ -31,7 +32,8 @@ func Api(ctx context.Context, group *ghttp.RouterGroup) { group.Group(simple.RouterPrefix(ctx, consts.AppApi), func(group *ghttp.RouterGroup) { group.Bind( - users.NewV1(), // 前台用户 + users.NewV1(), // 前台用户 + lesson.NewV1(), // 课程 ) }) } -- 2.47.2 From 903e7ba86128aaa91ee9662a0631ccbfca744ff9 Mon Sep 17 00:00:00 2001 From: GoCo Date: Fri, 25 Jul 2025 16:52:32 +0800 Subject: [PATCH 2/4] =?UTF-8?q?feat:=20=F0=9F=8E=B8=20=E8=AF=BE=E7=A8=8B?= =?UTF-8?q?=E7=AB=A0=E8=8A=82=E7=AE=A1=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/admin/lessonsection/lessonsection.go | 59 ++++++++ .../controller/admin/sys/lesson_section.go | 67 ++++++++ .../internal/dao/internal/lesson_section.go | 101 +++++++++++++ server/internal/dao/lesson_section.go | 22 +++ server/internal/logic/sys/lesson.go | 21 +++ server/internal/logic/sys/lesson_section.go | 143 ++++++++++++++++++ server/internal/model/do/lesson_section.go | 27 ++++ server/internal/model/entity/lesson.go | 2 +- .../internal/model/entity/lesson_category.go | 4 +- .../internal/model/entity/lesson_section.go | 25 +++ server/internal/model/entity/users.go | 8 +- .../model/input/sysin/lesson_section.go | 111 ++++++++++++++ .../router/genrouter/lesson_section.go | 13 ++ server/internal/service/sys.go | 28 ++++ .../data/generate/lesson_section_menu.sql | 62 ++++++++ 15 files changed, 686 insertions(+), 7 deletions(-) create mode 100644 server/api/admin/lessonsection/lessonsection.go create mode 100644 server/internal/controller/admin/sys/lesson_section.go create mode 100755 server/internal/dao/internal/lesson_section.go create mode 100755 server/internal/dao/lesson_section.go create mode 100644 server/internal/logic/sys/lesson_section.go create mode 100755 server/internal/model/do/lesson_section.go create mode 100755 server/internal/model/entity/lesson_section.go create mode 100644 server/internal/model/input/sysin/lesson_section.go create mode 100644 server/internal/router/genrouter/lesson_section.go create mode 100644 server/storage/data/generate/lesson_section_menu.sql diff --git a/server/api/admin/lessonsection/lessonsection.go b/server/api/admin/lessonsection/lessonsection.go new file mode 100644 index 0000000..a6e0fe9 --- /dev/null +++ b/server/api/admin/lessonsection/lessonsection.go @@ -0,0 +1,59 @@ +// Package lessonsection +// @Link https://github.com/bufanyun/hotgo +// @Copyright Copyright (c) 2025 HotGo CLI +// @Author Ms <133814250@qq.com> +// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE +// @AutoGenerate Version 2.17.8 +package lessonsection + +import ( + "hotgo/internal/model/input/form" + "hotgo/internal/model/input/sysin" + + "github.com/gogf/gf/v2/frame/g" +) + +// ListReq 查询课程章节列表 +type ListReq struct { + g.Meta `path:"/lessonSection/list" method:"get" tags:"课程章节" summary:"获取课程章节列表"` + sysin.LessonSectionListInp +} + +type ListRes struct { + form.PageRes + List []*sysin.LessonSectionListModel `json:"list" dc:"数据列表"` +} + +// ExportReq 导出课程章节列表 +type ExportReq struct { + g.Meta `path:"/lessonSection/export" method:"get" tags:"课程章节" summary:"导出课程章节列表"` + sysin.LessonSectionListInp +} + +type ExportRes struct{} + +// ViewReq 获取课程章节指定信息 +type ViewReq struct { + g.Meta `path:"/lessonSection/view" method:"get" tags:"课程章节" summary:"获取课程章节指定信息"` + sysin.LessonSectionViewInp +} + +type ViewRes struct { + *sysin.LessonSectionViewModel +} + +// EditReq 修改/新增课程章节 +type EditReq struct { + g.Meta `path:"/lessonSection/edit" method:"post" tags:"课程章节" summary:"修改/新增课程章节"` + sysin.LessonSectionEditInp +} + +type EditRes struct{} + +// DeleteReq 删除课程章节 +type DeleteReq struct { + g.Meta `path:"/lessonSection/delete" method:"post" tags:"课程章节" summary:"删除课程章节"` + sysin.LessonSectionDeleteInp +} + +type DeleteRes struct{} \ No newline at end of file diff --git a/server/internal/controller/admin/sys/lesson_section.go b/server/internal/controller/admin/sys/lesson_section.go new file mode 100644 index 0000000..110dc08 --- /dev/null +++ b/server/internal/controller/admin/sys/lesson_section.go @@ -0,0 +1,67 @@ +// Package sys +// @Link https://github.com/bufanyun/hotgo +// @Copyright Copyright (c) 2025 HotGo CLI +// @Author Ms <133814250@qq.com> +// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE +// @AutoGenerate Version 2.17.8 +package sys + +import ( + "context" + "hotgo/api/admin/lessonsection" + "hotgo/internal/model/input/sysin" + "hotgo/internal/service" +) + +var ( + LessonSection = cLessonSection{} +) + +type cLessonSection struct{} + +// List 查看课程章节列表 +func (c *cLessonSection) List(ctx context.Context, req *lessonsection.ListReq) (res *lessonsection.ListRes, err error) { + list, totalCount, err := service.SysLessonSection().List(ctx, &req.LessonSectionListInp) + if err != nil { + return + } + + if list == nil { + list = []*sysin.LessonSectionListModel{} + } + + res = new(lessonsection.ListRes) + res.List = list + res.PageRes.Pack(req, totalCount) + return +} + +// Export 导出课程章节列表 +func (c *cLessonSection) Export(ctx context.Context, req *lessonsection.ExportReq) (res *lessonsection.ExportRes, err error) { + err = service.SysLessonSection().Export(ctx, &req.LessonSectionListInp) + return +} + +// Edit 更新课程章节 +func (c *cLessonSection) Edit(ctx context.Context, req *lessonsection.EditReq) (res *lessonsection.EditRes, err error) { + err = service.SysLessonSection().Edit(ctx, &req.LessonSectionEditInp) + return +} + +// View 获取指定课程章节信息 +func (c *cLessonSection) View(ctx context.Context, req *lessonsection.ViewReq) (res *lessonsection.ViewRes, err error) { + data, err := service.SysLessonSection().View(ctx, &req.LessonSectionViewInp) + if err != nil { + return + } + + res = new(lessonsection.ViewRes) + res.LessonSectionViewModel = data + return +} + +// Delete 删除课程章节 +func (c *cLessonSection) Delete(ctx context.Context, req *lessonsection.DeleteReq) (res *lessonsection.DeleteRes, err error) { + err = service.SysLessonSection().Delete(ctx, &req.LessonSectionDeleteInp) + return +} \ No newline at end of file diff --git a/server/internal/dao/internal/lesson_section.go b/server/internal/dao/internal/lesson_section.go new file mode 100755 index 0000000..992af2f --- /dev/null +++ b/server/internal/dao/internal/lesson_section.go @@ -0,0 +1,101 @@ +// ========================================================================== +// Code generated and maintained by GoFrame CLI tool. DO NOT EDIT. +// ========================================================================== + +package internal + +import ( + "context" + + "github.com/gogf/gf/v2/database/gdb" + "github.com/gogf/gf/v2/frame/g" +) + +// LessonSectionDao is the data access object for the table hg_lesson_section. +type LessonSectionDao struct { + table string // table is the underlying table name of the DAO. + group string // group is the database configuration group name of the current DAO. + columns LessonSectionColumns // columns contains all the column names of Table for convenient usage. + handlers []gdb.ModelHandler // handlers for customized model modification. +} + +// LessonSectionColumns defines and stores column names for the table hg_lesson_section. +type LessonSectionColumns struct { + Id string // id + LessonId string // 课程id + VideoUrl string // 视频url + Name string // 章节名 + SortOrder string // 排序号 + ParentId string // 父章节id + Level string // 章节层级;1=章,2=节 + Revision string // 乐观锁 + CreatedBy string // 创建人 + CreatedTime string // 创建时间 + UpdatedBy string // 更新人 + UpdatedTime string // 更新时间 +} + +// lessonSectionColumns holds the columns for the table hg_lesson_section. +var lessonSectionColumns = LessonSectionColumns{ + Id: "id", + LessonId: "lesson_id", + VideoUrl: "video_url", + Name: "name", + SortOrder: "sort_order", + ParentId: "parent_id", + Level: "level", + Revision: "revision", + CreatedBy: "created_by", + CreatedTime: "created_time", + UpdatedBy: "updated_by", + UpdatedTime: "updated_time", +} + +// NewLessonSectionDao creates and returns a new DAO object for table data access. +func NewLessonSectionDao(handlers ...gdb.ModelHandler) *LessonSectionDao { + return &LessonSectionDao{ + group: "default", + table: "hg_lesson_section", + columns: lessonSectionColumns, + handlers: handlers, + } +} + +// DB retrieves and returns the underlying raw database management object of the current DAO. +func (dao *LessonSectionDao) DB() gdb.DB { + return g.DB(dao.group) +} + +// Table returns the table name of the current DAO. +func (dao *LessonSectionDao) Table() string { + return dao.table +} + +// Columns returns all column names of the current DAO. +func (dao *LessonSectionDao) Columns() LessonSectionColumns { + return dao.columns +} + +// Group returns the database configuration group name of the current DAO. +func (dao *LessonSectionDao) Group() string { + return dao.group +} + +// Ctx creates and returns a Model for the current DAO. It automatically sets the context for the current operation. +func (dao *LessonSectionDao) Ctx(ctx context.Context) *gdb.Model { + model := dao.DB().Model(dao.table) + for _, handler := range dao.handlers { + model = handler(model) + } + return model.Safe().Ctx(ctx) +} + +// Transaction wraps the transaction logic using function f. +// It rolls back the transaction and returns the error if function f returns a non-nil error. +// It commits the transaction and returns nil if function f returns nil. +// +// Note: Do not commit or roll back the transaction in function f, +// as it is automatically handled by this function. +func (dao *LessonSectionDao) Transaction(ctx context.Context, f func(ctx context.Context, tx gdb.TX) error) (err error) { + return dao.Ctx(ctx).Transaction(ctx, f) +} diff --git a/server/internal/dao/lesson_section.go b/server/internal/dao/lesson_section.go new file mode 100755 index 0000000..71606e9 --- /dev/null +++ b/server/internal/dao/lesson_section.go @@ -0,0 +1,22 @@ +// ================================================================================= +// This file is auto-generated by the GoFrame CLI tool. You may modify it as needed. +// ================================================================================= + +package dao + +import ( + "hotgo/internal/dao/internal" +) + +// lessonSectionDao is the data access object for the table hg_lesson_section. +// You can define custom methods on it to extend its functionality as needed. +type lessonSectionDao struct { + *internal.LessonSectionDao +} + +var ( + // LessonSection is a globally accessible object for table hg_lesson_section operations. + LessonSection = lessonSectionDao{internal.NewLessonSectionDao()} +) + +// Add your custom methods and functionality below. diff --git a/server/internal/logic/sys/lesson.go b/server/internal/logic/sys/lesson.go index 57e796a..791e460 100644 --- a/server/internal/logic/sys/lesson.go +++ b/server/internal/logic/sys/lesson.go @@ -12,6 +12,7 @@ import ( "hotgo/internal/dao" "hotgo/internal/library/contexts" "hotgo/internal/library/hgorm/handler" + "hotgo/internal/model/entity" "hotgo/internal/model/input/form" "hotgo/internal/model/input/sysin" "hotgo/internal/service" @@ -23,6 +24,9 @@ import ( "github.com/gogf/gf/v2/frame/g" "github.com/gogf/gf/v2/os/gctx" "github.com/gogf/gf/v2/util/gconv" + + "hotgo/internal/library/dict" + "hotgo/internal/model" ) type sSysLesson struct{} @@ -33,6 +37,7 @@ func NewSysLesson() *sSysLesson { func init() { service.RegisterSysLesson(NewSysLesson()) + dict.RegisterFunc("lessonOption", "课程管理选项", service.SysLesson().Option) } // Model 课程管理ORM模型 @@ -141,4 +146,20 @@ func (s *sSysLesson) View(ctx context.Context, in *sysin.LessonViewInp) (res *sy return } return +} + +// Option 获取课程管理选项 +func (s *sSysLesson) Option(ctx context.Context) (opts []*model.Option, err error) { + var models []*entity.Lesson + if err = s.Model(ctx).Fields(dao.Lesson.Columns().Id, dao.Lesson.Columns().Name). + OrderDesc(dao.Lesson.Columns().Id).Scan(&models); err != nil { + err = gerror.Wrap(err, "获取课程管理选项失败!") + return + } + + opts = make([]*model.Option, len(models)) + for k, v := range models { + opts[k] = dict.GenHashOption(v.Id, gconv.String(v.Name)) + } + return } \ No newline at end of file diff --git a/server/internal/logic/sys/lesson_section.go b/server/internal/logic/sys/lesson_section.go new file mode 100644 index 0000000..86b332b --- /dev/null +++ b/server/internal/logic/sys/lesson_section.go @@ -0,0 +1,143 @@ +// Package sys +// @Link https://github.com/bufanyun/hotgo +// @Copyright Copyright (c) 2025 HotGo CLI +// @Author Ms <133814250@qq.com> +// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE +// @AutoGenerate Version 2.17.8 +package sys + +import ( + "context" + "fmt" + "hotgo/internal/dao" + "hotgo/internal/library/contexts" + "hotgo/internal/library/hgorm/handler" + "hotgo/internal/library/hgorm/hook" + "hotgo/internal/model/input/form" + "hotgo/internal/model/input/sysin" + "hotgo/internal/service" + "hotgo/utility/convert" + "hotgo/utility/excel" + + "github.com/gogf/gf/v2/database/gdb" + "github.com/gogf/gf/v2/errors/gerror" + "github.com/gogf/gf/v2/frame/g" + "github.com/gogf/gf/v2/os/gctx" + "github.com/gogf/gf/v2/util/gconv" +) + +type sSysLessonSection struct{} + +func NewSysLessonSection() *sSysLessonSection { + return &sSysLessonSection{} +} + +func init() { + service.RegisterSysLessonSection(NewSysLessonSection()) +} + +// Model 课程章节ORM模型 +func (s *sSysLessonSection) Model(ctx context.Context, option ...*handler.Option) *gdb.Model { + return handler.Model(dao.LessonSection.Ctx(ctx), option...) +} + +// List 获取课程章节列表 +func (s *sSysLessonSection) List(ctx context.Context, in *sysin.LessonSectionListInp) (list []*sysin.LessonSectionListModel, totalCount int, err error) { + mod := s.Model(ctx) + + // 字段过滤 + mod = mod.Fields(sysin.LessonSectionListModel{}) + + // 查询id + if in.Id > 0 { + mod = mod.Where(dao.LessonSection.Columns().Id, in.Id) + } + + // 分页 + mod = mod.Page(in.Page, in.PerPage) + + // 排序 + mod = mod.OrderDesc(dao.LessonSection.Columns().Id) + + // 操作人摘要信息 + mod = mod.Hook(hook.MemberSummary) + + // 查询数据 + if err = mod.ScanAndCount(&list, &totalCount, false); err != nil { + err = gerror.Wrap(err, "获取课程章节列表失败,请稍后重试!") + return + } + return +} + +// Export 导出课程章节 +func (s *sSysLessonSection) Export(ctx context.Context, in *sysin.LessonSectionListInp) (err error) { + list, totalCount, err := s.List(ctx, in) + if err != nil { + return + } + + // 字段的排序是依据tags的字段顺序,如果你不想使用默认的排序方式,可以直接定义 tags = []string{"字段名称", "字段名称2", ...} + tags, err := convert.GetEntityDescTags(sysin.LessonSectionExportModel{}) + if err != nil { + return + } + + var ( + fileName = "导出课程章节-" + gctx.CtxId(ctx) + sheetName = fmt.Sprintf("索引条件共%v行,共%v页,当前导出是第%v页,本页共%v行", totalCount, form.CalPageCount(totalCount, in.PerPage), in.Page, len(list)) + exports []sysin.LessonSectionExportModel + ) + + if err = gconv.Scan(list, &exports); err != nil { + return + } + + err = excel.ExportByStructs(ctx, tags, exports, fileName, sheetName) + return +} + +// Edit 修改/新增课程章节 +func (s *sSysLessonSection) Edit(ctx context.Context, in *sysin.LessonSectionEditInp) (err error) { + return g.DB().Transaction(ctx, func(ctx context.Context, tx gdb.TX) (err error) { + + // 修改 + if in.Id > 0 { + in.UpdatedBy = contexts.GetUserId(ctx) + if _, err = s.Model(ctx). + Fields(sysin.LessonSectionUpdateFields{}). + WherePri(in.Id).Data(in).Update(); err != nil { + err = gerror.Wrap(err, "修改课程章节失败,请稍后重试!") + } + return + } + + // 新增 + in.CreatedBy = contexts.GetUserId(ctx) + if _, err = s.Model(ctx, &handler.Option{FilterAuth: false}). + Fields(sysin.LessonSectionInsertFields{}). + Data(in).OmitEmptyData().Insert(); err != nil { + err = gerror.Wrap(err, "新增课程章节失败,请稍后重试!") + } + return + }) +} + +// Delete 删除课程章节 +func (s *sSysLessonSection) Delete(ctx context.Context, in *sysin.LessonSectionDeleteInp) (err error) { + + if _, err = s.Model(ctx).WherePri(in.Id).Unscoped().Delete(); err != nil { + err = gerror.Wrap(err, "删除课程章节失败,请稍后重试!") + return + } + return +} + +// View 获取课程章节指定信息 +func (s *sSysLessonSection) View(ctx context.Context, in *sysin.LessonSectionViewInp) (res *sysin.LessonSectionViewModel, err error) { + if err = s.Model(ctx).WherePri(in.Id).Hook(hook.MemberSummary).Scan(&res); err != nil { + err = gerror.Wrap(err, "获取课程章节信息,请稍后重试!") + return + } + return +} \ No newline at end of file diff --git a/server/internal/model/do/lesson_section.go b/server/internal/model/do/lesson_section.go new file mode 100755 index 0000000..65405ce --- /dev/null +++ b/server/internal/model/do/lesson_section.go @@ -0,0 +1,27 @@ +// ================================================================================= +// Code generated and maintained by GoFrame CLI tool. DO NOT EDIT. +// ================================================================================= + +package do + +import ( + "github.com/gogf/gf/v2/frame/g" + "github.com/gogf/gf/v2/os/gtime" +) + +// LessonSection is the golang structure of table hg_lesson_section for DAO operations like Where/Data. +type LessonSection struct { + g.Meta `orm:"table:hg_lesson_section, do:true"` + Id interface{} // id + LessonId interface{} // 课程id + VideoUrl interface{} // 视频url + Name interface{} // 章节名 + SortOrder interface{} // 排序号 + ParentId interface{} // 父章节id + Level interface{} // 章节层级;1=章,2=节 + Revision interface{} // 乐观锁 + CreatedBy interface{} // 创建人 + CreatedTime *gtime.Time // 创建时间 + UpdatedBy interface{} // 更新人 + UpdatedTime *gtime.Time // 更新时间 +} diff --git a/server/internal/model/entity/lesson.go b/server/internal/model/entity/lesson.go index 52abc61..f7aa139 100755 --- a/server/internal/model/entity/lesson.go +++ b/server/internal/model/entity/lesson.go @@ -24,7 +24,7 @@ type Lesson struct { Arrangement string `json:"arrangement" orm:"arrangement" description:"学时安排"` StartTime *gtime.Time `json:"startTime" orm:"start_time" description:"开课时间"` EndTime *gtime.Time `json:"endTime" orm:"end_time" description:"结课时间"` - Revision int64 `json:"revision" orm:"revision" description:"乐观锁"` + Revision int `json:"revision" orm:"revision" description:"乐观锁"` Question string `json:"question" orm:"question" description:"常见问题"` CreatedBy int64 `json:"createdBy" orm:"created_by" description:"创建人"` CreatedTime *gtime.Time `json:"createdTime" orm:"created_time" description:"创建时间"` diff --git a/server/internal/model/entity/lesson_category.go b/server/internal/model/entity/lesson_category.go index 40a1af1..35ea967 100755 --- a/server/internal/model/entity/lesson_category.go +++ b/server/internal/model/entity/lesson_category.go @@ -12,8 +12,8 @@ import ( type LessonCategory struct { Id int64 `json:"id" orm:"id" description:"id"` Name string `json:"name" orm:"name" description:"分类名"` - SortOrder int64 `json:"sortOrder" orm:"sort_order" description:"排序"` - Revision int64 `json:"revision" orm:"revision" description:"乐观锁"` + SortOrder int `json:"sortOrder" orm:"sort_order" description:"排序"` + Revision int `json:"revision" orm:"revision" description:"乐观锁"` CreatedBy int64 `json:"createdBy" orm:"created_by" description:"创建人"` CreatedTime *gtime.Time `json:"createdTime" orm:"created_time" description:"创建时间"` UpdatedBy int64 `json:"updatedBy" orm:"updated_by" description:"更新人"` diff --git a/server/internal/model/entity/lesson_section.go b/server/internal/model/entity/lesson_section.go new file mode 100755 index 0000000..b02f97f --- /dev/null +++ b/server/internal/model/entity/lesson_section.go @@ -0,0 +1,25 @@ +// ================================================================================= +// Code generated and maintained by GoFrame CLI tool. DO NOT EDIT. +// ================================================================================= + +package entity + +import ( + "github.com/gogf/gf/v2/os/gtime" +) + +// LessonSection is the golang structure for table lesson_section. +type LessonSection struct { + Id int64 `json:"id" orm:"id" description:"id"` + LessonId int64 `json:"lessonId" orm:"lesson_id" description:"课程id"` + VideoUrl string `json:"videoUrl" orm:"video_url" description:"视频url"` + Name string `json:"name" orm:"name" description:"章节名"` + SortOrder int `json:"sortOrder" orm:"sort_order" description:"排序号"` + ParentId int `json:"parentId" orm:"parent_id" description:"父章节id"` + Level int `json:"level" orm:"level" description:"章节层级;1=章,2=节"` + Revision int `json:"revision" orm:"revision" description:"乐观锁"` + CreatedBy int64 `json:"createdBy" orm:"created_by" description:"创建人"` + CreatedTime *gtime.Time `json:"createdTime" orm:"created_time" description:"创建时间"` + UpdatedBy int64 `json:"updatedBy" orm:"updated_by" description:"更新人"` + UpdatedTime *gtime.Time `json:"updatedTime" orm:"updated_time" description:"更新时间"` +} diff --git a/server/internal/model/entity/users.go b/server/internal/model/entity/users.go index e8f2a75..101209a 100755 --- a/server/internal/model/entity/users.go +++ b/server/internal/model/entity/users.go @@ -19,15 +19,15 @@ type Users struct { Password string `json:"password" orm:"password" description:"密码"` Salt string `json:"salt" orm:"salt" description:"密码盐"` Realname string `json:"realname" orm:"realname" description:"真实姓名"` - Gender int64 `json:"gender" orm:"gender" description:"性别"` + Gender int `json:"gender" orm:"gender" description:"性别"` Birthday string `json:"birthday" orm:"birthday" description:"生日"` School string `json:"school" orm:"school" description:"学校"` Grade string `json:"grade" orm:"grade" description:"学历"` Major string `json:"major" orm:"major" description:"专业"` - Status int64 `json:"status" orm:"status" description:"用户状态"` + Status int `json:"status" orm:"status" description:"用户状态"` VerificationToken string `json:"verificationToken" orm:"verification_token" description:"邮箱验证令牌"` - EmailVerified int64 `json:"emailVerified" orm:"email_verified" description:"邮箱验证状态"` + EmailVerified int `json:"emailVerified" orm:"email_verified" description:"邮箱验证状态"` CreatedAt *gtime.Time `json:"createdAt" orm:"created_at" description:"注册时间"` LastLogin *gtime.Time `json:"lastLogin" orm:"last_login" description:"最后登录时间"` - LoginCount int64 `json:"loginCount" orm:"login_count" description:"累计登录次数"` + LoginCount int `json:"loginCount" orm:"login_count" description:"累计登录次数"` } diff --git a/server/internal/model/input/sysin/lesson_section.go b/server/internal/model/input/sysin/lesson_section.go new file mode 100644 index 0000000..2e96581 --- /dev/null +++ b/server/internal/model/input/sysin/lesson_section.go @@ -0,0 +1,111 @@ +// Package sysin +// @Link https://github.com/bufanyun/hotgo +// @Copyright Copyright (c) 2025 HotGo CLI +// @Author Ms <133814250@qq.com> +// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE +// @AutoGenerate Version 2.17.8 +package sysin + +import ( + "context" + "hotgo/internal/library/hgorm/hook" + "hotgo/internal/model/entity" + "hotgo/internal/model/input/form" +) + +// LessonSectionUpdateFields 修改课程章节字段过滤 +type LessonSectionUpdateFields struct { + LessonId int64 `json:"lessonId" dc:"课程id"` + VideoUrl string `json:"videoUrl" dc:"视频url"` + Name string `json:"name" dc:"章节名"` + SortOrder int `json:"sortOrder" dc:"排序号"` + ParentId int `json:"parentId" dc:"父章节id"` + Level int `json:"level" dc:"章节层级"` + UpdatedBy int64 `json:"updatedBy" dc:"更新人"` +} + +// LessonSectionInsertFields 新增课程章节字段过滤 +type LessonSectionInsertFields struct { + LessonId int64 `json:"lessonId" dc:"课程id"` + VideoUrl string `json:"videoUrl" dc:"视频url"` + Name string `json:"name" dc:"章节名"` + SortOrder int `json:"sortOrder" dc:"排序号"` + ParentId int `json:"parentId" dc:"父章节id"` + Level int `json:"level" dc:"章节层级"` + CreatedBy int64 `json:"createdBy" dc:"创建人"` +} + +// LessonSectionEditInp 修改/新增课程章节 +type LessonSectionEditInp struct { + entity.LessonSection +} + +func (in *LessonSectionEditInp) Filter(ctx context.Context) (err error) { + + return +} + +type LessonSectionEditModel struct{} + +// LessonSectionDeleteInp 删除课程章节 +type LessonSectionDeleteInp struct { + Id interface{} `json:"id" v:"required#id不能为空" dc:"id"` +} + +func (in *LessonSectionDeleteInp) Filter(ctx context.Context) (err error) { + return +} + +type LessonSectionDeleteModel struct{} + +// LessonSectionViewInp 获取指定课程章节信息 +type LessonSectionViewInp struct { + Id int64 `json:"id" v:"required#id不能为空" dc:"id"` +} + +func (in *LessonSectionViewInp) Filter(ctx context.Context) (err error) { + return +} + +type LessonSectionViewModel struct { + entity.LessonSection + CreatedBySumma *hook.MemberSumma `json:"createdBySumma" dc:"创建人摘要信息"` + UpdatedBySumma *hook.MemberSumma `json:"updatedBySumma" dc:"更新人摘要信息"` +} + +// LessonSectionListInp 获取课程章节列表 +type LessonSectionListInp struct { + form.PageReq + Id int64 `json:"id" dc:"id"` +} + +func (in *LessonSectionListInp) Filter(ctx context.Context) (err error) { + return +} + +type LessonSectionListModel struct { + Id int64 `json:"id" dc:"id"` + LessonId int64 `json:"lessonId" dc:"课程id"` + VideoUrl string `json:"videoUrl" dc:"视频url"` + Name string `json:"name" dc:"章节名"` + SortOrder int `json:"sortOrder" dc:"排序号"` + ParentId int `json:"parentId" dc:"父章节id"` + Level int `json:"level" dc:"章节层级"` + CreatedBy int64 `json:"createdBy" dc:"创建人"` + CreatedBySumma *hook.MemberSumma `json:"createdBySumma" dc:"创建人摘要信息"` + UpdatedBy int64 `json:"updatedBy" dc:"更新人"` + UpdatedBySumma *hook.MemberSumma `json:"updatedBySumma" dc:"更新人摘要信息"` +} + +// LessonSectionExportModel 导出课程章节 +type LessonSectionExportModel struct { + Id int64 `json:"id" dc:"id"` + LessonId int64 `json:"lessonId" dc:"课程id"` + VideoUrl string `json:"videoUrl" dc:"视频url"` + Name string `json:"name" dc:"章节名"` + SortOrder int `json:"sortOrder" dc:"排序号"` + ParentId int `json:"parentId" dc:"父章节id"` + Level int `json:"level" dc:"章节层级"` + CreatedBy int64 `json:"createdBy" dc:"创建人"` + UpdatedBy int64 `json:"updatedBy" dc:"更新人"` +} \ No newline at end of file diff --git a/server/internal/router/genrouter/lesson_section.go b/server/internal/router/genrouter/lesson_section.go new file mode 100644 index 0000000..586cf79 --- /dev/null +++ b/server/internal/router/genrouter/lesson_section.go @@ -0,0 +1,13 @@ +// Package genrouter +// @Link https://github.com/bufanyun/hotgo +// @Copyright Copyright (c) 2025 HotGo CLI +// @Author Ms <133814250@qq.com> +// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE +// @AutoGenerate Version 2.17.8 +package genrouter + +import "hotgo/internal/controller/admin/sys" + +func init() { + LoginRequiredRouter = append(LoginRequiredRouter, sys.LessonSection) // 课程章节 +} \ No newline at end of file diff --git a/server/internal/service/sys.go b/server/internal/service/sys.go index 55da94a..1b85f93 100644 --- a/server/internal/service/sys.go +++ b/server/internal/service/sys.go @@ -260,6 +260,8 @@ type ( Delete(ctx context.Context, in *sysin.LessonDeleteInp) (err error) // View 获取课程管理指定信息 View(ctx context.Context, in *sysin.LessonViewInp) (res *sysin.LessonViewModel, err error) + // Option 获取课程管理选项 + Option(ctx context.Context) (opts []*model.Option, err error) } ISysLessonCategory interface { // Model 课程分类ORM模型 @@ -277,6 +279,20 @@ type ( // Option 获取课程分类选项 Option(ctx context.Context) (opts []*model.Option, err error) } + ISysLessonSection interface { + // Model 课程章节ORM模型 + Model(ctx context.Context, option ...*handler.Option) *gdb.Model + // List 获取课程章节列表 + List(ctx context.Context, in *sysin.LessonSectionListInp) (list []*sysin.LessonSectionListModel, totalCount int, err error) + // Export 导出课程章节 + Export(ctx context.Context, in *sysin.LessonSectionListInp) (err error) + // Edit 修改/新增课程章节 + Edit(ctx context.Context, in *sysin.LessonSectionEditInp) (err error) + // Delete 删除课程章节 + Delete(ctx context.Context, in *sysin.LessonSectionDeleteInp) (err error) + // View 获取课程章节指定信息 + View(ctx context.Context, in *sysin.LessonSectionViewInp) (res *sysin.LessonSectionViewModel, err error) + } ISysLog interface { // Model 请求日志Orm模型 Model(ctx context.Context, option ...*handler.Option) *gdb.Model @@ -466,6 +482,7 @@ var ( localSysGenCodes ISysGenCodes localSysLesson ISysLesson localSysLessonCategory ISysLessonCategory + localSysLessonSection ISysLessonSection localSysLog ISysLog localSysLoginLog ISysLoginLog localSysNormalTreeDemo ISysNormalTreeDemo @@ -632,6 +649,17 @@ func RegisterSysLessonCategory(i ISysLessonCategory) { localSysLessonCategory = i } +func SysLessonSection() ISysLessonSection { + if localSysLessonSection == nil { + panic("implement not found for interface ISysLessonSection, forgot register?") + } + return localSysLessonSection +} + +func RegisterSysLessonSection(i ISysLessonSection) { + localSysLessonSection = i +} + func SysLog() ISysLog { if localSysLog == nil { panic("implement not found for interface ISysLog, forgot register?") diff --git a/server/storage/data/generate/lesson_section_menu.sql b/server/storage/data/generate/lesson_section_menu.sql new file mode 100644 index 0000000..56015ce --- /dev/null +++ b/server/storage/data/generate/lesson_section_menu.sql @@ -0,0 +1,62 @@ +-- hotgo自动生成菜单权限SQL 通常情况下只在首次生成代码时自动执行一次 +-- 如需再次执行请先手动删除生成的菜单权限和SQL文件:/Users/guochen/Documents/projects/g031/hotgo/server/storage/data/generate/lesson_section_menu.sql +-- Version: 2.17.8 +-- Date: 2025-07-25 16:32:05 +-- Link https://github.com/bufanyun/hotgo + +SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO"; +SET AUTOCOMMIT = 0; +START TRANSACTION; + +-- +-- 数据库: `hotgo` +-- + +-- -------------------------------------------------------- + +-- +-- 插入表中的数据 `hg_admin_menu` +-- + + +SET @now := now(); + + +-- 菜单目录 +INSERT INTO `hg_admin_menu` (`id`, `pid`, `title`, `name`, `path`, `icon`, `type`, `redirect`, `permissions`, `permission_name`, `component`, `always_show`, `active_menu`, `is_root`, `is_frame`, `frame_src`, `keep_alive`, `hidden`, `affix`, `level`, `tree`, `sort`, `remark`, `status`, `created_at`, `updated_at`) VALUES (NULL, '0', '课程章节', 'lessonSection', '/lessonSection', 'MenuOutlined', '1', '/lessonSection/index', '', '', 'LAYOUT', '1', '', '0', '0', '', '0', '0', '0', '1', '', '0', '', '1', @now, @now); + + +SET @dirId = LAST_INSERT_ID(); + + +-- 菜单页面 +-- 列表 +INSERT INTO `hg_admin_menu` (`id`, `pid`, `title`, `name`, `path`, `icon`, `type`, `redirect`, `permissions`, `permission_name`, `component`, `always_show`, `active_menu`, `is_root`, `is_frame`, `frame_src`, `keep_alive`, `hidden`, `affix`, `level`, `tree`, `sort`, `remark`, `status`, `created_at`, `updated_at`) VALUES (NULL, @dirId, '课程章节列表', 'lessonSectionIndex', 'index', '', '2', '', '/lessonSection/list', '', '/lessonSection/index', '1', 'lessonSection', '0', '0', '', '0', '1', '0', '2', CONCAT('tr_', @dirId,' '), '10', '', '1', @now, @now); + + +SET @listId = LAST_INSERT_ID(); + +-- 详情 +INSERT INTO `hg_admin_menu` (`id`, `pid`, `title`, `name`, `path`, `icon`, `type`, `redirect`, `permissions`, `permission_name`, `component`, `always_show`, `active_menu`, `is_root`, `is_frame`, `frame_src`, `keep_alive`, `hidden`, `affix`, `level`, `tree`, `sort`, `remark`, `status`, `created_at`, `updated_at`) VALUES (NULL, @listId, '课程章节详情', 'lessonSectionView', '', '', '3', '', '/lessonSection/view', '', '', '1', '', '0', '0', '', '0', '1', '0', '3', CONCAT('tr_', @dirId, ' tr_', @listId,' '), '10', '', '1', @now, @now); + + +-- 菜单按钮 + +-- 编辑 +INSERT INTO `hg_admin_menu` (`id`, `pid`, `title`, `name`, `path`, `icon`, `type`, `redirect`, `permissions`, `permission_name`, `component`, `always_show`, `active_menu`, `is_root`, `is_frame`, `frame_src`, `keep_alive`, `hidden`, `affix`, `level`, `tree`, `sort`, `remark`, `status`, `created_at`, `updated_at`) VALUES (NULL, @listId, '编辑/新增课程章节', 'lessonSectionEdit', '', '', '3', '', '/lessonSection/edit', '', '', '1', '', '0', '0', '', '0', '1', '0', '3', CONCAT('tr_', @dirId, ' tr_', @listId,' '), '20', '', '1', @now, @now); + + +SET @editId = LAST_INSERT_ID(); + + +-- 删除 +INSERT INTO `hg_admin_menu` (`id`, `pid`, `title`, `name`, `path`, `icon`, `type`, `redirect`, `permissions`, `permission_name`, `component`, `always_show`, `active_menu`, `is_root`, `is_frame`, `frame_src`, `keep_alive`, `hidden`, `affix`, `level`, `tree`, `sort`, `remark`, `status`, `created_at`, `updated_at`) VALUES (NULL, @listId, '删除课程章节', 'lessonSectionDelete', '', '', '3', '', '/lessonSection/delete', '', '', '1', '', '0', '0', '', '0', '0', '0', '3', CONCAT('tr_', @dirId, ' tr_', @listId,' '), '40', '', '1', @now, @now); + + + + +-- 导出 +INSERT INTO `hg_admin_menu` (`id`, `pid`, `title`, `name`, `path`, `icon`, `type`, `redirect`, `permissions`, `permission_name`, `component`, `always_show`, `active_menu`, `is_root`, `is_frame`, `frame_src`, `keep_alive`, `hidden`, `affix`, `level`, `tree`, `sort`, `remark`, `status`, `created_at`, `updated_at`) VALUES (NULL, @listId, '导出课程章节', 'lessonSectionExport', '', '', '3', '', '/lessonSection/export', '', '', '1', '', '0', '0', '', '0', '0', '0', '3', CONCAT('tr_', @dirId, ' tr_', @listId,' '), '70', '', '1', @now, @now); + + +COMMIT; \ No newline at end of file -- 2.47.2 From 6771d3298ff452f0410fd91e101e5828092e5127 Mon Sep 17 00:00:00 2001 From: GoCo Date: Fri, 25 Jul 2025 17:02:39 +0800 Subject: [PATCH 3/4] =?UTF-8?q?feat:=20=F0=9F=8E=B8=20=E8=AF=BE=E7=A8=8B?= =?UTF-8?q?=E7=AB=A0=E8=8A=82=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/api/api/lesson/lesson.go | 2 ++ server/api/api/lesson/v1/lesson.go | 25 +++++++++++++++- .../lesson/lesson_v1_lesson_section_detail.go | 28 +++++++++++++++++ .../lesson/lesson_v1_lesson_section_list.go | 30 +++++++++++++++++++ 4 files changed, 84 insertions(+), 1 deletion(-) create mode 100644 server/internal/controller/api/lesson/lesson_v1_lesson_section_detail.go create mode 100644 server/internal/controller/api/lesson/lesson_v1_lesson_section_list.go diff --git a/server/api/api/lesson/lesson.go b/server/api/api/lesson/lesson.go index 5aac3d5..2b1db55 100644 --- a/server/api/api/lesson/lesson.go +++ b/server/api/api/lesson/lesson.go @@ -13,4 +13,6 @@ import ( type ILessonV1 interface { LessonList(ctx context.Context, req *v1.LessonListReq) (res *v1.LessonListRes, err error) LessonDetail(ctx context.Context, req *v1.LessonDetailReq) (res *v1.LessonDetailRes, err error) + LessonSectionList(ctx context.Context, req *v1.LessonSectionListReq) (res *v1.LessonSectionListRes, err error) + LessonSectionDetail(ctx context.Context, req *v1.LessonSectionDetailReq) (res *v1.LessonSectionDetailRes, err error) } diff --git a/server/api/api/lesson/v1/lesson.go b/server/api/api/lesson/v1/lesson.go index df5ea1d..f76843e 100644 --- a/server/api/api/lesson/v1/lesson.go +++ b/server/api/api/lesson/v1/lesson.go @@ -25,5 +25,28 @@ type LessonDetailReq struct { // 查看课程详情响应 type LessonDetailRes struct { - Lesson *entity.Lesson `json:"lesson" dc:"课程"` + *entity.Lesson `dc:"课程"` +} + +// 获取课程章节列表请求 +type LessonSectionListReq struct { + g.Meta `path:"/lesson/section/list" method:"get" tags:"课程章节" summary:"获取课程章节列表"` + LessonId int64 `json:"lessonId" v:"required#课程ID必填" dc:"课程ID"` +} + +// 获取课程章节列表响应 +type LessonSectionListRes struct { + List []*entity.LessonSection `json:"list" dc:"课程章节列表"` + Total int `json:"total" dc:"总数"` +} + +// 获取课程章节详情请求 +type LessonSectionDetailReq struct { + g.Meta `path:"/lesson/section/detail" method:"get" tags:"课程章节" summary:"获取课程章节详情"` + Id int64 `json:"id" v:"required#课程章节ID必填" dc:"课程章节ID"` +} + +// 获取课程章节详情响应 +type LessonSectionDetailRes struct { + *entity.LessonSection `dc:"课程章节"` } diff --git a/server/internal/controller/api/lesson/lesson_v1_lesson_section_detail.go b/server/internal/controller/api/lesson/lesson_v1_lesson_section_detail.go new file mode 100644 index 0000000..a758b6d --- /dev/null +++ b/server/internal/controller/api/lesson/lesson_v1_lesson_section_detail.go @@ -0,0 +1,28 @@ +package lesson + +import ( + "context" + + "hotgo/internal/dao" + "hotgo/internal/model/entity" + + "github.com/gogf/gf/v2/errors/gcode" + "github.com/gogf/gf/v2/errors/gerror" + + v1 "hotgo/api/api/lesson/v1" +) + +func (c *ControllerV1) LessonSectionDetail(ctx context.Context, req *v1.LessonSectionDetailReq) (res *v1.LessonSectionDetailRes, err error) { + section := new(entity.LessonSection) + err = dao.LessonSection.Ctx(ctx).Where("id = ?", req.Id).Scan(section) + if err != nil { + return nil, gerror.NewCode(gcode.CodeDbOperationError, "数据库错误") + } + if section.Id == 0 { + return nil, gerror.NewCode(gcode.CodeNotFound, "课程章节不存在") + } + res = &v1.LessonSectionDetailRes{ + LessonSection: section, + } + return +} diff --git a/server/internal/controller/api/lesson/lesson_v1_lesson_section_list.go b/server/internal/controller/api/lesson/lesson_v1_lesson_section_list.go new file mode 100644 index 0000000..bb16fb3 --- /dev/null +++ b/server/internal/controller/api/lesson/lesson_v1_lesson_section_list.go @@ -0,0 +1,30 @@ +package lesson + +import ( + "context" + + "hotgo/internal/dao" + "hotgo/internal/model/entity" + + "github.com/gogf/gf/v2/errors/gcode" + "github.com/gogf/gf/v2/errors/gerror" + + v1 "hotgo/api/api/lesson/v1" +) + +func (c *ControllerV1) LessonSectionList(ctx context.Context, req *v1.LessonSectionListReq) (res *v1.LessonSectionListRes, err error) { + var list []*entity.LessonSection + err = dao.LessonSection.Ctx(ctx).Where("lesson_id = ?", req.LessonId).Scan(&list) + if err != nil { + return nil, gerror.NewCode(gcode.CodeDbOperationError, "数据库错误") + } + total, err := dao.LessonSection.Ctx(ctx).Where("lesson_id = ?", req.LessonId).Count() + if err != nil { + return nil, gerror.NewCode(gcode.CodeDbOperationError, "统计总数失败") + } + res = &v1.LessonSectionListRes{ + List: list, + Total: total, + } + return +} -- 2.47.2 From 258de92737d32a5e2f7d20b67203eefb96c6f787 Mon Sep 17 00:00:00 2001 From: GoCo Date: Fri, 25 Jul 2025 17:03:08 +0800 Subject: [PATCH 4/4] =?UTF-8?q?feat:=20=F0=9F=8E=B8=20=E8=AF=BE=E7=A8=8B?= =?UTF-8?q?=E7=AB=A0=E8=8A=82=20=E5=90=8E=E5=8F=B0=E7=AE=A1=E7=90=86?= =?UTF-8?q?=E9=A1=B5=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- web/src/api/lessonSection/index.ts | 42 ++++++ web/src/views/lessonSection/edit.vue | 148 +++++++++++++++++++ web/src/views/lessonSection/index.vue | 199 ++++++++++++++++++++++++++ web/src/views/lessonSection/model.ts | 129 +++++++++++++++++ web/src/views/lessonSection/view.vue | 96 +++++++++++++ 5 files changed, 614 insertions(+) create mode 100644 web/src/api/lessonSection/index.ts create mode 100644 web/src/views/lessonSection/edit.vue create mode 100644 web/src/views/lessonSection/index.vue create mode 100644 web/src/views/lessonSection/model.ts create mode 100644 web/src/views/lessonSection/view.vue diff --git a/web/src/api/lessonSection/index.ts b/web/src/api/lessonSection/index.ts new file mode 100644 index 0000000..e1f0ae6 --- /dev/null +++ b/web/src/api/lessonSection/index.ts @@ -0,0 +1,42 @@ +import { http, jumpExport } from '@/utils/http/axios'; + +// 获取课程章节列表 +export function List(params) { + return http.request({ + url: '/lessonSection/list', + method: 'get', + params, + }); +} + +// 删除/批量删除课程章节 +export function Delete(params) { + return http.request({ + url: '/lessonSection/delete', + method: 'POST', + params, + }); +} + +// 添加/编辑课程章节 +export function Edit(params) { + return http.request({ + url: '/lessonSection/edit', + method: 'POST', + params, + }); +} + +// 获取课程章节指定详情 +export function View(params) { + return http.request({ + url: '/lessonSection/view', + method: 'GET', + params, + }); +} + +// 导出课程章节 +export function Export(params) { + jumpExport('/lessonSection/export', params); +} \ No newline at end of file diff --git a/web/src/views/lessonSection/edit.vue b/web/src/views/lessonSection/edit.vue new file mode 100644 index 0000000..5849d8c --- /dev/null +++ b/web/src/views/lessonSection/edit.vue @@ -0,0 +1,148 @@ + + + + + \ No newline at end of file diff --git a/web/src/views/lessonSection/index.vue b/web/src/views/lessonSection/index.vue new file mode 100644 index 0000000..c425628 --- /dev/null +++ b/web/src/views/lessonSection/index.vue @@ -0,0 +1,199 @@ + + + + + \ No newline at end of file diff --git a/web/src/views/lessonSection/model.ts b/web/src/views/lessonSection/model.ts new file mode 100644 index 0000000..e39bc73 --- /dev/null +++ b/web/src/views/lessonSection/model.ts @@ -0,0 +1,129 @@ +import { h, ref } from 'vue'; +import { cloneDeep } from 'lodash-es'; +import { FormSchema } from '@/components/Form'; +import { renderOptionTag, renderPopoverMemberSumma, MemberSumma } from '@/utils'; +import { useDictStore } from '@/store/modules/dict'; + +const dict = useDictStore(); + +export class State { + public id = 0; // id + public lessonId = null; // 课程id + public videoUrl = ''; // 视频url + public name = ''; // 章节名 + public sortOrder = 0; // 排序号 + public parentId = 0; // 父章节id + public level = 0; // 章节层级 + public revision = 0; // 乐观锁 + public createdBy = 0; // 创建人 + public createdBySumma?: null | MemberSumma = null; // 创建人摘要信息 + public createdTime = ''; // 创建时间 + public updatedBy = 0; // 更新人 + public updatedBySumma?: null | MemberSumma = null; // 更新人摘要信息 + public updatedTime = ''; // 更新时间 + + constructor(state?: Partial) { + if (state) { + Object.assign(this, state); + } + } +} + +export function newState(state: State | Record | null): State { + if (state !== null) { + if (state instanceof State) { + return cloneDeep(state); + } + return new State(state); + } + return new State(); +} + +// 表单验证规则 + +// 表格搜索表单 +export const schemas = ref([ + { + field: 'id', + component: 'NInputNumber', + label: 'id', + componentProps: { + placeholder: '请输入id', + onUpdateValue: (e: any) => { + console.log(e); + }, + }, + }, +]); + +// 表格列 +export const columns = [ + { + title: 'id', + key: 'id', + align: 'left', + width: -1, + }, + { + title: '课程id', + key: 'lessonId', + align: 'left', + width: -1, + render(row: State) { + return renderOptionTag('lessonOption', row.lessonId); + }, + }, + { + title: '视频url', + key: 'videoUrl', + align: 'left', + width: -1, + }, + { + title: '章节名', + key: 'name', + align: 'left', + width: -1, + }, + { + title: '排序号', + key: 'sortOrder', + align: 'left', + width: -1, + }, + { + title: '父章节id', + key: 'parentId', + align: 'left', + width: -1, + }, + { + title: '章节层级', + key: 'level', + align: 'left', + width: -1, + }, + { + title: '创建人', + key: 'createdBy', + align: 'left', + width: -1, + render(row: State) { + return renderPopoverMemberSumma(row.createdBySumma); + }, + }, + { + title: '更新人', + key: 'updatedBy', + align: 'left', + width: -1, + render(row: State) { + return renderPopoverMemberSumma(row.updatedBySumma); + }, + }, +]; + +// 加载字典数据选项 +export function loadOptions() { + dict.loadOptions(['lessonOption']); +} \ No newline at end of file diff --git a/web/src/views/lessonSection/view.vue b/web/src/views/lessonSection/view.vue new file mode 100644 index 0000000..1ffea1c --- /dev/null +++ b/web/src/views/lessonSection/view.vue @@ -0,0 +1,96 @@ + + + + + \ No newline at end of file -- 2.47.2