report_share.go 8.4 KB

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