byte_core_service.go
6.0 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
package domainService
import (
"bytes"
"github.com/beego/beego/v2/client/httplib"
"gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/constant"
"gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/api/bytelib"
"gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/excel"
)
type ByteCoreService struct {
TempDataTable map[int]*domain.DataLoadDataTable
}
var ByteCore domain.ByteLibService = &WrapByteCoreService{} //&ByteCoreService{}
var _ domain.ByteLibService = (*ByteCoreService)(nil)
func (ptr *ByteCoreService) LoadDataTable(param domain.ReqLoadDataTable) (*domain.DataLoadDataTable, error) {
if v, ok := ptr.load(param.FileId); ok {
return v.Filter(param.Where), nil
}
file, err := httplib.Get(param.Url).Bytes()
if err != nil {
return nil, err
}
reader := bytes.NewReader(file)
var importer *excel.Importer
if param.Ext == domain.XLSX {
importer = excel.NewExcelImport(&excel.XLXSReader{})
} else if param.Ext == domain.XLS {
importer = excel.NewExcelImport(&excel.XLSReader{})
}
data, err := importer.OpenExcelFromIoReader(reader)
if err != nil {
return nil, err
}
cols := importer.Reader().Header().Columns
var response = &domain.DataLoadDataTable{
FileId: param.FileId,
Fields: columnToField(cols),
Data: data,
Total: len(data),
PageNumber: param.PageNumber,
InValidCells: make([]domain.InValidCell, 0),
}
ptr.save(param.FileId, response)
return response.Filter(param.Where), nil
}
func (ptr *ByteCoreService) EditTable(param domain.ReqEditDataTable) (*domain.DataEditDataTable, error) {
apiByteLib := bytelib.NewApiByteLib(constant.BYTE_CORE_HOST)
return apiByteLib.EditTable(param)
}
func (ptr *ByteCoreService) save(fileId int, dataTable *domain.DataLoadDataTable) {
// Once
if ptr.TempDataTable == nil {
ptr.TempDataTable = make(map[int]*domain.DataLoadDataTable)
}
ptr.TempDataTable[fileId] = dataTable
}
func (ptr *ByteCoreService) load(fileId int) (*domain.DataLoadDataTable, bool) {
v, ok := ptr.TempDataTable[fileId]
return v, ok
}
func columnToField(cols []string) []*domain.Field {
var fields []*domain.Field
for i, col := range cols {
fields = append(fields, &domain.Field{
Name: col,
Index: i + 1,
SQLType: domain.String.ToString(),
})
}
return fields
}
func (ptr *ByteCoreService) SaveTable(param domain.ReqSaveTable) (*domain.DataSaveTable, error) {
apiByteLib := bytelib.NewApiByteLib(constant.BYTE_CORE_HOST)
return apiByteLib.SaveTable(param)
}
func (ptr *ByteCoreService) GenerateTable(ctx *domain.Context, param domain.ReqGenerateTable) (*domain.DataGenerateTable, error) {
apiByteLib := bytelib.NewApiByteLib(constant.BYTE_CORE_HOST)
return apiByteLib.GenerateTable(param)
}
func (ptr *ByteCoreService) CopyTable(param domain.ReqCopyTable) (*domain.DataCopyTable, error) {
apiByteLib := bytelib.NewApiByteLib(constant.BYTE_CORE_HOST)
return apiByteLib.CopyTable(param)
}
func (ptr *ByteCoreService) AppendData(param domain.ReqAppendData) (*domain.DataAppendData, error) {
apiByteLib := bytelib.NewApiByteLib(constant.BYTE_CORE_HOST)
return apiByteLib.AppendData(param)
}
func (ptr *ByteCoreService) DeleteTable(param domain.ReqDeleteTable) (*domain.DataDeleteTable, error) {
apiByteLib := bytelib.NewApiByteLib(constant.BYTE_CORE_HOST)
return apiByteLib.DeleteTable(param)
}
func (ptr *ByteCoreService) CancelFile(param domain.ReqCancelFile) (*domain.DataCancelFile, error) {
apiByteLib := bytelib.NewApiByteLib(constant.BYTE_CORE_HOST)
return apiByteLib.CancelFile(param)
}
func (ptr *ByteCoreService) EditTableData(param domain.ReqEditTableData) (*domain.DataEditTableData, error) {
apiByteLib := bytelib.NewApiByteLib(constant.BYTE_CORE_HOST)
return apiByteLib.EditTableData(param)
}
func (ptr *ByteCoreService) SplitTable(param domain.ReqSplitTable) (*domain.DataSplitTable, error) {
apiByteLib := bytelib.NewApiByteLib(constant.BYTE_CORE_HOST)
return apiByteLib.SplitTable(param)
}
func (ptr *ByteCoreService) FieldOptionalValues(param domain.ReqFieldOptionalValues) (*domain.DataFieldOptionalValues, error) {
apiByteLib := bytelib.NewApiByteLib(constant.BYTE_CORE_HOST)
return apiByteLib.FieldOptionalValues(param)
}
func (ptr *ByteCoreService) FormulasGenerate(param domain.ReqFormulasGenerate) (*domain.DataFormulasGenerate, error) {
apiByteLib := bytelib.NewApiByteLib(constant.BYTE_CORE_HOST)
//if param.QuerySet.Type == domain.CalculateItem.ToString() {
// if err := starrocks.Exec(starrocks.DB,
// starrocks.CreateViewSql(param.Table.SQLName, param.Table.DataFields,
// starrocks.CalculateItemViewSql(¶m.QueryComponents[0].Formula.FieldExpr),
// )); err != nil {
// return nil, err
// }
// return &domain.DataFormulasGenerate{}, nil
//}
//if param.QuerySet.Type == domain.CalculateTable.ToString() {
// if err := starrocks.Exec(starrocks.DB,
// starrocks.CreateViewSql(param.Table.SQLName, param.Table.DataFields,
// starrocks.CalculateTableViewSql(param.QueryComponents[0].MasterTable.SQLName, ¶m.QueryComponents[0].Aggregation.Aggregation),
// )); err != nil {
// return nil, err
// }
// return &domain.DataFormulasGenerate{}, nil
//}
return apiByteLib.FormulasGenerate(param)
}
func (ptr *ByteCoreService) FormulasClear(param domain.ReqFormulasClear) (*domain.DataFormulasClear, error) {
apiByteLib := bytelib.NewApiByteLib(constant.BYTE_CORE_HOST)
return apiByteLib.FormulasClear(param)
}
//////////////
// 字库核心
//////////////
func CreateByteCoreService() (domain.ByteLibService, error) {
return ByteCore, nil
}
type WrapByteCoreService struct {
ByteCoreService
}
func (ptr *WrapByteCoreService) LoadDataTable(param domain.ReqLoadDataTable) (*domain.DataLoadDataTable, error) {
apiByteLib := bytelib.NewApiByteLib(constant.BYTE_CORE_HOST)
return apiByteLib.LoadDataTable(param)
}
//func (ptr *WrapByteCoreService) GenerateTable(ctx *domain.Context, param bytecore.ReqGenerateTable) (*bytecore.DataGenerateTable, error) {
// return nil, nil
//}