analyst_controller.go 5.7 KB

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