作者 yangfu

fix bug name duplicate

... ... @@ -30,7 +30,7 @@ func NewSaveChartLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SaveCha
func (l *SaveChartLogic) SaveChart(req *types.ChartSaveRequest) (resp *types.ChartSaveResponse, err error) {
var (
//conn = l.svcCtx.DefaultDBConn()
conn = l.svcCtx.DefaultDBConn()
//parentChart *domain.Chart
chart *domain.Chart
chartSetting *domain.ChartSetting
... ... @@ -62,6 +62,9 @@ func (l *SaveChartLogic) SaveChart(req *types.ChartSaveRequest) (resp *types.Cha
//if currentSortChart, _ := l.svcCtx.ChartRepository.FindOneByGroup(l.ctx, conn, tenantId, req.Pid); currentSortChart != nil {
// chart.Sort = currentSortChart.Sort + 1
//}
if total, _, _ := l.svcCtx.ChartRepository.FindByTypeAndName(l.ctx, conn, tenantId, req.Type, 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 chart, err = l.svcCtx.ChartRepository.Insert(ctx, conn, chart); err != nil {
return err
... ...
... ... @@ -29,7 +29,7 @@ func NewSaveAppPageLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SaveA
func (l *SaveAppPageLogic) SaveAppPage(req *types.AppPageSaveRequest) (resp *types.AppPageSaveResponse, err error) {
var (
//conn = l.svcCtx.DefaultDBConn()
conn = l.svcCtx.DefaultDBConn()
appPage *domain.AppPage
tenantId = contextdata.GetTenantFromCtx(l.ctx)
)
... ... @@ -39,6 +39,9 @@ func (l *SaveAppPageLogic) SaveAppPage(req *types.AppPageSaveRequest) (resp *typ
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
... ...
... ... @@ -39,27 +39,28 @@ func (l *SearchTableByModuleLogic) SearchTableByModule(req *types.SearchTableByM
}
result["导入模块"] = newList(list)
}, func() {
list, err := l.svcCtx.ByteMetadataService.ObjectTableSearch(l.ctx, bytelib.ObjectTableSearchRequest{
Token: req.Token,
TableTypes: []string{bytelib.SchemaTable},
Module: bytelib.ModuleQuerySetCenter,
ReturnGroupItem: true,
})
if err != nil {
batchError.Add(err)
}
result["拆解模块"] = newList(list)
//list, err := l.svcCtx.ByteMetadataService.ObjectTableSearch(l.ctx, bytelib.ObjectTableSearchRequest{
// Token: req.Token,
// TableTypes: []string{bytelib.SchemaTable},
// Module: bytelib.ModuleQuerySetCenter,
// ReturnGroupItem: true,
//})
//if err != nil {
// batchError.Add(err)
//}
//result["拆解模块"] = newList(list)
}, func() {
list, err := l.svcCtx.ByteMetadataService.ObjectTableSearch(l.ctx, bytelib.ObjectTableSearchRequest{
Token: req.Token,
TableTypes: []string{bytelib.CalculateItem, bytelib.CalculateSet},
Module: bytelib.ModuleCalculateCenter,
ReturnGroupItem: true,
})
if err != nil {
batchError.Add(err)
}
result["计算模块"] = newList(list)
//list, err := l.svcCtx.ByteMetadataService.ObjectTableSearch(l.ctx, bytelib.ObjectTableSearchRequest{
// Token: req.Token,
// TableTypes: []string{bytelib.CalculateItem, bytelib.CalculateSet},
// Module: bytelib.ModuleCalculateCenter,
// ReturnGroupItem: true,
// ExcludeTables: []int{0},
//})
//if err != nil {
// batchError.Add(err)
//}
//result["计算模块"] = newList(list)
})
if err = batchError.Err(); err != nil {
logx.Error(err)
... ...
... ... @@ -195,6 +195,36 @@ func (repository *AppPageRepository) Find(ctx context.Context, conn transaction.
return total, dms, nil
}
func (repository *AppPageRepository) FindByName(ctx context.Context, conn transaction.Conn, tenantId int64, name string) (int64, []*domain.AppPage, error) {
var (
tx = conn.DB()
ms []*models.AppPage
dms = make([]*domain.AppPage, 0)
)
queryFunc := func() (interface{}, error) {
tx = tx.Model(&ms).Order("id desc")
tx.Where("tenant_id = ?", tenantId)
tx.Where("name = ?", name)
if tx = tx.Find(&ms); tx.Error != nil {
return dms, tx.Error
}
return dms, nil
}
if _, err := repository.Query(queryFunc); err != nil {
return 0, nil, err
}
for _, item := range ms {
if dm, err := repository.ModelToDomainModel(item); err != nil {
return 0, dms, err
} else {
dms = append(dms, dm)
}
}
return int64(len(dms)), dms, nil
}
func (repository *AppPageRepository) ModelToDomainModel(from *models.AppPage) (*domain.AppPage, error) {
to := &domain.AppPage{}
err := copier.Copy(to, from)
... ...
... ... @@ -149,6 +149,39 @@ func (repository *ChartRepository) Find(ctx context.Context, conn transaction.Co
return total, dms, nil
}
// FindByTypeAndName 按类型、名称搜索图表(判断重复的图表)
func (repository *ChartRepository) FindByTypeAndName(ctx context.Context, conn transaction.Conn, tenantId int64, t string, name string) (int64, []*domain.Chart, error) {
var (
tx = conn.DB()
ms []*models.Chart
dms = make([]*domain.Chart, 0)
//total int64
)
queryFunc := func() (interface{}, error) {
tx = tx.Model(&ms).Order("id desc") //.Order("pid asc").Order("sort asc")
tx.Where("tenant_id = ?", tenantId)
tx.Where("type = ?", t)
tx.Where("name = ?", name)
if tx = tx.Find(&ms); tx.Error != nil {
return dms, tx.Error
}
return dms, nil
}
if _, err := repository.Query(queryFunc); err != nil {
return 0, nil, err
}
for _, item := range ms {
if dm, err := repository.ModelToDomainModel(item); err != nil {
return 0, dms, err
} else {
dms = append(dms, dm)
}
}
return int64(len(dms)), dms, nil
}
func (repository *ChartRepository) FindOneByGroup(ctx context.Context, conn transaction.Conn, tenantId, pid int64) (*domain.Chart, error) {
var (
err error
... ...
... ... @@ -27,6 +27,7 @@ type AppPageRepository interface {
FindOneByKey(ctx context.Context, conn transaction.Conn, key string) (*AppPage, error)
FindOneByChartId(ctx context.Context, conn transaction.Conn, tenantId, chartId int64) (*AppPage, error)
Find(ctx context.Context, conn transaction.Conn, queryOptions map[string]interface{}) (int64, []*AppPage, error)
FindByName(ctx context.Context, conn transaction.Conn, tenantId int64, name string) (int64, []*AppPage, error)
}
func (m *AppPage) Identify() interface{} {
... ...
... ... @@ -34,6 +34,7 @@ type ChartRepository interface {
FindOne(ctx context.Context, conn transaction.Conn, id int64) (*Chart, error)
Find(ctx context.Context, conn transaction.Conn, queryOptions map[string]interface{}) (int64, []*Chart, error)
FindOneByGroup(ctx context.Context, conn transaction.Conn, tenantId, pid int64) (*Chart, error)
FindByTypeAndName(ctx context.Context, conn transaction.Conn, tenantId int64, t string, name string) (int64, []*Chart, error)
}
/*************** 索引函数 开始****************/
... ...
... ... @@ -70,6 +70,14 @@ func (gateway Service) Do(ctx context.Context, url string, method string, val in
if err = json.Unmarshal(body, &baseResponse); err != nil {
return err
}
if baseResponse.Code != 0 {
return HttpError{
Base: Response{
Code: baseResponse.Code,
Msg: baseResponse.Msg,
},
}
}
if err = mapping.UnmarshalJsonBytes(baseResponse.Data, result); err != nil {
return err
}
... ...