monitor_online.go 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. package admin
  2. import (
  3. "gfast/app/model/admin/user_online"
  4. "gfast/app/service/admin/monitor_service"
  5. "gfast/library/response"
  6. "github.com/gogf/gf/frame/g"
  7. "github.com/gogf/gf/net/ghttp"
  8. "github.com/gogf/gf/util/gvalid"
  9. )
  10. type MonitorOnline struct{}
  11. // @Summary 用户状态列表
  12. // @Description 用户状态列表
  13. // @Tags 在线用户
  14. // @Param data body user_online.ReqListSearch true "data"
  15. // @Success 0 {object} response.Response "{"code": 200, "data": [...]}"
  16. // @Router /system/monitor/online/list [get]
  17. // @Security
  18. func (c *MonitorOnline) List(r *ghttp.Request) {
  19. var req *user_online.ReqListSearch
  20. //获取参数
  21. if err := r.Parse(&req); err != nil {
  22. response.FailJson(true, r, err.(*gvalid.Error).FirstString())
  23. }
  24. total, page, list, err := monitor_service.GetOnlineListPage(req)
  25. if err != nil {
  26. response.FailJson(true, r, err.Error())
  27. }
  28. result := g.Map{
  29. "currentPage": page,
  30. "total": total,
  31. "list": list,
  32. }
  33. response.SusJson(true, r, "用户在线状态", result)
  34. }
  35. // @Summary 强制退出
  36. // @Description 强制退出
  37. // @Tags 在线用户
  38. // @Param ids body integer true "ids[]"
  39. // @Success 0 {object} response.Response "{"code": 200, "data": [...]}"
  40. // @Router /system/monitor/online/forceLogout [post]
  41. // @Security
  42. func (c *MonitorOnline) ForceLogout(r *ghttp.Request) {
  43. ids := r.GetInts("ids")
  44. if len(ids) == 0 {
  45. response.FailJson(true, r, "参数错误")
  46. }
  47. if err := monitor_service.ForceLogout(ids); err != nil {
  48. response.FailJson(true, r, err.Error())
  49. }
  50. response.SusJson(true, r, "用户已退出")
  51. }