analyst_controller.go 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. package user
  2. import (
  3. "eta/eta_mini_ht_api/common/exception"
  4. "eta/eta_mini_ht_api/common/utils/page"
  5. "eta/eta_mini_ht_api/controllers"
  6. "eta/eta_mini_ht_api/service/analyst"
  7. "eta/eta_mini_ht_api/service/media"
  8. "eta/eta_mini_ht_api/service/report"
  9. "eta/eta_mini_ht_api/service/user"
  10. "fmt"
  11. )
  12. type AnalystController struct {
  13. controllers.ListController
  14. }
  15. // AnalystList 研究员列表
  16. // @Summary 研究员列表
  17. // @Description 研究员列表
  18. // @Success 200 {object} controllers.BaseResponse
  19. // @router /list [get]
  20. func (an *AnalystController) AnalystList() {
  21. controllers.Wrap(&an.BaseController, func() (result *controllers.WrapData, err error) {
  22. result = an.InitWrapData("获取研究员列表失败")
  23. var userInfo user.User
  24. userInfo = an.Data["user"].(user.User)
  25. pageRes := page.Page{
  26. Current: an.PageInfo.Current,
  27. PageSize: an.PageInfo.PageSize,
  28. }
  29. if an.PageInfo.LatestId == 0 {
  30. pageRes.Total, pageRes.LatestId = analyst.GetAnalystCount()
  31. an.PageInfo.LatestId = pageRes.LatestId
  32. an.PageInfo.Total = pageRes.Total
  33. } else {
  34. pageRes.LatestId = an.PageInfo.LatestId
  35. pageRes.Total = an.PageInfo.Total
  36. }
  37. an.PageInfo.Total = pageRes.Total
  38. pageRes.TotalPage = page.TotalPages(pageRes.Total, pageRes.PageSize)
  39. list, err := analyst.GetAnalystList(an.PageInfo, userInfo.Id)
  40. if err != nil {
  41. an.FailedResult("获取研究员列表失败", result)
  42. return
  43. }
  44. analystList := new(page.PageResult)
  45. analystList.Data = list
  46. analystList.Page = pageRes
  47. an.SuccessResult("获取研究员列表成功", analystList, result)
  48. return
  49. })
  50. }
  51. // AnalystDetail 研究员详情
  52. // @Summary 研究员详情
  53. // @Description 研究员详情
  54. // @Success 200 {object} controllers.BaseResponse
  55. // @router /analystDetail [get]
  56. func (an *AnalystController) AnalystDetail(analystId int) {
  57. controllers.Wrap(&an.BaseController, func() (result *controllers.WrapData, err error) {
  58. result = an.InitWrapData("获取研究员详情失败")
  59. fmt.Println(analystId)
  60. userInfo := an.Data["user"].(user.User)
  61. detail, err := user.GetAnalystDetail(userInfo.Id, analystId)
  62. if err != nil {
  63. an.FailedResult("获取研究员详情失败", result)
  64. return
  65. }
  66. an.SuccessResult("获取研究员详情成功", detail, result)
  67. return
  68. })
  69. }
  70. // AnalystReportList @Title 获取研究员报告列表
  71. // @Description 获取研究员报告列表
  72. // @Success 200 {object}
  73. // @router /reportList [get]
  74. func (an *AnalystController) AnalystReportList(analystName string) {
  75. controllers.Wrap(&an.BaseController, func() (result *controllers.WrapData, err error) {
  76. result = an.InitWrapData("分页获取研究员报告列表失败")
  77. pageRes := page.Page{
  78. Current: an.PageInfo.Current,
  79. PageSize: an.PageInfo.PageSize,
  80. }
  81. if an.PageInfo.LatestId == 0 {
  82. pageRes.Total, pageRes.LatestId = report.GetTotalPageCountByAnalyst(analystName)
  83. an.PageInfo.LatestId = pageRes.LatestId
  84. } else {
  85. pageRes.LatestId = an.PageInfo.LatestId
  86. pageRes.Total = an.PageInfo.Total
  87. }
  88. pageRes.TotalPage = page.TotalPages(pageRes.Total, pageRes.PageSize)
  89. list, err := report.GetReportPageByAnalyst(an.PageInfo, analystName)
  90. if err != nil {
  91. an.FailedResult("分页获取研究员报告列表失败", result)
  92. return
  93. }
  94. reports := new(page.PageResult)
  95. reports.Data = list
  96. reports.Page = pageRes
  97. an.SuccessResult("分页获取研究员报告列表成功", reports, result)
  98. return
  99. })
  100. }
  101. // MediaList 获取研究员媒体列表
  102. // @Description 获取研究员媒体列表
  103. // @Success 200 {object}
  104. // @router /mediaList [get]
  105. func (an *AnalystController) MediaList(mediaType string, analystId int) {
  106. controllers.Wrap(&an.BaseController, func() (result *controllers.WrapData, err error) {
  107. result = an.InitWrapData("分页查询研究员媒体列表失败")
  108. if mediaType == "" || !an.CheckMediaType(mediaType) {
  109. err = exception.New(exception.MediaTypeError)
  110. an.FailedResult("分页查询研究员媒体列表失败", result)
  111. return
  112. }
  113. pageRes := page.Page{
  114. Current: an.PageInfo.Current,
  115. PageSize: an.PageInfo.PageSize,
  116. }
  117. if an.PageInfo.LatestId == 0 {
  118. pageRes.Total, pageRes.LatestId = media.GetTotalPageCountByAnalystId(mediaType, analystId)
  119. an.PageInfo.LatestId = pageRes.LatestId
  120. an.PageInfo.Total = pageRes.Total
  121. } else {
  122. pageRes.LatestId = an.PageInfo.LatestId
  123. pageRes.Total = an.PageInfo.Total
  124. }
  125. pageRes.TotalPage = page.TotalPages(pageRes.Total, pageRes.PageSize)
  126. list, err := media.GetMediaPageByAnalystId(mediaType, an.PageInfo, analystId)
  127. if err != nil {
  128. an.FailedResult("分页查询研究员媒体列表失败", result)
  129. return
  130. }
  131. mediaList := new(page.PageResult)
  132. mediaList.Data = list
  133. mediaList.Page = pageRes
  134. an.SuccessResult("分页查询研究员媒体列表成功", mediaList, result)
  135. return
  136. })
  137. }