report_share.go 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. package controllers
  2. import (
  3. "eta_gn/eta_report/models"
  4. "html"
  5. )
  6. // ReportShareController 报告分享
  7. type ReportShareController struct {
  8. BaseCommonController
  9. }
  10. // Detail
  11. // @Title 日评详情
  12. // @Description 日评详情接口
  13. // @Param ReportCode query string true "报告唯一编码"
  14. // @Success 200 {object} models.ReportShareDetailResp
  15. // @router /share/detail [get]
  16. func (this *ReportShareController) Detail() {
  17. br := new(models.BaseResponse).Init()
  18. defer func() {
  19. this.Data["json"] = br
  20. this.ServeJSON()
  21. }()
  22. reportCode := this.GetString("ReportCode")
  23. if reportCode == "" {
  24. br.Msg = "参数错误"
  25. br.ErrMsg = "参数错误,reportCode 为空"
  26. return
  27. }
  28. report, err := models.GetReportByCode(reportCode)
  29. if err != nil {
  30. br.Msg = "该报告已删除"
  31. br.ErrMsg = "获取报告详情失败,Err:" + err.Error()
  32. return
  33. }
  34. report.ContentSub = html.UnescapeString(report.ContentSub)
  35. report.Content = html.UnescapeString(report.Content)
  36. report.ContentStruct = html.UnescapeString(report.ContentStruct)
  37. if report.HeadResourceId > 0 {
  38. headResource, err := models.GetResourceItemById(report.HeadResourceId)
  39. if err != nil {
  40. br.Msg = "操作失败"
  41. br.ErrMsg = "获取资源库版头失败, Err: " + err.Error()
  42. return
  43. }
  44. report.HeadImg = headResource.ImgUrl
  45. report.HeadStyle = headResource.Style
  46. }
  47. if report.EndResourceId > 0 {
  48. endResource, err := models.GetResourceItemById(report.EndResourceId)
  49. if err != nil {
  50. br.Msg = "操作失败"
  51. br.ErrMsg = "获取资源库版头失败, Err: " + err.Error()
  52. return
  53. }
  54. report.EndImg = endResource.ImgUrl
  55. report.EndStyle = endResource.Style
  56. }
  57. resp := new(models.ReportShareDetailResp)
  58. // 免责声明
  59. conf, e := models.GetBusinessConf()
  60. if e != nil {
  61. br.Msg = "获取失败"
  62. br.ErrMsg = "获取免责声明失败, Err: " + e.Error()
  63. return
  64. }
  65. if conf[models.BusinessConfDisclaimer] != "" {
  66. resp.Disclaimer = conf[models.BusinessConfDisclaimer]
  67. }
  68. // 研报分享抬头
  69. if v, ok := conf[models.BusinessConfH5ShareName]; ok {
  70. resp.H5ShareName = v
  71. }
  72. if v, ok := conf[models.BusinessConfH5ReportShareImg]; ok {
  73. resp.H5ReportShareImg = v
  74. }
  75. if v, ok := conf[models.BusinessConfWatermarkChart]; ok {
  76. resp.WatermarkChart = v
  77. }
  78. if v, ok := conf[models.BusinessConfWatermarkReport]; ok {
  79. resp.WatermarkReport = v
  80. }
  81. // 报告Logo
  82. if v, ok := conf[models.BusinessConfReportCenterLogoShow]; ok {
  83. if v == `true` {
  84. if reportLogo, ok := conf[models.BusinessConfReportLogo]; ok {
  85. resp.ReportLogo = reportLogo
  86. }
  87. }
  88. }
  89. // 章节类型的报告
  90. resp.Report = new(models.ReportItem)
  91. reportChapters := make([]*models.ReportChapter, 0)
  92. if report.HasChapter == 1 {
  93. // 获取章节内容
  94. chapters, e := models.GetPublishedChapterListByReportId(report.Id)
  95. if e != nil {
  96. br.Msg = "获取失败"
  97. br.ErrMsg = "获取章节列表失败, Err: " + e.Error()
  98. return
  99. }
  100. if len(chapters) > 0 {
  101. for _, chapter := range chapters {
  102. chapter.Content = html.UnescapeString(chapter.Content)
  103. chapter.ContentSub = html.UnescapeString(chapter.ContentSub)
  104. reportChapters = append(reportChapters, chapter)
  105. }
  106. }
  107. //report.Abstract = report.Title
  108. }
  109. // 更新pv
  110. if e = models.UpdateReportPv(report.Id); e != nil {
  111. br.Msg = "获取失败"
  112. br.ErrMsg = "更新报告pv失败, Err: " + e.Error()
  113. return
  114. }
  115. resp.Report.ReportShow = report.Format2Item()
  116. resp.Report.ChapterList = reportChapters
  117. br.Ret = 200
  118. br.Success = true
  119. br.Msg = "获取成功"
  120. br.Data = resp
  121. }