edb_terminal.go 3.9 KB

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