package jobs import ( "gadmin/config" "github.com/sirupsen/logrus" "os" "sync" ) var MigrateZoneBonus = new(jMigrateZoneBonus) type jMigrateZoneBonus struct { sync.Mutex } func (j *jMigrateZoneBonus) Run() { logrus.Info("MigrateZoneBonus Run.....") if os.Getenv("GIN_MODE") != "release" && os.Getenv("ADMIN_IS_LOCAL") != "1" { logrus.Warnf("测试环境禁止同步") return } j.Lock() defer j.Unlock() for serverId, _ := range config.GDBGroup { j.sync(serverId) } } func (j *jMigrateZoneBonus) sync(serverId int) { //todo //DB, err := player.GetDBByServerID(serverId) //if err != nil { // logrus.Warningf("SyncChannel GetDBByServerID err:%v", err) // return //} // //var ( // now = time.Now().Unix() // c = query.Use(config.GDBGroup[DB]).ZoneActivity // results []*model.ZoneActivity //) // //// BonusProperties 加成属性 //type BonusProperties struct { // DifScale int `json:"difScale"` // 难度系数 // RewardMulti float64 `json:"rewardMulti"` // 奖励倍数 // RewardEffectTime int64 `json:"rewardEffectTime"` // 奖励倍数生效时间 //} // //err = c.Select(c.Playerid, c.Difficulty). // //Where(c.ID.Gt(lastId)). // Where(c.Difficulty.Neq("{}")). // Order(c.Playerid). // 因为玩家ID是无序的,为了保证批量处理的顺序性和正确性,做个正排序处理 // FindInBatches(&results, 500, func(tx gen.Dao, batch int) error { // for _, result := range results { // var difficulty map[uint]int // if result.Difficulty == "" { // continue // } // // err = json.Unmarshal([]byte(result.Difficulty), &difficulty) // if err != nil { // panic(err) // } // // if len(difficulty) == 0 { // continue // } // // isSave := false // bonusProperties := make(map[string]*BonusProperties) // // for chapterId, scale := range difficulty { // // 无效数据 // if cast.ToInt64(chapterId) < 100 { // continue // } // // isSave = true // ck := fmt.Sprintf("%v_%v", chapterId, 0) // bonusProperties[ck] = new(BonusProperties) // bonusProperties[ck].DifScale = scale // bonusProperties[ck].RewardMulti = 1 // bonusProperties[ck].RewardEffectTime = now // } // // if isSave { // marshal, err := json.Marshal(bonusProperties) // if err != nil { // panic(err) // } // // _, err = query.Use(config.GDBGroup[DB]).ZoneActivity.Where(c.Playerid.Eq(result.Playerid)).Updates(&model.ZoneActivity{ // BonusProperties: string(marshal), // }) // if err != nil { // panic(err) // } // } // } // return nil // }) // //if err != nil { // logrus.Warnf("MigrateZoneBonus sync err:%+v", err) // return //} logrus.Info("MigrateZoneBonus sync success..") }