@@ -0,0 +1,65 @@
|
||||
package esmedia
|
||||
|
||||
import (
|
||||
"91porn-server/common/elastic"
|
||||
"91porn-server/common/log"
|
||||
"91porn-server/models"
|
||||
"91porn-server/models/v/mediamod"
|
||||
)
|
||||
|
||||
// SyncDataToES 同步数据到ES
|
||||
func SyncDataToES(data []*mediamod.Media) error {
|
||||
if len(data) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
source := buildSource(data)
|
||||
log.Info("Elastic sync ACG media data committing...")
|
||||
if err := es.BulkChecked(models.ESMediaTable, source); err != nil {
|
||||
log.Info("Elastic sync ACG media data commit failed.")
|
||||
return err
|
||||
}
|
||||
log.Info("Elastic sync ACG media data committed.")
|
||||
return nil
|
||||
}
|
||||
|
||||
func buildSource(data []*mediamod.Media) elastic.M {
|
||||
var source = elastic.M{}
|
||||
for _, v := range data {
|
||||
source[v.ID.Hex()] = mediamod.ESMedia{
|
||||
ID: v.ID,
|
||||
Title: v.Title,
|
||||
HorizontalCover: v.HorizontalCover,
|
||||
VerticalCover: v.VerticalCover,
|
||||
Tags: v.Tags,
|
||||
Summary: v.Summary,
|
||||
TotalEpisode: v.TotalEpisode,
|
||||
UpdateStatus: v.UpdateStatus,
|
||||
MediaType: v.MediaType,
|
||||
Kind: v.Kind,
|
||||
PermissionIconHide: v.PermissionIconHide,
|
||||
Permission: v.Permission,
|
||||
Price: v.Price,
|
||||
Direction: v.Direction,
|
||||
FreeTime: v.FreeTime,
|
||||
CountLike: v.CountLike,
|
||||
CountBrowse: v.CountBrowse,
|
||||
CountCollect: v.CountCollect,
|
||||
MID: v.MID,
|
||||
ModuleName: v.ModuleName,
|
||||
SectionName: v.SectionName,
|
||||
SID: v.SID,
|
||||
SectionSort: v.SectionSort,
|
||||
Choice: v.Choice,
|
||||
ChoiceSort: v.ChoiceSort,
|
||||
Number: v.Number,
|
||||
SortCode: v.SortCode,
|
||||
Status: v.Status,
|
||||
IsDelete: v.IsDelete,
|
||||
UpdatedAct: v.UpdatedAct,
|
||||
CreatedAt: v.CreatedAt,
|
||||
UpdateTime: v.UpdateTime,
|
||||
}
|
||||
}
|
||||
return source
|
||||
}
|
||||
Reference in New Issue
Block a user