修正log记录,数据库自动更新

This commit is contained in:
2023-06-13 11:26:23 +08:00
parent 91e3d72873
commit 708873087f
3 changed files with 24 additions and 49 deletions
+5 -19
View File
@@ -1,28 +1,14 @@
package model
import (
"fmt"
"gorm.io/gorm"
"time"
)
// AdminRole 后台-角色表
type AdminRole struct {
// Model
RoleId int64 `gorm:"column:role_id;type:bigint(19);primary_key;comment:主键id" json:"role_id"`
RoleName string `gorm:"column:role_name;type:varchar(100);comment:角色名称" json:"role_name"`
RoleStatus int `gorm:"column:role_status;type:tinyint(1);default:1;comment:角色状态(1:正常 2:禁用)" json:"role_status"`
IsAdmin int `gorm:"column:is_admin;type:tinyint(1);default:0;comment:是否管理员(0:否 1:是)" json:"is_admin"`
CreatedAt time.Time `gorm:"column:created_at;type:datetime;comment:创建时间" json:"created_at"`
UpdatedAt time.Time `gorm:"column:updated_at;type:datetime;comment:修改时间" json:"updated_at"`
Model
RoleId int64 `gorm:"column:role_id;type:bigint(19);primary_key;comment:主键id" json:"role_id"`
RoleName string `gorm:"column:role_name;type:varchar(100);comment:角色名称" json:"role_name"`
RoleStatus int `gorm:"column:role_status;type:tinyint(1);default:1;comment:角色状态(1:正常 2:禁用)" json:"role_status"`
IsAdmin int `gorm:"column:is_admin;type:tinyint(1);default:0;comment:是否管理员(0:否 1:是)" json:"is_admin"`
}
func (m *AdminRole) TableName() string {
return "gdxz_admin_role"
}
func (m *AdminRole) BeforeUpdate(tx *gorm.DB) (err error) {
fmt.Println(111111)
m.UpdatedAt = time.Now()
return nil
}
+7
View File
@@ -79,3 +79,10 @@ func (m *Model) BeforeCreate(tx *gorm.DB) (err error) {
return nil
}
func (m *Model) BeforeUpdate(tx *gorm.DB) (err error) {
m.UpdatedAt = LocalTime(time.Now())
tx.Statement.SetColumn("UpdatedAt", m.UpdatedAt)
return nil
}