search_chart_components_logic.go 1.7 KB
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
}