feat: Implement knowledge tag management and batch updates for FAQ entries

- Added API functions for listing, creating, updating, and deleting knowledge base tags.
- Introduced batch update functionality for enabling/disabling FAQ entries and updating their tags.
- Enhanced the KnowledgeBase.vue and FAQEntryManager.vue components to support tag management and batch operations.
- Updated localization files to include new strings related to tag management and batch operations.
This commit is contained in:
wizardchen
2025-11-18 11:48:37 +08:00
parent 822041d995
commit fdf5d9d781
29 changed files with 3359 additions and 382 deletions
+46
View File
@@ -88,10 +88,56 @@ func (h *FAQHandler) UpdateEntry(c *gin.Context) {
})
}
// UpdateEntryTagBatch updates tags for FAQ entries in batch.
func (h *FAQHandler) UpdateEntryTagBatch(c *gin.Context) {
ctx := c.Request.Context()
var req faqEntryTagBatchRequest
if err := c.ShouldBindJSON(&req); err != nil {
logger.Error(ctx, "Failed to bind FAQ entry tag batch payload", err)
c.Error(errors.NewBadRequestError("请求参数不合法").WithDetails(err.Error()))
return
}
if err := h.knowledgeService.UpdateFAQEntryTagBatch(ctx, c.Param("id"), req.Updates); err != nil {
logger.ErrorWithFields(ctx, err, nil)
c.Error(err)
return
}
c.JSON(http.StatusOK, gin.H{
"success": true,
})
}
// UpdateEntryStatusBatch updates the enable status of FAQ entries in batch.
func (h *FAQHandler) UpdateEntryStatusBatch(c *gin.Context) {
ctx := c.Request.Context()
var req faqEntryStatusBatchRequest
if err := c.ShouldBindJSON(&req); err != nil {
logger.Error(ctx, "Failed to bind FAQ entry status batch payload", err)
c.Error(errors.NewBadRequestError("请求参数不合法").WithDetails(err.Error()))
return
}
if err := h.knowledgeService.UpdateFAQEntryStatusBatch(ctx, c.Param("id"), req.Updates); err != nil {
logger.ErrorWithFields(ctx, err, nil)
c.Error(err)
return
}
c.JSON(http.StatusOK, gin.H{
"success": true,
})
}
type faqDeleteRequest struct {
IDs []string `json:"ids" binding:"required,min=1,dive,required"`
}
type faqEntryStatusBatchRequest struct {
Updates map[string]bool `json:"updates" binding:"required,min=1"`
}
type faqEntryTagBatchRequest struct {
Updates map[string]*string `json:"updates" binding:"required,min=1"`
}
// DeleteEntries deletes FAQ entries in batch.
func (h *FAQHandler) DeleteEntries(c *gin.Context) {
ctx := c.Request.Context()
+2 -2
View File
@@ -223,7 +223,7 @@ func (h *InitializationHandler) UpdateKBConfig(c *gin.Context) {
kbIdStr, &types.Pagination{
Page: 1,
PageSize: 1,
})
}, "")
if err == nil && knowledgeList != nil && knowledgeList.Total > 0 {
logger.Error(ctx, "Cannot change embedding model when files exist")
c.Error(errors.NewBadRequestError("知识库中已有文件,无法修改Embedding模型"))
@@ -1129,7 +1129,7 @@ func (h *InitializationHandler) GetCurrentConfigByKB(c *gin.Context) {
kbIdStr, &types.Pagination{
Page: 1,
PageSize: 1,
})
}, "")
hasFiles := false
if err == nil && knowledgeList != nil && knowledgeList.Total > 0 {
hasFiles = true
+23
View File
@@ -509,6 +509,29 @@ func (h *KnowledgeHandler) UpdateManualKnowledge(c *gin.Context) {
})
}
type knowledgeTagBatchRequest struct {
Updates map[string]*string `json:"updates" binding:"required,min=1"`
}
// UpdateKnowledgeTagBatch updates tags for knowledge items in batch.
func (h *KnowledgeHandler) UpdateKnowledgeTagBatch(c *gin.Context) {
ctx := c.Request.Context()
var req knowledgeTagBatchRequest
if err := c.ShouldBindJSON(&req); err != nil {
logger.Error(ctx, "Failed to parse knowledge tag batch request", err)
c.Error(errors.NewBadRequestError("请求参数不合法").WithDetails(err.Error()))
return
}
if err := h.kgService.UpdateKnowledgeTagBatch(ctx, req.Updates); err != nil {
logger.ErrorWithFields(ctx, err, nil)
c.Error(err)
return
}
c.JSON(http.StatusOK, gin.H{
"success": true,
})
}
// UpdateImageInfo updates a chunk's properties
func (h *KnowledgeHandler) UpdateImageInfo(c *gin.Context) {
ctx := c.Request.Context()