package sys import ( "context" "hotgo/internal/model/input/sysin" "hotgo/internal/service" "github.com/gogf/gf/v2/errors/gerror" "github.com/gogf/gf/v2/frame/g" ) type sSysImKafkaAudit struct{} func NewSysImKafkaAudit() *sSysImKafkaAudit { return &sSysImKafkaAudit{} } func init() { service.RegisterSysImKafkaAudit(NewSysImKafkaAudit()) } func (s *sSysImKafkaAudit) List(ctx context.Context, in *sysin.ImKafkaAuditListInp) (list []*sysin.ImKafkaAuditListModel, totalCount int, err error) { if err = in.Filter(ctx); err != nil { return } mod := g.DB().Model("im_audit_events").Safe().Ctx(ctx). Fields("id", "event_id", "tenant_code", "event_type", "biz_type", "biz_id", "actor_type", "actor_id", "action", "resource", "resource_id", "result", "reason", "occurred_at", "received_at") if in.TenantCode != "" { mod = mod.Where("tenant_code", in.TenantCode) } if in.EventId != "" { mod = mod.WhereLike("event_id", "%"+in.EventId+"%") } if in.EventType != "" { mod = mod.WhereLike("event_type", "%"+in.EventType+"%") } if in.BizType != "" { mod = mod.Where("biz_type", in.BizType) } if in.BizId != "" { mod = mod.WhereLike("biz_id", "%"+in.BizId+"%") } if in.ActorType != "" { mod = mod.Where("actor_type", in.ActorType) } if in.ActorId != "" { mod = mod.WhereLike("actor_id", "%"+in.ActorId+"%") } if in.Action != "" { mod = mod.WhereLike("action", "%"+in.Action+"%") } if in.Resource != "" { mod = mod.Where("resource", in.Resource) } if in.ResourceId != "" { mod = mod.WhereLike("resource_id", "%"+in.ResourceId+"%") } if in.Result != "" { mod = mod.Where("result", in.Result) } if len(in.CreatedAt) == 2 { mod = mod.WhereBetween("received_at", in.CreatedAt[0], in.CreatedAt[1]) } mod = mod.Page(in.Page, in.PerPage).OrderDesc("id") if err = mod.ScanAndCount(&list, &totalCount, false); err != nil { err = gerror.Wrap(err, "获取IM Kafka审计事件列表失败,请稍后重试!") } return } func (s *sSysImKafkaAudit) View(ctx context.Context, in *sysin.ImKafkaAuditViewInp) (res *sysin.ImKafkaAuditViewModel, err error) { if err = in.Filter(ctx); err != nil { return nil, err } mod := g.DB().Model("im_audit_events").Safe().Ctx(ctx). Fields("id", "event_id", "tenant_code", "event_type", "biz_type", "biz_id", "actor_type", "actor_id", "action", "resource", "resource_id", "result", "reason", "CAST(payload AS CHAR) payload", "CAST(envelope AS CHAR) envelope", "occurred_at", "received_at") if in.Id > 0 { mod = mod.Where("id", in.Id) } else { mod = mod.Where("event_id", in.EventId) } if err = mod.Scan(&res); err != nil { return nil, gerror.Wrap(err, "获取IM Kafka审计事件详情失败,请稍后重试!") } return }