smart_report.go 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. package services
  2. import (
  3. "eta/eta_hub/models"
  4. "eta/eta_hub/utils"
  5. "fmt"
  6. "html"
  7. "strconv"
  8. )
  9. // SmartReportElasticUpsert 新增/编辑报告es
  10. func SmartReportElasticUpsert(smartReportId int, state int) (err error) {
  11. if smartReportId <= 0 {
  12. return
  13. }
  14. reportOB := new(models.SmartReport)
  15. item, e := reportOB.GetItemById(smartReportId)
  16. if e != nil {
  17. if e.Error() == utils.ErrNoRow() {
  18. // 可能被删了就直接忽略掉
  19. return
  20. }
  21. err = fmt.Errorf("获取报告失败, Err: %s", e.Error())
  22. return
  23. }
  24. esReport := new(models.ElasticSmartReport)
  25. esReport.SmartReportId = item.SmartReportId
  26. esReport.Title = item.Title
  27. esReport.Abstract = item.Abstract
  28. esReport.BodyContent = utils.TrimHtml(html.UnescapeString(item.Content))
  29. esReport.PublishTime = item.PublishTime.Format(utils.FormatDateTime)
  30. esReport.PublishState = state
  31. esReport.Author = item.Author
  32. esReport.ClassifyIdFirst = item.ClassifyIdFirst
  33. esReport.ClassifyNameFirst = item.ClassifyNameFirst
  34. esReport.ClassifyIdSecond = item.ClassifyIdSecond
  35. esReport.ClassifyNameSecond = item.ClassifyNameSecond
  36. esReport.StageStr = strconv.Itoa(item.Stage)
  37. esReport.Frequency = item.Frequency
  38. if err = EsAddOrEditSmartReport(utils.SmartReportIndexName, strconv.Itoa(item.SmartReportId), esReport); err != nil {
  39. return
  40. }
  41. return
  42. }