作者 yangfu

Merge branch 'test'

... ... @@ -25,9 +25,11 @@ type SearchTableQuery struct {
ReturnDetailStructInfo bool `cname:"返回具体的结构信息 默认不返回" json:"returnDetailStructInfo"`
// 排除分组项,只返回一级列表;默认 false 不排除,连分组也返回
ReturnGroupItem bool `cname:"排除分组" json:"returnGroupItem"`
Context *domain.Context
FilterRules []*FilterRule `json:"filterRules"`
TableId int `cname:"ID" json:"tableId"`
// 排除指定表
ExcludeTables []int `cname:"排除指定表" json:"excludeTables"`
Context *domain.Context
FilterRules []*FilterRule `json:"filterRules"`
TableId int `cname:"ID" json:"tableId"`
}
type FilterRule struct {
// *:匹配所有
... ...
... ... @@ -234,6 +234,18 @@ func (tableService *TableService) Search(searchQuery *query.SearchTableQuery) (i
for _, table := range tables {
var item = &dto.TableDto{}
item.Load(table)
if len(searchQuery.ExcludeTables) > 0 {
exclude := false
for _, t := range searchQuery.ExcludeTables {
if t == item.TableId {
exclude = true
break
}
}
if exclude {
continue
}
}
if searchQuery.ReturnDetailStructInfo {
item.SetDetailStructInfo(table)
}
... ...
... ... @@ -76,6 +76,9 @@ func (tableService *TableService) TableObjectSearch(searchQuery *query.SearchTab
querySetMapGroup := make(map[int]bool)
querySetGroups := make([]*domain.QuerySet, 0)
for _, t := range result {
if filterTableByFilterRule(t, searchQuery) {
continue
}
if !domain.TableType(t.TableType).TableHasGroup() {
response = append(response, t)
continue
... ... @@ -87,9 +90,7 @@ func (tableService *TableService) TableObjectSearch(searchQuery *query.SearchTab
}
t.Update(v)
parentGroupId := v.ParentId
if filterTableByFilterRule(t, searchQuery.FilterRules) {
continue
}
response = append(response, t)
for {
if parentGroupId == 0 {
... ... @@ -129,7 +130,15 @@ func (tableService *TableService) TableObjectSearch(searchQuery *query.SearchTab
}
// true:代表需要过滤 false:不需要过滤
func filterTableByFilterRule(item *dto.TableObjectDto, filterRules []*query.FilterRule) bool {
func filterTableByFilterRule(item *dto.TableObjectDto, searchQuery *query.SearchTableQuery) bool {
filterRules := searchQuery.FilterRules
if len(searchQuery.ExcludeTables) > 0 {
for _, t := range searchQuery.ExcludeTables {
if t == item.TableId {
return true
}
}
}
for _, rule := range filterRules {
if rule.TableType == item.TableType && rule.Status > 0 && rule.Status != item.Status {
return true
... ...
... ... @@ -217,8 +217,9 @@ type (
)
type ColumnSchema struct {
ColumnName string `json:"columnName"`
ColumnType string `json:"columnType"`
ColumnName string `json:"columnName"`
ColumnType string `json:"columnType"`
ColumnSqlFriendlyName string `json:"columnSqlFriendlyName"`
}
func ToFields(fields []*Field) []*Field {
... ...
... ... @@ -6,8 +6,9 @@ func DomainFieldsToColumnSchemas(fields []*domain.Field) []domain.ColumnSchema {
result := make([]domain.ColumnSchema, 0)
for _, f := range fields {
res := domain.ColumnSchema{
ColumnName: f.Name,
ColumnType: f.SQLType,
ColumnName: f.Name,
ColumnType: f.SQLType,
ColumnSqlFriendlyName: f.SQLName,
}
if convertFiledSQLType(f.SQLType) {
res.ColumnType = domain.DECIMAL279.ToString()
... ... @@ -75,8 +76,9 @@ func FieldsToColumnSchemas(fields []*domain.Field) []domain.ColumnSchema {
for _, f := range fields {
result = append(result, domain.ColumnSchema{
ColumnName: f.Name,
ColumnType: f.SQLType,
ColumnName: f.Name,
ColumnType: f.SQLType,
ColumnSqlFriendlyName: f.SQLName,
})
}
return result
... ...
... ... @@ -54,11 +54,14 @@ func (ptr *TableEditDataService) RowEdit(ctx *domain.Context, request domain.Edi
}); err != nil {
return nil, err
}
for _, l := range request.RemoveList {
if e := ptr.remove(ctx, table, l, request.Where); e != nil {
log.Logger.Error(e.Error())
}
if err = starrocks.BatchDelete(starrocks.DB, table.SQLName, request.RemoveList); err != nil {
return nil, err
}
//for _, l := range request.RemoveList {
// if e := ptr.remove(ctx, table, l, request.Where); e != nil {
// log.Logger.Error(e.Error())
// }
//}
}
for _, l := range request.UpdateList {
if e := ptr.update(ctx, table, l, request.Where); e != nil {
... ...
... ... @@ -119,7 +119,7 @@ func MappingFieldsV2(mainTable *domain.Table, fields []*domain.Field) []*domain.
fields[i].Flag = v.Flag
builder.NewDataField(v.Name, v.SQLType, v.Flag)
} else {
if f.Flag == domain.ManualField && f.Index == 0 {
if f.Flag == domain.ManualField {
//mainTable.DataFieldIndex += 1
fields[i] = builder.NewDataField(f.Name, f.SQLType, domain.ManualField)
fields[i].Description = f.Description
... ...
... ... @@ -73,6 +73,28 @@ func Delete(db *gorm.DB, tableName string, fields []*domain.FieldValue) error {
return tx.Error
}
func BatchDelete(db *gorm.DB, tableName string, fields []*domain.FieldValues) error {
var pk *domain.FieldValue
var values = make([]string, 0)
for _, row := range fields {
for _, f := range row.FieldValues {
if f.Field.Flag == domain.PKField && f.Value != "" {
pk = f
values = append(values, f.Value)
}
}
}
if len(values) == 0 {
return fmt.Errorf("删除行为空")
}
sql := db.ToSQL(func(tx *gorm.DB) *gorm.DB {
c := Condition{}
return tx.Table(tableName).Where(fmt.Sprintf("%s in %s", pk.Field.SQLName, c.InArgs(values))).Delete("")
})
tx := db.Exec(sql)
return tx.Error
}
//DROP VIEW IF EXISTS
func DropView(db *gorm.DB, tableName string) error {
... ...
... ... @@ -146,6 +146,8 @@ func (c Condition) SetWhere(params QueryOptions, q *gorm.DB) {
} else {
q.Where(fmt.Sprintf("%v in %v", c.CastType(c.Field.SQLName, domain.DECIMALV2.ToString()), c.InArgs(c.In)))
}
} else if c.Field.SQLType == domain.Date.ToString() {
q.Where(fmt.Sprintf("%v in %v", c.CastType(c.FormatIfNull(params, c.Field), "datetime"), c.InArgs(c.In)))
} else {
q.Where(fmt.Sprintf("%v in %v", c.CastType(c.FormatIfNull(params, c.Field), "string"), c.InArgs(c.In)))
}
... ...