123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141 |
- package data
- import (
- "eta_gn/eta_api/models/data_manage"
- "eta_gn/eta_api/services/elastic"
- "eta_gn/eta_api/utils"
- "fmt"
- "strconv"
- "strings"
- )
- // EsAddOrEditChartInfo 新增和修改ES中的图表数据
- func EsAddOrEditChartInfo(chartInfoId int) {
- var err error
- defer func() {
- if err != nil {
- fmt.Println("新增和修改ES中的图表数据失败:", err.Error())
- }
- }()
- itemInfo, _ := data_manage.GetChartInfoById(chartInfoId)
- //添加es
- err = elastic.EsAddOrEditChartInfoData(utils.CHART_INDEX_NAME, strconv.Itoa(itemInfo.ChartInfoId), itemInfo)
- return
- }
- // EsDeleteChartInfo 删除ES中的图表数据
- func EsDeleteChartInfo(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(utils.CHART_INDEX_NAME, keyword, showSysId, sourceList, noPermissionChartIdList, startSize, pageSize)
- return
- }
- // EsAddOrEditMyChartInfoByChartInfoId 根据图表id 新增和修改ES中的图表数据
- func EsAddOrEditMyChartInfoByChartInfoId(chartInfoId int) {
- 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) {
- 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) {
- 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) {
- list, total, err = elastic.SearchMyChartInfoData(utils.MY_CHART_INDEX_NAME, keyword, adminId, noPermissionChartIdList, startSize, pageSize)
- return
- }
- // EsDeleteMyChartInfoByMyChartIds 根据我的图表IDs删除ES中的我的图表
- func EsDeleteMyChartInfoByMyChartIds(ids []int) {
- 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
- }
|