|
@@ -3,6 +3,7 @@ package chart |
|
@@ -3,6 +3,7 @@ package chart |
3
|
import (
|
3
|
import (
|
4
|
"context"
|
4
|
"context"
|
5
|
"fmt"
|
5
|
"fmt"
|
|
|
6
|
+ "gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/interanl/pkg/db/transaction"
|
6
|
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/interanl/pkg/domain"
|
7
|
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/interanl/pkg/domain"
|
7
|
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/pkg/contextdata"
|
8
|
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/pkg/contextdata"
|
8
|
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/pkg/xerr"
|
9
|
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/pkg/xerr"
|
|
@@ -35,6 +36,7 @@ func (l *DeleteChartLogic) DeleteChart(req *types.ChartDeleteRequest) (resp *typ |
|
@@ -35,6 +36,7 @@ func (l *DeleteChartLogic) DeleteChart(req *types.ChartDeleteRequest) (resp *typ |
35
|
appPage *domain.AppPage
|
36
|
appPage *domain.AppPage
|
36
|
)
|
37
|
)
|
37
|
resp = &types.ChartDeleteResponse{}
|
38
|
resp = &types.ChartDeleteResponse{}
|
|
|
39
|
+
|
38
|
if chart, err = l.svcCtx.ChartRepository.FindOne(l.ctx, conn, req.Id); err != nil {
|
40
|
if chart, err = l.svcCtx.ChartRepository.FindOne(l.ctx, conn, req.Id); err != nil {
|
39
|
return nil, xerr.NewErrMsgErr("不存在", err)
|
41
|
return nil, xerr.NewErrMsgErr("不存在", err)
|
40
|
}
|
42
|
}
|
|
@@ -48,9 +50,23 @@ func (l *DeleteChartLogic) DeleteChart(req *types.ChartDeleteRequest) (resp *typ |
|
@@ -48,9 +50,23 @@ func (l *DeleteChartLogic) DeleteChart(req *types.ChartDeleteRequest) (resp *typ |
48
|
if appPage.Identify() != nil {
|
50
|
if appPage.Identify() != nil {
|
49
|
return nil, xerr.NewErrMsgErr(fmt.Sprintf("该图表已被页面\"%v\"引用", appPage.Name), err)
|
51
|
return nil, xerr.NewErrMsgErr(fmt.Sprintf("该图表已被页面\"%v\"引用", appPage.Name), err)
|
50
|
}
|
52
|
}
|
51
|
- if chart, err = l.svcCtx.ChartRepository.Delete(l.ctx, conn, chart); err != nil {
|
|
|
52
|
- return nil, xerr.NewErrMsgErr("删除失败", err)
|
|
|
53
|
- }
|
53
|
+
|
|
|
54
|
+ err = transaction.UseTrans(l.ctx, conn.DB(), func(ctx context.Context, conn transaction.Conn) error {
|
|
|
55
|
+ if chart, err = l.svcCtx.ChartRepository.Delete(l.ctx, conn, chart); err != nil {
|
|
|
56
|
+ return xerr.NewErrMsgErr("删除失败", err)
|
|
|
57
|
+ }
|
|
|
58
|
+ //删除数据源
|
|
|
59
|
+ chartSetting, err := l.svcCtx.ChartSettingRepository.FindOne(l.ctx, conn, chart.Id)
|
|
|
60
|
+ if err == nil && len(chartSetting.DataSourceIds) > 0 {
|
|
|
61
|
+ for _, sourceId := range chartSetting.DataSourceIds {
|
|
|
62
|
+ err = DeleteObjectTable(l.ctx, l.svcCtx, conn, int(sourceId))
|
|
|
63
|
+ if err != nil {
|
|
|
64
|
+ return xerr.NewErrMsg("删除失败")
|
|
|
65
|
+ }
|
|
|
66
|
+ }
|
|
|
67
|
+ }
|
|
|
68
|
+ return nil
|
|
|
69
|
+ }, true)
|
54
|
|
70
|
|
55
|
resp = &types.ChartDeleteResponse{}
|
71
|
resp = &types.ChartDeleteResponse{}
|
56
|
return
|
72
|
return
|