save_app_page_logic.go
1.8 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
package page
import (
"context"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/interanl/pkg/db/transaction"
"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/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 SaveAppPageLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewSaveAppPageLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SaveAppPageLogic {
return &SaveAppPageLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *SaveAppPageLogic) SaveAppPage(req *types.AppPageSaveRequest) (resp *types.AppPageSaveResponse, err error) {
var (
conn = l.svcCtx.DefaultDBConn()
appPage *domain.AppPage
tenantId = contextdata.GetTenantFromCtx(l.ctx)
)
appPage = &domain.AppPage{
Name: req.Name,
Charts: req.Charts,
TenantId: tenantId,
Cover: req.Cover,
}
if total, _, _ := l.svcCtx.AppPageRepository.FindByName(l.ctx, conn, tenantId, req.Name); total > 0 {
return nil, xerr.NewErrMsgErr("页面名字重复", nil)
}
if err = transaction.UseTrans(l.ctx, l.svcCtx.DB, func(ctx context.Context, conn transaction.Conn) error {
if appPage, err = l.svcCtx.AppPageRepository.Insert(l.ctx, conn, appPage); err != nil {
return err
}
return nil
}, true); err != nil {
return nil, xerr.NewErrMsgErr("创建页面失败", err)
}
resp = &types.AppPageSaveResponse{
Id: appPage.Id,
}
return
}