report_share.go 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. package controllers
  2. import (
  3. "eta/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.Report = report
  116. resp.Report.ChapterList = reportChapters
  117. br.Ret = 200
  118. br.Success = true
  119. br.Msg = "获取成功"
  120. br.Data = resp
  121. }
  122. // OutSideReportDetail
  123. // @Title 日评详情
  124. // @Description 日评详情接口
  125. // @Param ReportCode query string true "报告唯一编码"
  126. // @Success 200 {object} models.ReportShareDetailResp
  127. // @router /share/outside/report/detail [get]
  128. func (this *ReportShareController) OutSideReportDetail() {
  129. br := new(models.BaseResponse).Init()
  130. defer func() {
  131. this.Data["json"] = br
  132. this.ServeJSON()
  133. }()
  134. reportCode := this.GetString("ReportCode")
  135. if reportCode == "" {
  136. br.Msg = "参数错误"
  137. br.ErrMsg = "参数错误,reportCode 为空"
  138. return
  139. }
  140. report, err := models.GetOutsideReportByReportCode(reportCode)
  141. if err != nil {
  142. br.Msg = "该报告已删除"
  143. br.ErrMsg = "获取报告详情失败,Err:" + err.Error()
  144. return
  145. }
  146. report.Content = html.UnescapeString(report.Content)
  147. attachmentList, err := models.GetOutsideReportAttachmentListByReportId(report.OutsideReportId)
  148. if err != nil {
  149. br.Msg = "获取失败"
  150. br.ErrMsg = "获取附件列表失败, Err: " + err.Error()
  151. return
  152. }
  153. outsideReportBO := models.OutsideReportBO{
  154. OutsideReportId: report.OutsideReportId,
  155. Source: report.Source,
  156. Title: report.Title,
  157. Abstract: report.Abstract,
  158. ClassifyId: report.ClassifyId,
  159. ClassifyName: report.ClassifyName,
  160. Content: report.Content,
  161. SysUserId: report.SysUserId,
  162. SysUserName: report.SysUserName,
  163. AttachmentList: attachmentList,
  164. }
  165. resp := new(models.OutsideReportResp)
  166. // 免责声明
  167. conf, e := models.GetBusinessConf()
  168. if e != nil {
  169. br.Msg = "获取失败"
  170. br.ErrMsg = "获取免责声明失败, Err: " + e.Error()
  171. return
  172. }
  173. if conf[models.BusinessConfDisclaimer] != "" {
  174. resp.Disclaimer = conf[models.BusinessConfDisclaimer]
  175. }
  176. // 研报分享抬头
  177. if v, ok := conf[models.BusinessConfH5ShareName]; ok {
  178. resp.H5ShareName = v
  179. }
  180. if v, ok := conf[models.BusinessConfH5ReportShareImg]; ok {
  181. resp.H5ReportShareImg = v
  182. }
  183. if v, ok := conf[models.BusinessConfWatermarkChart]; ok {
  184. resp.WatermarkChart = v
  185. }
  186. if v, ok := conf[models.BusinessConfWatermarkReport]; ok {
  187. resp.WatermarkReport = v
  188. }
  189. // 报告Logo
  190. if v, ok := conf[models.BusinessConfReportCenterLogoShow]; ok {
  191. if v == `true` {
  192. if reportLogo, ok := conf[models.BusinessConfReportLogo]; ok {
  193. resp.ReportLogo = reportLogo
  194. }
  195. }
  196. }
  197. resp.OutsideReportBO = &outsideReportBO
  198. br.Ret = 200
  199. br.Success = true
  200. br.Msg = "获取成功"
  201. br.Data = resp
  202. }