作者 yangfu

chore: compatible optimize

... ... @@ -13,6 +13,7 @@ import (
"gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/excel"
"gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/starrocks"
"gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/utils"
"strings"
"time"
)
... ... @@ -311,6 +312,39 @@ func (querySetService *QuerySetService) SearchQuerySet(ctx *domain.Context, sear
return nil, factory.FastError(err)
}
if len(searchQuerySetQuery.MatchName) > 0 {
mapQuerySet := (domain.QuerySets(querySets)).ToMap()
tmpQuerySets := make([]*domain.QuerySet, 0)
for _, item := range querySets {
if strings.Contains(item.Name, searchQuerySetQuery.MatchName) {
tmpQuerySets = append(tmpQuerySets, item)
}
}
tmpParentQuerySets := make([]*domain.QuerySet, 0)
mapTmpParentQuerySets := (domain.QuerySets(tmpQuerySets)).ToMap()
for _, item := range tmpQuerySets {
var parentId = item.ParentId
for {
if parentId <= 0 {
break
}
v, ok := mapQuerySet[parentId]
if !ok {
break
}
if _, ok := mapTmpParentQuerySets[v.QuerySetId]; !ok {
mapTmpParentQuerySets[v.QuerySetId] = v
tmpParentQuerySets = append(tmpParentQuerySets, v)
}
parentId = v.ParentId
}
}
tmpQuerySets = append(tmpQuerySets, tmpParentQuerySets...)
querySets = tmpQuerySets
}
var result = dto.NewQuerySetDtoList(querySets)
if err := transactionContext.CommitTransaction(); err != nil {
... ...
... ... @@ -132,3 +132,13 @@ func (querySet *QuerySet) GetDependencyTables(queryComponents []*QueryComponent)
sort.Ints(res)
return res
}
type QuerySets []*QuerySet
func (querySets QuerySets) ToMap() map[int]*QuerySet {
var result = make(map[int]*QuerySet)
for i := range querySets {
result[querySets[i].QuerySetId] = querySets[i]
}
return result
}
... ...
... ... @@ -160,7 +160,7 @@ func (repository *QuerySetRepository) Find(queryOptions map[string]interface{})
query.SetWhereByQueryOption("type = ?", "type")
query.SetWhereByQueryOption("flag = ?", "flag")
query.SetWhereByQueryOption("status = ?", "status")
query.SetWhereByQueryOption(fmt.Sprintf("name like '%%%v%%'", queryOptions["matchName"]), "matchName")
//query.SetWhereByQueryOption(fmt.Sprintf("name like '%%%v%%'", queryOptions["matchName"]), "matchName")
if v, ok := queryOptions["types"]; ok && len(v.([]string)) > 0 {
query.Where("type in (?)", pg.In(v))
}
... ...