From f4925cf693795bc7c1ac8cc519ba42a6d29bbd9f Mon Sep 17 00:00:00 2001 From: junleea <354425203@qq.com> Date: Sat, 5 Apr 2025 13:57:15 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=96=87=E4=BB=B6=E4=BF=9D?= =?UTF-8?q?=E5=AD=98=E5=B7=B2=E6=9C=89=E6=96=87=E4=BB=B6=E5=90=8D=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dao/file.go | 12 ++++++++++++ service/fileService.go | 18 ++++++++++++++++-- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/dao/file.go b/dao/file.go index a1458c7..1df5005 100644 --- a/dao/file.go +++ b/dao/file.go @@ -282,3 +282,15 @@ func GetUserFileSpace(userID int) UserFileSpace { } return space } + +func FindFileAuthByName(fileName string, userID int) FileAuth { + var file FileAuth + var db2 *gorm.DB + if proto.Config.SERVER_SQL_LOG { + db2 = DB.Debug() + } else { + db2 = DB + } + db2.Where("user_file_name = ? and auth_id = ?", fileName, userID).First(&file) + return file +} diff --git a/service/fileService.go b/service/fileService.go index 000a85e..c348aa3 100644 --- a/service/fileService.go +++ b/service/fileService.go @@ -15,6 +15,7 @@ import ( "os" "path" "regexp" + "strings" "time" ) @@ -245,8 +246,17 @@ func DeleteUserFile(userID, fileAuthID int) error { } func CreateUserFile(userID int, fileAuthName string, fileID int, UploadType string) dao.FileAuth { - fileAuth := dao.CreateFileAuth(userID, fileID, fileAuthName, UploadType, 1, "") - return fileAuth + //先查fileAuthName是否存在 + fileAuth := dao.FindFileAuthByName(fileAuthName, userID) + if fileAuth.ID != 0 { + log.Println("file auth name already exist, please change another name: ", fileAuthName) + //将要保存的文件名改为fileAuthName+uuid + strs := strings.Split(fileAuthName, ".") + fileAuthName = strs[0] + "_1." + strs[1] + //return fileAuth + } + fileAuth_ := dao.CreateFileAuth(userID, fileID, fileAuthName, UploadType, 1, "") + return fileAuth_ } func FindUserFileList(userID int, uploadType string) []dao.UserFileListResp { @@ -264,3 +274,7 @@ func FindUserFileList(userID int, uploadType string) []dao.UserFileListResp { log.Println("FindUserFileList res:", len(res)) return res } + +func CreateUserFileAfterUnique() { + +}