作者 yangfu

chore: compatible optimize

@@ -13,6 +13,7 @@ import ( @@ -13,6 +13,7 @@ import (
13 "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/excel" 13 "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/excel"
14 "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/starrocks" 14 "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/starrocks"
15 "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/utils" 15 "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/utils"
  16 + "strings"
16 "time" 17 "time"
17 ) 18 )
18 19
@@ -311,6 +312,39 @@ func (querySetService *QuerySetService) SearchQuerySet(ctx *domain.Context, sear @@ -311,6 +312,39 @@ func (querySetService *QuerySetService) SearchQuerySet(ctx *domain.Context, sear
311 return nil, factory.FastError(err) 312 return nil, factory.FastError(err)
312 } 313 }
313 314
  315 + if len(searchQuerySetQuery.MatchName) > 0 {
  316 + mapQuerySet := (domain.QuerySets(querySets)).ToMap()
  317 + tmpQuerySets := make([]*domain.QuerySet, 0)
  318 + for _, item := range querySets {
  319 + if strings.Contains(item.Name, searchQuerySetQuery.MatchName) {
  320 + tmpQuerySets = append(tmpQuerySets, item)
  321 + }
  322 + }
  323 +
  324 + tmpParentQuerySets := make([]*domain.QuerySet, 0)
  325 + mapTmpParentQuerySets := (domain.QuerySets(tmpQuerySets)).ToMap()
  326 + for _, item := range tmpQuerySets {
  327 + var parentId = item.ParentId
  328 + for {
  329 + if parentId <= 0 {
  330 + break
  331 + }
  332 + v, ok := mapQuerySet[parentId]
  333 + if !ok {
  334 + break
  335 + }
  336 + if _, ok := mapTmpParentQuerySets[v.QuerySetId]; !ok {
  337 + mapTmpParentQuerySets[v.QuerySetId] = v
  338 + tmpParentQuerySets = append(tmpParentQuerySets, v)
  339 + }
  340 + parentId = v.ParentId
  341 + }
  342 + }
  343 +
  344 + tmpQuerySets = append(tmpQuerySets, tmpParentQuerySets...)
  345 + querySets = tmpQuerySets
  346 + }
  347 +
314 var result = dto.NewQuerySetDtoList(querySets) 348 var result = dto.NewQuerySetDtoList(querySets)
315 349
316 if err := transactionContext.CommitTransaction(); err != nil { 350 if err := transactionContext.CommitTransaction(); err != nil {
@@ -132,3 +132,13 @@ func (querySet *QuerySet) GetDependencyTables(queryComponents []*QueryComponent) @@ -132,3 +132,13 @@ func (querySet *QuerySet) GetDependencyTables(queryComponents []*QueryComponent)
132 sort.Ints(res) 132 sort.Ints(res)
133 return res 133 return res
134 } 134 }
  135 +
  136 +type QuerySets []*QuerySet
  137 +
  138 +func (querySets QuerySets) ToMap() map[int]*QuerySet {
  139 + var result = make(map[int]*QuerySet)
  140 + for i := range querySets {
  141 + result[querySets[i].QuerySetId] = querySets[i]
  142 + }
  143 + return result
  144 +}
@@ -160,7 +160,7 @@ func (repository *QuerySetRepository) Find(queryOptions map[string]interface{}) @@ -160,7 +160,7 @@ func (repository *QuerySetRepository) Find(queryOptions map[string]interface{})
160 query.SetWhereByQueryOption("type = ?", "type") 160 query.SetWhereByQueryOption("type = ?", "type")
161 query.SetWhereByQueryOption("flag = ?", "flag") 161 query.SetWhereByQueryOption("flag = ?", "flag")
162 query.SetWhereByQueryOption("status = ?", "status") 162 query.SetWhereByQueryOption("status = ?", "status")
163 - query.SetWhereByQueryOption(fmt.Sprintf("name like '%%%v%%'", queryOptions["matchName"]), "matchName") 163 + //query.SetWhereByQueryOption(fmt.Sprintf("name like '%%%v%%'", queryOptions["matchName"]), "matchName")
164 if v, ok := queryOptions["types"]; ok && len(v.([]string)) > 0 { 164 if v, ok := queryOptions["types"]; ok && len(v.([]string)) > 0 {
165 query.Where("type in (?)", pg.In(v)) 165 query.Where("type in (?)", pg.In(v))
166 } 166 }