chart.go 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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. )
  7. type ChartController struct {
  8. BaseAuthController
  9. }
  10. // @Title List
  11. // @Description create users
  12. // @Param PageSize query int true "每页数据条数"
  13. // @Param CurrentIndex query int true "当前页页码,从1开始"
  14. // @Success 200 {object} models.BaseResponse
  15. // @router /list [get]
  16. func (this *ChartController) List() {
  17. br := new(models.BaseResponse).Init()
  18. defer func() {
  19. this.Data["json"] = br
  20. this.ServeJSON()
  21. }()
  22. pageSize, _ := this.GetInt("PageSize")
  23. currentIndex, _ := this.GetInt("CurrentIndex")
  24. result, err := services.GetChartList(currentIndex, pageSize)
  25. if err != nil {
  26. br.Msg = "查询图表失败"
  27. br.ErrMsg = "查询图表失败,系统异常,Err:" + err.Error()
  28. return
  29. }
  30. if result.Ret != 200 {
  31. br.Msg = "查询图表失败"
  32. br.ErrMsg = result.ErrMsg
  33. return
  34. }
  35. br.Msg = "查询图表成功"
  36. br.Data = result.Data
  37. br.Success = true
  38. br.Ret = 200
  39. }
  40. // @Title Locate
  41. // @Description create users
  42. // @Param PageSize query int true "每页数据条数"
  43. // @Param CurrentIndex query int true "当前页页码,从1开始"
  44. // @Success 200 {object} models.BaseResponse
  45. // @router /locate [get]
  46. func (this *ChartController) Locate() {
  47. br := new(models.BaseResponse).Init()
  48. defer func() {
  49. this.Data["json"] = br
  50. this.ServeJSON()
  51. }()
  52. pageSize, _ := this.GetInt("PageSize")
  53. currentIndex, _ := this.GetInt("CurrentIndex")
  54. if currentIndex <= 0 {
  55. currentIndex = 1
  56. }
  57. if pageSize <= 0 {
  58. pageSize = 2
  59. }
  60. result, err := services.GetChartList(currentIndex, pageSize)
  61. if err != nil {
  62. br.Msg = "查询图表失败"
  63. br.ErrMsg = "查询图表失败,系统异常,Err:" + err.Error()
  64. return
  65. }
  66. if result.Ret != 200 {
  67. br.Msg = result.Msg
  68. br.ErrMsg = result.ErrMsg
  69. return
  70. }
  71. total := len(result.Data.List)
  72. charts := make([]*response.ChartLocateItem, 0)
  73. items := result.Data.List
  74. for k, v := range items {
  75. var prevChartInfoId, nextChartInfoId int
  76. switch k {
  77. case 0:
  78. prevChartInfoId = -1
  79. if k < total-1 {
  80. nextChartInfoId = items[k+1].ChartInfoId
  81. } else {
  82. nextChartInfoId = -1
  83. }
  84. case total - 1:
  85. nextChartInfoId = -1
  86. if k > 0 {
  87. prevChartInfoId = items[k-1].ChartInfoId
  88. }
  89. default:
  90. prevChartInfoId = items[k-1].ChartInfoId
  91. nextChartInfoId = items[k+1].ChartInfoId
  92. }
  93. tmpLocate := &response.ChartLocateItem{
  94. ChartInfoId: v.ChartInfoId,
  95. ChartName: v.ChartName,
  96. UniqueCode: v.UniqueCode,
  97. PrevChartInfoId: prevChartInfoId,
  98. NextChartInfoId: nextChartInfoId,
  99. }
  100. charts = append(charts, tmpLocate)
  101. }
  102. br.Data = charts
  103. br.Msg = "查询成功"
  104. br.Success = true
  105. br.Ret = 200
  106. }