123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378 |
- package controllers
- import (
- "encoding/json"
- "github.com/rdlucklib/rdluck_tools/paging"
- "hongze/hz_crm_api/models"
- "hongze/hz_crm_api/models/video"
- "hongze/hz_crm_api/utils"
- "strconv"
- "strings"
- "time"
- )
- // 视频
- type VideoController struct {
- BaseAuthController
- }
- // @Title 获取视频标签列表
- // @Description 获取视频标签列表接口
- // @Success 200 {object} video.VideoTagsListResp
- // @router /tags/list [get]
- func (this *VideoController) TagsList() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- return
- }
- list, err := video.GetVideoTagsList()
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- resp := new(video.VideoTagsListResp)
- resp.List = list
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- // @Title 视频列表
- // @Description 视频列表接口
- // @Param PageSize query int true "每页数据条数"
- // @Param CurrentIndex query int true "当前页页码,从1开始"
- // @Param KeyWord query string true "搜索关键词"
- // @Success 200 {object} video.VideoListResp
- // @router /list [get]
- func (this *VideoController) List() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- pageSize, _ := this.GetInt("PageSize")
- currentIndex, _ := this.GetInt("CurrentIndex")
- keyWord := this.GetString("KeyWord")
- var startSize int
- if pageSize <= 0 {
- pageSize = utils.PageSize20
- }
- if currentIndex <= 0 {
- currentIndex = 1
- }
- startSize = paging.StartIndex(currentIndex, pageSize)
- var condition string
- var pars []interface{}
- if keyWord != "" {
- videoIdStr, err := video.GetVideoIdByKeyWord(keyWord)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- if videoIdStr != "" {
- condition += ` AND (a.title LIKE '%` + keyWord + `%' OR a.video_id IN(` + videoIdStr + `) ) `
- } else {
- condition += ` AND a.title LIKE '%` + keyWord + `%' `
- }
- }
- total, err := video.GetVideoListCount(condition, pars)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取数据总数失败,Err:" + err.Error()
- return
- }
- list, err := video.GetVideoList(condition, pars, startSize, pageSize)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取数据失败,Err:" + err.Error()
- return
- }
- page := paging.GetPaging(currentIndex, pageSize, total)
- resp := new(video.VideoListResp)
- resp.List = list
- resp.Paging = page
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- // @Title 保存视频
- // @Description 保存视频接口
- // @Param request body video.VideoSaveReq true "type json string"
- // @Success 200 {object} video.VideoSaveResp
- // @router /save [post]
- func (this *VideoController) Save() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- var req video.VideoSaveReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- if req.Title == "" {
- br.Msg = "标题不能为空"
- return
- }
- //if req.VideoUrl == "" {
- // br.Msg = "音频地址不能为空"
- // return
- //}
- videoCount, err := video.GetVideoByTitle(req.Title)
- if err != nil {
- br.Msg = "判断标题是否存在失败!"
- br.ErrMsg = "判断标题是否存在失败,Err:" + err.Error()
- return
- }
- if videoCount > 0 {
- br.Msg = "标题已存在!"
- br.IsSendEmail = false
- return
- }
- item := new(video.Video)
- item.Title = req.Title
- item.VideoUrl = req.VideoUrl
- item.VideoCoverUrl = req.VideoCoverUrl
- item.Status = 0
- item.CreateTime = time.Now()
- item.ModifyTime = time.Now()
- item.PlaySeconds = req.PlaySeconds
- newId, err := video.AddVideo(item)
- if err != nil {
- br.Msg = "保存失败"
- br.ErrMsg = "保存失败,Err:" + err.Error()
- return
- }
- if req.TagsIdStr != "" {
- tagsArr := strings.Split(req.TagsIdStr, ",")
- for _, v := range tagsArr {
- tagId, _ := strconv.Atoi(v)
- tagItem := new(video.VideoTags)
- tagItem.VideoId = int(newId)
- tagItem.TagsId = tagId
- err = video.AddVideoTags(tagItem)
- if err != nil {
- br.Msg = "保存失败"
- br.ErrMsg = "保存失败,Err:" + err.Error()
- return
- }
- }
- }
- resp := new(video.VideoSaveResp)
- resp.VideoId = int(newId)
- br.Ret = 200
- br.Success = true
- br.Msg = "保存成功"
- br.Data = resp
- }
- // @Title 删除视频
- // @Description 删除视频接口
- // @Param request body video.VideoDeleteReq true "type json string"
- // @Success Ret=200 保存成功
- // @router /delete [post]
- func (this *VideoController) Delete() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- var req video.VideoDeleteReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- if req.VideoId <= 0 {
- br.Msg = "参数错误"
- return
- }
- err = video.DeleteVideo(req.VideoId)
- if err != nil {
- br.Msg = "删除失败!"
- br.ErrMsg = "删除失败,Err:" + err.Error()
- return
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "删除成功"
- }
- // @Title 批量发布视频
- // @Description 批量发布视频接口
- // @Param request body video.VideoPublishReq true "type json string"
- // @Success Ret=200 保存成功
- // @router /publish [post]
- func (this *VideoController) Publish() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- var req video.VideoPublishReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- if req.VideoIds == "" {
- br.Msg = "参数错误"
- return
- }
- err = video.PublishVideo(req.VideoIds)
- if err != nil {
- br.Msg = "发布失败"
- br.ErrMsg = "发布失败,Err:" + err.Error()
- return
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "发布成功"
- }
- // @Title 编辑视频
- // @Description 编辑视频接口
- // @Param request body video.VideoEditReq true "type json string"
- // @Success Ret=200 编辑成功
- // @router /edit [post]
- func (this *VideoController) Edit() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- var req video.VideoEditReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- if req.Title == "" {
- br.Msg = "标题不能为空"
- return
- }
- if req.VideoUrl == "" {
- br.Msg = "音频地址不能为空"
- return
- }
- item := new(video.Video)
- item.Title = req.Title
- item.VideoUrl = req.VideoUrl
- item.VideoCoverUrl = req.VideoCoverUrl
- item.Status = 0
- item.CreateTime = time.Now()
- item.ModifyTime = time.Now()
- item.PlaySeconds = req.PlaySeconds
- item.VideoId = req.VideoId
- err = video.EditVideo(item, req.TagsIdStr)
- if err != nil {
- br.Msg = "编辑失败"
- br.ErrMsg = "编辑失败,Err:" + err.Error()
- return
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "编辑成功"
- }
- // @Title 取消视频发布
- // @Description 取消视频发布接口
- // @Param request body video.VideoPublishReq true "type json string"
- // @Success Ret=200 保存成功
- // @router /publish/cancel [post]
- func (this *VideoController) PublishCancel() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- var req video.VideoPublishReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- if req.VideoIds == "" {
- br.Msg = "参数错误"
- return
- }
- err = video.PublishVideoCancel(req.VideoIds)
- if err != nil {
- br.Msg = "取消发布失败"
- br.ErrMsg = "取消发布失败,Err:" + err.Error()
- return
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "取消发布成功"
- }
|