api_byte_lib.go
4.5 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
package bytelib
import (
"fmt"
"github.com/beego/beego/v2/core/logs"
"gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/domain/bytecore"
"gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/api"
"time"
)
// ApiByteLib 字库底层接口
type ApiByteLib struct {
api.BaseServiceGateway
baseUrL string
}
func NewApiByteLib(host string) *ApiByteLib {
gt := api.NewBaseServiceGateway(host)
gt.ConnectTimeout = 10 * time.Second
gt.ReadWriteTimeout = 10 * time.Second
gt.Interceptor = func(msg string) {
//log.Logger.Info(msg)
logs.Debug(msg)
}
return &ApiByteLib{
BaseServiceGateway: gt,
}
}
// 加载数据
func (gateway ApiByteLib) LoadDataTable(param bytecore.ReqLoadDataTable) (*bytecore.DataLoadDataTable, error) {
url := gateway.Host() + "/checkout-tables/query"
method := "post"
var data DataCheckoutTables
request := NewRequestCheckoutTablesQuery(param)
err := gateway.FastDoRequest(url, method, request, &data)
if err != nil {
return nil, err
}
response := ToDataLoadDataTable(data)
return response, nil
}
// EditTable 编辑表格
func (gateway ApiByteLib) EditTable(param bytecore.ReqEditDataTable) (*bytecore.DataEditDataTable, error) {
url := gateway.Host() + "/checkout-tables/pre-proccess"
method := "post"
var data DataCheckoutTables
request := NewRequestCheckoutTablesPreProccess(param)
err := gateway.FastDoRequest(url, method, request, &data)
if err != nil {
return nil, err
}
response := ToDataLoadDataTable(data)
return &bytecore.DataEditDataTable{
DataLoadDataTable: *response,
}, nil
}
// SaveTable 保存校验文件 (文件地址)
func (gateway ApiByteLib) SaveTable(param bytecore.ReqSaveTable) (*bytecore.DataSaveTable, error) {
url := gateway.Host() + "/checkout-tables/save"
method := "post"
var data ResponseCheckoutTablesSave
var request = RequestCheckoutTablesSave{
OriginalTableId: fmt.Sprintf("%v", param.FileId),
}
err := gateway.FastDoRequest(url, method, request, &data)
if err != nil {
return nil, err
}
var response = &bytecore.DataSaveTable{
Url: data.CheckoutTableUrl,
}
return response, nil
}
// GenerateTable 生成主表
func (gateway ApiByteLib) GenerateTable(param bytecore.ReqGenerateTable) (*bytecore.DataGenerateTable, error) {
url := gateway.Host() + "/checkout-tables/generate-master-table"
method := "post"
var data DataCheckoutTablesGenerateMasterTable
request := NewRequestCheckoutTablesGenerateMasterTable(param)
err := gateway.FastDoRequest(url, method, request, &data)
if err != nil {
return nil, err
}
var response = bytecore.DataGenerateTable{
TableName: data.MasterTableName,
}
return &response, nil
}
// CopyTable 表复制
func (gateway ApiByteLib) CopyTable(param bytecore.ReqCopyTable) (*bytecore.DataCopyTable, error) {
url := gateway.Host() + "/table/copy"
method := "post"
var data bytecore.DataCopyTable
err := gateway.FastDoRequest(url, method, param, &data)
if err != nil {
return nil, err
}
return &data, nil
}
// AppendData 追加数据
func (gateway ApiByteLib) AppendData(param bytecore.ReqAppendData) (*bytecore.DataAppendData, error) {
url := gateway.Host() + "/table/append"
method := "post"
var data bytecore.DataAppendData
err := gateway.FastDoRequest(url, method, param, &data)
if err != nil {
return nil, err
}
return &data, nil
}
// DeleteTable 表删除 (主表、副表、分表)
func (gateway ApiByteLib) DeleteTable(param bytecore.ReqDeleteTable) (*bytecore.DataDeleteTable, error) {
url := gateway.Host() + "/table/delete"
method := "post"
var data bytecore.DataDeleteTable
err := gateway.FastDoRequest(url, method, param, &data)
if err != nil {
return nil, err
}
return &data, nil
}
// CancelFile 表删除 (主表、副表、分表)
func (gateway ApiByteLib) CancelFile(param bytecore.ReqCancelFile) (*bytecore.DataCancelFile, error) {
url := gateway.Host() + "/table/cancel-file"
method := "post"
var data bytecore.DataCancelFile
err := gateway.FastDoRequest(url, method, param, &data)
if err != nil {
return nil, err
}
return &data, nil
}
// 表拆分
// 更新表结构(分表)
// EditTableData 编辑、添加、删除表数据(副表)
func (gateway ApiByteLib) EditTableData(param bytecore.ReqEditTableData) (*bytecore.DataEditTableData, error) {
url := gateway.Host() + "/table/cancel-file"
method := "post"
var data bytecore.DataEditTableData
err := gateway.FastDoRequest(url, method, param, &data)
if err != nil {
return nil, err
}
return &data, nil
}