operlog.go 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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/operloglist [get]
  20. // @Security Bearer
  21. func GetOperLogList(c *gin.Context) {
  22. var data models.SysOperLog
  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.OperName = c.Request.FormValue("operName")
  35. data.Status = c.Request.FormValue("status")
  36. data.OperIp = c.Request.FormValue("operIp")
  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/operlog/{infoId} [get]
  54. // @Security Bearer
  55. func GetOperLog(c *gin.Context) {
  56. var OperLog models.SysOperLog
  57. OperLog.OperId, _ = tools.StringToInt(c.Param("operId"))
  58. result, err := OperLog.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.SysOperLog true "data"
  70. // @Success 200 {string} string "{"code": 200, "message": "添加成功"}"
  71. // @Success 200 {string} string "{"code": -1, "message": "添加失败"}"
  72. // @Router /api/v1/operlog [post]
  73. // @Security Bearer
  74. func InsertOperLog(c *gin.Context) {
  75. var data models.SysOperLog
  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 删除数据
  86. // @Tags 操作日志
  87. // @Param operId path string true "以逗号(,)分割的operId"
  88. // @Success 200 {string} string "{"code": 200, "message": "删除成功"}"
  89. // @Success 200 {string} string "{"code": -1, "message": "删除失败"}"
  90. // @Router /api/v1/operlog/{operId} [delete]
  91. func DeleteOperLog(c *gin.Context) {
  92. var data models.SysOperLog
  93. data.UpdateBy = tools.GetUserIdStr(c)
  94. IDS := tools.IdsStrToIdsIntGroup("operId", c)
  95. _, err := data.BatchDelete(IDS)
  96. tools.HasError(err, "删除失败", 500)
  97. var res app.Response
  98. res.Msg = "删除成功"
  99. c.JSON(http.StatusOK, res.ReturnOK())
  100. }