...
|
...
|
@@ -2,6 +2,9 @@ package service |
|
|
|
|
|
import (
|
|
|
"fmt"
|
|
|
"path/filepath"
|
|
|
"time"
|
|
|
|
|
|
"github.com/linmadan/egglib-go/core/application"
|
|
|
"github.com/linmadan/egglib-go/utils/tool_funs"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/application/factory"
|
...
|
...
|
@@ -11,8 +14,6 @@ import ( |
|
|
"gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/domain"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/domainService"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/utils"
|
|
|
"path/filepath"
|
|
|
"time"
|
|
|
)
|
|
|
|
|
|
// 文件服务
|
...
|
...
|
@@ -34,14 +35,15 @@ func (fileService *FileService) CreateFile(ctx *domain.Context, createFileComman |
|
|
defer func() {
|
|
|
transactionContext.RollbackTransaction()
|
|
|
}()
|
|
|
fileInfo := &domain.FileInfo{
|
|
|
Name: domain.FileName(createFileCommand.Name),
|
|
|
Url: createFileCommand.Url,
|
|
|
FileSize: createFileCommand.FileSize,
|
|
|
Ext: filepath.Ext(createFileCommand.Name),
|
|
|
}
|
|
|
newFile := &domain.File{
|
|
|
FileType: domain.SourceFile.ToString(),
|
|
|
FileInfo: &domain.FileInfo{
|
|
|
Name: domain.FileName(createFileCommand.Name),
|
|
|
Url: createFileCommand.Url,
|
|
|
FileSize: createFileCommand.FileSize,
|
|
|
Ext: filepath.Ext(createFileCommand.Name),
|
|
|
},
|
|
|
FileType: domain.SourceFile.ToString(),
|
|
|
FileInfo: fileInfo,
|
|
|
SourceFileId: 0,
|
|
|
//Operator: "",
|
|
|
CreatedAt: time.Now(),
|
...
|
...
|
@@ -49,6 +51,18 @@ func (fileService *FileService) CreateFile(ctx *domain.Context, createFileComman |
|
|
Context: ctx,
|
|
|
}
|
|
|
fileRepository, _, _ := factory.FastPgFile(transactionContext, 0)
|
|
|
|
|
|
// 文件名相同进行替换
|
|
|
if oldFile, findOldFileErr := fileRepository.FindOne(map[string]interface{}{
|
|
|
"context": ctx,
|
|
|
"fileName": fileInfo.Name,
|
|
|
"fileType": domain.SourceFile.ToString(),
|
|
|
}); oldFile != nil && findOldFileErr == nil {
|
|
|
oldFile.FileInfo = fileInfo
|
|
|
oldFile.UpdatedAt = time.Now()
|
|
|
newFile = oldFile
|
|
|
}
|
|
|
|
|
|
file, err := fileRepository.Save(newFile)
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
...
|
...
|
@@ -92,7 +106,7 @@ func (fileService *FileService) GetFile(getFileQuery *query.GetFileQuery) (inter |
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
if file == nil {
|
|
|
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(getFileQuery.FileId)))
|
|
|
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%d", getFileQuery.FileId))
|
|
|
} else {
|
|
|
if err := transactionContext.CommitTransaction(); err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
...
|
...
|
@@ -207,7 +221,7 @@ func (fileService *FileService) RemoveFile(ctx *domain.Context, removeFileComman |
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
if file == nil {
|
|
|
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(removeFileCommand.FileId)))
|
|
|
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%d", removeFileCommand.FileId))
|
|
|
}
|
|
|
deleteFileService, _ := factory.CreateDeleteFileService(transactionContext)
|
|
|
err = deleteFileService.DeleteFiles(ctx, file)
|
...
|
...
|
@@ -248,7 +262,7 @@ func (fileService *FileService) UpdateFile(updateFileCommand *command.UpdateFile |
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
if file == nil {
|
|
|
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updateFileCommand.FileId)))
|
|
|
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%d", updateFileCommand.FileId))
|
|
|
}
|
|
|
if err := file.Update(tool_funs.SimpleStructToMap(updateFileCommand)); err != nil {
|
|
|
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
|
...
|
...
|
|