sa_compare.go 2.4 KB

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