api_byte_lib.go
9.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
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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
package bytelib
import (
"fmt"
"github.com/beego/beego/v2/core/logs"
"gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/api"
"time"
)
// ApiByteLib 字库底层接口
type ApiByteLib struct {
api.BaseServiceGateway
}
func NewApiByteLib(host string) *ApiByteLib {
gt := api.NewBaseServiceGateway(host)
gt.ConnectTimeout = 360 * time.Second
gt.ReadWriteTimeout = 360 * time.Second
gt.Interceptor = func(msg string) {
//log.Logger.Info(msg)
logs.Debug(msg)
}
gt.ServiceName = "【字库核心】"
return &ApiByteLib{
BaseServiceGateway: gt,
}
}
// 加载数据
func (gateway ApiByteLib) LoadDataTable(param domain.ReqLoadDataTable) (*domain.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 domain.ReqEditDataTable) (*domain.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 &domain.DataEditDataTable{
DataLoadDataTable: *response,
}, nil
}
// SaveTable 保存校验文件 (文件地址)
func (gateway ApiByteLib) SaveTable(param domain.ReqSaveTable) (*domain.DataSaveTable, error) {
url := gateway.Host() + "/checkout-tables/save"
method := "post"
var data ResponseCheckoutTablesSave
var request = RequestCheckoutTablesSave{
OriginalTableId: fmt.Sprintf("%v", param.FileId),
FilePostfix: "xlsx",
ColumnSchemas: FieldsToColumnSchemas(param.Table.DataFields),
}
err := gateway.FastDoRequest(url, method, request, &data)
if err != nil {
return nil, err
}
var response = &domain.DataSaveTable{
Url: data.CheckoutTableUrl,
}
return response, nil
}
// GenerateTable 生成主表
func (gateway ApiByteLib) GenerateTable(param domain.ReqGenerateTable) (*domain.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 = domain.DataGenerateTable{
TableName: data.MasterTableName,
}
return &response, nil
}
// CopyTable 表复制
func (gateway ApiByteLib) CopyTable(param domain.ReqCopyTable) (*domain.DataCopyTable, error) {
var url string
method := "post"
var data TableAppendResponse
var request interface{}
var copyRequest = NewCopyTableRequest(param)
switch param.Table.TableType {
case domain.MainTable.ToString():
request = CopyMasterTableRequest{
MasterTableId: intToString(param.Table.TableId),
CopyTableRequest: copyRequest,
}
url = gateway.Host() + "/master-tables/copy"
case domain.SubTable.ToString():
copyRequest.DatabaseTableName = param.MainTable.SQLName // 分表复制时 传入主表的表名
request = CopyMasterTableRequest{
MasterTableId: intToString(param.Table.TableId),
CopyTableRequest: copyRequest,
}
url = gateway.Host() + "/master-tables/copy"
case domain.SideTable.ToString():
request = CopyReplicationTableRequest{
ReplicationTableId: intToString(param.Table.TableId),
CopyTableRequest: copyRequest,
}
url = gateway.Host() + "/replication-tables/copy"
}
err := gateway.FastDoRequest(url, method, request, &data)
if err != nil {
return nil, err
}
return &domain.DataCopyTable{}, nil
}
// AppendData 追加数据
func (gateway ApiByteLib) AppendData(param domain.ReqAppendData) (*domain.DataAppendData, error) {
var url string
method := "post"
var data TableAppendResponse
var request interface{}
var appendRequest = NewTableAppendRequest(param)
switch param.Table.TableType {
case domain.MainTable.ToString():
request = MasterTablesAppendRequest{
MasterTableId: intToString(param.Table.TableId),
TableAppendRequest: appendRequest,
}
url = gateway.Host() + "/master-tables/append"
case domain.SideTable.ToString():
request = ReplicationTablesAppendRequest{
ReplicationTableId: intToString(param.Table.TableId),
TableAppendRequest: appendRequest,
}
url = gateway.Host() + "/replication-tables/append"
}
err := gateway.FastDoRequest(url, method, request, &data)
if err != nil {
return nil, err
}
return &domain.DataAppendData{
AppendCount: data.AppendCount,
}, nil
}
// DeleteTable 表删除 (主表、副表、分表)
func (gateway ApiByteLib) DeleteTable(param domain.ReqDeleteTable) (*domain.DataDeleteTable, error) {
url := gateway.Host() + "/table/delete"
method := "post"
var data domain.DataDeleteTable
err := gateway.FastDoRequest(url, method, param, &data)
if err != nil {
return nil, err
}
return &data, nil
}
// CancelFile 表删除 (主表、副表、分表)
func (gateway ApiByteLib) CancelFile(param domain.ReqCancelFile) (*domain.DataCancelFile, error) {
url := gateway.Host() + "/table/cancel-file"
method := "post"
var data domain.DataCancelFile
err := gateway.FastDoRequest(url, method, param, &data)
if err != nil {
return nil, err
}
return &data, nil
}
// 表拆分
func (gateway ApiByteLib) SplitTable(param domain.ReqSplitTable) (*domain.DataSplitTable, error) {
var url string
method := "post"
var data TableAppendResponse
var request interface{}
var splitRequest = NewSplitTableRequest(param)
switch param.FromTable.TableType {
case domain.MainTable.ToString():
request = SplitMasterTableRequest{
MasterTableId: intToString(param.FromTable.TableId),
SplitTableRequest: splitRequest,
}
url = gateway.Host() + "/master-tables/split"
case domain.SideTable.ToString():
request = SplitReplicationTableRequest{
ReplicationTableId: intToString(param.FromTable.TableId),
SplitTableRequest: splitRequest,
}
url = gateway.Host() + "/replication-tables/split"
}
err := gateway.FastDoRequest(url, method, request, &data)
if err != nil {
return nil, err
}
return &domain.DataSplitTable{}, nil
}
// 更新表结构(分表)
// EditTableData 编辑、添加、删除表数据(副表)
func (gateway ApiByteLib) EditTableData(param domain.ReqEditTableData) (*domain.DataEditTableData, error) {
url := gateway.Host() + "/table/cancel-file"
method := "post"
var data domain.DataEditTableData
err := gateway.FastDoRequest(url, method, param, &data)
if err != nil {
return nil, err
}
return &data, nil
}
// FieldOptionalValues 字段可选值
func (gateway ApiByteLib) FieldOptionalValues(param domain.ReqFieldOptionalValues) (*domain.DataFieldOptionalValues, error) {
url := gateway.Host() + "/checkout-tables/filter-column-data"
method := "post"
var data CheckoutTablesFilterColumnDataResponse
request := NewCheckoutTablesFilterColumnDataRequest(param)
err := gateway.FastDoRequest(url, method, request, &data)
if err != nil {
return nil, err
}
var response = domain.DataFieldOptionalValues{
//TableName: data.MasterTableName,
Field: param.Field,
Values: data.ShowData,
Total: data.DataCount,
}
return &response, nil
}
func (gateway ApiByteLib) FormulasGenerate(param domain.ReqFormulasGenerate) (*domain.DataFormulasGenerate, error) {
url := gateway.Host() + "/formulas/generate"
method := "post"
var data FormulasGenerateResponse
request := NewFormulasGenerateRequest(param.QuerySet, param.Table, param.QueryComponents)
err := gateway.FastDoRequest(url, method, request, &data)
if err != nil {
return nil, err
}
var response = domain.DataFormulasGenerate{
FormulaName: data.FormulaName,
}
return &response, nil
}
func (gateway ApiByteLib) FormulasClear(param domain.ReqFormulasClear) (*domain.DataFormulasClear, error) {
url := gateway.Host() + "/formulas/clear"
method := "post"
var data FormulasGenerateResponse
request := FormulasClearRequest{
FormulaId: intToString(param.QuerySetId),
}
err := gateway.FastDoRequest(url, method, request, &data)
if err != nil {
return nil, err
}
var response = domain.DataFormulasClear{}
return &response, nil
}
func (gateway ApiByteLib) ShowBusinessDatabases(request ReqShowBusinessDatabases) (*DataShowBusinessDatabases, error) {
url := gateway.Host() + "/databases/show-business-databases"
method := "post"
var data DataShowBusinessDatabases
err := gateway.FastDoRequest(url, method, request, &data)
if err != nil {
return nil, err
}
return &data, nil
}
func (gateway ApiByteLib) ShowBusinessTables(request ReqShowBusinessTables) (*DataShowBusinessTables, error) {
url := gateway.Host() + "/databases/show-tables"
method := "post"
var data DataShowBusinessTables
err := gateway.FastDoRequest(url, method, request, &data)
if err != nil {
return nil, err
}
return &data, nil
}
func (gateway ApiByteLib) QueryBusinessTable(request ReqQueryBusinessTable) (*DataQueryBusinessTable, error) {
url := gateway.Host() + "/databases/query-table"
method := "post"
var data DataQueryBusinessTable
err := gateway.FastDoRequest(url, method, request, &data)
if err != nil {
return nil, err
}
return &data, nil
}