修复知识库的标签管理和分类管理
This commit is contained in:
@@ -290,12 +290,13 @@ func (c *KnowledgeController) GetTags() {
|
||||
var result []map[string]interface{}
|
||||
for _, tag := range tags {
|
||||
result = append(result, map[string]interface{}{
|
||||
"tagId": tag.TagId,
|
||||
"tagName": tag.TagName,
|
||||
"tagColor": tag.TagColor,
|
||||
"usageCount": tag.UsageCount,
|
||||
"createTime": tag.CreateTime,
|
||||
"updateTime": tag.UpdateTime,
|
||||
"tagId": tag.TagId,
|
||||
"tagName": tag.TagName,
|
||||
"tagColor": tag.TagColor,
|
||||
"tagBackground": tag.TagBackground,
|
||||
"usageCount": tag.UsageCount,
|
||||
"createTime": tag.CreateTime,
|
||||
"updateTime": tag.UpdateTime,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -322,7 +323,8 @@ func (c *KnowledgeController) AddCategory() {
|
||||
return
|
||||
}
|
||||
|
||||
id, err := models.AddCategory(&category)
|
||||
// 不处理id,直接添加,表自动递增
|
||||
_, err = models.AddCategory(&category)
|
||||
if err != nil {
|
||||
c.Data["json"] = map[string]interface{}{
|
||||
"code": 1,
|
||||
@@ -336,12 +338,12 @@ func (c *KnowledgeController) AddCategory() {
|
||||
c.Data["json"] = map[string]interface{}{
|
||||
"code": 0,
|
||||
"message": "添加成功",
|
||||
"data": map[string]interface{}{"categoryId": id},
|
||||
"data": nil,
|
||||
}
|
||||
c.ServeJSON()
|
||||
}
|
||||
|
||||
// AddTag 添加标签
|
||||
// AddTag 添加或更新标签
|
||||
// @router /api/knowledge/tag/add [post]
|
||||
func (c *KnowledgeController) AddTag() {
|
||||
var tag models.KnowledgeTag
|
||||
@@ -356,6 +358,31 @@ func (c *KnowledgeController) AddTag() {
|
||||
return
|
||||
}
|
||||
|
||||
// 判断是添加还是更新
|
||||
if tag.TagId > 0 {
|
||||
// 更新操作
|
||||
err = models.UpdateTag(&tag)
|
||||
if err != nil {
|
||||
c.Data["json"] = map[string]interface{}{
|
||||
"code": 1,
|
||||
"message": "更新标签失败: " + err.Error(),
|
||||
"data": nil,
|
||||
}
|
||||
c.ServeJSON()
|
||||
return
|
||||
}
|
||||
|
||||
c.Data["json"] = map[string]interface{}{
|
||||
"code": 0,
|
||||
"message": "更新成功",
|
||||
"data": map[string]interface{}{"tagId": tag.TagId},
|
||||
}
|
||||
c.ServeJSON()
|
||||
return
|
||||
}
|
||||
|
||||
// 添加操作:确保 TagId 为 0,让数据库自动生成
|
||||
tag.TagId = 0
|
||||
id, err := models.AddTag(&tag)
|
||||
if err != nil {
|
||||
c.Data["json"] = map[string]interface{}{
|
||||
|
||||
Reference in New Issue
Block a user