正在显示
2 个修改的文件
包含
29 行增加
和
4 行删除
@@ -54,11 +54,14 @@ func (ptr *TableEditDataService) RowEdit(ctx *domain.Context, request domain.Edi | @@ -54,11 +54,14 @@ func (ptr *TableEditDataService) RowEdit(ctx *domain.Context, request domain.Edi | ||
54 | }); err != nil { | 54 | }); err != nil { |
55 | return nil, err | 55 | return nil, err |
56 | } | 56 | } |
57 | - for _, l := range request.RemoveList { | ||
58 | - if e := ptr.remove(ctx, table, l, request.Where); e != nil { | ||
59 | - log.Logger.Error(e.Error()) | ||
60 | - } | 57 | + if err = starrocks.BatchDelete(starrocks.DB, table.SQLName, request.RemoveList); err != nil { |
58 | + return nil, err | ||
61 | } | 59 | } |
60 | + //for _, l := range request.RemoveList { | ||
61 | + // if e := ptr.remove(ctx, table, l, request.Where); e != nil { | ||
62 | + // log.Logger.Error(e.Error()) | ||
63 | + // } | ||
64 | + //} | ||
62 | } | 65 | } |
63 | for _, l := range request.UpdateList { | 66 | for _, l := range request.UpdateList { |
64 | if e := ptr.update(ctx, table, l, request.Where); e != nil { | 67 | if e := ptr.update(ctx, table, l, request.Where); e != nil { |
@@ -73,6 +73,28 @@ func Delete(db *gorm.DB, tableName string, fields []*domain.FieldValue) error { | @@ -73,6 +73,28 @@ func Delete(db *gorm.DB, tableName string, fields []*domain.FieldValue) error { | ||
73 | return tx.Error | 73 | return tx.Error |
74 | } | 74 | } |
75 | 75 | ||
76 | +func BatchDelete(db *gorm.DB, tableName string, fields []*domain.FieldValues) error { | ||
77 | + var pk *domain.FieldValue | ||
78 | + var values = make([]string, 0) | ||
79 | + for _, row := range fields { | ||
80 | + for _, f := range row.FieldValues { | ||
81 | + if f.Field.Flag == domain.PKField && f.Value != "" { | ||
82 | + pk = f | ||
83 | + values = append(values, f.Value) | ||
84 | + } | ||
85 | + } | ||
86 | + } | ||
87 | + if len(values) == 0 { | ||
88 | + return fmt.Errorf("删除行为空") | ||
89 | + } | ||
90 | + sql := db.ToSQL(func(tx *gorm.DB) *gorm.DB { | ||
91 | + c := Condition{} | ||
92 | + return tx.Table(tableName).Where(fmt.Sprintf("%s in %s", pk.Field.SQLName, c.InArgs(values))).Delete("") | ||
93 | + }) | ||
94 | + tx := db.Exec(sql) | ||
95 | + return tx.Error | ||
96 | +} | ||
97 | + | ||
76 | //DROP VIEW IF EXISTS | 98 | //DROP VIEW IF EXISTS |
77 | 99 | ||
78 | func DropView(db *gorm.DB, tableName string) error { | 100 | func DropView(db *gorm.DB, tableName string) error { |
-
请 注册 或 登录 后发表评论