smart_report.go 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. package services
  2. import (
  3. "eta/eta_mobile/models/smart_report"
  4. "eta/eta_mobile/services/alarm_msg"
  5. "eta/eta_mobile/utils"
  6. "fmt"
  7. "html"
  8. "strconv"
  9. "time"
  10. )
  11. // SmartReportBuildVideoAndUpdate 生成音频
  12. func SmartReportBuildVideoAndUpdate(item *smart_report.SmartReport) {
  13. if item == nil {
  14. return
  15. }
  16. var err error
  17. defer func() {
  18. if err != nil {
  19. tips := fmt.Sprintf("智能研报-音频生成, errMsg: %s", err.Error())
  20. go alarm_msg.SendAlarmMsg(tips, 2)
  21. }
  22. }()
  23. videoUrl, videoName, videoSize, videoPlaySeconds, e := CreateReportVideo(item.Title, item.Content, time.Now().Local().Format(utils.FormatDateTime))
  24. if e != nil {
  25. err = fmt.Errorf("create audio err: %s", e.Error())
  26. return
  27. }
  28. item.VideoUrl = videoUrl
  29. item.VideoName = videoName
  30. item.VideoSize = videoSize
  31. item.VideoPlaySeconds = videoPlaySeconds
  32. item.ModifyTime = time.Now().Local()
  33. cols := []string{"VideoUrl", "VideoName", "VideoSize", "VideoPlaySeconds", "ModifyTime"}
  34. if e = item.Update(cols); e != nil {
  35. err = fmt.Errorf("smart report update err: %s", e.Error())
  36. return
  37. }
  38. }
  39. // UpdateSmartReportEditing 更新研报当前更新状态
  40. // status 枚举值 1:编辑中,0:完成编辑, 2:只做查询
  41. //func UpdateSmartReportEditing(reportId, status, thisUserId int, thisUserName string, adminIdName map[int]string) (ret models.MarkReportResp, err error) {
  42. // key := fmt.Sprint(utils.CACHE_SMART_REPORT_EDITING, reportId)
  43. // ret.Status = 0
  44. // ret.Msg = "无人编辑"
  45. //
  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. //
  59. // if opUserId > 0 && opUserId != thisUserId {
  60. // editor := opUser.Editor
  61. // if editor == "" {
  62. // editor = adminIdName[opUserId]
  63. // }
  64. // ret.Status = 1
  65. // ret.Msg = fmt.Sprintf("当前%s正在编辑报告", editor)
  66. // ret.Editor = editor
  67. // return
  68. // }
  69. //
  70. // if status == 1 {
  71. // nowUser := &models.MarkReportItem{AdminId: thisUserId, Editor: thisUserName, ReportClassifyNameFirst: classifyNameFirst}
  72. // bt, e := json.Marshal(nowUser)
  73. // if e != nil {
  74. // err = fmt.Errorf("格式化编辑者信息失败")
  75. // return
  76. // }
  77. // if opUserId > 0 {
  78. // utils.Rc.Do("SETEX", key, int64(180), string(bt)) //3分钟缓存
  79. // } else {
  80. // utils.Rc.SetNX(key, string(bt), time.Second*60*3) //3分钟缓存
  81. // }
  82. // } else if status == 0 {
  83. // //清除编辑缓存
  84. // _ = utils.Rc.Delete(key)
  85. // }
  86. // return
  87. //}
  88. // SmartReportElasticUpsert 新增/编辑报告es
  89. func SmartReportElasticUpsert(smartReportId int, state int) (err error) {
  90. if smartReportId <= 0 {
  91. return
  92. }
  93. reportOB := new(smart_report.SmartReport)
  94. item, e := reportOB.GetItemById(smartReportId)
  95. if e != nil {
  96. if e.Error() == utils.ErrNoRow() {
  97. // 可能被删了就直接忽略掉
  98. return
  99. }
  100. err = fmt.Errorf("获取报告失败, Err: %s", e.Error())
  101. return
  102. }
  103. esReport := new(smart_report.ElasticSmartReport)
  104. esReport.SmartReportId = item.SmartReportId
  105. esReport.Title = item.Title
  106. esReport.Abstract = item.Abstract
  107. esReport.BodyContent = utils.TrimHtml(html.UnescapeString(item.Content))
  108. esReport.PublishTime = item.PublishTime.Format(utils.FormatDateTime)
  109. esReport.PublishState = state
  110. esReport.Author = item.Author
  111. esReport.ClassifyIdFirst = item.ClassifyIdFirst
  112. esReport.ClassifyNameFirst = item.ClassifyNameFirst
  113. esReport.ClassifyIdSecond = item.ClassifyIdSecond
  114. esReport.ClassifyNameSecond = item.ClassifyNameSecond
  115. esReport.StageStr = strconv.Itoa(item.Stage)
  116. esReport.Frequency = item.Frequency
  117. if err = EsAddOrEditSmartReport(utils.SmartReportIndexName, strconv.Itoa(item.SmartReportId), esReport); err != nil {
  118. return
  119. }
  120. return
  121. }