package english_report import ( "github.com/gin-gonic/gin" "github.com/go-playground/validator/v10" "hongze/hongze_yb_en_api/controller/resp" "hongze/hongze_yb_en_api/global" "hongze/hongze_yb_en_api/models/base" "hongze/hongze_yb_en_api/models/english_classify" "hongze/hongze_yb_en_api/models/english_report" "hongze/hongze_yb_en_api/models/english_video" english_report_service "hongze/hongze_yb_en_api/services/english_report" "hongze/hongze_yb_en_api/utils" "strconv" ) type EnglishVideoController struct{} func (er *EnglishVideoController) List(c *gin.Context) { req := new(english_report.ReportListReq) err := c.BindQuery(&req) if err != nil { errs, ok := err.(validator.ValidationErrors) if !ok { resp.FailData("参数解析失败", "Err:"+err.Error(), c) return } resp.FailData("参数解析失败", errs.Translate(global.Trans), c) return } page := new(base.Page) page.SetPageSize(req.PageSize) page.SetCurrent(req.Current) item := new(english_video.EnglishVideo) condition := " state=2" var pars []interface{} var total int64 var tmpList []*english_video.EnglishVideo list := make([]*english_video.VideoListItem, 0) enClassify := new(english_classify.Classify) if req.ClassifyIdFirst > 0 { condition += " and classify_id_first = ?" pars = append(pars, req.ClassifyIdFirst) } if req.ClassifyIdSecond > 0 { condition += " and classify_id_second = ?" pars = append(pars, req.ClassifyIdSecond) } if req.ClassifyIdRoot > 0 && req.ClassifyIdFirst == 0 && req.ClassifyIdSecond == 0 { //查询顶级分类下的所有二级分类 secondClassify, err := enClassify.GetSecondChild(req.ClassifyIdRoot) if err != nil { resp.FailMsg("获取分类失败", "获取分类信息失败,Err:"+err.Error(), c) return } var classifyIdFirstSlice []int for _, v := range secondClassify { classifyIdFirstSlice = append(classifyIdFirstSlice, v.Id) } condition += " and classify_id_first in (?)" pars = append(pars, classifyIdFirstSlice) } page.AddOrderItem(base.OrderItem{Column: "publish_time", Asc: false}) page.AddOrderItem(base.OrderItem{Column: "id", Asc: false}) total, tmpList, err = item.SelectPage(page, condition, pars) if err != nil { resp.FailMsg("获取失败", "获取失败,Err:"+err.Error(), c) return } if len(tmpList) > 0 { for _, v := range tmpList { tmp := &english_video.VideoListItem{ Id: v.Id, ClassifyIdFirst: v.ClassifyIdFirst, ClassifyNameFirst: v.ClassifyNameFirst, ClassifyIdSecond: v.ClassifyIdSecond, ClassifyNameSecond: v.ClassifyNameSecond, Title: v.Title, Abstract: v.Abstract, Author: v.Author, PublishTime: utils.TimeTransferString(utils.FormatDateTime, v.PublishTime), VideoUrl: v.VideoUrl, VideoCoverUrl: v.VideoCoverUrl, VideoSeconds: v.VideoSeconds, VideoCode: v.VideoCode, ShareUrl: "https://share.hzinsights.com/reportEn?code=" + v.VideoCode, CreateTime: utils.TimeTransferString(utils.FormatDateTime, v.CreateTime), ModifyTime: utils.TimeTransferString(utils.FormatDateTime, v.ModifyTime), } list = append(list, tmp) } } page.SetTotal(total) baseData := new(base.BaseData) baseData.SetPage(page) baseData.SetList(list) resp.OkData("获取成功", baseData, c) } func (er *EnglishVideoController) Detail(c *gin.Context) { req := new(english_video.VideoDetailReq) err := c.BindQuery(&req) if err != nil { errs, ok := err.(validator.ValidationErrors) if !ok { resp.FailData("参数解析失败", "Err:"+err.Error(), c) return } resp.FailData("参数解析失败", errs.Translate(global.Trans), c) return } // 英文研报1.1改-路演开放所有权限 //userinfo := services.GetInfoByClaims(c) videoItem := new(english_video.EnglishVideo) videoItem, err = videoItem.GetEnglishVideoByCode(req.VideoCode) if err != nil { resp.FailMsg("该视频已删除", "视频查询失败,Err:"+err.Error(), c) return } // 权限校验 //authOk, e := english_report_service.CheckUserReportAuthByCompanyAndClassify(int(userinfo.CompanyId), videoItem.ClassifyIdSecond) //if e != nil { // resp.FailMsg("获取失败", "报告权限校验失败, Err: "+e.Error(), c) // return //} //videoUrl := `` //if authOk { // videoUrl = videoItem.VideoUrl //} err = videoItem.UpdatePvByVideoCode(req.VideoCode) if err != nil { resp.FailMsg("更新失败", "更新失败,Err:"+err.Error(), c) return } shareEmailId := req.ShareEmail if shareEmailId == 0 { shareEmailIdStr := c.GetString("shareEmailId") shareEmailId, _ = strconv.Atoi(shareEmailIdStr) } // 记录邮箱 if shareEmailId > 0 { go english_report_service.DealVideoEmail(videoItem, req.VideoCode, shareEmailId) } videoDetail := &english_video.VideoDetail{ Id: videoItem.Id, ClassifyIdFirst: videoItem.ClassifyIdFirst, ClassifyNameFirst: videoItem.ClassifyNameFirst, ClassifyIdSecond: videoItem.ClassifyIdSecond, ClassifyNameSecond: videoItem.ClassifyNameSecond, Title: videoItem.Title, Abstract: videoItem.Abstract, Author: videoItem.Author, Overview: videoItem.Overview, PublishTime: utils.TimeTransferString(utils.FormatDateTime, videoItem.PublishTime), VideoUrl: videoItem.VideoUrl, VideoCoverUrl: videoItem.VideoCoverUrl, VideoSeconds: videoItem.VideoSeconds, VideoCode: videoItem.VideoCode, CreateTime: utils.TimeTransferString(utils.FormatDateTime, videoItem.CreateTime), ModifyTime: utils.TimeTransferString(utils.FormatDateTime, videoItem.ModifyTime), } baseData := new(english_video.VideoDetailResp) baseData.Video = videoDetail baseData.AuthOk = true resp.OkData("查询成功", baseData, c) } // VideoPlayLog 记录视频播放日志 // @Tags 视频社区模块 // @Description 记录视频播放日志 // @Param video_id query int true "音频ID" // @Param source_agent query int true "操作来源,1:小程序,2:小程序 pc 3:弘则研究公众号,4:web pc" // @Success 200 {string} string "操作成功" // @failure 400 {string} string "操作失败" // @Router /play_log [post] func (er *EnglishVideoController) VideoPlayLog(c *gin.Context) { var req english_video.VideoPlayLogReq err := c.ShouldBind(&req) if err != nil { errs, ok := err.(validator.ValidationErrors) if !ok { resp.FailData("参数解析失败", "Err:"+err.Error(), c) return } resp.FailData("参数解析失败", errs.Translate(global.Trans), c) return } shareEmailIdStr := c.GetString("shareEmailId") shareEmailId, _ := strconv.Atoi(shareEmailIdStr) item := new(english_video.PlayLog) if req.Id > 0 { //查找当前播放日志,并更新停止播放时长 item.Id = req.Id item, err = item.GetById() if err != nil { if err == utils.ErrNoRow { resp.Fail("播放日志不存在", c) return } resp.FailMsg("查询播放日志失败", "新增播放日志失败,Err:"+err.Error(), c) return } item.StopSeconds = req.StopSeconds err = item.Update([]string{"stop_seconds"}) if err != nil { resp.FailMsg("更新播放日志失败", "更新播放日志失败,Err:"+err.Error(), c) return } } else { if req.VideoId == 0 { resp.Fail("请输入点击的视频ID", c) return } item = &english_video.PlayLog{ VideoId: req.VideoId, EmailId: shareEmailId, StopSeconds: 0, } err = item.Add() if err != nil { resp.FailMsg("新增播放日志失败", "新增播放日志失败,Err:"+err.Error(), c) return } } baseData := new(english_video.VideoPlayLogResp) baseData.Id = item.Id resp.OkData("操作成功", baseData, c) }