chart.go 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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 ChartController struct {
  9. BaseAuthController
  10. }
  11. // @Title List
  12. // @Description create users
  13. // @Param PageSize query int true "每页数据条数"
  14. // @Param CurrentIndex query int true "当前页页码,从1开始"
  15. // @Success 200 {object} models.BaseResponse
  16. // @router /list [get]
  17. func (this *ChartController) List() {
  18. br := new(models.BaseResponse).Init()
  19. defer func() {
  20. this.Data["json"] = br
  21. this.ServeJSON()
  22. }()
  23. pageSize, _ := this.GetInt("PageSize")
  24. currentIndex, _ := this.GetInt("CurrentIndex")
  25. result, err := services.GetChartList(currentIndex, pageSize)
  26. if err != nil {
  27. br.Msg = "查询图表失败"
  28. br.ErrMsg = "查询图表失败,系统异常,Err:" + err.Error()
  29. return
  30. }
  31. if result.Ret != 200 {
  32. br.Msg = "查询图表失败"
  33. br.ErrMsg = result.ErrMsg
  34. return
  35. }
  36. resp := new(response.ChartListResp)
  37. resp.List = result.Data.List
  38. resp.Paging = result.Data.Paging
  39. br.Msg = "查询图表成功"
  40. br.Data = result.Data
  41. br.Success = true
  42. br.Ret = 200
  43. }
  44. // @Title Detail
  45. // @Description 图表详情
  46. // @Param ChartInfoId query int true "图表详情id"
  47. // @Success 200 {object} models.BaseResponse
  48. // @router /detail [get]
  49. func (this *ChartController) Detail() {
  50. br := new(models.BaseResponse).Init()
  51. defer func() {
  52. this.Data["json"] = br
  53. this.ServeJSON()
  54. }()
  55. user := this.User
  56. if user.Status != utils.UserStatusFormal {
  57. br.Msg = "用户没有权限查看图表"
  58. return
  59. }
  60. chartInfoId, _ := this.GetInt("ChartInfoId")
  61. if chartInfoId <= 0 {
  62. br.Msg = "图表id错误"
  63. return
  64. }
  65. result, err := services.GetChartDetail(chartInfoId)
  66. if err != nil {
  67. br.Msg = "获取图表详情失败"
  68. br.ErrMsg = "获取图表详情失败,Err:" + err.Error()
  69. return
  70. }
  71. if result.Ret != 200 {
  72. br.Msg = result.Msg
  73. br.ErrMsg = result.ErrMsg
  74. return
  75. }
  76. count, err := models.GetMyChartCount(user.UserId, result.Data.UniqueCode)
  77. if err != nil {
  78. br.Msg = "获取图表详情失败"
  79. br.ErrMsg = "获取图表详情失败,Err:" + err.Error()
  80. }
  81. if count > 0 {
  82. result.Data.IsCollect = true
  83. }
  84. br.Data = result.Data
  85. br.Msg = "查询成功"
  86. br.Success = true
  87. br.Ret = 200
  88. }
  89. // @Title Locate
  90. // @Description create users
  91. // @Param PageSize query int true "每页数据条数"
  92. // @Param CurrentIndex query int true "当前页页码,从1开始"
  93. // @Success 200 {object} models.BaseResponse
  94. // @router /locate [get]
  95. func (this *ChartController) Locate() {
  96. br := new(models.BaseResponse).Init()
  97. defer func() {
  98. this.Data["json"] = br
  99. this.ServeJSON()
  100. }()
  101. pageSize, _ := this.GetInt("PageSize")
  102. currentIndex, _ := this.GetInt("CurrentIndex")
  103. if currentIndex <= 0 {
  104. currentIndex = 1
  105. }
  106. if pageSize <= 0 {
  107. pageSize = 2
  108. }
  109. result, err := services.GetChartList(currentIndex, pageSize)
  110. if err != nil {
  111. br.Msg = "查询图表失败"
  112. br.ErrMsg = "查询图表失败,系统异常,Err:" + err.Error()
  113. return
  114. }
  115. if result.Ret != 200 {
  116. br.Msg = result.Msg
  117. br.ErrMsg = result.ErrMsg
  118. return
  119. }
  120. total := len(result.Data.List)
  121. charts := make([]*response.ChartLocateItem, 0)
  122. items := result.Data.List
  123. for k, v := range items {
  124. var prevChartInfoId, nextChartInfoId int
  125. switch k {
  126. case 0:
  127. prevChartInfoId = -1
  128. if k < total-1 {
  129. nextChartInfoId = items[k+1].ChartInfoId
  130. } else {
  131. nextChartInfoId = -1
  132. }
  133. case total - 1:
  134. nextChartInfoId = -1
  135. if k > 0 {
  136. prevChartInfoId = items[k-1].ChartInfoId
  137. }
  138. default:
  139. prevChartInfoId = items[k-1].ChartInfoId
  140. nextChartInfoId = items[k+1].ChartInfoId
  141. }
  142. tmpLocate := &response.ChartLocateItem{
  143. ChartInfoId: v.ChartInfoId,
  144. ChartName: v.ChartName,
  145. UniqueCode: v.UniqueCode,
  146. PrevChartInfoId: prevChartInfoId,
  147. NextChartInfoId: nextChartInfoId,
  148. }
  149. charts = append(charts, tmpLocate)
  150. }
  151. br.Data = charts
  152. br.Msg = "查询成功"
  153. br.Success = true
  154. br.Ret = 200
  155. }