mirror of
https://github.com/go-admin-team/go-admin.git
synced 2026-09-21 10:13:01 +00:00
The pinned core dated from April, before sdk stopped being a separate module, so the build resolved sdk packages from the old module and core packages from the new one. Dropping the separate requirement is what makes the two agree again. Most of the diff is renames that came with that: the tenant accessors gained a ByTenant suffix, GetDb now returns one database and GetAllDb the map, and casbin moved to v3. The change that matters is four call sites moving from GetMemoryQueue to GetQueuePrefix. GetMemoryQueue returns a queue fixed at construction, so the login log, the operate log and the api check ran in process no matter what the settings file selected — a second instance saw none of it. GetQueuePrefix returns whatever the configuration built, which is the point of being able to configure a queue at all. Verified against core at main: build and vet clean. The two file_store failures are unchanged from before this branch; they need cloud credentials.
89 lines
3.0 KiB
Go
89 lines
3.0 KiB
Go
package models
|
|
|
|
import (
|
|
"encoding/json"
|
|
"errors"
|
|
"time"
|
|
|
|
log "github.com/go-admin-team/go-admin-core/logger"
|
|
"github.com/go-admin-team/go-admin-core/sdk"
|
|
"github.com/go-admin-team/go-admin-core/storage"
|
|
|
|
"go-admin/common/models"
|
|
)
|
|
|
|
type SysOperaLog struct {
|
|
models.Model
|
|
Title string `json:"title" gorm:"size:255;comment:操作模块"`
|
|
BusinessType string `json:"businessType" gorm:"size:128;comment:操作类型"`
|
|
BusinessTypes string `json:"businessTypes" gorm:"size:128;comment:BusinessTypes"`
|
|
Method string `json:"method" gorm:"size:128;comment:函数"`
|
|
RequestMethod string `json:"requestMethod" gorm:"size:128;comment:请求方式 GET POST PUT DELETE"`
|
|
OperatorType string `json:"operatorType" gorm:"size:128;comment:操作类型"`
|
|
OperName string `json:"operName" gorm:"size:128;comment:操作者"`
|
|
DeptName string `json:"deptName" gorm:"size:128;comment:部门名称"`
|
|
OperUrl string `json:"operUrl" gorm:"size:255;comment:访问地址"`
|
|
OperIp string `json:"operIp" gorm:"size:128;comment:客户端ip"`
|
|
OperLocation string `json:"operLocation" gorm:"size:128;comment:访问位置"`
|
|
OperParam string `json:"operParam" gorm:"text;comment:请求参数"`
|
|
Status string `json:"status" gorm:"size:4;comment:操作状态 1:正常 2:关闭"`
|
|
OperTime time.Time `json:"operTime" gorm:"comment:操作时间"`
|
|
JsonResult string `json:"jsonResult" gorm:"size:255;comment:返回数据"`
|
|
Remark string `json:"remark" gorm:"size:255;comment:备注"`
|
|
LatencyTime string `json:"latencyTime" gorm:"size:128;comment:耗时"`
|
|
UserAgent string `json:"userAgent" gorm:"size:255;comment:ua"`
|
|
CreatedAt time.Time `json:"createdAt" gorm:"comment:创建时间"`
|
|
UpdatedAt time.Time `json:"updatedAt" gorm:"comment:最后更新时间"`
|
|
models.ControlBy
|
|
}
|
|
|
|
func (*SysOperaLog) TableName() string {
|
|
return "sys_opera_log"
|
|
}
|
|
|
|
func (e *SysOperaLog) Generate() models.ActiveRecord {
|
|
o := *e
|
|
return &o
|
|
}
|
|
|
|
func (e *SysOperaLog) GetId() interface{} {
|
|
return e.Id
|
|
}
|
|
|
|
// SaveOperaLog 从队列中获取操作日志
|
|
func SaveOperaLog(message storage.Messager) (err error) {
|
|
//准备db
|
|
db := sdk.Runtime.GetDbByTenant(message.GetPrefix())
|
|
if db == nil {
|
|
err = errors.New("db not exist")
|
|
log.Errorf("host[%s]'s %s", message.GetPrefix(), err.Error())
|
|
// Log writing to the database ignores error
|
|
return nil
|
|
}
|
|
var rb []byte
|
|
rb, err = json.Marshal(message.GetValues())
|
|
if err != nil {
|
|
log.Errorf("json Marshal error, %s", err.Error())
|
|
// Log writing to the database ignores error
|
|
return nil
|
|
}
|
|
var l SysOperaLog
|
|
err = json.Unmarshal(rb, &l)
|
|
if err != nil {
|
|
log.Errorf("json Unmarshal error, %s", err.Error())
|
|
// Log writing to the database ignores error
|
|
return nil
|
|
}
|
|
// 超出100个字符返回值截断
|
|
if len(l.JsonResult) > 100 {
|
|
l.JsonResult = l.JsonResult[:100]
|
|
}
|
|
err = db.Create(&l).Error
|
|
if err != nil {
|
|
log.Errorf("db create error, %s", err.Error())
|
|
// Log writing to the database ignores error
|
|
return nil
|
|
}
|
|
return nil
|
|
}
|