正在显示
20 个修改的文件
包含
115 行增加
和
147 行删除
| @@ -378,8 +378,8 @@ formatMethod: 格式化方法(1.upper:大写2.lower:小写3.capitalize:首字母 | @@ -378,8 +378,8 @@ formatMethod: 格式化方法(1.upper:大写2.lower:小写3.capitalize:首字母 | ||
| 378 | 378 | ||
| 379 | ``` | 379 | ``` |
| 380 | separator: 分割符号 ‘|’ | 380 | separator: 分割符号 ‘|’ |
| 381 | -splitDirection: 拆分方向(1.left:从左边 2.right:从右边)-separator专属参数 | ||
| 382 | -splitCount: 拆分次数-separator专属参数 | 381 | +splitDirection: 拆分方向(1.left:从左边 2.right:从右边) |
| 382 | +splitCount: 拆分次数 | ||
| 383 | ``` | 383 | ``` |
| 384 | 384 | ||
| 385 | 2. 按字符数 | 385 | 2. 按字符数 |
| @@ -389,7 +389,9 @@ splitCount: 拆分次数-separator专属参数 | @@ -389,7 +389,9 @@ splitCount: 拆分次数-separator专属参数 | ||
| 389 | "action": "split-column", | 389 | "action": "split-column", |
| 390 | "params": { | 390 | "params": { |
| 391 | "splitMethod": "char-length", | 391 | "splitMethod": "char-length", |
| 392 | - "charLength": 10 | 392 | + "splitDirection": "left", |
| 393 | + "charLength": "10", | ||
| 394 | + "splitCount": "1" | ||
| 393 | } | 395 | } |
| 394 | } | 396 | } |
| 395 | ``` | 397 | ``` |
| @@ -398,6 +400,8 @@ splitCount: 拆分次数-separator专属参数 | @@ -398,6 +400,8 @@ splitCount: 拆分次数-separator专属参数 | ||
| 398 | 400 | ||
| 399 | ``` | 401 | ``` |
| 400 | charLength: 字符长度-char-length专属参数 | 402 | charLength: 字符长度-char-length专属参数 |
| 403 | +splitDirection: 拆分方向(1.left:从左边 2.right:从右边) | ||
| 404 | +splitCount: 拆分次数 (拆分策略是重复时:值0或者非1整数) | ||
| 401 | ``` | 405 | ``` |
| 402 | 406 | ||
| 403 | ### 提取 extract-column | 407 | ### 提取 extract-column |
| @@ -10,6 +10,7 @@ ENABLE_KAFKA_LOG11 = true | @@ -10,6 +10,7 @@ ENABLE_KAFKA_LOG11 = true | ||
| 10 | HTTPS_PORT = 8143 | 10 | HTTPS_PORT = 8143 |
| 11 | ALLIED_CREATION_USER_HOST = http://allied-creation-user-dev.fjmaimaimai.com | 11 | ALLIED_CREATION_USER_HOST = http://allied-creation-user-dev.fjmaimaimai.com |
| 12 | BYTE_CORE_HOST = http://47.97.5.102:8303 | 12 | BYTE_CORE_HOST = http://47.97.5.102:8303 |
| 13 | +METADATA_BASTION_HOST = http://106.75.231.90:9999 | ||
| 13 | 14 | ||
| 14 | STARROCKS_DB_NAME = character_library | 15 | STARROCKS_DB_NAME = character_library |
| 15 | STARROCKS_USER = root | 16 | STARROCKS_USER = root |
| @@ -26,5 +26,5 @@ func (d *FileDto) Load(f *domain.File) { | @@ -26,5 +26,5 @@ func (d *FileDto) Load(f *domain.File) { | ||
| 26 | d.Url = f.FileInfo.Url | 26 | d.Url = f.FileInfo.Url |
| 27 | d.FileType = f.FileType | 27 | d.FileType = f.FileType |
| 28 | d.Ext = f.FileInfo.Ext | 28 | d.Ext = f.FileInfo.Ext |
| 29 | - d.Time = xtime.New(f.CreatedAt).Local().Format("2006-01-02 15:04:05") | 29 | + d.Time = xtime.New(f.UpdatedAt).Local().Format("2006-01-02 15:04:05") |
| 30 | } | 30 | } |
| 1 | package service | 1 | package service |
| 2 | 2 | ||
| 3 | import ( | 3 | import ( |
| 4 | + "fmt" | ||
| 5 | + | ||
| 4 | "github.com/linmadan/egglib-go/core/application" | 6 | "github.com/linmadan/egglib-go/core/application" |
| 5 | "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/application/factory" | 7 | "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/application/factory" |
| 6 | "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/application/file/command" | 8 | "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/application/file/command" |
| @@ -35,7 +37,6 @@ func (fileService *FileService) FilePreview(ctx *domain.Context, loadDataTableCo | @@ -35,7 +37,6 @@ func (fileService *FileService) FilePreview(ctx *domain.Context, loadDataTableCo | ||
| 35 | return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | 37 | return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) |
| 36 | } | 38 | } |
| 37 | 39 | ||
| 38 | - //return dto.NewDataTableDtoDemo(loadDataTableService.GetFileId()), nil | ||
| 39 | return data, nil | 40 | return data, nil |
| 40 | } | 41 | } |
| 41 | 42 | ||
| @@ -93,6 +94,21 @@ func (fileService *FileService) EditDataTable(ctx *domain.Context, editDataTable | @@ -93,6 +94,21 @@ func (fileService *FileService) EditDataTable(ctx *domain.Context, editDataTable | ||
| 93 | } | 94 | } |
| 94 | editDataTableCommand.Fields = temporaryFile.Fields | 95 | editDataTableCommand.Fields = temporaryFile.Fields |
| 95 | editDataTableCommand.ProcessFields = temporaryFile.MatchFields(editDataTableCommand.ProcessFieldNames) | 96 | editDataTableCommand.ProcessFields = temporaryFile.MatchFields(editDataTableCommand.ProcessFieldNames) |
| 97 | + if len(editDataTableCommand.ProcessFields) == 0 { | ||
| 98 | + return nil, factory.FastError(fmt.Errorf("请至少选择一个数据列")) | ||
| 99 | + } | ||
| 100 | + // allowAction := func(fields []*domain.Field, action string) error { | ||
| 101 | + // for _, f := range fields { | ||
| 102 | + // if f.SQLType != string(domain.String) && | ||
| 103 | + // !(action == domain.RemoveColumn || action == domain.CopyColumn || action == domain.RenameColumn || action == domain.ConvertColumnType) { | ||
| 104 | + // return fmt.Errorf("列【%v】必须先转字符串类型",f.Name) | ||
| 105 | + // } | ||
| 106 | + // } | ||
| 107 | + // return nil | ||
| 108 | + // } | ||
| 109 | + // if err = allowAction(editDataTableCommand.ProcessFields, editDataTableCommand.Action); err != nil { | ||
| 110 | + // return nil, factory.FastError(err) | ||
| 111 | + // } | ||
| 96 | editDataTableService, _ := factory.CreateEditDataTableService(transactionContext) | 112 | editDataTableService, _ := factory.CreateEditDataTableService(transactionContext) |
| 97 | response, err := editDataTableService.Edit(ctx, editDataTableCommand.EditTableRequest) | 113 | response, err := editDataTableService.Edit(ctx, editDataTableCommand.EditTableRequest) |
| 98 | if err != nil { | 114 | if err != nil { |
| @@ -120,14 +136,6 @@ func (fileService *FileService) FlushDataTable(ctx *domain.Context, flushDataTab | @@ -120,14 +136,6 @@ func (fileService *FileService) FlushDataTable(ctx *domain.Context, flushDataTab | ||
| 120 | transactionContext.RollbackTransaction() | 136 | transactionContext.RollbackTransaction() |
| 121 | }() | 137 | }() |
| 122 | flushDataTableService, _ := factory.CreateFlushDataTableService(transactionContext) | 138 | flushDataTableService, _ := factory.CreateFlushDataTableService(transactionContext) |
| 123 | - //fields := make([]*domain.Field, 0) | ||
| 124 | - //for _, f := range flushDataTableCommand.DataFields { | ||
| 125 | - // fields = append(fields, &domain.Field{ | ||
| 126 | - // Name: f.Name, | ||
| 127 | - // SQLType: f.SQLType, | ||
| 128 | - // }) | ||
| 129 | - //} | ||
| 130 | - | ||
| 131 | cache := redis.NewFileCacheService() | 139 | cache := redis.NewFileCacheService() |
| 132 | temporaryFile, err := cache.Get(redis.KeyTemporaryFileInfo(flushDataTableCommand.ObjectId)) | 140 | temporaryFile, err := cache.Get(redis.KeyTemporaryFileInfo(flushDataTableCommand.ObjectId)) |
| 133 | if err != nil { | 141 | if err != nil { |
| @@ -2,6 +2,9 @@ package service | @@ -2,6 +2,9 @@ package service | ||
| 2 | 2 | ||
| 3 | import ( | 3 | import ( |
| 4 | "fmt" | 4 | "fmt" |
| 5 | + "path/filepath" | ||
| 6 | + "time" | ||
| 7 | + | ||
| 5 | "github.com/linmadan/egglib-go/core/application" | 8 | "github.com/linmadan/egglib-go/core/application" |
| 6 | "github.com/linmadan/egglib-go/utils/tool_funs" | 9 | "github.com/linmadan/egglib-go/utils/tool_funs" |
| 7 | "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/application/factory" | 10 | "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/application/factory" |
| @@ -11,8 +14,6 @@ import ( | @@ -11,8 +14,6 @@ import ( | ||
| 11 | "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/domain" | 14 | "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/domain" |
| 12 | "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/domainService" | 15 | "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" | 16 | "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/utils" |
| 14 | - "path/filepath" | ||
| 15 | - "time" | ||
| 16 | ) | 17 | ) |
| 17 | 18 | ||
| 18 | // 文件服务 | 19 | // 文件服务 |
| @@ -34,14 +35,15 @@ func (fileService *FileService) CreateFile(ctx *domain.Context, createFileComman | @@ -34,14 +35,15 @@ func (fileService *FileService) CreateFile(ctx *domain.Context, createFileComman | ||
| 34 | defer func() { | 35 | defer func() { |
| 35 | transactionContext.RollbackTransaction() | 36 | transactionContext.RollbackTransaction() |
| 36 | }() | 37 | }() |
| 37 | - newFile := &domain.File{ | ||
| 38 | - FileType: domain.SourceFile.ToString(), | ||
| 39 | - FileInfo: &domain.FileInfo{ | 38 | + fileInfo := &domain.FileInfo{ |
| 40 | Name: domain.FileName(createFileCommand.Name), | 39 | Name: domain.FileName(createFileCommand.Name), |
| 41 | Url: createFileCommand.Url, | 40 | Url: createFileCommand.Url, |
| 42 | FileSize: createFileCommand.FileSize, | 41 | FileSize: createFileCommand.FileSize, |
| 43 | Ext: filepath.Ext(createFileCommand.Name), | 42 | Ext: filepath.Ext(createFileCommand.Name), |
| 44 | - }, | 43 | + } |
| 44 | + newFile := &domain.File{ | ||
| 45 | + FileType: domain.SourceFile.ToString(), | ||
| 46 | + FileInfo: fileInfo, | ||
| 45 | SourceFileId: 0, | 47 | SourceFileId: 0, |
| 46 | //Operator: "", | 48 | //Operator: "", |
| 47 | CreatedAt: time.Now(), | 49 | CreatedAt: time.Now(), |
| @@ -49,6 +51,18 @@ func (fileService *FileService) CreateFile(ctx *domain.Context, createFileComman | @@ -49,6 +51,18 @@ func (fileService *FileService) CreateFile(ctx *domain.Context, createFileComman | ||
| 49 | Context: ctx, | 51 | Context: ctx, |
| 50 | } | 52 | } |
| 51 | fileRepository, _, _ := factory.FastPgFile(transactionContext, 0) | 53 | fileRepository, _, _ := factory.FastPgFile(transactionContext, 0) |
| 54 | + | ||
| 55 | + // 文件名相同进行替换 | ||
| 56 | + if oldFile, findOldFileErr := fileRepository.FindOne(map[string]interface{}{ | ||
| 57 | + "context": ctx, | ||
| 58 | + "fileName": fileInfo.Name, | ||
| 59 | + "fileType": domain.SourceFile.ToString(), | ||
| 60 | + }); oldFile != nil && findOldFileErr == nil { | ||
| 61 | + oldFile.FileInfo = fileInfo | ||
| 62 | + oldFile.UpdatedAt = time.Now() | ||
| 63 | + newFile = oldFile | ||
| 64 | + } | ||
| 65 | + | ||
| 52 | file, err := fileRepository.Save(newFile) | 66 | file, err := fileRepository.Save(newFile) |
| 53 | if err != nil { | 67 | if err != nil { |
| 54 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | 68 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) |
| @@ -92,7 +106,7 @@ func (fileService *FileService) GetFile(getFileQuery *query.GetFileQuery) (inter | @@ -92,7 +106,7 @@ func (fileService *FileService) GetFile(getFileQuery *query.GetFileQuery) (inter | ||
| 92 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | 106 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) |
| 93 | } | 107 | } |
| 94 | if file == nil { | 108 | if file == nil { |
| 95 | - return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(getFileQuery.FileId))) | 109 | + return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%d", getFileQuery.FileId)) |
| 96 | } else { | 110 | } else { |
| 97 | if err := transactionContext.CommitTransaction(); err != nil { | 111 | if err := transactionContext.CommitTransaction(); err != nil { |
| 98 | return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | 112 | return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) |
| @@ -207,7 +221,7 @@ func (fileService *FileService) RemoveFile(ctx *domain.Context, removeFileComman | @@ -207,7 +221,7 @@ func (fileService *FileService) RemoveFile(ctx *domain.Context, removeFileComman | ||
| 207 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | 221 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) |
| 208 | } | 222 | } |
| 209 | if file == nil { | 223 | if file == nil { |
| 210 | - return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(removeFileCommand.FileId))) | 224 | + return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%d", removeFileCommand.FileId)) |
| 211 | } | 225 | } |
| 212 | deleteFileService, _ := factory.CreateDeleteFileService(transactionContext) | 226 | deleteFileService, _ := factory.CreateDeleteFileService(transactionContext) |
| 213 | err = deleteFileService.DeleteFiles(ctx, file) | 227 | err = deleteFileService.DeleteFiles(ctx, file) |
| @@ -248,7 +262,7 @@ func (fileService *FileService) UpdateFile(updateFileCommand *command.UpdateFile | @@ -248,7 +262,7 @@ func (fileService *FileService) UpdateFile(updateFileCommand *command.UpdateFile | ||
| 248 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | 262 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) |
| 249 | } | 263 | } |
| 250 | if file == nil { | 264 | if file == nil { |
| 251 | - return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updateFileCommand.FileId))) | 265 | + return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%d", updateFileCommand.FileId)) |
| 252 | } | 266 | } |
| 253 | if err := file.Update(tool_funs.SimpleStructToMap(updateFileCommand)); err != nil { | 267 | if err := file.Update(tool_funs.SimpleStructToMap(updateFileCommand)); err != nil { |
| 254 | return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error()) | 268 | return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error()) |
| @@ -30,22 +30,12 @@ func (tableService *TableService) ExportDataTable(ctx *domain.Context, cmd *comm | @@ -30,22 +30,12 @@ func (tableService *TableService) ExportDataTable(ctx *domain.Context, cmd *comm | ||
| 30 | transactionContext.RollbackTransaction() | 30 | transactionContext.RollbackTransaction() |
| 31 | }() | 31 | }() |
| 32 | 32 | ||
| 33 | - // TODO:加锁 同一个用户同一个时间点只允许一次下载 | ||
| 34 | - | ||
| 35 | var table *domain.Table | 33 | var table *domain.Table |
| 36 | //var mainTable *domain.Table | 34 | //var mainTable *domain.Table |
| 37 | _, table, err = factory.FastPgTable(transactionContext, cmd.TableId) | 35 | _, table, err = factory.FastPgTable(transactionContext, cmd.TableId) |
| 38 | if err != nil { | 36 | if err != nil { |
| 39 | return nil, factory.FastError(err) | 37 | return nil, factory.FastError(err) |
| 40 | } | 38 | } |
| 41 | - //if table.TableType == domain.SubTable.ToString() { | ||
| 42 | - // _, mainTable, err = factory.FastPgTable(transactionContext, cmd.TableId) | ||
| 43 | - // if err != nil { | ||
| 44 | - // return nil, factory.FastError(err) | ||
| 45 | - // } | ||
| 46 | - //} else { | ||
| 47 | - // mainTable = table | ||
| 48 | - //} | ||
| 49 | var options = starrocks.QueryOptions{ | 39 | var options = starrocks.QueryOptions{ |
| 50 | TableName: table.SQLName, | 40 | TableName: table.SQLName, |
| 51 | Select: table.Fields(true), | 41 | Select: table.Fields(true), |
| @@ -91,7 +81,6 @@ func (tableService *TableService) ExportDataTableV2(ctx *domain.Context, cmd *co | @@ -91,7 +81,6 @@ func (tableService *TableService) ExportDataTableV2(ctx *domain.Context, cmd *co | ||
| 91 | transactionContext.RollbackTransaction() | 81 | transactionContext.RollbackTransaction() |
| 92 | }() | 82 | }() |
| 93 | 83 | ||
| 94 | - // TODO:加锁 同一个用户同一个时间点只允许一次下载 | ||
| 95 | locker := redis.NewLock(redis.KeyExportTable(ctx, cmd.TableId)) | 84 | locker := redis.NewLock(redis.KeyExportTable(ctx, cmd.TableId)) |
| 96 | locker.SetExpire(60 * 2) | 85 | locker.SetExpire(60 * 2) |
| 97 | ok, err := locker.Acquire() | 86 | ok, err := locker.Acquire() |
| @@ -23,15 +23,6 @@ func (tableService *TableService) RowEdit(ctx *domain.Context, cmd *command.RowE | @@ -23,15 +23,6 @@ func (tableService *TableService) RowEdit(ctx *domain.Context, cmd *command.RowE | ||
| 23 | defer func() { | 23 | defer func() { |
| 24 | transactionContext.RollbackTransaction() | 24 | transactionContext.RollbackTransaction() |
| 25 | }() | 25 | }() |
| 26 | - | ||
| 27 | - //editDataService, _ := factory.CreateTableEditDataService(transactionContext) | ||
| 28 | - //_, err = editDataService.RowEdit(ctx, domain.EditDataRequest{ | ||
| 29 | - // TableId: cmd.TableId, | ||
| 30 | - // Where: cmd.Where, | ||
| 31 | - // UpdateList: cmd.UpdateList, | ||
| 32 | - // AddList: cmd.AddList, | ||
| 33 | - // RemoveList: cmd.RemoveList, | ||
| 34 | - //}) | ||
| 35 | if err != nil { | 26 | if err != nil { |
| 36 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | 27 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) |
| 37 | } | 28 | } |
| @@ -16,27 +16,6 @@ import ( | @@ -16,27 +16,6 @@ import ( | ||
| 16 | type TableService struct { | 16 | type TableService struct { |
| 17 | } | 17 | } |
| 18 | 18 | ||
| 19 | -// 批量编辑分表 | ||
| 20 | -//func (tableService *TableService) BatchEditSubTable(batchEditSubTableCommand *command.BatchEditSubTableCommand) (interface{}, error) { | ||
| 21 | -// if err := batchEditSubTableCommand.ValidateCommand(); err != nil { | ||
| 22 | -// return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | ||
| 23 | -// } | ||
| 24 | -// transactionContext, err := factory.CreateTransactionContext(nil) | ||
| 25 | -// if err != nil { | ||
| 26 | -// return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
| 27 | -// } | ||
| 28 | -// if err := transactionContext.StartTransaction(); err != nil { | ||
| 29 | -// return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
| 30 | -// } | ||
| 31 | -// defer func() { | ||
| 32 | -// transactionContext.RollbackTransaction() | ||
| 33 | -// }() | ||
| 34 | -// if err := transactionContext.CommitTransaction(); err != nil { | ||
| 35 | -// return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
| 36 | -// } | ||
| 37 | -// return nil, nil | ||
| 38 | -//} | ||
| 39 | - | ||
| 40 | // 表复制 | 19 | // 表复制 |
| 41 | func (tableService *TableService) CopyDataTable(ctx *domain.Context, cmd *command.CopyDataTableCommand) (interface{}, error) { | 20 | func (tableService *TableService) CopyDataTable(ctx *domain.Context, cmd *command.CopyDataTableCommand) (interface{}, error) { |
| 42 | if err := cmd.ValidateCommand(); err != nil { | 21 | if err := cmd.ValidateCommand(); err != nil { |
| @@ -53,7 +32,7 @@ func (tableService *TableService) CopyDataTable(ctx *domain.Context, cmd *comman | @@ -53,7 +32,7 @@ func (tableService *TableService) CopyDataTable(ctx *domain.Context, cmd *comman | ||
| 53 | transactionContext.RollbackTransaction() | 32 | transactionContext.RollbackTransaction() |
| 54 | }() | 33 | }() |
| 55 | 34 | ||
| 56 | - copyDataTableService, err := factory.CreateCopyDataTableService(transactionContext) | 35 | + copyDataTableService, _ := factory.CreateCopyDataTableService(transactionContext) |
| 57 | 36 | ||
| 58 | if _, err = copyDataTableService.CopyTable(ctx, cmd.TableId, cmd.TableName); err != nil { | 37 | if _, err = copyDataTableService.CopyTable(ctx, cmd.TableId, cmd.TableName); err != nil { |
| 59 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | 38 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) |
| @@ -262,27 +241,6 @@ func (tableService *TableService) Search(searchQuery *query.SearchTableQuery) (i | @@ -262,27 +241,6 @@ func (tableService *TableService) Search(searchQuery *query.SearchTableQuery) (i | ||
| 262 | }, nil | 241 | }, nil |
| 263 | } | 242 | } |
| 264 | 243 | ||
| 265 | -// 表拆分 | ||
| 266 | -//func (tableService *TableService) SplitDataTable(splitDataTableCommand *command.SplitDataTableCommand) (interface{}, error) { | ||
| 267 | -// if err := splitDataTableCommand.ValidateCommand(); err != nil { | ||
| 268 | -// return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | ||
| 269 | -// } | ||
| 270 | -// transactionContext, err := factory.CreateTransactionContext(nil) | ||
| 271 | -// if err != nil { | ||
| 272 | -// return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
| 273 | -// } | ||
| 274 | -// if err := transactionContext.StartTransaction(); err != nil { | ||
| 275 | -// return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
| 276 | -// } | ||
| 277 | -// defer func() { | ||
| 278 | -// transactionContext.RollbackTransaction() | ||
| 279 | -// }() | ||
| 280 | -// if err := transactionContext.CommitTransaction(); err != nil { | ||
| 281 | -// return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
| 282 | -// } | ||
| 283 | -// return nil, nil | ||
| 284 | -//} | ||
| 285 | - | ||
| 286 | // 更新表服务 | 244 | // 更新表服务 |
| 287 | func (tableService *TableService) UpdateTable(updateTableCommand *command.UpdateTableCommand) (interface{}, error) { | 245 | func (tableService *TableService) UpdateTable(updateTableCommand *command.UpdateTableCommand) (interface{}, error) { |
| 288 | if err := updateTableCommand.ValidateCommand(); err != nil { | 246 | if err := updateTableCommand.ValidateCommand(); err != nil { |
| @@ -311,7 +269,7 @@ func (tableService *TableService) UpdateTable(updateTableCommand *command.Update | @@ -311,7 +269,7 @@ func (tableService *TableService) UpdateTable(updateTableCommand *command.Update | ||
| 311 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | 269 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) |
| 312 | } | 270 | } |
| 313 | if table == nil { | 271 | if table == nil { |
| 314 | - return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updateTableCommand.TableId))) | 272 | + return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%d", updateTableCommand.TableId)) |
| 315 | } | 273 | } |
| 316 | if err := table.Update(tool_funs.SimpleStructToMap(updateTableCommand)); err != nil { | 274 | if err := table.Update(tool_funs.SimpleStructToMap(updateTableCommand)); err != nil { |
| 317 | return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error()) | 275 | return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error()) |
| @@ -17,6 +17,7 @@ type ByteLibService interface { | @@ -17,6 +17,7 @@ type ByteLibService interface { | ||
| 17 | type ( | 17 | type ( |
| 18 | ReqLoadDataTable struct { | 18 | ReqLoadDataTable struct { |
| 19 | FileId int `json:"file_id"` | 19 | FileId int `json:"file_id"` |
| 20 | + FileType string `json:"file_type"` | ||
| 20 | FileName string `json:"file_name"` | 21 | FileName string `json:"file_name"` |
| 21 | Url string `json:"url"` | 22 | Url string `json:"url"` |
| 22 | Ext string `json:"ext"` | 23 | Ext string `json:"ext"` |
| @@ -29,10 +29,18 @@ type DataCheckoutTables struct { | @@ -29,10 +29,18 @@ type DataCheckoutTables struct { | ||
| 29 | } | 29 | } |
| 30 | 30 | ||
| 31 | func NewRequestCheckoutTablesQuery(param domain.ReqLoadDataTable) RequestCheckoutTablesQuery { | 31 | func NewRequestCheckoutTablesQuery(param domain.ReqLoadDataTable) RequestCheckoutTablesQuery { |
| 32 | + isSourceFile := true | ||
| 33 | + if param.FileType == domain.VerifiedFile.ToString() { | ||
| 34 | + isSourceFile = false | ||
| 35 | + } | ||
| 36 | + tableFileUrl := "" | ||
| 37 | + if param.IsFromOriginalTable { | ||
| 38 | + tableFileUrl = param.TableFileUrl | ||
| 39 | + } | ||
| 32 | return RequestCheckoutTablesQuery{ | 40 | return RequestCheckoutTablesQuery{ |
| 33 | OriginalTableId: param.OriginalTableId, | 41 | OriginalTableId: param.OriginalTableId, |
| 34 | - IsFromOriginalTable: param.IsFromOriginalTable, | ||
| 35 | - TableFileUrl: param.TableFileUrl, | 42 | + IsFromOriginalTable: isSourceFile, |
| 43 | + TableFileUrl: tableFileUrl, | ||
| 36 | ColumnSchemas: param.ColumnSchemas, | 44 | ColumnSchemas: param.ColumnSchemas, |
| 37 | PageNumber: param.PageNumber, | 45 | PageNumber: param.PageNumber, |
| 38 | PageSize: param.PageSize, | 46 | PageSize: param.PageSize, |
| @@ -61,8 +69,8 @@ func NewRequestCheckoutTablesPreProccess(param domain.ReqEditDataTable) RequestC | @@ -61,8 +69,8 @@ func NewRequestCheckoutTablesPreProccess(param domain.ReqEditDataTable) RequestC | ||
| 61 | ColumnSchemas: FieldsToColumnSchemas(param.Fields), | 69 | ColumnSchemas: FieldsToColumnSchemas(param.Fields), |
| 62 | PreProccessActionName: param.Action, | 70 | PreProccessActionName: param.Action, |
| 63 | PreProccessActionParameterValues: param.Params, | 71 | PreProccessActionParameterValues: param.Params, |
| 64 | - PageNumber: param.PageNumber, | ||
| 65 | - PageSize: param.PageSize, | 72 | + PageNumber: 1, //param.PageNumber, |
| 73 | + PageSize: 20, //param.PageSize, | ||
| 66 | QueryParameters: []interface{}{}, | 74 | QueryParameters: []interface{}{}, |
| 67 | SortParameters: make(map[string]interface{}), | 75 | SortParameters: make(map[string]interface{}), |
| 68 | } | 76 | } |
| @@ -104,7 +112,7 @@ func DomainFieldsToColumnSchemas(fields []*domain.Field) []domain.ColumnSchema { | @@ -104,7 +112,7 @@ func DomainFieldsToColumnSchemas(fields []*domain.Field) []domain.ColumnSchema { | ||
| 104 | for _, f := range fields { | 112 | for _, f := range fields { |
| 105 | result = append(result, domain.ColumnSchema{ | 113 | result = append(result, domain.ColumnSchema{ |
| 106 | ColumnName: f.Name, | 114 | ColumnName: f.Name, |
| 107 | - ColumnType: f.SQLType, | 115 | + ColumnType: f.SQLType, // domain.String.ToString(), |
| 108 | }) | 116 | }) |
| 109 | } | 117 | } |
| 110 | return result | 118 | return result |
| @@ -31,7 +31,8 @@ func (ptr *FlushDataTableService) Flush(ctx *domain.Context, fileId int, table * | @@ -31,7 +31,8 @@ func (ptr *FlushDataTableService) Flush(ctx *domain.Context, fileId int, table * | ||
| 31 | // New Table | 31 | // New Table |
| 32 | table = NewTable(domain.ExcelTable, file.FileInfo.Name, table.DataFields, table.RowCount).WithContext(ctx) | 32 | table = NewTable(domain.ExcelTable, file.FileInfo.Name, table.DataFields, table.RowCount).WithContext(ctx) |
| 33 | // 通知底层保存、进行回调 | 33 | // 通知底层保存、进行回调 |
| 34 | - response, _ := ByteCore.SaveTable(domain.ReqSaveTable{FileId: fileId}) | 34 | + var response *domain.DataSaveTable |
| 35 | + response, err = ByteCore.SaveTable(domain.ReqSaveTable{FileId: fileId}) | ||
| 35 | if err != nil { | 36 | if err != nil { |
| 36 | return nil, err | 37 | return nil, err |
| 37 | } | 38 | } |
| @@ -90,31 +91,28 @@ func (ptr *FlushDataTableService) flushSourceFile(ctx *domain.Context, table *do | @@ -90,31 +91,28 @@ func (ptr *FlushDataTableService) flushSourceFile(ctx *domain.Context, table *do | ||
| 90 | 91 | ||
| 91 | func (ptr *FlushDataTableService) flushVerifiedFile(ctx *domain.Context, table *domain.Table, file *domain.File, sourceFile *domain.File, fileRepository domain.FileRepository, url string) error { | 92 | func (ptr *FlushDataTableService) flushVerifiedFile(ctx *domain.Context, table *domain.Table, file *domain.File, sourceFile *domain.File, fileRepository domain.FileRepository, url string) error { |
| 92 | var err error | 93 | var err error |
| 93 | - temporaryFileTableId := table.TableId | ||
| 94 | - // 校验文件对应的表更新 | ||
| 95 | - table.TableId = file.FileInfo.TableId | ||
| 96 | // 追加日志到校验文件 | 94 | // 追加日志到校验文件 |
| 97 | if err = dao.ChangeStepLogOwner(ptr.transactionContext, file.FileId, sourceFile.FileId); err != nil { | 95 | if err = dao.ChangeStepLogOwner(ptr.transactionContext, file.FileId, sourceFile.FileId); err != nil { |
| 98 | return err | 96 | return err |
| 99 | } | 97 | } |
| 100 | sourceFile.UpdateFileUrl(url) | 98 | sourceFile.UpdateFileUrl(url) |
| 101 | - if sourceFile, err = fileRepository.Save(sourceFile); err != nil { | 99 | + if _, err = fileRepository.Save(sourceFile); err != nil { |
| 102 | return err | 100 | return err |
| 103 | } | 101 | } |
| 104 | // 删除中间文件 | 102 | // 删除中间文件 |
| 105 | if err = dao.FileDelete(ptr.transactionContext, file.FileId, domain.TemporaryFile); err != nil { | 103 | if err = dao.FileDelete(ptr.transactionContext, file.FileId, domain.TemporaryFile); err != nil { |
| 106 | return err | 104 | return err |
| 107 | } | 105 | } |
| 108 | - // 删除中间表 | ||
| 109 | - if err = dao.TableDelete(ptr.transactionContext, temporaryFileTableId, domain.ExcelTable); err != nil { | ||
| 110 | - return err | ||
| 111 | - } | ||
| 112 | - if _, err = fileRepository.Save(sourceFile); err != nil { | 106 | + // 更新表信息 |
| 107 | + tableRepository, _ := repository.NewTableRepository(ptr.transactionContext) | ||
| 108 | + sourceTable, err := tableRepository.FindOne(map[string]interface{}{"tableId": sourceFile.FileInfo.TableId}) | ||
| 109 | + if err != nil { | ||
| 113 | return err | 110 | return err |
| 114 | } | 111 | } |
| 115 | - // 更新 | ||
| 116 | - tableRepository, _ := repository.NewTableRepository(ptr.transactionContext) | ||
| 117 | - table, err = tableRepository.Save(table) | 112 | + sourceTable.DataFields = table.DataFields |
| 113 | + sourceTable.DataFieldIndex = table.DataFieldIndex | ||
| 114 | + sourceTable.UpdatedAt = time.Now() | ||
| 115 | + _, err = tableRepository.Save(sourceTable) | ||
| 118 | if err != nil { | 116 | if err != nil { |
| 119 | return err | 117 | return err |
| 120 | } | 118 | } |
| @@ -41,7 +41,7 @@ func (ptr *PreviewDataTableService) Preview(ctx *domain.Context, fileId int, fie | @@ -41,7 +41,7 @@ func (ptr *PreviewDataTableService) Preview(ctx *domain.Context, fileId int, fie | ||
| 41 | Url: file.FileInfo.Url, | 41 | Url: file.FileInfo.Url, |
| 42 | Ext: file.FileInfo.Ext, | 42 | Ext: file.FileInfo.Ext, |
| 43 | Where: where, | 43 | Where: where, |
| 44 | - | 44 | + //FileType: file.FileType, |
| 45 | OriginalTableId: fmt.Sprintf("%v", file.FileId), | 45 | OriginalTableId: fmt.Sprintf("%v", file.FileId), |
| 46 | IsFromOriginalTable: isSourceFile, | 46 | IsFromOriginalTable: isSourceFile, |
| 47 | TableFileUrl: fileUrl, | 47 | TableFileUrl: fileUrl, |
| @@ -32,11 +32,17 @@ func (ptr *CopyDataTableService) CopyTable(ctx *domain.Context, tableId int, tab | @@ -32,11 +32,17 @@ func (ptr *CopyDataTableService) CopyTable(ctx *domain.Context, tableId int, tab | ||
| 32 | return nil, fmt.Errorf("主表、分表才允许复制") | 32 | return nil, fmt.Errorf("主表、分表才允许复制") |
| 33 | } | 33 | } |
| 34 | var mainTable *domain.Table | 34 | var mainTable *domain.Table |
| 35 | + dataFields := table.DataFields | ||
| 35 | if table.TableType == domain.SubTable.ToString() { | 36 | if table.TableType == domain.SubTable.ToString() { |
| 36 | mainTable, err = tableRepository.FindOne(map[string]interface{}{"tableId": table.ParentId}) | 37 | mainTable, err = tableRepository.FindOne(map[string]interface{}{"tableId": table.ParentId}) |
| 37 | if err != nil { | 38 | if err != nil { |
| 38 | return nil, err | 39 | return nil, err |
| 39 | } | 40 | } |
| 41 | + // for i:=range table.ManualFields{ | ||
| 42 | + // f:= table.ManualFields[i].Copy() | ||
| 43 | + // f.Flag = domain.MainTableField | ||
| 44 | + // dataFields = append(dataFields,f) | ||
| 45 | + // } | ||
| 40 | } | 46 | } |
| 41 | // 验证表名是否重复 | 47 | // 验证表名是否重复 |
| 42 | duplicateTable, err := tableRepository.FindOne(map[string]interface{}{"context": ctx, "tableName": tableName}) | 48 | duplicateTable, err := tableRepository.FindOne(map[string]interface{}{"context": ctx, "tableName": tableName}) |
| @@ -44,7 +50,8 @@ func (ptr *CopyDataTableService) CopyTable(ctx *domain.Context, tableId int, tab | @@ -44,7 +50,8 @@ func (ptr *CopyDataTableService) CopyTable(ctx *domain.Context, tableId int, tab | ||
| 44 | return nil, fmt.Errorf("表名称重复") | 50 | return nil, fmt.Errorf("表名称重复") |
| 45 | } | 51 | } |
| 46 | 52 | ||
| 47 | - sideTable := NewCopyTable(domain.SideTable, tableName, table.DataFields, table.RowCount). | 53 | + |
| 54 | + sideTable := NewCopyTable(domain.SideTable, tableName,dataFields, table.RowCount). | ||
| 48 | WithContext(ctx). | 55 | WithContext(ctx). |
| 49 | WithParentId(table.TableId). | 56 | WithParentId(table.TableId). |
| 50 | WithDataFieldIndex(table.DataFieldIndex) | 57 | WithDataFieldIndex(table.DataFieldIndex) |
| @@ -2,28 +2,20 @@ package repository | @@ -2,28 +2,20 @@ package repository | ||
| 2 | 2 | ||
| 3 | import ( | 3 | import ( |
| 4 | "fmt" | 4 | "fmt" |
| 5 | + "time" | ||
| 6 | + | ||
| 5 | "github.com/go-pg/pg/v10" | 7 | "github.com/go-pg/pg/v10" |
| 6 | "github.com/linmadan/egglib-go/persistent/pg/sqlbuilder" | 8 | "github.com/linmadan/egglib-go/persistent/pg/sqlbuilder" |
| 7 | pgTransaction "github.com/linmadan/egglib-go/transaction/pg" | 9 | pgTransaction "github.com/linmadan/egglib-go/transaction/pg" |
| 8 | - "github.com/linmadan/egglib-go/utils/snowflake" | ||
| 9 | "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/domain" | 10 | "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/domain" |
| 10 | "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/pg/models" | 11 | "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/pg/models" |
| 11 | "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/pg/transform" | 12 | "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/pg/transform" |
| 12 | - "time" | ||
| 13 | ) | 13 | ) |
| 14 | 14 | ||
| 15 | type FileRepository struct { | 15 | type FileRepository struct { |
| 16 | transactionContext *pgTransaction.TransactionContext | 16 | transactionContext *pgTransaction.TransactionContext |
| 17 | } | 17 | } |
| 18 | 18 | ||
| 19 | -func (repository *FileRepository) nextIdentify() (int64, error) { | ||
| 20 | - IdWorker, err := snowflake.NewIdWorker(1) | ||
| 21 | - if err != nil { | ||
| 22 | - return 0, err | ||
| 23 | - } | ||
| 24 | - id, err := IdWorker.NextId() | ||
| 25 | - return id, err | ||
| 26 | -} | ||
| 27 | func (repository *FileRepository) Save(file *domain.File) (*domain.File, error) { | 19 | func (repository *FileRepository) Save(file *domain.File) (*domain.File, error) { |
| 28 | sqlBuildFields := []string{ | 20 | sqlBuildFields := []string{ |
| 29 | "file_id", | 21 | "file_id", |
| @@ -116,6 +108,9 @@ func (repository *FileRepository) FindOne(queryOptions map[string]interface{}) ( | @@ -116,6 +108,9 @@ func (repository *FileRepository) FindOne(queryOptions map[string]interface{}) ( | ||
| 116 | fileModel := new(models.File) | 108 | fileModel := new(models.File) |
| 117 | query := sqlbuilder.BuildQuery(tx.Model(fileModel), queryOptions) | 109 | query := sqlbuilder.BuildQuery(tx.Model(fileModel), queryOptions) |
| 118 | query.SetWhereByQueryOption("file.file_id = ?", "fileId") | 110 | query.SetWhereByQueryOption("file.file_id = ?", "fileId") |
| 111 | + WhereContext(query, queryOptions) | ||
| 112 | + query.SetWhereByQueryOption("file_info->>'name' = ?", "fileName") | ||
| 113 | + query.SetWhereByQueryOption("file_type = ?", "fileType") | ||
| 119 | if err := query.First(); err != nil { | 114 | if err := query.First(); err != nil { |
| 120 | if err.Error() == "pg: no rows in result set" { | 115 | if err.Error() == "pg: no rows in result set" { |
| 121 | return nil, domain.ErrorNotFound | 116 | return nil, domain.ErrorNotFound |
| @@ -150,7 +145,7 @@ func (repository *FileRepository) Find(queryOptions map[string]interface{}) (int | @@ -150,7 +145,7 @@ func (repository *FileRepository) Find(queryOptions map[string]interface{}) (int | ||
| 150 | query.Where(`updated_at<?`, v.(time.Time)) | 145 | query.Where(`updated_at<?`, v.(time.Time)) |
| 151 | } | 146 | } |
| 152 | query.SetOffsetAndLimit(20) | 147 | query.SetOffsetAndLimit(20) |
| 153 | - query.SetOrderDirect("file_id", "DESC") | 148 | + query.SetOrderDirect("updated_at", "DESC") |
| 154 | if count, err := query.SelectAndCount(); err != nil { | 149 | if count, err := query.SelectAndCount(); err != nil { |
| 155 | return 0, files, err | 150 | return 0, files, err |
| 156 | } else { | 151 | } else { |
| @@ -9,7 +9,6 @@ import ( | @@ -9,7 +9,6 @@ import ( | ||
| 9 | 9 | ||
| 10 | "github.com/linmadan/egglib-go/persistent/pg/sqlbuilder" | 10 | "github.com/linmadan/egglib-go/persistent/pg/sqlbuilder" |
| 11 | pgTransaction "github.com/linmadan/egglib-go/transaction/pg" | 11 | pgTransaction "github.com/linmadan/egglib-go/transaction/pg" |
| 12 | - "github.com/linmadan/egglib-go/utils/snowflake" | ||
| 13 | "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/domain" | 12 | "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/domain" |
| 14 | "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/pg/models" | 13 | "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/pg/models" |
| 15 | "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/pg/transform" | 14 | "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/pg/transform" |
| @@ -19,14 +18,6 @@ type LogRepository struct { | @@ -19,14 +18,6 @@ type LogRepository struct { | ||
| 19 | transactionContext *pgTransaction.TransactionContext | 18 | transactionContext *pgTransaction.TransactionContext |
| 20 | } | 19 | } |
| 21 | 20 | ||
| 22 | -func (repository *LogRepository) nextIdentify() (int64, error) { | ||
| 23 | - IdWorker, err := snowflake.NewIdWorker(1) | ||
| 24 | - if err != nil { | ||
| 25 | - return 0, err | ||
| 26 | - } | ||
| 27 | - id, err := IdWorker.NextId() | ||
| 28 | - return id, err | ||
| 29 | -} | ||
| 30 | func (repository *LogRepository) Save(log *domain.Log) (*domain.Log, error) { | 21 | func (repository *LogRepository) Save(log *domain.Log) (*domain.Log, error) { |
| 31 | sqlBuildFields := []string{ | 22 | sqlBuildFields := []string{ |
| 32 | "log_id", | 23 | "log_id", |
| @@ -164,7 +155,7 @@ func (repository *LogRepository) Find(queryOptions map[string]interface{}) (int6 | @@ -164,7 +155,7 @@ func (repository *LogRepository) Find(queryOptions map[string]interface{}) (int6 | ||
| 164 | query.SetWhereByQueryOption(" created_at < ?", "endTime") | 155 | query.SetWhereByQueryOption(" created_at < ?", "endTime") |
| 165 | } | 156 | } |
| 166 | 157 | ||
| 167 | - query.SetOffsetAndLimit(20) | 158 | + SetOffsetAndLimit(query,queryOptions,20) |
| 168 | if v, ok := queryOptions["sortByLogId"]; ok && len(v.(string)) > 0 { | 159 | if v, ok := queryOptions["sortByLogId"]; ok && len(v.(string)) > 0 { |
| 169 | query.SetOrderDirect("log_id", v.(string)) | 160 | query.SetOrderDirect("log_id", v.(string)) |
| 170 | } else { | 161 | } else { |
| @@ -6,7 +6,6 @@ import ( | @@ -6,7 +6,6 @@ import ( | ||
| 6 | 6 | ||
| 7 | "github.com/linmadan/egglib-go/persistent/pg/sqlbuilder" | 7 | "github.com/linmadan/egglib-go/persistent/pg/sqlbuilder" |
| 8 | pgTransaction "github.com/linmadan/egglib-go/transaction/pg" | 8 | pgTransaction "github.com/linmadan/egglib-go/transaction/pg" |
| 9 | - "github.com/linmadan/egglib-go/utils/snowflake" | ||
| 10 | "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/domain" | 9 | "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/domain" |
| 11 | "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" |
| 12 | "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/pg/transform" | 11 | "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/pg/transform" |
| @@ -16,14 +15,6 @@ type MappingRuleRepository struct { | @@ -16,14 +15,6 @@ type MappingRuleRepository struct { | ||
| 16 | transactionContext *pgTransaction.TransactionContext | 15 | transactionContext *pgTransaction.TransactionContext |
| 17 | } | 16 | } |
| 18 | 17 | ||
| 19 | -func (repository *MappingRuleRepository) nextIdentify() (int64, error) { | ||
| 20 | - IdWorker, err := snowflake.NewIdWorker(1) | ||
| 21 | - if err != nil { | ||
| 22 | - return 0, err | ||
| 23 | - } | ||
| 24 | - id, err := IdWorker.NextId() | ||
| 25 | - return id, err | ||
| 26 | -} | ||
| 27 | func (repository *MappingRuleRepository) Save(mappingRule *domain.MappingRule) (*domain.MappingRule, error) { | 18 | func (repository *MappingRuleRepository) Save(mappingRule *domain.MappingRule) (*domain.MappingRule, error) { |
| 28 | sqlBuildFields := []string{ | 19 | sqlBuildFields := []string{ |
| 29 | "mapping_rule_id", | 20 | "mapping_rule_id", |
| 1 | package repository | 1 | package repository |
| 2 | 2 | ||
| 3 | import ( | 3 | import ( |
| 4 | + | ||
| 4 | "github.com/linmadan/egglib-go/persistent/pg/sqlbuilder" | 5 | "github.com/linmadan/egglib-go/persistent/pg/sqlbuilder" |
| 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 | + "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/utils" | ||
| 6 | ) | 8 | ) |
| 7 | 9 | ||
| 8 | -func WhereContext(query *sqlbuilder.Query, queryOptions map[string]interface{}) { | 10 | +func WhereContext(query *sqlbuilder.Query, queryOptions map[string]interface{}) *sqlbuilder.Query{ |
| 9 | if _, ok := queryOptions["context"]; !ok { | 11 | if _, ok := queryOptions["context"]; !ok { |
| 10 | - return | 12 | + return query |
| 11 | } | 13 | } |
| 12 | context := queryOptions["context"].(*domain.Context) | 14 | context := queryOptions["context"].(*domain.Context) |
| 13 | query.Where("context->'companyId'='?'", context.CompanyId) | 15 | query.Where("context->'companyId'='?'", context.CompanyId) |
| 16 | + return query | ||
| 17 | +} | ||
| 18 | + | ||
| 19 | + | ||
| 20 | +func SetOffsetAndLimit(query *sqlbuilder.Query, queryOptions map[string]interface{},defaultLimit int) { | ||
| 21 | + pageNumber,pnOk:=queryOptions["pageNumber"] | ||
| 22 | + pageSize,psOk :=queryOptions["pageSize"] | ||
| 23 | + if pnOk && psOk{ | ||
| 24 | + iPageNumber:=utils.NumberString(utils.AssertString(pageNumber)).MustInt() | ||
| 25 | + iPageSize:=utils.NumberString(utils.AssertString(pageSize)).MustInt() | ||
| 26 | + queryOptions["limit"] = iPageSize | ||
| 27 | + queryOptions["offset"] = (iPageSize*(iPageNumber-1)) | ||
| 28 | + } | ||
| 29 | + query.SetOffsetAndLimit(defaultLimit) | ||
| 14 | } | 30 | } |
| @@ -6,7 +6,6 @@ import ( | @@ -6,7 +6,6 @@ import ( | ||
| 6 | 6 | ||
| 7 | "github.com/linmadan/egglib-go/persistent/pg/sqlbuilder" | 7 | "github.com/linmadan/egglib-go/persistent/pg/sqlbuilder" |
| 8 | pgTransaction "github.com/linmadan/egglib-go/transaction/pg" | 8 | pgTransaction "github.com/linmadan/egglib-go/transaction/pg" |
| 9 | - "github.com/linmadan/egglib-go/utils/snowflake" | ||
| 10 | "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/domain" | 9 | "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/domain" |
| 11 | "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" |
| 12 | "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/pg/transform" | 11 | "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/pg/transform" |
| @@ -16,14 +15,6 @@ type TableRepository struct { | @@ -16,14 +15,6 @@ type TableRepository struct { | ||
| 16 | transactionContext *pgTransaction.TransactionContext | 15 | transactionContext *pgTransaction.TransactionContext |
| 17 | } | 16 | } |
| 18 | 17 | ||
| 19 | -func (repository *TableRepository) nextIdentify() (int64, error) { | ||
| 20 | - IdWorker, err := snowflake.NewIdWorker(1) | ||
| 21 | - if err != nil { | ||
| 22 | - return 0, err | ||
| 23 | - } | ||
| 24 | - id, err := IdWorker.NextId() | ||
| 25 | - return id, err | ||
| 26 | -} | ||
| 27 | func (repository *TableRepository) Save(table *domain.Table) (*domain.Table, error) { | 18 | func (repository *TableRepository) Save(table *domain.Table) (*domain.Table, error) { |
| 28 | sqlBuildFields := []string{ | 19 | sqlBuildFields := []string{ |
| 29 | "table_id", | 20 | "table_id", |
| @@ -186,6 +186,10 @@ func queryWithoutLimitOffset(query *gorm.DB, params QueryOptions) { | @@ -186,6 +186,10 @@ func queryWithoutLimitOffset(query *gorm.DB, params QueryOptions) { | ||
| 186 | if len(params.Select) > 0 { | 186 | if len(params.Select) > 0 { |
| 187 | fields := make([]string, 0) | 187 | fields := make([]string, 0) |
| 188 | for _, f := range params.Select { | 188 | for _, f := range params.Select { |
| 189 | + if f.Flag==domain.ManualField{ | ||
| 190 | + fields = append(fields, "'' "+f.SQLName) | ||
| 191 | + continue | ||
| 192 | + } | ||
| 189 | fields = append(fields, f.SQLName) | 193 | fields = append(fields, f.SQLName) |
| 190 | } | 194 | } |
| 191 | query.Select(strings.Join(fields, ",")) | 195 | query.Select(strings.Join(fields, ",")) |
-
请 注册 或 登录 后发表评论