bytecore.go
5.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
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
package domain
type ByteLibService interface {
LoadDataTable(param ReqLoadDataTable) (*DataLoadDataTable, error)
EditTable(param ReqEditDataTable) (*DataEditDataTable, error)
SaveTable(param ReqSaveTable) (*DataSaveTable, error)
GenerateTable(ctx *Context, param ReqGenerateTable) (*DataGenerateTable, error)
CopyTable(param ReqCopyTable) (*DataCopyTable, error)
AppendData(param ReqAppendData) (*DataAppendData, error)
SplitTable(param ReqSplitTable) (*DataSplitTable, error)
DeleteTable(param ReqDeleteTable) (*DataDeleteTable, error)
CancelFile(param ReqCancelFile) (*DataCancelFile, error)
EditTableData(param ReqEditTableData) (*DataEditTableData, error)
FieldOptionalValues(param ReqFieldOptionalValues) (*DataFieldOptionalValues, error)
FormulasGenerate(param ReqFormulasGenerate) (*DataFormulasGenerate, error)
FormulasClear(param ReqFormulasClear) (*DataFormulasClear, error)
}
type (
ReqLoadDataTable struct {
FileId int `json:"file_id"`
FileType string `json:"file_type"`
FileName string `json:"file_name"`
Url string `json:"url"`
Ext string `json:"ext"`
Where
OriginalTableId string `json:"originalTableId"`
IsFromOriginalTable bool `json:"isFromOriginalTable"`
TableFileUrl string `json:"tableFileUrl"`
ColumnSchemas []ColumnSchema `json:"columnSchemas"`
SortParameters map[string]interface{} `json:"sortParameters"`
}
DataLoadDataTable struct {
FileId int `json:"objectId"`
ObjectType string `json:"objectType"`
TableType string `json:"tableType"`
Fields []*Field `json:"fields"`
Data [][]string `json:"data"`
Total int `json:"total"`
PageNumber int `json:"pageNumber"`
InValidCells []InValidCell `json:"inValidCells"`
}
QueryParameter struct {
ColumnName string `json:"columnName"`
ColumnContents []string `json:"columnContents"`
IsContainContent bool `json:"isContainContent"`
}
InValidCell struct {
Col string `json:"col"`
Index int `json:"index"`
Err string `json:"err"`
}
)
func NewInValidCells(fields Fields, mapData []map[string]string) []InValidCell {
inValidCells := make([]InValidCell, 0)
mapField := fields.ToMap()
for index, m := range mapData {
for k, v := range m {
if field, ok := mapField[k]; ok && len(v) > 0 {
_, err := ValueToType(v, field.SQLType)
if err != nil {
inValidCells = append(inValidCells, InValidCell{
Col: field.Name,
Index: index,
Err: err.Error(),
})
}
}
}
}
return inValidCells
}
// https://github.com/go-gota/gota 类似pandas的数据处理包
// https://github.com/gonum/gonum
func (table DataLoadDataTable) Filter(where Where) *DataLoadDataTable {
begin := (where.PageNumber - 1) * where.PageSize
if begin < 0 {
begin = 0
}
end := begin + where.PageSize
data := make([][]string, 0)
if begin < table.Total {
if end < table.Total {
data = table.Data[begin:end]
} else {
data = table.Data[begin:]
}
}
return &DataLoadDataTable{
FileId: table.FileId,
Fields: table.Fields,
Data: data,
Total: table.Total,
PageNumber: where.PageNumber,
InValidCells: make([]InValidCell, 0),
}
}
type (
ReqEditDataTable struct {
FileId int `json:"fileId"`
PageNumber int `json:"pageNumber"`
PageSize int `json:"pageSize"`
Fields []*Field `json:"fields"`
ProcessFields []*Field `json:"processFields"`
Action string `json:"action"`
Params map[string]interface{} `json:"params"`
HeaderRow int `json:"headerRow"`
}
DataEditDataTable struct {
DataLoadDataTable
}
)
type (
ReqSaveTable struct {
FileId int
Table *Table
}
DataSaveTable struct {
Url string `json:"url"`
}
)
type (
ReqGenerateTable struct {
FileId int
FileUrl string
Table *Table
}
DataGenerateTable struct {
TableName string
}
)
type (
ReqCopyTable struct {
MainTable *Table
Table *Table
CopyToTable *Table
}
DataCopyTable struct {
}
)
type (
ReqAppendData struct {
FileId int
FileUrl string
Table *Table
From []*Field
To []*Field
ExcelTable *Table
}
DataAppendData struct {
AppendCount int `json:"appendCount"`
}
)
type (
ReqDeleteTable struct {
}
DataDeleteTable struct {
}
)
type (
ReqSplitTable struct {
FromTable *Table
ToSubTable *Table
}
DataSplitTable struct {
}
)
type (
ReqFieldOptionalValues struct {
FileId int
Field *Field
Where Where
Match string
}
DataFieldOptionalValues struct {
Field *Field
Values []string
Total int
}
)
type (
ReqCancelFile struct {
}
DataCancelFile struct {
}
)
type (
ReqEditTableData struct {
}
DataEditTableData struct {
}
)
type ColumnSchema struct {
ColumnName string `json:"columnName"`
ColumnType string `json:"columnType"`
ColumnSqlFriendlyName string `json:"columnSqlFriendlyName"`
}
func ToFields(fields []*Field) []*Field {
result := make([]*Field, 0)
for _, f := range fields {
result = append(result, &Field{
Index: f.Index,
Name: f.Name,
SQLType: f.SQLType,
})
}
return result
}
type (
ReqFormulasGenerate struct {
QuerySet *QuerySet
Table *Table
QueryComponents []*QueryComponent
QuerySetService interface{}
Context interface{}
}
DataFormulasGenerate struct {
FormulaName string `json:"formulaName"`
}
)
type (
ReqFormulasClear struct {
QuerySetId int
}
DataFormulasClear struct {
}
)