bytelib.go
1.8 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
package bytecore
import "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/domain"
type ByteLibService interface {
LoadDataTable(param ReqLoadDataTable) (*DataLoadDataTable, error)
EditTable(param ReqEditDataTable) (*DataEditDataTable, error)
}
type (
ReqLoadDataTable struct {
FileId int
FileName string
Url string
Ext string
domain.Where
}
DataLoadDataTable struct {
FileId int `json:"fileId"`
DataFields []*Field `json:"dataFields"`
DataRows [][]string `json:"dataRows"`
Total int `json:"total"`
PageNumber int `json:"pageNumber"`
InValidCells []InValidCell `json:"inValidCells"`
}
Field struct {
// 索引序号
Index int `json:"index"`
// 名称
Name string `json:"name"`
// 对应数据库类型
Type string `json:"type"`
}
InValidCell struct {
X int `json:"x"`
Y int `json:"y"`
Error string `json:"error"`
}
)
// https://github.com/go-gota/gota 类似pandas的数据处理包
// https://github.com/gonum/gonum
func (table DataLoadDataTable) Filter(where domain.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.DataRows[begin:end]
} else {
data = table.DataRows[begin:]
}
}
return &DataLoadDataTable{
FileId: table.FileId,
DataFields: table.DataFields,
DataRows: data,
Total: table.Total,
PageNumber: where.PageNumber,
InValidCells: make([]InValidCell, 0),
}
}
type (
ReqEditDataTable struct {
FileId int
FileName string
Url string
Ext string
Fields []*Field
Action string
Params []interface{}
}
DataEditDataTable struct {
DataLoadDataTable
}
)