123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324 |
- package rag
- import (
- "encoding/json"
- "eta/eta_api/controllers"
- "eta/eta_api/models"
- "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"
- "github.com/rdlucklib/rdluck_tools/paging"
- "strings"
- "time"
- )
- // WechatPlatformController
- // @Description: 微信公众号管理
- type WechatPlatformController struct {
- controllers.BaseAuthController
- }
- // TagList
- // @Title 获取ppt列表
- // @Description 获取ppt列表接口
- // @Param PageSize query int true "每页数据条数"
- // @Param CurrentIndex query int true "当前页页码,从1开始"
- // @Param KeyWord query string true "搜索关键词"
- // @Success 200 {object} models.TagListResp
- // @router /tag/list [get]
- func (c *WechatPlatformController) TagList() {
- 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{}
- if keyWord != "" {
- condition = fmt.Sprintf(` AND %s = ?`, rag.WechatPlatformColumns.Nickname)
- pars = append(pars, `%`+keyWord+`%`)
- }
- obj := new(rag.Tag)
- total, list, err := obj.GetPageListByCondition(condition, pars, startSize, pageSize)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- page := paging.GetPaging(currentIndex, pageSize, total)
- resp := new(response.TagListResp)
- resp.Paging = page
- resp.List = list
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- // Add
- // @Title 新增公众号
- // @Description 新增公众号
- // @Param request body request.AddWechatPlatformReq true "type json string"
- // @Success 200 Ret=200 新增成功
- // @router /wechat_platform/add [post]
- func (c *WechatPlatformController) Add() {
- br := new(models.BaseResponse).Init()
- defer func() {
- c.Data["json"] = br
- c.ServeJSON()
- }()
- var req request.AddWechatPlatformReq
- err := json.Unmarshal(c.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- req.Name = strings.TrimSpace(req.Name)
- if req.Name == "" {
- br.Msg = "请输入公众号名称"
- br.IsSendEmail = false
- return
- }
- req.Link = strings.TrimSpace(req.Link)
- if req.Link == "" {
- br.Msg = "请输入文章链接"
- br.IsSendEmail = false
- return
- }
- var condition string
- var pars []interface{}
- condition = fmt.Sprintf(` AND %s = ?`, rag.WechatPlatformColumns.Nickname)
- pars = append(pars, req.Name)
- obj := new(rag.WechatPlatform)
- item, err := obj.GetByCondition(condition, pars)
- if err != nil && !utils.IsErrNoRow(err) {
- br.Msg = "公众号信息获取失败"
- br.ErrMsg = "公众号信息获取失败,Err:" + err.Error()
- return
- }
- if item.WechatPlatformId > 0 {
- br.Msg = "公众号名称重复"
- br.IsSendEmail = false
- return
- }
- item = &rag.WechatPlatform{
- WechatPlatformId: 0,
- FakeId: "",
- Nickname: req.Name,
- Alias: "",
- RoundHeadImg: "",
- ServiceType: 0,
- Signature: "",
- Verified: 0,
- ArticleLink: req.Link,
- Enabled: 0,
- SysUserId: c.SysUser.AdminId,
- ModifyTime: time.Now(),
- CreateTime: time.Now(),
- }
- err = item.Add(req.TagIdList)
- if err != nil {
- br.Msg = "添加失败"
- br.ErrMsg = "添加失败,Err:" + err.Error()
- return
- }
- // 异步新增公众号
- go llm.AddWechatPlatform(item)
- br.Ret = 200
- br.Success = true
- br.Msg = `添加成功`
- }
- // FollowList
- // @Title 我关注的接口
- // @Description 我关注的接口
- // @Param PageSize query int true "每页数据条数"
- // @Param CurrentIndex query int true "当前页页码,从1开始"
- // @Param KeyWord query string true "搜索关键词"
- // @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
- 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{}
- if keyWord != "" {
- condition = fmt.Sprintf(` AND %s = ?`, rag.WechatPlatformColumns.Nickname)
- pars = append(pars, `%`+keyWord+`%`)
- }
- obj := new(rag.WechatPlatform)
- list, err := obj.GetListByCondition(condition, pars, startSize, 100000)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- 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 = "获取成功"
- br.Data = resp
- }
|