123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162 |
- package ai_predict_model
- import (
- "eta/eta_mobile/controllers"
- "eta/eta_mobile/models"
- "eta/eta_mobile/models/data_manage"
- "eta/eta_mobile/services/data"
- "eta/eta_mobile/utils"
- "github.com/rdlucklib/rdluck_tools/paging"
- "strconv"
- "strings"
- "time"
- )
- // AiPredictModelIndexController AI预测模型标的
- type AiPredictModelIndexController struct {
- controllers.BaseAuthController
- }
- // SearchByEs
- // @Title 图表模糊搜索(从es获取)
- // @Description 图表模糊搜索(从es获取)
- // @Param Keyword query string true "图表名称"
- // @Param IsShowMe query bool true "是否只看我的,true、false"
- // @Param Source query int true "来源,14:日度预测,15:月度预测,默认0:全部14+15"
- // @Success 200 {object} data_manage.ChartInfo
- // @router /chart/search_by_es [get]
- func (this *AiPredictModelIndexController) SearchByEs() {
- br := new(models.BaseResponse).Init()
- defer func() {
- if br.ErrMsg == "" {
- br.IsSendEmail = false
- }
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- pageSize, _ := this.GetInt("PageSize")
- currentIndex, _ := this.GetInt("CurrentIndex")
- var startSize int
- if pageSize <= 0 {
- pageSize = utils.PageSize20
- }
- if currentIndex <= 0 {
- currentIndex = 1
- }
- startSize = paging.StartIndex(currentIndex, pageSize)
- keyword := this.GetString("Keyword")
- keyword = strings.TrimSpace(keyword)
- if keyword == "" {
- keyword = this.GetString("KeyWord")
- keyword = strings.TrimSpace(keyword)
- }
- //只看我的
- isShowMe, _ := this.GetBool("IsShowMe")
- showSysId := 0
- if isShowMe {
- showSysId = sysUser.AdminId
- }
- source, _ := this.GetInt("Source")
- sourceList := make([]int, 0)
- if source <= 0 {
- sourceList = append(sourceList, utils.CHART_SOURCE_AI_PREDICT_MODEL_MONTHLY, utils.CHART_SOURCE_AI_PREDICT_MODEL_DAILY)
- } else {
- sourceList = append(sourceList, source)
- }
- var searchList []*data_manage.ChartInfoMore
- var total int64
- var err error
- // 获取当前账号的不可见指标(AI预测的指标为标的均可见)
- noPermissionChartIdList := make([]int, 0)
- //{
- // obj := data_manage.EdbInfoNoPermissionAdmin{}
- // confList, err := obj.GetAllChartListByAdminId(this.SysUser.AdminId)
- // if err != nil && !utils.IsErrNoRow(err) {
- // br.Msg = "获取失败"
- // br.ErrMsg = "获取不可见指标配置数据失败,Err:" + err.Error()
- // return
- // }
- // for _, v := range confList {
- // noPermissionChartIdList = append(noPermissionChartIdList, v.ChartInfoId)
- // }
- //}
- if keyword != "" {
- searchList, total, err = data.EsSearchChartInfo(keyword, showSysId, sourceList, noPermissionChartIdList, startSize, pageSize)
- } else {
- total, searchList, err = data_manage.ChartInfoSearchByEmptyKeyWord(showSysId, sourceList, noPermissionChartIdList, startSize, pageSize)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
- return
- }
- }
- finalList := make([]*data_manage.ChartInfoMore, 0)
- if len(searchList) > 0 {
- chartInfoIds := ""
- chartEdbMap := make(map[int][]*data_manage.ChartEdbInfoMapping)
- for _, v := range searchList {
- chartInfoIds += strconv.Itoa(v.ChartInfoId) + ","
- }
- if chartInfoIds != "" {
- chartInfoIds = strings.Trim(chartInfoIds, ",")
- //判断是否需要展示英文标识
- edbList, e := data_manage.GetChartEdbMappingListByChartInfoIds(chartInfoIds)
- if e != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取图表,指标信息失败,Err:" + e.Error()
- return
- }
- for _, v := range edbList {
- chartEdbMap[v.ChartInfoId] = append(chartEdbMap[v.ChartInfoId], v)
- }
- }
- for _, v := range searchList {
- tmp := new(data_manage.ChartInfoMore)
- tmp.ChartInfo = v.ChartInfo
- // 图表数据权限
- tmp.HaveOperaAuth = true
- //判断是否需要展示英文标识
- if edbTmpList, ok := chartEdbMap[v.ChartInfoId]; ok {
- tmp.IsEnChart = data.CheckIsEnChart(v.ChartNameEn, edbTmpList, v.Source, v.ChartType)
- }
- tmp.SearchText = v.SearchText
- if tmp.SearchText == "" {
- tmp.SearchText = v.ChartName
- }
- finalList = append(finalList, tmp)
- }
- }
- //新增搜索词记录
- {
- searchKeyword := new(data_manage.SearchKeyword)
- searchKeyword.KeyWord = keyword
- searchKeyword.CreateTime = time.Now()
- go data_manage.AddSearchKeyword(searchKeyword)
- }
- page := paging.GetPaging(currentIndex, pageSize, int(total))
- resp := data_manage.ChartInfoListByEsResp{
- Paging: page,
- List: finalList,
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
|