english_video.go 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592
  1. package english_report
  2. import (
  3. "encoding/json"
  4. "github.com/rdlucklib/rdluck_tools/paging"
  5. "hongze/hz_crm_api/controllers"
  6. "hongze/hz_crm_api/models"
  7. "hongze/hz_crm_api/models/company"
  8. "hongze/hz_crm_api/services"
  9. "hongze/hz_crm_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.EnglishVideoDetail 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 := make([]*models.EnglishVideoList, 0)
  298. list, err = models.GetEnglishVideoList(condition, pars, startSize, pageSize)
  299. if err != nil {
  300. br.Msg = "获取失败"
  301. br.ErrMsg = "获取失败,Err:" + err.Error()
  302. return
  303. }
  304. page := paging.GetPaging(currentIndex, pageSize, total)
  305. resp := new(models.EnglishVideoListResp)
  306. if len(list) == 0 {
  307. list = make([]*models.EnglishVideoList, 0)
  308. resp.Paging = page
  309. resp.List = list
  310. br.Ret = 200
  311. br.Success = true
  312. br.Msg = "获取成功"
  313. br.Data = resp
  314. }
  315. // 查询分类信息
  316. var classifyIdSecondSlice []int
  317. classifyNameMap := make(map[int]*models.EnglishClassifyFullName)
  318. for _, item := range list {
  319. classifyIdSecondSlice = append(classifyIdSecondSlice, item.ClassifyIdSecond)
  320. }
  321. if len(classifyIdSecondSlice) > 0 {
  322. nameList, err := models.GetEnglishClassifyFullNameByIds(classifyIdSecondSlice)
  323. if err != nil {
  324. br.Msg = "获取分类名称失败"
  325. br.ErrMsg = "获取分类名称失败, ERR:" + err.Error()
  326. return
  327. }
  328. for _, v := range nameList {
  329. classifyNameMap[v.Id] = v
  330. }
  331. }
  332. // todo 获取邮件配置-是否有权限群发
  333. conf := new(models.EnglishReportEmailConf)
  334. authKey := "english_report_email_conf"
  335. confAuth, e := company.GetConfigDetailByCode(authKey)
  336. if e != nil {
  337. br.Msg = "获取失败"
  338. br.ErrMsg = "获取群发邮件权限失败, Err: " + e.Error()
  339. return
  340. }
  341. if confAuth.ConfigValue == "" {
  342. br.Msg = "获取失败"
  343. br.ErrMsg = "群发邮件配置为空"
  344. return
  345. }
  346. if e := json.Unmarshal([]byte(confAuth.ConfigValue), &conf); e != nil {
  347. br.Msg = "获取失败"
  348. br.ErrMsg = "群发邮件配置有误"
  349. return
  350. }
  351. authOk := false
  352. authArr := strings.Split(conf.SendAuthGroup, ",")
  353. if utils.InArrayByStr(authArr, sysUser.RoleTypeCode) {
  354. authOk = true
  355. }
  356. // todo 是否有群发邮件失败的记录,标记红点
  357. failList, e := models.GetEnglishReportEmailLogFailList(1)
  358. if e != nil {
  359. br.Msg = "获取失败"
  360. br.ErrMsg = "获取群发邮件记录失败, Err: " + e.Error()
  361. return
  362. }
  363. failMap := make(map[int]bool, 0)
  364. for i := range failList {
  365. failMap[failList[i].ReportId] = true
  366. }
  367. for _, item := range list {
  368. if item.State == 2 {
  369. //列表中展示分享地址
  370. //item.ShareUrl = "https://share.hzinsights.com/reportEn?code=" + item.ReportCode
  371. }
  372. item.EmailAuth = authOk
  373. if c, ok := failMap[item.Id]; ok {
  374. item.EmailHasFail = c
  375. }
  376. // 邮箱PV大于0的时候, 不展示最初版本的PV
  377. if item.PvEmail > 0 {
  378. item.Pv = 0
  379. }
  380. //处理分类名
  381. //处理分类名
  382. if n, ok := classifyNameMap[item.ClassifyIdSecond]; ok {
  383. if n.RootId == 0 {
  384. item.FullClassifyName = strings.Join([]string{n.ParentName, n.ClassifyName}, "/")
  385. } else {
  386. item.FullClassifyName = strings.Join([]string{n.RootName, n.ParentName, n.ClassifyName}, "/")
  387. }
  388. item.ClassifyIdRoot = n.RootId
  389. item.ClassifyNameRoot = n.RootName
  390. }
  391. }
  392. resp.Paging = page
  393. resp.List = list
  394. br.Ret = 200
  395. br.Success = true
  396. br.Msg = "获取成功"
  397. br.Data = resp
  398. }
  399. // @Title 发布报告接口
  400. // @Description 发布报告
  401. // @Param request body models.EnglishVideoReq true "type json string"
  402. // @Success 200 Ret=200 发布成功
  403. // @router /video/publish [post]
  404. func (this *EnglishVideoController) PublishVideo() {
  405. br := new(models.BaseResponse).Init()
  406. defer func() {
  407. this.Data["json"] = br
  408. this.ServeJSON()
  409. }()
  410. var req models.EnglishVideoReq
  411. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  412. if err != nil {
  413. br.Msg = "参数解析异常!"
  414. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  415. return
  416. }
  417. id := req.Id
  418. if id <= 0 {
  419. br.Msg = "请选择要发布的路演视频"
  420. return
  421. }
  422. videoInfo, err := models.GetEnglishVideoById(id)
  423. if err != nil {
  424. if err.Error() == utils.ErrNoRow() {
  425. br.Msg = "路演视频不存在"
  426. return
  427. }
  428. br.Msg = "获取路演视频失败"
  429. br.ErrMsg = "获取路演视频失败,Err:" + err.Error()
  430. return
  431. }
  432. var tmpErr error
  433. if videoInfo.VideoUrl == "" {
  434. br.Msg = "视频地址为空,不可发布"
  435. br.ErrMsg = "视频地址为空,不需要生成, id:" + strconv.Itoa(videoInfo.Id)
  436. return
  437. }
  438. if videoInfo.Title == "" {
  439. br.Msg = "标题为空,不可发布"
  440. br.ErrMsg = "标题为空,不需要生成, id:" + strconv.Itoa(videoInfo.Id)
  441. return
  442. }
  443. if videoInfo.State == 2 {
  444. br.Msg = "已发布,无需重复发布"
  445. return
  446. }
  447. if tmpErr = models.PublishEnglishVideoById(videoInfo.Id); tmpErr != nil {
  448. br.Msg = "路演视频发布失败"
  449. br.ErrMsg = "路演视频发布失败, Err:" + tmpErr.Error() + ", id:" + strconv.Itoa(videoInfo.Id)
  450. return
  451. }
  452. // 路演视频搜索
  453. go func() {
  454. _ = services.UpdateEnglishVideoEs(videoInfo.Id, 2)
  455. }()
  456. br.Ret = 200
  457. br.Success = true
  458. br.Msg = "发布成功"
  459. }
  460. // @Title 取消发布报告接口
  461. // @Description 取消发布报告
  462. // @Param request body models.EnglishVideoReq true "type json string"
  463. // @Success 200 Ret=200 取消发布成功
  464. // @router /video/publish/cancel [post]
  465. func (this *EnglishVideoController) PublishCancleVideo() {
  466. br := new(models.BaseResponse).Init()
  467. defer func() {
  468. this.Data["json"] = br
  469. this.ServeJSON()
  470. }()
  471. var req models.EnglishVideoReq
  472. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  473. if err != nil {
  474. br.Msg = "参数解析异常!"
  475. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  476. return
  477. }
  478. if req.Id <= 0 {
  479. br.Msg = "参数错误"
  480. br.ErrMsg = "参数错误,路演视频id不可为空"
  481. return
  482. }
  483. videoInfo, err := models.GetEnglishVideoById(req.Id)
  484. if err != nil {
  485. if err.Error() == utils.ErrNoRow() {
  486. br.Msg = "路演视频不存在"
  487. return
  488. }
  489. br.Msg = "获取路演视频失败"
  490. br.ErrMsg = "获取路演视频失败,Err:" + err.Error()
  491. return
  492. }
  493. if videoInfo.State == 1 {
  494. br.Msg = "已取消发布,无需重复取消"
  495. return
  496. }
  497. err = models.PublishCancelEnglishVideo(req.Id)
  498. if err != nil {
  499. br.Msg = "取消发布失败"
  500. br.ErrMsg = "取消发布失败,Err:" + err.Error()
  501. return
  502. }
  503. // 更新es里的报告状态
  504. go func() {
  505. _ = services.UpdateEnglishVideoEs(videoInfo.Id, 1)
  506. }()
  507. br.Ret = 200
  508. br.Success = true
  509. br.Msg = "取消发布成功"
  510. }
  511. // @Title 删除路演视频接口
  512. // @Description 删除路演视频
  513. // @Param request body models.EnglishVideoReq true "type json string"
  514. // @Success 200 Ret=200 删除成功
  515. // @router /video/delete [post]
  516. func (this *EnglishVideoController) Delete() {
  517. br := new(models.BaseResponse).Init()
  518. defer func() {
  519. this.Data["json"] = br
  520. this.ServeJSON()
  521. }()
  522. var req models.EnglishVideoReq
  523. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  524. if err != nil {
  525. br.Msg = "参数解析异常!"
  526. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  527. return
  528. }
  529. if req.Id <= 0 {
  530. br.Msg = "请选择要发布的路演视频"
  531. return
  532. }
  533. videoInfo, err := models.GetEnglishVideoById(req.Id)
  534. if err != nil {
  535. if err.Error() == utils.ErrNoRow() {
  536. br.Msg = "路演视频不存在"
  537. return
  538. }
  539. br.Msg = "获取路演视频失败"
  540. br.ErrMsg = "获取路演视频失败,Err:" + err.Error()
  541. return
  542. }
  543. // 更新es里的路演视频状态
  544. _ = services.UpdateEnglishVideoEs(videoInfo.Id, 1)
  545. if videoInfo.State == 2 {
  546. br.Msg = "路演视频已发布,不可删除"
  547. return
  548. }
  549. if err = models.DeleteEnglishVideo(req.Id); err != nil {
  550. br.Msg = "删除失败"
  551. br.ErrMsg = "删除路演视频失败, Err: " + err.Error()
  552. return
  553. }
  554. br.Ret = 200
  555. br.Success = true
  556. br.Msg = "删除成功"
  557. }