index.go 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. package ai_predict_model
  2. import (
  3. "eta/eta_mobile/controllers"
  4. "eta/eta_mobile/models"
  5. "eta/eta_mobile/models/data_manage"
  6. "eta/eta_mobile/services/data"
  7. "eta/eta_mobile/utils"
  8. "github.com/rdlucklib/rdluck_tools/paging"
  9. "strconv"
  10. "strings"
  11. "time"
  12. )
  13. // AiPredictModelIndexController AI预测模型标的
  14. type AiPredictModelIndexController struct {
  15. controllers.BaseAuthController
  16. }
  17. // SearchByEs
  18. // @Title 图表模糊搜索(从es获取)
  19. // @Description 图表模糊搜索(从es获取)
  20. // @Param Keyword query string true "图表名称"
  21. // @Param IsShowMe query bool true "是否只看我的,true、false"
  22. // @Param Source query int true "来源,14:日度预测,15:月度预测,默认0:全部14+15"
  23. // @Success 200 {object} data_manage.ChartInfo
  24. // @router /chart/search_by_es [get]
  25. func (this *AiPredictModelIndexController) SearchByEs() {
  26. br := new(models.BaseResponse).Init()
  27. defer func() {
  28. if br.ErrMsg == "" {
  29. br.IsSendEmail = false
  30. }
  31. this.Data["json"] = br
  32. this.ServeJSON()
  33. }()
  34. sysUser := this.SysUser
  35. if sysUser == nil {
  36. br.Msg = "请登录"
  37. br.ErrMsg = "请登录,SysUser Is Empty"
  38. br.Ret = 408
  39. return
  40. }
  41. pageSize, _ := this.GetInt("PageSize")
  42. currentIndex, _ := this.GetInt("CurrentIndex")
  43. var startSize int
  44. if pageSize <= 0 {
  45. pageSize = utils.PageSize20
  46. }
  47. if currentIndex <= 0 {
  48. currentIndex = 1
  49. }
  50. startSize = paging.StartIndex(currentIndex, pageSize)
  51. keyword := this.GetString("Keyword")
  52. keyword = strings.TrimSpace(keyword)
  53. if keyword == "" {
  54. keyword = this.GetString("KeyWord")
  55. keyword = strings.TrimSpace(keyword)
  56. }
  57. //只看我的
  58. isShowMe, _ := this.GetBool("IsShowMe")
  59. showSysId := 0
  60. if isShowMe {
  61. showSysId = sysUser.AdminId
  62. }
  63. source, _ := this.GetInt("Source")
  64. sourceList := make([]int, 0)
  65. if source <= 0 {
  66. sourceList = append(sourceList, utils.CHART_SOURCE_AI_PREDICT_MODEL_MONTHLY, utils.CHART_SOURCE_AI_PREDICT_MODEL_DAILY)
  67. } else {
  68. sourceList = append(sourceList, source)
  69. }
  70. var searchList []*data_manage.ChartInfoMore
  71. var total int64
  72. var err error
  73. // 获取当前账号的不可见指标(AI预测的指标为标的均可见)
  74. noPermissionChartIdList := make([]int, 0)
  75. //{
  76. // obj := data_manage.EdbInfoNoPermissionAdmin{}
  77. // confList, err := obj.GetAllChartListByAdminId(this.SysUser.AdminId)
  78. // if err != nil && !utils.IsErrNoRow(err) {
  79. // br.Msg = "获取失败"
  80. // br.ErrMsg = "获取不可见指标配置数据失败,Err:" + err.Error()
  81. // return
  82. // }
  83. // for _, v := range confList {
  84. // noPermissionChartIdList = append(noPermissionChartIdList, v.ChartInfoId)
  85. // }
  86. //}
  87. if keyword != "" {
  88. searchList, total, err = data.EsSearchChartInfo(keyword, showSysId, sourceList, noPermissionChartIdList, startSize, pageSize)
  89. } else {
  90. total, searchList, err = data_manage.ChartInfoSearchByEmptyKeyWord(showSysId, sourceList, noPermissionChartIdList, startSize, pageSize)
  91. if err != nil && err.Error() != utils.ErrNoRow() {
  92. br.Msg = "获取失败"
  93. br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
  94. return
  95. }
  96. }
  97. finalList := make([]*data_manage.ChartInfoMore, 0)
  98. if len(searchList) > 0 {
  99. chartInfoIds := ""
  100. chartEdbMap := make(map[int][]*data_manage.ChartEdbInfoMapping)
  101. for _, v := range searchList {
  102. chartInfoIds += strconv.Itoa(v.ChartInfoId) + ","
  103. }
  104. if chartInfoIds != "" {
  105. chartInfoIds = strings.Trim(chartInfoIds, ",")
  106. //判断是否需要展示英文标识
  107. edbList, e := data_manage.GetChartEdbMappingListByChartInfoIds(chartInfoIds)
  108. if e != nil {
  109. br.Msg = "获取失败"
  110. br.ErrMsg = "获取图表,指标信息失败,Err:" + e.Error()
  111. return
  112. }
  113. for _, v := range edbList {
  114. chartEdbMap[v.ChartInfoId] = append(chartEdbMap[v.ChartInfoId], v)
  115. }
  116. }
  117. for _, v := range searchList {
  118. tmp := new(data_manage.ChartInfoMore)
  119. tmp.ChartInfo = v.ChartInfo
  120. // 图表数据权限
  121. tmp.HaveOperaAuth = true
  122. //判断是否需要展示英文标识
  123. if edbTmpList, ok := chartEdbMap[v.ChartInfoId]; ok {
  124. tmp.IsEnChart = data.CheckIsEnChart(v.ChartNameEn, edbTmpList, v.Source, v.ChartType)
  125. }
  126. tmp.SearchText = v.SearchText
  127. if tmp.SearchText == "" {
  128. tmp.SearchText = v.ChartName
  129. }
  130. finalList = append(finalList, tmp)
  131. }
  132. }
  133. //新增搜索词记录
  134. {
  135. searchKeyword := new(data_manage.SearchKeyword)
  136. searchKeyword.KeyWord = keyword
  137. searchKeyword.CreateTime = time.Now()
  138. go data_manage.AddSearchKeyword(searchKeyword)
  139. }
  140. page := paging.GetPaging(currentIndex, pageSize, int(total))
  141. resp := data_manage.ChartInfoListByEsResp{
  142. Paging: page,
  143. List: finalList,
  144. }
  145. br.Ret = 200
  146. br.Success = true
  147. br.Msg = "获取成功"
  148. br.Data = resp
  149. }