123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130 |
- 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
- }
|