package model import ( "os" "surveyService/util" "time" "gorm.io/gorm" ) const SurveyMechanismTableName = "survey_mechanism" const ( SURVEY_MECHANISM_AUTHORIZE_STATUS_ENABLE = 1 // 可用 SURVEY_MECHANISM_AUTHORIZE_STATUS_DISABLE = 2 // 禁用 SURVEY_MECHANISM_STATUS_ENABLE = 1 // 可用 SURVEY_MECHANISM_STATUS_DISABLE = 2 // 禁用 ) type SurveyMechanism struct { ID int64 `gorm:"type:int(20);autoIncrement;comment:ID;" json:"id"` SN string `gorm:"type:varchar(255);comment:问卷编号;default:'';" json:"sn"` AuthorizeStatus int `gorm:"type:int(11);comment:状态:1:可用,2:禁用;default:2;" json:"status"` Status int `gorm:"type:int(11);comment:是否启用:1:启用,2:禁用;default:2;" json:"enable"` MechanismId string `gorm:"type:varchar(255);comment:机构编号;default:'';" json:"mechanismId"` SurveyId int64 `gorm:"type:int(20);comment:问卷ID;default:0;" json:"surveyId"` Permissions string `gorm:"type:mediumText;comment:权限;nullable;" json:"permissions"` Name string `gorm:"type:varchar(255);comment:问卷名称;default:'';" json:"name"` Cover string `gorm:"type:varchar(255);comment:封面;default:'';" json:"cover"` Description string `gorm:"type:mediumText;comment:描述;nullable;" json:"description"` Survey Survey `gorm:"foreignKey:SurveyId;references:ID" json:"survey"` SurveyResults []*SurveyResult `gorm:"foreignKey:SurveyMechanismId;references:ID" json:"surveyResults"` SurveyResult *SurveyResult `gorm:"foreignKey:SurveyMechanismId;references:ID" json:"surveyResult"` DeletedAt gorm.DeletedAt `gorm:"column:deleted_at" json:"-"` CreatedAt time.Time `gorm:"column:created_at" json:"createdAt"` UpdatedAt time.Time `gorm:"column:updated_at" json:"updatedAt"` } func (u *SurveyMechanism) AfterCreate(tx *gorm.DB) (err error) { tx.Model(u).Update("sn", u.GetHashId(u.ID)) return } func (u *SurveyMechanism) AfterFind(tx *gorm.DB) (err error) { return } func (u *SurveyMechanism) GetHashId(id int64) string { return util.GetHashId(id, SurveyMechanismTableName) } func (u *SurveyMechanism) GetRawId(sn string) int64 { rawId, _ := util.GetIdByHashId(sn, SurveyMechanismTableName) return rawId } func (u *SurveyMechanism) TableName() string { dbPrefix := os.Getenv("DB_PREFIX") return dbPrefix + SurveyMechanismTableName }