edb_terminal.go 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. package data_stat
  2. import (
  3. "encoding/json"
  4. "eta/eta_api/controllers"
  5. "eta/eta_api/models"
  6. "eta/eta_api/models/data_manage"
  7. "eta/eta_api/services/data_stat"
  8. "eta/eta_api/utils"
  9. "fmt"
  10. )
  11. // EdbTerminalController 数据源终端管理
  12. type EdbTerminalController struct {
  13. controllers.BaseAuthController
  14. }
  15. // Save
  16. // @Title 保存数据源终端
  17. // @Description 保存数据源终端接口
  18. // @Param request body true data_manage.AddEdbTerminalListReq "type json string"
  19. // @Success 200 string "操作成功"
  20. // @router /terminal/save [post]
  21. func (this *EdbTerminalController) Save() {
  22. br := new(models.BaseResponse).Init()
  23. br.IsSendEmail = false
  24. defer func() {
  25. this.Data["json"] = br
  26. this.ServeJSON()
  27. }()
  28. sysUser := this.SysUser
  29. if sysUser == nil {
  30. br.Msg = "请登录"
  31. br.ErrMsg = "请登录,SysUser Is Empty"
  32. br.Ret = 408
  33. return
  34. }
  35. var req *data_manage.AddEdbTerminalListReq
  36. if err := json.Unmarshal(this.Ctx.Input.RequestBody, &req); err != nil {
  37. br.Msg = "参数解析异常!"
  38. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  39. return
  40. }
  41. if req.Name == "" {
  42. br.Msg = "请输入终端名称"
  43. return
  44. }
  45. /*if req.ServerUrl == "" && req.Value == "" {
  46. br.Msg = "请输入终端地址或者token"
  47. return
  48. }*/
  49. if req.Num <= 0 {
  50. br.Msg = "请输入指标数据量"
  51. return
  52. }
  53. if req.Source == 0 {
  54. br.Msg = "请输入终端类型"
  55. return
  56. }
  57. // todo 校验终端数据
  58. errMsg, err := data_stat.SaveEdbTerminal(req)
  59. if err != nil {
  60. br.Msg = errMsg
  61. br.ErrMsg = "SaveEnglishVideoCover ErrMsg:" + err.Error()
  62. return
  63. }
  64. br.Ret = 200
  65. br.Success = true
  66. br.Msg = "操作成功"
  67. return
  68. }
  69. // SetStatus
  70. // @Title 启用/禁用数据源终端
  71. // @Description 启用/禁用数据源终端
  72. // @Param request body true data_manage.SetEdbTerminalStatusReq "type json string"
  73. // @Success 200 string "操作成功"
  74. // @router /terminal/status/set [post]
  75. func (this *EdbTerminalController) SetStatus() {
  76. br := new(models.BaseResponse).Init()
  77. br.IsSendEmail = false
  78. defer func() {
  79. this.Data["json"] = br
  80. this.ServeJSON()
  81. }()
  82. sysUser := this.SysUser
  83. if sysUser == nil {
  84. br.Msg = "请登录"
  85. br.ErrMsg = "请登录,SysUser Is Empty"
  86. br.Ret = 408
  87. return
  88. }
  89. var req *data_manage.SetEdbTerminalStatusReq
  90. if err := json.Unmarshal(this.Ctx.Input.RequestBody, &req); err != nil {
  91. br.Msg = "参数解析异常!"
  92. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  93. return
  94. }
  95. if req.TerminalId <= 0 {
  96. br.Msg = "请选择要操作的终端"
  97. return
  98. }
  99. if req.Status != 1 && req.Status != 2 {
  100. br.Msg = "请选择正确的终端状态"
  101. return
  102. }
  103. errMsg, err := data_stat.SetEdbTerminalStatus(req.TerminalId, req.Status)
  104. if err != nil {
  105. br.Msg = errMsg
  106. br.ErrMsg = "SetEdbTerminalStatus ErrMsg:" + err.Error()
  107. return
  108. }
  109. br.Ret = 200
  110. br.Success = true
  111. br.Msg = "操作成功"
  112. return
  113. }
  114. // List
  115. // @Title 数据源终端列表
  116. // @Description 数据源终端列表接口
  117. // @Success 200 {object} data_manage.EdbTerminalLisResp
  118. // @router /terminal/list [get]
  119. func (this *EdbTerminalController) List() {
  120. br := new(models.BaseResponse).Init()
  121. br.IsSendEmail = false
  122. defer func() {
  123. this.Data["json"] = br
  124. this.ServeJSON()
  125. }()
  126. sysUser := this.SysUser
  127. if sysUser == nil {
  128. br.Msg = "请登录"
  129. br.ErrMsg = "请登录,SysUser Is Empty"
  130. br.Ret = 408
  131. return
  132. }
  133. list, err := data_manage.GetEdbTerminalList()
  134. if err != nil {
  135. br.Msg = "获取终端列表失败"
  136. br.ErrMsg = "获取终端列表失败 ErrMsg:" + err.Error()
  137. return
  138. }
  139. resp := &data_manage.EdbTerminalListResp{
  140. List: list,
  141. }
  142. br.Ret = 200
  143. br.Success = true
  144. br.Msg = "获取成功"
  145. br.Data = resp
  146. }
  147. // TerminalCodeList
  148. // @Title 数据源终端列表
  149. // @Description 数据源终端列表接口
  150. // @Success 200 {object} data_manage.EdbTerminalCodeResp
  151. // @router /terminal/code [get]
  152. func (this *EdbTerminalController) TerminalCodeList() {
  153. br := new(models.BaseResponse).Init()
  154. br.IsSendEmail = false
  155. defer func() {
  156. this.Data["json"] = br
  157. this.ServeJSON()
  158. }()
  159. sysUser := this.SysUser
  160. if sysUser == nil {
  161. br.Msg = "请登录"
  162. br.ErrMsg = "请登录,SysUser Is Empty"
  163. br.Ret = 408
  164. return
  165. }
  166. source, _ := this.GetInt("Source", utils.DATA_SOURCE_MYSTEEL_CHEMICAL)
  167. list, err := data_manage.GetEdbTerminalBySource(source)
  168. if err != nil {
  169. br.Msg = "获取终端列表失败"
  170. br.ErrMsg = "获取终端列表失败 ErrMsg:" + err.Error()
  171. return
  172. }
  173. codeList := make([]*data_manage.EdbTerminalCode, 0)
  174. if len(list) > 0 {
  175. for _, v := range list {
  176. tmp := new(data_manage.EdbTerminalCode)
  177. tmp.TerminalCode = v.TerminalCode
  178. tmp.Source = v.Source
  179. tmp.Name = v.Name
  180. codeList = append(codeList, tmp)
  181. }
  182. }
  183. resp := &data_manage.EdbTerminalCodeResp{
  184. List: codeList,
  185. }
  186. br.Ret = 200
  187. br.Success = true
  188. br.Msg = "获取成功"
  189. br.Data = resp
  190. }
  191. // TerminalIndexDirInfo
  192. // @Title 获取指标终端文件夹信息
  193. // @Description 获取指标终端文件夹信息
  194. // @Success 200 {object} data_manage.EdbTerminalDirInfo
  195. // @router /terminal/index_dir [get]
  196. func (this *EdbTerminalController) TerminalIndexDirInfo() {
  197. br := new(models.BaseResponse).Init()
  198. br.IsSendEmail = false
  199. defer func() {
  200. this.Data["json"] = br
  201. this.ServeJSON()
  202. }()
  203. sysUser := this.SysUser
  204. if sysUser == nil {
  205. br.Msg = "请登录"
  206. br.ErrMsg = "请登录,SysUser Is Empty"
  207. br.Ret = 408
  208. return
  209. }
  210. source, _ := this.GetInt("Source")
  211. indexId, _ := this.GetInt("IndexId")
  212. if source <= 0 || indexId <= 0 {
  213. br.Msg = "请选择数据源和指标ID"
  214. return
  215. }
  216. info := new(data_manage.EdbTerminalDirInfo)
  217. var err error
  218. info, err = data_stat.GetEdbTerminalDirInfo(indexId, source)
  219. if err != nil {
  220. utils.FileLog.Info(fmt.Sprintf("获取终端文件夹信息失败indexId:%d,source:%d,Err:%s", indexId, source, err.Error()))
  221. //br.Msg = "获取终端文件夹信息失败"
  222. //br.ErrMsg = "获取终端文件夹信息失败 ErrMsg:" + err.Error()
  223. //return
  224. }
  225. br.Ret = 200
  226. br.Success = true
  227. br.Msg = "获取成功"
  228. br.Data = info
  229. }