| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- package mbsdsdk
- import (
- "encoding/json"
- "net/url"
- "git.sxidc.com/service-supports/fslog"
- )
- const bizAuditLogURLPrefix = "mbsd/api/inner/bizAuditLog"
- // Change 单字段变更
- type Change struct {
- Field string `json:"field"`
- Label string `json:"label"`
- Old string `json:"old"`
- New string `json:"new"`
- }
- // BizAuditEntry 业务审计日志写入条目(冗余快照,写入 SystemData 中心表)
- type BizAuditEntry struct {
- SourceService string `json:"sourceService"`
- Module string `json:"module"`
- ModuleLabel string `json:"moduleLabel"`
- Action string `json:"action"`
- ActionLabel string `json:"actionLabel"`
- TenantID string `json:"tenantId"`
- TenantName string `json:"tenantName"`
- OperatorID string `json:"operatorId"`
- OperatorName string `json:"operatorName"`
- OperatorRole string `json:"operatorRole"`
- SubjectType string `json:"subjectType"`
- SubjectID string `json:"subjectId"`
- SubjectLabel string `json:"subjectLabel"`
- TargetType string `json:"targetType"`
- TargetID string `json:"targetId"`
- TargetLabel string `json:"targetLabel"`
- Summary string `json:"summary"`
- Changes []Change `json:"changes,omitempty"`
- Source string `json:"source,omitempty"`
- }
- // WriteBizAuditAsync 异步写入业务审计日志;失败仅打日志,不影响业务事务
- func WriteBizAuditAsync(entry BizAuditEntry) {
- if entry.Summary == "" {
- return
- }
- go func() {
- if err := writeBizAudit(entry); err != nil {
- fslog.Warn("mbsdsdk: biz audit log write failed: " + err.Error())
- }
- }()
- }
- func writeBizAudit(entry BizAuditEntry) error {
- if invokeAPI == nil {
- return nil
- }
- body, err := json.Marshal(entry)
- if err != nil {
- return err
- }
- path, err := url.JoinPath(bizAuditLogURLPrefix)
- if err != nil {
- return err
- }
- _, err = invokeAPI.PostJSON(path, body, nil)
- return err
- }
|