chart.go 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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. // @Failure 403 {object} models.BaseResponse
  17. // @router /list [get]
  18. func (this *ChartController) List() {
  19. br := new(models.BaseResponse).Init()
  20. defer func() {
  21. this.Data["json"] = br
  22. this.ServeJSON()
  23. }()
  24. pageSize, _ := this.GetInt("PageSize")
  25. currentIndex, _ := this.GetInt("CurrentIndex")
  26. result, err := services.GetChartList(currentIndex, pageSize)
  27. if err != nil {
  28. br.Msg = "查询图表失败"
  29. br.ErrMsg = "查询图表失败,系统异常,Err:" + err.Error()
  30. return
  31. }
  32. if result.Ret != 200 {
  33. br.Msg = "查询图表失败"
  34. br.ErrMsg = result.ErrMsg
  35. return
  36. }
  37. resp := new(response.ChartListResp)
  38. resp.List = result.Data.List
  39. resp.Paging = result.Data.Paging
  40. br.Msg = "查询图表成功"
  41. br.Data = result.Data
  42. br.Success = true
  43. br.Ret = 200
  44. }
  45. // @Title Detail
  46. // @Description 图表详情
  47. // @Param ChartInfoId query int true "图表详情id"
  48. // @Success 200 {object} models.BaseResponse
  49. // @router /detail [get]
  50. func (this *ChartController) Detail() {
  51. br := new(models.BaseResponse).Init()
  52. defer func() {
  53. this.Data["json"] = br
  54. this.ServeJSON()
  55. }()
  56. if this.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. br.Data = result.Data
  77. br.Msg = "查询成功"
  78. br.Success = true
  79. br.Ret = 200
  80. }
  81. // @Title Locate
  82. // @Description create users
  83. // @Param PageSize query int true "每页数据条数"
  84. // @Param CurrentIndex query int true "当前页页码,从1开始"
  85. // @Success 200 {object} models.BaseResponse
  86. // @router /locate [get]
  87. func (this *ChartController) Locate() {
  88. br := new(models.BaseResponse).Init()
  89. defer func() {
  90. this.Data["json"] = br
  91. this.ServeJSON()
  92. }()
  93. pageSize, _ := this.GetInt("PageSize")
  94. currentIndex, _ := this.GetInt("CurrentIndex")
  95. if currentIndex <= 0 {
  96. currentIndex = 1
  97. }
  98. if pageSize <= 0 {
  99. pageSize = 2
  100. }
  101. result, err := services.GetChartList(currentIndex, pageSize)
  102. if err != nil {
  103. br.Msg = "查询图表失败"
  104. br.ErrMsg = "查询图表失败,系统异常,Err:" + err.Error()
  105. return
  106. }
  107. if result.Ret != 200 {
  108. br.Msg = result.Msg
  109. br.ErrMsg = result.ErrMsg
  110. return
  111. }
  112. total := len(result.Data.List)
  113. charts := make([]*response.ChartLocateItem, 0)
  114. items := result.Data.List
  115. for k, v := range items {
  116. var prevChartInfoId, nextChartInfoId int
  117. switch k {
  118. case 0:
  119. prevChartInfoId = -1
  120. if k < total-1 {
  121. nextChartInfoId = items[k+1].ChartInfoId
  122. } else {
  123. nextChartInfoId = -1
  124. }
  125. case total - 1:
  126. nextChartInfoId = -1
  127. if k > 0 {
  128. prevChartInfoId = items[k-1].ChartInfoId
  129. }
  130. default:
  131. prevChartInfoId = items[k-1].ChartInfoId
  132. nextChartInfoId = items[k+1].ChartInfoId
  133. }
  134. tmpLocate := &response.ChartLocateItem{
  135. ChartInfoId: v.ChartInfoId,
  136. ChartName: v.ChartName,
  137. UniqueCode: v.UniqueCode,
  138. PrevChartInfoId: prevChartInfoId,
  139. NextChartInfoId: nextChartInfoId,
  140. }
  141. charts = append(charts, tmpLocate)
  142. }
  143. br.Data = charts
  144. br.Msg = "查询成功"
  145. br.Success = true
  146. br.Ret = 200
  147. }