smart_report.go 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  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 && err.Error() != utils.ErrNoRow() {
  53. br.Msg = "操作失败"
  54. br.ErrMsg = "获取资源库版头失败, Err: " + err.Error()
  55. return
  56. }
  57. if headResource != nil && headResource.ResourceId > 0 {
  58. resp.Report.HeadImg = headResource.ImgUrl
  59. resp.Report.HeadStyle = headResource.Style
  60. }
  61. }
  62. if resp.Report.EndResourceId > 0 {
  63. endResource, err := models.GetResourceItemById(resp.Report.EndResourceId)
  64. if err != nil && err.Error() != utils.ErrNoRow() {
  65. br.Msg = "操作失败"
  66. br.ErrMsg = "获取资源库版尾失败, Err: " + err.Error()
  67. return
  68. }
  69. if endResource != nil && endResource.ResourceId > 0 {
  70. resp.Report.EndImg = endResource.ImgUrl
  71. resp.Report.EndStyle = endResource.Style
  72. }
  73. }
  74. // 免责声明
  75. conf, e := models.GetBusinessConf()
  76. if e != nil {
  77. br.Msg = "获取失败"
  78. br.ErrMsg = "获取免责声明失败, Err: " + e.Error()
  79. return
  80. }
  81. if conf[models.BusinessConfDisclaimer] != "" {
  82. resp.Disclaimer = conf[models.BusinessConfDisclaimer]
  83. }
  84. // 研报分享抬头
  85. if v, ok := conf[models.BusinessConfH5ShareName]; ok {
  86. resp.H5ShareName = v
  87. }
  88. if v, ok := conf[models.BusinessConfH5ReportShareImg]; ok {
  89. resp.H5ReportShareImg = v
  90. }
  91. // 更新pv
  92. if e = models.UpdateSmartReportPv(item.SmartReportId); e != nil {
  93. br.Msg = "获取失败"
  94. br.ErrMsg = "更新报告pv失败, Err: " + e.Error()
  95. return
  96. }
  97. br.Ret = 200
  98. br.Success = true
  99. br.Msg = "获取成功"
  100. br.Data = resp
  101. }
  102. // Detail
  103. // @Title 微信分享详情
  104. // @Description 微信分享详情
  105. // @Param ReportCode query string true "报告唯一编码"
  106. // @Success 200 {object} models.SmartReportWechatShareDetailResp
  107. // @router /wechat_share/detail [get]
  108. func (this *SmartReportController) WechatShareDetail() {
  109. br := new(models.BaseResponse).Init()
  110. defer func() {
  111. if br.ErrMsg == "" {
  112. br.IsSendEmail = false
  113. }
  114. this.Data["json"] = br
  115. this.ServeJSON()
  116. }()
  117. reportCode := this.GetString("ReportCode")
  118. if reportCode == "" {
  119. br.Msg = "获取失败"
  120. br.ErrMsg = fmt.Sprintf("参数有误, ReportCode: %s", reportCode)
  121. return
  122. }
  123. resp := new(models.SmartReportWechatShareDetailResp)
  124. item, e := models.GetReportByCode(reportCode)
  125. if e != nil {
  126. if e.Error() == utils.ErrNoRow() {
  127. br.Msg = "报告不存在, 请刷新页面"
  128. return
  129. }
  130. br.Msg = "获取失败"
  131. br.ErrMsg = "获取报告失败, Err: " + e.Error()
  132. return
  133. }
  134. // 免责声明
  135. conf, e := models.GetBusinessConf()
  136. if e != nil {
  137. br.Msg = "获取失败"
  138. br.ErrMsg = "获取免责声明失败, Err: " + e.Error()
  139. return
  140. }
  141. date := strings.Replace(item.CreateTime, "-", "", -1)
  142. dateStr := date[4:9]
  143. var shareTitle string
  144. // 研报分享抬头
  145. if utils.BusinessCode == "E2023080700" || utils.BusinessCode == "E2023080900" || utils.BusinessCode == "E2023080901" {
  146. shareTitle = "【第" + strconv.Itoa(item.Stage) + "期|FICC】" + item.Title + "(" + dateStr + ")"
  147. } else {
  148. shareTitle = "【第" + strconv.Itoa(item.Stage) + "期】" + item.Title + "(" + dateStr + ")"
  149. }
  150. if v, ok := conf[models.BusinessConfH5ReportShareImg]; ok {
  151. resp.H5ReportShareImg = v
  152. }
  153. if v, ok := conf[models.BusinessConfH5ShareName]; ok {
  154. resp.H5ShareName = v
  155. }
  156. resp.H5ShareTitle = shareTitle
  157. br.Ret = 200
  158. br.Success = true
  159. br.Msg = "获取成功"
  160. br.Data = resp
  161. }
  162. // WechatShareOutsideReportDetail
  163. // @Title 微信分享外部报告详情
  164. // @Description 微信分享外部报告详情
  165. // @Param ReportCode query string true "报告唯一编码"
  166. // @Success 200 {object} models.SmartReportWechatShareDetailResp
  167. // @router /wechat_share/outside/report/detail [get]
  168. func (this *SmartReportController) WechatShareOutsideReportDetail() {
  169. br := new(models.BaseResponse).Init()
  170. defer func() {
  171. if br.ErrMsg == "" {
  172. br.IsSendEmail = false
  173. }
  174. this.Data["json"] = br
  175. this.ServeJSON()
  176. }()
  177. reportCode := this.GetString("ReportCode")
  178. if reportCode == "" {
  179. br.Msg = "获取失败"
  180. br.ErrMsg = fmt.Sprintf("参数有误, ReportCode: %s", reportCode)
  181. return
  182. }
  183. resp := new(models.SmartReportWechatShareDetailResp)
  184. item, e := models.GetOutsideReportByReportCode(reportCode)
  185. if e != nil {
  186. if e.Error() == utils.ErrNoRow() {
  187. br.Msg = "报告不存在, 请刷新页面"
  188. return
  189. }
  190. br.Msg = "获取失败"
  191. br.ErrMsg = "获取报告失败, Err: " + e.Error()
  192. return
  193. }
  194. // 免责声明
  195. conf, e := models.GetBusinessConf()
  196. if e != nil {
  197. br.Msg = "获取失败"
  198. br.ErrMsg = "获取免责声明失败, Err: " + e.Error()
  199. return
  200. }
  201. /*
  202. date := strings.Replace(item.CreateTime, "-", "", -1)
  203. dateStr := date[4:9]
  204. var shareTitle string
  205. // 研报分享抬头
  206. if utils.BusinessCode == "E2023080700" || utils.BusinessCode == "E2023080900" || utils.BusinessCode == "E2023080901" {
  207. shareTitle = "【第" + strconv.Itoa(item.Stage) + "期|FICC】" + item.Title + "(" + dateStr + ")"
  208. } else {
  209. shareTitle = "【第" + strconv.Itoa(item.Stage) + "期】" + item.Title + "(" + dateStr + ")"
  210. }*/
  211. if v, ok := conf[models.BusinessConfH5ReportShareImg]; ok {
  212. resp.H5ReportShareImg = v
  213. }
  214. if v, ok := conf[models.BusinessConfH5ShareName]; ok {
  215. resp.H5ShareName = v
  216. }
  217. resp.H5ShareTitle = item.Title
  218. br.Ret = 200
  219. br.Success = true
  220. br.Msg = "获取成功"
  221. br.Data = resp
  222. }