survey_result.go 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. package model
  2. import (
  3. "os"
  4. "surveyService/util"
  5. "time"
  6. "gorm.io/gorm"
  7. )
  8. const SurveyResultTableName = "survey_result"
  9. const (
  10. SurveyResultMethodMechanism = 1 // 机构端
  11. SurveyResultMethodArchives = 2 // 用户端
  12. SurveyResultMethodManage = 3 // 平台后台
  13. SurveyResultStatusWait = 1 // 填写中
  14. SurveyResultStatusFulled = 2 // 已完善
  15. SurveyResultStatusDone = 3 // 已处理
  16. )
  17. type SurveyResult struct {
  18. ID int64 `gorm:"type:int(20);autoIncrement;comment:ID;" json:"id"`
  19. SN string `gorm:"type:varchar(255);comment:问卷结果编号;default:'';" json:"sn"`
  20. Method int `gorm:"type:int(11);comment:调查方式;default:1;" json:"method"`
  21. StartTime time.Time `gorm:"type:datetime;comment:开始时间;default:null;" json:"startTime"`
  22. EndTime time.Time `gorm:"type:datetime;comment:结束时间;default:null;" json:"endTime"`
  23. ArchivesId string `gorm:"type:varchar(255);comment:档案ID;default:'';" json:"archivesId"`
  24. AnswerRaw string `gorm:"type:mediumText;comment:答案原始数据;nullable;" json:"answerRaw"`
  25. ResultRaw string `gorm:"type:mediumText;comment:结果原始数据;nullable;" json:"resultRaw"`
  26. Status int `gorm:"type:int(11);comment:状态;default:1;" json:"status"`
  27. Remark string `gorm:"type:mediumText;comment:备注;nullable;" json:"remark"`
  28. SurveyMechanismId int64 `gorm:"type:int(20);comment:机构问卷ID;default:0;" json:"surveyMechanismId"`
  29. SurveyMechanism *SurveyMechanism `gorm:"foreignKey:SurveyMechanismId;references:ID" json:"surveyMechanism"`
  30. MechanismId string `gorm:"type:varchar(255);comment:机构ID;default:'';" json:"mechanismId"`
  31. Extra string `gorm:"type:varchar(255);comment:自定义参数;default:'';" json:"extra"`
  32. DeletedAt gorm.DeletedAt `gorm:"column:deleted_at" json:"-"`
  33. CreatedAt time.Time `gorm:"column:created_at" json:"createdAt"`
  34. UpdatedAt time.Time `gorm:"column:updated_at" json:"updatedAt"`
  35. }
  36. func (u *SurveyResult) AfterCreate(tx *gorm.DB) (err error) {
  37. tx.Model(u).Update("sn", u.GetHashId(u.ID))
  38. return
  39. }
  40. func (u *SurveyResult) AfterFind(tx *gorm.DB) (err error) {
  41. return
  42. }
  43. func (u *SurveyResult) GetHashId(id int64) string {
  44. return util.GetHashId(id, SurveyResultTableName)
  45. }
  46. func (u *SurveyResult) GetRawId(sn string) int64 {
  47. rawId, _ := util.GetIdByHashId(sn, SurveyResultTableName)
  48. return rawId
  49. }
  50. func (u *SurveyResult) TableName() string {
  51. dbPrefix := os.Getenv("DB_PREFIX")
  52. return dbPrefix + SurveyResultTableName
  53. }