作者 yangfu

feat: add table filter ruler

@@ -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 // *:匹配所有
@@ -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