package services import ( "eta/eta_hub/models" "eta/eta_hub/utils" "fmt" "html" "strconv" ) // SmartReportElasticUpsert 新增/编辑报告es func SmartReportElasticUpsert(smartReportId int, state int) (err error) { if smartReportId <= 0 { return } reportOB := new(models.SmartReport) item, e := reportOB.GetItemById(smartReportId) if e != nil { if e.Error() == utils.ErrNoRow() { // 可能被删了就直接忽略掉 return } err = fmt.Errorf("获取报告失败, Err: %s", e.Error()) return } esReport := new(models.ElasticSmartReport) esReport.SmartReportId = item.SmartReportId esReport.Title = item.Title esReport.Abstract = item.Abstract esReport.BodyContent = utils.TrimHtml(html.UnescapeString(item.Content)) esReport.PublishTime = item.PublishTime.Format(utils.FormatDateTime) esReport.PublishState = state esReport.Author = item.Author esReport.ClassifyIdFirst = item.ClassifyIdFirst esReport.ClassifyNameFirst = item.ClassifyNameFirst esReport.ClassifyIdSecond = item.ClassifyIdSecond esReport.ClassifyNameSecond = item.ClassifyNameSecond esReport.StageStr = strconv.Itoa(item.Stage) esReport.Frequency = item.Frequency if err = EsAddOrEditSmartReport(utils.SmartReportIndexName, strconv.Itoa(item.SmartReportId), esReport); err != nil { return } return }