loginlog.go 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. package log
  2. import (
  3. "net/http"
  4. "github.com/gin-gonic/gin"
  5. "github.com/gin-gonic/gin/binding"
  6. "device-manage/app/admin/models"
  7. "device-manage/tools"
  8. "device-manage/tools/app"
  9. )
  10. // @Summary 登录日志列表
  11. // @Description 获取JSON
  12. // @Tags 登录日志
  13. // @Param status query string false "status"
  14. // @Param dictCode query string false "dictCode"
  15. // @Param dictType query string false "dictType"
  16. // @Param pageSize query int false "页条数"
  17. // @Param pageIndex query int false "页码"
  18. // @Success 200 {object} app.Response "{"code": 200, "data": [...]}"
  19. // @Router /api/v1/loginloglist [get]
  20. // @Security Bearer
  21. func GetLoginLogList(c *gin.Context) {
  22. var data models.LoginLog
  23. var err error
  24. var pageSize = 10
  25. var pageIndex = 1
  26. size := c.Request.FormValue("pageSize")
  27. if size != "" {
  28. pageSize, err = tools.StringToInt(size)
  29. }
  30. index := c.Request.FormValue("pageIndex")
  31. if index != "" {
  32. pageIndex, err = tools.StringToInt(index)
  33. }
  34. data.Username = c.Request.FormValue("username")
  35. data.Status = c.Request.FormValue("status")
  36. data.Ipaddr = c.Request.FormValue("ipaddr")
  37. result, count, err := data.GetPage(pageSize, pageIndex)
  38. tools.HasError(err, "", -1)
  39. var mp = make(map[string]interface{}, 3)
  40. mp["list"] = result
  41. mp["count"] = count
  42. mp["pageIndex"] = pageIndex
  43. mp["pageSize"] = pageSize
  44. var res app.Response
  45. res.Data = mp
  46. c.JSON(http.StatusOK, res.ReturnOK())
  47. }
  48. // @Summary 通过编码获取登录日志
  49. // @Description 获取JSON
  50. // @Tags 登录日志
  51. // @Param infoId path int true "infoId"
  52. // @Success 200 {object} app.Response "{"code": 200, "data": [...]}"
  53. // @Router /api/v1/loginlog/{infoId} [get]
  54. // @Security Bearer
  55. func GetLoginLog(c *gin.Context) {
  56. var LoginLog models.LoginLog
  57. LoginLog.InfoId, _ = tools.StringToInt(c.Param("infoId"))
  58. result, err := LoginLog.Get()
  59. tools.HasError(err, "抱歉未找到相关信息", -1)
  60. var res app.Response
  61. res.Data = result
  62. c.JSON(http.StatusOK, res.ReturnOK())
  63. }
  64. // @Summary 添加登录日志
  65. // @Description 获取JSON
  66. // @Tags 登录日志
  67. // @Accept application/json
  68. // @Product application/json
  69. // @Param data body models.LoginLog true "data"
  70. // @Success 200 {string} string "{"code": 200, "message": "添加成功"}"
  71. // @Success 200 {string} string "{"code": -1, "message": "添加失败"}"
  72. // @Router /api/v1/loginlog [post]
  73. // @Security Bearer
  74. func InsertLoginLog(c *gin.Context) {
  75. var data models.LoginLog
  76. err := c.BindWith(&data, binding.JSON)
  77. tools.HasError(err, "", 500)
  78. result, err := data.Create()
  79. tools.HasError(err, "", -1)
  80. var res app.Response
  81. res.Data = result
  82. c.JSON(http.StatusOK, res.ReturnOK())
  83. }
  84. // @Summary 修改登录日志
  85. // @Description 获取JSON
  86. // @Tags 登录日志
  87. // @Accept application/json
  88. // @Product application/json
  89. // @Param data body models.LoginLog true "body"
  90. // @Success 200 {string} string "{"code": 200, "message": "添加成功"}"
  91. // @Success 200 {string} string "{"code": -1, "message": "添加失败"}"
  92. // @Router /api/v1/loginlog [put]
  93. // @Security Bearer
  94. func UpdateLoginLog(c *gin.Context) {
  95. var data models.LoginLog
  96. err := c.BindWith(&data, binding.JSON)
  97. tools.HasError(err, "", -1)
  98. result, err := data.Update(data.InfoId)
  99. tools.HasError(err, "", -1)
  100. var res app.Response
  101. res.Data = result
  102. c.JSON(http.StatusOK, res.ReturnOK())
  103. }
  104. // @Summary 批量删除登录日志
  105. // @Description 删除数据
  106. // @Tags 登录日志
  107. // @Param infoId path string true "以逗号(,)分割的infoId"
  108. // @Success 200 {string} string "{"code": 200, "message": "删除成功"}"
  109. // @Success 200 {string} string "{"code": -1, "message": "删除失败"}"
  110. // @Router /api/v1/loginlog/{infoId} [delete]
  111. func DeleteLoginLog(c *gin.Context) {
  112. var data models.LoginLog
  113. data.UpdateBy = tools.GetUserIdStr(c)
  114. IDS := tools.IdsStrToIdsIntGroup("infoId", c)
  115. _, err := data.BatchDelete(IDS)
  116. tools.HasError(err, "修改失败", 500)
  117. var res app.Response
  118. res.Msg = "删除成功"
  119. c.JSON(http.StatusOK, res.ReturnOK())
  120. }