package main import ( "context" "encoding/json" "time" _ "github.com/go-sql-driver/mysql" "git.nonolive.co/eson.hsm/databoard-collect/database" "github.com/go-xorm/xorm" "github.com/google/uuid" "go.mongodb.org/mongo-driver/bson" ) type CountLiveAnchors struct { UID string `xorm:"uid"` CreateAt time.Time `xorm:"create_at"` IsCounted int `xorm:"is_counted"` CountMap string `xorm:"count_map"` } func main() { mdb := database.NewStatisticsDB("mongodb://sg-board1.livenono.com:27018") engine, err := xorm.NewEngine("mysql", "root:Nono-databoard@tcp(127.0.0.1:3306)/databoard?parseTime=true&loc=Local&charset=utf8&collation=utf8_unicode_ci") if err != nil { panic(err) } cla := engine.Table("count_live_anchors") cur, err := mdb.C.CountLiveAnchors.Find(context.TODO(), bson.M{}) if err != nil { panic(err) } for cur.Next(context.TODO()) { la := &database.LiveAnchorsCountPoint{} err = cur.Decode(la) if err != nil { panic(err) } c := &CountLiveAnchors{} c.UID = uuid.New().String() c.IsCounted = 0 c.CreateAt = la.CreateAt data, err := json.Marshal(la.LiveAnchorDict) if err != nil { panic(err) } c.CountMap = string(data) _, err = cla.Insert(c) if err != nil { panic(err) } } }