复制项目

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,77 @@
package database
import (
"context"
"git.imall.cloud/openim/chat/pkg/common/db/model/bot"
tablebot "git.imall.cloud/openim/chat/pkg/common/db/table/bot"
"github.com/openimsdk/tools/db/mongoutil"
"github.com/openimsdk/tools/db/pagination"
"github.com/openimsdk/tools/db/tx"
)
type BotDatabase interface {
CreateAgent(ctx context.Context, jobs ...*tablebot.Agent) error
TakeAgent(ctx context.Context, userID string) (*tablebot.Agent, error)
FindAgents(ctx context.Context, userIDs []string) ([]*tablebot.Agent, error)
UpdateAgent(ctx context.Context, userID string, data map[string]any) error
DeleteAgents(ctx context.Context, userIDs []string) error
PageAgents(ctx context.Context, userIDs []string, pagination pagination.Pagination) (int64, []*tablebot.Agent, error)
TakeConversationRespID(ctx context.Context, convID, agentID string) (*tablebot.ConversationRespID, error)
UpdateConversationRespID(ctx context.Context, convID, agentID string, data map[string]any) error
}
type botDatabase struct {
tx tx.Tx
agent tablebot.AgentInterface
convRespID tablebot.ConversationRespIDInterface
}
func NewBotDatabase(cli *mongoutil.Client) (BotDatabase, error) {
agent, err := bot.NewAgent(cli.GetDB())
if err != nil {
return nil, err
}
convRespID, err := bot.NewConversationRespID(cli.GetDB())
if err != nil {
return nil, err
}
return &botDatabase{
tx: cli.GetTx(),
agent: agent,
convRespID: convRespID,
}, nil
}
func (a *botDatabase) CreateAgent(ctx context.Context, agents ...*tablebot.Agent) error {
return a.agent.Create(ctx, agents...)
}
func (a *botDatabase) TakeAgent(ctx context.Context, userID string) (*tablebot.Agent, error) {
return a.agent.Take(ctx, userID)
}
func (a *botDatabase) FindAgents(ctx context.Context, userIDs []string) ([]*tablebot.Agent, error) {
return a.agent.Find(ctx, userIDs)
}
func (a *botDatabase) UpdateAgent(ctx context.Context, userID string, data map[string]any) error {
return a.agent.Update(ctx, userID, data)
}
func (a *botDatabase) DeleteAgents(ctx context.Context, userIDs []string) error {
return a.agent.Delete(ctx, userIDs)
}
func (a *botDatabase) PageAgents(ctx context.Context, userIDs []string, pagination pagination.Pagination) (int64, []*tablebot.Agent, error) {
return a.agent.Page(ctx, userIDs, pagination)
}
func (a *botDatabase) UpdateConversationRespID(ctx context.Context, convID, agentID string, data map[string]any) error {
return a.convRespID.Update(ctx, convID, agentID, data)
}
func (a *botDatabase) TakeConversationRespID(ctx context.Context, convID, agentID string) (*tablebot.ConversationRespID, error) {
return a.convRespID.Take(ctx, convID, agentID)
}