活动开启通知
This commit is contained in:
parent
e3293d4313
commit
edc97360e5
@ -51,7 +51,8 @@ func (this *Activity) Start() (err error) {
|
||||
return
|
||||
}
|
||||
timer := time.NewTicker(time.Second * 1)
|
||||
this.LoadActivityData()
|
||||
this.LoadActivityData("")
|
||||
this.LoadActivityData("64ba8dc4510317d189b9624c")
|
||||
go func() {
|
||||
locp:
|
||||
for {
|
||||
@ -68,22 +69,64 @@ func (this *Activity) Start() (err error) {
|
||||
return
|
||||
}
|
||||
|
||||
func (this *Activity) LoadActivityData() {
|
||||
if c, err := this.DB.Find(core.SqlTable(this.TableName), bson.M{}); err != nil {
|
||||
return
|
||||
} else {
|
||||
this.hlock.Lock()
|
||||
defer this.hlock.Unlock()
|
||||
this.activity = make(map[pb.HdType]*pb.DBHuodong)
|
||||
for c.Next(context.Background()) {
|
||||
hd := &pb.DBHuodong{}
|
||||
if err = c.Decode(hd); err != nil {
|
||||
this.module.Errorf("err:%v", err)
|
||||
continue
|
||||
func (this *Activity) LoadActivityData(id string) {
|
||||
if id == "" { // 查所有的
|
||||
if c, err := this.DB.Find(core.SqlTable(this.TableName), bson.M{}); err != nil {
|
||||
return
|
||||
} else {
|
||||
this.hlock.Lock()
|
||||
defer this.hlock.Unlock()
|
||||
this.activity = make(map[pb.HdType]*pb.DBHuodong)
|
||||
for c.Next(context.Background()) {
|
||||
hd := &pb.DBHuodong{}
|
||||
if err = c.Decode(hd); err != nil {
|
||||
this.module.Errorf("err:%v", err)
|
||||
continue
|
||||
}
|
||||
this.activity[hd.Itype] = hd
|
||||
}
|
||||
}
|
||||
} else {
|
||||
var hd *pb.DBHuodong
|
||||
this.DB.FindOne(core.SqlTable(this.TableName), bson.M{"_id": id}).Decode(&hd)
|
||||
|
||||
this.hlock.Lock()
|
||||
if this.activity == nil {
|
||||
this.activity = make(map[pb.HdType]*pb.DBHuodong)
|
||||
}
|
||||
this.activity[hd.Itype] = hd
|
||||
this.hlock.Unlock()
|
||||
// rpc 通知
|
||||
if configure.Now().Unix() <= hd.Etime && configure.Now().Unix() >= hd.Stime {
|
||||
if err := this.service.RpcCall(
|
||||
context.Background(),
|
||||
comm.Service_Worker,
|
||||
string(comm.Rpc_ActivityStar),
|
||||
pb.RPCGeneralReqB1{
|
||||
Param1: "starActivity",
|
||||
Param2: []string{hd.Id},
|
||||
},
|
||||
nil,
|
||||
); err != nil {
|
||||
this.module.Errorln(err)
|
||||
}
|
||||
}
|
||||
if configure.Now().Unix() > hd.Etime {
|
||||
if err := this.service.RpcCall(
|
||||
context.Background(),
|
||||
comm.Service_Worker,
|
||||
string(comm.Rpc_ActivityOver),
|
||||
pb.RPCGeneralReqB1{
|
||||
Param1: "endActivity",
|
||||
Param2: []string{hd.Id},
|
||||
},
|
||||
nil,
|
||||
); err != nil {
|
||||
this.module.Errorln(err)
|
||||
}
|
||||
this.activity[hd.Itype] = hd
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func (this *Activity) CheckActivityData() {
|
||||
|
@ -98,8 +98,8 @@ func (this *Timer) getDBModelByUid(uid, tableName string) (model *db.DBModel, er
|
||||
}
|
||||
|
||||
// 重新加载活动数据
|
||||
func (this *Timer) ReloadActivityData() {
|
||||
this.activity.LoadActivityData()
|
||||
func (this *Timer) ReloadActivityData(id string) {
|
||||
this.activity.LoadActivityData(id)
|
||||
}
|
||||
|
||||
// 日志
|
||||
|
@ -45,5 +45,5 @@ func (this *Api_Comp) ActivityNotify(c *engine.Context) {
|
||||
Title: pb.ErrorCode_Success.ToString(),
|
||||
}
|
||||
// 通知更新活动
|
||||
this.module.modelweb.ReloadActivityData()
|
||||
this.module.modelweb.ReloadActivityData(req.Id)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user