解决循环引用问题

This commit is contained in:
junleea 2025-03-29 14:02:21 +08:00
parent f759046b15
commit ae355b23ca
3 changed files with 8 additions and 9 deletions

View File

@ -41,6 +41,11 @@ type FileAuthListResp struct {
FileStoreName string `gorm:"column:file_store_name;type:varchar(255);uniqueIndex:idx_file_name"` FileStoreName string `gorm:"column:file_store_name;type:varchar(255);uniqueIndex:idx_file_name"`
} }
type UserFileListResp struct {
FileAuth
FileStoreName string `json:"file_store_name" form:"file_store_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)

View File

@ -1,7 +1,6 @@
package proto package proto
import ( import (
"StuAcaWorksAI/dao"
"time" "time"
) )
@ -33,8 +32,3 @@ type SearchOneConfigFileResp struct {
FilePath string `json:"file_path" form:"file_path"` FilePath string `json:"file_path" form:"file_path"`
Content string `json:"content" form:"content"` Content string `json:"content" form:"content"`
} }
type UserFileListResp struct {
dao.FileAuth
FileStoreName string `json:"file_store_name" form:"file_store_name"`
}

View File

@ -249,16 +249,16 @@ func CreateUserFile(userID int, fileAuthName string, fileID int, UploadType stri
return fileAuth return fileAuth
} }
func FindUserFileList(userID int, uploadType string) []proto.UserFileListResp { func FindUserFileList(userID int, uploadType string) []dao.UserFileListResp {
fileList, files := dao.FileUserFileList(userID, uploadType) fileList, files := dao.FileUserFileList(userID, uploadType)
filesM := make(map[uint]dao.File) filesM := make(map[uint]dao.File)
for _, file := range files { for _, file := range files {
filesM[file.ID] = file filesM[file.ID] = file
} }
var res []proto.UserFileListResp var res []dao.UserFileListResp
for _, file := range fileList { for _, file := range fileList {
fileStoreName := filesM[uint(file.FileID)].FileStoreName fileStoreName := filesM[uint(file.FileID)].FileStoreName
r := proto.UserFileListResp{FileAuth: file, FileStoreName: fileStoreName} r := dao.UserFileListResp{FileAuth: file, FileStoreName: fileStoreName}
res = append(res, r) res = append(res, r)
} }
log.Println("FindUserFileList res:", len(res)) log.Println("FindUserFileList res:", len(res))