file.go 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. package dao
  2. import "time"
  3. // File 文件表
  4. type File struct {
  5. ID int `gorm:"primary_key;type:int" json:"id"` //编号
  6. OriginalName string `gorm:"type:varchar(45)" json:"originalName"` //文件原始名
  7. EncryptedName string `gorm:"type:varchar(45)" json:"encryptedName"` //文件加密名
  8. SavePath string `gorm:"type:varchar(45)" json:"savePath"` //保存路径
  9. CategoryName string `gorm:"type:varchar(12)" json:"categoryName"` //文件类别名
  10. AuthId string `gorm:"type:varchar(12);default:'100'" json:"authId"` //权限id
  11. SuffixName string `gorm:"type:varchar(12)" json:"suffixName"` //文件后缀名
  12. UploadTime time.Time `gorm:"column:upload_time;type:datetime" json:"uploadTime"` //上传时间
  13. Uploader int `gorm:"type:int" json:"uploader"` //上传者id
  14. IsShowed int `gorm:"type:int;default:0" json:"isShowed"` //收否展示 0=展示,1=不展示
  15. IsDeleted int `gorm:"type:int;default:0" json:"isDeleted"` //是否删除 0=未删除,1=删除
  16. }
  17. func (*File) TableName() string {
  18. return "file"
  19. }
  20. func (f *File) Create() error {
  21. return Db.Model(&f).Save(&f).Error
  22. }
  23. func (f *File) GetUserFiles(uid int) ([]File, error) {
  24. var files []File
  25. err := Db.Table("file").
  26. Select("file.*").
  27. Joins("left join user_file uf on uf.file_id = file.id").
  28. Where("uf.receiver = ? AND file.is_showed = 0 AND file.is_deleted = 0", uid).
  29. Order("upload_time DESC"). // 根据created_at字段降序排列
  30. Scan(&files).
  31. Error
  32. return files, err
  33. }