提交 67348e31 authored 作者: mooncake's avatar mooncake

update

上级 f2ebe6f0
...@@ -4,9 +4,37 @@ import ( ...@@ -4,9 +4,37 @@ import (
ctxutils "gitlab.wanzhuangkj.com/tush/xpkg/xutils/ctxutils" ctxutils "gitlab.wanzhuangkj.com/tush/xpkg/xutils/ctxutils"
setutils "gitlab.wanzhuangkj.com/tush/xpkg/xutils/setutils" setutils "gitlab.wanzhuangkj.com/tush/xpkg/xutils/setutils"
"gitlab.wanzhuangkj.com/tush/xpkg/xutils/xsf" "gitlab.wanzhuangkj.com/tush/xpkg/xutils/xsf"
"gitlab.wanzhuangkj.com/tush/xpkg/xutils/xtime"
"gorm.io/gorm" "gorm.io/gorm"
) )
type CommonModel struct {
ID xsf.ID `json:"id" form:"id" swaggertype:"string" gorm:"column:id;type:bigint(20);primaryKey;autoIncrement;comment:主键" example:"1234567890123456789" csv:"主键ID"` //主键
CreatedAt xtime.DateTime `json:"createdAt" form:"createdAt" gorm:"column:created_at;type:datetime;comment:创建时间" example:"2025-09-18 10:05:00" csv:"创建时间"` //创建时间
UpdatedAt xtime.DateTime `json:"updatedAt" form:"updatedAt" gorm:"column:updated_at;type:datetime;comment:更新时间" example:"2025-09-18 10:05:00" csv:"更新时间"` //更新时间
}
func (x CommonModel) GetID() xsf.ID {
return x.ID
}
func (x CommonModel) GetOrder() string {
return "id asc"
}
func (x *CommonModel) BeforeCreate(tx *gorm.DB) (err error) {
if x.CreatedAt.IsZero() {
x.CreatedAt = xtime.Now()
}
return nil
}
func (x *CommonModel) BeforeUpdate(tx *gorm.DB) (err error) {
if x.UpdatedAt.IsZero() {
x.UpdatedAt = xtime.Now()
}
return nil
}
func GetUid(tx *gorm.DB) xsf.ID { func GetUid(tx *gorm.DB) xsf.ID {
ctx := tx.Statement.Context ctx := tx.Statement.Context
return ctxutils.GetCtxUID(ctx) return ctxutils.GetCtxUID(ctx)
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论