edb.go 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  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. // EdbController 指标
  9. type EdbController struct {
  10. BaseAuthController
  11. }
  12. // SourceList
  13. // @Title 指标来源
  14. // @Description 指标来源
  15. // @Success 200 {object} data_manage.EdbSourceItem
  16. // @router /source/list [get]
  17. func (this *EdbController) SourceList() {
  18. br := new(models.BaseResponse).Init()
  19. defer func() {
  20. this.Data["json"] = br
  21. this.ServeJSON()
  22. }()
  23. sources, e := data_manage.GetEdbSourceItemsByCondition(``, make([]interface{}, 0), []string{}, "")
  24. if e != nil {
  25. br.Msg = "获取失败"
  26. br.ErrMsg = "SourceList GetEdbSourceItemsByCondition err: " + e.Error()
  27. return
  28. }
  29. resp := make([]*data_manage.EdbSourceItem, 0)
  30. for _, v := range sources {
  31. resp = append(resp, data_manage.FormatEdbSource2Item(v))
  32. }
  33. br.Data = resp
  34. br.Ret = 200
  35. br.Msg = "获取成功"
  36. }
  37. // ClassifyList
  38. // @Title 指标分类列表
  39. // @Description 指标分类列表
  40. // @Param ClassifyType query int false "分类类型: 0-普通指标; 1-预测指标"
  41. // @Success 200 {object} data_manage.EdbClassifyItem
  42. // @router /classify/list [get]
  43. func (this *EdbController) ClassifyList() {
  44. br := new(models.BaseResponse).Init()
  45. defer func() {
  46. this.Data["json"] = br
  47. this.ServeJSON()
  48. }()
  49. classifyType, _ := this.GetInt("ClassifyType", 0)
  50. cond := ` AND classify_type = ?`
  51. pars := make([]interface{}, 0)
  52. pars = append(pars, classifyType)
  53. // 获取所有分类
  54. classifyOb := new(data_manage.EdbClassify)
  55. classifies, e := classifyOb.GetItemsByCondition(cond, pars, []string{}, "parent_id ASC, sort ASC")
  56. if e != nil {
  57. br.Msg = "获取失败"
  58. br.ErrMsg = "ClassifyTree GetItemsByCondition err: " + e.Error()
  59. return
  60. }
  61. resp := make([]*data_manage.EdbClassifyItem, 0)
  62. for _, v := range classifies {
  63. resp = append(resp, data_manage.FormatEdbClassify2Item(v))
  64. }
  65. br.Data = resp
  66. br.Ret = 200
  67. br.Msg = "获取成功"
  68. }
  69. // ClassifyTree
  70. // @Title 指标分类树
  71. // @Description 指标分类树
  72. // @Param ClassifyType query int false "分类类型: 0-普通指标; 1-预测指标"
  73. // @Success 200 {object} data_manage.EdbClassifyItem
  74. // @router /classify/tree [get]
  75. func (this *EdbController) ClassifyTree() {
  76. br := new(models.BaseResponse).Init()
  77. defer func() {
  78. this.Data["json"] = br
  79. this.ServeJSON()
  80. }()
  81. classifyType, _ := this.GetInt("ClassifyType", 0)
  82. cond := ` AND classify_type = ?`
  83. pars := make([]interface{}, 0)
  84. pars = append(pars, classifyType)
  85. // 获取所有分类
  86. classifyOb := new(data_manage.EdbClassify)
  87. classifies, e := classifyOb.GetItemsByCondition(cond, pars, []string{}, "sort ASC, parent_id ASC")
  88. if e != nil {
  89. br.Msg = "获取失败"
  90. br.ErrMsg = "EdbClassifyTree GetItemsByCondition err: " + e.Error()
  91. return
  92. }
  93. // 递归生成分类树
  94. classifyTree := services.GetEdbClassifyTreeRecursive(classifies, 0)
  95. br.Data = classifyTree
  96. br.Ret = 200
  97. br.Msg = "获取成功"
  98. }
  99. // List
  100. // @Title 指标列表
  101. // @Description 指标列表
  102. // @Param ClassifyId query int true "指标分类ID"
  103. // @Success 200 {object} data_manage.EdbInfoItem
  104. // @router /list [get]
  105. func (this *EdbController) List() {
  106. br := new(models.BaseResponse).Init()
  107. defer func() {
  108. this.Data["json"] = br
  109. this.ServeJSON()
  110. }()
  111. classifyId, _ := this.GetInt("ClassifyId")
  112. if classifyId <= 0 {
  113. br.Msg = "参数有误"
  114. return
  115. }
  116. edbOb := new(data_manage.EdbInfo)
  117. cond := ` AND classify_id = ?`
  118. pars := make([]interface{}, 0)
  119. pars = append(pars, classifyId)
  120. edbList, e := edbOb.GetItemsByCondition(cond, pars, []string{}, "sort ASC")
  121. if e != nil {
  122. br.Msg = "获取失败"
  123. br.ErrMsg = "EdbList GetItemsByCondition err: " + e.Error()
  124. return
  125. }
  126. resp := make([]*data_manage.EdbInfoItem, 0)
  127. for _, v := range edbList {
  128. resp = append(resp, data_manage.FormatEdbInfo2Item(v, make([]*data_manage.EdbDataItem, 0)))
  129. }
  130. br.Data = resp
  131. br.Ret = 200
  132. br.Msg = "获取成功"
  133. }
  134. // Detail
  135. // @Title 指标详情
  136. // @Description 指标详情
  137. // @Success 200 {object} data_manage.EdbInfoItem
  138. // @router /detail [get]
  139. func (this *EdbController) Detail() {
  140. br := new(models.BaseResponse).Init()
  141. defer func() {
  142. this.Data["json"] = br
  143. this.ServeJSON()
  144. }()
  145. unicode := this.GetString("UniqueCode")
  146. if unicode == "" {
  147. br.Msg = "参数有误"
  148. return
  149. }
  150. edbOb := new(data_manage.EdbInfo)
  151. edb, e := edbOb.GetItemByUniCode(unicode)
  152. if e != nil {
  153. if e.Error() == utils.ErrNoRow() {
  154. br.Msg = "指标不存在"
  155. return
  156. }
  157. br.Msg = "获取失败"
  158. br.ErrMsg = "EdbDetail GetItemByCode err: " + e.Error()
  159. return
  160. }
  161. // 获取指标数据
  162. dataOb := new(data_manage.EdbData)
  163. dataList, e := dataOb.GetItemsBySourceAndCode(edb.Source, edb.EdbCode, []string{}, "")
  164. if e != nil {
  165. br.Msg = "获取失败"
  166. br.ErrMsg = "EdbDetail GetItemsBySourceAndCode err: " + e.Error()
  167. return
  168. }
  169. edbData := make([]*data_manage.EdbDataItem, 0)
  170. for _, v := range dataList {
  171. edbData = append(edbData, data_manage.FormatEdbData2Item(v))
  172. }
  173. resp := data_manage.FormatEdbInfo2Item(edb, edbData)
  174. br.Data = resp
  175. br.Ret = 200
  176. br.Msg = "获取成功"
  177. }