jiayue_edb_source.go 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. package data_manage
  2. import (
  3. "eta/eta_api/controllers"
  4. "eta/eta_api/models"
  5. "eta/eta_api/models/data_manage"
  6. "eta/eta_api/services/data"
  7. "eta/eta_api/utils"
  8. "fmt"
  9. "github.com/rdlucklib/rdluck_tools/paging"
  10. )
  11. // JiaYueEdbSourceController 嘉悦数据源
  12. type JiaYueEdbSourceController struct {
  13. controllers.BaseAuthController
  14. }
  15. // List
  16. // @Title 数据源列表
  17. // @Description 数据源列表
  18. // @Success 200 string "获取成功"
  19. // @router /edb_source/jiayue/list [get]
  20. func (this *JiaYueEdbSourceController) List() {
  21. br := new(models.BaseResponse).Init()
  22. defer func() {
  23. if br.ErrMsg == "" {
  24. br.IsSendEmail = false
  25. }
  26. this.Data["json"] = br
  27. this.ServeJSON()
  28. }()
  29. sysUser := this.SysUser
  30. if sysUser == nil {
  31. br.Msg = "请登录"
  32. br.ErrMsg = "请登录,SysUser Is Empty"
  33. return
  34. }
  35. cond := ` AND is_base = 1 AND from_bridge = 1`
  36. pars := make([]interface{}, 0)
  37. sources, e := data_manage.GetEdbSourceItemsByCondition(cond, pars, []string{}, "")
  38. if e != nil {
  39. br.Msg = "获取失败"
  40. br.ErrMsg = "获取指标来源失败, Err: "
  41. return
  42. }
  43. br.Data = sources
  44. br.Ret = 200
  45. br.Success = true
  46. br.Msg = "获取成功"
  47. }
  48. // FrequencyList
  49. // @Title 指标频度列表
  50. // @Description 指标频度列表
  51. // @Success 200 string "获取成功"
  52. // @router /edb_source/jiayue/frequency_list [get]
  53. func (this *JiaYueEdbSourceController) FrequencyList() {
  54. br := new(models.BaseResponse).Init()
  55. defer func() {
  56. if br.ErrMsg == "" {
  57. br.IsSendEmail = false
  58. }
  59. this.Data["json"] = br
  60. this.ServeJSON()
  61. }()
  62. sysUser := this.SysUser
  63. if sysUser == nil {
  64. br.Msg = "请登录"
  65. br.ErrMsg = "请登录,SysUser Is Empty"
  66. return
  67. }
  68. frequencies, e := data.GetJiaYueFrequencyListFromBridge()
  69. if e != nil {
  70. br.Msg = "获取失败"
  71. br.ErrMsg = "桥接服务获取指标频度失败, Err: " + e.Error()
  72. return
  73. }
  74. br.Data = frequencies
  75. br.Ret = 200
  76. br.Success = true
  77. br.Msg = "获取成功"
  78. }
  79. // IndexPageList
  80. // @Title 指标列表-分页
  81. // @Description 指标列表-分页
  82. // @Param PageSize query int false "每页数据条数"
  83. // @Param CurrentIndex query int false "当前页码"
  84. // @Param Source query int true "数据来源"
  85. // @Param Frequency query string false "频度"
  86. // @Param Keyword query string false "关键词: 指标ID/指标名称"
  87. // @Param SortField query int false "排序字段: 1-指标开始时间; 2-指标最新时间; 3-更新时间"
  88. // @Param SortRule query int false "排序方式: 1-正序; 2-倒序"
  89. // @Success 200 string "获取成功"
  90. // @router /edb_source/jiayue/index_page_list [get]
  91. func (this *JiaYueEdbSourceController) IndexPageList() {
  92. br := new(models.BaseResponse).Init()
  93. defer func() {
  94. if br.ErrMsg == "" {
  95. br.IsSendEmail = false
  96. }
  97. this.Data["json"] = br
  98. this.ServeJSON()
  99. }()
  100. sysUser := this.SysUser
  101. if sysUser == nil {
  102. br.Msg = "请登录"
  103. br.ErrMsg = "请登录,SysUser Is Empty"
  104. return
  105. }
  106. source, _ := this.GetInt("Source")
  107. frequency := this.GetString("Frequency")
  108. keyword := this.GetString("Keyword")
  109. sortField, _ := this.GetInt("SortField")
  110. sortRule, _ := this.GetInt("SortRule")
  111. if source <= 0 {
  112. br.Msg = "参数有误"
  113. br.ErrMsg = fmt.Sprintf("参数有误, Source: %d", source)
  114. return
  115. }
  116. cond := ` AND edb_source_id = ?`
  117. pars := make([]interface{}, 0)
  118. pars = append(pars, source)
  119. sourceItem, e := data_manage.GetEdbSourceItemByCondition(cond, pars)
  120. if e != nil {
  121. br.Msg = "数据源有误"
  122. br.ErrMsg = "获取数据源失败, Err: " + e.Error()
  123. return
  124. }
  125. // 分页
  126. pageSize, _ := this.GetInt("PageSize")
  127. currentIndex, _ := this.GetInt("CurrentIndex")
  128. if pageSize <= 0 {
  129. pageSize = utils.PageSize20
  130. }
  131. if currentIndex <= 0 {
  132. currentIndex = 1
  133. }
  134. var params data_manage.BridgeJiaYuePageIndexReq
  135. params.PageIndex = currentIndex
  136. params.PageSize = pageSize
  137. params.Keyword = keyword
  138. params.Frequency = frequency
  139. params.SourceExtend = sourceItem.SourceExtend
  140. params.SortField = sortField
  141. params.SortRule = sortRule
  142. total, list, e := data.GetJiaYueIndexPageListFromBridge(params)
  143. if e != nil {
  144. br.Msg = "获取失败"
  145. br.ErrMsg = "获取指标分页列表失败, Err: " + e.Error()
  146. return
  147. }
  148. items := make([]*data_manage.DictIndexItem, 0)
  149. for _, v := range list {
  150. t := data_manage.FormatDictIndex2Item(v)
  151. items = append(items, t)
  152. }
  153. page := paging.GetPaging(currentIndex, pageSize, total)
  154. resp := new(data_manage.JiaYueIndexPageListResp)
  155. resp.Paging = page
  156. resp.List = items
  157. br.Data = resp
  158. br.Ret = 200
  159. br.Success = true
  160. br.Msg = "获取成功"
  161. }