chart.go 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. package controllers
  2. import (
  3. "eta/eta_hub/models"
  4. "eta/eta_hub/models/data_manage"
  5. "eta/eta_hub/services"
  6. "eta/eta_hub/utils"
  7. )
  8. // ChartController 图表
  9. type ChartController struct {
  10. BaseAuthController
  11. }
  12. // ClassifyList
  13. // @Title 分类列表
  14. // @Description 分类列表
  15. // @Success 200 {object} data_manage.ChartClassifyItem
  16. // @router /classify/list [get]
  17. func (this *ChartController) ClassifyList() {
  18. br := new(models.BaseResponse).Init()
  19. defer func() {
  20. this.Data["json"] = br
  21. this.ServeJSON()
  22. }()
  23. source := utils.CHART_SOURCE_DEFAULT
  24. cond := ` AND source = ?`
  25. pars := make([]interface{}, 0)
  26. pars = append(pars, source)
  27. classifyOb := new(data_manage.ChartClassify)
  28. classifies, e := classifyOb.GetItemsByCondition(cond, pars, []string{}, "parent_id ASC, sort ASC")
  29. if e != nil {
  30. br.Msg = "获取失败"
  31. br.ErrMsg = "ChartClassifyList GetItemsByCondition err: " + e.Error()
  32. return
  33. }
  34. resp := make([]*data_manage.ChartClassifyItem, 0)
  35. for _, v := range classifies {
  36. resp = append(resp, data_manage.FormatChartClassify2Item(v))
  37. }
  38. br.Data = resp
  39. br.Ret = 200
  40. br.Msg = "获取成功"
  41. }
  42. // ClassifyTree
  43. // @Title 图库分类树
  44. // @Description 图库分类树
  45. // @Success 200 {object} data_manage.ChartClassifyItem
  46. // @router /classify/tree [get]
  47. func (this *ChartController) ClassifyTree() {
  48. br := new(models.BaseResponse).Init()
  49. defer func() {
  50. this.Data["json"] = br
  51. this.ServeJSON()
  52. }()
  53. // 获取所有分类
  54. classifyOb := new(data_manage.ChartClassify)
  55. cond := ` AND source = ?`
  56. pars := make([]interface{}, 0)
  57. pars = append(pars, utils.CHART_SOURCE_DEFAULT)
  58. classifies, e := classifyOb.GetItemsByCondition(cond, pars, []string{}, "sort ASC, parent_id ASC")
  59. if e != nil {
  60. br.Msg = "获取失败"
  61. br.ErrMsg = "ChartClassifyTree GetItemsByCondition err: " + e.Error()
  62. return
  63. }
  64. // 递归生成分类树
  65. classifyTree := services.GetChartClassifyTreeRecursive(classifies, 0)
  66. br.Data = classifyTree
  67. br.Ret = 200
  68. br.Msg = "获取成功"
  69. }
  70. // List
  71. // @Title 图表列表
  72. // @Description 图表列表
  73. // @Param ClassifyId query int true "图表分类ID"
  74. // @Success 200 {object} data_manage.ChartInfoItem
  75. // @router /list [get]
  76. func (this *ChartController) List() {
  77. br := new(models.BaseResponse).Init()
  78. defer func() {
  79. this.Data["json"] = br
  80. this.ServeJSON()
  81. }()
  82. classifyId, _ := this.GetInt("ClassifyId")
  83. if classifyId <= 0 {
  84. br.Msg = "参数有误"
  85. return
  86. }
  87. chartOb := new(data_manage.ChartInfo)
  88. cond := ` AND chart_classify_id = ? AND source = ?`
  89. pars := make([]interface{}, 0)
  90. pars = append(pars, classifyId, utils.CHART_SOURCE_DEFAULT)
  91. charts, e := chartOb.GetItemsByCondition(cond, pars, []string{}, "sort ASC")
  92. if e != nil {
  93. br.Msg = "获取失败"
  94. br.ErrMsg = "ChartList GetItemsByCondition err: " + e.Error()
  95. return
  96. }
  97. resp := make([]*data_manage.ChartInfoItem, 0)
  98. for _, v := range charts {
  99. resp = append(resp, data_manage.FormatChartInfo2Item(v))
  100. }
  101. br.Data = resp
  102. br.Ret = 200
  103. br.Msg = "获取成功"
  104. }
  105. // Detail
  106. // @Title 图表详情
  107. // @Description 图表详情(这个接口的意义不大, 拿到数据也没啥用=_=!)
  108. // @Success 200 {object} models.Report
  109. // @router /detail [get]
  110. //func (this *ChartController) Detail() {
  111. // br := new(models.BaseResponse).Init()
  112. // defer func() {
  113. // this.Data["json"] = br
  114. // this.ServeJSON()
  115. // }()
  116. //
  117. // unicode := this.GetString("UniqueCode")
  118. // if unicode == "" {
  119. // br.Msg = "参数有误"
  120. // return
  121. // }
  122. // chartOb := new(data_manage.ChartInfo)
  123. // _, e := chartOb.GetItemByCode(unicode)
  124. // if e != nil {
  125. // if e.Error() == utils.ErrNoRow() {
  126. // br.Msg = "图表不存在"
  127. // return
  128. // }
  129. // br.Msg = "获取失败"
  130. // br.ErrMsg = "ChartDetail GetItemByCode err: " + e.Error()
  131. // return
  132. // }
  133. //
  134. // // 从edb_chart_lib中获取图详情, 这边只做部分数据的返回
  135. // detail, e := services.GetChartDetailFromChartLibByUnicode(unicode)
  136. // if e != nil {
  137. // br.Msg = "获取失败"
  138. // br.ErrMsg = "ChartDetail GetChartDetailFromChartLibByUnicode err: " + e.Error()
  139. // return
  140. // }
  141. //
  142. // br.Data = detail
  143. // br.Ret = 200
  144. // br.Msg = "获取成功"
  145. //}