road_video.go 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762
  1. package yb
  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. ybModels "hongze/hz_crm_api/models/yb"
  9. "hongze/hz_crm_api/models/yb/request"
  10. "hongze/hz_crm_api/services"
  11. "hongze/hz_crm_api/services/yb"
  12. "hongze/hz_crm_api/utils"
  13. "strings"
  14. "time"
  15. )
  16. // RoadVideoController 研报视频社区
  17. type RoadVideoController struct {
  18. controllers.BaseAuthController
  19. }
  20. // List
  21. // @Title 视频列表
  22. // @Description 视频列表
  23. // @Param Keywords query string false "关键词"
  24. // @Param SortParam query string false "排序字段参数,用来排序的字段, 枚举值:'ClickNum':点击量"
  25. // @Param SortType query string true "如何排序,是正序还是倒序,枚举值:`asc 正序`,`desc 倒叙`"
  26. // @Success 200 {object} response.CommunityQuestionListResp
  27. // @router /road/video/list [get]
  28. func (r *RoadVideoController) List() {
  29. br := new(models.BaseResponse).Init()
  30. br.IsSendEmail = false
  31. defer func() {
  32. r.Data["json"] = br
  33. r.ServeJSON()
  34. }()
  35. sysUser := r.SysUser
  36. if sysUser == nil {
  37. br.Msg = "请登录"
  38. br.ErrMsg = "请登录,SysUser Is Empty"
  39. br.Ret = 408
  40. return
  41. }
  42. condition := ""
  43. pars := make([]interface{}, 0)
  44. keywords := r.GetString("Keywords", "")
  45. if keywords != "" {
  46. keywords = "%" + keywords + "%"
  47. condition += ` AND v.title LIKE ? `
  48. pars = append(pars, keywords)
  49. }
  50. var startSize int
  51. pageSize, _ := r.GetInt("PageSize")
  52. currentIndex, _ := r.GetInt("CurrentIndex")
  53. if pageSize <= 0 {
  54. pageSize = utils.PageSize20
  55. }
  56. if currentIndex <= 0 {
  57. currentIndex = 1
  58. }
  59. startSize = paging.StartIndex(currentIndex, pageSize)
  60. // 排序相关
  61. sortParam := r.GetString("SortParam")
  62. sortType := r.GetString("SortType")
  63. orderStr := ""
  64. if sortType != "" && strings.ToLower(sortType) != "desc" && strings.ToLower(sortType) != "asc" {
  65. br.Msg = "请输入正确的排序类型"
  66. return
  67. }
  68. if sortParam == "ClickNum" {
  69. orderStr = " ORDER BY l.click_num"
  70. if sortType != "" {
  71. orderStr += " " + sortType
  72. } else {
  73. orderStr += " DESC"
  74. }
  75. orderStr += ", v.modify_time DESC"
  76. }
  77. total, resp, err, errMsg := yb.GetRoadVideoList(condition, pars, orderStr, startSize, pageSize)
  78. if err != nil {
  79. br.Msg = errMsg
  80. br.ErrMsg = err.Error()
  81. return
  82. }
  83. page := paging.GetPaging(currentIndex, pageSize, total)
  84. resp.Paging = page
  85. br.Ret = 200
  86. br.Success = true
  87. br.Msg = "获取成功"
  88. br.Data = resp
  89. }
  90. // Save
  91. // @Title 保存视频
  92. // @Description 保存视频
  93. // @Param request body request.RoadVideoSaveReq true "type json string"
  94. // @Success 200 string "操作成功"
  95. // @router /road/video/save [post]
  96. func (r *RoadVideoController) Save() {
  97. br := new(models.BaseResponse).Init()
  98. br.IsSendEmail = false
  99. defer func() {
  100. r.Data["json"] = br
  101. r.ServeJSON()
  102. }()
  103. sysUser := r.SysUser
  104. if sysUser == nil {
  105. br.Msg = "请登录"
  106. br.ErrMsg = "请登录,SysUser Is Empty"
  107. br.Ret = 408
  108. return
  109. }
  110. var req request.RoadVideoSaveReq
  111. if err := json.Unmarshal(r.Ctx.Input.RequestBody, &req); err != nil {
  112. br.Msg = "参数解析异常!"
  113. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  114. return
  115. }
  116. if req.Title == "" {
  117. br.Msg = "请输入标题"
  118. return
  119. }
  120. if req.ChartPermissionIds == "" {
  121. br.Msg = "请选择品种"
  122. return
  123. }
  124. if req.CoverImgUrl == "" {
  125. br.Msg = "请上传封面图"
  126. return
  127. }
  128. if req.VideoUrl == "" {
  129. br.Msg = "请上传视频"
  130. return
  131. }
  132. data, errMsg, err := yb.SaveRoadVideo(sysUser, req.VideoId, req.ReportId, req.ChartPermissionIds, req.Title, req.CoverImgUrl, req.VideoUrl, req.VideoSeconds)
  133. if err != nil {
  134. br.Msg = errMsg
  135. br.ErrMsg = "Yb-SaveVideo ErrMsg:" + err.Error()
  136. return
  137. }
  138. br.Ret = 200
  139. br.Success = true
  140. br.Msg = "操作成功"
  141. br.Data = data
  142. }
  143. // Delete
  144. // @Title 删除视频
  145. // @Description 删除视频
  146. // @Param request body request.RoadVideoOptionReq true "type json string"
  147. // @Success 200 string "操作成功"
  148. // @router /road/video/delete [post]
  149. func (r *RoadVideoController) Delete() {
  150. br := new(models.BaseResponse).Init()
  151. br.IsSendEmail = false
  152. defer func() {
  153. r.Data["json"] = br
  154. r.ServeJSON()
  155. }()
  156. sysUser := r.SysUser
  157. if sysUser == nil {
  158. br.Msg = "请登录"
  159. br.ErrMsg = "请登录,SysUser Is Empty"
  160. br.Ret = 408
  161. return
  162. }
  163. var req request.RoadVideoOptionReq
  164. if err := json.Unmarshal(r.Ctx.Input.RequestBody, &req); err != nil {
  165. br.Msg = "参数解析异常!"
  166. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  167. return
  168. }
  169. if req.VideoId <= 0 {
  170. br.Msg = "参数有误"
  171. return
  172. }
  173. errMsg, err := yb.SoftDeleteRoadVideo(req.VideoId)
  174. if err != nil {
  175. br.Msg = errMsg
  176. br.ErrMsg = "Yb-DeleteVideo ErrMsg:" + err.Error()
  177. return
  178. }
  179. br.Ret = 200
  180. br.Success = true
  181. br.Msg = "操作成功"
  182. }
  183. // Publish
  184. // @Title 发布/取消视频
  185. // @Description 发布/取消视频
  186. // @Param request body request.RoadVideoPublishReq true "type json string"
  187. // @Success 200 string "操作成功"
  188. // @router /road/video/publish [post]
  189. func (r *RoadVideoController) Publish() {
  190. br := new(models.BaseResponse).Init()
  191. br.IsSendEmail = false
  192. defer func() {
  193. r.Data["json"] = br
  194. r.ServeJSON()
  195. }()
  196. sysUser := r.SysUser
  197. if sysUser == nil {
  198. br.Msg = "请登录"
  199. br.ErrMsg = "请登录,SysUser Is Empty"
  200. br.Ret = 408
  201. return
  202. }
  203. var req request.RoadVideoPublishReq
  204. if err := json.Unmarshal(r.Ctx.Input.RequestBody, &req); err != nil {
  205. br.Msg = "参数解析异常!"
  206. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  207. return
  208. }
  209. if req.VideoId <= 0 {
  210. br.Msg = "参数有误"
  211. return
  212. }
  213. errMsg, err := yb.PublishRoadVideo(req.VideoId, req.PublishState)
  214. if err != nil {
  215. br.Msg = errMsg
  216. br.ErrMsg = "Yb-PublishVideo ErrMsg:" + err.Error()
  217. return
  218. }
  219. br.Ret = 200
  220. br.Success = true
  221. br.Msg = "操作成功"
  222. }
  223. // SendThs
  224. // @Title 推送客群消息
  225. // @Description 推送客群消息
  226. // @Param request body request.RoadVideoOptionReq true "type json string"
  227. // @Success 200 string "操作成功"
  228. // @router /road/video/send_ths [post]
  229. func (r *RoadVideoController) SendThs() {
  230. br := new(models.BaseResponse).Init()
  231. br.IsSendEmail = false
  232. defer func() {
  233. r.Data["json"] = br
  234. r.ServeJSON()
  235. }()
  236. sysUser := r.SysUser
  237. if sysUser == nil {
  238. br.Msg = "请登录"
  239. br.ErrMsg = "请登录,SysUser Is Empty"
  240. br.Ret = 408
  241. return
  242. }
  243. var req request.RoadVideoOptionReq
  244. if err := json.Unmarshal(r.Ctx.Input.RequestBody, &req); err != nil {
  245. br.Msg = "参数解析异常!"
  246. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  247. return
  248. }
  249. if req.VideoId <= 0 {
  250. br.Msg = "参数有误"
  251. return
  252. }
  253. errMsg, err := yb.SendRoadVideoThsMsg(req.VideoId)
  254. if err != nil {
  255. br.Msg = errMsg
  256. br.ErrMsg = "Yb-SendVideoThsMsg ErrMsg:" + err.Error()
  257. return
  258. }
  259. br.Ret = 200
  260. br.Success = true
  261. br.Msg = "操作成功"
  262. }
  263. // VideoPlayLogList
  264. // @Title 获取视频点击量列表
  265. // @Description 获取视频点击量列表
  266. // @Param VideoId query int false "视频ID"
  267. // @Param SortType query int false "播放时长排序:默认倒序; 1-倒序(多一个数方便前端回显); 2-正序"
  268. // @Success 200 {object} response.QuestionClickLogListResp
  269. // @router /road/video/click/logs [get]
  270. func (r *RoadVideoController) VideoPlayLogList() {
  271. br := new(models.BaseResponse).Init()
  272. defer func() {
  273. r.Data["json"] = br
  274. r.ServeJSON()
  275. }()
  276. sysUser := r.SysUser
  277. if sysUser == nil {
  278. br.Msg = "请登录"
  279. br.ErrMsg = "请登录,SysUser Is Empty"
  280. br.Ret = 408
  281. return
  282. }
  283. videoId, _ := r.GetInt("VideoId")
  284. if videoId <= 0 {
  285. br.Msg = "请输入正确的视频ID"
  286. return
  287. }
  288. // 播放时长排序:1-DESC; 2-ASC;
  289. sortType, _ := r.GetInt("SortType")
  290. var startSize int
  291. pageSize, _ := r.GetInt("PageSize")
  292. currentIndex, _ := r.GetInt("CurrentIndex")
  293. if pageSize <= 0 {
  294. pageSize = utils.PageSize20
  295. }
  296. if currentIndex <= 0 {
  297. currentIndex = 1
  298. }
  299. startSize = paging.StartIndex(currentIndex, pageSize)
  300. total, resp, err := yb.GetVideoPlayLogList(videoId, 2, startSize, pageSize, sortType)
  301. if err != nil {
  302. br.Msg = "获取点击量详情列表失败"
  303. br.ErrMsg = "VideoPlayLogList ErrMsg:" + err.Error()
  304. return
  305. }
  306. page := paging.GetPaging(currentIndex, pageSize, int(total))
  307. resp.Paging = page
  308. br.Ret = 200
  309. br.Success = true
  310. br.Msg = "获取成功"
  311. br.Data = resp
  312. }
  313. // SendTemplateMsg
  314. // @Title 推送模板消息
  315. // @Description 推送模板消息
  316. // @Param request body request.RoadVideoOptionReq true "type json string"
  317. // @Success 200 string "操作成功"
  318. // @router /road/video/send_template_msg [post]
  319. func (r *RoadVideoController) SendTemplateMsg() {
  320. br := new(models.BaseResponse).Init()
  321. br.IsSendEmail = false
  322. defer func() {
  323. r.Data["json"] = br
  324. r.ServeJSON()
  325. }()
  326. sysUser := r.SysUser
  327. if sysUser == nil {
  328. br.Msg = "请登录"
  329. br.ErrMsg = "请登录,SysUser Is Empty"
  330. br.Ret = 408
  331. return
  332. }
  333. var req request.RoadVideoOptionReq
  334. if err := json.Unmarshal(r.Ctx.Input.RequestBody, &req); err != nil {
  335. br.Msg = "参数解析异常!"
  336. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  337. return
  338. }
  339. if req.VideoId <= 0 {
  340. br.Msg = "参数有误"
  341. return
  342. }
  343. errMsg, err := yb.SendRoadVideoTemplateMsg(req.VideoId)
  344. if err != nil {
  345. br.Msg = errMsg
  346. br.ErrMsg = "Yb-SendRoadVideoTemplateMsg ErrMsg:" + err.Error()
  347. return
  348. }
  349. br.Ret = 200
  350. br.Success = true
  351. br.Msg = "操作成功"
  352. }
  353. // GetPermission
  354. // @Title 查询品种权限
  355. // @Description 查询品种权限
  356. // @Param request body request.RoadVideoOptionReq true "type json string"
  357. // @Success 200 string "操作成功"
  358. // @router /road/permission [get]
  359. func (r *RoadVideoController) GetPermission() {
  360. br := new(models.BaseResponse).Init()
  361. defer func() {
  362. r.Data["json"] = br
  363. r.ServeJSON()
  364. }()
  365. sysUser := r.SysUser
  366. if sysUser == nil {
  367. br.Msg = "请登录"
  368. br.ErrMsg = "请登录,SysUser Is Empty"
  369. br.Ret = 408
  370. return
  371. }
  372. ret, err := yb.GetFiccPermission()
  373. if err != nil {
  374. br.Msg = "查询权限出错"
  375. br.ErrMsg = "Yb-SendVideoThsMsg ErrMsg:" + err.Error()
  376. return
  377. }
  378. br.Ret = 200
  379. br.Success = true
  380. br.Msg = "操作成功"
  381. br.Data = ret
  382. }
  383. // TwoWeekClassifyList
  384. // @Title 路演视频-关联报告类型列表
  385. // @Description 路演视频-关联报告类型列表
  386. // @Success 200 {object} models.SimpleClassifyList
  387. // @router /road/video/two_week_classify_list [get]
  388. func (r *RoadVideoController) TwoWeekClassifyList() {
  389. br := new(models.BaseResponse).Init()
  390. defer func() {
  391. r.Data["json"] = br
  392. r.ServeJSON()
  393. }()
  394. sysUser := r.SysUser
  395. if sysUser == nil {
  396. br.Msg = "请登录"
  397. br.ErrMsg = "请登录,SysUser Is Empty"
  398. br.Ret = 408
  399. return
  400. }
  401. // 2023-04-19 取classify表relate_video=1的二级分类, 但是需要分层级, 所以对应的一级分类也要组合起来
  402. list, e := models.GetAllClassifyByRelateVideo()
  403. if e != nil {
  404. br.Msg = "获取失败"
  405. br.ErrMsg = "获取路演视频可选报告分类失败, Err: " + e.Error()
  406. return
  407. }
  408. // 获取父级的分类
  409. {
  410. idMap := make(map[int]bool)
  411. currParentClassifyIdList := make([]int, 0)
  412. for _, v := range list {
  413. idMap[v.Id] = true
  414. if v.ParentId > 0 {
  415. currParentClassifyIdList = append(currParentClassifyIdList, v.ParentId)
  416. }
  417. }
  418. findList := list
  419. list = make([]*models.Classify, 0)
  420. tmpList, tmpErr := services.GetParentClassifyListByParentIdList(currParentClassifyIdList)
  421. if tmpErr != nil {
  422. br.Msg = "获取失败"
  423. br.ErrMsg = "获取上级分类信息失败,Err:" + tmpErr.Error()
  424. return
  425. }
  426. for _, v := range tmpList {
  427. if _, ok := idMap[v.Id]; !ok {
  428. list = append(list, v)
  429. }
  430. }
  431. list = append(list, findList...)
  432. }
  433. allList := make([]*models.SimpleClassifyList, 0)
  434. for _, v := range list {
  435. allList = append(allList, &models.SimpleClassifyList{
  436. Id: v.Id,
  437. ClassifyName: v.ClassifyName,
  438. ParentId: v.ParentId,
  439. Sort: v.Sort,
  440. CreateTime: v.CreateTime,
  441. Child: make([]*models.SimpleClassifyList, 0),
  442. })
  443. }
  444. // 先将分类列表排序
  445. services.SortClassifyListBySortAndCreateTime(allList)
  446. // 接着转换结构
  447. allList = services.GetClassifyListTreeRecursive(allList, 0)
  448. br.Ret = 200
  449. br.Success = true
  450. br.Msg = "操作成功"
  451. br.Data = allList
  452. }
  453. // SimpleReportList
  454. // @Title 路演视频选择报告-列表
  455. // @Description 路演视频选择报告-列表
  456. // @Param ClassifyIdSecond query int false "二级分类ID"
  457. // @Param Keyword query string false "关键词-报告标题"
  458. // @Success 200 string "获取成功"
  459. // @router /road/video/simple_report_list [get]
  460. func (r *RoadVideoController) SimpleReportList() {
  461. br := new(models.BaseResponse).Init()
  462. defer func() {
  463. r.Data["json"] = br
  464. r.ServeJSON()
  465. }()
  466. sysUser := r.SysUser
  467. if sysUser == nil {
  468. br.Msg = "请登录"
  469. br.ErrMsg = "请登录,SysUser Is Empty"
  470. br.Ret = 408
  471. return
  472. }
  473. cond := ` AND state = 2`
  474. pars := make([]interface{}, 0)
  475. classifyIdSecond, _ := r.GetInt("ClassifyIdSecond", 0)
  476. if classifyIdSecond <= 0 {
  477. // 2023-03-03 直接取classify表relate_video=1的二级分类下的报告
  478. //classifyCond := ` AND parent_id > 0 AND relate_video = 1`
  479. classifyCond := ` AND relate_video = 1`
  480. classifyPars := make([]interface{}, 0)
  481. classifyList, e := models.GetClassifyByCondition(classifyCond, "", classifyPars)
  482. if e != nil {
  483. br.Msg = "获取失败"
  484. br.ErrMsg = "获取路演视频可选报告分类失败, Err: " + e.Error()
  485. return
  486. }
  487. var hasChild bool
  488. firstClassifyIds := make([]int, 0)
  489. secondClassifyIds := make([]int, 0)
  490. thirdClassifyIds := make([]int, 0)
  491. for _, c := range classifyList {
  492. switch c.Level {
  493. case 1:
  494. firstClassifyIds = append(firstClassifyIds, c.Id)
  495. hasChild = true
  496. case 2:
  497. secondClassifyIds = append(secondClassifyIds, c.Id)
  498. hasChild = true
  499. case 3:
  500. thirdClassifyIds = append(thirdClassifyIds, c.Id)
  501. hasChild = true
  502. }
  503. }
  504. if hasChild {
  505. classifyCondList := make([]string, 0)
  506. if len(firstClassifyIds) > 0 {
  507. classifyCondList = append(classifyCondList, ` classify_id_first IN ( `+utils.GetOrmInReplace(len(firstClassifyIds))+` ) `)
  508. pars = append(pars, firstClassifyIds)
  509. }
  510. if len(secondClassifyIds) > 0 {
  511. classifyCondList = append(classifyCondList, ` classify_id_second IN ( `+utils.GetOrmInReplace(len(secondClassifyIds))+` ) `)
  512. pars = append(pars, secondClassifyIds)
  513. }
  514. if len(thirdClassifyIds) > 0 {
  515. classifyCondList = append(classifyCondList, ` classify_id_third IN ( `+utils.GetOrmInReplace(len(thirdClassifyIds))+` ) `)
  516. pars = append(pars, thirdClassifyIds)
  517. }
  518. cond += fmt.Sprintf(` AND (%s) `, strings.Join(classifyCondList, " OR "))
  519. } else {
  520. cond += ` AND 1 = 2`
  521. }
  522. } else {
  523. classifyItem, err := models.GetClassifyById(classifyIdSecond)
  524. if err != nil {
  525. br.Msg = "获取失败"
  526. br.ErrMsg = "获取分类失败, Err: " + err.Error()
  527. return
  528. }
  529. switch classifyItem.Level {
  530. case 1:
  531. cond += ` AND classify_id_first = ? `
  532. pars = append(pars, classifyIdSecond)
  533. case 2:
  534. cond += ` AND classify_id_second = ? `
  535. pars = append(pars, classifyIdSecond)
  536. case 3:
  537. cond += ` AND classify_id_third = ? `
  538. pars = append(pars, classifyIdSecond)
  539. }
  540. }
  541. keyword := r.GetString("Keyword", "")
  542. if keyword != "" {
  543. kw := fmt.Sprint("%", keyword, "%")
  544. cond += ` AND title LIKE ?`
  545. pars = append(pars, kw)
  546. }
  547. fieldArr := []string{"id", "classify_id_first", "classify_id_second", "classify_id_third", "title", "publish_time"}
  548. orderRule := ` ORDER BY publish_time DESC, id DESC`
  549. reports, e := models.GetReportByCondition(cond, pars, fieldArr, orderRule, true, 0, 5)
  550. if e != nil {
  551. br.Msg = "获取失败"
  552. br.ErrMsg = "获取双周报列表失败, Err: " + e.Error()
  553. return
  554. }
  555. // 查询报告权限
  556. classifyPermissions := make(map[int][]int, 0)
  557. {
  558. classifyIds := make([]int, 0)
  559. for _, v := range reports {
  560. minClassifyId, _, e := services.GetMinClassify(v)
  561. if e != nil {
  562. br.Msg = "获取失败"
  563. br.ErrMsg = "获取报告的最小分类失败, Err: " + e.Error()
  564. return
  565. }
  566. if utils.InArrayByInt(classifyIds, minClassifyId) {
  567. continue
  568. }
  569. classifyIds = append(classifyIds, minClassifyId)
  570. }
  571. if len(classifyIds) > 0 {
  572. classifyIdsPermissions, e := models.GetPermissionsByClassifyIds(classifyIds)
  573. if e != nil {
  574. br.Msg = "获取失败"
  575. br.ErrMsg = "获取分类权限失败, Err: " + e.Error()
  576. return
  577. }
  578. for _, v := range classifyIdsPermissions {
  579. classifyPermissions[v.ClassifyId] = append(classifyPermissions[v.ClassifyId], v.ChartPermissionId)
  580. }
  581. }
  582. }
  583. type SimpleReportListResp struct {
  584. ReportId int
  585. Title string
  586. PublishTime string
  587. BindVideo int
  588. BindVideoTitle string
  589. PermissionIds []int
  590. }
  591. respList := make([]*SimpleReportListResp, 0)
  592. if len(reports) > 0 {
  593. reportIds := make([]int, 0)
  594. for i := range reports {
  595. reportIds = append(reportIds, reports[i].Id)
  596. }
  597. // 是否绑定
  598. videos, e := ybModels.GetRoadVideoListByReportIds(reportIds)
  599. if e != nil {
  600. br.Msg = "获取失败"
  601. br.ErrMsg = "获取路演视频列表失败, Err: " + e.Error()
  602. return
  603. }
  604. bindMap := make(map[int]int)
  605. bindTitleMap := make(map[int]string)
  606. for i := range videos {
  607. bindMap[videos[i].ReportId] = videos[i].RoadVideoId
  608. bindTitleMap[videos[i].ReportId] = videos[i].Title
  609. }
  610. for i := range reports {
  611. tmpReport := reports[i]
  612. minClassifyId, _, e := services.GetMinClassify(tmpReport)
  613. if e != nil {
  614. br.Msg = "获取失败"
  615. br.ErrMsg = "获取报告的最小分类失败, Err: " + e.Error()
  616. return
  617. }
  618. respList = append(respList, &SimpleReportListResp{
  619. ReportId: tmpReport.Id,
  620. Title: tmpReport.Title,
  621. PublishTime: tmpReport.PublishTime.Format(utils.FormatDateTime),
  622. BindVideo: bindMap[tmpReport.Id],
  623. BindVideoTitle: bindTitleMap[tmpReport.Id],
  624. PermissionIds: classifyPermissions[minClassifyId],
  625. })
  626. }
  627. }
  628. br.Ret = 200
  629. br.Success = true
  630. br.Msg = "操作成功"
  631. br.Data = respList
  632. }
  633. // SendMsg
  634. // @Title 推送消息(模板/客群)
  635. // @Description 推送消息(模板/客群)
  636. // @Param request body request.RoadVideoOptionReq true "type json string"
  637. // @Success 200 string "操作成功"
  638. // @router /road/video/send_msg [post]
  639. func (r *RoadVideoController) SendMsg() {
  640. br := new(models.BaseResponse).Init()
  641. br.IsSendEmail = false
  642. defer func() {
  643. r.Data["json"] = br
  644. r.ServeJSON()
  645. }()
  646. sysUser := r.SysUser
  647. if sysUser == nil {
  648. br.Msg = "请登录"
  649. br.ErrMsg = "请登录,SysUser Is Empty"
  650. br.Ret = 408
  651. return
  652. }
  653. var req request.RoadVideoOptionReq
  654. if err := json.Unmarshal(r.Ctx.Input.RequestBody, &req); err != nil {
  655. br.Msg = "参数解析异常!"
  656. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  657. return
  658. }
  659. if req.VideoId <= 0 {
  660. br.Msg = "参数有误"
  661. return
  662. }
  663. // 加锁,避免重复点击造成的多次推送
  664. {
  665. redisKey := fmt.Sprint("road_video:send:msg:", req.VideoId)
  666. ok := utils.Rc.SetNX(redisKey, 1, time.Second*300)
  667. if !ok {
  668. br.Msg = "消息已推送, 请勿重复推送"
  669. return
  670. }
  671. defer func() {
  672. _ = utils.Rc.Delete(redisKey)
  673. }()
  674. }
  675. item, e := ybModels.GetRoadVideoById(req.VideoId)
  676. if e != nil {
  677. br.Msg = "视频不存在或已被删除"
  678. br.ErrMsg = "获取路演视频失败, Err: " + e.Error()
  679. return
  680. }
  681. if item.PublishState != 1 {
  682. br.Msg = "视频未发布, 不可推送"
  683. return
  684. }
  685. if item.SendThsState == 1 && item.SendTemplateState == 1 {
  686. br.Msg = "请勿重复推送"
  687. return
  688. }
  689. nowTime := time.Now().Local()
  690. updateCols := make([]string, 0)
  691. // 可能存在历史数据两个只推了一个所以此处加个判断
  692. // 模板消息
  693. if item.SendTemplateState == 0 {
  694. updateCols = append(updateCols, "SendTemplateState", "SendTemplateTime")
  695. item.SendTemplateState = 1
  696. item.SendTemplateTime = nowTime
  697. go func() {
  698. _ = services.SendYbRoadVideoWxMsg(item.RoadVideoId, item.Title, item.PublishTime.Format(utils.FormatDateTime), item.ChartPermissionIds)
  699. }()
  700. }
  701. // 客群消息
  702. if item.SendThsState == 0 {
  703. updateCols = append(updateCols, "SendThsState", "SendThsTime")
  704. item.SendThsState = 1
  705. item.SendThsTime = nowTime
  706. //go func() {
  707. // _ = services.SendYbRoadVideoThs(item.RoadVideoId, item.Title, item.ChartPermissionIds)
  708. //}()
  709. }
  710. // 更新状态
  711. if e := item.Update(updateCols); e != nil {
  712. br.Msg = "推送失败"
  713. br.ErrMsg = "更新路演视频信息失败, Err: " + e.Error()
  714. return
  715. }
  716. br.Ret = 200
  717. br.Success = true
  718. br.Msg = "操作成功"
  719. }