作者 yangfu

fix(core): some bug

... ... @@ -23,6 +23,7 @@ _testmain.go
*.test
.log
.idea
.vscode
app.log
go.sum
... ...
... ... @@ -378,8 +378,8 @@ formatMethod: 格式化方法(1.upper:大写2.lower:小写3.capitalize:首字母
```
separator: 分割符号 ‘|’
splitDirection: 拆分方向(1.left:从左边 2.right:从右边)-separator专属参数
splitCount: 拆分次数-separator专属参数
splitDirection: 拆分方向(1.left:从左边 2.right:从右边)
splitCount: 拆分次数
```
2. 按字符数
... ... @@ -389,7 +389,9 @@ splitCount: 拆分次数-separator专属参数
"action": "split-column",
"params": {
"splitMethod": "char-length",
"charLength": 10
"splitDirection": "left",
"charLength": "10",
"splitCount": "1"
}
}
```
... ... @@ -398,6 +400,8 @@ splitCount: 拆分次数-separator专属参数
```
charLength: 字符长度-char-length专属参数
splitDirection: 拆分方向(1.left:从左边 2.right:从右边)
splitCount: 拆分次数 (拆分策略是重复时:值0或者非1整数)
```
### 提取 extract-column
... ...
... ... @@ -10,6 +10,7 @@ ENABLE_KAFKA_LOG11 = true
HTTPS_PORT = 8143
ALLIED_CREATION_USER_HOST = http://allied-creation-user-dev.fjmaimaimai.com
BYTE_CORE_HOST = http://47.97.5.102:8303
METADATA_BASTION_HOST = http://106.75.231.90:9999
STARROCKS_DB_NAME = character_library
STARROCKS_USER = root
... ...
... ... @@ -26,5 +26,5 @@ func (d *FileDto) Load(f *domain.File) {
d.Url = f.FileInfo.Url
d.FileType = f.FileType
d.Ext = f.FileInfo.Ext
d.Time = xtime.New(f.CreatedAt).Local().Format("2006-01-02 15:04:05")
d.Time = xtime.New(f.UpdatedAt).Local().Format("2006-01-02 15:04:05")
}
... ...
package service
import (
"fmt"
"github.com/linmadan/egglib-go/core/application"
"gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/application/factory"
"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
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
//return dto.NewDataTableDtoDemo(loadDataTableService.GetFileId()), nil
return data, nil
}
... ... @@ -93,6 +94,21 @@ func (fileService *FileService) EditDataTable(ctx *domain.Context, editDataTable
}
editDataTableCommand.Fields = temporaryFile.Fields
editDataTableCommand.ProcessFields = temporaryFile.MatchFields(editDataTableCommand.ProcessFieldNames)
if len(editDataTableCommand.ProcessFields) == 0 {
return nil, factory.FastError(fmt.Errorf("请至少选择一个数据列"))
}
// allowAction := func(fields []*domain.Field, action string) error {
// for _, f := range fields {
// if f.SQLType != string(domain.String) &&
// !(action == domain.RemoveColumn || action == domain.CopyColumn || action == domain.RenameColumn || action == domain.ConvertColumnType) {
// return fmt.Errorf("列【%v】必须先转字符串类型",f.Name)
// }
// }
// return nil
// }
// if err = allowAction(editDataTableCommand.ProcessFields, editDataTableCommand.Action); err != nil {
// return nil, factory.FastError(err)
// }
editDataTableService, _ := factory.CreateEditDataTableService(transactionContext)
response, err := editDataTableService.Edit(ctx, editDataTableCommand.EditTableRequest)
if err != nil {
... ... @@ -120,14 +136,6 @@ func (fileService *FileService) FlushDataTable(ctx *domain.Context, flushDataTab
transactionContext.RollbackTransaction()
}()
flushDataTableService, _ := factory.CreateFlushDataTableService(transactionContext)
//fields := make([]*domain.Field, 0)
//for _, f := range flushDataTableCommand.DataFields {
// fields = append(fields, &domain.Field{
// Name: f.Name,
// SQLType: f.SQLType,
// })
//}
cache := redis.NewFileCacheService()
temporaryFile, err := cache.Get(redis.KeyTemporaryFileInfo(flushDataTableCommand.ObjectId))
if err != nil {
... ...
... ... @@ -2,6 +2,9 @@ package service
import (
"fmt"
"path/filepath"
"time"
"github.com/linmadan/egglib-go/core/application"
"github.com/linmadan/egglib-go/utils/tool_funs"
"gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/application/factory"
... ... @@ -11,8 +14,6 @@ import (
"gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/domainService"
"gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/utils"
"path/filepath"
"time"
)
// 文件服务
... ... @@ -34,14 +35,15 @@ func (fileService *FileService) CreateFile(ctx *domain.Context, createFileComman
defer func() {
transactionContext.RollbackTransaction()
}()
fileInfo := &domain.FileInfo{
Name: domain.FileName(createFileCommand.Name),
Url: createFileCommand.Url,
FileSize: createFileCommand.FileSize,
Ext: filepath.Ext(createFileCommand.Name),
}
newFile := &domain.File{
FileType: domain.SourceFile.ToString(),
FileInfo: &domain.FileInfo{
Name: domain.FileName(createFileCommand.Name),
Url: createFileCommand.Url,
FileSize: createFileCommand.FileSize,
Ext: filepath.Ext(createFileCommand.Name),
},
FileType: domain.SourceFile.ToString(),
FileInfo: fileInfo,
SourceFileId: 0,
//Operator: "",
CreatedAt: time.Now(),
... ... @@ -49,6 +51,18 @@ func (fileService *FileService) CreateFile(ctx *domain.Context, createFileComman
Context: ctx,
}
fileRepository, _, _ := factory.FastPgFile(transactionContext, 0)
// 文件名相同进行替换
if oldFile, findOldFileErr := fileRepository.FindOne(map[string]interface{}{
"context": ctx,
"fileName": fileInfo.Name,
"fileType": domain.SourceFile.ToString(),
}); oldFile != nil && findOldFileErr == nil {
oldFile.FileInfo = fileInfo
oldFile.UpdatedAt = time.Now()
newFile = oldFile
}
file, err := fileRepository.Save(newFile)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
... ... @@ -92,7 +106,7 @@ func (fileService *FileService) GetFile(getFileQuery *query.GetFileQuery) (inter
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if file == nil {
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(getFileQuery.FileId)))
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%d", getFileQuery.FileId))
} else {
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
... ... @@ -207,7 +221,7 @@ func (fileService *FileService) RemoveFile(ctx *domain.Context, removeFileComman
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if file == nil {
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(removeFileCommand.FileId)))
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%d", removeFileCommand.FileId))
}
deleteFileService, _ := factory.CreateDeleteFileService(transactionContext)
err = deleteFileService.DeleteFiles(ctx, file)
... ... @@ -248,7 +262,7 @@ func (fileService *FileService) UpdateFile(updateFileCommand *command.UpdateFile
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if file == nil {
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updateFileCommand.FileId)))
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%d", updateFileCommand.FileId))
}
if err := file.Update(tool_funs.SimpleStructToMap(updateFileCommand)); err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
... ...
... ... @@ -30,22 +30,12 @@ func (tableService *TableService) ExportDataTable(ctx *domain.Context, cmd *comm
transactionContext.RollbackTransaction()
}()
// TODO:加锁 同一个用户同一个时间点只允许一次下载
var table *domain.Table
//var mainTable *domain.Table
_, table, err = factory.FastPgTable(transactionContext, cmd.TableId)
if err != nil {
return nil, factory.FastError(err)
}
//if table.TableType == domain.SubTable.ToString() {
// _, mainTable, err = factory.FastPgTable(transactionContext, cmd.TableId)
// if err != nil {
// return nil, factory.FastError(err)
// }
//} else {
// mainTable = table
//}
var options = starrocks.QueryOptions{
TableName: table.SQLName,
Select: table.Fields(true),
... ... @@ -91,7 +81,6 @@ func (tableService *TableService) ExportDataTableV2(ctx *domain.Context, cmd *co
transactionContext.RollbackTransaction()
}()
// TODO:加锁 同一个用户同一个时间点只允许一次下载
locker := redis.NewLock(redis.KeyExportTable(ctx, cmd.TableId))
locker.SetExpire(60 * 2)
ok, err := locker.Acquire()
... ...
... ... @@ -23,15 +23,6 @@ func (tableService *TableService) RowEdit(ctx *domain.Context, cmd *command.RowE
defer func() {
transactionContext.RollbackTransaction()
}()
//editDataService, _ := factory.CreateTableEditDataService(transactionContext)
//_, err = editDataService.RowEdit(ctx, domain.EditDataRequest{
// TableId: cmd.TableId,
// Where: cmd.Where,
// UpdateList: cmd.UpdateList,
// AddList: cmd.AddList,
// RemoveList: cmd.RemoveList,
//})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
... ...
... ... @@ -16,27 +16,6 @@ import (
type TableService struct {
}
// 批量编辑分表
//func (tableService *TableService) BatchEditSubTable(batchEditSubTableCommand *command.BatchEditSubTableCommand) (interface{}, error) {
// if err := batchEditSubTableCommand.ValidateCommand(); err != nil {
// return nil, application.ThrowError(application.ARG_ERROR, err.Error())
// }
// transactionContext, err := factory.CreateTransactionContext(nil)
// if err != nil {
// return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
// }
// if err := transactionContext.StartTransaction(); err != nil {
// return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
// }
// defer func() {
// transactionContext.RollbackTransaction()
// }()
// if err := transactionContext.CommitTransaction(); err != nil {
// return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
// }
// return nil, nil
//}
// 表复制
func (tableService *TableService) CopyDataTable(ctx *domain.Context, cmd *command.CopyDataTableCommand) (interface{}, error) {
if err := cmd.ValidateCommand(); err != nil {
... ... @@ -53,7 +32,7 @@ func (tableService *TableService) CopyDataTable(ctx *domain.Context, cmd *comman
transactionContext.RollbackTransaction()
}()
copyDataTableService, err := factory.CreateCopyDataTableService(transactionContext)
copyDataTableService, _ := factory.CreateCopyDataTableService(transactionContext)
if _, err = copyDataTableService.CopyTable(ctx, cmd.TableId, cmd.TableName); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
... ... @@ -262,27 +241,6 @@ func (tableService *TableService) Search(searchQuery *query.SearchTableQuery) (i
}, nil
}
// 表拆分
//func (tableService *TableService) SplitDataTable(splitDataTableCommand *command.SplitDataTableCommand) (interface{}, error) {
// if err := splitDataTableCommand.ValidateCommand(); err != nil {
// return nil, application.ThrowError(application.ARG_ERROR, err.Error())
// }
// transactionContext, err := factory.CreateTransactionContext(nil)
// if err != nil {
// return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
// }
// if err := transactionContext.StartTransaction(); err != nil {
// return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
// }
// defer func() {
// transactionContext.RollbackTransaction()
// }()
// if err := transactionContext.CommitTransaction(); err != nil {
// return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
// }
// return nil, nil
//}
// 更新表服务
func (tableService *TableService) UpdateTable(updateTableCommand *command.UpdateTableCommand) (interface{}, error) {
if err := updateTableCommand.ValidateCommand(); err != nil {
... ... @@ -311,7 +269,7 @@ func (tableService *TableService) UpdateTable(updateTableCommand *command.Update
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if table == nil {
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updateTableCommand.TableId)))
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%d", updateTableCommand.TableId))
}
if err := table.Update(tool_funs.SimpleStructToMap(updateTableCommand)); err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
... ...
... ... @@ -17,6 +17,7 @@ type ByteLibService interface {
type (
ReqLoadDataTable struct {
FileId int `json:"file_id"`
FileType string `json:"file_type"`
FileName string `json:"file_name"`
Url string `json:"url"`
Ext string `json:"ext"`
... ...
... ... @@ -29,10 +29,18 @@ type DataCheckoutTables struct {
}
func NewRequestCheckoutTablesQuery(param domain.ReqLoadDataTable) RequestCheckoutTablesQuery {
isSourceFile := true
if param.FileType == domain.VerifiedFile.ToString() {
isSourceFile = false
}
tableFileUrl := ""
if param.IsFromOriginalTable {
tableFileUrl = param.TableFileUrl
}
return RequestCheckoutTablesQuery{
OriginalTableId: param.OriginalTableId,
IsFromOriginalTable: param.IsFromOriginalTable,
TableFileUrl: param.TableFileUrl,
IsFromOriginalTable: isSourceFile,
TableFileUrl: tableFileUrl,
ColumnSchemas: param.ColumnSchemas,
PageNumber: param.PageNumber,
PageSize: param.PageSize,
... ... @@ -61,8 +69,8 @@ func NewRequestCheckoutTablesPreProccess(param domain.ReqEditDataTable) RequestC
ColumnSchemas: FieldsToColumnSchemas(param.Fields),
PreProccessActionName: param.Action,
PreProccessActionParameterValues: param.Params,
PageNumber: param.PageNumber,
PageSize: param.PageSize,
PageNumber: 1, //param.PageNumber,
PageSize: 20, //param.PageSize,
QueryParameters: []interface{}{},
SortParameters: make(map[string]interface{}),
}
... ... @@ -104,7 +112,7 @@ func DomainFieldsToColumnSchemas(fields []*domain.Field) []domain.ColumnSchema {
for _, f := range fields {
result = append(result, domain.ColumnSchema{
ColumnName: f.Name,
ColumnType: f.SQLType,
ColumnType: f.SQLType, // domain.String.ToString(),
})
}
return result
... ...
... ... @@ -31,7 +31,8 @@ func (ptr *FlushDataTableService) Flush(ctx *domain.Context, fileId int, table *
// New Table
table = NewTable(domain.ExcelTable, file.FileInfo.Name, table.DataFields, table.RowCount).WithContext(ctx)
// 通知底层保存、进行回调
response, _ := ByteCore.SaveTable(domain.ReqSaveTable{FileId: fileId})
var response *domain.DataSaveTable
response, err = ByteCore.SaveTable(domain.ReqSaveTable{FileId: fileId})
if err != nil {
return nil, err
}
... ... @@ -90,31 +91,28 @@ func (ptr *FlushDataTableService) flushSourceFile(ctx *domain.Context, table *do
func (ptr *FlushDataTableService) flushVerifiedFile(ctx *domain.Context, table *domain.Table, file *domain.File, sourceFile *domain.File, fileRepository domain.FileRepository, url string) error {
var err error
temporaryFileTableId := table.TableId
// 校验文件对应的表更新
table.TableId = file.FileInfo.TableId
// 追加日志到校验文件
if err = dao.ChangeStepLogOwner(ptr.transactionContext, file.FileId, sourceFile.FileId); err != nil {
return err
}
sourceFile.UpdateFileUrl(url)
if sourceFile, err = fileRepository.Save(sourceFile); err != nil {
if _, err = fileRepository.Save(sourceFile); err != nil {
return err
}
// 删除中间文件
if err = dao.FileDelete(ptr.transactionContext, file.FileId, domain.TemporaryFile); err != nil {
return err
}
// 删除中间表
if err = dao.TableDelete(ptr.transactionContext, temporaryFileTableId, domain.ExcelTable); err != nil {
return err
}
if _, err = fileRepository.Save(sourceFile); err != nil {
// 更新表信息
tableRepository, _ := repository.NewTableRepository(ptr.transactionContext)
sourceTable, err := tableRepository.FindOne(map[string]interface{}{"tableId": sourceFile.FileInfo.TableId})
if err != nil {
return err
}
// 更新
tableRepository, _ := repository.NewTableRepository(ptr.transactionContext)
table, err = tableRepository.Save(table)
sourceTable.DataFields = table.DataFields
sourceTable.DataFieldIndex = table.DataFieldIndex
sourceTable.UpdatedAt = time.Now()
_, err = tableRepository.Save(sourceTable)
if err != nil {
return err
}
... ...
... ... @@ -41,7 +41,7 @@ func (ptr *PreviewDataTableService) Preview(ctx *domain.Context, fileId int, fie
Url: file.FileInfo.Url,
Ext: file.FileInfo.Ext,
Where: where,
//FileType: file.FileType,
OriginalTableId: fmt.Sprintf("%v", file.FileId),
IsFromOriginalTable: isSourceFile,
TableFileUrl: fileUrl,
... ...
... ... @@ -32,19 +32,26 @@ func (ptr *CopyDataTableService) CopyTable(ctx *domain.Context, tableId int, tab
return nil, fmt.Errorf("主表、分表才允许复制")
}
var mainTable *domain.Table
dataFields := table.DataFields
if table.TableType == domain.SubTable.ToString() {
mainTable, err = tableRepository.FindOne(map[string]interface{}{"tableId": table.ParentId})
if err != nil {
return nil, err
}
// for i:=range table.ManualFields{
// f:= table.ManualFields[i].Copy()
// f.Flag = domain.MainTableField
// dataFields = append(dataFields,f)
// }
}
// 验证表名是否重复
duplicateTable, err := tableRepository.FindOne(map[string]interface{}{"context": ctx, "tableName": tableName})
if err == nil && duplicateTable != nil {
return nil, fmt.Errorf("表名称重复")
}
sideTable := NewCopyTable(domain.SideTable, tableName, table.DataFields, table.RowCount).
sideTable := NewCopyTable(domain.SideTable, tableName,dataFields, table.RowCount).
WithContext(ctx).
WithParentId(table.TableId).
WithDataFieldIndex(table.DataFieldIndex)
... ...
... ... @@ -2,28 +2,20 @@ package repository
import (
"fmt"
"time"
"github.com/go-pg/pg/v10"
"github.com/linmadan/egglib-go/persistent/pg/sqlbuilder"
pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
"github.com/linmadan/egglib-go/utils/snowflake"
"gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/pg/models"
"gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/pg/transform"
"time"
)
type FileRepository struct {
transactionContext *pgTransaction.TransactionContext
}
func (repository *FileRepository) nextIdentify() (int64, error) {
IdWorker, err := snowflake.NewIdWorker(1)
if err != nil {
return 0, err
}
id, err := IdWorker.NextId()
return id, err
}
func (repository *FileRepository) Save(file *domain.File) (*domain.File, error) {
sqlBuildFields := []string{
"file_id",
... ... @@ -116,6 +108,9 @@ func (repository *FileRepository) FindOne(queryOptions map[string]interface{}) (
fileModel := new(models.File)
query := sqlbuilder.BuildQuery(tx.Model(fileModel), queryOptions)
query.SetWhereByQueryOption("file.file_id = ?", "fileId")
WhereContext(query, queryOptions)
query.SetWhereByQueryOption("file_info->>'name' = ?", "fileName")
query.SetWhereByQueryOption("file_type = ?", "fileType")
if err := query.First(); err != nil {
if err.Error() == "pg: no rows in result set" {
return nil, domain.ErrorNotFound
... ... @@ -150,7 +145,7 @@ func (repository *FileRepository) Find(queryOptions map[string]interface{}) (int
query.Where(`updated_at<?`, v.(time.Time))
}
query.SetOffsetAndLimit(20)
query.SetOrderDirect("file_id", "DESC")
query.SetOrderDirect("updated_at", "DESC")
if count, err := query.SelectAndCount(); err != nil {
return 0, files, err
} else {
... ...
... ... @@ -9,7 +9,6 @@ import (
"github.com/linmadan/egglib-go/persistent/pg/sqlbuilder"
pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
"github.com/linmadan/egglib-go/utils/snowflake"
"gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/pg/models"
"gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/pg/transform"
... ... @@ -19,14 +18,6 @@ type LogRepository struct {
transactionContext *pgTransaction.TransactionContext
}
func (repository *LogRepository) nextIdentify() (int64, error) {
IdWorker, err := snowflake.NewIdWorker(1)
if err != nil {
return 0, err
}
id, err := IdWorker.NextId()
return id, err
}
func (repository *LogRepository) Save(log *domain.Log) (*domain.Log, error) {
sqlBuildFields := []string{
"log_id",
... ... @@ -164,7 +155,7 @@ func (repository *LogRepository) Find(queryOptions map[string]interface{}) (int6
query.SetWhereByQueryOption(" created_at < ?", "endTime")
}
query.SetOffsetAndLimit(20)
SetOffsetAndLimit(query,queryOptions,20)
if v, ok := queryOptions["sortByLogId"]; ok && len(v.(string)) > 0 {
query.SetOrderDirect("log_id", v.(string))
} else {
... ...
... ... @@ -6,7 +6,6 @@ import (
"github.com/linmadan/egglib-go/persistent/pg/sqlbuilder"
pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
"github.com/linmadan/egglib-go/utils/snowflake"
"gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/pg/models"
"gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/pg/transform"
... ... @@ -16,14 +15,6 @@ type MappingRuleRepository struct {
transactionContext *pgTransaction.TransactionContext
}
func (repository *MappingRuleRepository) nextIdentify() (int64, error) {
IdWorker, err := snowflake.NewIdWorker(1)
if err != nil {
return 0, err
}
id, err := IdWorker.NextId()
return id, err
}
func (repository *MappingRuleRepository) Save(mappingRule *domain.MappingRule) (*domain.MappingRule, error) {
sqlBuildFields := []string{
"mapping_rule_id",
... ...
package repository
import (
"github.com/linmadan/egglib-go/persistent/pg/sqlbuilder"
"gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/utils"
)
func WhereContext(query *sqlbuilder.Query, queryOptions map[string]interface{}) {
func WhereContext(query *sqlbuilder.Query, queryOptions map[string]interface{}) *sqlbuilder.Query{
if _, ok := queryOptions["context"]; !ok {
return
return query
}
context := queryOptions["context"].(*domain.Context)
query.Where("context->'companyId'='?'", context.CompanyId)
return query
}
func SetOffsetAndLimit(query *sqlbuilder.Query, queryOptions map[string]interface{},defaultLimit int) {
pageNumber,pnOk:=queryOptions["pageNumber"]
pageSize,psOk :=queryOptions["pageSize"]
if pnOk && psOk{
iPageNumber:=utils.NumberString(utils.AssertString(pageNumber)).MustInt()
iPageSize:=utils.NumberString(utils.AssertString(pageSize)).MustInt()
queryOptions["limit"] = iPageSize
queryOptions["offset"] = (iPageSize*(iPageNumber-1))
}
query.SetOffsetAndLimit(defaultLimit)
}
\ No newline at end of file
... ...
... ... @@ -6,7 +6,6 @@ import (
"github.com/linmadan/egglib-go/persistent/pg/sqlbuilder"
pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
"github.com/linmadan/egglib-go/utils/snowflake"
"gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/pg/models"
"gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/pg/transform"
... ... @@ -16,14 +15,6 @@ type TableRepository struct {
transactionContext *pgTransaction.TransactionContext
}
func (repository *TableRepository) nextIdentify() (int64, error) {
IdWorker, err := snowflake.NewIdWorker(1)
if err != nil {
return 0, err
}
id, err := IdWorker.NextId()
return id, err
}
func (repository *TableRepository) Save(table *domain.Table) (*domain.Table, error) {
sqlBuildFields := []string{
"table_id",
... ...
... ... @@ -186,6 +186,10 @@ func queryWithoutLimitOffset(query *gorm.DB, params QueryOptions) {
if len(params.Select) > 0 {
fields := make([]string, 0)
for _, f := range params.Select {
if f.Flag==domain.ManualField{
fields = append(fields, "'' "+f.SQLName)
continue
}
fields = append(fields, f.SQLName)
}
query.Select(strings.Join(fields, ","))
... ...