mirror of
https://gitee.com/dromara/mayfly-go
synced 2025-11-03 07:50:25 +08:00
38 lines
771 B
Go
38 lines
771 B
Go
package model
|
|
|
|
import (
|
|
"time"
|
|
)
|
|
|
|
type Model struct {
|
|
Id uint64 `json:"id"`
|
|
CreateTime *time.Time `json:"createTime"`
|
|
CreatorId uint64 `json:"creatorId"`
|
|
Creator string `json:"creator"`
|
|
UpdateTime *time.Time `json:"updateTime"`
|
|
ModifierId uint64 `json:"modifierId"`
|
|
Modifier string `json:"modifier"`
|
|
}
|
|
|
|
// 设置基础信息. 如创建时间,修改时间,创建者,修改者信息
|
|
func (m *Model) SetBaseInfo(account *LoginAccount) {
|
|
nowTime := time.Now()
|
|
isCreate := m.Id == 0
|
|
if isCreate {
|
|
m.CreateTime = &nowTime
|
|
}
|
|
m.UpdateTime = &nowTime
|
|
|
|
if account == nil {
|
|
return
|
|
}
|
|
id := account.Id
|
|
name := account.Username
|
|
if isCreate {
|
|
m.CreatorId = id
|
|
m.Creator = name
|
|
}
|
|
m.Modifier = name
|
|
m.ModifierId = id
|
|
}
|