123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- package model
- import (
- "os"
- "surveyService/util"
- "time"
- "gorm.io/gorm"
- )
- const SurveyResultTableName = "survey_result"
- const (
- SurveyResultMethodMechanism = 1 // 机构端
- SurveyResultMethodArchives = 2 // 用户端
- SurveyResultMethodManage = 3 // 平台后台
- SurveyResultStatusWait = 1 // 填写中
- SurveyResultStatusFulled = 2 // 已完善
- SurveyResultStatusDone = 3 // 已处理
- )
- type SurveyResult struct {
- ID int64 `gorm:"type:int(20);autoIncrement;comment:ID;" json:"id"`
- SN string `gorm:"type:varchar(255);comment:问卷结果编号;default:'';" json:"sn"`
- Method int `gorm:"type:int(11);comment:调查方式;default:1;" json:"method"`
- StartTime time.Time `gorm:"type:datetime;comment:开始时间;default:null;" json:"startTime"`
- EndTime time.Time `gorm:"type:datetime;comment:结束时间;default:null;" json:"endTime"`
- ArchivesId string `gorm:"type:varchar(255);comment:档案ID;default:'';" json:"archivesId"`
- AnswerRaw string `gorm:"type:mediumText;comment:答案原始数据;nullable;" json:"answerRaw"`
- ResultRaw string `gorm:"type:mediumText;comment:结果原始数据;nullable;" json:"resultRaw"`
- Status int `gorm:"type:int(11);comment:状态;default:1;" json:"status"`
- Remark string `gorm:"type:mediumText;comment:备注;nullable;" json:"remark"`
- SurveyMechanismId int64 `gorm:"type:int(20);comment:机构问卷ID;default:0;" json:"surveyMechanismId"`
- SurveyMechanism *SurveyMechanism `gorm:"foreignKey:SurveyMechanismId;references:ID" json:"surveyMechanism"`
- MechanismId string `gorm:"type:varchar(255);comment:机构ID;default:'';" json:"mechanismId"`
- Extra string `gorm:"type:varchar(255);comment:自定义参数;default:'';" json:"extra"`
- 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 *SurveyResult) AfterCreate(tx *gorm.DB) (err error) {
- tx.Model(u).Update("sn", u.GetHashId(u.ID))
- return
- }
- func (u *SurveyResult) AfterFind(tx *gorm.DB) (err error) {
- return
- }
- func (u *SurveyResult) GetHashId(id int64) string {
- return util.GetHashId(id, SurveyResultTableName)
- }
- func (u *SurveyResult) GetRawId(sn string) int64 {
- rawId, _ := util.GetIdByHashId(sn, SurveyResultTableName)
- return rawId
- }
- func (u *SurveyResult) TableName() string {
- dbPrefix := os.Getenv("DB_PREFIX")
- return dbPrefix + SurveyResultTableName
- }
|