audit.go 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. package admin
  2. import (
  3. "Gwen/global"
  4. "Gwen/http/request/admin"
  5. "Gwen/http/response"
  6. "Gwen/model"
  7. "Gwen/service"
  8. "github.com/gin-gonic/gin"
  9. "gorm.io/gorm"
  10. )
  11. type Audit struct {
  12. }
  13. // ConnList 列表
  14. // @Tags 链接日志
  15. // @Summary 链接日志列表
  16. // @Description 链接日志列表
  17. // @Accept json
  18. // @Produce json
  19. // @Param page query int false "页码"
  20. // @Param page_size query int false "页大小"
  21. // @Param peer_id query int false "目标设备"
  22. // @Param from_peer query int false "来源设备"
  23. // @Success 200 {object} response.Response{data=model.AuditConnList}
  24. // @Failure 500 {object} response.Response
  25. // @Router /admin/audit_conn/list [get]
  26. // @Security token
  27. func (a *Audit) ConnList(c *gin.Context) {
  28. query := &admin.AuditQuery{}
  29. if err := c.ShouldBindQuery(query); err != nil {
  30. response.Fail(c, 101, response.TranslateMsg(c, "ParamsError")+err.Error())
  31. return
  32. }
  33. res := service.AllService.AuditService.AuditConnList(query.Page, query.PageSize, func(tx *gorm.DB) {
  34. if query.PeerId != "" {
  35. tx.Where("peer_id like ?", "%"+query.PeerId+"%")
  36. }
  37. if query.FromPeer != "" {
  38. tx.Where("from_peer like ?", "%"+query.FromPeer+"%")
  39. }
  40. })
  41. response.Success(c, res)
  42. }
  43. // ConnDelete 删除
  44. // @Tags 链接日志
  45. // @Summary 链接日志删除
  46. // @Description 链接日志删除
  47. // @Accept json
  48. // @Produce json
  49. // @Param body body model.AuditConn true "链接日志信息"
  50. // @Success 200 {object} response.Response
  51. // @Failure 500 {object} response.Response
  52. // @Router /admin/audit_conn/delete [post]
  53. // @Security token
  54. func (a *Audit) ConnDelete(c *gin.Context) {
  55. f := &model.AuditConn{}
  56. if err := c.ShouldBindJSON(f); err != nil {
  57. response.Fail(c, 101, response.TranslateMsg(c, "ParamsError")+err.Error())
  58. return
  59. }
  60. id := f.Id
  61. errList := global.Validator.ValidVar(c, id, "required,gt=0")
  62. if len(errList) > 0 {
  63. response.Fail(c, 101, errList[0])
  64. return
  65. }
  66. l := service.AllService.AuditService.InfoById(f.Id)
  67. if l.Id > 0 {
  68. err := service.AllService.AuditService.DeleteAuditConn(l)
  69. if err == nil {
  70. response.Success(c, nil)
  71. return
  72. }
  73. response.Fail(c, 101, err.Error())
  74. return
  75. }
  76. response.Fail(c, 101, response.TranslateMsg(c, "ItemNotFound"))
  77. }