audit.go 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. package api
  2. import (
  3. request "Gwen/http/request/api"
  4. "Gwen/http/response"
  5. "Gwen/model"
  6. "Gwen/service"
  7. "github.com/gin-gonic/gin"
  8. "github.com/gin-gonic/gin/binding"
  9. "time"
  10. )
  11. type Audit struct {
  12. }
  13. // AuditConn
  14. // @Tags 审计
  15. // @Summary 审计连接
  16. // @Description 审计连接
  17. // @Accept json
  18. // @Produce json
  19. // @Param body body request.AuditConnForm true "审计连接"
  20. // @Success 200 {string} string ""
  21. // @Failure 500 {object} response.Response
  22. // @Router /audit/conn [post]
  23. func (a *Audit) AuditConn(c *gin.Context) {
  24. af := &request.AuditConnForm{}
  25. err := c.ShouldBindBodyWith(af, binding.JSON)
  26. if err != nil {
  27. response.Error(c, response.TranslateMsg(c, "ParamsError")+err.Error())
  28. return
  29. }
  30. //fmt.Println(af)
  31. ac := af.ToAuditConn()
  32. if af.Action == model.AuditActionNew {
  33. service.AllService.AuditService.CreateAuditConn(ac)
  34. } else if af.Action == model.AuditActionClose {
  35. ex := service.AllService.AuditService.InfoByPeerIdAndConnId(af.Id, af.ConnId)
  36. if ex.Id != 0 {
  37. ex.CloseTime = time.Now().Unix()
  38. service.AllService.AuditService.UpdateAuditConn(ex)
  39. }
  40. } else if af.Action == "" {
  41. ex := service.AllService.AuditService.InfoByPeerIdAndConnId(af.Id, af.ConnId)
  42. if ex.Id != 0 {
  43. up := &model.AuditConn{
  44. IdModel: model.IdModel{Id: ex.Id},
  45. FromPeer: ac.FromPeer,
  46. FromName: ac.FromName,
  47. SessionId: ac.SessionId,
  48. }
  49. service.AllService.AuditService.UpdateAuditConn(up)
  50. }
  51. }
  52. response.Success(c, "")
  53. }