package data import ( "eta_gn/eta_api/models/data_manage" "eta_gn/eta_api/services/elastic" "eta_gn/eta_api/utils" "fmt" "strconv" "strings" ) // AddAllChartInfo // @Description: 更新es中的所有的图表数据 // @author: Roc // @datetime 2024-11-20 13:11:35 func AddAllChartInfo() { allList, err := data_manage.GetChartInfoAllList() if err != nil { fmt.Println("GetArticleAll Err:", err.Error()) return } total := len(allList) for k, v := range allList { AddOrEditChartInfoToEs(v.ChartInfoId) fmt.Println("剩余", total-k-1, "条图表数据,当前图表id:", v.ChartInfoId) } } // AddOrEditChartInfoToEs 新增和修改ES中的图表数据 func AddOrEditChartInfoToEs(chartInfoId int) { var err error defer func() { if err != nil { fmt.Println("新增和修改ES中的图表数据失败:", err.Error()) } }() itemInfo, err := data_manage.GetChartEsInfoById(chartInfoId) if err != nil { return } // 获取分享人 obj := data_manage.ChartInfoShare{} list, _ := obj.GetListByChartInfoId(itemInfo.ChartInfoId) sharedList := make([]int, 0) for _, v := range list { sharedList = append(sharedList, v.SysUserId) } itemInfo.SharedUserIdList = sharedList //添加es err = elastic.AddOrEditChartInfoToEsData(utils.CHART_INDEX_NAME, strconv.Itoa(itemInfo.ChartInfoId), itemInfo) return } // DeleteChartInfoToEs 删除ES中的图表数据 func DeleteChartInfoToEs(chartInfoId int) { var err error defer func() { if err != nil { fmt.Println("删除ES中的图表数据失败:", err.Error()) } }() //添加es err = elastic.EsDeleteDataV2(utils.CHART_INDEX_NAME, strconv.Itoa(chartInfoId)) return } // EsSearchChartInfo 搜索图表信息 func EsSearchChartInfo(keyword string, showSysId int, sourceList []int, noPermissionChartIdList []int, startSize, pageSize int) (list []*data_manage.ChartInfo, total int64, err error) { list, total, err = elastic.SearchChartInfoData(keyword, showSysId, sourceList, noPermissionChartIdList, startSize, pageSize) return } // ###### 下面是MY ETA 相关,没有意义了 // EsAddOrEditMyChartInfoByChartInfoId 根据图表id 新增和修改ES中的图表数据 func EsAddOrEditMyChartInfoByChartInfoId(chartInfoId int) { return errMsg := make([]string, 0) defer func() { if len(errMsg) > 0 { fmt.Println("新增和修改ES中的图表数据失败:", strings.Join(errMsg, "\n")) } }() var condition string var pars []interface{} condition += " and a.chart_info_id = ? " pars = append(pars, chartInfoId) allList, err := data_manage.GetMyChartListGroupByCharyInfoIdAndAdminIdByCondition(condition, pars) if err != nil { errMsg = append(errMsg, fmt.Sprintf("EsAddOrEditMyChartInfoByChartInfoId Err:%s", err.Error())) return } for _, v := range allList { //添加es err = elastic.EsAddOrEditDataInterface(utils.MY_CHART_INDEX_NAME, strconv.Itoa(v.MyChartId), v) if err != nil { errMsg = append(errMsg, fmt.Sprintf("myChartId:%d,添加Es失败,err:%s", v.MyChartId, err.Error())) } } return } // EsAddOrEditMyChartInfoByMyChartId 根据我的图库id 新增和修改ES中的图表数据 func EsAddOrEditMyChartInfoByMyChartId(myChartId int) { return errMsg := make([]string, 0) defer func() { if len(errMsg) > 0 { fmt.Println("新增和修改ES中的图表数据失败:", strings.Join(errMsg, "\n")) } }() var condition string var pars []interface{} condition += " AND a.my_chart_id = ? " pars = append(pars, myChartId) allList, err := data_manage.GetMyChartListGroupByCharyInfoIdAndAdminIdByCondition(condition, pars) if err != nil { errMsg = append(errMsg, fmt.Sprintf("EsAddOrEditMyChartInfoByMyChartId Err:%s", err.Error())) return } for _, v := range allList { //添加es err = elastic.EsAddOrEditDataInterface(utils.MY_CHART_INDEX_NAME, strconv.Itoa(v.MyChartId), v) if err != nil { errMsg = append(errMsg, fmt.Sprintf("myChartId:%d,添加Es失败,err:%s", v.MyChartId, err.Error())) } } return } // EsDeleteMyChartInfoByMyChartId 根据我的图库id 删除ES中的图表数据 func EsDeleteMyChartInfoByMyChartId(myChartId int) { return var err error defer func() { if err != nil { fmt.Println("删除ES中的图表数据失败:", err.Error()) } }() //添加es err = elastic.EsDeleteDataV2(utils.MY_CHART_INDEX_NAME, strconv.Itoa(myChartId)) return } // EsSearchMyChartInfo 搜索图表信息 func EsSearchMyChartInfo(keyword string, adminId int, noPermissionChartIdList []int, startSize, pageSize int) (list []*data_manage.MyChartList, total int64, err error) { return list, total, err = elastic.SearchMyChartInfoData(utils.MY_CHART_INDEX_NAME, keyword, adminId, noPermissionChartIdList, startSize, pageSize) return } // EsDeleteMyChartInfoByMyChartIds 根据我的图表IDs删除ES中的我的图表 func EsDeleteMyChartInfoByMyChartIds(ids []int) { return if len(ids) == 0 { return } errMsg := make([]string, 0) defer func() { if len(errMsg) > 0 { fmt.Println("EsDeleteMyChartInfoByMyChartIds, 删除ES中的我的图表数据失败:", strings.Join(errMsg, "\n")) } }() for _, v := range ids { id := strconv.Itoa(v) if e := elastic.EsDeleteDataV2(utils.MY_CHART_INDEX_NAME, id); e != nil { errMsg = append(errMsg, fmt.Sprintf("myChartId:%d,删除Es失败,err:%s", v, e.Error())) } } return }