save_as_chart_logic.go
1.5 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
package chart
import (
"context"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/interanl/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/pkg/xerr"
"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 SaveAsChartLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewSaveAsChartLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SaveAsChartLogic {
return &SaveAsChartLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *SaveAsChartLogic) SaveAsChart(req *types.ChartSaveAsRequest) (resp *types.ChartSaveResponse, err error) {
var (
conn = l.svcCtx.DefaultDBConn()
chartSetting *domain.ChartSetting
chart *domain.Chart
)
chart, err = l.svcCtx.ChartRepository.FindOne(l.ctx, conn, req.ChartId)
if err != nil {
return nil, xerr.NewErrMsgErr("未找到图表", err)
}
chartSetting, err = l.svcCtx.ChartSettingRepository.FindOne(l.ctx, conn, req.ChartId)
if err != nil {
return nil, xerr.NewErrMsgErr("未找到图表", err)
}
saveChartLogic := NewSaveChartLogic(l.ctx, l.svcCtx)
resp, err = saveChartLogic.SaveChart(&types.ChartSaveRequest{
Pid: 0,
Type: chart.Type,
ChartType: chart.ChartType,
ChartProperty: types.NewPropertyItem(chartSetting.ChartProperty(chart.Cover)),
})
return
}