fix 代码生成-导入表错误处理
This commit is contained in:
parent
953b1200e8
commit
db0b773269
@ -144,42 +144,33 @@ func (s *sToolsGenTable) SelectDbTableListByNames(ctx context.Context, tableName
|
|||||||
func (s *sToolsGenTable) ImportGenTable(ctx context.Context, tableList []*entity.ToolsGenTable) error {
|
func (s *sToolsGenTable) ImportGenTable(ctx context.Context, tableList []*entity.ToolsGenTable) error {
|
||||||
if tableList != nil {
|
if tableList != nil {
|
||||||
err := g.DB().Transaction(ctx, func(ctx context.Context, tx gdb.TX) error {
|
err := g.DB().Transaction(ctx, func(ctx context.Context, tx gdb.TX) error {
|
||||||
|
err := g.Try(ctx, func(ctx context.Context) {
|
||||||
for _, table := range tableList {
|
for _, table := range tableList {
|
||||||
tableName := table.TableName
|
tableName := table.TableName
|
||||||
// 保存列信息
|
// 保存列信息
|
||||||
genTableColumns, err := service.ToolsGenTableColumn().SelectDbTableColumnsByName(ctx, tableName)
|
genTableColumns, err := service.ToolsGenTableColumn().SelectDbTableColumnsByName(ctx, tableName)
|
||||||
if err != nil || len(genTableColumns) <= 0 {
|
liberr.ErrIsNil(ctx, err, "获取列数据失败")
|
||||||
_ = tx.Rollback()
|
if len(genTableColumns) <= 0 {
|
||||||
return gerror.New("获取列数据失败")
|
liberr.ErrIsNil(ctx, gerror.New("获取列数据失败"))
|
||||||
}
|
}
|
||||||
err = s.InitTable(ctx, table, genTableColumns)
|
err = s.InitTable(ctx, table, genTableColumns)
|
||||||
if err != nil {
|
liberr.ErrIsNil(ctx, err)
|
||||||
_ = tx.Rollback()
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
result, err1 := tx.Model(dao.ToolsGenTable.Table()).Insert(table)
|
result, err1 := tx.Model(dao.ToolsGenTable.Table()).Insert(table)
|
||||||
if err1 != nil {
|
liberr.ErrIsNil(ctx, err1)
|
||||||
_ = tx.Rollback()
|
|
||||||
return err1
|
|
||||||
}
|
|
||||||
tmpId, err2 := result.LastInsertId()
|
tmpId, err2 := result.LastInsertId()
|
||||||
|
liberr.ErrIsNil(ctx, err2, "保存数据失败")
|
||||||
if err2 != nil || tmpId <= 0 {
|
if tmpId <= 0 {
|
||||||
_ = tx.Rollback()
|
liberr.ErrIsNil(ctx, gerror.New("保存数据失败"))
|
||||||
return gerror.New("保存数据失败")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
table.TableId = tmpId
|
table.TableId = tmpId
|
||||||
for _, column := range genTableColumns {
|
for _, column := range genTableColumns {
|
||||||
service.ToolsGenTableColumn().InitColumnField(column, table)
|
service.ToolsGenTableColumn().InitColumnField(column, table)
|
||||||
_, err3 := tx.Model(dao.ToolsGenTableColumn.Table()).Insert(column)
|
_, err3 := tx.Model(dao.ToolsGenTableColumn.Table()).Insert(column)
|
||||||
if err3 != nil {
|
liberr.ErrIsNil(ctx, err3, "保存列数据失败")
|
||||||
_ = tx.Rollback()
|
|
||||||
return gerror.New("保存列数据失败")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
})
|
||||||
return nil
|
return err
|
||||||
})
|
})
|
||||||
return err
|
return err
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user