作者 yangfu

feat: add table filter ruler

... ... @@ -25,6 +25,8 @@ type SearchTableQuery struct {
ReturnDetailStructInfo bool `cname:"返回具体的结构信息 默认不返回" json:"returnDetailStructInfo"`
// 排除分组项,只返回一级列表;默认 false 不排除,连分组也返回
ReturnGroupItem bool `cname:"排除分组" json:"returnGroupItem"`
// 排除指定表
ExcludeTables []int `cname:"排除指定表" json:"excludeTables"`
Context *domain.Context
FilterRules []*FilterRule `json:"filterRules"`
TableId int `cname:"ID" json:"tableId"`
... ...
... ... @@ -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
... ...