代码拉取完成,页面将自动刷新
package handler
import (
"context"
"gitee.com/jingshanccc/course/course/dao"
"gitee.com/jingshanccc/course/course/proto/dto"
"gitee.com/jingshanccc/course/public"
"gitee.com/jingshanccc/course/public/config"
"gitee.com/jingshanccc/course/public/proto/basic"
"gitee.com/jingshanccc/course/public/util"
"github.com/micro/go-micro/v2/errors"
"gorm.io/gorm"
"strings"
"time"
)
//CourseList: get course page
func (c *CourseServiceHandler) CourseList(ctx context.Context, in *dto.CoursePageDto, out *dto.CoursePageDto) error {
count, courseDtos, err := courseDao.List(in)
if err != nil {
return errors.New(config.Conf.BasicConfig.BasicName+config.Conf.Services["course"].Name, err.Error(), err.Code())
}
_ = util.CopyProperties(out, in)
out.Rows = courseDtos
out.Total = count
return nil
}
//MyCourse: 我的课程
func (c *CourseServiceHandler) MyCourse(ctx context.Context, in *basic.String, out *dto.CourseDtoList) error {
courseDtos, err := memberCourseDao.MyCourse(in.Str)
if err != nil {
return errors.New(config.Conf.BasicConfig.BasicName+config.Conf.Services["course"].Name, err.Error(), err.Code())
}
out.Rows = courseDtos
return nil
}
//AddToMyCourse: 添加到我的课程
func (c *CourseServiceHandler) AddToMyCourse(ctx context.Context, in *dto.MemberCourseDto, out *basic.String) error {
var data dao.MemberCourse
_ = util.CopyProperties(&data, in)
data.LastLearn = "1 1 0"
data.CreateAt = time.Now()
data.UpdateAt = data.CreateAt
err := memberCourseDao.AddToMyCourse(&data)
if err != nil {
return errors.New(config.Conf.BasicConfig.BasicName+config.Conf.Services["course"].Name, err.Error(), err.Code())
}
courseDao.UpdateEnroll(in.CourseId)
return nil
}
//CourseInfo: 课程学习情况
func (c *CourseServiceHandler) CourseInfo(ctx context.Context, in *basic.StringList, out *basic.String) error {
info, err := memberCourseDao.CourseInfo(in.Rows[0], in.Rows[1])
out.Str = info
if err != nil {
return errors.New(config.Conf.BasicConfig.BasicName+config.Conf.Services["course"].Name, err.Error(), err.Code())
}
return nil
}
//SaveLearnInfo: 保存课程学习进度
func (c *CourseServiceHandler) SaveLearnInfo(ctx context.Context, in *basic.StringList, out *basic.String) error {
if len(in.Rows) != 3 || len(strings.Split(in.Rows[1], " ")) != 3 {
exception := public.NewBusinessException(public.VALID_PARM_ERROR)
return errors.New(config.Conf.BasicConfig.BasicName+config.Conf.Services["course"].Name, exception.Error(), exception.Code())
}
err := memberCourseDao.SaveLearnInfo(in.Rows)
if err != nil {
return errors.New(config.Conf.BasicConfig.BasicName+config.Conf.Services["course"].Name, err.Error(), err.Code())
}
return nil
}
//CarouselCourse: 轮播图课程
func (c *CourseServiceHandler) CarouselCourse(ctx context.Context, in *basic.String, out *dto.CourseDtoList) error {
courseDtos, err := courseDao.CarouselCourse()
if err != nil {
return errors.New(config.Conf.BasicConfig.BasicName+config.Conf.Services["course"].Name, err.Error(), err.Code())
}
out.Rows = courseDtos
return nil
}
//NewPublishCourse: 新上好课
func (c *CourseServiceHandler) NewPublishCourse(ctx context.Context, in *basic.String, out *dto.CourseDtoList) error {
courseDtos, err := courseDao.NewPublish()
if err != nil {
return errors.New(config.Conf.BasicConfig.BasicName+config.Conf.Services["course"].Name, err.Error(), err.Code())
}
out.Rows = courseDtos
return nil
}
//RelatedCourse: 新上好课
func (c *CourseServiceHandler) RelatedCourse(ctx context.Context, in *basic.String, out *dto.CourseDtoList) error {
ccds, _ := courseCategoryDao.SelectByCourseId(in.Str)
courseDtos, err := courseDao.SelectCourseByIds(courseCategoryDao.SelectCourseIds(ccds...), false)
if err != nil {
return errors.New(config.Conf.BasicConfig.BasicName+config.Conf.Services["course"].Name, err.Error(), err.Code())
}
if len(courseDtos) == 1 {
courseDtos, _ = courseDao.NewPublish()
}
out.Rows = courseDtos
return nil
}
//CategoryCourse: 分类搜索课程
func (c *CourseServiceHandler) CategoryCourse(ctx context.Context, in *basic.String, out *dto.CourseDtoList) error {
// 通过 分类id 获取分类id和其父分类id 获取两个id 对应的所有课程id
var ids []string
var err *public.BusinessException
var courseDtos []*dto.CourseDto
if in.Str != "" {
ids = courseCategoryDao.SelectCourseIds(in.Str)
courseDtos, err = courseDao.SelectCourseByIds(ids, false)
} else {
courseDtos, err = courseDao.SelectCourseByIds(ids, true)
}
if err != nil {
return errors.New(config.Conf.BasicConfig.BasicName+config.Conf.Services["course"].Name, err.Error(), err.Code())
}
out.Rows = courseDtos
return nil
}
//DownloadCourseContent: 下载课程讲义
func (c *CourseServiceHandler) DownloadCourseContent(ctx context.Context, in *basic.String, out *basic.String) error {
content, exception := courseDao.FindContent(in.Str)
if exception != nil {
return errors.New(config.Conf.BasicConfig.BasicName+config.Conf.Services["course"].Name, exception.Error(), exception.Code())
}
out.Str = util.TransToHtml(content.Content)
return nil
}
//CourseDetail: 课程详情
func (c *CourseServiceHandler) CourseDetail(ctx context.Context, in *basic.String, out *dto.CourseDto) error {
courseDb := courseDao.SelectByProperty("id", in.Str)
if courseDb.Id != "" {
_ = util.CopyProperties(out, courseDb)
teacherDb, _ := teacherDao.SelectByProperty("id", courseDb.TeacherId)
chapters, _ := chapterDao.SelectByProperty("course_id", courseDb.Id)
sections, _ := sectionDao.SelectByProperty("course_id", courseDb.Id)
out.Chapters = chapters
out.Teacher = teacherDb
out.Sections = sections
}
return nil
}
//SaveCourse: 保存/更新课程
func (c *CourseServiceHandler) SaveCourse(ctx context.Context, in *dto.CourseDto, out *dto.CourseDto) error {
cd, err := courseDao.Save(in)
if err != nil {
return errors.New(config.Conf.BasicConfig.BasicName+config.Conf.Services["course"].Name, err.Error(), err.Code())
}
_ = util.CopyProperties(out, cd)
return nil
}
//DeleteCourse: 删除课程
func (c *CourseServiceHandler) DeleteCourse(ctx context.Context, in *basic.StringList, out *basic.String) error {
exception := courseDao.Delete(in.Rows)
if exception != nil {
return errors.New(config.Conf.BasicConfig.BasicName+config.Conf.Services["course"].Name, exception.Error(), exception.Code())
}
return nil
}
//SortCourse: 更新课程排序
func (c *CourseServiceHandler) SortCourse(ctx context.Context, in *dto.SortDto, out *basic.String) error {
var exception *public.BusinessException
var tx *gorm.DB
var err error
defer func() {
if exception != nil {
tx.Rollback()
err = errors.New(config.Conf.BasicConfig.BasicName+config.Conf.Services["course"].Name, exception.Error(), exception.Code())
} else {
err = nil
}
}()
tx = public.DB.Begin()
exception = courseDao.UpdateSort(tx, in)
if in.NewSort > in.OldSort {
exception = courseDao.MoveSortsForward(tx, in)
}
if in.OldSort > in.NewSort {
exception = courseDao.MoveSortsBackward(tx, in)
}
tx.Commit()
return err
}
//FindCourseContent: 查找课程内容
func (c *CourseServiceHandler) FindCourseContent(ctx context.Context, in *basic.String, out *dto.CourseContentDto) error {
content, exception := courseDao.FindContent(in.Str)
if exception != nil {
return errors.New(config.Conf.BasicConfig.BasicName+config.Conf.Services["course"].Name, exception.Error(), exception.Code())
}
out.Id = content.Id
out.Content = content.Content
return nil
}
//SaveCourseContent: 保存课程内容
func (c *CourseServiceHandler) SaveCourseContent(ctx context.Context, in *dto.CourseContentDto, out *basic.String) error {
exception := courseDao.SaveContent(in)
if exception != nil {
return errors.New(config.Conf.BasicConfig.BasicName+config.Conf.Services["course"].Name, exception.Error(), exception.Code())
}
return nil
}
//ListCourseFile: 获取课程文件
func (c *CourseServiceHandler) ListCourseFile(ctx context.Context, in *basic.String, out *dto.CourseFileDtoList) error {
list, exception := courseFileDao.List(in.Str)
if exception != nil {
return errors.New(config.Conf.BasicConfig.BasicName+config.Conf.Services["course"].Name, exception.Error(), exception.Code())
}
out.Rows = list
return nil
}
//SaveCourseFile: 保存课程文件
func (c *CourseServiceHandler) SaveCourseFile(ctx context.Context, in *dto.CourseFileDto, out *dto.CourseFileDto) error {
fileDto, exception := courseFileDao.Save(in)
if exception != nil {
return errors.New(config.Conf.BasicConfig.BasicName+config.Conf.Services["course"].Name, exception.Error(), exception.Code())
}
_ = util.CopyProperties(out, fileDto)
return nil
}
//DeleteCourseFile: 删除课程文件
func (c *CourseServiceHandler) DeleteCourseFile(ctx context.Context, in *basic.String, out *basic.String) error {
exception := courseFileDao.Delete(in.Str)
if exception != nil {
return errors.New(config.Conf.BasicConfig.BasicName+config.Conf.Services["course"].Name, exception.Error(), exception.Code())
}
return nil
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。