report.go 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. package llm
  2. import (
  3. "eta/eta_api/controllers"
  4. "eta/eta_api/models"
  5. "eta/eta_api/models/rag"
  6. "eta/eta_api/models/rag/response"
  7. "eta/eta_api/services"
  8. "eta/eta_api/utils"
  9. "fmt"
  10. "github.com/rdlucklib/rdluck_tools/paging"
  11. "html"
  12. )
  13. // RagEtaReportController
  14. // @Description: eta报告的接口
  15. type RagEtaReportController struct {
  16. controllers.BaseAuthController
  17. }
  18. // ArticleList
  19. // @Title 我关注的接口
  20. // @Description 我关注的接口
  21. // @Param PageSize query int true "每页数据条数"
  22. // @Param CurrentIndex query int true "当前页页码,从1开始"
  23. // @Param KeyWord query string true "搜索关键词"
  24. // @Success 200 {object} *rag.RagEtaReportListListResp
  25. // @router /eta_report/article/list [get]
  26. func (c *RagEtaReportController) ArticleList() {
  27. br := new(models.BaseResponse).Init()
  28. defer func() {
  29. c.Data["json"] = br
  30. c.ServeJSON()
  31. }()
  32. sysUser := c.SysUser
  33. if sysUser == nil {
  34. br.Msg = "请登录"
  35. br.ErrMsg = "请登录,SysUser Is Empty"
  36. return
  37. }
  38. pageSize, _ := c.GetInt("PageSize")
  39. currentIndex, _ := c.GetInt("CurrentIndex")
  40. keyWord := c.GetString("KeyWord")
  41. var startSize int
  42. if pageSize <= 0 {
  43. pageSize = utils.PageSize20
  44. }
  45. if currentIndex <= 0 {
  46. currentIndex = 1
  47. }
  48. startSize = utils.StartIndex(currentIndex, pageSize)
  49. var total int
  50. viewList := make([]rag.RagEtaReportView, 0)
  51. var condition string
  52. var pars []interface{}
  53. if keyWord != "" {
  54. condition += fmt.Sprintf(` AND %s like ? `, rag.RagEtaReportColumns.Title)
  55. pars = append(pars, `%`+keyWord+`%`)
  56. }
  57. obj := new(rag.RagEtaReport)
  58. tmpTotal, list, err := obj.GetPageListByCondition(condition, pars, startSize, pageSize)
  59. if err != nil {
  60. br.Msg = "获取失败"
  61. br.ErrMsg = "获取失败,Err:" + err.Error()
  62. return
  63. }
  64. total = tmpTotal
  65. if list != nil && len(list) > 0 {
  66. viewList = obj.ListToViewList(list)
  67. }
  68. page := paging.GetPaging(currentIndex, pageSize, total)
  69. resp := response.RagEtaReportListListResp{
  70. List: viewList,
  71. Paging: page,
  72. }
  73. br.Ret = 200
  74. br.Success = true
  75. br.Msg = "获取成功"
  76. br.Data = resp
  77. }
  78. // ArticleDetail
  79. // @Title 文章详情
  80. // @Description 我关注的接口
  81. // @Param RagEtaReportId query int true "知识库与eta报告关联的id"
  82. // @Success 200 {object} []*rag.WechatArticle
  83. // @router /eta_report/article/detail [get]
  84. func (c *RagEtaReportController) ArticleDetail() {
  85. br := new(models.BaseResponse).Init()
  86. defer func() {
  87. c.Data["json"] = br
  88. c.ServeJSON()
  89. }()
  90. sysUser := c.SysUser
  91. if sysUser == nil {
  92. br.Msg = "请登录"
  93. br.ErrMsg = "请登录,SysUser Is Empty"
  94. return
  95. }
  96. ragEtaReportId, _ := c.GetInt("RagEtaReportId")
  97. if ragEtaReportId <= 0 {
  98. br.Msg = "请选择文章"
  99. br.IsSendEmail = false
  100. return
  101. }
  102. obj := new(rag.RagEtaReport)
  103. item, err := obj.GetById(ragEtaReportId)
  104. if err != nil {
  105. br.Msg = "获取失败"
  106. br.ErrMsg = "获取失败,Err:" + err.Error()
  107. return
  108. }
  109. if item.IsDeleted == 1 {
  110. br.Msg = "文章已删除"
  111. br.IsSendEmail = false
  112. return
  113. }
  114. resp := item.ToView()
  115. content := ``
  116. // 获取源报告信息
  117. {
  118. if item.ReportChapterId <= 0 {
  119. // 普通报告
  120. reportInfo, err := models.GetReportByReportId(item.ReportId)
  121. if err != nil && !utils.IsErrNoRow(err) {
  122. br.Msg = "获取报告详情失败"
  123. br.ErrMsg = "获取源报告详情失败,Err:" + err.Error()
  124. return
  125. }
  126. content = reportInfo.Content
  127. } else {
  128. // 章节报告
  129. reportChapterInfo, err := models.GetReportChapterInfoById(item.ReportChapterId)
  130. if err != nil && !utils.IsErrNoRow(err) {
  131. br.Msg = "获取报告详情失败"
  132. br.ErrMsg = "获取源报告章节详情失败,Err:" + err.Error()
  133. return
  134. }
  135. content = reportChapterInfo.Content
  136. }
  137. if content != `` {
  138. content = html.UnescapeString(content)
  139. businessConf, err := models.GetBusinessConfByKey(models.BusinessConfIsOpenChartExpired)
  140. if err != nil {
  141. br.Msg = "获取失败"
  142. br.ErrMsg = "获取配置失败,Err:" + err.Error()
  143. return
  144. }
  145. if businessConf.ConfVal == `true` {
  146. tokenMap := make(map[string]string)
  147. content = services.HandleReportContent(content, "add", tokenMap)
  148. }
  149. }
  150. }
  151. resp.Content = content
  152. br.Ret = 200
  153. br.Success = true
  154. br.Msg = "获取成功"
  155. br.Data = resp
  156. }
  157. // ArticleDel
  158. // @Title 删除文章
  159. // @Description 我关注的接口
  160. // @Param RagEtaReportId query int true "知识库与eta报告关联的id"
  161. // @Success 200 {object} []*rag.WechatPlatform
  162. // @router /eta_report/article/del [get]
  163. func (c *RagEtaReportController) ArticleDel() {
  164. br := new(models.BaseResponse).Init()
  165. defer func() {
  166. c.Data["json"] = br
  167. c.ServeJSON()
  168. }()
  169. sysUser := c.SysUser
  170. if sysUser == nil {
  171. br.Msg = "请登录"
  172. br.ErrMsg = "请登录,SysUser Is Empty"
  173. return
  174. }
  175. ragEtaReportId, _ := c.GetInt("RagEtaReportId")
  176. if ragEtaReportId <= 0 {
  177. br.Msg = "请选择文章"
  178. br.IsSendEmail = false
  179. return
  180. }
  181. obj := new(rag.RagEtaReport)
  182. item, err := obj.GetById(ragEtaReportId)
  183. if err != nil {
  184. br.Msg = "获取失败"
  185. br.ErrMsg = "获取失败,Err:" + err.Error()
  186. return
  187. }
  188. if item.IsDeleted == 1 {
  189. br.Msg = "文章已删除"
  190. br.IsSendEmail = false
  191. return
  192. }
  193. item.IsDeleted = 1
  194. err = item.Update([]string{"is_deleted"})
  195. if err != nil {
  196. br.Msg = "删除失败"
  197. br.ErrMsg = "删除失败,Err:" + err.Error()
  198. return
  199. }
  200. br.Ret = 200
  201. br.Success = true
  202. br.Msg = "删除成功"
  203. }