report.go 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  1. package controllers
  2. import (
  3. "eta/eta_mini_api/models"
  4. "eta/eta_mini_api/models/response"
  5. "eta/eta_mini_api/services"
  6. "eta/eta_mini_api/utils"
  7. )
  8. type ReportController struct {
  9. BaseAuthController
  10. }
  11. // @Title 研报详情
  12. // @Description 研报详情接口
  13. // @Param ReportId query int true "报告id"
  14. // @Success 200 {object} models.ReportDetailResp
  15. // @router /detail [get]
  16. func (this *ReportController) Detail() {
  17. br := new(models.BaseResponse).Init()
  18. defer func() {
  19. this.Data["json"] = br
  20. this.ServeJSON()
  21. }()
  22. reportId, _ := this.GetInt("ReportId")
  23. if reportId <= 0 {
  24. br.Msg = "报告不存在"
  25. return
  26. }
  27. user := this.User
  28. if user == nil {
  29. // 如果没有用户没有绑定信息,单独处理
  30. resp, er := services.GetReportDetailNoUser(reportId)
  31. if er != nil {
  32. br.Msg = "查询报告详情失败"
  33. br.ErrMsg = "查询报告失败,系统异常,Err:" + er.Error()
  34. return
  35. }
  36. if resp.Ret != 200 {
  37. br.Msg = resp.Msg
  38. br.ErrMsg = resp.ErrMsg
  39. return
  40. }
  41. br.Msg = "查询成功"
  42. br.Data = resp.Data
  43. br.Success = true
  44. br.Ret = 200
  45. return
  46. }
  47. result, err := services.GetReportDetail(reportId, user.UserId)
  48. if err != nil {
  49. br.Msg = "查询报告详情失败"
  50. br.ErrMsg = "查询报告失败,系统异常,Err:" + err.Error()
  51. return
  52. }
  53. if result.Ret == 403 {
  54. br.Msg = result.Msg
  55. br.ErrMsg = result.ErrMsg
  56. return
  57. }
  58. if result.Ret == 200 && result.Data.Report == nil {
  59. // 后台没有这个报告,那么尝试删除我的收藏
  60. models.DeleteMyReportByUserIdAndReportId(user.UserId, reportId)
  61. br.Msg = "该报告已删除或不存在,请刷新页面"
  62. return
  63. }
  64. count, err := models.GetMyReportCountByUserIdAndReportId(user.UserId, reportId)
  65. if err != nil {
  66. br.Msg = "查询收藏数量失败"
  67. br.ErrMsg = "查询收藏数量失败,Err:" + err.Error()
  68. return
  69. }
  70. if count > 0 {
  71. result.Data.IsCollect = true
  72. } else {
  73. result.Data.IsCollect = false
  74. }
  75. if user.UserId != 0 {
  76. result.Data.IsSignIn = true
  77. }
  78. br.Msg = "查询成功"
  79. br.Success = true
  80. br.Ret = 200
  81. br.Data = result.Data
  82. }
  83. // @Title 研报列表
  84. // @Description 研报列表
  85. // @Param ChartPermissionId query int true "品种ID"
  86. // @Param Level query int true "品种层级"
  87. // @Param PageSize query int true "每页数据条数"
  88. // @Param CurrentIndex query int true "当前页页码,从1开始"
  89. // @Param RangeType query string true "范围类型,1-一天内,2-一周内,3-半年内"
  90. // @Success 200 {object} response.ReportList
  91. // @router /list [get]
  92. func (this *ReportController) List() {
  93. br := new(models.BaseResponse).Init()
  94. defer func() {
  95. this.Data["json"] = br
  96. this.ServeJSON()
  97. }()
  98. pageSize, _ := this.GetInt("PageSize")
  99. currentIndex, _ := this.GetInt("CurrentIndex")
  100. chartPermissionId, _ := this.GetInt("ChartPermissionId")
  101. level, _ := this.GetInt("Level")
  102. rangeType, _ := this.GetInt("RangeType")
  103. reports, err := services.GetReportList(chartPermissionId, level, rangeType, currentIndex, pageSize)
  104. if err != nil {
  105. br.Msg = "研报列表查询失败"
  106. br.ErrMsg = "研报列表查询失败,系统异常,Err:" + err.Error()
  107. return
  108. }
  109. if reports.Ret != 200 {
  110. br.Msg = reports.Msg
  111. br.ErrMsg = reports.ErrMsg
  112. return
  113. }
  114. br.Data = reports.Data
  115. br.Msg = "查询成功"
  116. br.Ret = 200
  117. br.Success = true
  118. }
  119. // @Title 今日研报列表
  120. // @Description 今日研报列表
  121. // @Param PageSize query int true "每页数据条数"
  122. // @Param CurrentIndex query int true "当前页页码,从1开始"
  123. // @Success 200 {object} models.ReportDetailResp
  124. // @router /daily/list [get]
  125. func (this *ReportController) DailyList() {
  126. br := new(models.BaseResponse).Init()
  127. defer func() {
  128. this.Data["json"] = br
  129. this.ServeJSON()
  130. }()
  131. pageSize, _ := this.GetInt("PageSize")
  132. currentIndex, _ := this.GetInt("CurrentIndex")
  133. if pageSize <= 0 {
  134. pageSize = utils.PageSize20
  135. }
  136. reports, err := services.GetReportDailyList(currentIndex, pageSize)
  137. if err != nil {
  138. br.Msg = "研报列表查询失败"
  139. br.ErrMsg = "研报列表查询失败,系统异常,Err:" + err.Error()
  140. return
  141. }
  142. br.Data = reports.Data
  143. br.Msg = "查询成功"
  144. br.Ret = 200
  145. br.Success = true
  146. }
  147. // @Title 最新研报列表
  148. // @Description 最新研报列表
  149. // @Param PageSize query int true "每页数据条数"
  150. // @Param CurrentIndex query int true "当前页页码,从1开始"
  151. // @Success 200 {object} models.ReportDetailResp
  152. // @router /recent/list [get]
  153. func (this *ReportController) RecentList() {
  154. br := new(models.BaseResponse).Init()
  155. defer func() {
  156. this.Data["json"] = br
  157. this.ServeJSON()
  158. }()
  159. pageSize, _ := this.GetInt("PageSize")
  160. currentIndex, _ := this.GetInt("CurrentIndex")
  161. if pageSize <= 0 {
  162. pageSize = 3
  163. }
  164. reports, err := services.GetReportRecentList(currentIndex, pageSize)
  165. if err != nil {
  166. br.Msg = "研报列表查询失败"
  167. br.ErrMsg = "研报列表查询失败,系统异常,Err:" + err.Error()
  168. return
  169. }
  170. br.Data = reports.Data
  171. br.Msg = "查询成功"
  172. br.Ret = 200
  173. br.Success = true
  174. }
  175. // @Title 研报列表
  176. // @Description 研报列表
  177. // @Param ReportId query int true "报告id"
  178. // @Param chartPermissionId query int true "品种ID"
  179. // @Param PageSize query int true "每页数据条数"
  180. // @Param CurrentIndex query int true "当前页页码,从1开始"
  181. // @Success 200 {object} models.ReportDetailResp
  182. // @router /search [get]
  183. func (this *ReportController) Search() {
  184. br := new(models.BaseResponse).Init()
  185. defer func() {
  186. this.Data["json"] = br
  187. this.ServeJSON()
  188. }()
  189. keyWord := this.GetString("KeyWord")
  190. pageSize, _ := this.GetInt("PageSize")
  191. currentIndex, _ := this.GetInt("CurrentIndex")
  192. if pageSize <= 0 {
  193. pageSize = utils.PageSize30
  194. }
  195. if keyWord == "" {
  196. br.Msg = "请输入关键字"
  197. return
  198. }
  199. reports, err := services.SearchReport(keyWord, currentIndex, pageSize)
  200. if err != nil {
  201. br.Msg = "研报列表查询失败"
  202. br.ErrMsg = "研报列表查询失败,系统异常,Err:" + err.Error()
  203. return
  204. }
  205. if reports.Ret != 200 {
  206. br.Msg = reports.Msg
  207. br.ErrMsg = reports.ErrMsg
  208. return
  209. }
  210. resp := new(response.ReportSearchViewResp)
  211. list := make([]*response.ReportSearchListView, 0)
  212. for _, v := range reports.Data.List {
  213. tmpReport := &response.ReportSearchListView{
  214. ReportId: v.ReportId,
  215. ReportChapterId: v.ReportChapterId,
  216. ClassifyIdFirst: v.ClassifyIdFirst,
  217. ClassifyNameFirst: v.ClassifyNameFirst,
  218. ClassifyIdSecond: v.ClassifyIdSecond,
  219. ClassifyNameSecond: v.ClassifyNameSecond,
  220. ReportChapterTypeId: v.ReportChapterTypeId,
  221. PublishTime: v.PublishTime.Format(utils.FormatDate),
  222. Title: v.Title,
  223. ContentSub: v.ContentSub,
  224. Abstract: v.Abstract,
  225. Stage: v.Stage,
  226. Author: v.Author,
  227. }
  228. if v.PublishTime.IsZero() {
  229. tmpReport.PublishTime = ""
  230. }
  231. list = append(list, tmpReport)
  232. }
  233. resp.List = list
  234. resp.Paging = reports.Data.Paging
  235. br.Data = resp
  236. br.Msg = "查询成功"
  237. br.Ret = 200
  238. br.Success = true
  239. }