report_share.go 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. package controllers
  2. import (
  3. "encoding/json"
  4. "eta/eta_report/models"
  5. "fmt"
  6. "html"
  7. "strings"
  8. )
  9. // ReportShareController 报告分享
  10. type ReportShareController struct {
  11. BaseCommonController
  12. }
  13. // Detail
  14. // @Title 日评详情
  15. // @Description 日评详情接口
  16. // @Param ReportCode query string true "报告唯一编码"
  17. // @Param IsReplace query int false "是否报告转长图的场景:1-是"
  18. // @Success 200 {object} models.ReportShareDetailResp
  19. // @router /share/detail [get]
  20. func (this *ReportShareController) Detail() {
  21. br := new(models.BaseResponse).Init()
  22. defer func() {
  23. this.Data["json"] = br
  24. this.ServeJSON()
  25. }()
  26. reportCode := this.GetString("ReportCode")
  27. isReplace, _ := this.GetInt("IsReplace", 0)
  28. if reportCode == "" {
  29. br.Msg = "参数错误"
  30. br.ErrMsg = "参数错误,reportCode 为空"
  31. return
  32. }
  33. report, err := models.GetReportByCode(reportCode)
  34. if err != nil {
  35. br.Msg = "该报告已删除"
  36. br.ErrMsg = "获取报告详情失败,Err:" + err.Error()
  37. return
  38. }
  39. report.ContentSub = html.UnescapeString(report.ContentSub)
  40. report.Content = html.UnescapeString(report.Content)
  41. report.ContentStruct = html.UnescapeString(report.ContentStruct)
  42. if report.HeadResourceId > 0 {
  43. headResource, err := models.GetResourceItemById(report.HeadResourceId)
  44. if err != nil {
  45. br.Msg = "操作失败"
  46. br.ErrMsg = "获取资源库版头失败, Err: " + err.Error()
  47. return
  48. }
  49. report.HeadImg = headResource.ImgUrl
  50. report.HeadStyle = headResource.Style
  51. }
  52. if report.EndResourceId > 0 {
  53. endResource, err := models.GetResourceItemById(report.EndResourceId)
  54. if err != nil {
  55. br.Msg = "操作失败"
  56. br.ErrMsg = "获取资源库版头失败, Err: " + err.Error()
  57. return
  58. }
  59. report.EndImg = endResource.ImgUrl
  60. report.EndStyle = endResource.Style
  61. }
  62. resp := new(models.ReportShareDetailResp)
  63. // 免责声明
  64. conf, e := models.GetBusinessConf()
  65. if e != nil {
  66. br.Msg = "获取失败"
  67. br.ErrMsg = "获取免责声明失败, Err: " + e.Error()
  68. return
  69. }
  70. // (为了兼容内网客户)需要判断是否替换资源地址
  71. var urlReplace models.Report2ImgReplace
  72. if isReplace == 1 && conf[models.BusinessConfReport2ImgReplace] != "" {
  73. if e := json.Unmarshal([]byte(conf[models.BusinessConfReport2ImgReplace]), &urlReplace); e != nil {
  74. br.Msg = "获取失败"
  75. br.ErrMsg = fmt.Sprintf("获取报告替换配置失败, %v", e)
  76. return
  77. }
  78. }
  79. if conf[models.BusinessConfDisclaimer] != "" {
  80. resp.Disclaimer = conf[models.BusinessConfDisclaimer]
  81. }
  82. // 研报分享抬头
  83. if v, ok := conf[models.BusinessConfH5ShareName]; ok {
  84. resp.H5ShareName = v
  85. }
  86. if v, ok := conf[models.BusinessConfH5ReportShareImg]; ok {
  87. resp.H5ReportShareImg = v
  88. }
  89. if v, ok := conf[models.BusinessConfWatermarkChart]; ok {
  90. resp.WatermarkChart = v
  91. }
  92. if v, ok := conf[models.BusinessConfWatermarkReport]; ok {
  93. resp.WatermarkReport = v
  94. }
  95. // 报告Logo
  96. if v, ok := conf[models.BusinessConfReportCenterLogoShow]; ok {
  97. if v == `true` {
  98. if reportLogo, ok := conf[models.BusinessConfReportLogo]; ok {
  99. resp.ReportLogo = reportLogo
  100. }
  101. }
  102. }
  103. // 章节类型的报告
  104. resp.Report = new(models.ReportItem)
  105. reportChapters := make([]*models.ReportChapter, 0)
  106. if report.HasChapter == 1 {
  107. // 获取章节内容
  108. chapters, e := models.GetPublishedChapterListByReportId(report.Id)
  109. if e != nil {
  110. br.Msg = "获取失败"
  111. br.ErrMsg = "获取章节列表失败, Err: " + e.Error()
  112. return
  113. }
  114. if len(chapters) > 0 {
  115. for _, chapter := range chapters {
  116. chapter.Content = html.UnescapeString(chapter.Content)
  117. chapter.ContentSub = html.UnescapeString(chapter.ContentSub)
  118. if urlReplace.IsReplace {
  119. if urlReplace.OssUrlOrigin != "" {
  120. chapter.Content = strings.ReplaceAll(chapter.Content, urlReplace.OssUrlOrigin, urlReplace.OssUrlNew)
  121. chapter.ContentSub = strings.ReplaceAll(chapter.ContentSub, urlReplace.OssUrlOrigin, urlReplace.OssUrlNew)
  122. }
  123. if urlReplace.ChartUrlOrigin != "" {
  124. chapter.Content = strings.ReplaceAll(chapter.Content, urlReplace.ChartUrlOrigin, urlReplace.ChartUrlNew)
  125. chapter.ContentSub = strings.ReplaceAll(chapter.ContentSub, urlReplace.ChartUrlOrigin, urlReplace.ChartUrlNew)
  126. }
  127. }
  128. reportChapters = append(reportChapters, chapter)
  129. }
  130. }
  131. //report.Abstract = report.Title
  132. }
  133. // 替换地址
  134. if urlReplace.IsReplace {
  135. if urlReplace.OssUrlOrigin != "" {
  136. resp.H5ReportShareImg = strings.ReplaceAll(resp.H5ReportShareImg, urlReplace.OssUrlOrigin, urlReplace.OssUrlNew)
  137. resp.ReportLogo = strings.ReplaceAll(resp.ReportLogo, urlReplace.OssUrlOrigin, urlReplace.OssUrlNew)
  138. report.Content = strings.ReplaceAll(report.Content, urlReplace.OssUrlOrigin, urlReplace.OssUrlNew)
  139. report.ContentSub = strings.ReplaceAll(report.ContentSub, urlReplace.OssUrlOrigin, urlReplace.OssUrlNew)
  140. }
  141. if urlReplace.ChartUrlOrigin != "" {
  142. report.Content = strings.ReplaceAll(report.Content, urlReplace.ChartUrlOrigin, urlReplace.ChartUrlNew)
  143. report.ContentSub = strings.ReplaceAll(report.ContentSub, urlReplace.ChartUrlOrigin, urlReplace.ChartUrlNew)
  144. }
  145. }
  146. // 更新pv
  147. if e = models.UpdateReportPv(report.Id); e != nil {
  148. br.Msg = "获取失败"
  149. br.ErrMsg = "更新报告pv失败, Err: " + e.Error()
  150. return
  151. }
  152. resp.Report.Report = report
  153. resp.Report.ChapterList = reportChapters
  154. br.Ret = 200
  155. br.Success = true
  156. br.Msg = "获取成功"
  157. br.Data = resp
  158. }
  159. // OutSideReportDetail
  160. // @Title 日评详情
  161. // @Description 日评详情接口
  162. // @Param ReportCode query string true "报告唯一编码"
  163. // @Success 200 {object} models.ReportShareDetailResp
  164. // @router /share/outside/report/detail [get]
  165. func (this *ReportShareController) OutSideReportDetail() {
  166. br := new(models.BaseResponse).Init()
  167. defer func() {
  168. this.Data["json"] = br
  169. this.ServeJSON()
  170. }()
  171. reportCode := this.GetString("ReportCode")
  172. if reportCode == "" {
  173. br.Msg = "参数错误"
  174. br.ErrMsg = "参数错误,reportCode 为空"
  175. return
  176. }
  177. report, err := models.GetOutsideReportByReportCode(reportCode)
  178. if err != nil {
  179. br.Msg = "该报告已删除"
  180. br.ErrMsg = "获取报告详情失败,Err:" + err.Error()
  181. return
  182. }
  183. report.Content = html.UnescapeString(report.Content)
  184. attachmentList, err := models.GetOutsideReportAttachmentListByReportId(report.OutsideReportId)
  185. if err != nil {
  186. br.Msg = "获取失败"
  187. br.ErrMsg = "获取附件列表失败, Err: " + err.Error()
  188. return
  189. }
  190. outsideReportBO := models.OutsideReportBO{
  191. OutsideReportId: report.OutsideReportId,
  192. Source: report.Source,
  193. Title: report.Title,
  194. Abstract: report.Abstract,
  195. ClassifyId: report.ClassifyId,
  196. ClassifyName: report.ClassifyName,
  197. Content: report.Content,
  198. SysUserId: report.SysUserId,
  199. SysUserName: report.SysUserName,
  200. AttachmentList: attachmentList,
  201. }
  202. resp := new(models.OutsideReportResp)
  203. // 免责声明
  204. conf, e := models.GetBusinessConf()
  205. if e != nil {
  206. br.Msg = "获取失败"
  207. br.ErrMsg = "获取免责声明失败, Err: " + e.Error()
  208. return
  209. }
  210. if conf[models.BusinessConfDisclaimer] != "" {
  211. resp.Disclaimer = conf[models.BusinessConfDisclaimer]
  212. }
  213. // 研报分享抬头
  214. if v, ok := conf[models.BusinessConfH5ShareName]; ok {
  215. resp.H5ShareName = v
  216. }
  217. if v, ok := conf[models.BusinessConfH5ReportShareImg]; ok {
  218. resp.H5ReportShareImg = v
  219. }
  220. if v, ok := conf[models.BusinessConfWatermarkChart]; ok {
  221. resp.WatermarkChart = v
  222. }
  223. if v, ok := conf[models.BusinessConfWatermarkReport]; ok {
  224. resp.WatermarkReport = v
  225. }
  226. // 报告Logo
  227. if v, ok := conf[models.BusinessConfReportCenterLogoShow]; ok {
  228. if v == `true` {
  229. if reportLogo, ok := conf[models.BusinessConfReportLogo]; ok {
  230. resp.ReportLogo = reportLogo
  231. }
  232. }
  233. }
  234. resp.OutsideReportBO = &outsideReportBO
  235. br.Ret = 200
  236. br.Success = true
  237. br.Msg = "获取成功"
  238. br.Data = resp
  239. }