chart.go 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  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. if this.User.Status != utils.UserStatusFormal {
  56. br.Msg = "用户没有权限查看图表"
  57. return
  58. }
  59. chartInfoId, _ := this.GetInt("ChartInfoId")
  60. if chartInfoId <= 0 {
  61. br.Msg = "图表id错误"
  62. return
  63. }
  64. result, err := services.GetChartDetail(chartInfoId)
  65. if err != nil {
  66. br.Msg = "获取图表详情失败"
  67. br.ErrMsg = "获取图表详情失败,Err:" + err.Error()
  68. return
  69. }
  70. if result.Ret != 200 {
  71. br.Msg = result.Msg
  72. br.ErrMsg = result.ErrMsg
  73. return
  74. }
  75. br.Data = result.Data
  76. br.Msg = "查询成功"
  77. br.Success = true
  78. br.Ret = 200
  79. }
  80. // @Title Locate
  81. // @Description create users
  82. // @Param PageSize query int true "每页数据条数"
  83. // @Param CurrentIndex query int true "当前页页码,从1开始"
  84. // @Success 200 {object} models.BaseResponse
  85. // @router /locate [get]
  86. func (this *ChartController) Locate() {
  87. br := new(models.BaseResponse).Init()
  88. defer func() {
  89. this.Data["json"] = br
  90. this.ServeJSON()
  91. }()
  92. pageSize, _ := this.GetInt("PageSize")
  93. currentIndex, _ := this.GetInt("CurrentIndex")
  94. if currentIndex <= 0 {
  95. currentIndex = 1
  96. }
  97. if pageSize <= 0 {
  98. pageSize = 2
  99. }
  100. result, err := services.GetChartList(currentIndex, pageSize)
  101. if err != nil {
  102. br.Msg = "查询图表失败"
  103. br.ErrMsg = "查询图表失败,系统异常,Err:" + err.Error()
  104. return
  105. }
  106. if result.Ret != 200 {
  107. br.Msg = result.Msg
  108. br.ErrMsg = result.ErrMsg
  109. return
  110. }
  111. total := len(result.Data.List)
  112. charts := make([]*response.ChartLocateItem, 0)
  113. items := result.Data.List
  114. for k, v := range items {
  115. var prevChartInfoId, nextChartInfoId int
  116. switch k {
  117. case 0:
  118. prevChartInfoId = -1
  119. if k < total-1 {
  120. nextChartInfoId = items[k+1].ChartInfoId
  121. } else {
  122. nextChartInfoId = -1
  123. }
  124. case total - 1:
  125. nextChartInfoId = -1
  126. if k > 0 {
  127. prevChartInfoId = items[k-1].ChartInfoId
  128. }
  129. default:
  130. prevChartInfoId = items[k-1].ChartInfoId
  131. nextChartInfoId = items[k+1].ChartInfoId
  132. }
  133. tmpLocate := &response.ChartLocateItem{
  134. ChartInfoId: v.ChartInfoId,
  135. ChartName: v.ChartName,
  136. UniqueCode: v.UniqueCode,
  137. PrevChartInfoId: prevChartInfoId,
  138. NextChartInfoId: nextChartInfoId,
  139. }
  140. charts = append(charts, tmpLocate)
  141. }
  142. br.Data = charts
  143. br.Msg = "查询成功"
  144. br.Success = true
  145. br.Ret = 200
  146. }