edb_terminal.go 4.8 KB

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