diff --git a/mongo/mongo.go b/mongo/mongo.go index c262864..b4d2aac 100644 --- a/mongo/mongo.go +++ b/mongo/mongo.go @@ -9,9 +9,10 @@ import ( "context" "errors" "fmt" - "gitee.com/red-future---jilin-g/common/log/consts" "time" + "gitee.com/red-future---jilin-g/common/log/consts" + "gitee.com/red-future---jilin-g/common/beans" "gitee.com/red-future---jilin-g/common/log/model/entity" "gitee.com/red-future---jilin-g/common/redis" @@ -460,16 +461,16 @@ func (m *MongoDB) Delete(ctx context.Context, filter bson.M, collection string, } // DeleteSoft 假删除记录 -func (m *MongoDB) DeleteSoft(ctx context.Context, filter bson.M, collection string, opts ...options.Lister[options.UpdateManyOptions]) (result *mongo.UpdateResult, err error) { +func (m *MongoDB) DeleteSoft(ctx context.Context, filter bson.M, collection string, opts ...options.Lister[options.UpdateManyOptions]) (modifiedCount int64, err error) { update := bson.M{"$set": bson.M{"isDeleted": true}} return m.Update(ctx, filter, update, collection, opts...) } // Update 修改记录 -func (m *MongoDB) Update(ctx context.Context, filter bson.M, update bson.M, collection string, opts ...options.Lister[options.UpdateManyOptions]) (result *mongo.UpdateResult, err error) { +func (m *MongoDB) Update(ctx context.Context, filter bson.M, update bson.M, collection string, opts ...options.Lister[options.UpdateManyOptions]) (modifiedCount int64, err error) { source, err := m.getDataSource() if err != nil { - return nil, err + return 0, err } db := source.Database() @@ -507,10 +508,11 @@ func (m *MongoDB) Update(ctx context.Context, filter bson.M, update bson.M, coll } setDoc["updatedAt"] = gtime.Now().Time update["$set"] = setDoc - result, err = db.Collection(collection).UpdateMany(ctx, filter, update, opts...) + result, err := db.Collection(collection).UpdateMany(ctx, filter, update, opts...) if err != nil { return } + modifiedCount = result.ModifiedCount // 清理redis err = m.CleanRedis(ctx, filter, user.TenantId, collection) // 写日志