修复file上传未设置到用户,修复查询数据失败问题
This commit is contained in:
parent
4b61e7102e
commit
6ec1a5906d
30
dao/file.go
30
dao/file.go
|
|
@ -3,6 +3,7 @@ package dao
|
||||||
import (
|
import (
|
||||||
"StuAcaWorksAI/proto"
|
"StuAcaWorksAI/proto"
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
|
"log"
|
||||||
)
|
)
|
||||||
|
|
||||||
type File struct {
|
type File struct {
|
||||||
|
|
@ -35,6 +36,17 @@ type ConfigFile struct {
|
||||||
FilePath string `gorm:"column:file_path"`
|
FilePath string `gorm:"column:file_path"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type FileAuthListResp struct {
|
||||||
|
gorm.Model
|
||||||
|
AuthID int `gorm:"column:auth_id"`
|
||||||
|
FileID int `gorm:"column:file_id"`
|
||||||
|
UserFileName string `gorm:"column:user_file_name;type:varchar(255);uniqueIndex:idx_file_name"` //对于同一个文件,不同用户有不同的文件名
|
||||||
|
UploadType string `gorm:"column:upload_type"` // 上传类型: im,avatar,file,config,config为系统文件
|
||||||
|
IsPrivate int `gorm:"column:is_private"` // 是否私有,私有文件只能自己下载或者通过分享链接下载,1为私有,0为公开
|
||||||
|
ShareCode string `gorm:"column:share_code"` // 分享码,用于分享时的验证,构建分享链接
|
||||||
|
FileStoreName string `gorm:"column:file_store_name;type:varchar(255);uniqueIndex:idx_file_name"`
|
||||||
|
}
|
||||||
|
|
||||||
func CreateFile(fileStoreName, fileName, fileType, filePath, md5Str string, fileSize, authID int, NeedAuth bool) File {
|
func CreateFile(fileStoreName, fileName, fileType, filePath, md5Str string, fileSize, authID int, NeedAuth bool) File {
|
||||||
file := File{FileStoreName: fileStoreName, FileName: fileName, FileType: fileType, FilePath: filePath, FileSize: fileSize, AuthID: authID, NeedAuth: NeedAuth, Md5: md5Str}
|
file := File{FileStoreName: fileStoreName, FileName: fileName, FileType: fileType, FilePath: filePath, FileSize: fileSize, AuthID: authID, NeedAuth: NeedAuth, Md5: md5Str}
|
||||||
result := DB.Create(&file)
|
result := DB.Create(&file)
|
||||||
|
|
@ -179,13 +191,21 @@ func FindConfigFileByAuthID(auth_id int) []ConfigFile {
|
||||||
}
|
}
|
||||||
|
|
||||||
// 通用通过用户id及类型查询
|
// 通用通过用户id及类型查询
|
||||||
func FileUserFileList(userID int, fileType string) []FileAuth {
|
func FileUserFileList(userID int, fileType string) []FileAuthListResp {
|
||||||
var files []FileAuth
|
var files []FileAuthListResp
|
||||||
|
query := DB.Where("file_auths.auth_id = ? AND file_auths.upload_type = ?", userID, fileType).
|
||||||
|
Joins("LEFT JOIN files ON file_auths.file_id = files.id")
|
||||||
|
|
||||||
if proto.Config.SERVER_SQL_LOG {
|
if proto.Config.SERVER_SQL_LOG {
|
||||||
DB.Debug().Where("auth_id = ? and upload_type = ?", userID, fileType).Find(&files)
|
query = query.Debug()
|
||||||
} else {
|
|
||||||
DB.Where("auth_id = ? and upload_type = ?", userID, fileType).Find(&files)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
result := query.Find(&files)
|
||||||
|
if result.Error != nil {
|
||||||
|
log.Printf("查询文件列表时出错,UserID: %d, FileType: %s, 错误信息: %v", userID, fileType, result.Error)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
return files
|
return files
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue