chart.go 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  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. "github.com/rdlucklib/rdluck_tools/paging"
  8. )
  9. // ChartController 图表
  10. type ChartController struct {
  11. BaseAuthController
  12. }
  13. // ClassifyList
  14. // @Title 分类列表
  15. // @Description 分类列表
  16. // @Success 200 {object} data_manage.ChartClassifyItem
  17. // @router /classify/list [get]
  18. func (this *ChartController) ClassifyList() {
  19. br := new(models.BaseResponse).Init()
  20. defer func() {
  21. this.Data["json"] = br
  22. this.ServeJSON()
  23. }()
  24. source := utils.CHART_SOURCE_DEFAULT
  25. cond := ` AND source = ?`
  26. pars := make([]interface{}, 0)
  27. pars = append(pars, source)
  28. classifyOb := new(data_manage.ChartClassify)
  29. classifies, e := classifyOb.GetItemsByCondition(cond, pars, []string{}, "parent_id ASC, sort ASC")
  30. if e != nil {
  31. br.Msg = "获取失败"
  32. br.ErrMsg = "ChartClassifyList GetItemsByCondition err: " + e.Error()
  33. return
  34. }
  35. resp := make([]*data_manage.ChartClassifyItem, 0)
  36. for _, v := range classifies {
  37. resp = append(resp, data_manage.FormatChartClassify2Item(v))
  38. }
  39. br.Data = resp
  40. br.Ret = 200
  41. br.Msg = "获取成功"
  42. }
  43. // ClassifyTree
  44. // @Title 图库分类树
  45. // @Description 图库分类树
  46. // @Success 200 {object} data_manage.ChartClassifyItem
  47. // @router /classify/tree [get]
  48. func (this *ChartController) ClassifyTree() {
  49. br := new(models.BaseResponse).Init()
  50. defer func() {
  51. this.Data["json"] = br
  52. this.ServeJSON()
  53. }()
  54. // 获取所有分类
  55. classifyOb := new(data_manage.ChartClassify)
  56. cond := ` AND source = ?`
  57. pars := make([]interface{}, 0)
  58. pars = append(pars, utils.CHART_SOURCE_DEFAULT)
  59. classifies, e := classifyOb.GetItemsByCondition(cond, pars, []string{}, "sort ASC, parent_id ASC")
  60. if e != nil {
  61. br.Msg = "获取失败"
  62. br.ErrMsg = "ChartClassifyTree GetItemsByCondition err: " + e.Error()
  63. return
  64. }
  65. // 递归生成分类树
  66. classifyTree := services.GetChartClassifyTreeRecursive(classifies, 0)
  67. br.Data = classifyTree
  68. br.Ret = 200
  69. br.Msg = "获取成功"
  70. }
  71. // List
  72. // @Title 图表列表
  73. // @Description 图表列表
  74. // @Param ClassifyId query int true "图表分类ID"
  75. // @Success 200 {object} data_manage.ChartInfoItem
  76. // @router /list [get]
  77. func (this *ChartController) List() {
  78. br := new(models.BaseResponse).Init()
  79. defer func() {
  80. this.Data["json"] = br
  81. this.ServeJSON()
  82. }()
  83. classifyId, _ := this.GetInt("ClassifyId")
  84. pageSize, _ := this.GetInt("PageSize")
  85. currentIndex, _ := this.GetInt("CurrentIndex")
  86. cond := ` AND source = ?`
  87. pars := make([]interface{}, 0)
  88. pars = append(pars, utils.CHART_SOURCE_DEFAULT)
  89. if classifyId > 0 {
  90. cond += ` AND chart_classify_id = ?`
  91. pars = append(pars, classifyId)
  92. }
  93. chartOb := new(data_manage.ChartInfo)
  94. if pageSize > 0 {
  95. if currentIndex <= 0 {
  96. currentIndex = 1
  97. }
  98. startSize := utils.StartIndex(currentIndex, pageSize)
  99. total, err := chartOb.GetItemTotal(cond, pars)
  100. if err != nil {
  101. br.Msg = "获取失败"
  102. br.ErrMsg = "ChartList GetItemTotal err: " + err.Error()
  103. return
  104. }
  105. resp := new(data_manage.ChartInfoItemResp)
  106. if total == 0 {
  107. resp.List = make([]*data_manage.ChartInfoItem, 0)
  108. resp.Paging = paging.GetPaging(currentIndex, pageSize, 0)
  109. br.Data = resp
  110. br.Ret = 200
  111. br.Msg = "获取成功"
  112. return
  113. }
  114. charts, e := chartOb.GetItemsPageByCondition(cond, pars, []string{}, "", startSize, pageSize)
  115. if e != nil {
  116. br.Msg = "获取失败"
  117. br.ErrMsg = "ChartList GetItemsPageByCondition err: " + e.Error()
  118. return
  119. }
  120. list := make([]*data_manage.ChartInfoItem, 0)
  121. for _, v := range charts {
  122. list = append(list, data_manage.FormatChartInfo2Item(v))
  123. }
  124. page := paging.GetPaging(currentIndex, pageSize, total)
  125. resp.List = list
  126. resp.Paging = page
  127. br.Data = resp
  128. br.Ret = 200
  129. br.Msg = "获取成功"
  130. return
  131. }
  132. charts, e := chartOb.GetItemsByCondition(cond, pars, []string{}, "sort ASC, create_time DESC")
  133. if e != nil {
  134. br.Msg = "获取失败"
  135. br.ErrMsg = "ChartList GetItemsByCondition err: " + e.Error()
  136. return
  137. }
  138. resp := make([]*data_manage.ChartInfoItem, 0)
  139. for _, v := range charts {
  140. resp = append(resp, data_manage.FormatChartInfo2Item(v))
  141. }
  142. br.Data = resp
  143. br.Ret = 200
  144. br.Msg = "获取成功"
  145. }
  146. // Detail
  147. // @Title 图表详情
  148. // @Description 图表详情(这个接口的意义不大, 拿到数据也没啥用=_=!)
  149. // @Success 200 {object} models.Report
  150. // @router /detail [get]
  151. func (this *ChartController) Detail() {
  152. br := new(models.BaseResponse).Init()
  153. defer func() {
  154. this.Data["json"] = br
  155. this.ServeJSON()
  156. }()
  157. unicode := this.GetString("UniqueCode")
  158. if unicode == "" {
  159. br.Msg = "参数有误"
  160. return
  161. }
  162. chartOb := new(data_manage.ChartInfo)
  163. _, e := chartOb.GetItemByCode(unicode)
  164. if e != nil {
  165. if e.Error() == utils.ErrNoRow() {
  166. br.Msg = "图表不存在"
  167. return
  168. }
  169. br.Msg = "获取失败"
  170. br.ErrMsg = "ChartDetail GetItemByCode err: " + e.Error()
  171. return
  172. }
  173. // 从edb_chart_lib中获取图详情, 这边只做部分数据的返回
  174. detail, e := services.GetChartDetailFromChartLibByUnicode(unicode)
  175. if e != nil {
  176. br.Msg = "获取失败"
  177. br.ErrMsg = "ChartDetail GetChartDetailFromChartLibByUnicode err: " + e.Error()
  178. return
  179. }
  180. br.Data = detail
  181. br.Ret = 200
  182. br.Msg = "获取成功"
  183. }