Files
mayfly-go/server/pkg/model/model.go

38 lines
771 B
Go
Raw Normal View History

2021-01-08 15:37:32 +08:00
package model
2020-09-01 10:34:11 +08:00
import (
"time"
)
type Model struct {
2021-04-16 15:10:07 +08:00
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"`
2021-01-08 15:37:32 +08:00
}
// 设置基础信息. 如创建时间,修改时间,创建者,修改者信息
2021-04-16 15:10:07 +08:00
func (m *Model) SetBaseInfo(account *LoginAccount) {
2021-01-08 15:37:32 +08:00
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
2020-09-01 10:34:11 +08:00
}