123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228 |
- package llm
- import (
- "eta/eta_api/controllers"
- "eta/eta_api/models"
- "eta/eta_api/models/rag"
- "eta/eta_api/models/rag/response"
- "eta/eta_api/services"
- "eta/eta_api/utils"
- "fmt"
- "github.com/rdlucklib/rdluck_tools/paging"
- "html"
- )
- // RagEtaReportController
- // @Description: eta报告的接口
- type RagEtaReportController struct {
- controllers.BaseAuthController
- }
- // ArticleList
- // @Title 我关注的接口
- // @Description 我关注的接口
- // @Param PageSize query int true "每页数据条数"
- // @Param CurrentIndex query int true "当前页页码,从1开始"
- // @Param KeyWord query string true "搜索关键词"
- // @Success 200 {object} *rag.RagEtaReportListListResp
- // @router /eta_report/article/list [get]
- func (c *RagEtaReportController) ArticleList() {
- 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 total int
- viewList := make([]rag.RagEtaReportView, 0)
- var condition string
- var pars []interface{}
- if keyWord != "" {
- condition += fmt.Sprintf(` AND %s like ? `, rag.RagEtaReportColumns.Title)
- pars = append(pars, `%`+keyWord+`%`)
- }
- obj := new(rag.RagEtaReport)
- tmpTotal, list, err := obj.GetPageListByCondition(condition, pars, startSize, pageSize)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- total = tmpTotal
- if list != nil && len(list) > 0 {
- viewList = obj.ListToViewList(list)
- }
- page := paging.GetPaging(currentIndex, pageSize, total)
- resp := response.RagEtaReportListListResp{
- List: viewList,
- Paging: page,
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- // ArticleDetail
- // @Title 文章详情
- // @Description 我关注的接口
- // @Param RagEtaReportId query int true "知识库与eta报告关联的id"
- // @Success 200 {object} []*rag.WechatArticle
- // @router /eta_report/article/detail [get]
- func (c *RagEtaReportController) ArticleDetail() {
- 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
- }
- ragEtaReportId, _ := c.GetInt("RagEtaReportId")
- if ragEtaReportId <= 0 {
- br.Msg = "请选择文章"
- br.IsSendEmail = false
- return
- }
- obj := new(rag.RagEtaReport)
- item, err := obj.GetById(ragEtaReportId)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- if item.IsDeleted == 1 {
- br.Msg = "文章已删除"
- br.IsSendEmail = false
- return
- }
- resp := item.ToView()
- content := ``
- // 获取源报告信息
- {
- if item.ReportChapterId <= 0 {
- // 普通报告
- reportInfo, err := models.GetReportByReportId(item.ReportId)
- if err != nil && !utils.IsErrNoRow(err) {
- br.Msg = "获取报告详情失败"
- br.ErrMsg = "获取源报告详情失败,Err:" + err.Error()
- return
- }
- content = reportInfo.Content
- } else {
- // 章节报告
- reportChapterInfo, err := models.GetReportChapterInfoById(item.ReportChapterId)
- if err != nil && !utils.IsErrNoRow(err) {
- br.Msg = "获取报告详情失败"
- br.ErrMsg = "获取源报告章节详情失败,Err:" + err.Error()
- return
- }
- content = reportChapterInfo.Content
- }
- if content != `` {
- content = html.UnescapeString(content)
- businessConf, err := models.GetBusinessConfByKey(models.BusinessConfIsOpenChartExpired)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取配置失败,Err:" + err.Error()
- return
- }
- if businessConf.ConfVal == `true` {
- tokenMap := make(map[string]string)
- content = services.HandleReportContent(content, "add", tokenMap)
- }
- }
- }
- resp.Content = content
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- // ArticleDel
- // @Title 删除文章
- // @Description 我关注的接口
- // @Param RagEtaReportId query int true "知识库与eta报告关联的id"
- // @Success 200 {object} []*rag.WechatPlatform
- // @router /eta_report/article/del [get]
- func (c *RagEtaReportController) ArticleDel() {
- 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
- }
- ragEtaReportId, _ := c.GetInt("RagEtaReportId")
- if ragEtaReportId <= 0 {
- br.Msg = "请选择文章"
- br.IsSendEmail = false
- return
- }
- obj := new(rag.RagEtaReport)
- item, err := obj.GetById(ragEtaReportId)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- if item.IsDeleted == 1 {
- br.Msg = "文章已删除"
- br.IsSendEmail = false
- return
- }
- item.IsDeleted = 1
- err = item.Update([]string{"is_deleted"})
- if err != nil {
- br.Msg = "删除失败"
- br.ErrMsg = "删除失败,Err:" + err.Error()
- return
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "删除成功"
- }
|