sa_compare.go 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. package semantic_analysis
  2. import (
  3. "fmt"
  4. "github.com/rdlucklib/rdluck_tools/paging"
  5. "hongze/hongze_ETA_mobile_api/controllers"
  6. "hongze/hongze_ETA_mobile_api/models"
  7. "hongze/hongze_ETA_mobile_api/models/data_manage"
  8. saModel "hongze/hongze_ETA_mobile_api/models/semantic_analysis"
  9. "hongze/hongze_ETA_mobile_api/services"
  10. "hongze/hongze_ETA_mobile_api/utils"
  11. "time"
  12. )
  13. // SaCompareController 语义分析-文档比对
  14. type SaCompareController struct {
  15. controllers.BaseAuthController
  16. }
  17. // SearchByEs
  18. // @Title 文档对比搜索(从es获取)
  19. // @Description 图表模糊搜索(从es获取)
  20. // @Param Keyword query string true "文档对比标题"
  21. // @Success 200 {object} saModel.CompareListByEsResp
  22. // @router /compare/search [get]
  23. func (this *SaCompareController) SearchByEs() {
  24. br := new(models.BaseResponse).Init()
  25. defer func() {
  26. this.Data["json"] = br
  27. this.ServeJSON()
  28. }()
  29. sysUser := this.SysUser
  30. if sysUser == nil {
  31. br.Msg = "请登录"
  32. br.ErrMsg = "请登录,SysUser Is Empty"
  33. br.Ret = 408
  34. return
  35. }
  36. pageSize, _ := this.GetInt("PageSize")
  37. currentIndex, _ := this.GetInt("CurrentIndex")
  38. var startSize int
  39. if pageSize <= 0 {
  40. pageSize = utils.PageSize20
  41. }
  42. if currentIndex <= 0 {
  43. currentIndex = 1
  44. }
  45. startSize = paging.StartIndex(currentIndex, pageSize)
  46. keyword := this.GetString("Keyword")
  47. var searchList []*saModel.SaCompareElastic
  48. var total int
  49. var err error
  50. if keyword != "" {
  51. total, searchList, err = services.EsSearchSaCompareData(keyword, startSize, pageSize)
  52. } else {
  53. var list []*saModel.SaCompare
  54. saCompare := new(saModel.SaCompare)
  55. existCond := fmt.Sprintf(` AND result_img != ""`)
  56. existPars := make([]interface{}, 0)
  57. total, list, err = saCompare.GetPageItemsByCondition(startSize, pageSize, existCond, existPars, []string{}, "")
  58. if err != nil && err.Error() != utils.ErrNoRow() {
  59. br.Msg = "获取失败"
  60. br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
  61. return
  62. }
  63. for _, v := range list {
  64. tmp := new(saModel.SaCompareElastic)
  65. tmp.SaCompareId = v.SaCompareId
  66. tmp.ResultImg = v.ResultImg
  67. tmp.CreateTime = v.CreateTime.Format(utils.FormatDateTime)
  68. tmp.ModifyTime = v.ModifyTime.Format(utils.FormatDateTime)
  69. tmp.SysAdminId = v.SysAdminId
  70. tmp.SysAdminName = v.SysAdminName
  71. tmp.ClassifyId = v.ClassifyId
  72. tmp.ClassifyName = v.ClassifyName
  73. tmp.Title = v.Title
  74. searchList = append(searchList, tmp)
  75. }
  76. }
  77. //新增搜索词记录
  78. {
  79. searchKeyword := new(data_manage.SearchKeyword)
  80. searchKeyword.KeyWord = keyword
  81. searchKeyword.CreateTime = time.Now()
  82. go data_manage.AddSearchKeyword(searchKeyword)
  83. }
  84. page := paging.GetPaging(currentIndex, pageSize, total)
  85. resp := saModel.CompareListByEsResp{
  86. Paging: page,
  87. List: searchList,
  88. }
  89. br.Ret = 200
  90. br.Success = true
  91. br.Msg = "获取成功"
  92. br.Data = resp
  93. }