39 lines
1.2 KiB
Go
39 lines
1.2 KiB
Go
package model
|
|
|
|
import (
|
|
"gorm.io/gorm"
|
|
"hepa-calc-api/global"
|
|
"time"
|
|
)
|
|
|
|
type BaseArea struct {
|
|
Id int64 `gorm:"column:id;type:bigint(20);primary_key;AUTO_INCREMENT" json:"id"`
|
|
CreateDate *LocalTime `gorm:"column:create_date;type:datetime;NOT NULL" json:"create_date"`
|
|
ModifyDate *LocalTime `gorm:"column:modify_date;type:datetime;NOT NULL" json:"modify_date"`
|
|
Orders int `gorm:"column:orders;type:int(11)" json:"orders"`
|
|
FullName string `gorm:"column:full_name;type:longtext;NOT NULL" json:"full_name"`
|
|
Name string `gorm:"column:name;type:varchar(100);NOT NULL" json:"name"`
|
|
TreePath string `gorm:"column:tree_path;type:varchar(255);NOT NULL" json:"tree_path"`
|
|
Parent int64 `gorm:"column:parent;type:bigint(20)" json:"parent"`
|
|
CanClinic int `gorm:"column:can_clinic;type:int(11);default:1" json:"can_clinic"`
|
|
Model
|
|
}
|
|
|
|
func (m *BaseArea) TableName() string {
|
|
return "base_area"
|
|
}
|
|
|
|
func (m *BaseArea) BeforeCreate(tx *gorm.DB) error {
|
|
if m.Id == 0 {
|
|
m.Id = global.Snowflake.Generate().Int64()
|
|
}
|
|
|
|
m.CreatedAt = LocalTime(time.Now())
|
|
tx.Statement.SetColumn("CreatedAt", m.CreatedAt)
|
|
|
|
m.UpdatedAt = LocalTime(time.Now())
|
|
tx.Statement.SetColumn("UpdatedAt", m.UpdatedAt)
|
|
|
|
return nil
|
|
}
|