正在显示
8 个修改的文件
包含
102 行增加
和
22 行删除
@@ -30,7 +30,7 @@ func NewSaveChartLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SaveCha | @@ -30,7 +30,7 @@ func NewSaveChartLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SaveCha | ||
30 | 30 | ||
31 | func (l *SaveChartLogic) SaveChart(req *types.ChartSaveRequest) (resp *types.ChartSaveResponse, err error) { | 31 | func (l *SaveChartLogic) SaveChart(req *types.ChartSaveRequest) (resp *types.ChartSaveResponse, err error) { |
32 | var ( | 32 | var ( |
33 | - //conn = l.svcCtx.DefaultDBConn() | 33 | + conn = l.svcCtx.DefaultDBConn() |
34 | //parentChart *domain.Chart | 34 | //parentChart *domain.Chart |
35 | chart *domain.Chart | 35 | chart *domain.Chart |
36 | chartSetting *domain.ChartSetting | 36 | chartSetting *domain.ChartSetting |
@@ -62,6 +62,9 @@ func (l *SaveChartLogic) SaveChart(req *types.ChartSaveRequest) (resp *types.Cha | @@ -62,6 +62,9 @@ func (l *SaveChartLogic) SaveChart(req *types.ChartSaveRequest) (resp *types.Cha | ||
62 | //if currentSortChart, _ := l.svcCtx.ChartRepository.FindOneByGroup(l.ctx, conn, tenantId, req.Pid); currentSortChart != nil { | 62 | //if currentSortChart, _ := l.svcCtx.ChartRepository.FindOneByGroup(l.ctx, conn, tenantId, req.Pid); currentSortChart != nil { |
63 | // chart.Sort = currentSortChart.Sort + 1 | 63 | // chart.Sort = currentSortChart.Sort + 1 |
64 | //} | 64 | //} |
65 | + if total, _, _ := l.svcCtx.ChartRepository.FindByTypeAndName(l.ctx, conn, tenantId, req.Type, req.Name); total > 0 { | ||
66 | + return nil, xerr.NewErrMsgErr("图表名字重复", nil) | ||
67 | + } | ||
65 | if err = transaction.UseTrans(l.ctx, l.svcCtx.DB, func(ctx context.Context, conn transaction.Conn) error { | 68 | if err = transaction.UseTrans(l.ctx, l.svcCtx.DB, func(ctx context.Context, conn transaction.Conn) error { |
66 | if chart, err = l.svcCtx.ChartRepository.Insert(ctx, conn, chart); err != nil { | 69 | if chart, err = l.svcCtx.ChartRepository.Insert(ctx, conn, chart); err != nil { |
67 | return err | 70 | return err |
@@ -29,7 +29,7 @@ func NewSaveAppPageLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SaveA | @@ -29,7 +29,7 @@ func NewSaveAppPageLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SaveA | ||
29 | 29 | ||
30 | func (l *SaveAppPageLogic) SaveAppPage(req *types.AppPageSaveRequest) (resp *types.AppPageSaveResponse, err error) { | 30 | func (l *SaveAppPageLogic) SaveAppPage(req *types.AppPageSaveRequest) (resp *types.AppPageSaveResponse, err error) { |
31 | var ( | 31 | var ( |
32 | - //conn = l.svcCtx.DefaultDBConn() | 32 | + conn = l.svcCtx.DefaultDBConn() |
33 | appPage *domain.AppPage | 33 | appPage *domain.AppPage |
34 | tenantId = contextdata.GetTenantFromCtx(l.ctx) | 34 | tenantId = contextdata.GetTenantFromCtx(l.ctx) |
35 | ) | 35 | ) |
@@ -39,6 +39,9 @@ func (l *SaveAppPageLogic) SaveAppPage(req *types.AppPageSaveRequest) (resp *typ | @@ -39,6 +39,9 @@ func (l *SaveAppPageLogic) SaveAppPage(req *types.AppPageSaveRequest) (resp *typ | ||
39 | TenantId: tenantId, | 39 | TenantId: tenantId, |
40 | Cover: req.Cover, | 40 | Cover: req.Cover, |
41 | } | 41 | } |
42 | + if total, _, _ := l.svcCtx.AppPageRepository.FindByName(l.ctx, conn, tenantId, req.Name); total > 0 { | ||
43 | + return nil, xerr.NewErrMsgErr("页面名字重复", nil) | ||
44 | + } | ||
42 | if err = transaction.UseTrans(l.ctx, l.svcCtx.DB, func(ctx context.Context, conn transaction.Conn) error { | 45 | if err = transaction.UseTrans(l.ctx, l.svcCtx.DB, func(ctx context.Context, conn transaction.Conn) error { |
43 | if appPage, err = l.svcCtx.AppPageRepository.Insert(l.ctx, conn, appPage); err != nil { | 46 | if appPage, err = l.svcCtx.AppPageRepository.Insert(l.ctx, conn, appPage); err != nil { |
44 | return err | 47 | return err |
@@ -39,27 +39,28 @@ func (l *SearchTableByModuleLogic) SearchTableByModule(req *types.SearchTableByM | @@ -39,27 +39,28 @@ func (l *SearchTableByModuleLogic) SearchTableByModule(req *types.SearchTableByM | ||
39 | } | 39 | } |
40 | result["导入模块"] = newList(list) | 40 | result["导入模块"] = newList(list) |
41 | }, func() { | 41 | }, func() { |
42 | - list, err := l.svcCtx.ByteMetadataService.ObjectTableSearch(l.ctx, bytelib.ObjectTableSearchRequest{ | ||
43 | - Token: req.Token, | ||
44 | - TableTypes: []string{bytelib.SchemaTable}, | ||
45 | - Module: bytelib.ModuleQuerySetCenter, | ||
46 | - ReturnGroupItem: true, | ||
47 | - }) | ||
48 | - if err != nil { | ||
49 | - batchError.Add(err) | ||
50 | - } | ||
51 | - result["拆解模块"] = newList(list) | 42 | + //list, err := l.svcCtx.ByteMetadataService.ObjectTableSearch(l.ctx, bytelib.ObjectTableSearchRequest{ |
43 | + // Token: req.Token, | ||
44 | + // TableTypes: []string{bytelib.SchemaTable}, | ||
45 | + // Module: bytelib.ModuleQuerySetCenter, | ||
46 | + // ReturnGroupItem: true, | ||
47 | + //}) | ||
48 | + //if err != nil { | ||
49 | + // batchError.Add(err) | ||
50 | + //} | ||
51 | + //result["拆解模块"] = newList(list) | ||
52 | }, func() { | 52 | }, func() { |
53 | - list, err := l.svcCtx.ByteMetadataService.ObjectTableSearch(l.ctx, bytelib.ObjectTableSearchRequest{ | ||
54 | - Token: req.Token, | ||
55 | - TableTypes: []string{bytelib.CalculateItem, bytelib.CalculateSet}, | ||
56 | - Module: bytelib.ModuleCalculateCenter, | ||
57 | - ReturnGroupItem: true, | ||
58 | - }) | ||
59 | - if err != nil { | ||
60 | - batchError.Add(err) | ||
61 | - } | ||
62 | - result["计算模块"] = newList(list) | 53 | + //list, err := l.svcCtx.ByteMetadataService.ObjectTableSearch(l.ctx, bytelib.ObjectTableSearchRequest{ |
54 | + // Token: req.Token, | ||
55 | + // TableTypes: []string{bytelib.CalculateItem, bytelib.CalculateSet}, | ||
56 | + // Module: bytelib.ModuleCalculateCenter, | ||
57 | + // ReturnGroupItem: true, | ||
58 | + // ExcludeTables: []int{0}, | ||
59 | + //}) | ||
60 | + //if err != nil { | ||
61 | + // batchError.Add(err) | ||
62 | + //} | ||
63 | + //result["计算模块"] = newList(list) | ||
63 | }) | 64 | }) |
64 | if err = batchError.Err(); err != nil { | 65 | if err = batchError.Err(); err != nil { |
65 | logx.Error(err) | 66 | logx.Error(err) |
@@ -195,6 +195,36 @@ func (repository *AppPageRepository) Find(ctx context.Context, conn transaction. | @@ -195,6 +195,36 @@ func (repository *AppPageRepository) Find(ctx context.Context, conn transaction. | ||
195 | return total, dms, nil | 195 | return total, dms, nil |
196 | } | 196 | } |
197 | 197 | ||
198 | +func (repository *AppPageRepository) FindByName(ctx context.Context, conn transaction.Conn, tenantId int64, name string) (int64, []*domain.AppPage, error) { | ||
199 | + var ( | ||
200 | + tx = conn.DB() | ||
201 | + ms []*models.AppPage | ||
202 | + dms = make([]*domain.AppPage, 0) | ||
203 | + ) | ||
204 | + queryFunc := func() (interface{}, error) { | ||
205 | + tx = tx.Model(&ms).Order("id desc") | ||
206 | + tx.Where("tenant_id = ?", tenantId) | ||
207 | + tx.Where("name = ?", name) | ||
208 | + if tx = tx.Find(&ms); tx.Error != nil { | ||
209 | + return dms, tx.Error | ||
210 | + } | ||
211 | + return dms, nil | ||
212 | + } | ||
213 | + | ||
214 | + if _, err := repository.Query(queryFunc); err != nil { | ||
215 | + return 0, nil, err | ||
216 | + } | ||
217 | + | ||
218 | + for _, item := range ms { | ||
219 | + if dm, err := repository.ModelToDomainModel(item); err != nil { | ||
220 | + return 0, dms, err | ||
221 | + } else { | ||
222 | + dms = append(dms, dm) | ||
223 | + } | ||
224 | + } | ||
225 | + return int64(len(dms)), dms, nil | ||
226 | +} | ||
227 | + | ||
198 | func (repository *AppPageRepository) ModelToDomainModel(from *models.AppPage) (*domain.AppPage, error) { | 228 | func (repository *AppPageRepository) ModelToDomainModel(from *models.AppPage) (*domain.AppPage, error) { |
199 | to := &domain.AppPage{} | 229 | to := &domain.AppPage{} |
200 | err := copier.Copy(to, from) | 230 | err := copier.Copy(to, from) |
@@ -149,6 +149,39 @@ func (repository *ChartRepository) Find(ctx context.Context, conn transaction.Co | @@ -149,6 +149,39 @@ func (repository *ChartRepository) Find(ctx context.Context, conn transaction.Co | ||
149 | return total, dms, nil | 149 | return total, dms, nil |
150 | } | 150 | } |
151 | 151 | ||
152 | +// FindByTypeAndName 按类型、名称搜索图表(判断重复的图表) | ||
153 | +func (repository *ChartRepository) FindByTypeAndName(ctx context.Context, conn transaction.Conn, tenantId int64, t string, name string) (int64, []*domain.Chart, error) { | ||
154 | + var ( | ||
155 | + tx = conn.DB() | ||
156 | + ms []*models.Chart | ||
157 | + dms = make([]*domain.Chart, 0) | ||
158 | + //total int64 | ||
159 | + ) | ||
160 | + queryFunc := func() (interface{}, error) { | ||
161 | + tx = tx.Model(&ms).Order("id desc") //.Order("pid asc").Order("sort asc") | ||
162 | + tx.Where("tenant_id = ?", tenantId) | ||
163 | + tx.Where("type = ?", t) | ||
164 | + tx.Where("name = ?", name) | ||
165 | + if tx = tx.Find(&ms); tx.Error != nil { | ||
166 | + return dms, tx.Error | ||
167 | + } | ||
168 | + return dms, nil | ||
169 | + } | ||
170 | + | ||
171 | + if _, err := repository.Query(queryFunc); err != nil { | ||
172 | + return 0, nil, err | ||
173 | + } | ||
174 | + | ||
175 | + for _, item := range ms { | ||
176 | + if dm, err := repository.ModelToDomainModel(item); err != nil { | ||
177 | + return 0, dms, err | ||
178 | + } else { | ||
179 | + dms = append(dms, dm) | ||
180 | + } | ||
181 | + } | ||
182 | + return int64(len(dms)), dms, nil | ||
183 | +} | ||
184 | + | ||
152 | func (repository *ChartRepository) FindOneByGroup(ctx context.Context, conn transaction.Conn, tenantId, pid int64) (*domain.Chart, error) { | 185 | func (repository *ChartRepository) FindOneByGroup(ctx context.Context, conn transaction.Conn, tenantId, pid int64) (*domain.Chart, error) { |
153 | var ( | 186 | var ( |
154 | err error | 187 | err error |
@@ -27,6 +27,7 @@ type AppPageRepository interface { | @@ -27,6 +27,7 @@ type AppPageRepository interface { | ||
27 | FindOneByKey(ctx context.Context, conn transaction.Conn, key string) (*AppPage, error) | 27 | FindOneByKey(ctx context.Context, conn transaction.Conn, key string) (*AppPage, error) |
28 | FindOneByChartId(ctx context.Context, conn transaction.Conn, tenantId, chartId int64) (*AppPage, error) | 28 | FindOneByChartId(ctx context.Context, conn transaction.Conn, tenantId, chartId int64) (*AppPage, error) |
29 | Find(ctx context.Context, conn transaction.Conn, queryOptions map[string]interface{}) (int64, []*AppPage, error) | 29 | Find(ctx context.Context, conn transaction.Conn, queryOptions map[string]interface{}) (int64, []*AppPage, error) |
30 | + FindByName(ctx context.Context, conn transaction.Conn, tenantId int64, name string) (int64, []*AppPage, error) | ||
30 | } | 31 | } |
31 | 32 | ||
32 | func (m *AppPage) Identify() interface{} { | 33 | func (m *AppPage) Identify() interface{} { |
@@ -34,6 +34,7 @@ type ChartRepository interface { | @@ -34,6 +34,7 @@ type ChartRepository interface { | ||
34 | FindOne(ctx context.Context, conn transaction.Conn, id int64) (*Chart, error) | 34 | FindOne(ctx context.Context, conn transaction.Conn, id int64) (*Chart, error) |
35 | Find(ctx context.Context, conn transaction.Conn, queryOptions map[string]interface{}) (int64, []*Chart, error) | 35 | Find(ctx context.Context, conn transaction.Conn, queryOptions map[string]interface{}) (int64, []*Chart, error) |
36 | FindOneByGroup(ctx context.Context, conn transaction.Conn, tenantId, pid int64) (*Chart, error) | 36 | FindOneByGroup(ctx context.Context, conn transaction.Conn, tenantId, pid int64) (*Chart, error) |
37 | + FindByTypeAndName(ctx context.Context, conn transaction.Conn, tenantId int64, t string, name string) (int64, []*Chart, error) | ||
37 | } | 38 | } |
38 | 39 | ||
39 | /*************** 索引函数 开始****************/ | 40 | /*************** 索引函数 开始****************/ |
@@ -70,6 +70,14 @@ func (gateway Service) Do(ctx context.Context, url string, method string, val in | @@ -70,6 +70,14 @@ func (gateway Service) Do(ctx context.Context, url string, method string, val in | ||
70 | if err = json.Unmarshal(body, &baseResponse); err != nil { | 70 | if err = json.Unmarshal(body, &baseResponse); err != nil { |
71 | return err | 71 | return err |
72 | } | 72 | } |
73 | + if baseResponse.Code != 0 { | ||
74 | + return HttpError{ | ||
75 | + Base: Response{ | ||
76 | + Code: baseResponse.Code, | ||
77 | + Msg: baseResponse.Msg, | ||
78 | + }, | ||
79 | + } | ||
80 | + } | ||
73 | if err = mapping.UnmarshalJsonBytes(baseResponse.Data, result); err != nil { | 81 | if err = mapping.UnmarshalJsonBytes(baseResponse.Data, result); err != nil { |
74 | return err | 82 | return err |
75 | } | 83 | } |
-
请 注册 或 登录 后发表评论