jiayue_edb_source.go 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  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. // 测试环境老在报错=_=!
  69. if utils.RunMode == "debug" {
  70. br.Data = make([]string, 0)
  71. br.Ret = 200
  72. br.Success = true
  73. br.Msg = "获取成功"
  74. return
  75. }
  76. frequencies, e := data.GetJiaYueFrequencyListFromBridge()
  77. if e != nil {
  78. br.Msg = "获取失败"
  79. br.ErrMsg = "桥接服务获取指标频度失败, Err: " + e.Error()
  80. return
  81. }
  82. br.Data = frequencies
  83. br.Ret = 200
  84. br.Success = true
  85. br.Msg = "获取成功"
  86. }
  87. // IndexPageList
  88. // @Title 指标列表-分页
  89. // @Description 指标列表-分页
  90. // @Param PageSize query int false "每页数据条数"
  91. // @Param CurrentIndex query int false "当前页码"
  92. // @Param Source query int true "数据来源"
  93. // @Param Frequency query string false "频度"
  94. // @Param Keyword query string false "关键词: 指标ID/指标名称"
  95. // @Param SortField query int false "排序字段: 1-指标开始时间; 2-指标最新时间; 3-更新时间"
  96. // @Param SortRule query int false "排序方式: 1-正序; 2-倒序"
  97. // @Success 200 string "获取成功"
  98. // @router /edb_source/jiayue/index_page_list [get]
  99. func (this *JiaYueEdbSourceController) IndexPageList() {
  100. br := new(models.BaseResponse).Init()
  101. defer func() {
  102. if br.ErrMsg == "" {
  103. br.IsSendEmail = false
  104. }
  105. this.Data["json"] = br
  106. this.ServeJSON()
  107. }()
  108. sysUser := this.SysUser
  109. if sysUser == nil {
  110. br.Msg = "请登录"
  111. br.ErrMsg = "请登录,SysUser Is Empty"
  112. return
  113. }
  114. source, _ := this.GetInt("Source")
  115. frequency := this.GetString("Frequency")
  116. keyword := this.GetString("Keyword")
  117. sortField, _ := this.GetInt("SortField")
  118. sortRule, _ := this.GetInt("SortRule")
  119. if source <= 0 {
  120. br.Msg = "参数有误"
  121. br.ErrMsg = fmt.Sprintf("参数有误, Source: %d", source)
  122. return
  123. }
  124. cond := ` AND edb_source_id = ?`
  125. pars := make([]interface{}, 0)
  126. pars = append(pars, source)
  127. sourceItem, e := data_manage.GetEdbSourceItemByCondition(cond, pars)
  128. if e != nil {
  129. br.Msg = "数据源有误"
  130. br.ErrMsg = "获取数据源失败, Err: " + e.Error()
  131. return
  132. }
  133. // 分页
  134. pageSize, _ := this.GetInt("PageSize")
  135. currentIndex, _ := this.GetInt("CurrentIndex")
  136. if pageSize <= 0 {
  137. pageSize = utils.PageSize20
  138. }
  139. if currentIndex <= 0 {
  140. currentIndex = 1
  141. }
  142. // 测试环境老在报错=_=!
  143. if utils.RunMode == "debug" {
  144. page := paging.GetPaging(currentIndex, pageSize, 0)
  145. resp := new(data_manage.JiaYueIndexPageListResp)
  146. resp.Paging = page
  147. resp.List = make([]*data_manage.DictIndexItem, 0)
  148. br.Data = resp
  149. br.Ret = 200
  150. br.Success = true
  151. br.Msg = "获取成功"
  152. return
  153. }
  154. var params data_manage.BridgeJiaYuePageIndexReq
  155. params.PageIndex = currentIndex
  156. params.PageSize = pageSize
  157. params.Keyword = keyword
  158. params.Frequency = frequency
  159. params.SourceExtend = sourceItem.SourceExtend
  160. params.SortField = sortField
  161. params.SortRule = sortRule
  162. total, list, e := data.GetJiaYueIndexPageListFromBridge(params)
  163. if e != nil {
  164. br.Msg = "获取失败"
  165. br.ErrMsg = "获取指标分页列表失败, Err: " + e.Error()
  166. return
  167. }
  168. items := make([]*data_manage.DictIndexItem, 0)
  169. for _, v := range list {
  170. t := data_manage.FormatDictIndex2Item(v)
  171. items = append(items, t)
  172. }
  173. page := paging.GetPaging(currentIndex, pageSize, total)
  174. resp := new(data_manage.JiaYueIndexPageListResp)
  175. resp.Paging = page
  176. resp.List = items
  177. br.Data = resp
  178. br.Ret = 200
  179. br.Success = true
  180. br.Msg = "获取成功"
  181. }