feat: 操作日志

This commit is contained in:
Blizzard
2025-09-15 21:49:55 +08:00
parent 6beb915adf
commit 79c19bc47c
10 changed files with 186 additions and 15 deletions
+1
View File
@@ -6,4 +6,5 @@ type ServiceGroup struct {
ClientService
RoleService
MenuService
OperationRecordService
}
+2 -2
View File
@@ -11,7 +11,7 @@ type JwtService struct{}
var JwtServiceApp = new(JwtService)
// 登出,禁用jwt
func (s JwtService) PutBlacklist(userId string, token string) (err error) {
func (s *JwtService) PutBlacklist(userId string, token string) (err error) {
expire, err := utils.ParseDuration(global.Config.JWT.ExpiresTime)
if err != nil {
return err
@@ -20,7 +20,7 @@ func (s JwtService) PutBlacklist(userId string, token string) (err error) {
return err
}
func (s JwtService) IsInBlacklist(userId string, token string) bool {
func (s *JwtService) IsInBlacklist(userId string, token string) bool {
val, err := global.Redis.Get(context.Background(), userId).Result()
return err == nil && val == token
}
+57
View File
@@ -0,0 +1,57 @@
package system
import (
"sundynix-go/global"
common "sundynix-go/model/commom/request"
"sundynix-go/model/system"
systemReq "sundynix-go/model/system/request"
)
type OperationRecordService struct{}
var OperationRecordServiceApp = new(OperationRecordService)
func (o *OperationRecordService) CreateOperationRecord(operationRecord system.SysOperationRecord) (err error) {
return global.DB.Create(&operationRecord).Error
}
func (o *OperationRecordService) GetRecordList(info systemReq.GetOperationRecordList) (list interface{}, total int64, err error) {
limit := info.PageSize
offset := info.PageSize * (info.Current - 1)
db := global.DB.Model(&system.SysOperationRecord{})
var operationRecordList []system.SysOperationRecord
if info.Ip != "" {
db = db.Where("ip = ?", info.Method)
}
if info.Method != "" {
db = db.Where("method = ?", info.Method)
}
if info.Path != "" {
db = db.Where("path = ?", info.Path)
}
if info.UserId != "" {
db = db.Where("status = ?", info.UserId)
}
if info.Status != 0 {
db = db.Where("status = ?", info.Status)
}
err = db.Count(&total).Error
if err != nil {
return
}
err = db.Limit(limit).Offset(offset).Find(&operationRecordList).Error
return operationRecordList, total, err
}
func (o *OperationRecordService) GetRecordById(id string) (record *system.SysOperationRecord, err error) {
var r system.SysOperationRecord
err = global.DB.Where("id = ?", id).First(&r).Error
return &r, err
}
func (o *OperationRecordService) DeleteRecordsByIds(ids common.IdsReq) (err error) {
// Unscoped()禁用软删除 --> 永久物理删除
err = global.DB.Where("id in ?", ids.Ids).Unscoped().Delete(&system.SysOperationRecord{}).Error
return err
}