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