file_table_delete_file_service.go
1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package domainService
import (
"fmt"
pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
"gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/dao"
"gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/log"
)
type DeleteFileService struct {
transactionContext *pgTransaction.TransactionContext
}
func NewDeleteFileService(transactionContext *pgTransaction.TransactionContext) (*DeleteFileService, error) {
if transactionContext == nil {
return nil, fmt.Errorf("transactionContext参数不能为nil")
} else {
return &DeleteFileService{
transactionContext: transactionContext,
}, nil
}
}
// DeleteFiles 文件删除
func (ptr *DeleteFileService) DeleteFiles(ctx *domain.Context, files ...*domain.File) error {
for _, file := range files {
if err := ptr.delete(ctx, file); err != nil {
return err
}
}
return nil
}
func (ptr *DeleteFileService) delete(ctx *domain.Context, file *domain.File) error {
// delete file
if err := dao.FileDelete(ptr.transactionContext, file.FileId, domain.FileType(file.FileType)); err != nil {
return err
}
// delete table
if file.FileInfo.TableId > 0 {
if err := dao.TableDelete(ptr.transactionContext, file.FileInfo.TableId, domain.ExcelTable); err != nil {
return err
}
}
// delete log
if err := dao.LogDirectDelete(ptr.transactionContext, file.FileId, domain.VerifiedStepLog); err != nil {
return err
}
log.Logger.Info(fmt.Sprintf("[%v] 删除文件:%v 文件类型:%v", ctx.OperatorName, file.FileInfo.Name, file.FileType))
return nil
}