44 lines
1.1 KiB
Go
44 lines
1.1 KiB
Go
package po
|
|
|
|
import "go.mongodb.org/mongo-driver/bson/primitive"
|
|
|
|
type TBase struct {
|
|
OID primitive.ObjectID `bson:"_id,omitempty"` // 主键
|
|
CreatedAt int64 `bson:"createdAt"` // 创建时间
|
|
UpdatedAt int64 `bson:"updatedAt"` // 更新时间
|
|
DeletedAt int64 `bson:"deletedAt"` // 删除时间
|
|
CreatedBy_OID primitive.ObjectID `bson:"createdBy"` // 创建人OID
|
|
Tenant_OID primitive.ObjectID `bson:"tenantId"` // 租户ID
|
|
}
|
|
|
|
// Id 获取主键
|
|
func (t *TBase) Id() string {
|
|
return t.OID.Hex()
|
|
}
|
|
|
|
// CreatedBy 获取创建人 Id
|
|
func (t *TBase) CreatedBy() string {
|
|
return t.CreatedBy_OID.Hex()
|
|
}
|
|
|
|
// SetCreatedBy 设置创建人 Id
|
|
func (t *TBase) SetCreatedBy(createdBy string) {
|
|
t.CreatedBy_OID, _ = primitive.ObjectIDFromHex(createdBy)
|
|
}
|
|
|
|
// TenantId 获取租户 Id
|
|
func (t *TBase) TenantId() string {
|
|
return t.Tenant_OID.Hex()
|
|
}
|
|
|
|
// SetTenantId 设置租户 Id
|
|
func (t *TBase) SetTenantId(tenantId string) {
|
|
t.Tenant_OID, _ = primitive.ObjectIDFromHex(tenantId)
|
|
}
|
|
|
|
// SetNow 设置当前时间
|
|
func (t *TBase) SetNow(now int64) {
|
|
t.CreatedAt = now
|
|
t.UpdatedAt = now
|
|
}
|