From edc97360e550a45fda7438ac04163d8fbef24537 Mon Sep 17 00:00:00 2001 From: meixiongfeng <766881921@qq.com> Date: Thu, 28 Sep 2023 11:13:05 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B4=BB=E5=8A=A8=E5=BC=80=E5=90=AF=E9=80=9A?= =?UTF-8?q?=E7=9F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/timer/activity.go | 71 +++++++++++++++++++++++++------ modules/timer/module.go | 4 +- modules/web/api_activitynotify.go | 2 +- 3 files changed, 60 insertions(+), 17 deletions(-) diff --git a/modules/timer/activity.go b/modules/timer/activity.go index a1e39809b..732e249a9 100644 --- a/modules/timer/activity.go +++ b/modules/timer/activity.go @@ -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() { diff --git a/modules/timer/module.go b/modules/timer/module.go index fa83a4a90..518375678 100644 --- a/modules/timer/module.go +++ b/modules/timer/module.go @@ -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) } // 日志 diff --git a/modules/web/api_activitynotify.go b/modules/web/api_activitynotify.go index e1e6f24ab..df2a706eb 100644 --- a/modules/web/api_activitynotify.go +++ b/modules/web/api_activitynotify.go @@ -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) }