smart_report.go 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. package controllers
  2. import (
  3. "eta_gn/eta_report/models"
  4. "eta_gn/eta_report/utils"
  5. "fmt"
  6. "strconv"
  7. )
  8. // SmartReportController 智能研报
  9. type SmartReportController struct {
  10. BaseCommonController
  11. }
  12. // Detail
  13. // @Title 报告详情
  14. // @Description 报告详情
  15. // @Param ReportCode query string true "报告唯一编码"
  16. // @Success 200 {object} models.SmartReportShareDetailResp
  17. // @router /share/detail [get]
  18. func (this *SmartReportController) Detail() {
  19. br := new(models.BaseResponse).Init()
  20. defer func() {
  21. if br.ErrMsg == "" {
  22. br.IsSendEmail = false
  23. }
  24. this.Data["json"] = br
  25. this.ServeJSON()
  26. }()
  27. reportCode := this.GetString("ReportCode")
  28. if reportCode == "" {
  29. br.Msg = "获取失败"
  30. br.ErrMsg = fmt.Sprintf("参数有误, ReportCode: %s", reportCode)
  31. return
  32. }
  33. resp := new(models.SmartReportShareDetailResp)
  34. reportOB := new(models.SmartReport)
  35. cond := ` AND report_code = ?`
  36. pars := make([]interface{}, 0)
  37. pars = append(pars, reportCode)
  38. item, e := reportOB.GetItemByCondition(cond, pars)
  39. if e != nil {
  40. if e.Error() == utils.ErrNoRow() {
  41. br.Msg = "报告不存在, 请刷新页面"
  42. return
  43. }
  44. br.Msg = "获取失败"
  45. br.ErrMsg = "获取报告失败, Err: " + e.Error()
  46. return
  47. }
  48. resp.Report = models.FormatSmartReport2Item(item)
  49. if resp.Report.HeadResourceId > 0 {
  50. headResource, err := models.GetResourceItemById(resp.Report.HeadResourceId)
  51. if err != nil {
  52. br.Msg = "操作失败"
  53. br.ErrMsg = "获取资源库版头失败, Err: " + e.Error()
  54. return
  55. }
  56. resp.Report.HeadImg = headResource.ImgUrl
  57. resp.Report.HeadStyle = headResource.Style
  58. }
  59. if resp.Report.EndResourceId > 0 {
  60. endResource, err := models.GetResourceItemById(resp.Report.EndResourceId)
  61. if err != nil {
  62. br.Msg = "操作失败"
  63. br.ErrMsg = "获取资源库版头失败, Err: " + e.Error()
  64. return
  65. }
  66. resp.Report.EndImg = endResource.ImgUrl
  67. resp.Report.EndStyle = endResource.Style
  68. }
  69. // 免责声明
  70. conf, e := models.GetBusinessConf()
  71. if e != nil {
  72. br.Msg = "获取失败"
  73. br.ErrMsg = "获取免责声明失败, Err: " + e.Error()
  74. return
  75. }
  76. if conf[models.BusinessConfDisclaimer] != "" {
  77. resp.Disclaimer = conf[models.BusinessConfDisclaimer]
  78. }
  79. // 研报分享抬头
  80. if v, ok := conf[models.BusinessConfH5ShareName]; ok {
  81. resp.H5ShareName = v
  82. }
  83. if v, ok := conf[models.BusinessConfH5ReportShareImg]; ok {
  84. resp.H5ReportShareImg = v
  85. }
  86. // 更新pv
  87. if e = models.UpdateSmartReportPv(item.SmartReportId); e != nil {
  88. br.Msg = "获取失败"
  89. br.ErrMsg = "更新报告pv失败, Err: " + e.Error()
  90. return
  91. }
  92. br.Ret = 200
  93. br.Success = true
  94. br.Msg = "获取成功"
  95. br.Data = resp
  96. }
  97. // Detail
  98. // @Title 微信分享详情
  99. // @Description 微信分享详情
  100. // @Param ReportCode query string true "报告唯一编码"
  101. // @Success 200 {object} models.SmartReportWechatShareDetailResp
  102. // @router /wechat_share/detail [get]
  103. func (this *SmartReportController) WechatShareDetail() {
  104. br := new(models.BaseResponse).Init()
  105. defer func() {
  106. if br.ErrMsg == "" {
  107. br.IsSendEmail = false
  108. }
  109. this.Data["json"] = br
  110. this.ServeJSON()
  111. }()
  112. reportCode := this.GetString("ReportCode")
  113. if reportCode == "" {
  114. br.Msg = "获取失败"
  115. br.ErrMsg = fmt.Sprintf("参数有误, ReportCode: %s", reportCode)
  116. return
  117. }
  118. resp := new(models.SmartReportWechatShareDetailResp)
  119. item, e := models.GetReportByCode(reportCode)
  120. if e != nil {
  121. if e.Error() == utils.ErrNoRow() {
  122. br.Msg = "报告不存在, 请刷新页面"
  123. return
  124. }
  125. br.Msg = "获取失败"
  126. br.ErrMsg = "获取报告失败, Err: " + e.Error()
  127. return
  128. }
  129. // 免责声明
  130. conf, e := models.GetBusinessConf()
  131. if e != nil {
  132. br.Msg = "获取失败"
  133. br.ErrMsg = "获取免责声明失败, Err: " + e.Error()
  134. return
  135. }
  136. //date := strings.Replace(item.CreateTime, "-", "", -1)
  137. //dateStr := date[4:9]
  138. dateStr := item.CreateTime.Format("01-02")
  139. var shareTitle string
  140. // 研报分享抬头
  141. if utils.BusinessCode == "E2023080700" || utils.BusinessCode == "E2023080900" || utils.BusinessCode == "E2023080901" {
  142. shareTitle = "【第" + strconv.Itoa(item.Stage) + "期|FICC】" + item.Title + "(" + dateStr + ")"
  143. } else {
  144. shareTitle = "【第" + strconv.Itoa(item.Stage) + "期】" + item.Title + "(" + dateStr + ")"
  145. }
  146. if v, ok := conf[models.BusinessConfH5ReportShareImg]; ok {
  147. resp.H5ReportShareImg = v
  148. }
  149. if v, ok := conf[models.BusinessConfH5ShareName]; ok {
  150. resp.H5ShareName = v
  151. }
  152. resp.H5ShareTitle = shareTitle
  153. br.Ret = 200
  154. br.Success = true
  155. br.Msg = "获取成功"
  156. br.Data = resp
  157. }