mirror of
https://github.com/Tencent/WeKnora.git
synced 2026-09-24 16:29:01 +08:00
feat: 新增FAQ条目批量更新排除功能,支持在ByTag操作中排除指定ID列表
This commit is contained in:
+4
-2
@@ -69,6 +69,8 @@ type FAQEntryFieldsBatchRequest struct {
|
||||
ByID map[string]FAQEntryFieldsUpdate `json:"by_id,omitempty"`
|
||||
// ByTag updates all entries under a tag, key is tag ID (empty string for uncategorized)
|
||||
ByTag map[string]FAQEntryFieldsUpdate `json:"by_tag,omitempty"`
|
||||
// ExcludeIDs IDs to exclude from the ByTag update
|
||||
ExcludeIDs []string `json:"exclude_ids,omitempty"`
|
||||
}
|
||||
|
||||
// FAQEntryTagBatchRequest updates tags in bulk.
|
||||
@@ -255,10 +257,10 @@ func (c *Client) UpdateFAQEntry(ctx context.Context,
|
||||
// - byID: update by entry ID, key is entry ID
|
||||
// - byTag: update all entries under a tag, key is tag ID (empty string for uncategorized)
|
||||
func (c *Client) UpdateFAQEntryFieldsBatch(ctx context.Context,
|
||||
knowledgeBaseID string, byID map[string]FAQEntryFieldsUpdate, byTag map[string]FAQEntryFieldsUpdate,
|
||||
knowledgeBaseID string, byID map[string]FAQEntryFieldsUpdate, byTag map[string]FAQEntryFieldsUpdate, excludeIDs []string,
|
||||
) error {
|
||||
path := fmt.Sprintf("/api/v1/knowledge-bases/%s/faq/entries/fields", knowledgeBaseID)
|
||||
resp, err := c.doRequest(ctx, http.MethodPut, path, &FAQEntryFieldsBatchRequest{ByID: byID, ByTag: byTag}, nil)
|
||||
resp, err := c.doRequest(ctx, http.MethodPut, path, &FAQEntryFieldsBatchRequest{ByID: byID, ByTag: byTag, ExcludeIDs: excludeIDs}, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -569,6 +569,7 @@ func (r *chunkRepository) UpdateChunkFieldsByTagID(
|
||||
isEnabled *bool,
|
||||
setFlags types.ChunkFlags,
|
||||
clearFlags types.ChunkFlags,
|
||||
excludeIDs []string,
|
||||
) ([]string, error) {
|
||||
// First, get the IDs of chunks that will be affected (for is_enabled sync)
|
||||
var affectedIDs []string
|
||||
@@ -583,6 +584,11 @@ func (r *chunkRepository) UpdateChunkFieldsByTagID(
|
||||
} else {
|
||||
query = query.Where("tag_id = ?", tagID)
|
||||
}
|
||||
|
||||
if len(excludeIDs) > 0 {
|
||||
query = query.Where("id NOT IN ?", excludeIDs)
|
||||
}
|
||||
|
||||
// Only get chunks that need to change
|
||||
query = query.Where("is_enabled != ?", *isEnabled)
|
||||
if err := query.Find(&chunks).Error; err != nil {
|
||||
@@ -612,6 +618,10 @@ func (r *chunkRepository) UpdateChunkFieldsByTagID(
|
||||
query = query.Where("tag_id = ?", tagID)
|
||||
}
|
||||
|
||||
if len(excludeIDs) > 0 {
|
||||
query = query.Where("id NOT IN ?", excludeIDs)
|
||||
}
|
||||
|
||||
// Handle flags update
|
||||
if setFlags != 0 || clearFlags != 0 {
|
||||
flagsExpr := "flags"
|
||||
|
||||
@@ -3570,7 +3570,7 @@ func (s *knowledgeService) UpdateFAQEntryFieldsBatch(ctx context.Context,
|
||||
// Update all chunks with this tag
|
||||
affectedIDs, err := s.chunkRepo.UpdateChunkFieldsByTagID(
|
||||
ctx, tenantID, kb.ID, tagID,
|
||||
update.IsEnabled, setFlags, clearFlags,
|
||||
update.IsEnabled, setFlags, clearFlags, req.ExcludeIDs,
|
||||
)
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
@@ -245,6 +245,8 @@ type FAQEntryFieldsBatchUpdate struct {
|
||||
ByID map[string]FAQEntryFieldsUpdate `json:"by_id,omitempty"`
|
||||
// ByTag 按Tag批量更新,key为TagID(空字符串表示未分类)
|
||||
ByTag map[string]FAQEntryFieldsUpdate `json:"by_tag,omitempty"`
|
||||
// ExcludeIDs 在ByTag操作中需要排除的ID列表
|
||||
ExcludeIDs []string `json:"exclude_ids,omitempty"`
|
||||
}
|
||||
|
||||
// FAQImportTaskStatus 导入任务状态
|
||||
|
||||
@@ -64,7 +64,7 @@ type ChunkRepository interface {
|
||||
UpdateChunkFlagsBatch(ctx context.Context, tenantID uint64, kbID string, setFlags map[string]types.ChunkFlags, clearFlags map[string]types.ChunkFlags) error
|
||||
// UpdateChunkFieldsByTagID updates fields for all chunks with the specified tag ID.
|
||||
// Supports updating is_enabled and flags fields.
|
||||
UpdateChunkFieldsByTagID(ctx context.Context, tenantID uint64, kbID string, tagID string, isEnabled *bool, setFlags types.ChunkFlags, clearFlags types.ChunkFlags) ([]string, error)
|
||||
UpdateChunkFieldsByTagID(ctx context.Context, tenantID uint64, kbID string, tagID string, isEnabled *bool, setFlags types.ChunkFlags, clearFlags types.ChunkFlags, excludeIDs []string) ([]string, error)
|
||||
// FAQChunkDiff compares FAQ chunks between two knowledge bases and returns the differences.
|
||||
// Returns: chunksToAdd (content_hash in src but not in dst), chunksToDelete (content_hash in dst but not in src)
|
||||
FAQChunkDiff(ctx context.Context, srcTenantID uint64, srcKBID string, dstTenantID uint64, dstKBID string) (chunksToAdd []string, chunksToDelete []string, err error)
|
||||
|
||||
Reference in New Issue
Block a user