package services import ( "eta/eta_forum_admin/models" "eta/eta_forum_admin/services/elastic" "eta/eta_forum_admin/utils" "fmt" "strconv" ) func CreateChartInfoIndex() { indexName := utils.CHART_INDEX_NAME mappingJson := `{ "mappings": { "dynamic": true, "properties": { "ChartInfoId": { "type": "integer" }, "ChartName": { "type": "text", "term_vector": "with_positions_offsets", "analyzer": "ik_smart" }, "ChartClassifyId": { "type": "integer" }, "SysUserId": { "type": "integer" }, "SysUserRealName": { "type": "text", "term_vector": "with_positions_offsets", "analyzer": "ik_smart" }, "UniqueCode": { "type": "text", "term_vector": "with_positions_offsets" }, "Unit": { "type": "text", "term_vector": "with_positions_offsets" }, "CreateTime": { "type": "date" }, "ModifyTime": { "type": "date" }, "DateType": { "type": "integer" }, "StartDate": { "type": "text", "term_vector": "with_positions_offsets" }, "EndDate": { "type": "text", "term_vector": "with_positions_offsets" }, "IsSetName": { "type": "integer" }, "EdbInfoIds": { "type": "text", "term_vector": "with_positions_offsets" }, "ChartType": { "type": "integer" }, "Calendar": { "type": "text", "term_vector": "with_positions_offsets" }, "ChartImage": { "type": "text", "term_vector": "with_positions_offsets" } } } }` elastic.EsCreateIndex(indexName, mappingJson) } func AddAllChartInfo() { allList, err := models.GetChartInfoAllList() if err != nil { fmt.Println("GetArticleAll Err:", err.Error()) return } total := len(allList) for k, v := range allList { EsAddOrEditChartInfo(v.ChartInfoId) //fmt.Println(v.ChartInfoId) fmt.Println("剩余", total-k-1, "条数据,当前图表id:", v.ChartInfoId) } } // EsAddOrEditChartInfo 新增和修改ES中的图表数据 func EsAddOrEditChartInfo(chartInfoId int) { var err error defer func() { if err != nil { fmt.Println("新增和修改ES中的图表数据失败:", err.Error()) } }() itemInfo, _ := models.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, startSize, pageSize int) (list []*models.ChartInfo, total int64, err error) { list, total, err = elastic.SearchChartInfoData(utils.CHART_INDEX_NAME, keyword, showSysId, sourceList, startSize, pageSize) return }