edb.go 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  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/services/data"
  7. "eta/eta_hub/utils"
  8. )
  9. // EdbController 指标
  10. type EdbController struct {
  11. BaseAuthController
  12. }
  13. // SourceList
  14. // @Title 指标来源
  15. // @Description 指标来源
  16. // @Success 200 {object} data_manage.EdbSourceItem
  17. // @router /source/list [get]
  18. func (this *EdbController) SourceList() {
  19. br := new(models.BaseResponse).Init()
  20. defer func() {
  21. this.Data["json"] = br
  22. this.ServeJSON()
  23. }()
  24. sources, e := data_manage.GetEdbSourceItemsByCondition(``, make([]interface{}, 0), []string{}, "")
  25. if e != nil {
  26. br.Msg = "获取失败"
  27. br.ErrMsg = "SourceList GetEdbSourceItemsByCondition err: " + e.Error()
  28. return
  29. }
  30. resp := make([]*data_manage.EdbSourceItem, 0)
  31. for _, v := range sources {
  32. resp = append(resp, data_manage.FormatEdbSource2Item(v))
  33. }
  34. br.Data = resp
  35. br.Ret = 200
  36. br.Msg = "获取成功"
  37. }
  38. // ClassifyList
  39. // @Title 指标分类列表
  40. // @Description 指标分类列表
  41. // @Param ClassifyType query int false "分类类型: 0-普通指标; 1-预测指标"
  42. // @Success 200 {object} data_manage.EdbClassifyItem
  43. // @router /classify/list [get]
  44. func (this *EdbController) ClassifyList() {
  45. br := new(models.BaseResponse).Init()
  46. defer func() {
  47. this.Data["json"] = br
  48. this.ServeJSON()
  49. }()
  50. classifyType, _ := this.GetInt("ClassifyType", 0)
  51. cond := ` AND classify_type = ?`
  52. pars := make([]interface{}, 0)
  53. pars = append(pars, classifyType)
  54. // 获取所有分类
  55. classifyOb := new(data_manage.EdbClassify)
  56. classifies, e := classifyOb.GetItemsByCondition(cond, pars, []string{}, "parent_id ASC, sort ASC")
  57. if e != nil {
  58. br.Msg = "获取失败"
  59. br.ErrMsg = "ClassifyTree GetItemsByCondition err: " + e.Error()
  60. return
  61. }
  62. resp := make([]*data_manage.EdbClassifyItem, 0)
  63. for _, v := range classifies {
  64. resp = append(resp, data_manage.FormatEdbClassify2Item(v))
  65. }
  66. br.Data = resp
  67. br.Ret = 200
  68. br.Msg = "获取成功"
  69. }
  70. // ClassifyTree
  71. // @Title 指标分类树
  72. // @Description 指标分类树
  73. // @Param ClassifyType query int false "分类类型: 0-普通指标; 1-预测指标"
  74. // @Success 200 {object} data_manage.EdbClassifyItem
  75. // @router /classify/tree [get]
  76. func (this *EdbController) ClassifyTree() {
  77. br := new(models.BaseResponse).Init()
  78. defer func() {
  79. this.Data["json"] = br
  80. this.ServeJSON()
  81. }()
  82. classifyType, _ := this.GetInt("ClassifyType", 0)
  83. cond := ` AND classify_type = ?`
  84. pars := make([]interface{}, 0)
  85. pars = append(pars, classifyType)
  86. // 获取所有分类
  87. classifyOb := new(data_manage.EdbClassify)
  88. classifies, e := classifyOb.GetItemsByCondition(cond, pars, []string{}, "sort ASC, parent_id ASC")
  89. if e != nil {
  90. br.Msg = "获取失败"
  91. br.ErrMsg = "EdbClassifyTree GetItemsByCondition err: " + e.Error()
  92. return
  93. }
  94. // 递归生成分类树
  95. classifyTree := services.GetEdbClassifyTreeRecursive(classifies, 0)
  96. br.Data = classifyTree
  97. br.Ret = 200
  98. br.Msg = "获取成功"
  99. }
  100. // List
  101. // @Title 指标列表
  102. // @Description 指标列表
  103. // @Param ClassifyId query int true "指标分类ID"
  104. // @Success 200 {object} data_manage.EdbInfoItem
  105. // @router /list [get]
  106. func (this *EdbController) List() {
  107. br := new(models.BaseResponse).Init()
  108. defer func() {
  109. this.Data["json"] = br
  110. this.ServeJSON()
  111. }()
  112. classifyId, _ := this.GetInt("ClassifyId")
  113. if classifyId <= 0 {
  114. br.Msg = "参数有误"
  115. return
  116. }
  117. edbOb := new(data_manage.EdbInfo)
  118. cond := ` AND classify_id = ?`
  119. pars := make([]interface{}, 0)
  120. pars = append(pars, classifyId)
  121. edbList, e := edbOb.GetItemsByCondition(cond, pars, []string{}, "sort ASC")
  122. if e != nil {
  123. br.Msg = "获取失败"
  124. br.ErrMsg = "EdbList GetItemsByCondition err: " + e.Error()
  125. return
  126. }
  127. resp := make([]*data_manage.EdbInfoItem, 0)
  128. for _, v := range edbList {
  129. resp = append(resp, data_manage.FormatEdbInfo2Item(v))
  130. }
  131. br.Data = resp
  132. br.Ret = 200
  133. br.Msg = "获取成功"
  134. }
  135. // Detail
  136. // @Title 指标详情
  137. // @Description 指标详情
  138. // @Success 200 {object} data_manage.EdbInfoItem
  139. // @router /detail [get]
  140. func (this *EdbController) Detail() {
  141. br := new(models.BaseResponse).Init()
  142. defer func() {
  143. this.Data["json"] = br
  144. this.ServeJSON()
  145. }()
  146. unicode := this.GetString("UniqueCode")
  147. if unicode == "" {
  148. br.Msg = "参数有误"
  149. return
  150. }
  151. edbOb := new(data_manage.EdbInfo)
  152. edb, e := edbOb.GetItemByUniCode(unicode)
  153. if e != nil {
  154. if e.Error() == utils.ErrNoRow() {
  155. br.Msg = "指标不存在"
  156. return
  157. }
  158. br.Msg = "获取失败"
  159. br.ErrMsg = "EdbDetail GetItemByCode err: " + e.Error()
  160. return
  161. }
  162. // 获取指标数据
  163. //dataOb := new(data_manage.EdbData)
  164. //dataList, e := dataOb.GetItemsBySourceAndCode(edb.Source, edb.EdbCode, []string{}, "")
  165. //if e != nil {
  166. // br.Msg = "获取失败"
  167. // br.ErrMsg = "EdbDetail GetItemsBySourceAndCode err: " + e.Error()
  168. // return
  169. //}
  170. //edbData := make([]*data_manage.EdbDataItem, 0)
  171. //for _, v := range dataList {
  172. // edbData = append(edbData, data_manage.FormatEdbData2Item(v))
  173. //}
  174. resp := data_manage.FormatEdbInfo2Item(edb)
  175. br.Data = resp
  176. br.Ret = 200
  177. br.Msg = "获取成功"
  178. }
  179. // EdbData
  180. // @Title 指标数据
  181. // @Description 指标数据
  182. // @Success 200 {object} data_manage.EdbInfoItem
  183. // @router /data [get]
  184. func (this *EdbController) EdbData() {
  185. br := new(models.BaseResponse).Init()
  186. defer func() {
  187. this.Data["json"] = br
  188. this.ServeJSON()
  189. }()
  190. unicode := this.GetString("UniqueCode")
  191. if unicode == "" {
  192. br.Msg = "参数有误"
  193. return
  194. }
  195. edbOb := new(data_manage.EdbInfo)
  196. edb, e := edbOb.GetItemByUniCode(unicode)
  197. if e != nil {
  198. if e.Error() == utils.ErrNoRow() {
  199. br.Msg = "指标不存在"
  200. return
  201. }
  202. br.Msg = "获取失败"
  203. br.ErrMsg = "EdbDetail GetItemByCode err: " + e.Error()
  204. return
  205. }
  206. // 获取指标数据
  207. dataOb := new(data_manage.EdbData)
  208. dataList, e := dataOb.GetItemsBySourceAndCode(edb.Source, edb.EdbCode, []string{}, "")
  209. if e != nil {
  210. br.Msg = "获取失败"
  211. br.ErrMsg = "EdbData GetItemsBySourceAndCode err: " + e.Error()
  212. return
  213. }
  214. edbData := make([]*data_manage.EdbDataItem, 0)
  215. for _, v := range dataList {
  216. edbData = append(edbData, data_manage.FormatEdbData2Item(v))
  217. }
  218. br.Data = edbData
  219. br.Ret = 200
  220. br.Msg = "获取成功"
  221. }
  222. // TraceEdbInfo
  223. // @Title 指标溯源接口
  224. // @Description 指标溯源接口
  225. // @Param EdbInfoId query int true "指标id"
  226. // @Success 200 {object} data_manage.ChartListResp
  227. // @router /edb_info/trace [get]
  228. func (this *EdbInfoController) TraceEdbInfo() {
  229. br := new(models.BaseResponse).Init()
  230. defer func() {
  231. this.Data["json"] = br
  232. this.ServeJSON()
  233. }()
  234. edbInfoId, _ := this.GetInt("EdbInfoId")
  235. if edbInfoId <= 0 {
  236. br.Msg = "参数错误"
  237. br.ErrMsg = "参数错误"
  238. return
  239. }
  240. resp, err := data.TraceEdbInfoByEdbInfoId(edbInfoId)
  241. if err != nil {
  242. br.Msg = "获取失败"
  243. br.Msg = "获取失败,Err:" + err.Error()
  244. return
  245. }
  246. br.Ret = 200
  247. br.Data = resp
  248. br.Msg = "刷新成功"
  249. }