医生绑定药房
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"gorm.io/gorm"
|
||||
"hospital-admin-api/global"
|
||||
"time"
|
||||
)
|
||||
|
||||
// DoctorPharmacy 医生-药房关联表
|
||||
type DoctorPharmacy struct {
|
||||
DoctorPharmacyId int64 `gorm:"column:doctor_pharmacy_id;type:bigint(20);primary_key;comment:主键id" json:"doctor_pharmacy_id"`
|
||||
DoctorId int64 `gorm:"column:doctor_id;type:bigint(19);comment:医生id;NOT NULL" json:"doctor_id"`
|
||||
PharmacyId int64 `gorm:"column:pharmacy_id;type:bigint(20);comment:药房id;NOT NULL" json:"pharmacy_id"`
|
||||
IsDefault int `gorm:"column:is_default;type:tinyint(1);default:0;comment:是否默认药房(0:否 1:是)" json:"is_default"`
|
||||
Status int `gorm:"column:status;type:tinyint(1);default:1;comment:状态(0:禁用 1:正常)" json:"status"`
|
||||
Model
|
||||
Pharmacy *Pharmacy `gorm:"foreignKey:PharmacyId;references:pharmacy_id" json:"pharmacy"`
|
||||
}
|
||||
|
||||
func (m *DoctorPharmacy) TableName() string {
|
||||
return "gdxz_doctor_pharmacy"
|
||||
}
|
||||
|
||||
func (m *DoctorPharmacy) BeforeCreate(tx *gorm.DB) error {
|
||||
if m.DoctorPharmacyId == 0 {
|
||||
m.DoctorPharmacyId = 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
|
||||
}
|
||||
Reference in New Issue
Block a user