Merge branch 'meixiongfeng' of http://git.legu.cc/liwei_3d/go_dreamfactory into dev
This commit is contained in:
commit
14be41a497
@ -123,6 +123,7 @@ func (this *apiComp) ChallengeOver(session comm.IUserSession, req *pb.PagodaChal
|
|||||||
Lv: userinfo.Lv,
|
Lv: userinfo.Lv,
|
||||||
CostTime: req.Report.Costtime,
|
CostTime: req.Report.Costtime,
|
||||||
}
|
}
|
||||||
|
|
||||||
conn.Mgo.InsertOne(comm.TablePagodaRecord, newData)
|
conn.Mgo.InsertOne(comm.TablePagodaRecord, newData)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package pagoda
|
package pagoda
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"go_dreamfactory/comm"
|
"go_dreamfactory/comm"
|
||||||
"go_dreamfactory/lego/core"
|
"go_dreamfactory/lego/core"
|
||||||
@ -12,7 +13,9 @@ import (
|
|||||||
"sort"
|
"sort"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"go.mongodb.org/mongo-driver/bson"
|
||||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||||
|
"go.mongodb.org/mongo-driver/mongo/options"
|
||||||
)
|
)
|
||||||
|
|
||||||
var floorRankKey = "pagoda:floor"
|
var floorRankKey = "pagoda:floor"
|
||||||
@ -71,32 +74,38 @@ func (this *ModelRank) getPagodaRankList(uid string) []*pb.DBPagodaRecord {
|
|||||||
}
|
}
|
||||||
return pagodaRank
|
return pagodaRank
|
||||||
}
|
}
|
||||||
func (this *ModelRank) addPagodaList(session comm.IUserSession, data *pb.DBPagoda, Leadpos int32, line []*pb.LineUp, costTime int32) {
|
|
||||||
userinfo := this.modulePagoda.ModuleUser.GetUser(session.GetUserId())
|
// func (this *ModelRank) addPagodaList(session comm.IUserSession, data *pb.DBPagoda, Leadpos int32, line []*pb.LineUp, costTime int32) {
|
||||||
new := &pb.DBPagodaRecord{
|
// userinfo := this.modulePagoda.ModuleUser.GetUser(session.GetUserId())
|
||||||
Id: primitive.NewObjectID().Hex(),
|
// new := &pb.DBPagodaRecord{
|
||||||
Uid: session.GetUserId(),
|
// Id: primitive.NewObjectID().Hex(),
|
||||||
PagodaId: data.PagodaId,
|
// Uid: session.GetUserId(),
|
||||||
Type: data.Type,
|
// PagodaId: data.PagodaId,
|
||||||
Nickname: userinfo.Name,
|
// Type: data.Type,
|
||||||
Icon: "", // icon 暂无
|
// Nickname: userinfo.Name,
|
||||||
Lv: userinfo.Lv,
|
// Icon: "", // icon 暂无
|
||||||
CostTime: costTime,
|
// Lv: userinfo.Lv,
|
||||||
Line: line,
|
// CostTime: costTime,
|
||||||
}
|
// Line: line,
|
||||||
this.AddList(session.GetUserId(), new.Id, new) //写爬塔记录
|
// }
|
||||||
// 查询本层是否上榜
|
// this.AddList(session.GetUserId(), new.Id, new) //写爬塔记录
|
||||||
rankData, ilen, err1 := this.GetFloorLastRankData(data.PagodaId)
|
// // 查询本层是否上榜
|
||||||
if err1 == nil {
|
// rankData, ilen, err1 := this.GetFloorLastRankData(data.PagodaId)
|
||||||
if ilen < comm.MaxRankNum || rankData.CostTime < costTime {
|
// if err1 == nil {
|
||||||
this.ChangeFloorRankList(session, data.PagodaId, new)
|
// if ilen < comm.MaxRankNum || rankData.CostTime < costTime {
|
||||||
}
|
// this.ChangeFloorRankList(session, data.PagodaId, new)
|
||||||
}
|
// }
|
||||||
return
|
// }
|
||||||
}
|
// return
|
||||||
|
// }
|
||||||
|
|
||||||
// 插入新的排行数据
|
// 插入新的排行数据
|
||||||
func (this *ModelRank) addPagodaRankList(session comm.IUserSession, data *pb.DBSeasonPagoda, Leadpos int32, line []*pb.LineUp, costTime int32) {
|
func (this *ModelRank) addPagodaRankList(session comm.IUserSession, data *pb.DBSeasonPagoda, Leadpos int32, line []*pb.LineUp, costTime int32) {
|
||||||
|
uid := session.GetUserId()
|
||||||
|
var (
|
||||||
|
dbModel *db.DBModel
|
||||||
|
err error
|
||||||
|
)
|
||||||
userinfo := this.modulePagoda.ModuleUser.GetUser(session.GetUserId())
|
userinfo := this.modulePagoda.ModuleUser.GetUser(session.GetUserId())
|
||||||
new := &pb.DBPagodaRecord{
|
new := &pb.DBPagodaRecord{
|
||||||
Id: primitive.NewObjectID().Hex(),
|
Id: primitive.NewObjectID().Hex(),
|
||||||
@ -104,16 +113,32 @@ func (this *ModelRank) addPagodaRankList(session comm.IUserSession, data *pb.DBS
|
|||||||
PagodaId: data.PagodaId,
|
PagodaId: data.PagodaId,
|
||||||
Type: data.Type,
|
Type: data.Type,
|
||||||
Nickname: userinfo.Name,
|
Nickname: userinfo.Name,
|
||||||
Icon: "", // icon 暂无
|
Icon: "", // 暂时没有数据
|
||||||
Lv: userinfo.Lv,
|
Lv: userinfo.Lv,
|
||||||
|
Leadpos: Leadpos,
|
||||||
|
Line: line,
|
||||||
CostTime: costTime,
|
CostTime: costTime,
|
||||||
}
|
}
|
||||||
this.AddList(session.GetUserId(), new.Id, new) //写爬塔记录
|
if this.modulePagoda.IsCross() {
|
||||||
|
if dbModel, err = this.modulePagoda.GetDBNoduleByUid(uid, this.TableName, this.Expired); err != nil {
|
||||||
|
this.modulePagoda.Errorln(err)
|
||||||
|
|
||||||
|
} else {
|
||||||
|
if err = dbModel.AddList(session.GetUserId(), new.Id, new); err != nil {
|
||||||
|
this.modulePagoda.Errorf("err:%v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if err := this.AddList(session.GetUserId(), new.Id, new); err != nil {
|
||||||
|
this.modulePagoda.Errorf("err:%v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// 查询本层是否上榜
|
// 查询本层是否上榜
|
||||||
rankData, ilen, err1 := this.GetFloorLastRankData(data.PagodaId)
|
rankData, ilen, err1 := this.GetFloorLastRankData(data.PagodaId, dbModel)
|
||||||
if err1 != nil {
|
if err1 != nil {
|
||||||
if rankData.CostTime < costTime || ilen < comm.MaxRankNum {
|
if rankData.CostTime < costTime || ilen < comm.MaxRankNum {
|
||||||
this.ChangeFloorRankList(session, data.PagodaId, new)
|
this.ChangeFloorRankList(session, data.PagodaId, new, dbModel)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
@ -137,30 +162,46 @@ func (this *ModelRank) GetFloorRankList(floor int32) (result []*pb.DBPagodaRecor
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 获取排行榜最后一个元素
|
// 获取排行榜最后一个元素
|
||||||
func (this *ModelRank) GetFloorLastRankData(floor int32) (curData *pb.DBPagodaRecord, len int, err error) {
|
func (this *ModelRank) GetFloorLastRankData(floor int32, dbModel *db.DBModel) (curData *pb.DBPagodaRecord, len int, err error) {
|
||||||
key := fmt.Sprintf("%s-%d-rank", floorRankKey, floor)
|
key := fmt.Sprintf("%s-%d-rank", floorRankKey, floor)
|
||||||
len, err = this.Redis.Llen(key)
|
len, err = dbModel.Redis.Llen(key)
|
||||||
curData = &pb.DBPagodaRecord{}
|
curData = &pb.DBPagodaRecord{}
|
||||||
if this.Redis.Lindex(key, -1, curData); err != nil {
|
if dbModel.Redis.Lindex(key, -1, curData); err != nil {
|
||||||
this.modulePagoda.Errorf("err:%v", err)
|
this.modulePagoda.Errorf("err:%v", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if curData == nil {
|
||||||
|
data := make([]interface{}, 0) // options.Find().SetLimit(comm.MaxRankList)
|
||||||
|
if _data, err := dbModel.DB.Find(comm.TableSeasonRecord, bson.M{"pagodaId": floor}, options.Find().SetSort(bson.M{"pagodaId": -1}).SetLimit(comm.MaxRankList)); err == nil {
|
||||||
|
for _data.Next(context.TODO()) {
|
||||||
|
temp := &pb.DBPagodaRecord{}
|
||||||
|
if err = _data.Decode(temp); err == nil {
|
||||||
|
data = append(data, temp)
|
||||||
|
curData = temp
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
err := dbModel.Redis.RPush(key, data...)
|
||||||
|
if err == nil {
|
||||||
|
this.modulePagoda.Errorf("rpush failed :%v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// 修改某一层排行数据
|
// 修改某一层排行数据
|
||||||
func (this *ModelRank) ChangeFloorRankList(session comm.IUserSession, floor int32, curData *pb.DBPagodaRecord) (err error) {
|
func (this *ModelRank) ChangeFloorRankList(session comm.IUserSession, floor int32, curData *pb.DBPagodaRecord, dbModel *db.DBModel) (err error) {
|
||||||
key := fmt.Sprintf("%s-%d-rank", floorRankKey, floor)
|
key := fmt.Sprintf("%s-%d-rank", floorRankKey, floor)
|
||||||
lockkey := fmt.Sprintf("%s-%d-lock", floorRankKey, floor)
|
lockkey := fmt.Sprintf("%s-%d-lock", floorRankKey, floor)
|
||||||
|
|
||||||
this.Redis.Lock(lockkey, time.Now().Second()*5)
|
dbModel.Redis.Lock(lockkey, time.Now().Second()*5)
|
||||||
defer this.Redis.UnLock(lockkey)
|
defer dbModel.Redis.UnLock(lockkey)
|
||||||
if this.Redis.RPush(key, curData); err != nil {
|
if dbModel.Redis.RPush(key, curData); err != nil {
|
||||||
this.modulePagoda.Errorf("err:%v", err)
|
this.modulePagoda.Errorf("err:%v", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
temp := make([]*pb.DBPagodaRecord, 0)
|
temp := make([]*pb.DBPagodaRecord, 0)
|
||||||
if err = this.Redis.LRange(key, 0, -1, &temp); err != nil {
|
if err = dbModel.Redis.LRange(key, 0, -1, &temp); err != nil {
|
||||||
this.modulePagoda.Errorf("err:%v", err)
|
this.modulePagoda.Errorf("err:%v", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -169,14 +210,14 @@ func (this *ModelRank) ChangeFloorRankList(session comm.IUserSession, floor int3
|
|||||||
return temp[i].CostTime < temp[j].CostTime
|
return temp[i].CostTime < temp[j].CostTime
|
||||||
})
|
})
|
||||||
iLne := len(temp)
|
iLne := len(temp)
|
||||||
if this.Redis.RPush(key, temp); err != nil {
|
if dbModel.Redis.RPush(key, temp); err != nil {
|
||||||
this.modulePagoda.Errorf("err:%v", err)
|
this.modulePagoda.Errorf("err:%v", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if iLne > comm.MaxRankNum {
|
if iLne > comm.MaxRankNum {
|
||||||
iLne = comm.MaxRankNum
|
iLne = comm.MaxRankNum
|
||||||
}
|
}
|
||||||
err = this.Redis.Ltrim(key, -1*iLne, -1) //对一个列表进行修剪
|
err = dbModel.Redis.Ltrim(key, -1*iLne, -1) //对一个列表进行修剪
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf("delete failed")
|
log.Errorf("delete failed")
|
||||||
}
|
}
|
||||||
|
@ -89,6 +89,57 @@ func Test_Modules(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestXxx(t *testing.T) {
|
func TestXxx(t *testing.T) {
|
||||||
|
// uid := session.GetUserId()
|
||||||
|
// if !this.module.IsCross() {
|
||||||
|
// if conn, err := db.Cross(); err == nil {
|
||||||
|
// userinfo := this.module.ModuleUser.GetUser(session.GetUserId())
|
||||||
|
// newData := &pb.DBPagodaRecord{
|
||||||
|
// Id: primitive.NewObjectID().Hex(),
|
||||||
|
// Uid: session.GetUserId(),
|
||||||
|
// PagodaId: 111,
|
||||||
|
// Type: 201,
|
||||||
|
// Nickname: userinfo.Name,
|
||||||
|
// Icon: "", // icon 暂无
|
||||||
|
// Lv: userinfo.Lv,
|
||||||
|
// CostTime: 1002,
|
||||||
|
// }
|
||||||
|
|
||||||
|
// conn.Mgo.InsertOne(comm.TablePagodaRecord, newData)
|
||||||
|
// users := make([]*pb.DBPagodaRecord, 0)
|
||||||
|
// users = append(users, newData)
|
||||||
|
// var (
|
||||||
|
// pipe *pipe.RedisPipe = conn.Redis.RedisPipe(context.TODO())
|
||||||
|
// menbers []*redis.Z
|
||||||
|
// )
|
||||||
|
|
||||||
|
// menbers = make([]*redis.Z, 10)
|
||||||
|
// for i := 0; i < 10; i++ {
|
||||||
|
// uid += strconv.Itoa(i)
|
||||||
|
// menbers[i] = &redis.Z{Score: float64(i), Member: uid}
|
||||||
|
// }
|
||||||
|
|
||||||
|
// if cmd := pipe.ZAdd("pagodaList", menbers...); cmd != nil {
|
||||||
|
// this.module.Errorln(err)
|
||||||
|
|
||||||
|
// dock, err1 := cmd.Result()
|
||||||
|
// this.module.Errorln(dock, err1)
|
||||||
|
// }
|
||||||
|
// if _, err = pipe.Exec(); err != nil {
|
||||||
|
// this.module.Errorln(err)
|
||||||
|
// return
|
||||||
|
// }
|
||||||
|
// rd := pipe.ZRevRank("pagodaList", "dfmxf_6358f3f1375f6a340a12e2ab01234567")
|
||||||
|
// //rd := pipe.ZRange("pagodaList", 1, 5)
|
||||||
|
// if _, err = pipe.Exec(); err != nil {
|
||||||
|
// this.module.Errorln(err)
|
||||||
|
// return
|
||||||
|
// }
|
||||||
|
// _data3 := rd.Val()
|
||||||
|
// _data, err2 := rd.Result()
|
||||||
|
// this.module.Errorln(_data, err2, _data3)
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
// if !this.module.IsCross() {
|
// if !this.module.IsCross() {
|
||||||
// if conn, err := db.Cross(); err == nil {
|
// if conn, err := db.Cross(); err == nil {
|
||||||
// userinfo := this.module.ModuleUser.GetUser(session.GetUserId())
|
// userinfo := this.module.ModuleUser.GetUser(session.GetUserId())
|
||||||
|
@ -11,7 +11,7 @@ import (
|
|||||||
|
|
||||||
func (this *apiComp) CreateCheck(session comm.IUserSession, req *pb.UserCreateReq) (code pb.ErrorCode) {
|
func (this *apiComp) CreateCheck(session comm.IUserSession, req *pb.UserCreateReq) (code pb.ErrorCode) {
|
||||||
name := strings.TrimSpace(req.NickName)
|
name := strings.TrimSpace(req.NickName)
|
||||||
if name == "" || len(name) > 30 || req.Figure == 0 {
|
if name == "" || len(name) > 30 {
|
||||||
code = pb.ErrorCode_UserNickNameEmpty
|
code = pb.ErrorCode_UserNickNameEmpty
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user