report_pc.go 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. package controllers
  2. import (
  3. "hongze/hongze_api/models"
  4. "hongze/hongze_api/utils"
  5. )
  6. // @Title 研报列表
  7. // @Description 研报列表接口
  8. // @Param ClassifyId query int true "分类id"
  9. // @Success 200 {object} models.ResearchReportListResp
  10. // @router /pc/research/report/list [get]
  11. func (this *ReportCommonController) ResearchReportList() {
  12. br := new(models.BaseResponse).Init()
  13. defer func() {
  14. this.Data["json"] = br
  15. this.ServeJSON()
  16. }()
  17. classifyId, _ := this.GetInt("ClassifyId")
  18. if classifyId <= 0 {
  19. br.Msg = "参数错误"
  20. br.ErrMsg = "参数错误,分类id小于等于0"
  21. return
  22. }
  23. list, err := models.GetResearchReportList(classifyId)
  24. if err != nil {
  25. br.Msg = "获取失败"
  26. br.ErrMsg = "获取失败,Err:" + err.Error()
  27. return
  28. }
  29. resp := new(models.ResearchReportListResp)
  30. resp.List = list
  31. br.Ret = 200
  32. br.Success = true
  33. br.Msg = "获取成功"
  34. br.Data = resp
  35. }
  36. // @Title 研报PC端搜索接口
  37. // @Param KeyWord query string true "搜索关键词"
  38. // @Success 200 {object} models.PcSearchReportListResp
  39. // @router /pc/search/report/list [get]
  40. func (this *ReportCommonController) PcSearchReportList() {
  41. // @Description 研报PC端搜索接口
  42. // @Param PageSize query int true "每页数据条数"
  43. // @Param CurrentIndex query int true "当前页页码,从1开始"
  44. br := new(models.BaseResponse).Init()
  45. defer func() {
  46. this.Data["json"] = br
  47. this.ServeJSON()
  48. }()
  49. keyWord := this.GetString("KeyWord")
  50. //pageSize, _ := this.GetInt("PageSize")
  51. //currentIndex, _ := this.GetInt("CurrentIndex")
  52. //classifyId, _ := this.GetInt("ClassifyId")
  53. //if classifyId <= 0 {
  54. // br.Msg = "参数错误"
  55. // br.ErrMsg = "参数错误,分类id小于等于0"
  56. // return
  57. //}
  58. //
  59. //page := paging.GetPaging(currentIndex, pageSize, 0)
  60. resp := new(models.PcSearchReportListResp)
  61. var condition string
  62. //var pars []interface{}
  63. if keyWord != "" {
  64. condition += ` AND (a.title LIKE '%` + keyWord + `%' OR a.abstract LIKE '%` + keyWord + `%') `
  65. } else {
  66. list := make([]*models.ReportList, 0)
  67. resp.List = list
  68. //resp.Paging = page
  69. br.Ret = 200
  70. br.Success = true
  71. br.Msg = "获取成功"
  72. br.Data = resp
  73. return
  74. }
  75. //var startSize int
  76. //if pageSize <= 0 {
  77. // pageSize = utils.PageSize20
  78. //}
  79. //if currentIndex <= 0 {
  80. // currentIndex = 1
  81. //}
  82. //startSize = utils.StartIndex(currentIndex, pageSize)
  83. //total, err := models.GetSearchReportListCount(condition)
  84. //if err != nil {
  85. // br.Msg = "获取数据失败"
  86. // br.ErrMsg = "获取数据失败,Err:" + err.Error()
  87. // return
  88. //}
  89. var uid int
  90. if this.Token != "" && this.User != nil {
  91. uid = this.User.UserId
  92. }
  93. var hasPermission bool
  94. reportType := "rddp"
  95. reportPermissionList, err := models.GetReportVarietyListByUserIdExt(uid, reportType) //获取客户拥有权限的报告id
  96. if err != nil {
  97. if err.Error() != utils.ErrNoRow() {
  98. br.Msg = "获取报告详情失败"
  99. br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  100. return
  101. } else {
  102. hasPermission = false
  103. }
  104. }
  105. if len(reportPermissionList) == 0 {
  106. hasPermission = false
  107. }
  108. permissionMap := make(map[int]int)
  109. for _, v := range reportPermissionList {
  110. if _, ok := permissionMap[v.ReportChapterTypeId]; !ok {
  111. permissionMap[v.ReportChapterTypeId] = v.ReportChapterTypeId
  112. }
  113. }
  114. list, err := models.GetSearchReportList(condition)
  115. if err != nil {
  116. br.Msg = "获取失败"
  117. br.ErrMsg = "获取失败,Err:" + err.Error()
  118. return
  119. }
  120. listLen := len(list)
  121. for i := 0; i < listLen; i++ {
  122. item := list[i]
  123. if this.Token != "" {
  124. count, err := models.GetReportPermission(uid, item.ClassifyNameSecond)
  125. if err != nil && err.Error()!=utils.ErrNoRow() {
  126. br.Msg = "获取失败"
  127. br.ErrMsg = "判断报告是否拥有权限失败,Err:" + err.Error()
  128. return
  129. }
  130. if count > 0 {
  131. list[i].HasPermission = 1
  132. } else {
  133. list[i].VideoUrl = ""
  134. list[i].VideoName = ""
  135. list[i].VideoPlaySeconds = ""
  136. list[i].VideoSize = ""
  137. }
  138. } else {
  139. list[i].VideoUrl = ""
  140. list[i].VideoName = ""
  141. list[i].VideoPlaySeconds = ""
  142. list[i].VideoSize = ""
  143. }
  144. if hasPermission == false {
  145. list[i].VideoUrl = ""
  146. list[i].VideoName = ""
  147. list[i].VideoPlaySeconds = ""
  148. list[i].VideoSize = ""
  149. }
  150. if item.ClassifyNameFirst == "权益研报" {
  151. list[i].TitleType = "路演精华"
  152. } else {
  153. list[i].TitleType = "FICC"
  154. }
  155. }
  156. //page = paging.GetPaging(currentIndex, pageSize, total)
  157. resp.List = list
  158. //resp.Paging = page
  159. br.Ret = 200
  160. br.Success = true
  161. br.Msg = "获取成功"
  162. br.Data = resp
  163. }