file_table_generate_main_table_service.go
2.3 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
53
54
55
56
57
58
59
60
61
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/domain/bytecore"
"gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/repository"
)
type GenerateMainTableService struct {
transactionContext *pgTransaction.TransactionContext
}
// GenerateTable 主表生成 【data-table】
func (ptr *GenerateMainTableService) GenerateTable(ctx *domain.Context, fileId int, tableName string) (interface{}, error) {
fileRepository, _ := repository.NewFileRepository(ptr.transactionContext)
file, err := fileRepository.FindOne(map[string]interface{}{"fileId": fileId})
if err != nil {
return nil, fmt.Errorf("文件不存在")
}
tableRepository, _ := repository.NewTableRepository(ptr.transactionContext)
table, err := tableRepository.FindOne(map[string]interface{}{"tableId": file.FileInfo.TableId})
if err != nil {
return nil, fmt.Errorf("文件未校验")
}
duplicateTable, err := tableRepository.FindOne(map[string]interface{}{"context": ctx, "tableName": tableName})
if err == nil && duplicateTable != nil {
return nil, fmt.Errorf("表名称重复")
}
mainTable := NewTable(domain.MainTable, tableName, table.DataFields, table.RowCount).WithContext(ctx)
_, err = tableRepository.Save(mainTable)
if err != nil {
return nil, err
}
// 日志
if err = FastLog(ptr.transactionContext, domain.CommonLog, mainTable.TableId, &GenerateMainTableLog{
LogEntry: domain.NewLogEntry(tableName, domain.MainTable.ToString(), domain.GenerateMainTable, ctx),
FileName: file.FileInfo.Name,
}); err != nil {
return nil, err
}
if _, err = ByteCore.GenerateTable(ctx, bytecore.ReqGenerateTable{FileId: fileId, FileUrl: file.FileInfo.Url, Table: table}); err != nil {
return nil, err
}
return struct{}{}, nil
}
func NewGenerateMainTableService(transactionContext *pgTransaction.TransactionContext) (*GenerateMainTableService, error) {
if transactionContext == nil {
return nil, fmt.Errorf("transactionContext参数不能为nil")
} else {
return &GenerateMainTableService{
transactionContext: transactionContext,
}, nil
}
}