operation_log.go 1011 Bytes
Newer Older
hujiebin's avatar
hujiebin committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
package mgr_m

import (
	"git.hilo.cn/hilo-common/domain"
	"git.hilo.cn/hilo-common/resource/mysql"
	"gorm.io/gorm"
)

type MgrOperationModuleUrl struct {
	mysql.Entity
	ModuleId mysql.ID
	Method   string
	FullPath string
}

type MgrOperationLog struct {
	mysql.Entity
	ModuleId    mysql.ID
	ModuleUrlId mysql.ID
	Content     string
	Description string
	MediaUrls   string
	TargetUid   mysql.ID
	OperUid     mysql.ID
	MgrId       mysql.ID
}

// 根据path获取操作模块
func GetOperationModuleUrl(model *domain.Model, method, fullPath string) MgrOperationModuleUrl {
	var config MgrOperationModuleUrl
	if err := model.Db.Model(MgrOperationModuleUrl{}).Where("method = ? AND full_path = ?", method, fullPath).First(&config).Error; err != nil {
		if err != gorm.ErrRecordNotFound {
			model.Log.Errorf("GetOperationModuleUrl fail:%v", err)
		}
	}
	return config
}

// 保存操作日志
func SaveOperationLog(model *domain.Model, log MgrOperationLog) error {
	err := model.Db.Create(&log).Error
	return err
}