Roc 1 月之前
父节点
当前提交
f2683294a4

+ 113 - 11
controllers/rag/wechat_platform_controller.go

@@ -7,6 +7,7 @@ import (
 	"eta/eta_api/models/rag"
 	"eta/eta_api/models/rag/request"
 	"eta/eta_api/models/rag/response"
+	"eta/eta_api/models/system"
 	"eta/eta_api/services/llm"
 	"eta/eta_api/utils"
 	"fmt"
@@ -161,15 +162,15 @@ func (c *WechatPlatformController) Add() {
 	br.Msg = `添加成功`
 }
 
-// List
-// @Title 获取ppt列表
-// @Description 获取ppt列表接口
+// FollowList
+// @Title 我关注的接口
+// @Description 我关注的接口
 // @Param   PageSize   query   int  true       "每页数据条数"
 // @Param   CurrentIndex   query   int  true       "当前页页码,从1开始"
 // @Param   KeyWord   query   string  true       "搜索关键词"
-// @Success 200 {object} models.WechatPlatformListResp
-// @router /wechat_platform/list [get]
-func (c *WechatPlatformController) List() {
+// @Success 200 {object} []*rag.WechatPlatform
+// @router /wechat_platform/list/follow [get]
+func (c *WechatPlatformController) FollowList() {
 	br := new(models.BaseResponse).Init()
 	defer func() {
 		c.Data["json"] = br
@@ -204,17 +205,118 @@ func (c *WechatPlatformController) List() {
 	}
 
 	obj := new(rag.WechatPlatform)
-	total, list, err := obj.GetPageListByCondition(condition, pars, startSize, pageSize)
+	list, err := obj.GetListByCondition(condition, pars, startSize, 100000)
 	if err != nil {
 		br.Msg = "获取失败"
 		br.ErrMsg = "获取失败,Err:" + err.Error()
 		return
 	}
 
-	page := paging.GetPaging(currentIndex, pageSize, total)
-	resp := new(response.WechatPlatformListResp)
-	resp.Paging = page
-	resp.List = list
+	br.Ret = 200
+	br.Success = true
+	br.Msg = "获取成功"
+	br.Data = list
+}
+
+// PublicList
+// @Title 公共列表
+// @Description 公共列表
+// @Param   PageSize   query   int  true       "每页数据条数"
+// @Param   CurrentIndex   query   int  true       "当前页页码,从1开始"
+// @Param   KeyWord   query   string  true       "搜索关键词"
+// @Success 200 {object} models.WechatPlatformListResp
+// @router /wechat_platform/list/public [get]
+func (c *WechatPlatformController) PublicList() {
+	br := new(models.BaseResponse).Init()
+	defer func() {
+		c.Data["json"] = br
+		c.ServeJSON()
+	}()
+
+	sysUser := c.SysUser
+	if sysUser == nil {
+		br.Msg = "请登录"
+		br.ErrMsg = "请登录,SysUser Is Empty"
+		return
+	}
+	pageSize, _ := c.GetInt("PageSize")
+	currentIndex, _ := c.GetInt("CurrentIndex")
+	keyWord := c.GetString("KeyWord")
+
+	var startSize int
+	if pageSize <= 0 {
+		pageSize = utils.PageSize20
+	}
+	if currentIndex <= 0 {
+		currentIndex = 1
+	}
+	startSize = utils.StartIndex(currentIndex, pageSize)
+
+	var condition string
+	var pars []interface{}
+
+	condition = fmt.Sprintf(` AND b.%s = ?`, rag.WechatPlatformUserMappingColumns.SysUserID)
+	pars = append(pars, c.SysUser.AdminId)
+
+	if keyWord != "" {
+		condition = fmt.Sprintf(` AND %s = ?`, rag.WechatPlatformColumns.Nickname)
+		pars = append(pars, `%`+keyWord+`%`)
+	}
+
+	obj := new(rag.WechatPlatformUserMapping)
+	list, err := obj.GetListByCondition(condition, pars, startSize, pageSize)
+	if err != nil {
+		br.Msg = "获取失败"
+		br.ErrMsg = "获取失败,Err:" + err.Error()
+		return
+	}
+
+	resp := make([]response.WechatPlatformPublicListResp, 0)
+
+	if list != nil && len(list) > 0 {
+		userIdList := make([]int, 0)
+		uerIdMap := make(map[int]bool)
+		userFollowIndexMap := make(map[int]int)
+		for _, v := range list {
+			if _, ok := uerIdMap[v.FollowUserId]; !ok {
+				userIdList = append(userIdList, v.FollowUserId)
+				uerIdMap[v.FollowUserId] = true
+			}
+
+			index, ok := userFollowIndexMap[v.FollowUserId]
+			if !ok {
+				userFollowIndexMap[v.FollowUserId] = len(resp)
+
+				resp = append(resp, response.WechatPlatformPublicListResp{
+					UserId: v.FollowUserId,
+					List:   []*rag.UserFollowWechatPlatform{v},
+				})
+			} else {
+				resp[index].List = append(resp[index].List, v)
+			}
+		}
+
+		userList, err := system.GetAdminListByIdList(userIdList)
+		if err != nil {
+			br.Msg = "获取失败"
+			br.ErrMsg = "获取失败,Err:" + err.Error()
+			return
+		}
+		userNameMap := make(map[int]*system.Admin)
+		for _, v := range userList {
+			userNameMap[v.AdminId] = v
+		}
+
+		for k, v := range resp {
+			userInfo, ok := userNameMap[v.UserId]
+			if !ok {
+				continue
+			}
+			resp[k].Name = userInfo.RealName + `关注`
+		}
+
+	}
+
 	br.Ret = 200
 	br.Success = true
 	br.Msg = "获取成功"

+ 7 - 0
models/rag/response/wechat_platform.go

@@ -10,6 +10,13 @@ type WechatPlatformListResp struct {
 	Paging *paging.PagingItem `description:"分页数据"`
 }
 
+type WechatPlatformPublicListResp struct {
+	UserId int    `description:"用户id"`
+	Name   string `description:"研究员名称"`
+	List   []*rag.UserFollowWechatPlatform
+	//Paging *paging.PagingItem `description:"分页数据"`
+}
+
 type TagListResp struct {
 	List   []*rag.Tag
 	Paging *paging.PagingItem `description:"分页数据"`

+ 56 - 1
models/rag/wechat_platform_user_mapping.go

@@ -1,6 +1,12 @@
 package rag
 
-import "time"
+import (
+	"database/sql"
+	"eta/eta_api/global"
+	"eta/eta_api/utils"
+	"fmt"
+	"time"
+)
 
 type WechatPlatformUserMapping struct {
 	WechatPlatformUserMappingId int       `gorm:"column:wechat_platform_user_mapping_id;type:int(9) UNSIGNED;primaryKey;not null;" description:"wechat_platform_user_mapping_id"`
@@ -29,3 +35,52 @@ var WechatPlatformUserMappingColumns = struct {
 	ModifyTime:                  "modify_time",
 	CreateTime:                  "create_time",
 }
+
+type UserFollowWechatPlatform struct {
+	WechatPlatformId int       `gorm:"column:wechat_platform_id;type:int(10) UNSIGNED;primaryKey;not null;" description:"wechat_platform_id"`
+	FakeId           string    `gorm:"column:fake_id;type:varchar(255);comment:公众号唯一id;" description:"公众号唯一id"`
+	Nickname         string    `gorm:"column:nickname;type:varchar(255);comment:公众号名称;" description:"公众号名称"`
+	Alias            string    `gorm:"column:alias;type:varchar(255);comment:别名;" description:"别名"`
+	RoundHeadImg     string    `gorm:"column:round_head_img;type:varchar(255);comment:头像;" description:"头像"`
+	ServiceType      int       `gorm:"column:service_type;type:int(11);comment:类型;default:0;" description:"类型"`
+	Signature        string    `gorm:"column:signature;type:varchar(255);comment:签名;" description:"签名"`
+	Verified         int       `gorm:"column:verified;type:int(11);comment:是否认证,0:未认证,1:已认证;这个我不确定,再核实下;default:0;" description:"是否认证,0:未认证,1:已认证;这个我不确定,再核实下"`
+	ArticleLink      string    `gorm:"column:article_link;type:varchar(255);comment:添加公众时的文章链接;" description:"添加公众时的文章链接"`
+	Enabled          int       `gorm:"column:enabled;type:tinyint(9);comment:是否启用,0:禁用,1:启用;default:1;" description:"是否启用,0:禁用,1:启用"`
+	SysUserId        int       `gorm:"column:sys_user_id;type:int(9) UNSIGNED;comment:用户id;default:0;" description:"用户id"`
+	ModifyTime       time.Time `gorm:"column:modify_time;type:datetime;comment:最后一次修改时间;default:NULL;" description:"最后一次修改时间"`
+	CreateTime       time.Time `gorm:"column:create_time;type:datetime;comment:添加时间;default:NULL;" description:"添加时间"`
+	FollowUserId     int       `gorm:"column:follow_user_id;type:int(9) UNSIGNED;comment:关注的用户id;default:0;" description:"关注的用户id"`
+}
+
+func (m *WechatPlatformUserMapping) GetListByCondition(condition string, pars []interface{}, startSize, pageSize int) (items []*UserFollowWechatPlatform, err error) {
+	sqlStr := fmt.Sprintf(`SELECT a.wechat_platform_id,a.fake_id,a.nickname,a.alias,a.round_head_img,a.service_type,a.signature,a.verified,a.article_link,a.enabled,a.sys_user_id,a.modify_time,a.create_time,b.sys_user_id as follow_user_id FROM wechat_platform a JOIN wechat_platform_user_mapping b on a.wechat_platform_id=b.wechat_platform_id WHERE 1=1 %s LIMIT ?,?`, condition)
+	pars = append(pars, startSize, pageSize)
+	err = global.DbMap[utils.DbNameAI].Raw(sqlStr, pars...).Find(&items).Error
+
+	return
+}
+
+func (m *WechatPlatformUserMapping) GetCountByCondition(condition string, pars []interface{}) (total int, err error) {
+	var intNull sql.NullInt64
+	sqlStr := fmt.Sprintf(`SELECT COUNT(1) total FROM wechat_platform a JOIN wechat_platform_user_mapping b on a.wechat_platform_id=b.wechat_platform_id WHERE 1=1 `, condition)
+	err = global.DbMap[utils.DbNameAI].Raw(sqlStr, pars...).Scan(&intNull).Error
+	if err == nil && intNull.Valid {
+		total = int(intNull.Int64)
+	}
+
+	return
+}
+
+func (m *WechatPlatformUserMapping) GetPageListByCondition(condition string, pars []interface{}, startSize, pageSize int) (total int, items []*UserFollowWechatPlatform, err error) {
+
+	total, err = m.GetCountByCondition(condition, pars)
+	if err != nil {
+		return
+	}
+	if total > 0 {
+		items, err = m.GetListByCondition(condition, pars, startSize, pageSize)
+	}
+
+	return
+}

+ 11 - 2
routers/commentsRouter.go

@@ -8550,8 +8550,17 @@ func init() {
 
     beego.GlobalControllerRouter["eta/eta_api/controllers/rag:WechatPlatformController"] = append(beego.GlobalControllerRouter["eta/eta_api/controllers/rag:WechatPlatformController"],
         beego.ControllerComments{
-            Method: "List",
-            Router: `/wechat_platform/list`,
+            Method: "FollowList",
+            Router: `/wechat_platform/list/follow`,
+            AllowHTTPMethods: []string{"get"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
+    beego.GlobalControllerRouter["eta/eta_api/controllers/rag:WechatPlatformController"] = append(beego.GlobalControllerRouter["eta/eta_api/controllers/rag:WechatPlatformController"],
+        beego.ControllerComments{
+            Method: "PublicList",
+            Router: `/wechat_platform/list/public`,
             AllowHTTPMethods: []string{"get"},
             MethodParams: param.Make(),
             Filters: nil,