作者 yangfu

refactor: optimize table query

正在显示 60 个修改的文件 包含 1418 行增加167 行删除
@@ -27,4 +27,6 @@ _testmain.go @@ -27,4 +27,6 @@ _testmain.go
27 app.log 27 app.log
28 go.sum 28 go.sum
29 lastupdate.tmp 29 lastupdate.tmp
30 -*.log  
  30 +*.log
  31 +
  32 +public/*
@@ -139,16 +139,14 @@ @@ -139,16 +139,14 @@
139 - [ ] 表数据自定义查询 /table/preview where conditions 升序、降序 包含、不包含 139 - [ ] 表数据自定义查询 /table/preview where conditions 升序、降序 包含、不包含
140 - [ ] 表数据字段可选值搜索 /table/field-optional 文本匹配 140 - [ ] 表数据字段可选值搜索 /table/field-optional 文本匹配
141 - [ ] 表数据更新、添加、删除 /table/row-data-mutation 141 - [ ] 表数据更新、添加、删除 /table/row-data-mutation
142 -- [ ] 表数据导出 142 +- [ ] 表数据导出 /table/export-table
143 143
144 ## 数据验证 144 ## 数据验证
145 145
146 -- [ ] 文件验证 /data/edit-data-table 146 +- [] 文件验证 /data/edit-data-table
147 147
148 ## 底层字库接口 148 ## 底层字库接口
149 149
150 -- [ ] 表格编辑  
151 -  
152 ```json 150 ```json
153 { 151 {
154 "file": {}, 152 "file": {},
@@ -157,7 +155,8 @@ @@ -157,7 +155,8 @@
157 "params": ["产品名2"] 155 "params": ["产品名2"]
158 } 156 }
159 ``` 157 ```
160 - 158 +- [ ] 数据预览
  159 +- [ ] 表格编辑
161 - [ ] 保存校验文件 (文件地址) 160 - [ ] 保存校验文件 (文件地址)
162 - [ ] 生成主表 161 - [ ] 生成主表
163 - [ ] 表复制 162 - [ ] 表复制
@@ -165,4 +164,10 @@ @@ -165,4 +164,10 @@
165 - [ ] 表删除 (主表、副表、分表) 164 - [ ] 表删除 (主表、副表、分表)
166 - [ ] 表拆分 165 - [ ] 表拆分
167 - [ ] 更新表结构(分表) 166 - [ ] 更新表结构(分表)
168 -- [ ] 编辑、添加、删除表数据(副表)  
  167 +- [ ] 编辑、添加、删除表数据(副表)
  168 +- [ ] 取消校验
  169 +
  170 +## 定时作业
  171 +
  172 +- 隔天清理校验中的文件
  173 +- 隔天清理public临时文件
  1 +/*1.初始化索引*/
  2 +
  3 +/*files*/
  4 +CREATE INDEX IF NOT EXISTS idx_files_company_id_file_type ON metadata.files USING btree((context->>'companyId'),file_type);
  5 +CREATE INDEX IF NOT EXISTS idx_files_source_file_id ON metadata.files USING btree(source_file_id);
  6 +
  7 +/*tables*/
  8 +CREATE INDEX IF NOT EXISTS idx_tables_company_id_table_type ON metadata.tables USING btree((context->>'companyId'),table_type);
  9 +CREATE INDEX IF NOT EXISTS idx_tables_parent_id ON metadata.tables USING btree(parent_id);
  10 +
  11 +/*logs*/
  12 +CREATE INDEX IF NOT EXISTS idx_logs_company_id_log_type_source_id ON metadata.logs USING btree((context->>'companyId'),log_type,source_id);
  13 +CREATE INDEX IF NOT EXISTS idx_logs_company_id_object_name ON metadata.logs USING btree((context->>'companyId'),object_name);
  14 +CREATE INDEX IF NOT EXISTS idx_logs_company_id_object_type ON metadata.logs USING btree((context->>'companyId'),object_type);
  15 +CREATE INDEX IF NOT EXISTS idx_logs_company_id_operation_type ON metadata.logs USING btree((context->>'companyId'),operation_type);
  16 +CREATE INDEX IF NOT EXISTS idx_logs_company_id_content ON metadata.logs USING btree((context->>'companyId'),content);
  17 +CREATE INDEX IF NOT EXISTS idx_logs_company_id_operator_name ON metadata.logs USING btree((context->>'companyId'),operator_name);
  18 +CREATE INDEX IF NOT EXISTS idx_logs_company_id_created_at ON metadata.logs USING btree((context->>'companyId'),created_at);
  19 +
  20 +/*mapping_rules*/
  21 +CREATE INDEX IF NOT EXISTS idx_mapping_rules_company_id_table_id_file_id ON metadata.mapping_rules USING btree((context->>'companyId'),table_id,file_id);
@@ -45,6 +45,7 @@ require ( @@ -45,6 +45,7 @@ require (
45 golang.org/x/tools v0.1.5 // indirect 45 golang.org/x/tools v0.1.5 // indirect
46 google.golang.org/protobuf v1.28.0 // indirect 46 google.golang.org/protobuf v1.28.0 // indirect
47 gorm.io/driver/mysql v1.3.6 47 gorm.io/driver/mysql v1.3.6
  48 + gorm.io/driver/postgres v1.3.9
48 gorm.io/gorm v1.23.8 49 gorm.io/gorm v1.23.8
49 ) 50 )
50 51
@@ -16,6 +16,8 @@ import ( @@ -16,6 +16,8 @@ import (
16 _ "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/port/beego" 16 _ "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/port/beego"
17 ) 17 )
18 18
  19 +const Version = "v1.0.1"
  20 +
