smart_report.go 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. package controllers
  2. import (
  3. "eta/eta_report/models"
  4. "eta/eta_report/utils"
  5. "fmt"
  6. "strconv"
  7. "strings"
  8. )
  9. // SmartReportController 智能研报
  10. type SmartReportController struct {
  11. BaseCommonController
  12. }
  13. // Detail
  14. // @Title 报告详情
  15. // @Description 报告详情
  16. // @Param ReportCode query string true "报告唯一编码"
  17. // @Success 200 {object} models.SmartReportShareDetailResp
  18. // @router /share/detail [get]
  19. func (this *SmartReportController) Detail() {
  20. br := new(models.BaseResponse).Init()
  21. defer func() {
  22. if br.ErrMsg == "" {
  23. br.IsSendEmail = false
  24. }
  25. this.Data["json"] = br
  26. this.ServeJSON()
  27. }()
  28. reportCode := this.GetString("ReportCode")
  29. if reportCode == "" {
  30. br.Msg = "获取失败"
  31. br.ErrMsg = fmt.Sprintf("参数有误, ReportCode: %s", reportCode)
  32. return
  33. }
  34. resp := new(models.SmartReportShareDetailResp)
  35. reportOB := new(models.SmartReport)
  36. cond := ` AND report_code = ?`
  37. pars := make([]interface{}, 0)
  38. pars = append(pars, reportCode)
  39. item, e := reportOB.GetItemByCondition(cond, pars)
  40. if e != nil {
  41. if e.Error() == utils.ErrNoRow() {
  42. br.Msg = "报告不存在, 请刷新页面"
  43. return
  44. }
  45. br.Msg = "获取失败"
  46. br.ErrMsg = "获取报告失败, Err: " + e.Error()
  47. return
  48. }
  49. resp.Report = models.FormatSmartReport2Item(item)
  50. if resp.Report.HeadResourceId > 0 {
  51. headResource, err := models.GetResourceItemById(resp.Report.HeadResourceId)
  52. if err != nil {
  53. br.Msg = "操作失败"
  54. br.ErrMsg = "获取资源库版头失败, Err: " + e.Error()
  55. return
  56. }
  57. resp.Report.HeadImg = headResource.ImgUrl
  58. resp.Report.HeadStyle = headResource.Style
  59. }
  60. if resp.Report.EndResourceId > 0 {
  61. endResource, err := models.GetResourceItemById(resp.Report.EndResourceId)
  62. if err != nil {
  63. br.Msg = "操作失败"
  64. br.ErrMsg = "获取资源库版头失败, Err: " + e.Error()
  65. return
  66. }
  67. resp.Report.EndImg = endResource.ImgUrl
  68. resp.Report.EndStyle = endResource.Style
  69. }
  70. // 免责声明
  71. conf, e := models.GetBusinessConf()
  72. if e != nil {
  73. br.Msg = "获取失败"
  74. br.ErrMsg = "获取免责声明失败, Err: " + e.Error()
  75. return
  76. }
  77. if conf[models.BusinessConfDisclaimer] != "" {
  78. resp.Disclaimer = conf[models.BusinessConfDisclaimer]
  79. }
  80. // 研报分享抬头
  81. if v, ok := conf[models.BusinessConfH5ShareName]; ok {
  82. resp.H5ShareName = v
  83. }
  84. if v, ok := conf[models.BusinessConfH5ReportShareImg]; ok {
  85. resp.H5ReportShareImg = v
  86. }
  87. // 更新pv
  88. if e = models.UpdateSmartReportPv(item.SmartReportId); e != nil {
  89. br.Msg = "获取失败"
  90. br.ErrMsg = "更新报告pv失败, Err: " + e.Error()
  91. return
  92. }
  93. br.Ret = 200
  94. br.Success = true
  95. br.Msg = "获取成功"
  96. br.Data = resp
  97. }
  98. // Detail
  99. // @Title 微信分享详情
  100. // @Description 微信分享详情
  101. // @Param ReportCode query string true "报告唯一编码"
  102. // @Success 200 {object} models.SmartReportWechatShareDetailResp
  103. // @router /wechat_share/detail [get]
  104. func (this *SmartReportController) WechatShareDetail() {
  105. br := new(models.BaseResponse).Init()
  106. defer func() {
  107. if br.ErrMsg == "" {
  108. br.IsSendEmail = false
  109. }
  110. this.Data["json"] = br
  111. this.ServeJSON()
  112. }()
  113. reportCode := this.GetString("ReportCode")
  114. if reportCode == "" {
  115. br.Msg = "获取失败"
  116. br.ErrMsg = fmt.Sprintf("参数有误, ReportCode: %s", reportCode)
  117. return
  118. }
  119. resp := new(models.SmartReportWechatShareDetailResp)
  120. item, e := models.GetReportByCode(reportCode)
  121. if e != nil {
  122. if e.Error() == utils.ErrNoRow() {
  123. br.Msg = "报告不存在, 请刷新页面"
  124. return
  125. }
  126. br.Msg = "获取失败"
  127. br.ErrMsg = "获取报告失败, Err: " + e.Error()
  128. return
  129. }
  130. // 免责声明
  131. conf, e := models.GetBusinessConf()
  132. if e != nil {
  133. br.Msg = "获取失败"
  134. br.ErrMsg = "获取免责声明失败, Err: " + e.Error()
  135. return
  136. }
  137. date := strings.Replace(item.CreateTime, "-", "", -1)
  138. dateStr := date[4:9]
  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. }
  158. // WechatShareOutsideReportDetail
  159. // @Title 微信分享外部报告详情
  160. // @Description 微信分享外部报告详情
  161. // @Param ReportCode query string true "报告唯一编码"
  162. // @Success 200 {object} models.SmartReportWechatShareDetailResp
  163. // @router /wechat_share/outside/report/detail [get]
  164. func (this *SmartReportController) WechatShareOutsideReportDetail() {
  165. br := new(models.BaseResponse).Init()
  166. defer func() {
  167. if br.ErrMsg == "" {
  168. br.IsSendEmail = false
  169. }
  170. this.Data["json"] = br
  171. this.ServeJSON()
  172. }()
  173. reportCode := this.GetString("ReportCode")
  174. if reportCode == "" {
  175. br.Msg = "获取失败"
  176. br.ErrMsg = fmt.Sprintf("参数有误, ReportCode: %s", reportCode)
  177. return
  178. }
  179. resp := new(models.SmartReportWechatShareDetailResp)
  180. item, e := models.GetOutsideReportByReportCode(reportCode)
  181. if e != nil {
  182. if e.Error() == utils.ErrNoRow() {
  183. br.Msg = "报告不存在, 请刷新页面"
  184. return
  185. }
  186. br.Msg = "获取失败"
  187. br.ErrMsg = "获取报告失败, Err: " + e.Error()
  188. return
  189. }
  190. // 免责声明
  191. conf, e := models.GetBusinessConf()
  192. if e != nil {
  193. br.Msg = "获取失败"
  194. br.ErrMsg = "获取免责声明失败, Err: " + e.Error()
  195. return
  196. }
  197. /*
  198. date := strings.Replace(item.CreateTime, "-", "", -1)
  199. dateStr := date[4:9]
  200. var shareTitle string
  201. // 研报分享抬头
  202. if utils.BusinessCode == "E2023080700" || utils.BusinessCode == "E2023080900" || utils.BusinessCode == "E2023080901" {
  203. shareTitle = "【第" + strconv.Itoa(item.Stage) + "期|FICC】" + item.Title + "(" + dateStr + ")"
  204. } else {
  205. shareTitle = "【第" + strconv.Itoa(item.Stage) + "期】" + item.Title + "(" + dateStr + ")"
  206. }*/
  207. if v, ok := conf[models.BusinessConfH5ReportShareImg]; ok {
  208. resp.H5ReportShareImg = v
  209. }
  210. if v, ok := conf[models.BusinessConfH5ShareName]; ok {
  211. resp.H5ShareName = v
  212. }
  213. resp.H5ShareTitle = item.Title
  214. br.Ret = 200
  215. br.Success = true
  216. br.Msg = "获取成功"
  217. br.Data = resp
  218. }