diff --git a/cmd/v2/ui/views/rtask_testview.go b/cmd/v2/ui/views/rtask_testview.go index b11abeb57..4d817abf0 100644 --- a/cmd/v2/ui/views/rtask_testview.go +++ b/cmd/v2/ui/views/rtask_testview.go @@ -15,6 +15,7 @@ import ( "path/filepath" "strings" "sync" + "sync/atomic" cfg "go_dreamfactory/sys/configure/structs" @@ -29,7 +30,7 @@ import ( type RtaskTestView struct { BaseformView itemList *common.ItemList - resultCount int //结果条数 + resultCount int32 //结果条数 resultChan chan string //结果内容 flag bool msgs []string @@ -103,7 +104,6 @@ func (this *RtaskTestView) CreateView(t *model.TestCase) fyne.CanvasObject { if tb, err := cfg.NewTables(commCfg.Loader); err == nil { for _, v := range tb.RdtaskCondi.GetDataList() { wg.Add(1) - this.resultCount++ params := []int32{v.Data1, v.Data2, v.Data3, v.Data4, v.Data5} var p []int32 for _, v := range params { @@ -128,38 +128,46 @@ func (this *RtaskTestView) CreateView(t *model.TestCase) fyne.CanvasObject { // msgs = append(msgs, fmt.Sprintf("condId:%v rtype:%v params:%v", condId, rtype, p)) }(v.Id, v.Type, p) wg.Wait() - // time.Sleep(time.Millisecond * 100) } } go func() { for msg := range this.resultChan { + // logrus.Debug("add msg") this.msgs = append(this.msgs, msg) + // old := atomic.LoadInt32(&this.resultCount) + // n := old - 1 + // if atomic.CompareAndSwapInt32(&this.resultCount, old, n) { + // break + // } } }() go func() { var flag bool - for this.resultCount == 0 && flag { - logrus.Debug("结束") + for !flag { + count := atomic.LoadInt32(&this.resultCount) + logrus.Debug("count:", count) + if count == 100 { + logrus.Debug("结束") + record := strings.Join(this.msgs, "\n") + var buf bytes.Buffer + buf.WriteString(fmt.Sprintf("---任务参数测试报告---\n")) + buf.WriteString(record) + buf.WriteString("\n-------") - record := strings.Join(this.msgs, "\n") - var buf bytes.Buffer - buf.WriteString(fmt.Sprintf("---任务参数测试报告---\n")) - buf.WriteString(record) - buf.WriteString("\n-------") + file, err := os.OpenFile(filepath.Join(this.reportPath, "report.txt"), os.O_TRUNC|os.O_CREATE, os.ModePerm) + if err != nil { + logrus.Error(err) + } + defer file.Close() - file, err := os.OpenFile(filepath.Join(this.reportPath, "report.txt"), os.O_TRUNC|os.O_CREATE, os.ModePerm) - if err != nil { - logrus.Error(err) + if _, err := file.WriteString(buf.String()); err != nil { + logrus.Error(err) + } + flag = true } - defer file.Close() - - if _, err := file.WriteString(buf.String()); err != nil { - logrus.Error(err) - } - flag = true } }() } @@ -223,12 +231,12 @@ func (this *RtaskTestView) rtestListener() { return } - // if !rsp.Flag { msg := fmt.Sprintf("%v - %v", rsp.RtaskType, rsp.Flag) this.resultChan <- msg - this.resultCount-- - // } + atomic.AddInt32(&this.resultCount, 1) + + logrus.Debug("resp", msg) } }, }) diff --git a/modules/rtask/api_tasktest.go b/modules/rtask/api_tasktest.go index 9fb12b7d9..4eb08f444 100644 --- a/modules/rtask/api_tasktest.go +++ b/modules/rtask/api_tasktest.go @@ -13,7 +13,7 @@ func (this *apiComp) RtestCheck(session comm.IUserSession, req *pb.RtaskTestReq) } func (this *apiComp) Rtest(session comm.IUserSession, req *pb.RtaskTestReq) (code pb.ErrorCode, data *pb.ErrorData) { - rsp := &pb.RtaskTestResp{Flag: true} + rsp := &pb.RtaskTestResp{Flag: true,RtaskType: req.RtaskType} if req.CondiId != 0 { if code = this.moduleRtask.CheckCondi(session.GetUserId(), req.CondiId); code != pb.ErrorCode_Success { rsp.Flag = false @@ -44,7 +44,6 @@ func (this *apiComp) Rtest(session comm.IUserSession, req *pb.RtaskTestReq) (cod } this.moduleRtask.modelRtask.Change(rtask.Uid, update) - } else { this.moduleRtask.TriggerTask(session.GetUserId(), &comm.TaskParam{ TT: comm.TaskType(req.RtaskType), diff --git a/modules/rtask/module.go b/modules/rtask/module.go index cca776d18..d43a8e4b1 100644 --- a/modules/rtask/module.go +++ b/modules/rtask/module.go @@ -303,17 +303,17 @@ func (this *ModuleRtask) processOneTask(session comm.IUserSession, rtaskType com } } condIds = append(condIds, handle.condId) + + update := map[string]interface{}{ + "vals": record.Vals, + } + + this.modelRtaskRecord.Change(uid, update) } } } - update := map[string]interface{}{ - "vals": record.Vals, - } - - this.modelRtaskRecord.Change(uid, update) - for _, condId := range condIds { if code = this.CheckCondi(uid, condId, params...); code == pb.ErrorCode_Success { module, err := this.service.GetModule(comm.ModuleWorldtask) @@ -392,6 +392,13 @@ func (this *ModuleRtask) CheckCondi(uid string, condiId int32, params ...int32) code = pb.ErrorCode_DataNotFound return } + if len(params) == 0 { + if v, ok := record.Vals[condiId]; ok { + for _, p := range v.Data { + params = append(params, p) + } + } + } if _, ok := this.modelRtask.checkCondi(uid, condiId, record, params...); !ok { code = pb.ErrorCode_RtaskCondiNoReach return diff --git a/modules/rtask/verifyHandle.go b/modules/rtask/verifyHandle.go index 4c3d5cfe3..7958ae31a 100644 --- a/modules/rtask/verifyHandle.go +++ b/modules/rtask/verifyHandle.go @@ -14,19 +14,10 @@ import ( // five params (1-GreatEqual 2-equal 3-equal 4-equal 5-equal) func (this *ModelRtaskRecord) verifyGreatEqual(uid string, record *pb.DBRtaskRecord, cfg *cfg.GameRdtaskCondiData, params ...int32) (ok bool, count int32, err error) { - if record == nil { - err = errors.WithMessagef(err, "玩家数据DBRtaskRecord空") + if len(params) == 0 { + err = errors.New("玩家参数数据缺失") return } - - if v, f := record.Vals[cfg.Id]; f { - if len(v.Data) == 0 { - err = errors.WithMessagef(err, "玩家参数数据缺失 %v", v.Data) - return - } - params = toArr(v.Data) - } - var paramLen int if paramLen, err = lenParam(cfg, params...); err == nil { //参数比较,默认第一个参数soGreateEqual,其它soEqual @@ -88,9 +79,7 @@ func (this *ModelRtaskRecord) verifyGreatEqual(uid string, record *pb.DBRtaskRec // firstParam (first-Equal) func (this *ModelRtaskRecord) verifyFirstEqualParam(uid string, record *pb.DBRtaskRecord, cfg *cfg.GameRdtaskCondiData, params ...int32) (ok bool, count int32, err error) { - if len(params) == 1 { - ok, err = soEqual(params[0], cfg.Data1) } @@ -107,7 +96,10 @@ func (this *ModelRtaskRecord) verifyFirstGreatEqualParam(uid string, record *pb. // three params (first-greatEqual second-equal third-lessEqual) func (this *ModelRtaskRecord) verifyThirdLessEqualParam(uid string, record *pb.DBRtaskRecord, cfg *cfg.GameRdtaskCondiData, params ...int32) (ok bool, count int32, err error) { - + if len(params) == 0 { + err = errors.New("玩家参数数据缺失") + return + } var paramLen int if paramLen, err = lenParam(cfg, params...); err == nil { //参数比较,默认第一个参数soGreateEqual,其它soEqual @@ -139,6 +131,10 @@ func (this *ModelRtaskRecord) verifyThirdLessEqualParam(uid string, record *pb.D // three params (first-greatEqual second-equal third-greatEqual) func (this *ModelRtaskRecord) verifyThirdGreatEqualParam(uid string, record *pb.DBRtaskRecord, cfg *cfg.GameRdtaskCondiData, params ...int32) (ok bool, count int32, err error) { + if len(params) == 0 { + err = errors.New("玩家参数数据缺失") + return + } var paramLen int if paramLen, err = lenParam(cfg, params...); err == nil { //参数比较,默认第一个参数soGreateEqual,其它soEqual @@ -170,6 +166,10 @@ func (this *ModelRtaskRecord) verifyThirdGreatEqualParam(uid string, record *pb. // two params(first-Great second-Equal) func (this *ModelRtaskRecord) veriftyFirstGreatParam(uid string, record *pb.DBRtaskRecord, cfg *cfg.GameRdtaskCondiData, params ...int32) (ok bool, count int32, err error) { + if len(params) == 0 { + err = errors.New("玩家参数数据缺失") + return + } var paramLen int if paramLen, err = lenParam(cfg, params...); err == nil { //参数比较,默认第一个参数soGreateEqual,其它soEqual