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() { + +}