package elastic import ( "context" "eta/eta_api/utils" "fmt" "time" ) // WechatArticleAndPlatform // @Description: 存入ES的数据 type WechatArticleAndPlatform struct { WechatArticleId int `gorm:"column:wechat_article_id;type:int(10) UNSIGNED;primaryKey;not null;" description:""` WechatPlatformId int `gorm:"column:wechat_platform_id;type:int(11);comment:归属公众号id;default:0;" description:"归属公众号id"` FakeId string `gorm:"column:fake_id;type:varchar(255);comment:公众号唯一id;" description:"公众号唯一id"` Title string `gorm:"column:title;type:varchar(255);comment:标题;" description:"标题"` Link string `gorm:"column:link;type:varchar(255);comment:链接;" description:"链接"` CoverUrl string `gorm:"column:cover_url;type:varchar(255);comment:公众号封面;" description:"公众号封面"` Description string `gorm:"column:description;type:varchar(255);comment:描述;" description:"描述"` Content string `gorm:"column:content;type:longtext;comment:报告详情;" description:"报告详情"` TextContent string `gorm:"column:text_content;type:text;comment:文本内容;" description:"文本内容"` //Abstract string `gorm:"column:abstract;type:text;comment:摘要;" description:"摘要"` Country string `gorm:"column:country;type:varchar(255);comment:国家;" description:"国家"` Province string `gorm:"column:province;type:varchar(255);comment:省;" description:"省"` City string `gorm:"column:city;type:varchar(255);comment:市;" description:"市"` ArticleCreateTime time.Time `gorm:"column:article_create_time;type:datetime;comment:报告创建时间;default:NULL;" description:"报告创建时间"` IsDeleted int `gorm:"column:is_deleted;type:tinyint(4);comment:是否删除,0:未删除,1: 已删除;default:0;" description:"是否删除,0:未删除,1: 已删除"` ModifyTime time.Time `gorm:"column:modify_time;type:datetime;comment:修改时间;default:NULL;" description:"修改时间"` CreateTime time.Time `gorm:"column:create_time;type:datetime;comment:入库时间;default:NULL;" description:"入库时间"` Nickname string `gorm:"column:nickname;type:varchar(255);comment:公众号名称;" description:"nickname"` // 公众号名称 Alias string `gorm:"column:alias;type:varchar(255);comment:别名;" description:"alias"` // 别名 RoundHeadImg string `gorm:"column:round_head_img;type:varchar(255);comment:头像;" description:"round_head_img"` // 头像 } // WechatArticleEsAddOrEdit // @Description: 新增/编辑微信文章 // @author: Roc // @datetime 2025-03-13 10:24:05 // @param docId string // @param item WechatArticleAndPlatform // @return err error func WechatArticleEsAddOrEdit(docId string, item WechatArticleAndPlatform) (err error) { if docId == "" { return } if utils.EsWechatArticleName == `` { return } defer func() { if err != nil { fmt.Println("WechatArticleEsAddOrEdit Err:", err.Error()) } }() client := utils.EsClient resp, err := client.Index().Index(utils.EsWechatArticleName).Id(docId).BodyJson(item).Refresh("true").Do(context.Background()) if err != nil { fmt.Println("新增失败:", err.Error()) return err } if resp.Status == 0 { fmt.Println("新增成功", resp.Result) err = nil } else { fmt.Println("WechatArticleEsAddOrEdit", resp.Status, resp.Result) } return } // WechatArticleEsDel // @Description: 删除微信文章 // @author: Roc // @datetime 2025-03-13 10:23:55 // @param docId string // @return err error func WechatArticleEsDel(docId string) (err error) { if docId == "" { return } if utils.EsWechatArticleName == `` { return } defer func() { if err != nil { fmt.Println("EsDeleteEdbInfoData Err:", err.Error()) } }() client := utils.EsClient resp, err := client.Delete().Index(utils.EsWechatArticleName).Id(docId).Refresh(`true`).Do(context.Background()) if err != nil { return } if resp.Status == 0 { fmt.Println("删除成功") } else { fmt.Println("WechatArticleEsDel", resp.Status, resp.Result) } return }