search_chart_logic.go
1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package chart
import (
"context"
"github.com/samber/lo"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/interanl/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/pkg/contextdata"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/pkg/xcollection"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/api/internal/types"
"github.com/zeromicro/go-zero/core/logx"
)
type SearchChartLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewSearchChartLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SearchChartLogic {
return &SearchChartLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *SearchChartLogic) SearchChart(req *types.ChartSearchRequest) (resp interface{}, err error) {
var (
conn = l.svcCtx.DefaultDBConn()
tenantId = contextdata.GetTenantFromCtx(l.ctx)
charts []*domain.Chart
)
_, charts, err = l.svcCtx.ChartRepository.Find(l.ctx, conn, domain.IndexTenantId(tenantId)())
var chartItems = make([]xcollection.TreeNode, 0)
lo.EveryBy(charts, func(chart *domain.Chart) bool {
// 按类型过滤
if len(req.IncludeTypes) > 0 {
if !lo.Contains(req.IncludeTypes, chart.Type) {
return true
}
}
chartItems = append(chartItems, types.NewChartItem(chart))
return true
})
if req.DataStyle == "tree" {
resp = xcollection.NewTree(chartItems).Nodes
} else if req.DataStyle == "flat" {
resp = chartItems
} else {
resp = chartItems
}
return map[string]interface{}{
"list": resp,
}, nil
}