smart_report.go 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. package smart_report
  2. import (
  3. "encoding/json"
  4. "eta/eta_api/models"
  5. "eta/eta_api/models/smart_report"
  6. "eta/eta_api/services"
  7. "eta/eta_api/services/alarm_msg"
  8. "eta/eta_api/utils"
  9. "fmt"
  10. "time"
  11. )
  12. // SmartReportBuildVideoAndUpdate 生成音频
  13. func SmartReportBuildVideoAndUpdate(item *smart_report.SmartReport) {
  14. if item == nil {
  15. return
  16. }
  17. var err error
  18. defer func() {
  19. if err != nil {
  20. tips := fmt.Sprintf("智能研报-音频生成, errMsg: %s", err.Error())
  21. go alarm_msg.SendAlarmMsg(tips, 2)
  22. }
  23. }()
  24. videoUrl, videoName, videoSize, videoPlaySeconds, e := services.CreateReportVideo(item.Title, item.Content, time.Now().Local().Format(utils.FormatDateTime))
  25. if e != nil {
  26. err = fmt.Errorf("create audio err: %s", e.Error())
  27. return
  28. }
  29. item.VideoUrl = videoUrl
  30. item.VideoName = videoName
  31. item.VideoSize = videoSize
  32. item.VideoPlaySeconds = fmt.Sprintf("%.2f", videoPlaySeconds)
  33. item.ModifyTime = time.Now().Local()
  34. cols := []string{"VideoUrl", "VideoName", "VideoSize", "VideoPlaySeconds", "ModifyTime"}
  35. if e = item.Update(cols); e != nil {
  36. err = fmt.Errorf("smart report update err: %s", e.Error())
  37. return
  38. }
  39. }
  40. // UpdateSmartReportEditing 更新研报当前更新状态
  41. // status 枚举值 1:编辑中,0:完成编辑, 2:只做查询
  42. func UpdateSmartReportEditing(reportId, status, thisUserId int, thisUserName string, adminIdName map[int]string) (ret models.MarkReportResp, err error) {
  43. key := fmt.Sprint(utils.CACHE_SMART_REPORT_EDITING, reportId)
  44. ret.Status = 0
  45. ret.Msg = "无人编辑"
  46. opUserId, e := utils.Rc.RedisInt(key)
  47. var opUser models.MarkReportItem
  48. var classifyNameFirst string
  49. if e != nil {
  50. opUserInfoStr, tErr := utils.Rc.RedisString(key)
  51. if tErr == nil {
  52. tErr = json.Unmarshal([]byte(opUserInfoStr), &opUser)
  53. if tErr == nil {
  54. opUserId = opUser.AdminId
  55. }
  56. }
  57. }
  58. if opUserId > 0 && opUserId != thisUserId {
  59. editor := opUser.Editor
  60. if editor == "" {
  61. editor = adminIdName[opUserId]
  62. }
  63. ret.Status = 1
  64. ret.Msg = fmt.Sprintf("当前%s正在编辑报告", editor)
  65. ret.Editor = editor
  66. return
  67. }
  68. if status == 1 {
  69. nowUser := &models.MarkReportItem{AdminId: thisUserId, Editor: thisUserName, ReportClassifyNameFirst: classifyNameFirst}
  70. bt, e := json.Marshal(nowUser)
  71. if e != nil {
  72. err = fmt.Errorf("格式化编辑者信息失败")
  73. return
  74. }
  75. if opUserId > 0 {
  76. utils.Rc.Do("SETEX", key, int64(180), string(bt)) //3分钟缓存
  77. } else {
  78. utils.Rc.SetNX(key, string(bt), time.Second*60*3) //3分钟缓存
  79. }
  80. } else if status == 0 {
  81. //清除编辑缓存
  82. _ = utils.Rc.Delete(key)
  83. }
  84. return
  85. }