This commit is contained in:
wh_zcy 2023-03-10 16:50:09 +08:00
parent d3952e521c
commit 8c29001e84
3 changed files with 51 additions and 35 deletions

View File

@ -50,9 +50,11 @@ func (this *apiComp) Rtest(session comm.IUserSession, req *pb.RtaskTestReq) (cod
this.moduleRtask.modelRtask.Change(rtask.Uid, update) this.moduleRtask.modelRtask.Change(rtask.Uid, update)
} else { } else {
if code = this.moduleRtask.SendToRtask(session, comm.TaskType(req.RtaskType), req.Params...); code != pb.ErrorCode_Success { this.moduleRtask.TriggerTask(session.GetUserId(), &comm.TaskParam{
rsp.Flag = false TT: comm.TaskType(req.RtaskType),
} Params: req.Params,
})
rsp.Flag = true
} }
if err := session.SendMsg(string(this.moduleRtask.GetType()), "rtest", rsp); err != nil { if err := session.SendMsg(string(this.moduleRtask.GetType()), "rtest", rsp); err != nil {

View File

@ -218,8 +218,24 @@ func (this *ModuleRtask) initRtaskVerifyHandle() {
} }
} }
func (this *ModuleRtask) processOneTask(uid string, rtaskType comm.TaskType, params ...int32) (code pb.ErrorCode) { // 处理触发的任务
func (this *ModuleRtask) processOneTask(session comm.IUserSession, rtaskType comm.TaskType, params ...int32) (code pb.ErrorCode) {
uid := session.GetUserId()
var condis []*rtaskCondi var condis []*rtaskCondi
if this.IsCross() {
//随机任务
if _, err := this.service.AcrossClusterRpcGo(
context.Background(),
session.GetServiecTag(),
comm.Service_Worker,
string(comm.Rpc_ModuleRtaskSendTask),
pb.RPCRTaskReq{Uid: uid, TaskType: int32(rtaskType), Param: params},
nil); err != nil {
this.Errorln(err)
}
return
}
for _, codiConf := range this.configure.getRtaskCondis(int32(rtaskType)) { for _, codiConf := range this.configure.getRtaskCondis(int32(rtaskType)) {
v, ok := this.handleMap[codiConf.Id] v, ok := this.handleMap[codiConf.Id]
if !ok { if !ok {
@ -244,7 +260,6 @@ func (this *ModuleRtask) processOneTask(uid string, rtaskType comm.TaskType, par
condis = append(condis, v) condis = append(condis, v)
} }
} }
session, _ := this.GetUserSession(uid)
// update // update
for _, v := range condis { for _, v := range condis {
@ -275,21 +290,6 @@ func (this *ModuleRtask) processOneTask(uid string, rtaskType comm.TaskType, par
if worldtask, ok := module.(comm.IWorldtask); ok { if worldtask, ok := module.(comm.IWorldtask); ok {
if err := worldtask.TaskcondNotify(session, conf.Id); err != nil { 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.Error("任务条件达成通知",
log.Field{Key: "uid", Value: uid}, log.Field{Key: "uid", Value: uid},
log.Field{Key: "condId", Value: conf.Id}, log.Field{Key: "condId", Value: conf.Id},
@ -297,8 +297,6 @@ func (this *ModuleRtask) processOneTask(uid string, rtaskType comm.TaskType, par
) )
} }
} }
}
}
}() }()
} }
userModule, err := this.service.GetModule(comm.ModuleUser) userModule, err := this.service.GetModule(comm.ModuleUser)
@ -311,7 +309,7 @@ func (this *ModuleRtask) processOneTask(uid string, rtaskType comm.TaskType, par
}() }()
// 公会 // 公会
if user, ok := userModule.(comm.IUser); ok { if user, ok := userModule.(comm.IUser); ok {
ex, err := user.GetUserExpand(session.GetUserId()) ex, err := user.GetUserExpand(uid)
if err == nil && ex.SociatyId != "" { if err == nil && ex.SociatyId != "" {
sociatyModule, err := this.service.GetModule(comm.ModuleSociaty) sociatyModule, err := this.service.GetModule(comm.ModuleSociaty)
if err != nil { if err != nil {
@ -326,11 +324,12 @@ func (this *ModuleRtask) processOneTask(uid string, rtaskType comm.TaskType, par
log.Field{Key: "err", Value: err2.Error()}, log.Field{Key: "err", Value: err2.Error()},
) )
} }
if module, err := this.service.GetModule(comm.ModuleRtask); err == nil { this.processOneTask(session, comm.Rtype156, 1)
if iRtask, ok := module.(comm.IRtask); ok { // if module, err := this.service.GetModule(comm.ModuleRtask); err == nil {
iRtask.SendToRtask(session, comm.Rtype156, 1) // if iRtask, ok := module.(comm.IRtask); ok {
} // iRtask.SendToRtask(session, comm.Rtype156, 1)
} // }
// }
} }
} }
} }
@ -343,6 +342,7 @@ func (this *ModuleRtask) processOneTask(uid string, rtaskType comm.TaskType, par
return return
} }
// Deprecated
func (this *ModuleRtask) SendToRtask(session comm.IUserSession, rtaskType comm.TaskType, params ...int32) (code pb.ErrorCode) { func (this *ModuleRtask) SendToRtask(session comm.IUserSession, rtaskType comm.TaskType, params ...int32) (code pb.ErrorCode) {
uid := session.GetUserId() uid := session.GetUserId()
if this.IsCross() { if this.IsCross() {
@ -490,6 +490,20 @@ func (this *ModuleRtask) SendToRtask(session comm.IUserSession, rtaskType comm.T
} }
func (this *ModuleRtask) TriggerTask(uid string, taskParams ...*comm.TaskParam) { func (this *ModuleRtask) TriggerTask(uid string, taskParams ...*comm.TaskParam) {
session, ok := this.GetUserSession(uid)
if !ok {
return
}
for _, tp := range taskParams {
if code := this.processOneTask(session, tp.TT, tp.Params...); code != pb.ErrorCode_Success {
this.Debug("任务处理",
log.Field{Key: "uid", Value: uid},
log.Field{Key: "taskType", Value: tp.TT},
log.Field{Key: "params", Value: tp.Params})
}
session.Push()
comm.PuttaskParam(tp)
}
return return
} }
@ -566,7 +580,7 @@ func (this *ModuleRtask) Rpc_ModuleRtaskSendTask(ctx context.Context, args *pb.R
err = fmt.Errorf("未查询到用户:%s在线信息!", args.Uid) err = fmt.Errorf("未查询到用户:%s在线信息!", args.Uid)
return return
} else { } else {
this.SendToRtask(session, comm.TaskType(args.TaskType), args.Param...) this.processOneTask(session, comm.TaskType(args.TaskType), args.Param...)
session.Push() session.Push()
} }
return return

View File

@ -123,7 +123,7 @@ func (this *apiComp) Create(session comm.IUserSession, req *pb.UserCreateReq) (c
} }
if req.Figure != 0 { if req.Figure != 0 {
this.module.ModuleRtask.SendToRtask(session, comm.Rtype72, 1) this.module.ModuleRtask.TriggerTask(uid,&comm.TaskParam{TT:comm.Rtype72,Params: []int32{1}})
} }
this.mail.SendMailByCid(session, comm.Welcomemail, nil) this.mail.SendMailByCid(session, comm.Welcomemail, nil)