浏览代码

fix:文章列表接口新增返回标签信息

Roc 2 周之前
父节点
当前提交
45a0506afc
共有 3 个文件被更改,包括 47 次插入0 次删除
  1. 27 0
      controllers/llm/wechat_platform.go
  2. 2 0
      models/rag/wechat_article.go
  3. 18 0
      models/rag/wechat_platform_tag_mapping.go

+ 27 - 0
controllers/llm/wechat_platform.go

@@ -573,6 +573,33 @@ func (c *WechatPlatformController) ArticleList() {
 		}
 	}
 
+	// 标签处理
+	{
+		wechatPlateIdList := make([]int, 0)
+		for _, v := range viewList {
+			wechatPlateIdList = append(wechatPlateIdList, v.WechatPlatformId)
+		}
+		obj := rag.WechatPlatformTagMapping{}
+		mappingList, err := obj.GetWechatPlatformTagListByWechatPlatformIdList(wechatPlateIdList)
+		if err != nil {
+			br.Msg = "获取失败"
+			br.ErrMsg = "获取失败,Err:" + err.Error()
+			return
+		}
+		wechatPlatformIdMap := make(map[int]*rag.WechatPlatformTagItem)
+		for _, v := range mappingList {
+			wechatPlatformIdMap[v.WechatPlatformId] = v
+		}
+		for k, v := range viewList {
+			item, ok := wechatPlatformIdMap[v.WechatPlatformId]
+			if !ok {
+				continue
+			}
+			viewList[k].TagName = item.TagName
+			viewList[k].TagId = item.TagId
+		}
+	}
+
 	page := paging.GetPaging(currentIndex, pageSize, total)
 	resp := response.WechatArticleListListResp{
 		List:   viewList,

+ 2 - 0
models/rag/wechat_article.go

@@ -93,6 +93,8 @@ type WechatArticleView struct {
 	CreateTime                 string `gorm:"column:create_time;type:datetime;comment:入库时间;default:NULL;" description:"入库时间"`
 	WechatPlatformName         string `gorm:"column:title;type:varchar(255);comment:标题;" description:"微信公众号名称"`
 	WechatPlatformRoundHeadImg string `gorm:"column:round_head_img;type:varchar(255);comment:头像;" description:"微信公众号头像"`
+	TagName                    string `gorm:"column:tag_name;type:varchar(255);comment:标签名称;" description:"标签名称"`
+	TagId                      int    `gorm:"column:tag_id;type:varchar(255);comment:标签id;" description:"标签id"`
 }
 
 func (m *WechatArticle) ToView() WechatArticleView {

+ 18 - 0
models/rag/wechat_platform_tag_mapping.go

@@ -80,3 +80,21 @@ func (m *WechatPlatformTagMapping) GetPageListByCondition(condition string, pars
 
 	return
 }
+
+type WechatPlatformTagItem struct {
+	TagId            int    `json:"tag_id"`
+	TagName          string `json:"tag_name"`
+	WechatPlatformId int    `json:"tag_article"`
+}
+
+func (m *WechatPlatformTagMapping) GetWechatPlatformTagListByWechatPlatformIdList(wechatPlatformIdList []int) (items []*WechatPlatformTagItem, err error) {
+	num := len(wechatPlatformIdList)
+	if num <= 0 {
+		return
+	}
+	sqlStr := `SELECT a.wechat_platform_id,b.tag_id,b.tag_name FROM wechat_platform_tag_mapping AS a 
+    JOIN tag AS b on a.tag_id = b.tag_id  WHERE a.wechat_platform_id IN (?) GROUP BY a.wechat_platform_id `
+	err = global.DbMap[utils.DbNameAI].Raw(sqlStr, wechatPlatformIdList).Find(&items).Error
+
+	return
+}