正在显示
17 个修改的文件
包含
57 行增加
和
33 行删除
| 1 | package domain | 1 | package domain |
| 2 | 2 | ||
| 3 | type ByteLibService interface { | 3 | type ByteLibService interface { |
| 4 | + // LoadDataTable 加载表数据 | ||
| 4 | LoadDataTable(param ReqLoadDataTable) (*DataLoadDataTable, error) | 5 | LoadDataTable(param ReqLoadDataTable) (*DataLoadDataTable, error) |
| 6 | + // EditTable 编辑表结构(列重名,类型修改,列拆分 ...) | ||
| 5 | EditTable(param ReqEditDataTable) (*DataEditDataTable, error) | 7 | EditTable(param ReqEditDataTable) (*DataEditDataTable, error) |
| 8 | + // SaveTable 编辑后进行表结构保存(底层生成一份新的excel文件) | ||
| 6 | SaveTable(param ReqSaveTable) (*DataSaveTable, error) | 9 | SaveTable(param ReqSaveTable) (*DataSaveTable, error) |
| 10 | + // GenerateTable 生成表 (主表) | ||
| 7 | GenerateTable(ctx *Context, param ReqGenerateTable) (*DataGenerateTable, error) | 11 | GenerateTable(ctx *Context, param ReqGenerateTable) (*DataGenerateTable, error) |
| 12 | + // CopyTable 复制表 | ||
| 8 | CopyTable(param ReqCopyTable) (*DataCopyTable, error) | 13 | CopyTable(param ReqCopyTable) (*DataCopyTable, error) |
| 14 | + // AppendData 追加数据到指定表 | ||
| 9 | AppendData(param ReqAppendData) (*DataAppendData, error) | 15 | AppendData(param ReqAppendData) (*DataAppendData, error) |
| 16 | + // SplitTable 拆分表 (分表) | ||
| 10 | SplitTable(param ReqSplitTable) (*DataSplitTable, error) | 17 | SplitTable(param ReqSplitTable) (*DataSplitTable, error) |
| 18 | + // DeleteTable 删除表 | ||
| 11 | DeleteTable(param ReqDeleteTable) (*DataDeleteTable, error) | 19 | DeleteTable(param ReqDeleteTable) (*DataDeleteTable, error) |
| 20 | + // CancelFile 取消对表的操作 | ||
| 12 | CancelFile(param ReqCancelFile) (*DataCancelFile, error) | 21 | CancelFile(param ReqCancelFile) (*DataCancelFile, error) |
| 22 | + // EditTableData 编辑表数据 | ||
| 13 | EditTableData(param ReqEditTableData) (*DataEditTableData, error) | 23 | EditTableData(param ReqEditTableData) (*DataEditTableData, error) |
| 24 | + // FieldOptionalValues 字段可选值 | ||
| 14 | FieldOptionalValues(param ReqFieldOptionalValues) (*DataFieldOptionalValues, error) | 25 | FieldOptionalValues(param ReqFieldOptionalValues) (*DataFieldOptionalValues, error) |
| 26 | + // FormulasGenerate 表达式生成 (底层生成视图) | ||
| 15 | FormulasGenerate(param ReqFormulasGenerate) (*DataFormulasGenerate, error) | 27 | FormulasGenerate(param ReqFormulasGenerate) (*DataFormulasGenerate, error) |
| 28 | + // FormulasClear 表达式清除 | ||
| 16 | FormulasClear(param ReqFormulasClear) (*DataFormulasClear, error) | 29 | FormulasClear(param ReqFormulasClear) (*DataFormulasClear, error) |
| 17 | } | 30 | } |
| 18 | 31 |
| 1 | package domain | 1 | package domain |
| 2 | 2 | ||
| 3 | +// FileTableService 文件表服务(导入模块) | ||
| 3 | type FileTableService interface { | 4 | type FileTableService interface { |
| 5 | + // Preview 预览(Excel文件) | ||
| 4 | Preview(ctx *Context, fileId int, fields []*Field, where Where) (interface{}, error) | 6 | Preview(ctx *Context, fileId int, fields []*Field, where Where) (interface{}, error) |
| 7 | + // Edit 编辑表 | ||
| 5 | Edit() | 8 | Edit() |
| 9 | + // Flush 保存编辑状态的表元数据 | ||
| 6 | Flush(ctx *Context, fileId int, table *Table) (interface{}, error) | 10 | Flush(ctx *Context, fileId int, table *Table) (interface{}, error) |
| 11 | + // DeleteFiles 批量删除文件 | ||
| 7 | DeleteFiles(ctx *Context, files ...*File) error | 12 | DeleteFiles(ctx *Context, files ...*File) error |
| 13 | + // GenerateTable 生成主表 | ||
| 8 | GenerateTable(ctx *Context, fileId int, tableName string) (interface{}, error) | 14 | GenerateTable(ctx *Context, fileId int, tableName string) (interface{}, error) |
| 9 | } | 15 | } |
| 10 | 16 | ||
| 17 | +// TableService 表服务 | ||
| 11 | type TableService interface { | 18 | type TableService interface { |
| 19 | + // Preview 预览 | ||
| 12 | Preview(ctx *Context, tableId int, where Where) (interface{}, error) | 20 | Preview(ctx *Context, tableId int, where Where) (interface{}, error) |
| 21 | + // CopyTable 拷贝表 | ||
| 13 | CopyTable(ctx *Context, tableId int, tableName string) (interface{}, error) | 22 | CopyTable(ctx *Context, tableId int, tableName string) (interface{}, error) |
| 23 | + // DeleteTables 删除表 | ||
| 14 | DeleteTables(ctx *Context, tables ...*Table) error | 24 | DeleteTables(ctx *Context, tables ...*Table) error |
| 25 | + // AppendData 追加表数据 | ||
| 15 | AppendData(ctx *Context, fileId int, tableId int, mappingFields []*MappingField) (interface{}, error) | 26 | AppendData(ctx *Context, fileId int, tableId int, mappingFields []*MappingField) (interface{}, error) |
| 27 | + // UpdateTableStruct 更新表结构(分表) | ||
| 16 | UpdateTableStruct(ctx *Context, tableId int, fields []*Field, name string) (interface{}, error) | 28 | UpdateTableStruct(ctx *Context, tableId int, fields []*Field, name string) (interface{}, error) |
| 29 | + // AddTableStruct 添加表结构(分表) | ||
| 17 | AddTableStruct(ctx *Context, parentTableId int, fields []*Field, name string) (interface{}, error) | 30 | AddTableStruct(ctx *Context, parentTableId int, fields []*Field, name string) (interface{}, error) |
| 18 | } | 31 | } |
| 19 | 32 | ||
| 33 | +// PreviewDataTableService 具体的表预览服务 | ||
| 20 | type PreviewDataTableService interface { | 34 | type PreviewDataTableService interface { |
| 35 | + // Preview 预览 | ||
| 21 | Preview(ctx *Context, fileId int, fields []*Field, where Where) (interface{}, error) | 36 | Preview(ctx *Context, fileId int, fields []*Field, where Where) (interface{}, error) |
| 37 | + // RePreview 重新预览 | ||
| 22 | RePreview(ctx *Context, fileId int, fields []*Field, where Where) (interface{}, error) | 38 | RePreview(ctx *Context, fileId int, fields []*Field, where Where) (interface{}, error) |
| 39 | + // CreateTemporaryFile 创建临时文件(计算集修改的时候,先创建临时文件,保存成功后覆盖原文件) | ||
| 23 | CreateTemporaryFile(ctx *Context, fileId int) (*File, error) | 40 | CreateTemporaryFile(ctx *Context, fileId int) (*File, error) |
| 24 | GetFileId() int | 41 | GetFileId() int |
| 25 | } | 42 | } |
| 26 | 43 | ||
| 44 | +// EditDataTableService 编辑表数据(副表) | ||
| 27 | type EditDataTableService interface { | 45 | type EditDataTableService interface { |
| 28 | Edit(ctx *Context, param EditTableRequest) (*DataEditDataTable, error) | 46 | Edit(ctx *Context, param EditTableRequest) (*DataEditDataTable, error) |
| 29 | } | 47 | } |
| 30 | 48 | ||
| 49 | +// FlushDataTableService 保存编辑状态的表 | ||
| 31 | type FlushDataTableService interface { | 50 | type FlushDataTableService interface { |
| 32 | Flush(ctx *Context, fileId int, table *Table) (interface{}, error) | 51 | Flush(ctx *Context, fileId int, table *Table) (interface{}, error) |
| 33 | } | 52 | } |
| 34 | 53 | ||
| 54 | +// DeleteFileService 删除文件服务 | ||
| 35 | type DeleteFileService interface { | 55 | type DeleteFileService interface { |
| 36 | DeleteFiles(ctx *Context, files ...*File) error | 56 | DeleteFiles(ctx *Context, files ...*File) error |
| 37 | } | 57 | } |
| 38 | 58 | ||
| 59 | +// GenerateMainTableService 生成主表服务 | ||
| 39 | type GenerateMainTableService interface { | 60 | type GenerateMainTableService interface { |
| 40 | GenerateTable(ctx *Context, fileId int, tableName string) (interface{}, error) | 61 | GenerateTable(ctx *Context, fileId int, tableName string) (interface{}, error) |
| 41 | } | 62 | } |
| 42 | 63 | ||
| 64 | +// CopyDataTableService 拷贝表服务 | ||
| 43 | type CopyDataTableService interface { | 65 | type CopyDataTableService interface { |
| 44 | CopyTable(ctx *Context, tableId int, tableName string) (interface{}, error) | 66 | CopyTable(ctx *Context, tableId int, tableName string) (interface{}, error) |
| 45 | } | 67 | } |
| 46 | 68 | ||
| 69 | +// DeleteDataTableService 删除表服务 | ||
| 47 | type DeleteDataTableService interface { | 70 | type DeleteDataTableService interface { |
| 48 | DeleteTable(ctx *Context, tableId int) (interface{}, error) | 71 | DeleteTable(ctx *Context, tableId int) (interface{}, error) |
| 49 | DeleteTables(ctx *Context, tables ...*Table) error | 72 | DeleteTables(ctx *Context, tables ...*Table) error |
| 50 | } | 73 | } |
| 51 | 74 | ||
| 75 | +// AppendDataToTableService 追加数据服务 | ||
| 52 | type AppendDataToTableService interface { | 76 | type AppendDataToTableService interface { |
| 53 | AppendData(ctx *Context, fileId int, tableId int, mappingFields []*MappingField) (interface{}, error) | 77 | AppendData(ctx *Context, fileId int, tableId int, mappingFields []*MappingField) (interface{}, error) |
| 54 | PreflightCheck(ctx *Context, fileId int, tableId int, mappingFields []*MappingField) (interface{}, error) | 78 | PreflightCheck(ctx *Context, fileId int, tableId int, mappingFields []*MappingField) (interface{}, error) |
| @@ -56,10 +80,12 @@ type AppendDataToTableService interface { | @@ -56,10 +80,12 @@ type AppendDataToTableService interface { | ||
| 56 | 80 | ||
| 57 | /************************************/ | 81 | /************************************/ |
| 58 | 82 | ||
| 83 | +// UpdateTableStructService 更新表结构服务(分表) | ||
| 59 | type UpdateTableStructService interface { | 84 | type UpdateTableStructService interface { |
| 60 | UpdateTableStruct(ctx *Context, tableId int, fields []*Field, name string) (interface{}, error) | 85 | UpdateTableStruct(ctx *Context, tableId int, fields []*Field, name string) (interface{}, error) |
| 61 | } | 86 | } |
| 62 | 87 | ||
| 88 | +// AddTableStructService 添加表结构服务(分表) | ||
| 63 | type AddTableStructService interface { | 89 | type AddTableStructService interface { |
| 64 | AddTableStruct(ctx *Context, parentTableId int, fields []*Field, name string) (*Table, error) | 90 | AddTableStruct(ctx *Context, parentTableId int, fields []*Field, name string) (*Table, error) |
| 65 | } | 91 | } |
| @@ -20,6 +20,7 @@ const ( | @@ -20,6 +20,7 @@ const ( | ||
| 20 | QuerySetDeleteEvent EventType = "table.query.set.delete" // 删除 | 20 | QuerySetDeleteEvent EventType = "table.query.set.delete" // 删除 |
| 21 | ) | 21 | ) |
| 22 | 22 | ||
| 23 | +// EventTable 表事件 | ||
| 23 | type EventTable struct { | 24 | type EventTable struct { |
| 24 | Context *Context | 25 | Context *Context |
| 25 | Type EventType | 26 | Type EventType |
| @@ -39,6 +40,7 @@ func (et *EventTable) WithContext(t *Context) *EventTable { | @@ -39,6 +40,7 @@ func (et *EventTable) WithContext(t *Context) *EventTable { | ||
| 39 | et.Context = t | 40 | et.Context = t |
| 40 | return et | 41 | return et |
| 41 | } | 42 | } |
| 43 | + | ||
| 42 | func (et *EventTable) WithType(t EventType) *EventTable { | 44 | func (et *EventTable) WithType(t EventType) *EventTable { |
| 43 | et.Type = t | 45 | et.Type = t |
| 44 | return et | 46 | return et |
| @@ -14,6 +14,8 @@ type ByteCoreService struct { | @@ -14,6 +14,8 @@ type ByteCoreService struct { | ||
| 14 | TempDataTable map[int]*domain.DataLoadDataTable | 14 | TempDataTable map[int]*domain.DataLoadDataTable |
| 15 | } | 15 | } |
| 16 | 16 | ||
| 17 | +// ByteCore 字库底层核心 | ||
| 18 | +// 主表、拆分、数据读取等功能 | ||
| 17 | var ByteCore domain.ByteLibService = &WrapByteCoreService{} //&ByteCoreService{} | 19 | var ByteCore domain.ByteLibService = &WrapByteCoreService{} //&ByteCoreService{} |
| 18 | 20 | ||
| 19 | var _ domain.ByteLibService = (*ByteCoreService)(nil) | 21 | var _ domain.ByteLibService = (*ByteCoreService)(nil) |
| @@ -14,7 +14,7 @@ type PreviewDataTableService struct { | @@ -14,7 +14,7 @@ type PreviewDataTableService struct { | ||
| 14 | transactionContext *pgTransaction.TransactionContext | 14 | transactionContext *pgTransaction.TransactionContext |
| 15 | } | 15 | } |
| 16 | 16 | ||
| 17 | -// RePreview 重新预览 | 17 | +// RePreview 重新预览,表头重置时,前端调用重新预览接口,重置缓存的表头行号 |
| 18 | func (ptr *PreviewDataTableService) RePreview(ctx *domain.Context, fileId int, fields []*domain.Field, where domain.Where) (interface{}, error) { | 18 | func (ptr *PreviewDataTableService) RePreview(ctx *domain.Context, fileId int, fields []*domain.Field, where domain.Where) (interface{}, error) { |
| 19 | fileRepository, _ := repository.NewFileRepository(ptr.transactionContext) | 19 | fileRepository, _ := repository.NewFileRepository(ptr.transactionContext) |
| 20 | file, err := fileRepository.FindOne(map[string]interface{}{"fileId": fileId}) | 20 | file, err := fileRepository.FindOne(map[string]interface{}{"fileId": fileId}) |
| @@ -14,6 +14,7 @@ type PGLogService struct { | @@ -14,6 +14,7 @@ type PGLogService struct { | ||
| 14 | transactionContext *pgTransaction.TransactionContext | 14 | transactionContext *pgTransaction.TransactionContext |
| 15 | } | 15 | } |
| 16 | 16 | ||
| 17 | +// NewPGLogService 服务操作日志记录 | ||
| 17 | func NewPGLogService(transactionContext *pgTransaction.TransactionContext) (*PGLogService, error) { | 18 | func NewPGLogService(transactionContext *pgTransaction.TransactionContext) (*PGLogService, error) { |
| 18 | if transactionContext == nil { | 19 | if transactionContext == nil { |
| 19 | return nil, fmt.Errorf("transactionContext参数不能为nil") | 20 | return nil, fmt.Errorf("transactionContext参数不能为nil") |
| @@ -24,6 +25,7 @@ func NewPGLogService(transactionContext *pgTransaction.TransactionContext) (*PGL | @@ -24,6 +25,7 @@ func NewPGLogService(transactionContext *pgTransaction.TransactionContext) (*PGL | ||
| 24 | } | 25 | } |
| 25 | } | 26 | } |
| 26 | 27 | ||
| 28 | +// FastLog 快速记录日志 | ||
| 27 | func FastLog(transactionContext *pgTransaction.TransactionContext, logType domain.LogType, sourceId int, logEntry Log) error { | 29 | func FastLog(transactionContext *pgTransaction.TransactionContext, logType domain.LogType, sourceId int, logEntry Log) error { |
| 28 | logService, _ := NewPGLogService(transactionContext) | 30 | logService, _ := NewPGLogService(transactionContext) |
| 29 | return logService.Log(logType, sourceId, logEntry) | 31 | return logService.Log(logType, sourceId, logEntry) |
| @@ -21,6 +21,7 @@ var ( | @@ -21,6 +21,7 @@ var ( | ||
| 21 | ErrFieldsNotMatch = func(table string) error { return fmt.Errorf("[%v]字段数量不一致或类型不匹配", table) } | 21 | ErrFieldsNotMatch = func(table string) error { return fmt.Errorf("[%v]字段数量不一致或类型不匹配", table) } |
| 22 | ) | 22 | ) |
| 23 | 23 | ||
| 24 | +// QuerySetService 查询集服务,对拆分、计算模块数据集合的处理 | ||
| 24 | type QuerySetService struct { | 25 | type QuerySetService struct { |
| 25 | transactionContext *pgTransaction.TransactionContext | 26 | transactionContext *pgTransaction.TransactionContext |
| 26 | } | 27 | } |
| @@ -5,6 +5,7 @@ import ( | @@ -5,6 +5,7 @@ import ( | ||
| 5 | "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/domain/astexpr" | 5 | "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/domain/astexpr" |
| 6 | ) | 6 | ) |
| 7 | 7 | ||
| 8 | +// LoadCalculateItemData 加载计算项数据,实时计算某个列的值 | ||
| 8 | func (ptr *QuerySetService) LoadCalculateItemData(ctx *domain.Context, t *domain.Table, formula *domain.FieldFormulaExpr) (*domain.DataTable, error) { | 9 | func (ptr *QuerySetService) LoadCalculateItemData(ctx *domain.Context, t *domain.Table, formula *domain.FieldFormulaExpr) (*domain.DataTable, error) { |
| 9 | var ( | 10 | var ( |
| 10 | res = &domain.DataTable{} | 11 | res = &domain.DataTable{} |
| @@ -15,6 +15,7 @@ import ( | @@ -15,6 +15,7 @@ import ( | ||
| 15 | const DefaultExpandNum = 1000 | 15 | const DefaultExpandNum = 1000 |
| 16 | const MaxExpandNum = 5000 | 16 | const MaxExpandNum = 5000 |
| 17 | 17 | ||
| 18 | +// LoadCalculateSetData 加载计算集数据,根据排列规则,动态进行集合数据排列,返回一个二维表 | ||
| 18 | func (ptr *QuerySetService) LoadCalculateSetData(ctx *domain.Context, qs *domain.QuerySet, queryComponents []*domain.QueryComponent) (*domain.DataTable, error) { | 19 | func (ptr *QuerySetService) LoadCalculateSetData(ctx *domain.Context, qs *domain.QuerySet, queryComponents []*domain.QueryComponent) (*domain.DataTable, error) { |
| 19 | var ( | 20 | var ( |
| 20 | res = &domain.DataTable{} | 21 | res = &domain.DataTable{} |
| @@ -21,6 +21,7 @@ func NewAddTableStructService(transactionContext *pgTransaction.TransactionConte | @@ -21,6 +21,7 @@ func NewAddTableStructService(transactionContext *pgTransaction.TransactionConte | ||
| 21 | } | 21 | } |
| 22 | } | 22 | } |
| 23 | 23 | ||
| 24 | +// AddTableStruct 添加表结构(新建分表) | ||
| 24 | func (ptr *AddTableStructService) AddTableStruct(ctx *domain.Context, parentTableId int, fields []*domain.Field, name string) (*domain.Table, error) { | 25 | func (ptr *AddTableStructService) AddTableStruct(ctx *domain.Context, parentTableId int, fields []*domain.Field, name string) (*domain.Table, error) { |
| 25 | tableRepository, _ := repository.NewTableRepository(ptr.transactionContext) | 26 | tableRepository, _ := repository.NewTableRepository(ptr.transactionContext) |
| 26 | mainTable, err := tableRepository.FindOne(map[string]interface{}{"tableId": parentTableId}) | 27 | mainTable, err := tableRepository.FindOne(map[string]interface{}{"tableId": parentTableId}) |
| @@ -43,6 +43,9 @@ func NewCircleDependError(t *domain.Table, qs *domain.QuerySet) CircleDependErro | @@ -43,6 +43,9 @@ func NewCircleDependError(t *domain.Table, qs *domain.QuerySet) CircleDependErro | ||
| 43 | } | 43 | } |
| 44 | } | 44 | } |
| 45 | 45 | ||
| 46 | +// TableDependencyService 表依赖服务 | ||
| 47 | +// 查询表所有的依赖关系 | ||
| 48 | +// 判断是否循环依赖 | ||
| 46 | type TableDependencyService struct { | 49 | type TableDependencyService struct { |
| 47 | transactionContext *pgTransaction.TransactionContext | 50 | transactionContext *pgTransaction.TransactionContext |
| 48 | DetectedCycleCallBack func() | 51 | DetectedCycleCallBack func() |
| @@ -23,6 +23,7 @@ func NewTableEditDataService(transactionContext *pgTransaction.TransactionContex | @@ -23,6 +23,7 @@ func NewTableEditDataService(transactionContext *pgTransaction.TransactionContex | ||
| 23 | } | 23 | } |
| 24 | } | 24 | } |
| 25 | 25 | ||
| 26 | +// RowEdit 行数据编辑 | ||
| 26 | func (ptr *TableEditDataService) RowEdit(ctx *domain.Context, request domain.EditDataRequest) (interface{}, error) { | 27 | func (ptr *TableEditDataService) RowEdit(ctx *domain.Context, request domain.EditDataRequest) (interface{}, error) { |
| 27 | tableRepository, _ := repository.NewTableRepository(ptr.transactionContext) | 28 | tableRepository, _ := repository.NewTableRepository(ptr.transactionContext) |
| 28 | var table *domain.Table = request.Table | 29 | var table *domain.Table = request.Table |
| @@ -24,6 +24,7 @@ func NewUpdateTableStructService(transactionContext *pgTransaction.TransactionCo | @@ -24,6 +24,7 @@ func NewUpdateTableStructService(transactionContext *pgTransaction.TransactionCo | ||
| 24 | } | 24 | } |
| 25 | } | 25 | } |
| 26 | 26 | ||
| 27 | +// UpdateTableStruct 更新表结构 | ||
| 27 | func (ptr *UpdateTableStructService) UpdateTableStruct(ctx *domain.Context, tableId int, fields []*domain.Field, name string) (interface{}, error) { | 28 | func (ptr *UpdateTableStructService) UpdateTableStruct(ctx *domain.Context, tableId int, fields []*domain.Field, name string) (interface{}, error) { |
| 28 | tableRepository, _ := repository.NewTableRepository(ptr.transactionContext) | 29 | tableRepository, _ := repository.NewTableRepository(ptr.transactionContext) |
| 29 | table, err := tableRepository.FindOne(map[string]interface{}{"tableId": tableId}) | 30 | table, err := tableRepository.FindOne(map[string]interface{}{"tableId": tableId}) |
| @@ -83,6 +84,7 @@ func (ptr *UpdateTableStructService) UpdateTableStruct(ctx *domain.Context, tabl | @@ -83,6 +84,7 @@ func (ptr *UpdateTableStructService) UpdateTableStruct(ctx *domain.Context, tabl | ||
| 83 | return struct{}{}, nil | 84 | return struct{}{}, nil |
| 84 | } | 85 | } |
| 85 | 86 | ||
| 87 | +// DependencyTables 依赖的表列表 | ||
| 86 | func DependencyTables(ptr *pgTransaction.TransactionContext, context *domain.Context, tableId int) ([]TableNode, error) { | 88 | func DependencyTables(ptr *pgTransaction.TransactionContext, context *domain.Context, tableId int) ([]TableNode, error) { |
| 87 | ret := make([]TableNode, 0) | 89 | ret := make([]TableNode, 0) |
| 88 | // tableId 相关联的 | 90 | // tableId 相关联的 |
| @@ -14,9 +14,6 @@ func Insert(db *gorm.DB, tableName string, fields []*domain.FieldValue) error { | @@ -14,9 +14,6 @@ func Insert(db *gorm.DB, tableName string, fields []*domain.FieldValue) error { | ||
| 14 | value := map[string]interface{}{} | 14 | value := map[string]interface{}{} |
| 15 | for _, f := range fields { | 15 | for _, f := range fields { |
| 16 | if f.Field.Flag == domain.PKField && f.Value == "" { | 16 | if f.Field.Flag == domain.PKField && f.Value == "" { |
| 17 | - //continue | ||
| 18 | - //id, _ := uuid.NewUUID() | ||
| 19 | - // idString := id.String() | ||
| 20 | // 需要调用分布式id生成 | 17 | // 需要调用分布式id生成 |
| 21 | id, _ := utils.NewSnowflakeId() | 18 | id, _ := utils.NewSnowflakeId() |
| 22 | idString := fmt.Sprintf("%d", id) | 19 | idString := fmt.Sprintf("%d", id) |
| @@ -24,8 +21,6 @@ func Insert(db *gorm.DB, tableName string, fields []*domain.FieldValue) error { | @@ -24,8 +21,6 @@ func Insert(db *gorm.DB, tableName string, fields []*domain.FieldValue) error { | ||
| 24 | } | 21 | } |
| 25 | value[f.Field.SQLName] = f.TypeValue() | 22 | value[f.Field.SQLName] = f.TypeValue() |
| 26 | } | 23 | } |
| 27 | - //tx := db.Table(tableName).Create(value) | ||
| 28 | - //return tx.Error | ||
| 29 | sql := db.ToSQL(func(tx *gorm.DB) *gorm.DB { | 24 | sql := db.ToSQL(func(tx *gorm.DB) *gorm.DB { |
| 30 | return tx.Table(tableName).Create(value) | 25 | return tx.Table(tableName).Create(value) |
| 31 | }) | 26 | }) |
| @@ -45,8 +40,6 @@ func Update(db *gorm.DB, tableName string, fields []*domain.FieldValue) error { | @@ -45,8 +40,6 @@ func Update(db *gorm.DB, tableName string, fields []*domain.FieldValue) error { | ||
| 45 | if pk == nil && pk.Value != "" && pk.TypeValue() != nil { | 40 | if pk == nil && pk.Value != "" && pk.TypeValue() != nil { |
| 46 | return fmt.Errorf("主键不能为空") | 41 | return fmt.Errorf("主键不能为空") |
| 47 | } | 42 | } |
| 48 | - //tx := db.Table(tableName).Where("? = ?", pk.Field.SQLName, pk.Value).Updates(value) | ||
| 49 | - //return tx.Error | ||
| 50 | sql := db.ToSQL(func(tx *gorm.DB) *gorm.DB { | 43 | sql := db.ToSQL(func(tx *gorm.DB) *gorm.DB { |
| 51 | return tx.Table(tableName).Create(value) | 44 | return tx.Table(tableName).Create(value) |
| 52 | }) | 45 | }) |
| @@ -64,8 +57,6 @@ func Delete(db *gorm.DB, tableName string, fields []*domain.FieldValue) error { | @@ -64,8 +57,6 @@ func Delete(db *gorm.DB, tableName string, fields []*domain.FieldValue) error { | ||
| 64 | if pk == nil { | 57 | if pk == nil { |
| 65 | return fmt.Errorf("主键不能为空") | 58 | return fmt.Errorf("主键不能为空") |
| 66 | } | 59 | } |
| 67 | - //tx := db.Table(tableName).Delete("? = ?", pk.Field.SQLName, pk.Value) | ||
| 68 | - //return tx.Error | ||
| 69 | sql := db.ToSQL(func(tx *gorm.DB) *gorm.DB { | 60 | sql := db.ToSQL(func(tx *gorm.DB) *gorm.DB { |
| 70 | return tx.Table(tableName).Delete("? = ?", pk.Field.SQLName, pk.Value) | 61 | return tx.Table(tableName).Delete("? = ?", pk.Field.SQLName, pk.Value) |
| 71 | }) | 62 | }) |
| @@ -222,9 +222,6 @@ func (c Condition) CastTypeByField(f *domain.Field, t string) string { | @@ -222,9 +222,6 @@ func (c Condition) CastTypeByField(f *domain.Field, t string) string { | ||
| 222 | } | 222 | } |
| 223 | 223 | ||
| 224 | func formatFiled(f *domain.Field) string { | 224 | func formatFiled(f *domain.Field) string { |
| 225 | - //if f.SQLType == domain.Float.ToString() || f.SQLType == domain.DECIMAL279.ToString() { | ||
| 226 | - // return castTypeAlias(f.SQLName, domain.DECIMALV2.ToString()) | ||
| 227 | - //} | ||
| 228 | return f.SQLName | 225 | return f.SQLName |
| 229 | } | 226 | } |
| 230 | 227 | ||
| @@ -346,15 +343,6 @@ func WrapDeleteFuncWithDB(db *gorm.DB) func(QueryOptions) (int64, error) { | @@ -346,15 +343,6 @@ func WrapDeleteFuncWithDB(db *gorm.DB) func(QueryOptions) (int64, error) { | ||
| 346 | return func(params QueryOptions) (int64, error) { | 343 | return func(params QueryOptions) (int64, error) { |
| 347 | query := db.Table(params.TableName) | 344 | query := db.Table(params.TableName) |
| 348 | queryWithoutLimitOffset(query, params) | 345 | queryWithoutLimitOffset(query, params) |
| 349 | - //if params.Offset > 0 { | ||
| 350 | - // query.Offset(params.Offset) | ||
| 351 | - //} | ||
| 352 | - //if params.Limit > 0 { | ||
| 353 | - // query.Limit(params.Limit) | ||
| 354 | - //} | ||
| 355 | - //if params.Context != nil { | ||
| 356 | - // query.Where(fmt.Sprintf("context->>'companyId'='%v'", params.Context.CompanyId)) | ||
| 357 | - //} | ||
| 358 | rows, err := query.Rows() | 346 | rows, err := query.Rows() |
| 359 | defer rows.Close() | 347 | defer rows.Close() |
| 360 | if err != nil { | 348 | if err != nil { |
| @@ -34,17 +34,6 @@ func Init() error { | @@ -34,17 +34,6 @@ func Init() error { | ||
| 34 | } | 34 | } |
| 35 | 35 | ||
| 36 | func Test() { | 36 | func Test() { |
| 37 | - //var result [][]interface{} | ||
| 38 | - //query := DB.Raw("select * from sales_performance_area_belongs").Select(&result) | ||
| 39 | - //if query.Error != nil { | ||
| 40 | - // log.Logger.Error(query.Error.Error()) | ||
| 41 | - //} | ||
| 42 | - //if len(result) > 0 { | ||
| 43 | - // | ||
| 44 | - //} | ||
| 45 | - | ||
| 46 | - //rows, err := DB.Raw("select * from sales_performance_area_belongs").Rows() | ||
| 47 | - | ||
| 48 | rows, err := DB.Table("sales_performance_area_categorys").Rows() | 37 | rows, err := DB.Table("sales_performance_area_categorys").Rows() |
| 49 | if err != nil { | 38 | if err != nil { |
| 50 | log.Logger.Error(err.Error()) | 39 | log.Logger.Error(err.Error()) |
-
请 注册 或 登录 后发表评论