This commit is contained in:
wh_zcy 2023-03-30 20:37:59 +08:00
parent 5e96e588f8
commit 707934fbef
5 changed files with 25 additions and 239 deletions

View File

@ -211,8 +211,6 @@ type (
RemoveCondi(uid string, condiId int32) error
// 更新任务条件数据
ChangeCondi(uid string, data map[int32]*pb.RtaskData) error
//任务触发
SendToRtask(session IUserSession, rtaskType TaskType, params ...int32) (code pb.ErrorCode)
//任务批量触发
TriggerTask(uid string, taskParams ...*TaskParam)
// 获取任务条件记录

View File

@ -94,8 +94,12 @@ func (this *ModelRtask) checkCondi(uid string, condiId int32) (err error, ok boo
var condi *rtaskCondi
cond, ok := this.moduleRtask.handleMap.Load(condiId)
if !ok {
errors.Errorf("condiID: %v handle no found", condiId)
return
rcs := this.moduleRtask.getHandle(comm.TaskType(conf.Type))
for _, v:=range rcs {
if v.condId == condiId {
cond = v
}
}
}
if condi, ok = cond.(*rtaskCondi); !ok {

View File

@ -45,9 +45,7 @@ type ModuleRtask struct {
}
func NewModule() core.IModule {
return &ModuleRtask{
// handleMap: make(map[int32]*rtaskCondi),
}
return &ModuleRtask{}
}
func (this *ModuleRtask) GetType() core.M_Modules {
@ -57,7 +55,6 @@ func (this *ModuleRtask) GetType() core.M_Modules {
func (this *ModuleRtask) Init(service core.IService, module core.IModule, options core.IModuleOptions) (err error) {
err = this.ModuleBase.Init(service, module, options)
this.service = service.(base.IRPCXService)
// this.initRtaskVerifyHandle()
return
}
func (this *ModuleRtask) Start() (err error) {
@ -260,145 +257,6 @@ func (this *ModuleRtask) getHandle(tt comm.TaskType) (condis []*rtaskCondi) {
return
}
// 条件校验初始
// Deprecated
func (this *ModuleRtask) initRtaskVerifyHandle() {
conf, err := this.configure.getRtaskCondiCfg()
if err != nil {
return
}
for _, v := range conf.GetDataList() {
if typeCfg, err := this.configure.getRtaskTypeById(v.Id); err == nil {
if typeCfg != nil {
switch comm.TaskType(typeCfg.Type) {
case comm.Rtype1:
this.registerVerifyHandle(v.Id, &rtaskCondi{
find: this.modelRtaskRecord.equalFirstParam,
verify: this.modelRtask.verfiyRtype1,
update: this.modelRtaskRecord.overrideUpdate,
})
case comm.Rtype2:
this.registerVerifyHandle(v.Id, &rtaskCondi{
find: this.modelRtaskRecord.equalFirstParam,
verify: this.modelRtask.verifyRtype2,
update: this.modelRtaskRecord.overrideUpdate,
})
case comm.Rtype3:
this.registerVerifyHandle(v.Id, &rtaskCondi{
find: this.modelRtaskRecord.equalFirstParam,
verify: this.modelRtask.verifyRtype3,
update: this.modelRtaskRecord.overrideUpdate,
})
case comm.Rtype4:
this.registerVerifyHandle(v.Id, &rtaskCondi{
find: this.modelRtaskRecord.equalFirstParam,
verify: this.modelRtask.verifyRtype4,
update: this.modelRtaskRecord.overrideUpdate,
})
case comm.Rtype5:
this.registerVerifyHandle(v.Id, &rtaskCondi{
find: this.modelRtaskRecord.equalFirstParam,
verify: this.modelRtask.verifyRtype5,
update: this.modelRtaskRecord.overrideUpdate,
})
case comm.Rtype6:
this.registerVerifyHandle(v.Id, &rtaskCondi{
find: this.modelRtaskRecord.equalFirstParam,
verify: this.modelRtask.verifyRtype6,
update: this.modelRtaskRecord.overrideUpdate,
})
case comm.Rtype8:
this.registerVerifyHandle(v.Id, &rtaskCondi{
find: this.modelRtaskRecord.equalFirstParam,
verify: this.modelRtask.verfiyRtype8,
update: this.modelRtaskRecord.overrideUpdate,
})
case comm.Rtype9:
this.registerVerifyHandle(v.Id, &rtaskCondi{
find: this.modelRtaskRecord.equalFirstParam,
verify: this.modelRtask.verfiyRtype9,
update: this.modelRtaskRecord.overrideUpdate,
})
case comm.Rtype10:
this.registerVerifyHandle(v.Id, &rtaskCondi{
find: this.modelRtaskRecord.equalFirstParam,
verify: this.modelRtask.verfiyRtype10,
update: this.modelRtaskRecord.overrideUpdate,
})
case comm.Rtype11, comm.Rtype84, comm.Rtype85:
this.registerVerifyHandle(v.Id, &rtaskCondi{
find: this.modelRtaskRecord.lessEqualFirstParam,
verify: this.modelRtaskRecord.verifyFirstGreatEqualParam,
update: this.modelRtaskRecord.overrideUpdate,
})
case comm.Rtype18:
this.registerVerifyHandle(v.Id, &rtaskCondi{
find: this.modelRtaskRecord.greatEqualFirstParam,
verify: this.modelRtaskRecord.verifyFirstGreatEqualParam,
update: this.modelRtaskRecord.addUpdate,
})
case comm.Rtype7, comm.Rtype12, comm.Rtype13, comm.Rtype14, comm.Rtype15,
comm.Rtype19, comm.Rtype21, comm.Rtype24,
comm.Rtype26, comm.Rtype27, comm.Rtype28, comm.Rtype38,
comm.Rtype39, comm.Rtype50, comm.Rtype51, comm.Rtype53,
comm.Rtype54, comm.Rtype57, comm.Rtype58, comm.Rtype60,
comm.Rtype62, comm.Rtype64, comm.Rtype69, comm.Rtype72, comm.Rtype88, comm.Rtype104,
comm.Rtype96, comm.Rtype105, comm.Rtype128, comm.Rtype130, comm.Rtype131,
comm.Rtype141, comm.Rtype142, comm.Rtype143, comm.Rtype144, comm.Rtype145, comm.Rtype146,
comm.Rtype147, comm.Rtype149, comm.Rtype153, comm.Rtype154, comm.Rtype155, comm.Rtype156:
this.registerVerifyHandle(v.Id, &rtaskCondi{
find: this.modelRtaskRecord.lessEqualFirstParam,
verify: this.modelRtaskRecord.verifyFirstGreatEqualParam,
update: this.modelRtaskRecord.addUpdate,
})
case comm.Rtype20:
this.registerVerifyHandle(v.Id, &rtaskCondi{
find: this.modelRtaskRecord.equalFirstParam,
verify: this.modelRtask.verifyRtype20,
update: this.modelRtaskRecord.overrideUpdate,
})
case comm.Rtype22, comm.Rtype109:
this.registerVerifyHandle(v.Id, &rtaskCondi{
find: this.modelRtaskRecord.equalFirstParam,
verify: this.modelRtaskRecord.verifyFirstEqualParam,
update: this.modelRtaskRecord.overrideUpdate,
})
case comm.Rtype63:
this.registerVerifyHandle(v.Id, &rtaskCondi{
find: this.modelRtaskRecord.equalFirstParam,
verify: this.modelRtask.verifyRtype63,
update: this.modelRtaskRecord.addUpdate,
})
case comm.Rtype16, comm.Rtype17,
comm.Rtype35, comm.Rtype44,
comm.Rtype59, comm.Rtype61, comm.Rtype70:
this.registerVerifyHandle(v.Id, &rtaskCondi{
find: this.modelRtaskRecord.equalParams,
verify: this.modelRtaskRecord.verifyFromDb,
update: this.modelRtaskRecord.overrideUpdate,
})
case comm.Rtype23, comm.Rtype25, comm.Rtype29, comm.Rtype30, comm.Rtype31,
comm.Rtype32, comm.Rtype33, comm.Rtype34, comm.Rtype36,
comm.Rtype37, comm.Rtype40, comm.Rtype41,
comm.Rtype42, comm.Rtype43, comm.Rtype45,
comm.Rtype46, comm.Rtype47, comm.Rtype48, comm.Rtype49,
comm.Rtype52, comm.Rtype55, comm.Rtype56,
comm.Rtype65, comm.Rtype66, comm.Rtype67, comm.Rtype68, comm.Rtype140:
this.registerVerifyHandle(v.Id, &rtaskCondi{
find: this.modelRtaskRecord.lessThanParams,
verify: this.modelRtaskRecord.verifyFromDb,
update: this.modelRtaskRecord.addUpdate,
})
default:
log.Warnf("rtaskType[%v] not register", typeCfg.Type)
}
}
}
}
}
// 处理触发的任务
func (this *ModuleRtask) processOneTask(session comm.IUserSession, rtaskType comm.TaskType, params ...int32) (code pb.ErrorCode) {
uid := session.GetUserId()
@ -481,80 +339,6 @@ func (this *ModuleRtask) processOneTask(session comm.IUserSession, rtaskType com
return
}
// Deprecated
func (this *ModuleRtask) SendToRtask(session comm.IUserSession, rtaskType comm.TaskType, params ...int32) (code pb.ErrorCode) {
uid := session.GetUserId()
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
}
this.Debug("任务事件触发",
log.Field{Key: "uid", Value: uid},
log.Field{Key: "taskType", Value: rtaskType},
log.Field{Key: "params", Value: params},
)
var (
condis []*rtaskCondi
)
condis = this.getHandle(rtaskType)
// for _, codiConf := range this.configure.getRtaskCondis(int32(rtaskType)) {
// v, ok := this.handleMap[codiConf.Id]
// if !ok {
// this.Warn("未注册事件处理器",
// log.Field{Key: "uid", Value: uid},
// log.Field{Key: "condiId", Value: codiConf.Id},
// )
// code = pb.ErrorCode_RtaskCondiNoFound
// return
// }
// if v.find == nil {
// this.Warn("未设置find Handle",
// log.Field{Key: "uid", Value: uid},
// log.Field{Key: "condiId", Value: codiConf.Id},
// )
// return
// }
// if condiId, _ := v.find(codiConf, params...); condiId != 0 {
// v.condId = codiConf.Id
// condis = append(condis, v)
// }
// }
// update
for _, v := range condis {
conf, err := this.configure.getRtaskTypeById(v.condId)
if err != nil {
log.Errorf("get condId conf err:%v", err)
code = pb.ErrorCode_RtaskCondiNoFound
return
}
if v.update != nil {
if err := v.update(uid, conf, params...); err != nil {
log.Errorf("update task:%v", err)
code = pb.ErrorCode_DBError
}
}
}
return
}
func (this *ModuleRtask) TriggerTask(uid string, taskParams ...*comm.TaskParam) {
this.Debug("任务处理",
log.Field{Key: "uid", Value: uid},

View File

@ -17,9 +17,7 @@ func (this *apiComp) SendCheck(session comm.IUserSession, req *pb.TaskSendReq) (
func (this *apiComp) Send(session comm.IUserSession, req *pb.TaskSendReq) (code pb.ErrorCode, data proto.Message) {
if imodule, err := this.service.GetModule(comm.ModuleRtask); err == nil {
if itask, ok := imodule.(comm.IRtask); ok {
if code = itask.SendToRtask(session, comm.TaskType(req.TaskType), req.Params...); code != pb.ErrorCode_Success {
return
}
itask.TriggerTask(session.GetUserId(), comm.GettaskParam(comm.TaskType(req.TaskType), req.Params...))
}
}

View File

@ -70,7 +70,7 @@ func (this *apiComp) Finish(session comm.IUserSession, req *pb.WorldtaskFinishRe
return
}
updateCheckCond := func(nextTaskId int32) *pb.DBWorldtask {
updateCheckCond := func(userTask *pb.DBWorldtask, nextTaskId int32) *pb.DBWorldtask {
//检查下个任务的完成条件
nextTaskConf, err := this.module.configure.getWorldtaskById(nextTaskId)
if err != nil || curTaskConf == nil {
@ -85,13 +85,16 @@ func (this *apiComp) Finish(session comm.IUserSession, req *pb.WorldtaskFinishRe
userTask.CurrentTask = make(map[int32]*pb.Worldtask)
}
if len(nextTaskConf.Completetask) == 1 && nextTaskConf.Completetask[0] == 0 {
update := make(map[string]interface{})
if (len(nextTaskConf.Completetask) == 1 && nextTaskConf.Completetask[0] == 0) ||
len(nextTaskConf.Completetask) == 0 {
wt := &pb.Worldtask{
TaskId: nextTaskId,
TaskType: nextTaskConf.Des,
CondiIds: []int32{},
}
userTask.CurrentTask[nextTaskConf.Group] = wt
update["currentTask"] = userTask.CurrentTask
} else {
for _, condiId := range nextTaskConf.Completetask {
if condiId == 0 {
@ -105,9 +108,8 @@ func (this *apiComp) Finish(session comm.IUserSession, req *pb.WorldtaskFinishRe
log.Field{Key: "uid", Value: uid},
log.Field{Key: "taskId", Value: nextTaskId},
log.Field{Key: "condiId", Value: condiId},
)
rsp.CondiId = condiId
rsp.TaskId = nextTaskId
)
} else {
nwt, ok := userTask.CurrentTask[nextTaskConf.Group]
if ok {
@ -121,19 +123,19 @@ func (this *apiComp) Finish(session comm.IUserSession, req *pb.WorldtaskFinishRe
}
}
userTask.CurrentTask[nextTaskConf.Group] = nwt
update["currentTask"] = userTask.CurrentTask
}
}
}
}
}
update := map[string]interface{}{
"currentTask": userTask.CurrentTask,
}
if err := this.module.modelWorldtask.Change(uid, update); err != nil {
code = pb.ErrorCode_DBError
return nil
if len(update) > 0 {
if err := this.module.modelWorldtask.Change(uid, update); err != nil {
code = pb.ErrorCode_DBError
return nil
}
}
return userTask
@ -145,9 +147,9 @@ func (this *apiComp) Finish(session comm.IUserSession, req *pb.WorldtaskFinishRe
nextTask := make(map[int32]*pb.Worldtask)
for _, next := range nextTaskIds {
userTask = updateCheckCond(next)
if userTask != nil {
for k, v := range userTask.CurrentTask {
ut := updateCheckCond(userTask, next)
if ut != nil {
for k, v := range ut.CurrentTask {
nextTask[k] = &pb.Worldtask{
TaskId: v.TaskId,
}