复制项目

This commit is contained in:
kim.dev.6789
2026-01-14 22:35:45 +08:00
parent 305d526110
commit b7f8db7d08
297 changed files with 81784 additions and 0 deletions

View File

@@ -0,0 +1,50 @@
package bot
import (
"context"
"git.imall.cloud/openim/chat/pkg/common/db/table/bot"
"github.com/openimsdk/tools/db/mongoutil"
"github.com/openimsdk/tools/errs"
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/mongo/options"
)
func NewConversationRespID(db *mongo.Database) (bot.ConversationRespIDInterface, error) {
coll := db.Collection("conversation_resp_id")
_, err := coll.Indexes().CreateOne(context.Background(), mongo.IndexModel{
Keys: bson.D{
{Key: "conversation_id", Value: 1},
{Key: "agent_id", Value: 1},
},
Options: options.Index().SetUnique(true),
})
if err != nil {
return nil, errs.Wrap(err)
}
return &ConversationRespID{coll: coll}, nil
}
type ConversationRespID struct {
coll *mongo.Collection
}
func (o *ConversationRespID) Create(ctx context.Context, elems ...*bot.ConversationRespID) error {
return mongoutil.InsertMany(ctx, o.coll, elems)
}
func (o *ConversationRespID) Take(ctx context.Context, convID, agentID string) (*bot.ConversationRespID, error) {
return mongoutil.FindOne[*bot.ConversationRespID](ctx, o.coll, bson.M{"conversation_id": convID, "agent_id": agentID})
}
func (o *ConversationRespID) Update(ctx context.Context, convID, agentID string, data map[string]any) error {
if len(data) == 0 {
return nil
}
return mongoutil.UpdateOne(ctx, o.coll, bson.M{"conversation_id": convID, "agent_id": agentID}, bson.M{"$set": data}, false, options.Update().SetUpsert(true))
}
func (o *ConversationRespID) Delete(ctx context.Context, convID, agentID string) error {
return mongoutil.DeleteMany(ctx, o.coll, bson.M{"conversation_id": convID, "agent_id": agentID})
}