eta_training_video.go 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726
  1. package eta_training_video
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "github.com/rdlucklib/rdluck_tools/paging"
  6. "hongze/hz_crm_api/controllers"
  7. "hongze/hz_crm_api/models"
  8. "hongze/hz_crm_api/models/eta_training_video"
  9. etaTrainingVideoService "hongze/hz_crm_api/services/eta_training_video"
  10. "hongze/hz_crm_api/utils"
  11. "html/template"
  12. "strings"
  13. "time"
  14. )
  15. // EtaTrainingVideoController ETA培训视频
  16. type EtaTrainingVideoController struct {
  17. controllers.BaseAuthController
  18. }
  19. // PageList
  20. // @Title 视频列表-分页
  21. // @Description 视频列表-分页
  22. // @Param PageSize query int true "每页数据量"
  23. // @Param CurrentIndex query int true "当前页码"
  24. // @Param Keyword query string false "关键词: 视频名称/社会信用码/视频编码"
  25. // @Param StartTime query string false "创建时间区间: 开始时间"
  26. // @Param EndTime query string false "创建时间区间: 结束时间"
  27. // @Param ClassifyId query int false "分类ID"
  28. // @Param TagIds query string false "标签IDs, 英文逗号拼接"
  29. // @Param PublishState query int false "发布状态: 1-未发布; 2-已发布"
  30. // @Success 200 Ret=200 获取成功
  31. // @router /page_list [get]
  32. func (this *EtaTrainingVideoController) PageList() {
  33. br := new(models.BaseResponse).Init()
  34. defer func() {
  35. if br.ErrMsg == "" {
  36. br.IsSendEmail = false
  37. }
  38. this.Data["json"] = br
  39. this.ServeJSON()
  40. }()
  41. sysUser := this.SysUser
  42. if sysUser == nil {
  43. br.Msg = "请登录"
  44. br.ErrMsg = "请登录,SysUser Is Empty"
  45. br.Ret = 408
  46. return
  47. }
  48. // 分页
  49. pageSize, _ := this.GetInt("PageSize")
  50. currentIndex, _ := this.GetInt("CurrentIndex")
  51. var startSize int
  52. if pageSize <= 0 {
  53. pageSize = utils.PageSize20
  54. }
  55. if currentIndex <= 0 {
  56. currentIndex = 1
  57. }
  58. startSize = utils.StartIndex(currentIndex, pageSize)
  59. // 筛选项
  60. cond := ``
  61. pars := make([]interface{}, 0)
  62. {
  63. // 关键词
  64. keyword := this.GetString("Keyword", "")
  65. keyword = strings.TrimSpace(keyword)
  66. keyword = template.HTMLEscapeString(keyword)
  67. if keyword != "" {
  68. kw := fmt.Sprint("%", keyword, "%")
  69. cond += fmt.Sprintf(` AND (%s LIKE ?)`, eta_training_video.VideoColumns.Title)
  70. pars = append(pars, kw)
  71. }
  72. // 创建时间
  73. startTime := this.GetString("StartTime", "")
  74. endTime := this.GetString("EndTime", "")
  75. if startTime != "" && endTime != "" {
  76. st := fmt.Sprint(startTime, " 00:00:00")
  77. ed := fmt.Sprint(endTime, " 23:59:59")
  78. cond += fmt.Sprintf(` AND (%s BETWEEN ? AND ?)`, eta_training_video.VideoColumns.CreateTime)
  79. pars = append(pars, st, ed)
  80. }
  81. // 分类ID
  82. classifyId, _ := this.GetInt("ClassifyId", 0)
  83. if classifyId > 0 {
  84. cond += fmt.Sprintf(` AND FIND_IN_SET(?, %s)`, eta_training_video.VideoColumns.ClassifyIds)
  85. pars = append(pars, classifyId)
  86. }
  87. // 标签IDs
  88. strTagIds := this.GetString("TagIds", "")
  89. if strTagIds != "" {
  90. strTags := strings.Split(strTagIds, ",")
  91. if len(strTags) > 0 {
  92. joinArr := make([]string, 0)
  93. cond += ` AND (`
  94. for _, s := range strTags {
  95. joinArr = append(joinArr, fmt.Sprintf(`FIND_IN_SET(?, %s)`, eta_training_video.VideoColumns.TagIds))
  96. pars = append(pars, s)
  97. }
  98. cond += strings.Join(joinArr, ` OR `)
  99. cond += `)`
  100. } else {
  101. cond += ` AND 1=2`
  102. }
  103. }
  104. // 发布状态
  105. publishState, _ := this.GetInt("PublishState", 0)
  106. if publishState > 0 {
  107. stateMap := map[int]int{1: 0, 2: 1}
  108. cond += fmt.Sprintf(` AND %s = ?`, eta_training_video.VideoColumns.PublishState)
  109. pars = append(pars, stateMap[publishState])
  110. }
  111. }
  112. // 获取列表
  113. videoOb := new(eta_training_video.EtaTrainingVideo)
  114. total, e := videoOb.GetCountByCondition(cond, pars)
  115. if e != nil {
  116. br.Msg = "获取失败"
  117. br.ErrMsg = "获取视频总数失败, Err: " + e.Error()
  118. return
  119. }
  120. list, e := videoOb.GetPageItemsByCondition(cond, pars, []string{}, "", startSize, pageSize)
  121. if e != nil {
  122. br.Msg = "获取失败"
  123. br.ErrMsg = "获取视频列表失败, Err: " + e.Error()
  124. return
  125. }
  126. items, e := etaTrainingVideoService.FormatVideosToVideoItems(list)
  127. if e != nil {
  128. br.Msg = "获取失败"
  129. br.ErrMsg = e.Error()
  130. return
  131. }
  132. resp := new(eta_training_video.EtaTrainingVideoListResp)
  133. resp.List = items
  134. resp.Paging = paging.GetPaging(currentIndex, pageSize, total)
  135. br.Data = resp
  136. br.Ret = 200
  137. br.Success = true
  138. br.Msg = "获取成功"
  139. }
  140. // Add
  141. // @Title 新增视频
  142. // @Description 新增视频
  143. // @Param request body eta_training_video.EtaTrainingVideoAddReq true "type json string"
  144. // @Success 200 Ret=200 操作成功
  145. // @router /add [post]
  146. func (this *EtaTrainingVideoController) Add() {
  147. br := new(models.BaseResponse).Init()
  148. defer func() {
  149. if br.ErrMsg == "" {
  150. br.IsSendEmail = false
  151. }
  152. this.Data["json"] = br
  153. this.ServeJSON()
  154. }()
  155. sysUser := this.SysUser
  156. if sysUser == nil {
  157. br.Msg = "请登录"
  158. br.ErrMsg = "请登录,SysUser Is Empty"
  159. br.Ret = 408
  160. return
  161. }
  162. // 参数校验
  163. var req eta_training_video.EtaTrainingVideoAddReq
  164. if e := json.Unmarshal(this.Ctx.Input.RequestBody, &req); e != nil {
  165. br.Msg = "参数解析异常!"
  166. br.ErrMsg = "参数解析失败,Err:" + e.Error()
  167. return
  168. }
  169. if req.ClassifyId <= 0 {
  170. br.Msg = "请选择视频分类"
  171. return
  172. }
  173. req.Title = strings.TrimSpace(req.Title)
  174. if req.Title == "" {
  175. br.Msg = "请输入视频名称"
  176. return
  177. }
  178. if req.Introduce != "" {
  179. req.Introduce = strings.TrimSpace(req.Introduce)
  180. req.Introduce = template.HTMLEscapeString(req.Introduce)
  181. }
  182. req.CoverImg = strings.TrimSpace(req.CoverImg)
  183. if req.CoverImg == "" {
  184. br.Msg = "请上传封面图"
  185. return
  186. }
  187. req.VideoUrl = strings.TrimSpace(req.VideoUrl)
  188. if req.VideoUrl == "" {
  189. br.Msg = "请上传视频"
  190. return
  191. }
  192. // 分类
  193. strClassifyIds := ""
  194. classifyRelates := make([]*eta_training_video.EtaTrainingVideoClassifyRelate, 0)
  195. {
  196. classifyOB := new(eta_training_video.EtaTrainingVideoClassify)
  197. classifies, e := classifyOB.GetItemsByCondition(``, make([]interface{}, 0), []string{}, "")
  198. if e != nil {
  199. br.Msg = "操作失败"
  200. br.ErrMsg = "获取分类失败, Err: " + e.Error()
  201. return
  202. }
  203. for _, c := range classifies {
  204. if c.EtaTrainingVideoClassifyId != req.ClassifyId {
  205. continue
  206. }
  207. strClassifyIds += fmt.Sprintf("%d,", req.ClassifyId)
  208. classifyRelates = append(classifyRelates, &eta_training_video.EtaTrainingVideoClassifyRelate{
  209. EtaTrainingVideoClassifyId: c.EtaTrainingVideoClassifyId,
  210. ClassifyParentId: c.ParentId,
  211. ClassifyName: c.ClassifyName,
  212. })
  213. // 分类所有父级
  214. if c.ParentId > 0 {
  215. parents := etaTrainingVideoService.GetClassifyParentsRecursive(classifies, c.ParentId)
  216. for _, p := range parents {
  217. strClassifyIds += fmt.Sprintf("%d,", p.EtaTrainingVideoClassifyId)
  218. classifyRelates = append(classifyRelates, &eta_training_video.EtaTrainingVideoClassifyRelate{
  219. EtaTrainingVideoClassifyId: p.EtaTrainingVideoClassifyId,
  220. ClassifyParentId: p.ParentId,
  221. ClassifyName: p.ClassifyName,
  222. })
  223. }
  224. }
  225. }
  226. strClassifyIds = strings.TrimRight(strClassifyIds, ",")
  227. }
  228. // 标签
  229. strTagIds := ""
  230. tagRelates := make([]*eta_training_video.EtaTrainingVideoTagRelate, 0)
  231. if len(req.TagIds) > 0 {
  232. tagOB := new(eta_training_video.EtaTrainingVideoTag)
  233. tags, e := tagOB.GetItemsByCondition(``, make([]interface{}, 0), []string{}, "")
  234. if e != nil {
  235. br.Msg = "操作失败"
  236. br.ErrMsg = "获取标签失败, Err: " + e.Error()
  237. return
  238. }
  239. tagMap := make(map[int]*eta_training_video.EtaTrainingVideoTag)
  240. for _, t := range tags {
  241. tagMap[t.EtaTrainingVideoTagId] = t
  242. }
  243. for _, r := range req.TagIds {
  244. t := tagMap[r]
  245. if t == nil {
  246. continue
  247. }
  248. tagRelates = append(tagRelates, &eta_training_video.EtaTrainingVideoTagRelate{
  249. EtaTrainingVideoTagId: r,
  250. TagName: t.TagName,
  251. })
  252. strTagIds += fmt.Sprintf("%d,", r)
  253. }
  254. strTagIds = strings.TrimRight(strTagIds, ",")
  255. }
  256. // 视频编码
  257. now := time.Now().Local()
  258. videoCode := utils.MD5(fmt.Sprint(now.UnixMicro()))
  259. item := new(eta_training_video.EtaTrainingVideo)
  260. item.VideoCode = videoCode
  261. item.Title = req.Title
  262. item.Introduce = req.Introduce
  263. item.ClassifyIds = strClassifyIds
  264. item.TagIds = strTagIds
  265. item.CoverImg = req.CoverImg
  266. item.VideoUrl = req.VideoUrl
  267. item.CreateTime = now
  268. item.ModifyTime = now
  269. if e := item.CreateVideoAndRelates(item, classifyRelates, tagRelates); e != nil {
  270. br.Msg = "操作失败"
  271. br.ErrMsg = "新增视频及关联失败, Err: " + e.Error()
  272. return
  273. }
  274. // 操作日志
  275. go func() {
  276. logItem := new(eta_training_video.EtaTrainingVideoOpLog)
  277. logItem.EtaTrainingVideoId = item.EtaTrainingVideoId
  278. logItem.SysUserId = sysUser.AdminId
  279. logItem.SysRealName = sysUser.RealName
  280. logItem.OpType = eta_training_video.VideoOpTypeAdd
  281. logItem.OpData = string(this.Ctx.Input.RequestBody)
  282. logItem.CreateTime = now
  283. _ = logItem.Create()
  284. }()
  285. // 更新标签引用数
  286. go func() {
  287. tagOB := new(eta_training_video.EtaTrainingVideoTag)
  288. for _, t := range tagRelates {
  289. _ = tagOB.UpdateVideoTotal(t.EtaTrainingVideoTagId)
  290. }
  291. }()
  292. br.Data = item.EtaTrainingVideoId
  293. br.Ret = 200
  294. br.Success = true
  295. br.Msg = "操作成功"
  296. }
  297. // Edit
  298. // @Title 编辑视频
  299. // @Description 编辑视频
  300. // @Param request body eta_training_video.EtaTrainingVideoEditReq true "type json string"
  301. // @Success 200 Ret=200 操作成功
  302. // @router /edit [post]
  303. func (this *EtaTrainingVideoController) Edit() {
  304. br := new(models.BaseResponse).Init()
  305. defer func() {
  306. if br.ErrMsg == "" {
  307. br.IsSendEmail = false
  308. }
  309. this.Data["json"] = br
  310. this.ServeJSON()
  311. }()
  312. sysUser := this.SysUser
  313. if sysUser == nil {
  314. br.Msg = "请登录"
  315. br.ErrMsg = "请登录,SysUser Is Empty"
  316. br.Ret = 408
  317. return
  318. }
  319. // 参数校验
  320. var req eta_training_video.EtaTrainingVideoEditReq
  321. if e := json.Unmarshal(this.Ctx.Input.RequestBody, &req); e != nil {
  322. br.Msg = "参数解析异常!"
  323. br.ErrMsg = "参数解析失败,Err:" + e.Error()
  324. return
  325. }
  326. if req.VideoId <= 0 {
  327. br.Msg = "参数有误"
  328. br.ErrMsg = fmt.Sprintf("参数有误, 视频ID: %d", req.VideoId)
  329. return
  330. }
  331. if req.ClassifyId <= 0 {
  332. br.Msg = "请选择视频分类"
  333. return
  334. }
  335. req.Title = strings.TrimSpace(req.Title)
  336. if req.Title == "" {
  337. br.Msg = "请输入视频名称"
  338. return
  339. }
  340. if req.Introduce == "" {
  341. req.Introduce = strings.TrimSpace(req.Introduce)
  342. req.Introduce = template.HTMLEscapeString(req.Introduce)
  343. }
  344. req.CoverImg = strings.TrimSpace(req.CoverImg)
  345. if req.CoverImg == "" {
  346. br.Msg = "请上传封面图"
  347. return
  348. }
  349. req.VideoUrl = strings.TrimSpace(req.VideoUrl)
  350. if req.VideoUrl == "" {
  351. br.Msg = "请上传视频"
  352. return
  353. }
  354. ob := new(eta_training_video.EtaTrainingVideo)
  355. item, e := ob.GetItemById(req.VideoId)
  356. if e != nil {
  357. if e.Error() == utils.ErrNoRow() {
  358. br.Msg = "视频不存在, 请刷新页面"
  359. return
  360. }
  361. br.Msg = "操作失败"
  362. br.ErrMsg = "获取视频失败, Err: " + e.Error()
  363. return
  364. }
  365. // 分类
  366. strClassifyIds := ""
  367. classifyRelates := make([]*eta_training_video.EtaTrainingVideoClassifyRelate, 0)
  368. {
  369. classifyOB := new(eta_training_video.EtaTrainingVideoClassify)
  370. classifies, e := classifyOB.GetItemsByCondition(``, make([]interface{}, 0), []string{}, "")
  371. if e != nil {
  372. br.Msg = "操作失败"
  373. br.ErrMsg = "获取分类失败, Err: " + e.Error()
  374. return
  375. }
  376. for _, c := range classifies {
  377. if c.EtaTrainingVideoClassifyId != req.ClassifyId {
  378. continue
  379. }
  380. strClassifyIds += fmt.Sprintf("%d,", req.ClassifyId)
  381. classifyRelates = append(classifyRelates, &eta_training_video.EtaTrainingVideoClassifyRelate{
  382. EtaTrainingVideoClassifyId: c.EtaTrainingVideoClassifyId,
  383. ClassifyParentId: c.ParentId,
  384. ClassifyName: c.ClassifyName,
  385. })
  386. // 分类所有父级
  387. if c.ParentId > 0 {
  388. parents := etaTrainingVideoService.GetClassifyParentsRecursive(classifies, c.ParentId)
  389. for _, p := range parents {
  390. strClassifyIds += fmt.Sprintf("%d,", p.EtaTrainingVideoClassifyId)
  391. classifyRelates = append(classifyRelates, &eta_training_video.EtaTrainingVideoClassifyRelate{
  392. EtaTrainingVideoClassifyId: p.EtaTrainingVideoClassifyId,
  393. ClassifyParentId: p.ParentId,
  394. ClassifyName: p.ClassifyName,
  395. })
  396. }
  397. }
  398. }
  399. strClassifyIds = strings.TrimRight(strClassifyIds, ",")
  400. }
  401. // 标签
  402. strTagIds := ""
  403. tagRelates := make([]*eta_training_video.EtaTrainingVideoTagRelate, 0)
  404. if len(req.TagIds) > 0 {
  405. tagOB := new(eta_training_video.EtaTrainingVideoTag)
  406. tags, e := tagOB.GetItemsByCondition(``, make([]interface{}, 0), []string{}, "")
  407. if e != nil {
  408. br.Msg = "操作失败"
  409. br.ErrMsg = "获取标签失败, Err: " + e.Error()
  410. return
  411. }
  412. tagMap := make(map[int]*eta_training_video.EtaTrainingVideoTag)
  413. for _, t := range tags {
  414. tagMap[t.EtaTrainingVideoTagId] = t
  415. }
  416. for _, r := range req.TagIds {
  417. t := tagMap[r]
  418. if t == nil {
  419. continue
  420. }
  421. tagRelates = append(tagRelates, &eta_training_video.EtaTrainingVideoTagRelate{
  422. EtaTrainingVideoTagId: r,
  423. TagName: t.TagName,
  424. })
  425. strTagIds += fmt.Sprintf("%d,", r)
  426. }
  427. strTagIds = strings.TrimRight(strTagIds, ",")
  428. }
  429. now := time.Now().Local()
  430. item.Title = req.Title
  431. item.Introduce = req.Introduce
  432. item.ClassifyIds = strClassifyIds
  433. item.TagIds = strTagIds
  434. item.CoverImg = req.CoverImg
  435. item.VideoUrl = req.VideoUrl
  436. item.ModifyTime = now
  437. cols := []string{"Title", "Introduce", "ClassifyIds", "TagIds", "CoverImg", "VideoUrl", "ModifyTime"}
  438. if e := item.UpdateVideoAndRelates(item, cols, classifyRelates, tagRelates); e != nil {
  439. br.Msg = "操作失败"
  440. br.ErrMsg = "更新视频及关联失败, Err: " + e.Error()
  441. return
  442. }
  443. // 操作日志
  444. go func() {
  445. logItem := new(eta_training_video.EtaTrainingVideoOpLog)
  446. logItem.EtaTrainingVideoId = item.EtaTrainingVideoId
  447. logItem.SysUserId = sysUser.AdminId
  448. logItem.SysRealName = sysUser.RealName
  449. logItem.OpType = eta_training_video.VideoOpTypeEdit
  450. logItem.OpData = string(this.Ctx.Input.RequestBody)
  451. logItem.CreateTime = now
  452. _ = logItem.Create()
  453. }()
  454. // 更新标签引用数
  455. go func() {
  456. tagOB := new(eta_training_video.EtaTrainingVideoTag)
  457. for _, t := range tagRelates {
  458. _ = tagOB.UpdateVideoTotal(t.EtaTrainingVideoTagId)
  459. }
  460. }()
  461. br.Data = item.EtaTrainingVideoId
  462. br.Ret = 200
  463. br.Success = true
  464. br.Msg = "操作成功"
  465. }
  466. // Publish
  467. // @Title 发布/取消视频
  468. // @Description 发布/取消视频
  469. // @Param request body eta_training_video.EtaTrainingVideoPublishReq true "type json string"
  470. // @Success 200 Ret=200 操作成功
  471. // @router /publish [post]
  472. func (this *EtaTrainingVideoController) Publish() {
  473. br := new(models.BaseResponse).Init()
  474. defer func() {
  475. if br.ErrMsg == "" {
  476. br.IsSendEmail = false
  477. }
  478. this.Data["json"] = br
  479. this.ServeJSON()
  480. }()
  481. sysUser := this.SysUser
  482. if sysUser == nil {
  483. br.Msg = "请登录"
  484. br.ErrMsg = "请登录,SysUser Is Empty"
  485. br.Ret = 408
  486. return
  487. }
  488. // 参数校验
  489. var req eta_training_video.EtaTrainingVideoPublishReq
  490. if e := json.Unmarshal(this.Ctx.Input.RequestBody, &req); e != nil {
  491. br.Msg = "参数解析异常!"
  492. br.ErrMsg = "参数解析失败,Err:" + e.Error()
  493. return
  494. }
  495. if req.VideoId <= 0 {
  496. br.Msg = "参数有误"
  497. br.ErrMsg = fmt.Sprint("参数有误, 视频ID: ", req.VideoId)
  498. return
  499. }
  500. if req.PublishState != 0 && req.PublishState != 1 {
  501. br.Msg = "参数有误"
  502. br.ErrMsg = fmt.Sprint("参数有误, 发布状态: ", req.PublishState)
  503. return
  504. }
  505. ob := new(eta_training_video.EtaTrainingVideo)
  506. item, e := ob.GetItemById(req.VideoId)
  507. if e != nil {
  508. if e.Error() == utils.ErrNoRow() {
  509. br.Msg = "视频不存在, 请刷新页面"
  510. return
  511. }
  512. br.Msg = "操作失败"
  513. br.ErrMsg = "获取ETA培训视频失败, Err: " + e.Error()
  514. return
  515. }
  516. now := time.Now().Local()
  517. item.PublishState = req.PublishState
  518. item.ModifyTime = now
  519. cols := []string{"PublishState", "ModifyTime"}
  520. if item.PublishState == 1 {
  521. item.PublishTime = now
  522. cols = append(cols, "PublishTime")
  523. }
  524. if e := item.Update(cols); e != nil {
  525. br.Msg = "操作失败"
  526. br.ErrMsg = "发布ETA培训视频失败, Err: " + e.Error()
  527. return
  528. }
  529. // 操作日志
  530. go func() {
  531. logItem := new(eta_training_video.EtaTrainingVideoOpLog)
  532. logItem.EtaTrainingVideoId = item.EtaTrainingVideoId
  533. logItem.SysUserId = sysUser.AdminId
  534. logItem.SysRealName = sysUser.RealName
  535. opTypeMap := map[int]int{0: eta_training_video.VideoOpTypeCancelPublish, 1: eta_training_video.VideoOpTypePublish}
  536. logItem.OpType = opTypeMap[req.PublishState]
  537. logItem.OpData = string(this.Ctx.Input.RequestBody)
  538. logItem.CreateTime = now
  539. _ = logItem.Create()
  540. }()
  541. br.Ret = 200
  542. br.Success = true
  543. br.Msg = "操作成功"
  544. }
  545. // Remove
  546. // @Title 删除视频
  547. // @Description 删除视频
  548. // @Param request body eta_training_video.EtaTrainingVideoRemoveReq true "type json string"
  549. // @Success 200 Ret=200 操作成功
  550. // @router /remove [post]
  551. func (this *EtaTrainingVideoController) Remove() {
  552. br := new(models.BaseResponse).Init()
  553. defer func() {
  554. if br.ErrMsg == "" {
  555. br.IsSendEmail = false
  556. }
  557. this.Data["json"] = br
  558. this.ServeJSON()
  559. }()
  560. sysUser := this.SysUser
  561. if sysUser == nil {
  562. br.Msg = "请登录"
  563. br.ErrMsg = "请登录,SysUser Is Empty"
  564. br.Ret = 408
  565. return
  566. }
  567. // 参数校验
  568. var req eta_training_video.EtaTrainingVideoRemoveReq
  569. if e := json.Unmarshal(this.Ctx.Input.RequestBody, &req); e != nil {
  570. br.Msg = "参数解析异常!"
  571. br.ErrMsg = "参数解析失败,Err:" + e.Error()
  572. return
  573. }
  574. if req.VideoId <= 0 {
  575. br.Msg = "参数有误"
  576. br.ErrMsg = fmt.Sprint("参数有误, 视频ID: ", req.VideoId)
  577. return
  578. }
  579. ob := new(eta_training_video.EtaTrainingVideo)
  580. item, e := ob.GetItemById(req.VideoId)
  581. if e != nil {
  582. if e.Error() == utils.ErrNoRow() {
  583. br.Ret = 200
  584. br.Success = true
  585. br.Msg = "操作成功"
  586. return
  587. }
  588. br.Msg = "操作失败"
  589. br.ErrMsg = "获取ETA培训视频失败, Err: " + e.Error()
  590. return
  591. }
  592. if e := item.Del(); e != nil {
  593. br.Msg = "操作失败"
  594. br.ErrMsg = "删除ETA培训视频失败, Err: " + e.Error()
  595. return
  596. }
  597. // 移除分类、标签关联, 更新标签引用数
  598. go func() {
  599. cr := new(eta_training_video.EtaTrainingVideoClassifyRelate)
  600. _ = cr.RemoveRelateByVideoId(item.EtaTrainingVideoId)
  601. tr := new(eta_training_video.EtaTrainingVideoTagRelate)
  602. _ = tr.RemoveRelateByVideoId(item.EtaTrainingVideoId)
  603. t := new(eta_training_video.EtaTrainingVideoTag)
  604. _ = t.RemoveVideoTotalByVideoId(item.EtaTrainingVideoId)
  605. }()
  606. // 操作日志
  607. go func() {
  608. logItem := new(eta_training_video.EtaTrainingVideoOpLog)
  609. logItem.EtaTrainingVideoId = item.EtaTrainingVideoId
  610. logItem.SysUserId = sysUser.AdminId
  611. logItem.SysRealName = sysUser.RealName
  612. logItem.OpType = eta_training_video.VideoOpTypeRemove
  613. b, e := json.Marshal(item)
  614. if e != nil {
  615. return
  616. }
  617. logItem.OpData = string(b)
  618. logItem.CreateTime = time.Now().Local()
  619. _ = logItem.Create()
  620. }()
  621. br.Ret = 200
  622. br.Success = true
  623. br.Msg = "操作成功"
  624. }
  625. // Detail
  626. // @Title 视频详情
  627. // @Description 视频详情
  628. // @Param VideoId query int false "视频ID"
  629. // @Success 200 Ret=200 操作成功
  630. // @router /detail [get]
  631. func (this *EtaTrainingVideoController) Detail() {
  632. br := new(models.BaseResponse).Init()
  633. defer func() {
  634. if br.ErrMsg == "" {
  635. br.IsSendEmail = false
  636. }
  637. this.Data["json"] = br
  638. this.ServeJSON()
  639. }()
  640. sysUser := this.SysUser
  641. if sysUser == nil {
  642. br.Msg = "请登录"
  643. br.ErrMsg = "请登录,SysUser Is Empty"
  644. br.Ret = 408
  645. return
  646. }
  647. videoId, _ := this.GetInt("VideoId", 0)
  648. if videoId <= 0 {
  649. br.Msg = "参数有误"
  650. br.ErrMsg = fmt.Sprint("参数有误, 视频ID: ", videoId)
  651. return
  652. }
  653. ob := new(eta_training_video.EtaTrainingVideo)
  654. item, e := ob.GetItemById(videoId)
  655. if e != nil {
  656. if e.Error() == utils.ErrNoRow() {
  657. br.Msg = "视频不存在, 请刷新页面"
  658. return
  659. }
  660. br.Msg = "获取失败"
  661. br.ErrMsg = "获取ETA培训视频失败, Err: " + e.Error()
  662. return
  663. }
  664. list := make([]*eta_training_video.EtaTrainingVideo, 0)
  665. list = append(list, item)
  666. formats, e := etaTrainingVideoService.FormatVideosToVideoItems(list)
  667. if e != nil {
  668. br.Msg = "获取失败"
  669. br.ErrMsg = "格式化视频信息失败, Err: " + e.Error()
  670. return
  671. }
  672. result := new(eta_training_video.EtaTrainingVideoItem)
  673. if len(formats) > 0 {
  674. result = formats[0]
  675. }
  676. br.Data = result
  677. br.Ret = 200
  678. br.Success = true
  679. br.Msg = "获取成功"
  680. }