search_chart_components_logic.go
1.7 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
59
60
61
62
63
64
65
66
67
68
69
package chart
import (
"context"
"fmt"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/interanl/pkg/domain"
"strings"
"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 SearchChartComponentsLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewSearchChartComponentsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SearchChartComponentsLogic {
return &SearchChartComponentsLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *SearchChartComponentsLogic) SearchChartComponents(req *types.ChartComponentSearchRequest) (resp *types.ChartComponentSearchResponse, err error) {
pathMaker := func(filename string) string {
return fmt.Sprintf("%s/%s/%s", l.svcCtx.Config.HostName, "public", filename)
}
var list = []types.ChartComponentItem{
{
Name: "记录型表格",
Code: domain.RecordTable1,
Cover: pathMaker("RecordTable-1.png"),
},
{
Name: "总体指标",
Code: domain.MetricsCard1,
Cover: pathMaker("MetricsCard-1.png"),
},
{
Name: "容器卡片",
Code: domain.ContainerCard1,
Cover: pathMaker("ContainerCard-1.png"),
},
{
Name: "四分图",
Code: domain.QuarterChart1,
Cover: pathMaker("QuarterChart-1.png"),
},
}
var result = make([]types.ChartComponentItem, 0)
for _, com := range list {
if req.Name != "" {
if !strings.Contains(com.Name, req.Name) {
continue
}
}
result = append(result, com)
}
resp = &types.ChartComponentSearchResponse{
List: result,
Total: int64(len(result)),
}
return
}