合并分支 'test' 到 'master'
Test 查看合并请求 !5
正在显示
7 个修改的文件
包含
68 行增加
和
17 行删除
| @@ -25,9 +25,11 @@ type SearchTableQuery struct { | @@ -25,9 +25,11 @@ type SearchTableQuery struct { | ||
| 25 | ReturnDetailStructInfo bool `cname:"返回具体的结构信息 默认不返回" json:"returnDetailStructInfo"` | 25 | ReturnDetailStructInfo bool `cname:"返回具体的结构信息 默认不返回" json:"returnDetailStructInfo"` |
| 26 | // 排除分组项,只返回一级列表;默认 false 不排除,连分组也返回 | 26 | // 排除分组项,只返回一级列表;默认 false 不排除,连分组也返回 |
| 27 | ReturnGroupItem bool `cname:"排除分组" json:"returnGroupItem"` | 27 | ReturnGroupItem bool `cname:"排除分组" json:"returnGroupItem"` |
| 28 | - Context *domain.Context | ||
| 29 | - FilterRules []*FilterRule `json:"filterRules"` | ||
| 30 | - TableId int `cname:"ID" json:"tableId"` | 28 | + // 排除指定表 |
| 29 | + ExcludeTables []int `cname:"排除指定表" json:"excludeTables"` | ||
| 30 | + Context *domain.Context | ||
| 31 | + FilterRules []*FilterRule `json:"filterRules"` | ||
| 32 | + TableId int `cname:"ID" json:"tableId"` | ||
| 31 | } | 33 | } |
| 32 | type FilterRule struct { | 34 | type FilterRule struct { |
| 33 | // *:匹配所有 | 35 | // *:匹配所有 |
| @@ -234,6 +234,18 @@ func (tableService *TableService) Search(searchQuery *query.SearchTableQuery) (i | @@ -234,6 +234,18 @@ func (tableService *TableService) Search(searchQuery *query.SearchTableQuery) (i | ||
| 234 | for _, table := range tables { | 234 | for _, table := range tables { |
| 235 | var item = &dto.TableDto{} | 235 | var item = &dto.TableDto{} |
| 236 | item.Load(table) | 236 | item.Load(table) |
| 237 | + if len(searchQuery.ExcludeTables) > 0 { | ||
| 238 | + exclude := false | ||
| 239 | + for _, t := range searchQuery.ExcludeTables { | ||
| 240 | + if t == item.TableId { | ||
| 241 | + exclude = true | ||
| 242 | + break | ||
| 243 | + } | ||
| 244 | + } | ||
| 245 | + if exclude { | ||
| 246 | + continue | ||
| 247 | + } | ||
| 248 | + } | ||
| 237 | if searchQuery.ReturnDetailStructInfo { | 249 | if searchQuery.ReturnDetailStructInfo { |
| 238 | item.SetDetailStructInfo(table) | 250 | item.SetDetailStructInfo(table) |
| 239 | } | 251 | } |
| @@ -76,6 +76,9 @@ func (tableService *TableService) TableObjectSearch(searchQuery *query.SearchTab | @@ -76,6 +76,9 @@ func (tableService *TableService) TableObjectSearch(searchQuery *query.SearchTab | ||
| 76 | querySetMapGroup := make(map[int]bool) | 76 | querySetMapGroup := make(map[int]bool) |
| 77 | querySetGroups := make([]*domain.QuerySet, 0) | 77 | querySetGroups := make([]*domain.QuerySet, 0) |
| 78 | for _, t := range result { | 78 | for _, t := range result { |
| 79 | + if filterTableByFilterRule(t, searchQuery) { | ||
| 80 | + continue | ||
| 81 | + } | ||
| 79 | if !domain.TableType(t.TableType).TableHasGroup() { | 82 | if !domain.TableType(t.TableType).TableHasGroup() { |
| 80 | response = append(response, t) | 83 | response = append(response, t) |
| 81 | continue | 84 | continue |
| @@ -87,9 +90,7 @@ func (tableService *TableService) TableObjectSearch(searchQuery *query.SearchTab | @@ -87,9 +90,7 @@ func (tableService *TableService) TableObjectSearch(searchQuery *query.SearchTab | ||
| 87 | } | 90 | } |
| 88 | t.Update(v) | 91 | t.Update(v) |
| 89 | parentGroupId := v.ParentId | 92 | parentGroupId := v.ParentId |
| 90 | - if filterTableByFilterRule(t, searchQuery.FilterRules) { | ||
| 91 | - continue | ||
| 92 | - } | 93 | + |
| 93 | response = append(response, t) | 94 | response = append(response, t) |
| 94 | for { | 95 | for { |
| 95 | if parentGroupId == 0 { | 96 | if parentGroupId == 0 { |
| @@ -129,7 +130,15 @@ func (tableService *TableService) TableObjectSearch(searchQuery *query.SearchTab | @@ -129,7 +130,15 @@ func (tableService *TableService) TableObjectSearch(searchQuery *query.SearchTab | ||
| 129 | } | 130 | } |
| 130 | 131 | ||
| 131 | // true:代表需要过滤 false:不需要过滤 | 132 | // true:代表需要过滤 false:不需要过滤 |
| 132 | -func filterTableByFilterRule(item *dto.TableObjectDto, filterRules []*query.FilterRule) bool { | 133 | +func filterTableByFilterRule(item *dto.TableObjectDto, searchQuery *query.SearchTableQuery) bool { |
| 134 | + filterRules := searchQuery.FilterRules | ||
| 135 | + if len(searchQuery.ExcludeTables) > 0 { | ||
| 136 | + for _, t := range searchQuery.ExcludeTables { | ||
| 137 | + if t == item.TableId { | ||
| 138 | + return true | ||
| 139 | + } | ||
| 140 | + } | ||
| 141 | + } | ||
| 133 | for _, rule := range filterRules { | 142 | for _, rule := range filterRules { |
| 134 | if rule.TableType == item.TableType && rule.Status > 0 && rule.Status != item.Status { | 143 | if rule.TableType == item.TableType && rule.Status > 0 && rule.Status != item.Status { |
| 135 | return true | 144 | return true |
| @@ -217,8 +217,9 @@ type ( | @@ -217,8 +217,9 @@ type ( | ||
| 217 | ) | 217 | ) |
| 218 | 218 | ||
| 219 | type ColumnSchema struct { | 219 | type ColumnSchema struct { |
| 220 | - ColumnName string `json:"columnName"` | ||
| 221 | - ColumnType string `json:"columnType"` | 220 | + ColumnName string `json:"columnName"` |
| 221 | + ColumnType string `json:"columnType"` | ||
| 222 | + ColumnSqlFriendlyName string `json:"columnSqlFriendlyName"` | ||
| 222 | } | 223 | } |
| 223 | 224 | ||
| 224 | func ToFields(fields []*Field) []*Field { | 225 | func ToFields(fields []*Field) []*Field { |
| @@ -6,8 +6,9 @@ func DomainFieldsToColumnSchemas(fields []*domain.Field) []domain.ColumnSchema { | @@ -6,8 +6,9 @@ func DomainFieldsToColumnSchemas(fields []*domain.Field) []domain.ColumnSchema { | ||
| 6 | result := make([]domain.ColumnSchema, 0) | 6 | result := make([]domain.ColumnSchema, 0) |
| 7 | for _, f := range fields { | 7 | for _, f := range fields { |
| 8 | res := domain.ColumnSchema{ | 8 | res := domain.ColumnSchema{ |
| 9 | - ColumnName: f.Name, | ||
| 10 | - ColumnType: f.SQLType, | 9 | + ColumnName: f.Name, |
| 10 | + ColumnType: f.SQLType, | ||
| 11 | + ColumnSqlFriendlyName: f.SQLName, | ||
| 11 | } | 12 | } |
| 12 | if convertFiledSQLType(f.SQLType) { | 13 | if convertFiledSQLType(f.SQLType) { |
| 13 | res.ColumnType = domain.DECIMAL279.ToString() | 14 | res.ColumnType = domain.DECIMAL279.ToString() |
| @@ -75,8 +76,9 @@ func FieldsToColumnSchemas(fields []*domain.Field) []domain.ColumnSchema { | @@ -75,8 +76,9 @@ func FieldsToColumnSchemas(fields []*domain.Field) []domain.ColumnSchema { | ||
| 75 | 76 | ||
| 76 | for _, f := range fields { | 77 | for _, f := range fields { |
| 77 | result = append(result, domain.ColumnSchema{ | 78 | result = append(result, domain.ColumnSchema{ |
| 78 | - ColumnName: f.Name, | ||
| 79 | - ColumnType: f.SQLType, | 79 | + ColumnName: f.Name, |
| 80 | + ColumnType: f.SQLType, | ||
| 81 | + ColumnSqlFriendlyName: f.SQLName, | ||
| 80 | }) | 82 | }) |
| 81 | } | 83 | } |
| 82 | return result | 84 | return result |
| @@ -54,11 +54,14 @@ func (ptr *TableEditDataService) RowEdit(ctx *domain.Context, request domain.Edi | @@ -54,11 +54,14 @@ func (ptr *TableEditDataService) RowEdit(ctx *domain.Context, request domain.Edi | ||
| 54 | }); err != nil { | 54 | }); err != nil { |
| 55 | return nil, err | 55 | return nil, err |
| 56 | } | 56 | } |
| 57 | - for _, l := range request.RemoveList { | ||
| 58 | - if e := ptr.remove(ctx, table, l, request.Where); e != nil { | ||
| 59 | - log.Logger.Error(e.Error()) | ||
| 60 | - } | 57 | + if err = starrocks.BatchDelete(starrocks.DB, table.SQLName, request.RemoveList); err != nil { |
| 58 | + return nil, err | ||
| 61 | } | 59 | } |
| 60 | + //for _, l := range request.RemoveList { | ||
| 61 | + // if e := ptr.remove(ctx, table, l, request.Where); e != nil { | ||
| 62 | + // log.Logger.Error(e.Error()) | ||
| 63 | + // } | ||
| 64 | + //} | ||
| 62 | } | 65 | } |
| 63 | for _, l := range request.UpdateList { | 66 | for _, l := range request.UpdateList { |
| 64 | if e := ptr.update(ctx, table, l, request.Where); e != nil { | 67 | if e := ptr.update(ctx, table, l, request.Where); e != nil { |
| @@ -73,6 +73,28 @@ func Delete(db *gorm.DB, tableName string, fields []*domain.FieldValue) error { | @@ -73,6 +73,28 @@ func Delete(db *gorm.DB, tableName string, fields []*domain.FieldValue) error { | ||
| 73 | return tx.Error | 73 | return tx.Error |
| 74 | } | 74 | } |
| 75 | 75 | ||
| 76 | +func BatchDelete(db *gorm.DB, tableName string, fields []*domain.FieldValues) error { | ||
| 77 | + var pk *domain.FieldValue | ||
| 78 | + var values = make([]string, 0) | ||
| 79 | + for _, row := range fields { | ||
| 80 | + for _, f := range row.FieldValues { | ||
| 81 | + if f.Field.Flag == domain.PKField && f.Value != "" { | ||
| 82 | + pk = f | ||
| 83 | + values = append(values, f.Value) | ||
| 84 | + } | ||
| 85 | + } | ||
| 86 | + } | ||
| 87 | + if len(values) == 0 { | ||
| 88 | + return fmt.Errorf("删除行为空") | ||
| 89 | + } | ||
| 90 | + sql := db.ToSQL(func(tx *gorm.DB) *gorm.DB { | ||
| 91 | + c := Condition{} | ||
| 92 | + return tx.Table(tableName).Where(fmt.Sprintf("%s in %s", pk.Field.SQLName, c.InArgs(values))).Delete("") | ||
| 93 | + }) | ||
| 94 | + tx := db.Exec(sql) | ||
| 95 | + return tx.Error | ||
| 96 | +} | ||
| 97 | + | ||
| 76 | //DROP VIEW IF EXISTS | 98 | //DROP VIEW IF EXISTS |
| 77 | 99 | ||
| 78 | func DropView(db *gorm.DB, tableName string) error { | 100 | func DropView(db *gorm.DB, tableName string) error { |
-
请 注册 或 登录 后发表评论