From 5acf0521c4495b3f32488adf80b5c57b35aa5f4d Mon Sep 17 00:00:00 2001 From: wh_zcy Date: Fri, 10 Mar 2023 15:43:58 +0800 Subject: [PATCH] update --- comm/imodule.go | 2 +- modules/rtask/module.go | 83 +++++++++++++++++++++++++++++++++++++++-- 2 files changed, 80 insertions(+), 5 deletions(-) diff --git a/comm/imodule.go b/comm/imodule.go index 45d9c0ad2..4245e1446 100644 --- a/comm/imodule.go +++ b/comm/imodule.go @@ -214,7 +214,7 @@ type ( //任务触发 SendToRtask(session IUserSession, rtaskType TaskType, params ...int32) (code pb.ErrorCode) //任务批量触发 - TriggerTask(uid string, taskParams ...TaskParam) (code pb.ErrorCode) + TriggerTask(uid string, taskParams ...*TaskParam) // 获取任务条件记录 GetCondiData(uid string) *pb.DBRtaskRecord } diff --git a/modules/rtask/module.go b/modules/rtask/module.go index 3fe2f2acf..1b29f2ced 100644 --- a/modules/rtask/module.go +++ b/modules/rtask/module.go @@ -218,8 +218,7 @@ func (this *ModuleRtask) initRtaskVerifyHandle() { } } -func (this *ModuleRtask) processOneTask(session comm.IUserSession, rtaskType comm.TaskType, params ...int32) (code pb.ErrorCode) { - uid := session.GetUserId() +func (this *ModuleRtask) processOneTask(uid string, rtaskType comm.TaskType, params ...int32) (code pb.ErrorCode) { var condis []*rtaskCondi for _, codiConf := range this.configure.getRtaskCondis(int32(rtaskType)) { v, ok := this.handleMap[codiConf.Id] @@ -245,6 +244,7 @@ func (this *ModuleRtask) processOneTask(session comm.IUserSession, rtaskType com condis = append(condis, v) } } + session, _ := this.GetUserSession(uid) // update for _, v := range condis { @@ -262,7 +262,82 @@ func (this *ModuleRtask) processOneTask(session comm.IUserSession, rtaskType com } } - // + //任务完成则推送 + if code := this.CheckCondi(uid, conf.Id); code == pb.ErrorCode_Success { + module, err := this.service.GetModule(comm.ModuleWorldtask) + if err == nil { + go func() { + defer func() { + if r := recover(); r != nil { + log.Errorf("[worldtask ] err:%v ", r) + } + }() + + if worldtask, ok := module.(comm.IWorldtask); ok { + if err := worldtask.TaskcondNotify(session, conf.Id); err != nil { + var customErr = new(comm.CustomError) + if errors.As(err, &customErr) { + notifyErr := &pb.NotifyErrorNotifyPush{ + ReqMainType: string(comm.ModuleWorldtask), + ReqSubType: "finish", + Message: "", + } + + if customErr.Code == pb.ErrorCode_WorldtaskLvNotEnough { + notifyErr.Code = pb.ErrorCode_WorldtaskLvNotEnough + session.SendMsg(string(comm.ModuleWorldtask), "finish", notifyErr) + } else if customErr.Code == pb.ErrorCode_UserSessionNobeing { + notifyErr.Code = pb.ErrorCode_UserSessionNobeing + session.SendMsg(string(comm.ModuleWorldtask), "finish", notifyErr) + } else { + log.Error("任务条件达成通知", + log.Field{Key: "uid", Value: uid}, + log.Field{Key: "condId", Value: conf.Id}, + log.Field{Key: "err", Value: err.Error()}, + ) + } + } + } + } + }() + } + userModule, err := this.service.GetModule(comm.ModuleUser) + if err == nil { + go func() { + defer func() { //程序异常 收集异常信息传递给前端显示 + if r := recover(); r != nil { + log.Errorf("[sociatytask ] err:%v ", r) + } + }() + // 公会 + if user, ok := userModule.(comm.IUser); ok { + ex, err := user.GetUserExpand(session.GetUserId()) + if err == nil && ex.SociatyId != "" { + sociatyModule, err := this.service.GetModule(comm.ModuleSociaty) + if err != nil { + return + } + if sociaty, ok := sociatyModule.(comm.ISociaty); ok { + if err2 := sociaty.TaskcondNotify(uid, ex.SociatyId, conf.Id); err2 != nil { + log.Error("公会任务条件达成通知", + log.Field{Key: "uid", Value: uid}, + log.Field{Key: "sociatyId", Value: ex.SociatyId}, + log.Field{Key: "condId", Value: conf.Id}, + log.Field{Key: "err", Value: err2.Error()}, + ) + } + if module, err := this.service.GetModule(comm.ModuleRtask); err == nil { + if iRtask, ok := module.(comm.IRtask); ok { + iRtask.SendToRtask(session, comm.Rtype156, 1) + } + } + } + } + } + }() + } + } + } return @@ -414,7 +489,7 @@ func (this *ModuleRtask) SendToRtask(session comm.IUserSession, rtaskType comm.T return } -func (this *ModuleRtask) TriggerTask(uid string, taskParams ...comm.TaskParam) (code pb.ErrorCode) { +func (this *ModuleRtask) TriggerTask(uid string, taskParams ...*comm.TaskParam) { return }