切换批次和文件的 ID 类型为 UUID,更新相关逻辑和文档
This commit is contained in:
@@ -34,6 +34,7 @@ func (s *UploadService) CreateBatch(ctx context.Context, files []*multipart.File
|
||||
|
||||
// 2. 准备 Batch
|
||||
batch := &model.FileBatch{
|
||||
ID: uuid.New().String(),
|
||||
PickupCode: pickupCode,
|
||||
Remark: remark,
|
||||
ExpireType: expireType,
|
||||
@@ -69,6 +70,7 @@ func (s *UploadService) CreateTextBatch(ctx context.Context, content string, rem
|
||||
|
||||
// 2. 准备 Batch
|
||||
batch := &model.FileBatch{
|
||||
ID: uuid.New().String(),
|
||||
PickupCode: pickupCode,
|
||||
Remark: remark,
|
||||
ExpireType: expireType,
|
||||
@@ -101,7 +103,7 @@ func (s *UploadService) applyExpire(batch *model.FileBatch, expireType string, e
|
||||
}
|
||||
}
|
||||
|
||||
func (s *UploadService) processFile(ctx context.Context, tx *gorm.DB, batchID uint, fileHeader *multipart.FileHeader) (*model.FileItem, error) {
|
||||
func (s *UploadService) processFile(ctx context.Context, tx *gorm.DB, batchID string, fileHeader *multipart.FileHeader) (*model.FileItem, error) {
|
||||
file, err := fileHeader.Open()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -110,7 +112,8 @@ func (s *UploadService) processFile(ctx context.Context, tx *gorm.DB, batchID ui
|
||||
|
||||
// 生成唯一存储路径
|
||||
ext := filepath.Ext(fileHeader.Filename)
|
||||
storagePath := fmt.Sprintf("%d/%s%s", batchID, uuid.New().String(), ext)
|
||||
fileID := uuid.New().String()
|
||||
storagePath := fmt.Sprintf("%s/%s%s", batchID, fileID, ext)
|
||||
|
||||
// 保存到存储层
|
||||
if err := storage.GlobalStorage.Save(ctx, storagePath, file); err != nil {
|
||||
@@ -119,6 +122,7 @@ func (s *UploadService) processFile(ctx context.Context, tx *gorm.DB, batchID ui
|
||||
|
||||
// 创建数据库记录
|
||||
item := &model.FileItem{
|
||||
ID: fileID,
|
||||
BatchID: batchID,
|
||||
OriginalName: fileHeader.Filename,
|
||||
StoragePath: storagePath,
|
||||
|
||||
Reference in New Issue
Block a user