From 074f1074e320ccf984f77300868a7d2fdc4139dc Mon Sep 17 00:00:00 2001 From: 陆恒 Date: Wed, 2 Sep 2020 10:07:56 +0800 Subject: [PATCH] 提交 --- src/HttpServer/logic/function.go | 9 ++++----- src/HttpServer/logic/logic.go | 36 +++++++++++++++++++++++++++++------- src/mysql/dbmysql.go | 11 +++++++---- 3 files changed, 40 insertions(+), 16 deletions(-) diff --git a/src/HttpServer/logic/function.go b/src/HttpServer/logic/function.go index 86acc6d..76e7fa2 100644 --- a/src/HttpServer/logic/function.go +++ b/src/HttpServer/logic/function.go @@ -11,7 +11,6 @@ import ( "encoding/json" "errors" "io/ioutil" - "mysql" "net/http" "sort" "strconv" @@ -55,10 +54,10 @@ func GetUserInfo(uniqueid string) (*UserData, error) { data, err := redishandler.GetRedisClient().HGet(redis.USER_DATA_KEY, uniqueid) if err != nil { - logger.Info("GetUserInfo from mysql") - //return nil, err + //logger.Info("GetUserInfo from mysql") + return nil, err //从mysql读取 - err,info,task,ach := mysql.GetFromBackUp(uniqueid) + /*err,info,task,ach := mysql.GetFromBackUp(uniqueid) if err != nil { return nil, err } @@ -73,7 +72,7 @@ func GetUserInfo(uniqueid string) (*UserData, error) { return nil, err } - return &tmp, nil + return &tmp, nil*/ }else { var tmp UserData err = json.Unmarshal([]byte(data), &tmp) diff --git a/src/HttpServer/logic/logic.go b/src/HttpServer/logic/logic.go index 3a9bb13..b21909f 100644 --- a/src/HttpServer/logic/logic.go +++ b/src/HttpServer/logic/logic.go @@ -7,6 +7,7 @@ import ( "common/redis" "encoding/json" "fmt" + "mysql" "net/http" "strconv" "strings" @@ -1193,8 +1194,32 @@ func HandlerLogin(w http.ResponseWriter, data string, uuid int) { if !isexist { //不存在 //属于新登录的玩家数据 - //需要判断是否存在老的版本的数据 - isexist, err = redishandler.GetRedisClient().HExists(redis.USER_DATA_KEY, strconv.Itoa(uuid)) + //需要判断是否存在mysql中 + logger.Info("GetUserInfo from mysql") + //return nil, err + //从mysql读取 + err,info,task,ach,isfind := mysql.GetFromBackUp(uniqueuuid) + if err != nil { + /*logger.Error("mysql failed err=%v", err) + resp.Message = "服务器错误" + resp.Code = ERROR_SRV_ERROR + break*/ + logger.Error("mysql failed err=%v", err) + err = GetUserData(uuid, uniqueuuid, &rdata, &resp) + } + + if isfind { + //先保存数据 + err = redishandler.GetRedisClient().HSet(redis.USER_DATA_KEY, uniqueuuid,info) + err = redishandler.GetRedisClient().HSet(redis.USER_TASKINFO_LIST, uniqueuuid,task) + err = redishandler.GetRedisClient().HSet(redis.USER_ACHIEVEMENTINFO_LIST, uniqueuuid,ach) + }else { + //不存在老的数据 之间走新号流程 + err = InitUserInfo(&rdata, &resp, uuid, uniqueuuid) + } + + + /*isexist, err = redishandler.GetRedisClient().HExists(redis.USER_DATA_KEY, strconv.Itoa(uuid)) if err == nil && isexist { //如果存在老的数据 做数据迁移 oldstr, err := redishandler.GetRedisClient().HGet(redis.USER_DATA_KEY, strconv.Itoa(uuid)) @@ -1217,11 +1242,8 @@ func HandlerLogin(w http.ResponseWriter, data string, uuid int) { //删除老的数据 redishandler.GetRedisClient().HDel(redis.USER_DATA_KEY, strconv.Itoa(uuid)) logger.Info("HandlerLogin uuid=%v do set", uuid) - } - } else { - //不存在老的数据 之间走新号流程 - err = InitUserInfo(&rdata, &resp, uuid, uniqueuuid) - } + }*/ + } else { //已经迁移过的数据之间返回 diff --git a/src/mysql/dbmysql.go b/src/mysql/dbmysql.go index f22576f..ba22f83 100644 --- a/src/mysql/dbmysql.go +++ b/src/mysql/dbmysql.go @@ -46,7 +46,8 @@ func ExcuteCmd(cmd string) error { return err } -func GetFromBackUp(uniqueid string) (error,string,string,string) { +func GetFromBackUp(uniqueid string) (error,string,string,string,bool) { + isfind := false cmd := "select info,task,achieve from hedaoshi where uid = " + uniqueid rows, err := m_game_db.Query(cmd) if rows != nil { @@ -54,7 +55,7 @@ func GetFromBackUp(uniqueid string) (error,string,string,string) { } if err != nil { logger.Notic("TestClearData mysql select error:%v", err) - return err,"","","" + return err,"","","",isfind } var info,task,ach string for rows.Next() { @@ -62,14 +63,16 @@ func GetFromBackUp(uniqueid string) (error,string,string,string) { err = rows.Scan(&info,&task,&ach) if err != nil { logger.Notic("GetFromBackUp mysql handle result error:%v", err) - return err,"","","" + return err,"","","",isfind } + + isfind = true logger.Info("GetFromBackUp uniqueid=%v",uniqueid) break } - return nil,info,task,ach + return nil,info,task,ach,isfind } func TestClearData(uid int) (int,error) { -- libgit2 0.21.0