19 func main() { 21 func main() {
20 defer func() { 22 defer func() {
21 if r := recover(); r != nil { 23 if r := recover(); r != nil {
@@ -31,6 +33,8 @@ func main() { @@ -31,6 +33,8 @@ func main() {
31 } 33 }
32 34
33 time.Sleep(time.Second) 35 time.Sleep(time.Second)
  36 + log.Logger.Info("Service:" + constant.SERVICE_NAME)
  37 + log.Logger.Info("Version:" + Version)
34 log.Logger.Info("server start!") 38 log.Logger.Info("server start!")
35 web.Run() 39 web.Run()
36 log.Logger.Info("server stop!") 40 log.Logger.Info("server stop!")
@@ -13,7 +13,7 @@ func FastLog(transactionContext application.TransactionContext, logType domain.L @@ -13,7 +13,7 @@ func FastLog(transactionContext application.TransactionContext, logType domain.L
13 return logService.Log(logType, sourceId, logEntry) 13 return logService.Log(logType, sourceId, logEntry)
14 } 14 }
15 15
16 -func CreateLoadDataTableService(transactionContext application.TransactionContext) (domain.LoadDataTableService, error) { 16 +func CreateLoadDataTableService(transactionContext application.TransactionContext) (domain.PreviewDataTableService, error) {
17 return domainService.NewLoadDataTableService(transactionContext.(*pg.TransactionContext)) 17 return domainService.NewLoadDataTableService(transactionContext.(*pg.TransactionContext))
18 } 18 }
19 19
  1 +package factory
  2 +
  3 +import (
  4 + "github.com/linmadan/egglib-go/core/application"
  5 + "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/domain"
  6 + "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/starrocks"
  7 +)
  8 +
  9 +func FastError(err error) error {
  10 + return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  11 +}
  12 +
  13 +func FastDataTable(options starrocks.QueryOptions) (*domain.DataTable, error) {
  14 + var err error
  15 + // 待优化分批下载,压缩
  16 + var dataTable *domain.DataTable
  17 + dataTable, err = starrocks.Query(options, starrocks.WrapQueryFuncWithDB(starrocks.DB))
  18 + if err != nil {
  19 + return nil, err
  20 + }
  21 +
  22 + dataTable.Total, err = starrocks.WrapQueryCountWithDB(options, starrocks.DB)()
  23 + if err != nil {
  24 + return nil, err
  25 + }
  26 + return dataTable, nil
  27 +}
  1 +package command
  2 +
  3 +import (
  4 + "fmt"
  5 + "reflect"
  6 + "strings"
  7 +
  8 + "github.com/beego/beego/v2/core/validation"
  9 +)
  10 +
  11 +type CancelVerifyingFileCommand struct {
  12 + // 文件ID
  13 + FileId int `cname:"文件ID" json:"fileId" valid:"Required"`
  14 +}
  15 +
  16 +func (cmd *CancelVerifyingFileCommand) Valid(validation *validation.Validation) {
  17 +
  18 +}
  19 +
  20 +func (cmd *CancelVerifyingFileCommand) ValidateCommand() error {
  21 + valid := validation.Validation{}
  22 + b, err := valid.Valid(cmd)
  23 + if err != nil {
  24 + return err
  25 + }
  26 + if !b {
  27 + elem := reflect.TypeOf(cmd).Elem()
  28 + for _, validErr := range valid.Errors {
  29 + field, isExist := elem.FieldByName(validErr.Field)
  30 + if isExist {
  31 + return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1))
  32 + } else {
  33 + return fmt.Errorf(validErr.Message)
  34 + }
  35 + }
  36 + }
  37 + return nil
  38 +}
@@ -2,7 +2,7 @@ package command @@ -2,7 +2,7 @@ package command
2 2
3 import ( 3 import (
4 "fmt" 4 "fmt"
5 - "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/application/file/dto" 5 + "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/domain"
6 "reflect" 6 "reflect"
7 "strings" 7 "strings"
8 8
@@ -11,11 +11,11 @@ import ( @@ -11,11 +11,11 @@ import (
11 11
12 type FlushDataTableCommand struct { 12 type FlushDataTableCommand struct {
13 // 文件ID 13 // 文件ID
14 - FileId int `cname:"文件ID" json:"fileId" valid:"Required"` 14 + FileId int `cname:"文件ID" json:"objectId" valid:"Required"`
15 // 记录数 15 // 记录数
16 RowCount int `cname:"记录数" json:"rowCount" valid:"Required"` 16 RowCount int `cname:"记录数" json:"rowCount" valid:"Required"`
17 // 数据列 17 // 数据列
18 - DataFields []*dto.Field `cname:"数据列" json:"dataFields" valid:"Required"` 18 + DataFields []*domain.Field `cname:"数据列" json:"fields" valid:"Required"`
19 } 19 }
20 20
21 func (flushDataTableCommand *FlushDataTableCommand) Valid(validation *validation.Validation) { 21 func (flushDataTableCommand *FlushDataTableCommand) Valid(validation *validation.Validation) {
@@ -11,7 +11,7 @@ import ( @@ -11,7 +11,7 @@ import (
11 11
12 type LoadDataTableCommand struct { 12 type LoadDataTableCommand struct {
13 // 文件ID 13 // 文件ID
14 - FileId int `cname:"文件ID" json:"fileId" valid:"Required"` 14 + FileId int `cname:"文件ID" json:"objectId" valid:"Required"`
15 // 页号 15 // 页号
16 //PageNumber int `cname:"页号" json:"pageNumber"` 16 //PageNumber int `cname:"页号" json:"pageNumber"`
17 // 页号 17 // 页号
@@ -12,6 +12,8 @@ type FileDto struct { @@ -12,6 +12,8 @@ type FileDto struct {
12 Name string `json:"name"` 12 Name string `json:"name"`
13 // 文件地址 13 // 文件地址
14 Url string `json:"url"` 14 Url string `json:"url"`
  15 + // 文件类型
  16 + FileType string `json:"fileType"`
15 // 创建时间 17 // 创建时间
16 Time string `json:"time"` 18 Time string `json:"time"`
17 } 19 }
@@ -20,5 +22,6 @@ func (d *FileDto) Load(f *domain.File) { @@ -20,5 +22,6 @@ func (d *FileDto) Load(f *domain.File) {
20 d.FileId = f.FileId 22 d.FileId = f.FileId
21 d.Name = f.FileInfo.Name 23 d.Name = f.FileInfo.Name
22 d.Url = f.FileInfo.Url 24 d.Url = f.FileInfo.Url
  25 + d.FileType = f.FileType
23 d.Time = xtime.New(f.CreatedAt).Local().Format("2006-01-02 15:04:05") 26 d.Time = xtime.New(f.CreatedAt).Local().Format("2006-01-02 15:04:05")
24 } 27 }
@@ -7,8 +7,8 @@ import ( @@ -7,8 +7,8 @@ import (
7 "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/domain" 7 "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/domain"
8 ) 8 )
9 9
10 -// 加载表格数据  
11 -func (fileService *FileService) LoadDataTable(ctx *domain.Context, loadDataTableCommand *command.LoadDataTableCommand) (interface{}, error) { 10 +// FilePreview 加载表格数据
  11 +func (fileService *FileService) FilePreview(ctx *domain.Context, loadDataTableCommand *command.LoadDataTableCommand) (interface{}, error) {
12 if err := loadDataTableCommand.ValidateCommand(); err != nil { 12 if err := loadDataTableCommand.ValidateCommand(); err != nil {
13 return nil, application.ThrowError(application.ARG_ERROR, err.Error()) 13 return nil, application.ThrowError(application.ARG_ERROR, err.Error())
14 } 14 }
@@ -24,7 +24,7 @@ func (fileService *FileService) LoadDataTable(ctx *domain.Context, loadDataTable @@ -24,7 +24,7 @@ func (fileService *FileService) LoadDataTable(ctx *domain.Context, loadDataTable
24 }() 24 }()
25 25
26 loadDataTableService, _ := factory.CreateLoadDataTableService(transactionContext) 26 loadDataTableService, _ := factory.CreateLoadDataTableService(transactionContext)
27 - data, err := loadDataTableService.Load(ctx, loadDataTableCommand.FileId, loadDataTableCommand.Where) 27 + data, err := loadDataTableService.Preview(ctx, loadDataTableCommand.FileId, loadDataTableCommand.Where)
28 if err != nil { 28 if err != nil {
29 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 29 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
30 } 30 }
@@ -37,7 +37,7 @@ func (fileService *FileService) LoadDataTable(ctx *domain.Context, loadDataTable @@ -37,7 +37,7 @@ func (fileService *FileService) LoadDataTable(ctx *domain.Context, loadDataTable
37 return data, nil 37 return data, nil
38 } 38 }
39 39
40 -// 编辑表格数据 40 +// EditDataTable 编辑表格数据
41 func (fileService *FileService) EditDataTable(ctx *domain.Context, editDataTableCommand *command.EditDataTableCommand) (interface{}, error) { 41 func (fileService *FileService) EditDataTable(ctx *domain.Context, editDataTableCommand *command.EditDataTableCommand) (interface{}, error) {
42 if err := editDataTableCommand.ValidateCommand(); err != nil { 42 if err := editDataTableCommand.ValidateCommand(); err != nil {
43 return nil, application.ThrowError(application.ARG_ERROR, err.Error()) 43 return nil, application.ThrowError(application.ARG_ERROR, err.Error())
@@ -59,7 +59,7 @@ func (fileService *FileService) EditDataTable(ctx *domain.Context, editDataTable @@ -59,7 +59,7 @@ func (fileService *FileService) EditDataTable(ctx *domain.Context, editDataTable
59 return struct{}{}, nil 59 return struct{}{}, nil
60 } 60 }
61 61
62 -// 持久化表格数据 62 +// FlushDataTable 持久化表格数据
63 func (fileService *FileService) FlushDataTable(ctx *domain.Context, flushDataTableCommand *command.FlushDataTableCommand) (interface{}, error) { 63 func (fileService *FileService) FlushDataTable(ctx *domain.Context, flushDataTableCommand *command.FlushDataTableCommand) (interface{}, error) {
64 if err := flushDataTableCommand.ValidateCommand(); err != nil { 64 if err := flushDataTableCommand.ValidateCommand(); err != nil {
65 return nil, application.ThrowError(application.ARG_ERROR, err.Error()) 65 return nil, application.ThrowError(application.ARG_ERROR, err.Error())
@@ -79,7 +79,7 @@ func (fileService *FileService) FlushDataTable(ctx *domain.Context, flushDataTab @@ -79,7 +79,7 @@ func (fileService *FileService) FlushDataTable(ctx *domain.Context, flushDataTab
79 for _, f := range flushDataTableCommand.DataFields { 79 for _, f := range flushDataTableCommand.DataFields {
80 fields = append(fields, &domain.Field{ 80 fields = append(fields, &domain.Field{
81 Name: f.Name, 81 Name: f.Name,
82 - SQLType: f.Type, 82 + SQLType: f.SQLType,
83 }) 83 })
84 } 84 }
85 if _, err := flushDataTableService.Flush(ctx, flushDataTableCommand.FileId, &domain.Table{ 85 if _, err := flushDataTableService.Flush(ctx, flushDataTableCommand.FileId, &domain.Table{
@@ -94,7 +94,7 @@ func (fileService *FileService) FlushDataTable(ctx *domain.Context, flushDataTab @@ -94,7 +94,7 @@ func (fileService *FileService) FlushDataTable(ctx *domain.Context, flushDataTab
94 return struct{}{}, nil 94 return struct{}{}, nil
95 } 95 }
96 96
97 -// 生成主表 97 +// GenerateMainTable 生成主表
98 func (fileService *FileService) GenerateMainTable(ctx *domain.Context, generateMainTableCommand *command.GenerateMainTableCommand) (interface{}, error) { 98 func (fileService *FileService) GenerateMainTable(ctx *domain.Context, generateMainTableCommand *command.GenerateMainTableCommand) (interface{}, error) {
99 if err := generateMainTableCommand.ValidateCommand(); err != nil { 99 if err := generateMainTableCommand.ValidateCommand(); err != nil {
100 return nil, application.ThrowError(application.ARG_ERROR, err.Error()) 100 return nil, application.ThrowError(application.ARG_ERROR, err.Error())
@@ -121,7 +121,7 @@ func (fileService *FileService) GenerateMainTable(ctx *domain.Context, generateM @@ -121,7 +121,7 @@ func (fileService *FileService) GenerateMainTable(ctx *domain.Context, generateM
121 return struct{}{}, nil 121 return struct{}{}, nil
122 } 122 }
123 123
124 -// 生成主表 124 +// AppendDataToTable 追加数据
125 func (fileService *FileService) AppendDataToTable(ctx *domain.Context, cmd *command.AppendDataToTableCommand) (interface{}, error) { 125 func (fileService *FileService) AppendDataToTable(ctx *domain.Context, cmd *command.AppendDataToTableCommand) (interface{}, error) {
126 if err := cmd.ValidateCommand(); err != nil { 126 if err := cmd.ValidateCommand(); err != nil {
127 return nil, application.ThrowError(application.ARG_ERROR, err.Error()) 127 return nil, application.ThrowError(application.ARG_ERROR, err.Error())
@@ -9,6 +9,7 @@ import ( @@ -9,6 +9,7 @@ import (
9 "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/application/file/dto" 9 "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/application/file/dto"
10 "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/application/file/query" 10 "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/application/file/query"
11 "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/domain" 11 "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/domain"
  12 + "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/domain/bytecore"
12 "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/domainService" 13 "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/domainService"
13 "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/utils" 14 "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/utils"
14 "path/filepath" 15 "path/filepath"
@@ -210,7 +211,7 @@ func (fileService *FileService) RemoveFile(removeFileCommand *command.RemoveFile @@ -210,7 +211,7 @@ func (fileService *FileService) RemoveFile(removeFileCommand *command.RemoveFile
210 return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(removeFileCommand.FileId))) 211 return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(removeFileCommand.FileId)))
211 } 212 }
212 deleteFileService, _ := factory.CreateDeleteFileService(transactionContext) 213 deleteFileService, _ := factory.CreateDeleteFileService(transactionContext)
213 - err = deleteFileService.Delete(nil, file) 214 + err = deleteFileService.DeleteFiles(nil, file)
214 if err != nil { 215 if err != nil {
215 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 216 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
216 } 217 }
@@ -263,6 +264,48 @@ func (fileService *FileService) UpdateFile(updateFileCommand *command.UpdateFile @@ -263,6 +264,48 @@ func (fileService *FileService) UpdateFile(updateFileCommand *command.UpdateFile
263 } 264 }
264 } 265 }
265 266
  267 +// 取消校验中的文件
  268 +func (fileService *FileService) CancelVerifyingFile(ctx *domain.Context, cmd *command.CancelVerifyingFileCommand) (interface{}, error) {
  269 + if err := cmd.ValidateCommand(); err != nil {
  270 + return nil, application.ThrowError(application.ARG_ERROR, err.Error())
  271 + }
  272 + transactionContext, err := factory.CreateTransactionContext(nil)
  273 + if err != nil {
  274 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  275 + }
  276 + if err := transactionContext.StartTransaction(); err != nil {
  277 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  278 + }
  279 + defer func() {
  280 + transactionContext.RollbackTransaction()
  281 + }()
  282 +
  283 + _, file, err := factory.FastPgFile(transactionContext, cmd.FileId)
  284 + if err != nil {
  285 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  286 + }
  287 + if file.FileType != domain.TemporaryFile.ToString() {
  288 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "校验中的文件才允许取消")
  289 + }
  290 +
  291 + deleteFileService, _ := factory.CreateDeleteFileService(transactionContext)
  292 + err = deleteFileService.DeleteFiles(nil, file)
  293 + if err != nil {
  294 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  295 + }
  296 +
  297 + byteCore, _ := factory.CreateByteCoreService(transactionContext)
  298 + _, err = byteCore.CancelFile(bytecore.ReqCancelFile{})
  299 + if err != nil {
  300 + return nil, factory.FastError(err)
  301 + }
  302 +
  303 + if err := transactionContext.CommitTransaction(); err != nil {
  304 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  305 + }
  306 + return struct{}{}, nil
  307 +}
  308 +
266 func NewFileService(options map[string]interface{}) *FileService { 309 func NewFileService(options map[string]interface{}) *FileService {
267 newFileService := &FileService{} 310 newFileService := &FileService{}
268 return newFileService 311 return newFileService
@@ -87,26 +87,15 @@ func (mappingRuleService *MappingRuleService) GetMappingRule(getMappingRuleQuery @@ -87,26 +87,15 @@ func (mappingRuleService *MappingRuleService) GetMappingRule(getMappingRuleQuery
87 defer func() { 87 defer func() {
88 transactionContext.RollbackTransaction() 88 transactionContext.RollbackTransaction()
89 }() 89 }()
90 - var mappingRuleRepository domain.MappingRuleRepository  
91 - if value, err := factory.CreateMappingRuleRepository(map[string]interface{}{  
92 - "transactionContext": transactionContext,  
93 - }); err != nil {  
94 - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())  
95 - } else {  
96 - mappingRuleRepository = value  
97 - }  
98 - mappingRule, err := mappingRuleRepository.FindOne(map[string]interface{}{"mappingRuleId": getMappingRuleQuery.MappingRuleId}) 90 + _, mappingRule, err := factory.FastPgMappingRule(transactionContext, getMappingRuleQuery.MappingRuleId)
99 if err != nil { 91 if err != nil {
100 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 92 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
101 } 93 }
102 - if mappingRule == nil {  
103 - return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(getMappingRuleQuery.MappingRuleId)))  
104 - } else {  
105 - if err := transactionContext.CommitTransaction(); err != nil {  
106 - return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())  
107 - }  
108 - return mappingRule, nil 94 +
  95 + if err := transactionContext.CommitTransaction(); err != nil {
  96 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
109 } 97 }
  98 + return mappingRule, nil
110 } 99 }
111 100
112 // 返回匹配规则服务列表 101 // 返回匹配规则服务列表
  1 +package command
  2 +
  3 +import (
  4 + "fmt"
  5 + "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/domain"
  6 + "reflect"
  7 + "strings"
  8 +
  9 + "github.com/beego/beego/v2/core/validation"
  10 +)
  11 +
  12 +type FieldOptionalValuesCommand struct {
  13 + ObjectType string `cname:"对象类型" json:"objectType" valid:"Required"`
  14 + ObjectId int `cname:"对象Id标识" json:"objectId" valid:"Required"`
  15 + Field domain.Field `cname:"列" json:"field" valid:"Required"`
  16 + Match string `cname:"匹配内容" json:"match"`
  17 + PageNumber int `json:"pageNumber"`
  18 + PageSize int `json:"pageSize"`
  19 +}
  20 +
  21 +func (cmd *FieldOptionalValuesCommand) Valid(validation *validation.Validation) {
  22 +
  23 +}
  24 +
  25 +func (cmd *FieldOptionalValuesCommand) ValidateCommand() error {
  26 + valid := validation.Validation{}
  27 + b, err := valid.Valid(cmd)
  28 + if err != nil {
  29 + return err
  30 + }
  31 + if !b {
  32 + elem := reflect.TypeOf(cmd).Elem()
  33 + for _, validErr := range valid.Errors {
  34 + field, isExist := elem.FieldByName(validErr.Field)
  35 + if isExist {
  36 + return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1))
  37 + } else {
  38 + return fmt.Errorf(validErr.Message)
  39 + }
  40 + }
  41 + }
  42 + return nil
  43 +}
  1 +package command
  2 +
  3 +import (
  4 + "fmt"
  5 + "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/domain"
  6 + "reflect"
  7 + "strings"
  8 +
  9 + "github.com/beego/beego/v2/core/validation"
  10 +)
  11 +
  12 +type TablePreviewCommand struct {
  13 + // 表Id
  14 + TableId int `cname:"表Id" json:"objectId" valid:"Required"`
  15 +
  16 + Where domain.Where `json:"where"`
  17 +}
  18 +
  19 +func (cmd *TablePreviewCommand) Valid(validation *validation.Validation) {
  20 +
  21 +}
  22 +
  23 +func (cmd *TablePreviewCommand) ValidateCommand() error {
  24 + valid := validation.Validation{}
  25 + b, err := valid.Valid(cmd)
  26 + if err != nil {
  27 + return err
  28 + }
  29 + if !b {
  30 + elem := reflect.TypeOf(cmd).Elem()
  31 + for _, validErr := range valid.Errors {
  32 + field, isExist := elem.FieldByName(validErr.Field)
  33 + if isExist {
  34 + return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1))
  35 + } else {
  36 + return fmt.Errorf(validErr.Message)
  37 + }
  38 + }
  39 + }
  40 + return nil
  41 +}
  1 +package command
  2 +
  3 +import (
  4 + "fmt"
  5 + "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/domain"
  6 + "reflect"
  7 + "strings"
  8 +
  9 + "github.com/beego/beego/v2/core/validation"
  10 +)
  11 +
  12 +type DBTablePreviewCommand struct {
  13 + // 表Id
  14 + ObjectId int `cname:"表Id" json:"objectId" valid:"Required"`
  15 + //ObjectType string `json:"objectType"`
  16 + Where domain.Where `json:"where"`
  17 +}
  18 +
  19 +func (cmd *DBTablePreviewCommand) Valid(validation *validation.Validation) {
  20 +
  21 +}
  22 +
  23 +func (cmd *DBTablePreviewCommand) ValidateCommand() error {
  24 + valid := validation.Validation{}
  25 + b, err := valid.Valid(cmd)
  26 + if err != nil {
  27 + return err
  28 + }
  29 + if !b {
  30 + elem := reflect.TypeOf(cmd).Elem()
  31 + for _, validErr := range valid.Errors {
  32 + field, isExist := elem.FieldByName(validErr.Field)
  33 + if isExist {
  34 + return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1))
  35 + } else {
  36 + return fmt.Errorf(validErr.Message)
  37 + }
  38 + }
  39 + }
  40 + return nil
  41 +}
@@ -13,7 +13,7 @@ type TableDetailDto struct { @@ -13,7 +13,7 @@ type TableDetailDto struct {
13 ParentId int `json:"parentId"` 13 ParentId int `json:"parentId"`
14 // 主表字段 14 // 主表字段
15 MainTableFields []*domain.Field `json:"mainTableFields"` 15 MainTableFields []*domain.Field `json:"mainTableFields"`
16 - // 手动添加的列 16 + // 手动添加字段
17 ManualFields []*domain.Field `json:"manualFields"` 17 ManualFields []*domain.Field `json:"manualFields"`
18 // 数据列 18 // 数据列
19 Fields []*domain.Field `json:"fields"` 19 Fields []*domain.Field `json:"fields"`
  1 +package dto
  2 +
  3 +import "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/domain"
  4 +
  5 +type TablePreviewDto struct {
  6 + // 表Id
  7 + TableId int `json:"objectId"`
  8 + // 表Id
  9 + ObjectType string `json:"objectType"`
  10 + // 表类型 MainTable:主表 SideTable:副表 SubTable:分表 ExcelTable:Excel表
  11 + TableType string `json:"tableType"`
  12 + // 名称
  13 + Name string `json:"name"`
  14 + // 数据
  15 + *domain.DataTable
  16 +}
  17 +
  18 +func (d *TablePreviewDto) Load(m *domain.Table, dataTable *domain.DataTable, objectType string) *TablePreviewDto {
  19 + d.TableId = m.TableId
  20 + d.TableType = m.TableType
  21 + d.ObjectType = objectType
  22 + d.Name = m.Name
  23 + d.DataTable = &domain.DataTable{}
  24 + d.Fields = dataTable.MatchFields(m.Fields(true))
  25 + d.Data = dataTable.Data
  26 + d.Total = dataTable.Total
  27 + if len(d.Data) == 0 {
  28 + d.Data = make([][]string, 0)
  29 + }
  30 + return d
  31 +}
  1 +package service
  2 +
  3 +import (
  4 + "fmt"
  5 + "github.com/linmadan/egglib-go/core/application"
  6 + "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/application/factory"
  7 + "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/application/table/command"
  8 + "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/application/table/dto"
  9 + "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/domain"
  10 + "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/pg"
  11 + "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/starrocks"
  12 +)
  13 +
  14 +func (tableService *TableService) DBTablePreview(ctx *domain.Context, cmd *command.DBTablePreviewCommand) (interface{}, error) {
  15 + if err := cmd.ValidateCommand(); err != nil {
  16 + return nil, application.ThrowError(application.ARG_ERROR, err.Error())
  17 + }
  18 + transactionContext, err := factory.CreateTransactionContext(nil)
  19 + if err != nil {
  20 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  21 + }
  22 + if err := transactionContext.StartTransaction(); err != nil {
  23 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  24 + }
  25 + defer func() {
  26 + transactionContext.RollbackTransaction()
  27 + }()
  28 +
  29 + var table *domain.Table
  30 + var ok bool
  31 + table, ok = domain.DBTables[cmd.ObjectId]
  32 + if !ok {
  33 + return nil, factory.FastError(fmt.Errorf("表%v不存在", cmd.ObjectId))
  34 + }
  35 +
  36 + var options = starrocks.QueryOptions{
  37 + TableName: table.SQLName,
  38 + Select: table.Fields(true),
  39 + Context: ctx,
  40 + }
  41 + options.SetCondition(cmd.Where.Conditions)
  42 + options.SetOffsetLimit(cmd.Where.PageNumber, cmd.Where.PageSize)
  43 + var dataTable *domain.DataTable
  44 + switch cmd.ObjectId {
  45 + case domain.DBTableTableOperateLog.ToInt():
  46 + options.SetCondition([]domain.Condition{{
  47 + Field: &domain.Field{
  48 + SQLName: "log_type",
  49 + SQLType: domain.String.ToString(),
  50 + },
  51 + In: []interface{}{domain.CommonLog.ToString()},
  52 + }})
  53 + }
  54 +
  55 + dataTable, err = starrocks.Query(options, starrocks.WrapQueryFuncWithDB(pg.GormDB))
  56 + if err != nil {
  57 + return nil, factory.FastError(err)
  58 + }
  59 + dataTable.Total, err = starrocks.WrapQueryCountWithDB(options, pg.GormDB)()
  60 + if err != nil {
  61 + return nil, factory.FastError(err)
  62 + }
  63 +
  64 + response := (&dto.TablePreviewDto{}).Load(table, dataTable, domain.ObjectDBTable)
  65 + if err := transactionContext.CommitTransaction(); err != nil {
  66 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  67 + }
  68 + return response, nil
  69 +}
  1 +package service
  2 +
  3 +import (
  4 + "fmt"
  5 + "github.com/linmadan/egglib-go/core/application"
  6 + "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/application/factory"
  7 + "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/application/table/command"
  8 + "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/domain"
  9 + "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/excel"
  10 + "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/starrocks"
  11 + "time"
  12 +)
  13 +
  14 +func (tableService *TableService) ExportDataTable(ctx *domain.Context, cmd *command.TablePreviewCommand) (interface{}, error) {
  15 + if err := cmd.ValidateCommand(); err != nil {
  16 + return nil, application.ThrowError(application.ARG_ERROR, err.Error())
  17 + }
  18 + transactionContext, err := factory.CreateTransactionContext(nil)
  19 + if err != nil {
  20 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  21 + }
  22 + if err := transactionContext.StartTransaction(); err != nil {
  23 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  24 + }
  25 + defer func() {
  26 + transactionContext.RollbackTransaction()
  27 + }()
  28 +
  29 + // TODO:加锁 同一个用户同一个时间点只允许一次下载
  30 +
  31 + var table *domain.Table
  32 + var mainTable *domain.Table
  33 + _, table, err = factory.FastPgTable(transactionContext, cmd.TableId)
  34 + if err != nil {
  35 + return nil, factory.FastError(err)
  36 + }
  37 + if table.TableType == domain.SubTable.ToString() {
  38 + _, mainTable, err = factory.FastPgTable(transactionContext, cmd.TableId)
  39 + if err != nil {
  40 + return nil, factory.FastError(err)
  41 + }
  42 + } else {
  43 + mainTable = table
  44 + }
  45 + var options = starrocks.QueryOptions{
  46 + TableName: mainTable.SQLName,
  47 + Select: table.Fields(true),
  48 + }
  49 + // 待优化分批下载,压缩
  50 + var dataTable *domain.DataTable
  51 + dataTable, err = starrocks.Query(options, starrocks.DefaultQueryFunc)
  52 + if err != nil {
  53 + return nil, factory.FastError(err)
  54 + }
  55 + count, err := starrocks.QueryCount(options)
  56 + if err != nil {
  57 + return nil, factory.FastError(err)
  58 + }
  59 + filename := fmt.Sprintf("%v_%v.xlsx", table.Name, time.Now().Format("060102150405"))
  60 + path := fmt.Sprintf("public/%v", filename)
  61 + excelWriter := excel.NewXLXSWriterTo(domain.Fields(table.Fields(false)).NameArrayString(), dataTable.Data) //
  62 + if err = excelWriter.Save(path); err != nil {
  63 + return nil, factory.FastError(err)
  64 + }
  65 +
  66 + if err := transactionContext.CommitTransaction(); err != nil {
  67 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  68 + }
  69 + return map[string]interface{}{
  70 + "url": domain.DownloadUrl(filename),
  71 + "count": count,
  72 + }, nil
  73 +}
  1 +package service
  2 +
  3 +import (
  4 + "fmt"
  5 + "github.com/linmadan/egglib-go/core/application"
  6 + "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/application/factory"
  7 + "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/application/table/command"
  8 + "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/domain"
  9 + "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/pg"
  10 + "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/starrocks"
  11 + "gorm.io/gorm"
  12 +)
  13 +
  14 +func (tableService *TableService) FieldOptionalValues(ctx *domain.Context, cmd *command.FieldOptionalValuesCommand) (interface{}, error) {
  15 + if err := cmd.ValidateCommand(); err != nil {
  16 + return nil, application.ThrowError(application.ARG_ERROR, err.Error())
  17 + }
  18 + transactionContext, err := factory.CreateTransactionContext(nil)
  19 + if err != nil {
  20 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  21 + }
  22 + if err := transactionContext.StartTransaction(); err != nil {
  23 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  24 + }
  25 + defer func() {
  26 + transactionContext.RollbackTransaction()
  27 + }()
  28 + var dataTable *domain.DataTable
  29 + tableRepository, _, _ := factory.FastPgTable(transactionContext, 0)
  30 + var table *domain.Table
  31 + var db *gorm.DB
  32 + switch cmd.ObjectType {
  33 + case domain.ObjectFile:
  34 + table, err = tableRepository.FindOne(map[string]interface{}{"ctx": ctx, "tableId": cmd.ObjectId})
  35 + if err != nil {
  36 + return nil, factory.FastError(err)
  37 + }
  38 + case domain.ObjectMetaTable:
  39 + table, err = tableRepository.FindOne(map[string]interface{}{"ctx": ctx, "tableId": cmd.ObjectId})
  40 + if err != nil {
  41 + return nil, factory.FastError(err)
  42 + }
  43 + db = starrocks.DB
  44 + case domain.ObjectDBTable:
  45 + table = domain.DBTables[cmd.ObjectId]
  46 + db = pg.GormDB
  47 + }
  48 +
  49 + field, ok := table.MatchField(&cmd.Field)
  50 + if !ok {
  51 + return nil, factory.FastError(fmt.Errorf("列:%v 不存在", cmd.Field.Name))
  52 + }
  53 + options := &starrocks.QueryOptions{
  54 + TableName: table.SQLName,
  55 + Select: []*domain.Field{field},
  56 + Where: []starrocks.Condition{
  57 + {
  58 + Condition: domain.Condition{
  59 + Field: field,
  60 + Like: cmd.Match,
  61 + Order: "ASC",
  62 + },
  63 + Distinct: true,
  64 + },
  65 + },
  66 + }
  67 + options.SetOffsetLimit(cmd.PageNumber, cmd.PageSize)
  68 +
  69 + dataTable, err = starrocks.Query(*options, starrocks.WrapQueryFuncWithDB(db))
  70 + if err != nil {
  71 + return nil, factory.FastError(err)
  72 + }
  73 + dataTable.Total, err = starrocks.WrapQueryCountWithDB(*options, db)()
  74 + if err != nil {
  75 + return nil, factory.FastError(err)
  76 + }
  77 +
  78 + if err := transactionContext.CommitTransaction(); err != nil {
  79 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  80 + }
  81 + return map[string]interface{}{
  82 + "values": dataTable.OptionalValue(),
  83 + "total": dataTable.Total,
  84 + }, nil
  85 +}
@@ -348,31 +348,6 @@ func (tableService *TableService) AddTableStruct(ctx *domain.Context, cmd *comma @@ -348,31 +348,6 @@ func (tableService *TableService) AddTableStruct(ctx *domain.Context, cmd *comma
348 return struct{}{}, nil 348 return struct{}{}, nil
349 } 349 }
350 350
351 -func (tableService *TableService) PreviewDataTable(ctx *domain.Context, cmd *command.AddTableStructCommand) (interface{}, error) {  
352 - if err := cmd.ValidateCommand(); err != nil {  
353 - return nil, application.ThrowError(application.ARG_ERROR, err.Error())  
354 - }  
355 - transactionContext, err := factory.CreateTransactionContext(nil)  
356 - if err != nil {  
357 - return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())  
358 - }  
359 - if err := transactionContext.StartTransaction(); err != nil {  
360 - return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())  
361 - }  
362 - defer func() {  
363 - transactionContext.RollbackTransaction()  
364 - }()  
365 -  
366 - AddTableStructService, _ := factory.CreateAddTableStructService(transactionContext)  
367 - if _, err := AddTableStructService.AddTableStruct(ctx, cmd.TableId, cmd.Fields, cmd.Name); err != nil {  
368 - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())  
369 - }  
370 - if err := transactionContext.CommitTransaction(); err != nil {  
371 - return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())  
372 - }  
373 - return struct{}{}, nil  
374 -}  
375 -  
376 func NewTableService(options map[string]interface{}) *TableService { 351 func NewTableService(options map[string]interface{}) *TableService {
377 newTableService := &TableService{} 352 newTableService := &TableService{}
378 return newTableService 353 return newTableService
  1 +package service
  2 +
  3 +import (
  4 + "github.com/linmadan/egglib-go/core/application"
  5 + "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/application/factory"
  6 + "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/application/table/command"
  7 + "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/application/table/dto"
  8 + "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/domain"
  9 + "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/starrocks"
  10 +)
  11 +
  12 +func (tableService *TableService) TablePreview(ctx *domain.Context, cmd *command.TablePreviewCommand) (interface{}, error) {
  13 + if err := cmd.ValidateCommand(); err != nil {
  14 + return nil, application.ThrowError(application.ARG_ERROR, err.Error())
  15 + }
  16 + transactionContext, err := factory.CreateTransactionContext(nil)
  17 + if err != nil {
  18 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  19 + }
  20 + if err := transactionContext.StartTransaction(); err != nil {
  21 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  22 + }
  23 + defer func() {
  24 + transactionContext.RollbackTransaction()
  25 + }()
  26 +
  27 + var table *domain.Table
  28 + _, table, err = factory.FastPgTable(transactionContext, cmd.TableId)
  29 + if err != nil {
  30 + return nil, factory.FastError(err)
  31 + }
  32 +
  33 + var options = starrocks.QueryOptions{
  34 + TableName: table.SQLName,
  35 + Select: table.Fields(true),
  36 + }
  37 + options.SetCondition(cmd.Where.Conditions)
  38 + options.SetOffsetLimit(cmd.Where.PageNumber, cmd.Where.PageSize)
  39 + var dataTable *domain.DataTable
  40 + dataTable, err = factory.FastDataTable(options)
  41 + if err != nil {
  42 + return nil, factory.FastError(err)
  43 + }
  44 + response := (&dto.TablePreviewDto{}).Load(table, dataTable, domain.ObjectMetaTable)
  45 +
  46 + if err := transactionContext.CommitTransaction(); err != nil {
  47 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  48 + }
  49 + return response, nil
  50 +}
@@ -23,6 +23,10 @@ var ALLIED_CREATION_USER_HOST = "http://localhost:8081" //"http://allied-creatio @@ -23,6 +23,10 @@ var ALLIED_CREATION_USER_HOST = "http://localhost:8081" //"http://allied-creatio
23 23
24 var MMM_BYTE_BANK_HOST = "http://220.250.41.79:8301" 24 var MMM_BYTE_BANK_HOST = "http://220.250.41.79:8301"
25 25
  26 +var METADATA_BASTION_HOST = "http://127.0.0.1:8080"
  27 +
  28 +var BYTE_CORE_HOST = "http://127.0.0.1:8080"
  29 +
26 //var CUSTOMER_ACCOUNT = []int64{3129687560814592, 3129687690100739, 3492238958608384} 30 //var CUSTOMER_ACCOUNT = []int64{3129687560814592, 3129687690100739, 3492238958608384}
27 31
28 //const CUSTOMER_ACCOUNT_DELIMITER = "," 32 //const CUSTOMER_ACCOUNT_DELIMITER = ","
@@ -39,6 +43,7 @@ func init() { @@ -39,6 +43,7 @@ func init() {
39 ALLIED_CREATION_USER_HOST = Configurator.DefaultString("ALLIED_CREATION_USER_HOST", ALLIED_CREATION_USER_HOST) 43 ALLIED_CREATION_USER_HOST = Configurator.DefaultString("ALLIED_CREATION_USER_HOST", ALLIED_CREATION_USER_HOST)
40 //ALLIED_CREATION_COOPERATION_HOST = Configurator.DefaultString("ALLIED_CREATION_COOPERATION_HOST", ALLIED_CREATION_COOPERATION_HOST) 44 //ALLIED_CREATION_COOPERATION_HOST = Configurator.DefaultString("ALLIED_CREATION_COOPERATION_HOST", ALLIED_CREATION_COOPERATION_HOST)
41 MMM_BYTE_BANK_HOST = Configurator.DefaultString("MMM_BYTE_BANK_HOST", MMM_BYTE_BANK_HOST) 45 MMM_BYTE_BANK_HOST = Configurator.DefaultString("MMM_BYTE_BANK_HOST", MMM_BYTE_BANK_HOST)
  46 + BYTE_CORE_HOST = Configurator.DefaultString("BYTE_CORE_HOST", BYTE_CORE_HOST)
42 SERVICE_ENV = Configurator.DefaultString("SERVICE_ENV", SERVICE_ENV) 47 SERVICE_ENV = Configurator.DefaultString("SERVICE_ENV", SERVICE_ENV)
43 HTTP_PORT = Configurator.DefaultInt("HTTP_PORT", HTTP_PORT) 48 HTTP_PORT = Configurator.DefaultInt("HTTP_PORT", HTTP_PORT)
44 SERVICE_NAME = fmt.Sprintf("%v-%v", SERVICE_NAME, SERVICE_ENV) 49 SERVICE_NAME = fmt.Sprintf("%v-%v", SERVICE_NAME, SERVICE_ENV)
@@ -5,6 +5,13 @@ import "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastio @@ -5,6 +5,13 @@ import "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastio
5 type ByteLibService interface { 5 type ByteLibService interface {
6 LoadDataTable(param ReqLoadDataTable) (*DataLoadDataTable, error) 6 LoadDataTable(param ReqLoadDataTable) (*DataLoadDataTable, error)
7 EditTable(param ReqEditDataTable) (*DataEditDataTable, error) 7 EditTable(param ReqEditDataTable) (*DataEditDataTable, error)
  8 + SaveTable(param ReqSaveTable) (*DataSaveTable, error)
  9 + GenerateTable(param ReqGenerateTable) (*DataGenerateTable, error)
  10 + CopyTable(param ReqCopyTable) (*DataCopyTable, error)
  11 + AppendData(param ReqAppendData) (*DataAppendData, error)
  12 + DeleteTable(param ReqDeleteTable) (*DataDeleteTable, error)
  13 + CancelFile(param ReqCancelFile) (*DataCancelFile, error)
  14 + EditTableData(param ReqEditTableData) (*DataEditTableData, error)
8 } 15 }
9 16
10 type ( 17 type (
@@ -17,9 +24,11 @@ type ( @@ -17,9 +24,11 @@ type (
17 } 24 }
18 25
19 DataLoadDataTable struct { 26 DataLoadDataTable struct {
20 - FileId int `json:"fileId"`  
21 - DataFields []*Field `json:"dataFields"`  
22 - DataRows [][]string `json:"dataRows"` 27 + FileId int `json:"objectId"`
  28 + ObjectType string `json:"objectType"`
  29 + TableType string `json:"tableType"`
  30 + Fields []*Field `json:"fields"`
  31 + Data [][]string `json:"data"`
23 Total int `json:"total"` 32 Total int `json:"total"`
24 PageNumber int `json:"pageNumber"` 33 PageNumber int `json:"pageNumber"`
25 InValidCells []InValidCell `json:"inValidCells"` 34 InValidCells []InValidCell `json:"inValidCells"`
@@ -31,7 +40,7 @@ type ( @@ -31,7 +40,7 @@ type (
31 // 名称 40 // 名称
32 Name string `json:"name"` 41 Name string `json:"name"`
33 // 对应数据库类型 42 // 对应数据库类型
34 - Type string `json:"type"` 43 + Type string `json:"sqlType"`
35 } 44 }
36 45
37 InValidCell struct { 46 InValidCell struct {
@@ -53,15 +62,15 @@ func (table DataLoadDataTable) Filter(where domain.Where) *DataLoadDataTable { @@ -53,15 +62,15 @@ func (table DataLoadDataTable) Filter(where domain.Where) *DataLoadDataTable {
53 data := make([][]string, 0) 62 data := make([][]string, 0)
54 if begin < table.Total { 63 if begin < table.Total {
55 if end < table.Total { 64 if end < table.Total {
56 - data = table.DataRows[begin:end] 65 + data = table.Data[begin:end]
57 } else { 66 } else {
58 - data = table.DataRows[begin:] 67 + data = table.Data[begin:]
59 } 68 }
60 } 69 }
61 return &DataLoadDataTable{ 70 return &DataLoadDataTable{
62 FileId: table.FileId, 71 FileId: table.FileId,
63 - DataFields: table.DataFields,  
64 - DataRows: data, 72 + Fields: table.Fields,
  73 + Data: data,
65 Total: table.Total, 74 Total: table.Total,
66 PageNumber: where.PageNumber, 75 PageNumber: where.PageNumber,
67 InValidCells: make([]InValidCell, 0), 76 InValidCells: make([]InValidCell, 0),
@@ -83,3 +92,60 @@ type ( @@ -83,3 +92,60 @@ type (
83 DataLoadDataTable 92 DataLoadDataTable
84 } 93 }
85 ) 94 )
  95 +
  96 +type (
  97 + ReqSaveTable struct {
  98 + }
  99 +
  100 + DataSaveTable struct {
  101 + Url string `json:"url"`
  102 + }
  103 +)
  104 +
  105 +type (
  106 + ReqGenerateTable struct {
  107 + }
  108 +
  109 + DataGenerateTable struct {
  110 + }
  111 +)
  112 +
  113 +type (
  114 + ReqCopyTable struct {
  115 + }
  116 +
  117 + DataCopyTable struct {
  118 + }
  119 +)
  120 +
  121 +type (
  122 + ReqAppendData struct {
  123 + }
  124 +
  125 + DataAppendData struct {
  126 + }
  127 +)
  128 +
  129 +type (
  130 + ReqDeleteTable struct {
  131 + }
  132 +
  133 + DataDeleteTable struct {
  134 + }
  135 +)
  136 +
  137 +type (
  138 + ReqCancelFile struct {
  139 + }
  140 +
  141 + DataCancelFile struct {
  142 + }
  143 +)
  144 +
  145 +type (
  146 + ReqEditTableData struct {
  147 + }
  148 +
  149 + DataEditTableData struct {
  150 + }
  151 +)
1 package domain 1 package domain
2 2
3 type DataTable struct { 3 type DataTable struct {
4 - Fields []*Field  
5 - Data [][]string  
6 - Total int 4 + Fields []*Field `json:"fields"`
  5 + Data [][]string `json:"data"`
  6 + Total int64 `json:"total"`
7 } 7 }
8 8
9 type Where struct { 9 type Where struct {
10 - PageNumber int `json:"pageNumber"`  
11 - PageSize int `json:"pageSize"` 10 + PageNumber int `json:"pageNumber"`
  11 + PageSize int `json:"pageSize"`
  12 + Conditions []Condition `json:"conditions"`
  13 +}
  14 +
  15 +type Condition struct {
  16 + Field *Field `json:"field"`
  17 + Like string `json:"like"`
  18 + In []interface{} `json:"in"`
  19 + Ex []interface{} `json:"ex"`
  20 + Range []interface{} `json:"range"`
  21 + Order string `json:"order"`
  22 +}
  23 +
  24 +func (t *DataTable) OptionalValue() []string {
  25 + var values = make([]string, 0)
  26 + if len(t.Data) > 0 && len(t.Data[0]) == 1 {
  27 + for i := range t.Data {
  28 + if len(t.Data[i]) == 0 {
  29 + continue
  30 + }
  31 + values = append(values, t.Data[i][0])
  32 + }
  33 + }
  34 + return values
  35 +}
  36 +
  37 +func (t *DataTable) MatchFields(from []*Field) []*Field {
  38 + return from
12 } 39 }
1 package domain 1 package domain
2 2
3 -type LoadDataTableService interface {  
4 - Load(ctx *Context, fileId int, where Where) (interface{}, error)  
5 - GetFileId() int 3 +type FileTableService interface {
  4 + Preview(ctx *Context, fileId int, where Where) (interface{}, error)
  5 + Edit()
  6 + Flush(ctx *Context, fileId int, table *Table) (interface{}, error)
  7 + DeleteFiles(ctx *Context, files ...*File) error
  8 + GenerateTable(ctx *Context, fileId int, tableName string) (interface{}, error)
6 } 9 }
7 10
8 -type EditDataTableService interface { 11 +type TableService interface {
  12 + Preview(ctx *Context, tableId int, where Where) (interface{}, error)
  13 + CopyTable(ctx *Context, tableId int, tableName string) (interface{}, error)
  14 + DeleteTables(ctx *Context, tables ...*Table) error
  15 + AppendData(ctx *Context, fileId int, tableId int, mappingFields []*MappingField) (interface{}, error)
  16 + UpdateTableStruct(ctx *Context, tableId int, fields []*Field, name string) (interface{}, error)
  17 + AddTableStruct(ctx *Context, parentTableId int, fields []*Field, name string) (interface{}, error)
  18 +}
  19 +
  20 +type PreviewDataTableService interface {
  21 + Preview(ctx *Context, fileId int, where Where) (interface{}, error)
  22 + GetFileId() int
9 } 23 }
10 24
  25 +type EditDataTableService interface{}
  26 +
11 type FlushDataTableService interface { 27 type FlushDataTableService interface {
12 Flush(ctx *Context, fileId int, table *Table) (interface{}, error) 28 Flush(ctx *Context, fileId int, table *Table) (interface{}, error)
13 } 29 }
14 30
15 type DeleteFileService interface { 31 type DeleteFileService interface {
16 - Delete(ctx *Context, files ...*File) error 32 + DeleteFiles(ctx *Context, files ...*File) error
17 } 33 }
18 34
19 type GenerateMainTableService interface { 35 type GenerateMainTableService interface {
@@ -29,6 +45,12 @@ type DeleteDataTableService interface { @@ -29,6 +45,12 @@ type DeleteDataTableService interface {
29 DeleteTables(ctx *Context, tables ...*Table) error 45 DeleteTables(ctx *Context, tables ...*Table) error
30 } 46 }
31 47
  48 +type AppendDataToTableService interface {
  49 + AppendData(ctx *Context, fileId int, tableId int, mappingFields []*MappingField) (interface{}, error)
  50 +}
  51 +
  52 +/************************************/
  53 +
32 type UpdateTableStructService interface { 54 type UpdateTableStructService interface {
33 UpdateTableStruct(ctx *Context, tableId int, fields []*Field, name string) (interface{}, error) 55 UpdateTableStruct(ctx *Context, tableId int, fields []*Field, name string) (interface{}, error)
34 } 56 }
@@ -36,7 +58,3 @@ type UpdateTableStructService interface { @@ -36,7 +58,3 @@ type UpdateTableStructService interface {
36 type AddTableStructService interface { 58 type AddTableStructService interface {
37 AddTableStruct(ctx *Context, parentTableId int, fields []*Field, name string) (interface{}, error) 59 AddTableStruct(ctx *Context, parentTableId int, fields []*Field, name string) (interface{}, error)
38 } 60 }
39 -  
40 -type AppendDataToTableService interface {  
41 - AppendData(ctx *Context, fileId int, tableId int, mappingFields []*MappingField) (interface{}, error)  
42 -}  
1 package domain 1 package domain
2 2
3 -import "fmt" 3 +import (
  4 + "fmt"
  5 + "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/constant"
  6 +)
4 7
5 var ( 8 var (
6 ErrorNotFound = fmt.Errorf("没有此资源") 9 ErrorNotFound = fmt.Errorf("没有此资源")
@@ -36,9 +39,9 @@ var ( @@ -36,9 +39,9 @@ var (
36 ) 39 )
37 40
38 var ( 41 var (
39 - PKField int = 0 // 主键字段  
40 - MainTableField int = 1 // 主表字段  
41 - ManualField int = 2 // 手动添加 42 + PKField int = 1 // 主键字段
  43 + MainTableField int = 2 // 主表字段
  44 + ManualField int = 3 // 手动添加
42 ) 45 )
43 46
44 var ( 47 var (
@@ -60,6 +63,7 @@ var ObjectTypeMap = map[string]string{ @@ -60,6 +63,7 @@ var ObjectTypeMap = map[string]string{
60 SubTable.ToString(): "分表", 63 SubTable.ToString(): "分表",
61 SourceFile.ToString(): "源文件", 64 SourceFile.ToString(): "源文件",
62 VerifiedFile.ToString(): "校验文件", 65 VerifiedFile.ToString(): "校验文件",
  66 + ObjectDBTable: "业务表",
63 } 67 }
64 68
65 var ( 69 var (
@@ -121,3 +125,85 @@ func EnumsDescription(m map[string]string, key string) string { @@ -121,3 +125,85 @@ func EnumsDescription(m map[string]string, key string) string {
121 } 125 }
122 return "" 126 return ""
123 } 127 }
  128 +
  129 +func DownloadUrl(filename string) string {
  130 + return fmt.Sprintf("%v/%v/%v", constant.METADATA_BASTION_HOST, "static", filename)
  131 +}
  132 +
  133 +var DBTables = map[int]*Table{
  134 + DBTableTableOperateLog.ToInt(): &Table{
  135 + TableId: 1,
  136 + TableType: ObjectDBTable,
  137 + Name: "日志信息",
  138 + SQLName: "metadata.logs",
  139 + DataFieldIndex: 6,
  140 + PK: &Field{
  141 + Index: 0,
  142 + Name: "日志ID",
  143 + SQLName: "log_id",
  144 + SQLType: Int.ToString(),
  145 + Flag: PKField,
  146 + },
  147 + DataFields: []*Field{
  148 + {
  149 + Index: 1,
  150 + Name: "数据表表名/文件名",
  151 + SQLName: "object_name",
  152 + SQLType: String.ToString(),
  153 + Flag: MainTableField,
  154 + },
  155 + {
  156 + Index: 2,
  157 + Name: "类型",
  158 + SQLName: "object_type",
  159 + SQLType: String.ToString(),
  160 + Flag: MainTableField,
  161 + },
  162 + {
  163 + Index: 3,
  164 + Name: "操作类型",
  165 + SQLName: "operation_type",
  166 + SQLType: String.ToString(),
  167 + Flag: MainTableField,
  168 + },
  169 + {
  170 + Index: 4,
  171 + Name: "日志内容",
  172 + SQLName: "content",
  173 + SQLType: String.ToString(),
  174 + Flag: MainTableField,
  175 + },
  176 + {
  177 + Index: 5,
  178 + Name: "操作时间",
  179 + SQLName: "created_at",
  180 + SQLType: Datetime.ToString(),
  181 + Flag: MainTableField,
  182 + },
  183 + {
  184 + Index: 6,
  185 + Name: "操作人",
  186 + SQLName: "operator_name",
  187 + SQLType: String.ToString(),
  188 + Flag: MainTableField,
  189 + },
  190 + },
  191 + },
  192 +}
  193 +
  194 +type DBTable int
  195 +
  196 +func (t DBTable) ToInt() int {
  197 + return int(t)
  198 +}
  199 +
  200 +const (
  201 + DBTableTableOperateLog DBTable = 1
  202 + DBTableBusinessLog DBTable = 2
  203 +)
  204 +
  205 +const (
  206 + ObjectFile = "File"
  207 + ObjectMetaTable = "MetaTable"
  208 + ObjectDBTable = "DBTable"
  209 +)
@@ -16,7 +16,7 @@ type Field struct { @@ -16,7 +16,7 @@ type Field struct {
16 SQLType string `json:"sqlType"` 16 SQLType string `json:"sqlType"`
17 // 描述 17 // 描述
18 Description string `json:"description"` 18 Description string `json:"description"`
19 - // 标识 1:主表字段 2:手动添加 19 + // 标识 1.主键 2:主表字段 3:手动添加
20 Flag int `json:"flag"` 20 Flag int `json:"flag"`
21 } 21 }
22 22
@@ -40,6 +40,14 @@ func (fields Fields) ToMap() map[string]*Field { @@ -40,6 +40,14 @@ func (fields Fields) ToMap() map[string]*Field {
40 return m 40 return m
41 } 41 }
42 42
  43 +func (fields Fields) NameArrayString() []string {
  44 + m := make([]string, 0)
  45 + for i := range fields {
  46 + m = append(m, fields[i].Name)
  47 + }
  48 + return m
  49 +}
  50 +
43 func (fields Fields) Select(options map[string]interface{}) []*Field { 51 func (fields Fields) Select(options map[string]interface{}) []*Field {
44 var result []*Field 52 var result []*Field
45 for _, field := range fields { 53 for _, field := range fields {
1 package domain 1 package domain
2 2
3 -import "time" 3 +import (
  4 + "fmt"
  5 + "math/rand"
  6 + "time"
  7 +)
4 8
5 // Table 表 9 // Table 表
6 type Table struct { 10 type Table struct {
@@ -53,6 +57,8 @@ func (table *Table) Identify() interface{} { @@ -53,6 +57,8 @@ func (table *Table) Identify() interface{} {
53 } 57 }
54 58
55 func (table *Table) WithContext(ctx *Context) *Table { 59 func (table *Table) WithContext(ctx *Context) *Table {
  60 + rand.Seed(time.Now().Unix())
  61 + table.SQLName = fmt.Sprintf("%v_t%v_c%v", table.SQLName, rand.Intn(10000), ctx.CompanyId)
56 table.Context = ctx 62 table.Context = ctx
57 return table 63 return table
58 } 64 }
@@ -63,15 +69,26 @@ func (table *Table) Update(data map[string]interface{}) error { @@ -63,15 +69,26 @@ func (table *Table) Update(data map[string]interface{}) error {
63 69
64 func (t *Table) Fields(includePK bool) []*Field { 70 func (t *Table) Fields(includePK bool) []*Field {
65 var fields []*Field 71 var fields []*Field
66 - if len(t.fields) == 0 {  
67 - if includePK {  
68 - fields = append(fields, t.PK)  
69 - }  
70 - fields = append(fields, t.DataFields...)  
71 - if t.TableType == SubTable.ToString() {  
72 - fields = append(fields, t.ManualFields...)  
73 - }  
74 - t.fields = fields 72 +
  73 + if includePK && t.PK != nil {
  74 + fields = append(fields, t.PK)
  75 + }
  76 + fields = append(fields, t.DataFields...)
  77 + if t.TableType == SubTable.ToString() {
  78 + fields = append(fields, t.ManualFields...)
75 } 79 }
  80 + t.fields = fields
  81 +
76 return t.fields 82 return t.fields
77 } 83 }
  84 +
  85 +func (t *Table) MatchField(field *Field) (*Field, bool) {
  86 + if len(t.fields) == 0 {
  87 + t.fields = t.Fields(true)
  88 + }
  89 + mField := (Fields)(t.fields).ToMap()
  90 + if v, ok := mField[field.Name]; ok {
  91 + return v, true
  92 + }
  93 + return nil, false
  94 +}
@@ -2,7 +2,10 @@ package api @@ -2,7 +2,10 @@ package api
2 2
3 import ( 3 import (
4 rawjson "encoding/json" 4 rawjson "encoding/json"
  5 + "fmt"
5 "github.com/linmadan/egglib-go/utils/json" 6 "github.com/linmadan/egglib-go/utils/json"
  7 + "net/http"
  8 + "strings"
6 "time" 9 "time"
7 10
8 "github.com/beego/beego/v2/client/httplib" 11 "github.com/beego/beego/v2/client/httplib"
@@ -23,6 +26,7 @@ type BaseServiceGateway struct { @@ -23,6 +26,7 @@ type BaseServiceGateway struct {
23 ConnectTimeout time.Duration 26 ConnectTimeout time.Duration
24 ReadWriteTimeout time.Duration 27 ReadWriteTimeout time.Duration
25 host string 28 host string
  29 + Interceptor func(msg string)
26 } 30 }
27 31
28 type Request struct { 32 type Request struct {
@@ -33,16 +37,17 @@ type Request struct { @@ -33,16 +37,17 @@ type Request struct {
33 37
34 func (gateway BaseServiceGateway) CreateRequest(url string, method string) *httplib.BeegoHTTPRequest { 38 func (gateway BaseServiceGateway) CreateRequest(url string, method string) *httplib.BeegoHTTPRequest {
35 var request *httplib.BeegoHTTPRequest 39 var request *httplib.BeegoHTTPRequest
  40 + method = strings.ToUpper(method)
36 switch method { 41 switch method {
37 - case "get", "GET": 42 + case http.MethodGet:
38 request = httplib.Get(url) 43 request = httplib.Get(url)
39 - case "post", "POST": 44 + case http.MethodPost:
40 request = httplib.Post(url) 45 request = httplib.Post(url)
41 - case "put", "PUT": 46 + case http.MethodPut:
42 request = httplib.Put(url) 47 request = httplib.Put(url)
43 - case "delete", "DELETE": 48 + case http.MethodDelete:
44 request = httplib.Delete(url) 49 request = httplib.Delete(url)
45 - case "head", "HEADER": 50 + case http.MethodHead:
46 request = httplib.Head(url) 51 request = httplib.Head(url)
47 default: 52 default:
48 request = httplib.Get(url) 53 request = httplib.Get(url)
@@ -59,7 +64,24 @@ func (gateway BaseServiceGateway) GetResponseData(result Response, data interfac @@ -59,7 +64,24 @@ func (gateway BaseServiceGateway) GetResponseData(result Response, data interfac
59 } 64 }
60 65
61 func (gateway BaseServiceGateway) FastDoRequest(url, method string, param interface{}, data interface{}) error { 66 func (gateway BaseServiceGateway) FastDoRequest(url, method string, param interface{}, data interface{}) error {
62 - err := gateway.DoRequest(Request{ 67 + begin := time.Now()
  68 + var err error
  69 + var result = "success"
  70 + defer func() {
  71 + jsonParam, _ := json.Marshal(param)
  72 + jsonData, _ := json.Marshal(data)
  73 + if err != nil {
  74 + result = err.Error()
  75 + }
  76 + if gateway.Interceptor != nil {
  77 + gateway.Interceptor(fmt.Sprintf("%v | %v | %v : %v \n request:%v \n response:%v", time.Since(begin), url, strings.ToUpper(method),
  78 + result,
  79 + string(jsonParam),
  80 + string(jsonData),
  81 + ))
  82 + }
  83 + }()
  84 + err = gateway.DoRequest(Request{
63 Url: url, 85 Url: url,
64 Method: method, 86 Method: method,
65 Param: param, 87 Param: param,
@@ -3,6 +3,7 @@ package bytelib @@ -3,6 +3,7 @@ package bytelib
3 import ( 3 import (
4 "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/domain/bytecore" 4 "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/domain/bytecore"
5 "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/api" 5 "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/api"
  6 + "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/log"
6 "time" 7 "time"
7 ) 8 )
8 9
@@ -16,6 +17,9 @@ func NewApiByteLib(host string) *ApiByteLib { @@ -16,6 +17,9 @@ func NewApiByteLib(host string) *ApiByteLib {
16 gt := api.NewBaseServiceGateway(host) 17 gt := api.NewBaseServiceGateway(host)
17 gt.ConnectTimeout = 10 * time.Second 18 gt.ConnectTimeout = 10 * time.Second
18 gt.ReadWriteTimeout = 10 * time.Second 19 gt.ReadWriteTimeout = 10 * time.Second
  20 + gt.Interceptor = func(msg string) {
  21 + log.Logger.Info(msg)
  22 + }
19 return &ApiByteLib{ 23 return &ApiByteLib{
20 BaseServiceGateway: gt, 24 BaseServiceGateway: gt,
21 } 25 }
@@ -39,18 +43,90 @@ func (gateway ApiByteLib) EditTable(param bytecore.ReqEditDataTable) (*bytecore. @@ -39,18 +43,90 @@ func (gateway ApiByteLib) EditTable(param bytecore.ReqEditDataTable) (*bytecore.
39 return &data, nil 43 return &data, nil
40 } 44 }
41 45
42 -// 保存校验文件 (文件地址) 46 +// SaveTable 保存校验文件 (文件地址)
  47 +func (gateway ApiByteLib) SaveTable(param bytecore.ReqSaveTable) (*bytecore.DataSaveTable, error) {
  48 + url := gateway.Host() + "/table/save"
  49 + method := "post"
  50 + var data bytecore.DataSaveTable
  51 + err := gateway.FastDoRequest(url, method, param, &data)
  52 + if err != nil {
  53 + return nil, err
  54 + }
  55 + return &data, nil
  56 +}
43 57
44 -// 生成主表 58 +// GenerateTable 生成主表
  59 +func (gateway ApiByteLib) GenerateTable(param bytecore.ReqGenerateTable) (*bytecore.DataGenerateTable, error) {
  60 + url := gateway.Host() + "/table/generate"
  61 + method := "post"
  62 + var data bytecore.DataGenerateTable
  63 + err := gateway.FastDoRequest(url, method, param, &data)
  64 + if err != nil {
  65 + return nil, err
  66 + }
  67 + return &data, nil
  68 +}
45 69
46 -// 表复制 70 +// CopyTable 表复制
  71 +func (gateway ApiByteLib) CopyTable(param bytecore.ReqCopyTable) (*bytecore.DataCopyTable, error) {
  72 + url := gateway.Host() + "/table/copy"
  73 + method := "post"
  74 + var data bytecore.DataCopyTable
  75 + err := gateway.FastDoRequest(url, method, param, &data)
  76 + if err != nil {
  77 + return nil, err
  78 + }
  79 + return &data, nil
  80 +}
47 81
48 -// 追加数据 82 +// AppendData 追加数据
  83 +func (gateway ApiByteLib) AppendData(param bytecore.ReqAppendData) (*bytecore.DataAppendData, error) {
  84 + url := gateway.Host() + "/table/append"
  85 + method := "post"
  86 + var data bytecore.DataAppendData
  87 + err := gateway.FastDoRequest(url, method, param, &data)
  88 + if err != nil {
  89 + return nil, err
  90 + }
  91 + return &data, nil
  92 +}
49 93
50 -// 表删除 (主表、副表、分表) 94 +// DeleteTable 表删除 (主表、副表、分表)
  95 +func (gateway ApiByteLib) DeleteTable(param bytecore.ReqDeleteTable) (*bytecore.DataDeleteTable, error) {
  96 + url := gateway.Host() + "/table/delete"
  97 + method := "post"
  98 + var data bytecore.DataDeleteTable
  99 + err := gateway.FastDoRequest(url, method, param, &data)
  100 + if err != nil {
  101 + return nil, err
  102 + }
  103 + return &data, nil
  104 +}
  105 +
  106 +// CancelFile 表删除 (主表、副表、分表)
  107 +func (gateway ApiByteLib) CancelFile(param bytecore.ReqCancelFile) (*bytecore.DataCancelFile, error) {
  108 + url := gateway.Host() + "/table/cancel-file"
  109 + method := "post"
  110 + var data bytecore.DataCancelFile
  111 + err := gateway.FastDoRequest(url, method, param, &data)
  112 + if err != nil {
  113 + return nil, err
  114 + }
  115 + return &data, nil
  116 +}
51 117
52 // 表拆分 118 // 表拆分
53 119
54 // 更新表结构(分表) 120 // 更新表结构(分表)
55 121
56 -// 编辑、添加、删除表数据(副表) 122 +// EditTableData 编辑、添加、删除表数据(副表)
  123 +func (gateway ApiByteLib) EditTableData(param bytecore.ReqEditTableData) (*bytecore.DataEditTableData, error) {
  124 + url := gateway.Host() + "/table/cancel-file"
  125 + method := "post"
  126 + var data bytecore.DataEditTableData
  127 + err := gateway.FastDoRequest(url, method, param, &data)
  128 + if err != nil {
  129 + return nil, err
  130 + }
  131 + return &data, nil
  132 +}
@@ -14,6 +14,8 @@ type ByteCoreService struct { @@ -14,6 +14,8 @@ type ByteCoreService struct {
14 14
15 var ByteCore = &ByteCoreService{} //bytecore.ByteLibService 15 var ByteCore = &ByteCoreService{} //bytecore.ByteLibService
16 16
  17 +var _ bytecore.ByteLibService = (*ByteCoreService)(nil)
  18 +
17 func (ptr *ByteCoreService) LoadDataTable(param bytecore.ReqLoadDataTable) (*bytecore.DataLoadDataTable, error) { 19 func (ptr *ByteCoreService) LoadDataTable(param bytecore.ReqLoadDataTable) (*bytecore.DataLoadDataTable, error) {
18 if v, ok := ptr.load(param.FileId); ok { 20 if v, ok := ptr.load(param.FileId); ok {
19 return v.Filter(param.Where), nil 21 return v.Filter(param.Where), nil
@@ -37,8 +39,8 @@ func (ptr *ByteCoreService) LoadDataTable(param bytecore.ReqLoadDataTable) (*byt @@ -37,8 +39,8 @@ func (ptr *ByteCoreService) LoadDataTable(param bytecore.ReqLoadDataTable) (*byt
37 39
38 var response = &bytecore.DataLoadDataTable{ 40 var response = &bytecore.DataLoadDataTable{
39 FileId: param.FileId, 41 FileId: param.FileId,
40 - DataFields: columnToField(cols),  
41 - DataRows: data, 42 + Fields: columnToField(cols),
  43 + Data: data,
42 Total: len(data), 44 Total: len(data),
43 PageNumber: param.PageNumber, 45 PageNumber: param.PageNumber,
44 InValidCells: make([]bytecore.InValidCell, 0), 46 InValidCells: make([]bytecore.InValidCell, 0),
@@ -77,6 +79,34 @@ func columnToField(cols []string) []*bytecore.Field { @@ -77,6 +79,34 @@ func columnToField(cols []string) []*bytecore.Field {
77 return fields 79 return fields
78 } 80 }
79 81
  82 +func (ptr *ByteCoreService) SaveTable(param bytecore.ReqSaveTable) (*bytecore.DataSaveTable, error) {
  83 + return nil, nil
  84 +}
  85 +
  86 +func (ptr *ByteCoreService) GenerateTable(param bytecore.ReqGenerateTable) (*bytecore.DataGenerateTable, error) {
  87 + return nil, nil
  88 +}
  89 +
  90 +func (ptr *ByteCoreService) CopyTable(param bytecore.ReqCopyTable) (*bytecore.DataCopyTable, error) {
  91 + return nil, nil
  92 +}
  93 +
  94 +func (ptr *ByteCoreService) AppendData(param bytecore.ReqAppendData) (*bytecore.DataAppendData, error) {
  95 + return nil, nil
  96 +}
  97 +
  98 +func (ptr *ByteCoreService) DeleteTable(param bytecore.ReqDeleteTable) (*bytecore.DataDeleteTable, error) {
  99 + return nil, nil
  100 +}
  101 +
  102 +func (ptr *ByteCoreService) CancelFile(param bytecore.ReqCancelFile) (*bytecore.DataCancelFile, error) {
  103 + return nil, nil
  104 +}
  105 +
  106 +func (ptr *ByteCoreService) EditTableData(param bytecore.ReqEditTableData) (*bytecore.DataEditTableData, error) {
  107 + return nil, nil
  108 +}
  109 +
80 ////////////// 110 //////////////
81 // 字库核心 111 // 字库核心
82 ////////////// 112 //////////////
1 -package domainService  
2 -  
3 -import pgTransaction "github.com/linmadan/egglib-go/transaction/pg"  
4 -  
5 -type DeleteTableService struct {  
6 - transactionContext *pgTransaction.TransactionContext  
7 -}  
8 -  
9 -func (ptr *DeleteTableService) Delete(tableIds ...int) error {  
10 - // delete table  
11 -  
12 - // delete log  
13 - return nil  
14 -}  
@@ -21,7 +21,8 @@ func NewDeleteFileService(transactionContext *pgTransaction.TransactionContext) @@ -21,7 +21,8 @@ func NewDeleteFileService(transactionContext *pgTransaction.TransactionContext)
21 } 21 }
22 } 22 }
23 23
24 -func (ptr *DeleteFileService) Delete(ctx *domain.Context, files ...*domain.File) error { 24 +// DeleteFiles 文件删除
  25 +func (ptr *DeleteFileService) DeleteFiles(ctx *domain.Context, files ...*domain.File) error {
25 for _, file := range files { 26 for _, file := range files {
26 if err := ptr.delete(file); err != nil { 27 if err := ptr.delete(file); err != nil {
27 return err 28 return err
@@ -11,6 +11,7 @@ type EditDataTableService struct { @@ -11,6 +11,7 @@ type EditDataTableService struct {
11 transactionContext *pgTransaction.TransactionContext 11 transactionContext *pgTransaction.TransactionContext
12 } 12 }
13 13
  14 +// Edit 表结构编辑 【data-table】
14 func (ptr *EditDataTableService) Edit(ctx *domain.Context, fileId int, tableId int, mappingFields []*domain.MappingField) (interface{}, error) { 15 func (ptr *EditDataTableService) Edit(ctx *domain.Context, fileId int, tableId int, mappingFields []*domain.MappingField) (interface{}, error) {
15 fileRepository, _ := repository.NewFileRepository(ptr.transactionContext) 16 fileRepository, _ := repository.NewFileRepository(ptr.transactionContext)
16 file, err := fileRepository.FindOne(map[string]interface{}{"fileId": fileId}) 17 file, err := fileRepository.FindOne(map[string]interface{}{"fileId": fileId})
@@ -4,6 +4,7 @@ import ( @@ -4,6 +4,7 @@ import (
4 "fmt" 4 "fmt"
5 "github.com/google/uuid" 5 "github.com/google/uuid"
6 pgTransaction "github.com/linmadan/egglib-go/transaction/pg" 6 pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
  7 + "github.com/linmadan/egglib-go/utils/tool_funs"
7 "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/domain" 8 "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/domain"
8 "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/dao" 9 "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/dao"
9 "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/repository" 10 "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/repository"
@@ -15,6 +16,7 @@ type FlushDataTableService struct { @@ -15,6 +16,7 @@ type FlushDataTableService struct {
15 transactionContext *pgTransaction.TransactionContext 16 transactionContext *pgTransaction.TransactionContext
16 } 17 }
17 18
  19 +// Flush 保存表 【data-table】
18 func (ptr *FlushDataTableService) Flush(ctx *domain.Context, fileId int, table *domain.Table) (interface{}, error) { 20 func (ptr *FlushDataTableService) Flush(ctx *domain.Context, fileId int, table *domain.Table) (interface{}, error) {
19 fileRepository, _ := repository.NewFileRepository(ptr.transactionContext) 21 fileRepository, _ := repository.NewFileRepository(ptr.transactionContext)
20 file, err := fileRepository.FindOne(map[string]interface{}{"fileId": fileId}) 22 file, err := fileRepository.FindOne(map[string]interface{}{"fileId": fileId})
@@ -69,7 +71,7 @@ func (ptr *FlushDataTableService) flushSourceFile(ctx *domain.Context, table *do @@ -69,7 +71,7 @@ func (ptr *FlushDataTableService) flushSourceFile(ctx *domain.Context, table *do
69 return err 71 return err
70 } 72 }
71 deleteFileService, _ := NewDeleteFileService(ptr.transactionContext) 73 deleteFileService, _ := NewDeleteFileService(ptr.transactionContext)
72 - if err = deleteFileService.Delete(ctx, files...); err != nil { 74 + if err = deleteFileService.DeleteFiles(ctx, files...); err != nil {
73 return err 75 return err
74 } 76 }
75 return nil 77 return nil
@@ -119,7 +121,7 @@ func NewTable(tableType domain.TableType, fileName string, dataFields []*domain. @@ -119,7 +121,7 @@ func NewTable(tableType domain.TableType, fileName string, dataFields []*domain.
119 // New Table 121 // New Table
120 table.TableType = tableType.ToString() 122 table.TableType = tableType.ToString()
121 table.Name = fileName 123 table.Name = fileName
122 - table.SQLName = SQLTableName() 124 + table.SQLName = pin(fileName) //SQLTableName()
123 table.PK = PK() 125 table.PK = PK()
124 table.DataFieldIndex = len(dataFields) 126 table.DataFieldIndex = len(dataFields)
125 for i, field := range dataFields { 127 for i, field := range dataFields {
@@ -144,7 +146,7 @@ func PK() *domain.Field { @@ -144,7 +146,7 @@ func PK() *domain.Field {
144 SQLName: "id", 146 SQLName: "id",
145 SQLType: domain.Int.ToString(), 147 SQLType: domain.Int.ToString(),
146 Description: "主键", 148 Description: "主键",
147 - Flag: 0, 149 + Flag: domain.PKField,
148 } 150 }
149 } 151 }
150 152
@@ -152,13 +154,13 @@ func DataField(name string, sqlType string, flag int, index int) *domain.Field { @@ -152,13 +154,13 @@ func DataField(name string, sqlType string, flag int, index int) *domain.Field {
152 return &domain.Field{ 154 return &domain.Field{
153 Index: index, 155 Index: index,
154 Name: name, 156 Name: name,
155 - SQLName: fieldName(index), 157 + SQLName: fmt.Sprintf("%v_c%d", pin(name), index), //fieldName(index),
156 SQLType: sqlType, 158 SQLType: sqlType,
157 Description: "", 159 Description: "",
158 Flag: flag, 160 Flag: flag,
159 } 161 }
160 } 162 }
161 163
162 -func fieldName(index int) string {  
163 - return fmt.Sprintf("col%d", index) 164 +func pin(name string) string {
  165 + return tool_funs.ToPinYin(name, "_")
164 } 166 }
@@ -11,6 +11,7 @@ type GenerateMainTableService struct { @@ -11,6 +11,7 @@ type GenerateMainTableService struct {
11 transactionContext *pgTransaction.TransactionContext 11 transactionContext *pgTransaction.TransactionContext
12 } 12 }
13 13
  14 +// GenerateTable 主表生成 【data-table】
14 func (ptr *GenerateMainTableService) GenerateTable(ctx *domain.Context, fileId int, tableName string) (interface{}, error) { 15 func (ptr *GenerateMainTableService) GenerateTable(ctx *domain.Context, fileId int, tableName string) (interface{}, error) {
15 fileRepository, _ := repository.NewFileRepository(ptr.transactionContext) 16 fileRepository, _ := repository.NewFileRepository(ptr.transactionContext)
16 file, err := fileRepository.FindOne(map[string]interface{}{"fileId": fileId}) 17 file, err := fileRepository.FindOne(map[string]interface{}{"fileId": fileId})
@@ -23,7 +24,7 @@ func (ptr *GenerateMainTableService) GenerateTable(ctx *domain.Context, fileId i @@ -23,7 +24,7 @@ func (ptr *GenerateMainTableService) GenerateTable(ctx *domain.Context, fileId i
23 if err != nil { 24 if err != nil {
24 return nil, fmt.Errorf("文件未校验") 25 return nil, fmt.Errorf("文件未校验")
25 } 26 }
26 - duplicateTable, err := tableRepository.FindOne(map[string]interface{}{"context": ctx, "tableType": domain.MainTable.ToString(), "tableName": tableName}) 27 + duplicateTable, err := tableRepository.FindOne(map[string]interface{}{"context": ctx, "tableName": tableName})
27 if err == nil && duplicateTable != nil { 28 if err == nil && duplicateTable != nil {
28 return nil, fmt.Errorf("表名称重复") 29 return nil, fmt.Errorf("表名称重复")
29 } 30 }
@@ -8,12 +8,13 @@ import ( @@ -8,12 +8,13 @@ import (
8 "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/repository" 8 "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/repository"
9 ) 9 )
10 10
11 -type LoadDataTableService struct { 11 +type PreviewDataTableService struct {
12 FileId int 12 FileId int
13 transactionContext *pgTransaction.TransactionContext 13 transactionContext *pgTransaction.TransactionContext
14 } 14 }
15 15
16 -func (ptr *LoadDataTableService) Load(ctx *domain.Context, fileId int, where domain.Where) (interface{}, error) { 16 +// Preview 预览 【data-table】
  17 +func (ptr *PreviewDataTableService) Preview(ctx *domain.Context, fileId int, where domain.Where) (interface{}, error) {
17 fileRepository, _ := repository.NewFileRepository(ptr.transactionContext) 18 fileRepository, _ := repository.NewFileRepository(ptr.transactionContext)
18 file, err := fileRepository.FindOne(map[string]interface{}{"fileId": fileId}) 19 file, err := fileRepository.FindOne(map[string]interface{}{"fileId": fileId})
19 if err != nil { 20 if err != nil {
@@ -42,19 +43,27 @@ func (ptr *LoadDataTableService) Load(ctx *domain.Context, fileId int, where dom @@ -42,19 +43,27 @@ func (ptr *LoadDataTableService) Load(ctx *domain.Context, fileId int, where dom
42 if err != nil { 43 if err != nil {
43 return nil, err 44 return nil, err
44 } 45 }
45 - 46 + response.ObjectType = domain.ObjectFile
  47 + response.TableType = domain.ExcelTable.ToString()
46 return response, nil 48 return response, nil
47 } 49 }
48 50
49 -func (ptr *LoadDataTableService) GetFileId() int { 51 +//func convert(from *bytecore.DataLoadDataTable)(to *domain.DataTable){
  52 +// to = &domain.DataTable{
  53 +//
  54 +// }
  55 +// return
  56 +//}
  57 +
  58 +func (ptr *PreviewDataTableService) GetFileId() int {
50 return ptr.FileId 59 return ptr.FileId
51 } 60 }
52 61
53 -func NewLoadDataTableService(transactionContext *pgTransaction.TransactionContext) (*LoadDataTableService, error) { 62 +func NewLoadDataTableService(transactionContext *pgTransaction.TransactionContext) (*PreviewDataTableService, error) {
54 if transactionContext == nil { 63 if transactionContext == nil {
55 return nil, fmt.Errorf("transactionContext参数不能为nil") 64 return nil, fmt.Errorf("transactionContext参数不能为nil")
56 } else { 65 } else {
57 - return &LoadDataTableService{ 66 + return &PreviewDataTableService{
58 transactionContext: transactionContext, 67 transactionContext: transactionContext,
59 }, nil 68 }, nil
60 } 69 }
@@ -32,7 +32,7 @@ func (ptr *AddTableStructService) AddTableStruct(ctx *domain.Context, parentTabl @@ -32,7 +32,7 @@ func (ptr *AddTableStructService) AddTableStruct(ctx *domain.Context, parentTabl
32 } 32 }
33 33
34 // 验证表名是否重复 34 // 验证表名是否重复
35 - duplicateTable, err := tableRepository.FindOne(map[string]interface{}{"tableType": domain.SubTable.ToString(), "tableName": name}) 35 + duplicateTable, err := tableRepository.FindOne(map[string]interface{}{"context": ctx, "tableName": name})
36 if err == nil && duplicateTable != nil { 36 if err == nil && duplicateTable != nil {
37 return nil, fmt.Errorf("表名称重复") 37 return nil, fmt.Errorf("表名称重复")
38 } 38 }
@@ -5,12 +5,14 @@ import ( @@ -5,12 +5,14 @@ import (
5 pgTransaction "github.com/linmadan/egglib-go/transaction/pg" 5 pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
6 "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/domain" 6 "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/domain"
7 "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/repository" 7 "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/repository"
  8 + "time"
8 ) 9 )
9 10
10 type AppendDataToTableService struct { 11 type AppendDataToTableService struct {
11 transactionContext *pgTransaction.TransactionContext 12 transactionContext *pgTransaction.TransactionContext
12 } 13 }
13 14
  15 +// AppendData 追加数据 【data-table】
14 func (ptr *AppendDataToTableService) AppendData(ctx *domain.Context, fileId int, tableId int, mappingFields []*domain.MappingField) (interface{}, error) { 16 func (ptr *AppendDataToTableService) AppendData(ctx *domain.Context, fileId int, tableId int, mappingFields []*domain.MappingField) (interface{}, error) {
15 fileRepository, _ := repository.NewFileRepository(ptr.transactionContext) 17 fileRepository, _ := repository.NewFileRepository(ptr.transactionContext)
16 file, err := fileRepository.FindOne(map[string]interface{}{"fileId": fileId}) 18 file, err := fileRepository.FindOne(map[string]interface{}{"fileId": fileId})
@@ -38,6 +40,13 @@ func (ptr *AppendDataToTableService) AppendData(ctx *domain.Context, fileId int, @@ -38,6 +40,13 @@ func (ptr *AppendDataToTableService) AppendData(ctx *domain.Context, fileId int,
38 return nil, err 40 return nil, err
39 } 41 }
40 42
  43 + // 更新表数据
  44 + table.RowCount += excelTable.RowCount
  45 + table.UpdatedAt = time.Now()
  46 + if _, err = tableRepository.Save(table); err != nil {
  47 + return nil, err
  48 + }
  49 +
41 // 日志 50 // 日志
42 if err = FastLog(ptr.transactionContext, domain.CommonLog, table.TableId, &AppendDataToTableLog{ 51 if err = FastLog(ptr.transactionContext, domain.CommonLog, table.TableId, &AppendDataToTableLog{
43 LogEntry: domain.NewLogEntry(table.Name, domain.MainTable.ToString(), domain.AppendData, ctx), 52 LogEntry: domain.NewLogEntry(table.Name, domain.MainTable.ToString(), domain.AppendData, ctx),
@@ -21,14 +21,18 @@ func NewCopyDataTableService(transactionContext *pgTransaction.TransactionContex @@ -21,14 +21,18 @@ func NewCopyDataTableService(transactionContext *pgTransaction.TransactionContex
21 } 21 }
22 } 22 }
23 23
  24 +// CopyTable 表复制 【data-table】
24 func (ptr *CopyDataTableService) CopyTable(ctx *domain.Context, tableId int, tableName string) (interface{}, error) { 25 func (ptr *CopyDataTableService) CopyTable(ctx *domain.Context, tableId int, tableName string) (interface{}, error) {
25 tableRepository, _ := repository.NewTableRepository(ptr.transactionContext) 26 tableRepository, _ := repository.NewTableRepository(ptr.transactionContext)
26 table, err := tableRepository.FindOne(map[string]interface{}{"tableId": tableId}) 27 table, err := tableRepository.FindOne(map[string]interface{}{"tableId": tableId})
27 if err != nil { 28 if err != nil {
28 return nil, err 29 return nil, err
29 } 30 }
  31 + if table.TableType != domain.MainTable.ToString() {
  32 + return nil, fmt.Errorf("主表才允许复制")
  33 + }
30 // 验证表名是否重复 34 // 验证表名是否重复
31 - duplicateTable, err := tableRepository.FindOne(map[string]interface{}{"tableType": domain.SideTable.ToString(), "tableName": tableName}) 35 + duplicateTable, err := tableRepository.FindOne(map[string]interface{}{"context": ctx, "tableName": tableName})
32 if err == nil && duplicateTable != nil { 36 if err == nil && duplicateTable != nil {
33 return nil, fmt.Errorf("表名称重复") 37 return nil, fmt.Errorf("表名称重复")
34 } 38 }
@@ -21,6 +21,7 @@ func NewDeleteDataTableService(transactionContext *pgTransaction.TransactionCont @@ -21,6 +21,7 @@ func NewDeleteDataTableService(transactionContext *pgTransaction.TransactionCont
21 } 21 }
22 } 22 }
23 23
  24 +// DeleteTable 表删除 【data-table】
24 func (ptr *DeleteDataTableService) DeleteTable(ctx *domain.Context, tableId int) (interface{}, error) { 25 func (ptr *DeleteDataTableService) DeleteTable(ctx *domain.Context, tableId int) (interface{}, error) {
25 tableRepository, _ := repository.NewTableRepository(ptr.transactionContext) 26 tableRepository, _ := repository.NewTableRepository(ptr.transactionContext)
26 table, err := tableRepository.FindOne(map[string]interface{}{"tableId": tableId}) 27 table, err := tableRepository.FindOne(map[string]interface{}{"tableId": tableId})
@@ -8,6 +8,7 @@ import ( @@ -8,6 +8,7 @@ import (
8 "github.com/xuri/excelize/v2" 8 "github.com/xuri/excelize/v2"
9 "io" 9 "io"
10 "os" 10 "os"
  11 + "path/filepath"
11 ) 12 )
12 13
13 type XLXSWriterTo struct { 14 type XLXSWriterTo struct {
@@ -27,6 +28,9 @@ func (wt *XLXSWriterTo) WriteTo(w io.Writer) (n int64, err error) { @@ -27,6 +28,9 @@ func (wt *XLXSWriterTo) WriteTo(w io.Writer) (n int64, err error) {
27 func (wt *XLXSWriterTo) Save(fileName string) error { 28 func (wt *XLXSWriterTo) Save(fileName string) error {
28 var file *excelize.File 29 var file *excelize.File
29 var err error 30 var err error
  31 + if err = checkPath(fileName); err != nil {
  32 + return err
  33 + }
30 file, err = wt.newFile() 34 file, err = wt.newFile()
31 if err != nil { 35 if err != nil {
32 return nil 36 return nil
@@ -34,6 +38,27 @@ func (wt *XLXSWriterTo) Save(fileName string) error { @@ -34,6 +38,27 @@ func (wt *XLXSWriterTo) Save(fileName string) error {
34 return file.SaveAs(fileName) 38 return file.SaveAs(fileName)
35 } 39 }
36 40
  41 +func checkPath(fileName string) error {
  42 + dir := filepath.Dir(fileName)
  43 + if !Exists(dir) {
  44 + if err := os.Mkdir(dir, os.ModePerm); err != nil {
  45 + return err
  46 + }
  47 + }
  48 + return nil
  49 +}
  50 +
  51 +func Exists(path string) bool {
  52 + _, err := os.Stat(path) //os.Stat获取文件信息
  53 + if err != nil {
  54 + if os.IsExist(err) {
  55 + return true
  56 + }
  57 + return false
  58 + }
  59 + return true
  60 +}
  61 +
37 func (wt *XLXSWriterTo) newFile() (*excelize.File, error) { 62 func (wt *XLXSWriterTo) newFile() (*excelize.File, error) {
38 sheet := "Sheet1" 63 sheet := "Sheet1"
39 file := excelize.NewFile() 64 file := excelize.NewFile()
@@ -94,6 +119,9 @@ func (xw *CSVWriterTo) WriteTo(w io.Writer) (n int64, err error) { @@ -94,6 +119,9 @@ func (xw *CSVWriterTo) WriteTo(w io.Writer) (n int64, err error) {
94 } 119 }
95 120
96 func (xw *CSVWriterTo) Save(fileName string) error { 121 func (xw *CSVWriterTo) Save(fileName string) error {
  122 + if err := checkPath(fileName); err != nil {
  123 + return err
  124 + }
97 csvFile, err := os.Create(fileName) 125 csvFile, err := os.Create(fileName)
98 if err != nil { 126 if err != nil {
99 return err 127 return err
@@ -143,10 +171,13 @@ func (xw *XlSWriterTo) WriteTo(w io.Writer) (n int64, err error) { @@ -143,10 +171,13 @@ func (xw *XlSWriterTo) WriteTo(w io.Writer) (n int64, err error) {
143 } 171 }
144 172
145 func (xw *XlSWriterTo) Save(fileName string) error { 173 func (xw *XlSWriterTo) Save(fileName string) error {
  174 + if err := checkPath(fileName); err != nil {
  175 + return err
  176 + }
146 option := excel.Option{"Visible": true, "DisplayAlerts": true, "ScreenUpdating": true} 177 option := excel.Option{"Visible": true, "DisplayAlerts": true, "ScreenUpdating": true}
147 xl, err := excel.New(option) //xl, _ := excel.Open("test_excel.xls", option) 178 xl, err := excel.New(option) //xl, _ := excel.Open("test_excel.xls", option)
148 if err != nil { 179 if err != nil {
149 - 180 + return err
150 } 181 }
151 defer xl.Quit() 182 defer xl.Quit()
152 183
@@ -8,10 +8,16 @@ import ( @@ -8,10 +8,16 @@ import (
8 "github.com/go-pg/pg/v10/orm" 8 "github.com/go-pg/pg/v10/orm"
9 "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/constant" 9 "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/constant"
10 "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/pg/models" 10 "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/pg/models"
  11 + "gorm.io/driver/postgres"
  12 + "gorm.io/gorm"
  13 + "gorm.io/gorm/logger"
11 "log" 14 "log"
  15 + "os"
  16 + "time"
12 ) 17 )
13 18
14 var DB *pg.DB 19 var DB *pg.DB
  20 +var GormDB *gorm.DB
15 21
16 func Init() { 22 func Init() {
17 DB = pg.Connect(&pg.Options{ 23 DB = pg.Connect(&pg.Options{
@@ -41,6 +47,30 @@ func Init() { @@ -41,6 +47,30 @@ func Init() {
41 //comment.AddComments(DB, model) 47 //comment.AddComments(DB, model)
42 } 48 }
43 } 49 }
  50 +
  51 + var err error
  52 + newLogger := logger.New(
  53 + log.New(os.Stdout, "\r\n", log.LstdFlags), // io writer
  54 + logger.Config{
  55 + SlowThreshold: time.Second, // Slow SQL threshold
  56 + LogLevel: logger.Info, // Log level
  57 + IgnoreRecordNotFoundError: true, // Ignore ErrRecordNotFound error for logger
  58 + Colorful: false, // Disable color
  59 + },
  60 + )
  61 +
  62 + dsn := fmt.Sprintf("host=%v user=%v password=%v dbname=%v port=%v sslmode=disable TimeZone=Asia/Shanghai",
  63 + constant.POSTGRESQL_HOST, constant.POSTGRESQL_USER, constant.POSTGRESQL_PASSWORD, constant.POSTGRESQL_DB_NAME, constant.POSTGRESQL_PORT)
  64 + GormDB, err = gorm.Open(postgres.Open(dsn), &gorm.Config{
  65 + Logger: newLogger,
  66 + //NamingStrategy: schema.NamingStrategy{
  67 + // TablePrefix: "metadata.", // schema name
  68 + // SingularTable: false,
  69 + //},
  70 + })
  71 + if err != nil {
  72 + newLogger.Error(context.Background(), err.Error())
  73 + }
44 } 74 }
45 75
46 type SqlGeneratePrintHook struct{} 76 type SqlGeneratePrintHook struct{}
@@ -2,7 +2,11 @@ package starrocks @@ -2,7 +2,11 @@ package starrocks
2 2
3 import ( 3 import (
4 "database/sql" 4 "database/sql"
  5 + "fmt"
5 "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/domain" 6 "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/domain"
  7 + "gorm.io/gorm"
  8 + "reflect"
  9 + "strings"
6 ) 10 )
7 11
8 func Query(params QueryOptions, queryFunc func(params QueryOptions) (*sql.Rows, error)) (*domain.DataTable, error) { 12 func Query(params QueryOptions, queryFunc func(params QueryOptions) (*sql.Rows, error)) (*domain.DataTable, error) {
@@ -10,24 +14,172 @@ func Query(params QueryOptions, queryFunc func(params QueryOptions) (*sql.Rows, @@ -10,24 +14,172 @@ func Query(params QueryOptions, queryFunc func(params QueryOptions) (*sql.Rows,
10 if err != nil { 14 if err != nil {
11 return nil, err 15 return nil, err
12 } 16 }
  17 + defer rows.Close()
13 dataTable := &domain.DataTable{} 18 dataTable := &domain.DataTable{}
14 - dataTable.Data, _ = ScanRows(rows)  
15 - return nil, nil 19 + dataTable.Data, err = ScanRows(rows)
  20 +
  21 + //rows.Columns()
  22 + return dataTable, err
16 } 23 }
17 24
18 type QueryOptions struct { 25 type QueryOptions struct {
19 TableName string 26 TableName string
20 Select []*domain.Field 27 Select []*domain.Field
21 - Where []string  
22 - Order []string 28 + Where []Condition
23 Offset int 29 Offset int
24 Limit int 30 Limit int
  31 + Context *domain.Context
  32 +}
  33 +
  34 +func (o *QueryOptions) SetOffsetLimit(pageNumber, pageSize int) {
  35 + if pageNumber == 0 {
  36 + pageNumber = 1
  37 + }
  38 + if pageSize == 0 {
  39 + pageSize = 20
  40 + }
  41 + o.Offset = (pageNumber - 1) * pageSize
  42 + o.Limit = pageSize
  43 +}
  44 +
  45 +func (o *QueryOptions) SetCondition(conditions []domain.Condition) {
  46 + for _, c := range conditions {
  47 + o.Where = append(o.Where, Condition{
  48 + Condition: c,
  49 + })
  50 + }
25 } 51 }
26 52
27 type Condition struct { 53 type Condition struct {
28 - Field *domain.Field  
29 - In []interface{}  
30 - Ex []interface{}  
31 - Range []interface{}  
32 - Order []interface{} 54 + domain.Condition
  55 + Distinct bool
  56 +}
  57 +
  58 +func (c Condition) SetWhere(q *gorm.DB) {
  59 + if len(c.Like) > 0 {
  60 + q.Where(fmt.Sprintf("%v like '%%%v%%'", c.Field.SQLName, c.Like))
  61 + }
  62 + if len(c.In) > 0 {
  63 + q.Where(fmt.Sprintf("%v in %v", c.Field.SQLName, c.InArgs(c.In)))
  64 + }
  65 + if len(c.Ex) > 0 {
  66 + in := c.InArgs(c.Ex)
  67 + q.Where(fmt.Sprintf("%v not in %v", c.Field.SQLName, in))
  68 + }
  69 + if c.Distinct {
  70 + q.Distinct(c.Field.SQLName)
  71 + }
  72 + if len(c.Order) > 0 {
  73 + q.Order(fmt.Sprintf("%v %v", c.Field.SQLName, c.Order))
  74 + }
  75 +}
  76 +func (c Condition) InArgs(args interface{}) string {
  77 + bytes := make([]byte, 0)
  78 + bytes = appendIn(bytes, reflect.ValueOf(args))
  79 + return string(bytes)
  80 +}
  81 +
  82 +func appendIn(b []byte, slice reflect.Value) []byte {
  83 + sliceLen := slice.Len()
  84 + b = append(b, '(')
  85 + for i := 0; i < sliceLen; i++ {
  86 + if i > 0 {
  87 + b = append(b, ',')
  88 + }
  89 +
  90 + elem := slice.Index(i)
  91 + if elem.Kind() == reflect.Interface {
  92 + elem = elem.Elem()
  93 + }
  94 +
  95 + if elem.Kind() == reflect.Slice {
  96 + //b = appendIn(b, elem)
  97 + } else {
  98 + b = appendValue(b, elem)
  99 + }
  100 + }
  101 + b = append(b, ')')
  102 + return b
  103 +}
  104 +
  105 +func appendValue(b []byte, v reflect.Value) []byte {
  106 + if v.Kind() == reflect.Ptr && v.IsNil() {
  107 +
  108 + return append(b, "NULL"...)
  109 + }
  110 + if v.Kind() == reflect.Int || v.Kind() == reflect.Int64 || v.Kind() == reflect.Float64 {
  111 + return append(b, []byte(v.String())...)
  112 + }
  113 + b = append(b, []byte("'")...)
  114 + b = append(b, []byte(v.String())...)
  115 + b = append(b, []byte("'")...)
  116 + return b
  117 +}
  118 +
  119 +func DefaultQueryFunc(params QueryOptions) (*sql.Rows, error) {
  120 + query := DB.Table(params.TableName)
  121 + rows, err := query.Rows()
  122 + if err != nil {
  123 + return nil, err
  124 + }
  125 + return rows, nil
  126 +}
  127 +
  128 +func WrapQueryFuncWithDB(db *gorm.DB) func(QueryOptions) (*sql.Rows, error) {
  129 + return func(params QueryOptions) (*sql.Rows, error) {
  130 + query := db.Table(params.TableName)
  131 + queryWithoutLimitOffset(query, params)
  132 + if params.Offset > 0 {
  133 + query.Offset(params.Offset)
  134 + }
  135 + if params.Limit > 0 {
  136 + query.Limit(params.Limit)
  137 + }
  138 + if params.Context != nil {
  139 + query.Where(fmt.Sprintf("context->>'companyId'='%v'", params.Context.CompanyId))
  140 + //query.Where("context->>'companyId'='?'", params.Context.CompanyId)
  141 + }
  142 + rows, err := query.Rows()
  143 + if err != nil {
  144 + return nil, err
  145 + }
  146 + return rows, nil
  147 + }
  148 +}
  149 +
  150 +func SetTable(query *gorm.DB, tableName string) {
  151 + query.Statement.Table = tableName
  152 +}
  153 +
  154 +func queryWithoutLimitOffset(query *gorm.DB, params QueryOptions) {
  155 + if len(params.Select) > 0 {
  156 + fields := make([]string, 0)
  157 + for _, f := range params.Select {
  158 + fields = append(fields, f.SQLName)
  159 + }
  160 + query.Select(strings.Join(fields, ","))
  161 + }
  162 + if len(params.Where) > 0 {
  163 + for _, w := range params.Where {
  164 + w.SetWhere(query)
  165 + }
  166 + }
  167 +}
  168 +
  169 +func QueryCount(params QueryOptions) (int64, error) {
  170 + var total int64
  171 + query := DB.Table(params.TableName)
  172 + queryWithoutLimitOffset(query, params)
  173 + query.Count(&total)
  174 + return total, query.Error
  175 +}
  176 +
  177 +func WrapQueryCountWithDB(params QueryOptions, db *gorm.DB) func() (int64, error) {
  178 + return func() (int64, error) {
  179 + var total int64
  180 + query := db.Table(params.TableName)
  181 + queryWithoutLimitOffset(query, params)
  182 + query.Count(&total)
  183 + return total, query.Error
  184 + }
33 } 185 }
@@ -8,7 +8,6 @@ import ( @@ -8,7 +8,6 @@ import (
8 ) 8 )
9 9
10 func ScanRows(rows *sql.Rows) ([][]string, error) { 10 func ScanRows(rows *sql.Rows) ([][]string, error) {
11 - defer rows.Close()  
12 var results [][]string 11 var results [][]string
13 cols, err := rows.Columns() 12 cols, err := rows.Columns()
14 if err != nil { 13 if err != nil {
@@ -7,14 +7,27 @@ import ( @@ -7,14 +7,27 @@ import (
7 "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/log" 7 "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/log"
8 "gorm.io/driver/mysql" 8 "gorm.io/driver/mysql"
9 "gorm.io/gorm" 9 "gorm.io/gorm"
  10 + "gorm.io/gorm/logger"
  11 + rawlog "log"
  12 + "os"
10 "reflect" 13 "reflect"
  14 + "time"
11 ) 15 )
12 16
13 var DB *gorm.DB 17 var DB *gorm.DB
14 18
15 func Init() error { 19 func Init() error {
16 var err error 20 var err error
17 - DB, err = gorm.Open(mysql.Open(constant.STARROCKS_MYSQL_DATA_SOURCE), &gorm.Config{}) 21 + newLogger := logger.New(
  22 + rawlog.New(os.Stdout, "\r\n", rawlog.LstdFlags), // io writer
  23 + logger.Config{
  24 + SlowThreshold: time.Second, // Slow SQL threshold
  25 + LogLevel: logger.Info, // Log level
  26 + IgnoreRecordNotFoundError: true, // Ignore ErrRecordNotFound error for logger
  27 + Colorful: false, // Disable color
  28 + },
  29 + )
  30 + DB, err = gorm.Open(mysql.Open(constant.STARROCKS_MYSQL_DATA_SOURCE), &gorm.Config{Logger: newLogger})
18 31
19 //Test1() 32 //Test1()
20 return err 33 return err
@@ -26,7 +26,7 @@ func init() { @@ -26,7 +26,7 @@ func init() {
26 web.BConfig.Listen.HTTPPort = port 26 web.BConfig.Listen.HTTPPort = port
27 } 27 }
28 } 28 }
29 - web.InsertFilter("/*", web.BeforeExec, filters.AllowCors()) 29 + web.InsertFilter("/*", web.BeforeRouter, filters.AllowCors())
30 web.InsertFilter("/*", web.BeforeExec, filters.CreateRequstLogFilter(Logger)) 30 web.InsertFilter("/*", web.BeforeExec, filters.CreateRequstLogFilter(Logger))
31 web.InsertFilter("/*", web.AfterExec, filters.CreateResponseLogFilter(Logger), web.WithReturnOnOutput(false)) 31 web.InsertFilter("/*", web.AfterExec, filters.CreateResponseLogFilter(Logger), web.WithReturnOnOutput(false))
32 } 32 }
  1 +package controllers
  2 +
  3 +import (
  4 + "github.com/linmadan/egglib-go/web/beego"
  5 + "path/filepath"
  6 +)
  7 +
  8 +type DownloadFileController struct {
  9 + beego.BaseController
  10 +}
  11 +
  12 +func (controller *DownloadFileController) DownloadHandle() {
  13 + filename := filepath.Base(controller.GetString(":filename"))
  14 + controller.Ctx.Output.Download("public/" + filename)
  15 +}
@@ -90,11 +90,11 @@ func (controller *FileController) SearchVerifiedFile() { @@ -90,11 +90,11 @@ func (controller *FileController) SearchVerifiedFile() {
90 controller.Response(data, err) 90 controller.Response(data, err)
91 } 91 }
92 92
93 -func (controller *FileController) LoadDataTable() { 93 +func (controller *FileController) FilePreview() {
94 fileService := service.NewFileService(nil) 94 fileService := service.NewFileService(nil)
95 loadDataTableCommand := &command.LoadDataTableCommand{} 95 loadDataTableCommand := &command.LoadDataTableCommand{}
96 controller.Unmarshal(loadDataTableCommand) 96 controller.Unmarshal(loadDataTableCommand)
97 - data, err := fileService.LoadDataTable(ParseContext(controller.BaseController), loadDataTableCommand) 97 + data, err := fileService.FilePreview(ParseContext(controller.BaseController), loadDataTableCommand)
98 controller.Response(data, err) 98 controller.Response(data, err)
99 } 99 }
100 100
@@ -124,8 +124,16 @@ func (controller *FileController) GenerateMainTable() { @@ -124,8 +124,16 @@ func (controller *FileController) GenerateMainTable() {
124 124
125 func (controller *FileController) AppendDataToTable() { 125 func (controller *FileController) AppendDataToTable() {
126 fileService := service.NewFileService(nil) 126 fileService := service.NewFileService(nil)
127 - cmdd := &command.AppendDataToTableCommand{}  
128 - controller.Unmarshal(cmdd)  
129 - data, err := fileService.AppendDataToTable(ParseContext(controller.BaseController), cmdd) 127 + cmd := &command.AppendDataToTableCommand{}
  128 + controller.Unmarshal(cmd)
  129 + data, err := fileService.AppendDataToTable(ParseContext(controller.BaseController), cmd)
  130 + controller.Response(data, err)
  131 +}
  132 +
  133 +func (controller *FileController) CancelVerifyingFile() {
  134 + fileService := service.NewFileService(nil)
  135 + cmd := &command.CancelVerifyingFileCommand{}
  136 + controller.Unmarshal(cmd)
  137 + data, err := fileService.CancelVerifyingFile(ParseContext(controller.BaseController), cmd)
130 controller.Response(data, err) 138 controller.Response(data, err)
131 } 139 }
@@ -71,7 +71,9 @@ func (controller *MappingRuleController) SearchMappingRule() { @@ -71,7 +71,9 @@ func (controller *MappingRuleController) SearchMappingRule() {
71 func (controller *MappingRuleController) PrepareMappingRule() { 71 func (controller *MappingRuleController) PrepareMappingRule() {
72 mappingRuleService := service.NewMappingRuleService(nil) 72 mappingRuleService := service.NewMappingRuleService(nil)
73 prepareCommand := &command.PrepareCommand{} 73 prepareCommand := &command.PrepareCommand{}
74 - controller.Unmarshal(prepareCommand) 74 + //controller.Unmarshal(prepareCommand)
  75 + prepareCommand.TableId, _ = controller.GetInt("tableId")
  76 + prepareCommand.FileId, _ = controller.GetInt("fileId")
75 data, err := mappingRuleService.Prepare(prepareCommand) 77 data, err := mappingRuleService.Prepare(prepareCommand)
76 controller.Response(data, err) 78 controller.Response(data, err)
77 } 79 }
@@ -6,6 +6,9 @@ import ( @@ -6,6 +6,9 @@ import (
6 "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/application/table/query" 6 "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/application/table/query"
7 "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/application/table/service" 7 "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/application/table/service"
8 "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/domain" 8 "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/domain"
  9 +
  10 + filecommand "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/application/file/command"
  11 + fileservice "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/application/file/service"
9 ) 12 )
10 13
11 type TableController struct { 14 type TableController struct {
@@ -138,3 +141,63 @@ func (controller *TableController) AddTableStruct() { @@ -138,3 +141,63 @@ func (controller *TableController) AddTableStruct() {
138 data, err := tableService.AddTableStruct(ParseContext(controller.BaseController), batchEditSubTableCommand) 141 data, err := tableService.AddTableStruct(ParseContext(controller.BaseController), batchEditSubTableCommand)
139 controller.Response(data, err) 142 controller.Response(data, err)
140 } 143 }
  144 +
  145 +func (controller *TableController) ExportDataTable() {
  146 + tableService := service.NewTableService(nil)
  147 + cmd := &command.TablePreviewCommand{}
  148 + controller.Unmarshal(cmd)
  149 + data, err := tableService.ExportDataTable(ParseContext(controller.BaseController), cmd)
  150 + controller.Response(data, err)
  151 +}
  152 +
  153 +func (controller *TableController) TablePreview() {
  154 + tableService := service.NewTableService(nil)
  155 + cmd := &command.TablePreviewCommand{}
  156 + controller.Unmarshal(cmd)
  157 + data, err := tableService.TablePreview(ParseContext(controller.BaseController), cmd)
  158 + controller.Response(data, err)
  159 +}
  160 +
  161 +func (controller *TableController) DBTablePreview() {
  162 + tableService := service.NewTableService(nil)
  163 + cmd := &command.DBTablePreviewCommand{}
  164 + controller.Unmarshal(cmd)
  165 + data, err := tableService.DBTablePreview(ParseContext(controller.BaseController), cmd)
  166 + controller.Response(data, err)
  167 +}
  168 +
  169 +func (controller *TableController) FieldOptionalValues() {
  170 + tableService := service.NewTableService(nil)
  171 + cmd := &command.FieldOptionalValuesCommand{}
  172 + controller.Unmarshal(cmd)
  173 + data, err := tableService.FieldOptionalValues(ParseContext(controller.BaseController), cmd)
  174 + controller.Response(data, err)
  175 +}
  176 +
  177 +func (controller *TableController) Preview() {
  178 + tableService := service.NewTableService(nil)
  179 + fileService := fileservice.NewFileService(nil)
  180 + cmd := &struct {
  181 + ObjectType string `json:"objectType"`
  182 + }{}
  183 + controller.Unmarshal(cmd)
  184 + var data interface{}
  185 + var err error
  186 + switch cmd.ObjectType {
  187 + case domain.ObjectFile:
  188 + cmd := &filecommand.LoadDataTableCommand{}
  189 + controller.Unmarshal(cmd)
  190 + data, err = fileService.FilePreview(ParseContext(controller.BaseController), cmd)
  191 + case domain.ObjectMetaTable:
  192 + cmd := &command.TablePreviewCommand{}
  193 + controller.Unmarshal(cmd)
  194 + data, err = tableService.TablePreview(ParseContext(controller.BaseController), cmd)
  195 + case domain.ObjectDBTable:
  196 + cmd := &command.DBTablePreviewCommand{}
  197 + controller.Unmarshal(cmd)
  198 + data, err = tableService.DBTablePreview(ParseContext(controller.BaseController), cmd)
  199 + default:
  200 +
  201 + }
  202 + controller.Response(data, err)
  203 +}
  1 +package routers
  2 +
  3 +import (
  4 + "github.com/beego/beego/v2/server/web"
  5 + "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/port/beego/controllers"
  6 +)
  7 +
  8 +func init() {
  9 + web.Router("/data/business/db-table-preview", &controllers.TableController{}, "Post:DBTablePreview")
  10 +}
  1 +package routers
  2 +
  3 +import (
  4 + "github.com/beego/beego/v2/server/web"
  5 + "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/port/beego/controllers"
  6 +)
  7 +
  8 +func init() {
  9 + web.Router("/static/:filename", &controllers.DownloadFileController{}, "*:DownloadHandle")
  10 +}
@@ -14,8 +14,9 @@ func init() { @@ -14,8 +14,9 @@ func init() {
14 web.Router("/data/files/search", &controllers.FileController{}, "Post:SearchFile") 14 web.Router("/data/files/search", &controllers.FileController{}, "Post:SearchFile")
15 web.Router("/data/files/search-source-file", &controllers.FileController{}, "Post:SearchSourceFile") 15 web.Router("/data/files/search-source-file", &controllers.FileController{}, "Post:SearchSourceFile")
16 web.Router("/data/files/search-verified-file", &controllers.FileController{}, "Post:SearchVerifiedFile") 16 web.Router("/data/files/search-verified-file", &controllers.FileController{}, "Post:SearchVerifiedFile")
  17 + web.Router("/data/files/cancel-verifying-file", &controllers.FileController{}, "Post:CancelVerifyingFile")
17 18
18 - web.Router("/data/load-data-table", &controllers.FileController{}, "Post:LoadDataTable") 19 + web.Router("/data/file-preview", &controllers.FileController{}, "Post:FilePreview")
19 web.Router("/data/edit-data-table", &controllers.FileController{}, "Post:EditDataTable") 20 web.Router("/data/edit-data-table", &controllers.FileController{}, "Post:EditDataTable")
20 web.Router("/data/flush-data-table", &controllers.FileController{}, "Post:FlushDataTable") 21 web.Router("/data/flush-data-table", &controllers.FileController{}, "Post:FlushDataTable")
21 web.Router("/data/generate-main-table", &controllers.FileController{}, "Post:GenerateMainTable") 22 web.Router("/data/generate-main-table", &controllers.FileController{}, "Post:GenerateMainTable")
@@ -12,5 +12,5 @@ func init() { @@ -12,5 +12,5 @@ func init() {
12 web.Router("/data/mapping-rules/:mappingRuleId", &controllers.MappingRuleController{}, "Delete:RemoveMappingRule") 12 web.Router("/data/mapping-rules/:mappingRuleId", &controllers.MappingRuleController{}, "Delete:RemoveMappingRule")
13 web.Router("/data/mapping-rules/", &controllers.MappingRuleController{}, "Get:ListMappingRule") 13 web.Router("/data/mapping-rules/", &controllers.MappingRuleController{}, "Get:ListMappingRule")
14 web.Router("/data/mapping-rules/search", &controllers.MappingRuleController{}, "Post:SearchMappingRule") 14 web.Router("/data/mapping-rules/search", &controllers.MappingRuleController{}, "Post:SearchMappingRule")
15 - web.Router("/data/mapping-rules/prepare", &controllers.MappingRuleController{}, "Post:PrepareMappingRule") 15 + web.Router("/data/mapping-rules/prepare", &controllers.MappingRuleController{}, "Get:PrepareMappingRule")
16 } 16 }
@@ -20,6 +20,13 @@ func init() { @@ -20,6 +20,13 @@ func init() {
20 web.Router("/data/tables/batch-edit-sub-table", &controllers.TableController{}, "Post:BatchEditSubTable") 20 web.Router("/data/tables/batch-edit-sub-table", &controllers.TableController{}, "Post:BatchEditSubTable")
21 web.Router("/data/tables/copy-data-table", &controllers.TableController{}, "Post:CopyDataTable") 21 web.Router("/data/tables/copy-data-table", &controllers.TableController{}, "Post:CopyDataTable")
22 web.Router("/data/tables/update-table-struct", &controllers.TableController{}, "Post:UpdateTableStruct") 22 web.Router("/data/tables/update-table-struct", &controllers.TableController{}, "Post:UpdateTableStruct")
23 - web.Router("/data/tables/add-table-struct", &controllers.TableController{}, "Post:AddTableStruct")  
24 - // web.Router("/data/tables/preview", &controllers.TableController{}, "Post:PreviewDataTable") 23 + web.Router("/data/tables/add-sub-table", &controllers.TableController{}, "Post:AddTableStruct")
  24 + web.Router("/data/tables/export-table", &controllers.TableController{}, "Post:ExportDataTable")
  25 +
  26 + web.Router("/data/tables/table-preview", &controllers.TableController{}, "Post:TablePreview")
  27 + web.Router("/data/field-optional-values", &controllers.TableController{}, "Post:FieldOptionalValues")
  28 +
  29 + web.Router("/business/db-table-preview", &controllers.TableController{}, "Post:DBTablePreview")
  30 +
  31 + web.Router("/data/table-preview", &controllers.TableController{}, "Post:Preview")
25 } 32 }