english_video.go 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552
  1. package english_report
  2. import (
  3. "encoding/json"
  4. "github.com/rdlucklib/rdluck_tools/paging"
  5. "eta/eta_api/controllers"
  6. "eta/eta_api/models"
  7. "eta/eta_api/models/company"
  8. "eta/eta_api/services"
  9. "eta/eta_api/utils"
  10. "strconv"
  11. "strings"
  12. )
  13. // EnglishVideoController 英文研报-线上路演
  14. type EnglishVideoController struct {
  15. controllers.BaseAuthController
  16. }
  17. // CoverList
  18. // @Title 封面库列表
  19. // @Description 封面库
  20. // @Param PageSize query int false "每页数据量"
  21. // @Param CurrentIndex query int false "页码"
  22. // @Success 200 {object} models.EnglishVideoCoverListResp
  23. // @router /video/cover/list [get]
  24. func (this *EnglishVideoController) CoverList() {
  25. br := new(models.BaseResponse).Init()
  26. br.IsSendEmail = false
  27. defer func() {
  28. this.Data["json"] = br
  29. this.ServeJSON()
  30. }()
  31. sysUser := this.SysUser
  32. if sysUser == nil {
  33. br.Msg = "请登录"
  34. br.ErrMsg = "请登录,SysUser Is Empty"
  35. br.Ret = 408
  36. return
  37. }
  38. condition := ""
  39. pars := make([]interface{}, 0)
  40. var startSize int
  41. pageSize, _ := this.GetInt("PageSize")
  42. currentIndex, _ := this.GetInt("CurrentIndex")
  43. if pageSize <= 0 {
  44. pageSize = utils.PageSize20
  45. }
  46. if currentIndex <= 0 {
  47. currentIndex = 1
  48. }
  49. startSize = paging.StartIndex(currentIndex, pageSize)
  50. total, resp, err := services.GetEnglishVideoCoverList(condition, pars, "", startSize, pageSize)
  51. if err != nil {
  52. br.Msg = "获取封面库列表失败"
  53. br.ErrMsg = "GetEnglishVideoCoverList ErrMsg:" + err.Error()
  54. return
  55. }
  56. page := paging.GetPaging(currentIndex, pageSize, total)
  57. resp.Paging = page
  58. br.Ret = 200
  59. br.Success = true
  60. br.Msg = "获取成功"
  61. br.Data = resp
  62. }
  63. // CoverSave
  64. // @Title 保存封面图
  65. // @Description 保存封面图
  66. // @Param request body request.EnglishVideoCoverSaveReq true "type json string"
  67. // @Success 200 string "操作成功"
  68. // @router /video/cover/save [post]
  69. func (this *EnglishVideoController) CoverSave() {
  70. br := new(models.BaseResponse).Init()
  71. br.IsSendEmail = false
  72. defer func() {
  73. this.Data["json"] = br
  74. this.ServeJSON()
  75. }()
  76. sysUser := this.SysUser
  77. if sysUser == nil {
  78. br.Msg = "请登录"
  79. br.ErrMsg = "请登录,SysUser Is Empty"
  80. br.Ret = 408
  81. return
  82. }
  83. var req models.EnglishVideoCoverSaveReq
  84. if err := json.Unmarshal(this.Ctx.Input.RequestBody, &req); err != nil {
  85. br.Msg = "参数解析异常!"
  86. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  87. return
  88. }
  89. if req.CoverName == "" {
  90. br.Msg = "请输入封面名称"
  91. return
  92. }
  93. if req.CoverUrl == "" {
  94. br.Msg = "请上传封面图"
  95. return
  96. }
  97. data, errMsg, err := services.SaveEnglishVideoCover(req.Id, req.CoverName, req.CoverUrl)
  98. if err != nil {
  99. br.Msg = errMsg
  100. br.ErrMsg = "SaveEnglishVideoCover ErrMsg:" + err.Error()
  101. return
  102. }
  103. br.Ret = 200
  104. br.Success = true
  105. br.Msg = "操作成功"
  106. br.Data = data
  107. }
  108. // CoverDelete
  109. // @Title 删除封面图
  110. // @Description 删除封面图
  111. // @Param request body models.EnglishVideoCoverOptionReq true "type json string"
  112. // @Success 200 string "操作成功"
  113. // @router /video/cover/delete [post]
  114. func (this *EnglishVideoController) CoverDelete() {
  115. br := new(models.BaseResponse).Init()
  116. br.IsSendEmail = false
  117. defer func() {
  118. this.Data["json"] = br
  119. this.ServeJSON()
  120. }()
  121. sysUser := this.SysUser
  122. if sysUser == nil {
  123. br.Msg = "请登录"
  124. br.ErrMsg = "请登录,SysUser Is Empty"
  125. br.Ret = 408
  126. return
  127. }
  128. var req models.EnglishVideoCoverOptionReq
  129. if err := json.Unmarshal(this.Ctx.Input.RequestBody, &req); err != nil {
  130. br.Msg = "参数解析异常!"
  131. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  132. return
  133. }
  134. if req.Id <= 0 {
  135. br.Msg = "参数有误"
  136. return
  137. }
  138. errMsg, err := services.SoftDeleteEnglishVideoCover(req.Id)
  139. if err != nil {
  140. br.Msg = errMsg
  141. br.ErrMsg = "SoftDeleteEnglishVideoCover ErrMsg:" + err.Error()
  142. return
  143. }
  144. br.Ret = 200
  145. br.Success = true
  146. br.Msg = "操作成功"
  147. }
  148. // @Title 新增/编辑路演视频
  149. // @Description 新增/编辑路演视频
  150. // @Param request body models.SaveEnglishVideoReq true "type json string"
  151. // @Success 200 {object} models.SaveEnglishVideoResp
  152. // @router /video/save [post]
  153. func (this *EnglishVideoController) Save() {
  154. br := new(models.BaseResponse).Init()
  155. defer func() {
  156. this.Data["json"] = br
  157. this.ServeJSON()
  158. }()
  159. sysUser := this.SysUser
  160. if sysUser == nil {
  161. br.Msg = "请登录"
  162. br.ErrMsg = "请登录,SysUser Is Empty"
  163. br.Ret = 408
  164. return
  165. }
  166. var req models.SaveEnglishVideoReq
  167. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  168. if err != nil {
  169. br.Msg = "参数解析异常!"
  170. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  171. return
  172. }
  173. if req.Title == "" {
  174. br.Msg = "请输入标题"
  175. return
  176. }
  177. if req.ClassifyIdFirst <= 0 {
  178. br.Msg = "请输入一级分类"
  179. return
  180. }
  181. if req.ClassifyIdSecond <= 0 {
  182. br.Msg = "请选择二级分类"
  183. return
  184. }
  185. if req.VideoUrl == "" {
  186. br.Msg = "请输入视频地址"
  187. return
  188. }
  189. if req.VideoCoverUrl == "" {
  190. br.Msg = "请输入视频封面地址"
  191. return
  192. }
  193. if req.VideoSeconds == "" {
  194. br.Msg = "请输入视频时长"
  195. return
  196. }
  197. if req.Overview == "" {
  198. br.Msg = "请输入overview"
  199. return
  200. }
  201. if req.Abstract == "" {
  202. br.Msg = "请输入摘要"
  203. return
  204. }
  205. id, videoCode, err, errMsg := services.SaveEnglishVideo(req, sysUser)
  206. if err != nil {
  207. br.Msg = err.Error()
  208. br.ErrMsg = errMsg
  209. return
  210. }
  211. resp := new(models.SaveEnglishVideoResp)
  212. resp.Id = id
  213. resp.VideoCode = videoCode
  214. br.Ret = 200
  215. br.Success = true
  216. br.Msg = "保存成功"
  217. br.Data = resp
  218. }
  219. // @Title 获取路演视频详情接口
  220. // @Description 获取路演视频详情接口
  221. // @Param request body models.ReportDetailReq true "type json string"
  222. // @Success 200 {object} models.EnglishVideoDetailView
  223. // @router /video/detail [get]
  224. func (this *EnglishVideoController) Detail() {
  225. br := new(models.BaseResponse).Init()
  226. defer func() {
  227. this.Data["json"] = br
  228. this.ServeJSON()
  229. }()
  230. id, err := this.GetInt("Id")
  231. if err != nil {
  232. br.Msg = "获取参数失败!"
  233. br.ErrMsg = "获取参数失败,Err:" + err.Error()
  234. return
  235. }
  236. if id <= 0 {
  237. br.Msg = "请选择路演视频记录"
  238. return
  239. }
  240. item, err := models.GetEnglishVideoById(id)
  241. if err != nil {
  242. if err.Error() == utils.ErrNoRow() {
  243. br.Msg = "路演视频不存在"
  244. return
  245. }
  246. br.Msg = "获取失败"
  247. br.ErrMsg = "获取失败,Err:" + err.Error()
  248. return
  249. }
  250. br.Ret = 200
  251. br.Success = true
  252. br.Msg = "获取成功"
  253. br.Data = item
  254. }
  255. // @Title 获取报告列表接口
  256. // @Description 获取报告列表
  257. // @Param PageSize query int true "每页数据条数"
  258. // @Param CurrentIndex query int true "当前页页码,从1开始"
  259. // @Param KeyWord query string true "搜索关键词"
  260. // @Success 200 {object} models.ReportListResp
  261. // @router /video/list [get]
  262. func (this *EnglishVideoController) List() {
  263. br := new(models.BaseResponse).Init()
  264. defer func() {
  265. this.Data["json"] = br
  266. this.ServeJSON()
  267. }()
  268. sysUser := this.SysUser
  269. if sysUser == nil {
  270. br.Msg = "请登录"
  271. br.ErrMsg = "请登录,SysUser Is Empty"
  272. br.Ret = 408
  273. return
  274. }
  275. pageSize, _ := this.GetInt("PageSize")
  276. currentIndex, _ := this.GetInt("CurrentIndex")
  277. keyWord := this.GetString("KeyWord")
  278. var startSize int
  279. if pageSize <= 0 {
  280. pageSize = utils.PageSize20
  281. }
  282. if currentIndex <= 0 {
  283. currentIndex = 1
  284. }
  285. startSize = utils.StartIndex(currentIndex, pageSize)
  286. var condition string
  287. var pars []interface{}
  288. if keyWord != "" {
  289. condition += ` AND title LIKE '%` + keyWord + `%' `
  290. }
  291. total, err := models.GetEnglishVideoListCount(condition, pars)
  292. if err != nil {
  293. br.Msg = "获取失败"
  294. br.ErrMsg = "获取失败,Err:" + err.Error()
  295. return
  296. }
  297. list, err := models.GetEnglishVideoList(condition, pars, startSize, pageSize)
  298. if err != nil {
  299. br.Msg = "获取失败"
  300. br.ErrMsg = "获取失败,Err:" + err.Error()
  301. return
  302. }
  303. // todo 获取邮件配置-是否有权限群发
  304. conf := new(models.EnglishReportEmailConf)
  305. authKey := "english_report_email_conf"
  306. confAuth, e := company.GetConfigDetailByCode(authKey)
  307. if e != nil {
  308. br.Msg = "获取失败"
  309. br.ErrMsg = "获取群发邮件权限失败, Err: " + e.Error()
  310. return
  311. }
  312. if confAuth.ConfigValue == "" {
  313. br.Msg = "获取失败"
  314. br.ErrMsg = "群发邮件配置为空"
  315. return
  316. }
  317. if e := json.Unmarshal([]byte(confAuth.ConfigValue), &conf); e != nil {
  318. br.Msg = "获取失败"
  319. br.ErrMsg = "群发邮件配置有误"
  320. return
  321. }
  322. authOk := false
  323. authArr := strings.Split(conf.SendAuthGroup, ",")
  324. if utils.InArrayByStr(authArr, sysUser.RoleTypeCode) {
  325. authOk = true
  326. }
  327. // todo 是否有群发邮件失败的记录,标记红点
  328. failList, e := models.GetEnglishReportEmailLogFailList(1)
  329. if e != nil {
  330. br.Msg = "获取失败"
  331. br.ErrMsg = "获取群发邮件记录失败, Err: " + e.Error()
  332. return
  333. }
  334. failMap := make(map[int]bool, 0)
  335. for i := range failList {
  336. failMap[failList[i].ReportId] = true
  337. }
  338. for _, item := range list {
  339. if item.State == 2 {
  340. //列表中展示分享地址
  341. //item.ShareUrl = "https://share.hzinsights.com/reportEn?code=" + item.ReportCode
  342. }
  343. item.EmailAuth = authOk
  344. if c, ok := failMap[item.Id]; ok {
  345. item.EmailHasFail = c
  346. }
  347. // 邮箱PV大于0的时候, 不展示最初版本的PV
  348. if item.PvEmail > 0 {
  349. item.Pv = 0
  350. }
  351. }
  352. page := paging.GetPaging(currentIndex, pageSize, total)
  353. resp := new(models.EnglishVideoListResp)
  354. resp.Paging = page
  355. resp.List = list
  356. br.Ret = 200
  357. br.Success = true
  358. br.Msg = "获取成功"
  359. br.Data = resp
  360. }
  361. // @Title 发布报告接口
  362. // @Description 发布报告
  363. // @Param request body models.EnglishVideoReq true "type json string"
  364. // @Success 200 Ret=200 发布成功
  365. // @router /video/publish [post]
  366. func (this *EnglishVideoController) PublishVideo() {
  367. br := new(models.BaseResponse).Init()
  368. defer func() {
  369. this.Data["json"] = br
  370. this.ServeJSON()
  371. }()
  372. var req models.EnglishVideoReq
  373. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  374. if err != nil {
  375. br.Msg = "参数解析异常!"
  376. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  377. return
  378. }
  379. id := req.Id
  380. if id <= 0 {
  381. br.Msg = "请选择要发布的路演视频"
  382. return
  383. }
  384. videoInfo, err := models.GetEnglishVideoById(id)
  385. if err != nil {
  386. if err.Error() == utils.ErrNoRow() {
  387. br.Msg = "路演视频不存在"
  388. return
  389. }
  390. br.Msg = "获取路演视频失败"
  391. br.ErrMsg = "获取路演视频失败,Err:" + err.Error()
  392. return
  393. }
  394. var tmpErr error
  395. if videoInfo.VideoUrl == "" {
  396. br.Msg = "视频地址为空,不可发布"
  397. br.ErrMsg = "视频地址为空,不需要生成, id:" + strconv.Itoa(videoInfo.Id)
  398. return
  399. }
  400. if videoInfo.Title == "" {
  401. br.Msg = "标题为空,不可发布"
  402. br.ErrMsg = "标题为空,不需要生成, id:" + strconv.Itoa(videoInfo.Id)
  403. return
  404. }
  405. if videoInfo.State == 2 {
  406. br.Msg = "已发布,无需重复发布"
  407. return
  408. }
  409. if tmpErr = models.PublishEnglishVideoById(videoInfo.Id); tmpErr != nil {
  410. br.Msg = "路演视频发布失败"
  411. br.ErrMsg = "路演视频发布失败, Err:" + tmpErr.Error() + ", id:" + strconv.Itoa(videoInfo.Id)
  412. return
  413. }
  414. // 路演视频搜索
  415. go func() {
  416. _ = services.UpdateEnglishVideoEs(videoInfo.Id, 2)
  417. }()
  418. br.Ret = 200
  419. br.Success = true
  420. br.Msg = "发布成功"
  421. }
  422. // @Title 取消发布报告接口
  423. // @Description 取消发布报告
  424. // @Param request body models.EnglishVideoReq true "type json string"
  425. // @Success 200 Ret=200 取消发布成功
  426. // @router /video/publish/cancel [post]
  427. func (this *EnglishVideoController) PublishCancleVideo() {
  428. br := new(models.BaseResponse).Init()
  429. defer func() {
  430. this.Data["json"] = br
  431. this.ServeJSON()
  432. }()
  433. var req models.EnglishVideoReq
  434. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  435. if err != nil {
  436. br.Msg = "参数解析异常!"
  437. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  438. return
  439. }
  440. if req.Id <= 0 {
  441. br.Msg = "参数错误"
  442. br.ErrMsg = "参数错误,路演视频id不可为空"
  443. return
  444. }
  445. videoInfo, err := models.GetEnglishVideoById(req.Id)
  446. if err != nil {
  447. if err.Error() == utils.ErrNoRow() {
  448. br.Msg = "路演视频不存在"
  449. return
  450. }
  451. br.Msg = "获取路演视频失败"
  452. br.ErrMsg = "获取路演视频失败,Err:" + err.Error()
  453. return
  454. }
  455. if videoInfo.State == 1 {
  456. br.Msg = "已取消发布,无需重复取消"
  457. return
  458. }
  459. err = models.PublishCancelEnglishVideo(req.Id)
  460. if err != nil {
  461. br.Msg = "取消发布失败"
  462. br.ErrMsg = "取消发布失败,Err:" + err.Error()
  463. return
  464. }
  465. // 更新es里的报告状态
  466. go func() {
  467. _ = services.UpdateEnglishVideoEs(videoInfo.Id, 1)
  468. }()
  469. br.Ret = 200
  470. br.Success = true
  471. br.Msg = "取消发布成功"
  472. }
  473. // @Title 删除路演视频接口
  474. // @Description 删除路演视频
  475. // @Param request body models.EnglishVideoReq true "type json string"
  476. // @Success 200 Ret=200 删除成功
  477. // @router /video/delete [post]
  478. func (this *EnglishVideoController) Delete() {
  479. br := new(models.BaseResponse).Init()
  480. defer func() {
  481. this.Data["json"] = br
  482. this.ServeJSON()
  483. }()
  484. var req models.EnglishVideoReq
  485. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  486. if err != nil {
  487. br.Msg = "参数解析异常!"
  488. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  489. return
  490. }
  491. if req.Id <= 0 {
  492. br.Msg = "请选择要发布的路演视频"
  493. return
  494. }
  495. videoInfo, err := models.GetEnglishVideoById(req.Id)
  496. if err != nil {
  497. if err.Error() == utils.ErrNoRow() {
  498. br.Msg = "路演视频不存在"
  499. return
  500. }
  501. br.Msg = "获取路演视频失败"
  502. br.ErrMsg = "获取路演视频失败,Err:" + err.Error()
  503. return
  504. }
  505. // 更新es里的路演视频状态
  506. _ = services.UpdateEnglishVideoEs(videoInfo.Id, 1)
  507. if videoInfo.State == 2 {
  508. br.Msg = "路演视频已发布,不可删除"
  509. return
  510. }
  511. if err = models.DeleteEnglishVideo(req.Id); err != nil {
  512. br.Msg = "删除失败"
  513. br.ErrMsg = "删除路演视频失败, Err: " + err.Error()
  514. return
  515. }
  516. br.Ret = 200
  517. br.Success = true
  518. br.Msg = "删除成功"
  519. }