diff --git a/modules/atlas/module.go b/modules/atlas/module.go index f36b87f06..b7e646bba 100644 --- a/modules/atlas/module.go +++ b/modules/atlas/module.go @@ -47,7 +47,8 @@ func (this *PandaAtlas) OnInstallComp() { func (this *PandaAtlas) CheckActivatePandaAtlasCollect(uid string, id string) { conf := this.configure.GetPandoAtlasConf(id) - if conf != nil { + if conf == nil { + this.Errorf("GetPandoAtlasConf err:%d", id) return } if this.IsCross() { diff --git a/modules/dispatch/api_refresh.go b/modules/dispatch/api_refresh.go index b63aedac0..6469fa2e7 100644 --- a/modules/dispatch/api_refresh.go +++ b/modules/dispatch/api_refresh.go @@ -63,7 +63,7 @@ func (a *apiComp) Refresh(session comm.IUserSession, req *pb.DispatchRefreshReq) return } - a.module.Debug("刷新", log.Field{Key: "taskIds", Value: taskIds}) + // a.module.Debug("刷新", log.Field{Key: "taskIds", Value: taskIds}) //更新公告任务 if err := a.module.modelDispatch.updateTasks(session.GetUserId(), d.Nb, taskIds); err != nil { a.module.Debug("更新公告失败", log.Field{Key: "uid", Value: session.GetUserId()}) diff --git a/modules/dispatch/model_dispatch.go b/modules/dispatch/model_dispatch.go index bf1d392ca..4302cc861 100644 --- a/modules/dispatch/model_dispatch.go +++ b/modules/dispatch/model_dispatch.go @@ -79,7 +79,7 @@ func (this *modelDispatch) getDBDispatch(uid string) (dis *pb.DBDispatch) { } // 获取随机任务ID -func (this *modelDispatch) getTasksWeight(uid string, d *pb.DBDispatch) int32 { +func (this *modelDispatch) getTasksWeight(d *pb.DBDispatch) int32 { if d == nil { return 0 } @@ -120,40 +120,9 @@ func (this *modelDispatch) taskRandom(uid string, dispatch *pb.DBDispatch) (task var n int n = len(dispatch.Nb.Tasks) - var existIds []int32 - for _, v := range dispatch.Nb.Tasks { - existIds = append(existIds, v.TaskId) - } - if n == 0 { - //随机6个任务 - total := 0 - for total < 6 { - tId := this.getTasksWeight(uid, dispatch) - if tId == 0 { - return - } - - //去重 - if _, ok := utils.Findx(existIds, int32(tId)); !ok { - existIds = append(existIds, int32(tId)) - total++ - } - - } - - for _, id := range existIds { - taskConf, err := this.module.configure.getDispatchTaskConf(int32(id)) - if err != nil { - continue - } - //公告持续截至时间 - duration := configure.Now().Unix() + int64(taskConf.Taskcd) - tasks = append(tasks, &pb.DispatchTask{ - TaskId: int32(id), - Duration: duration, - }) - } + //随机任务 + tasks = this.randomTask(dispatch, NOTICE_NUM) } else { var randCount int for i := 0; i < len(dispatch.Nb.Tasks); i++ { @@ -166,97 +135,107 @@ func (this *modelDispatch) taskRandom(uid string, dispatch *pb.DBDispatch) (task } } //追加随机 - tasks = append(tasks, this.addRandomTask(uid, dispatch, randCount)...) + tasks = append(tasks, this.addRandomTask(dispatch, randCount)...) } return } -func (this *modelDispatch) addRandomTask(uid string, dispatch *pb.DBDispatch, n int) (tasks []*pb.DispatchTask) { +func (this *modelDispatch) randomTask(dispatch *pb.DBDispatch, n int) (tasks []*pb.DispatchTask) { + total := 0 + for total < n { + rid := this.getTasksWeight(dispatch) + if rid == 0 { + return nil + } + if len(dispatch.Nb.Tasks) == 0 { + dispatch.Nb.Tasks = append(dispatch.Nb.Tasks, &pb.DispatchTask{ + TaskId: rid, + }) + total++ + } else { + //去重 + exist := false + for _, v := range dispatch.Nb.Tasks { + if v.TaskId == rid { + exist = true + } + } + if !exist { + dispatch.Nb.Tasks = append(dispatch.Nb.Tasks, &pb.DispatchTask{ + TaskId: rid, + }) + total++ + } + } + + } + + //更新任务持续截至时间 + for _, task := range dispatch.Nb.Tasks { + taskConf, err := this.module.configure.getDispatchTaskConf(task.TaskId) + if err != nil { + return nil + } + + if task.Duration == 0 { + duration := configure.Now().Unix() + int64(taskConf.Taskcd) + task.Duration = duration + } + tasks = append(tasks, task) + } + + return +} + +func (this *modelDispatch) addRandomTask(dispatch *pb.DBDispatch, n int) (tasks []*pb.DispatchTask) { if n <= 0 { tasks = dispatch.Nb.Tasks return } - var existIds []int32 - for _, v := range dispatch.Nb.Tasks { - existIds = append(existIds, v.TaskId) - } - - total := 0 - - for total < n { - rid := this.getTasksWeight(uid, dispatch) - if rid == 0 { - return nil - } - //去重 - if _, ok := utils.Findx(existIds, int32(rid)); !ok { - existIds = append(existIds, int32(rid)) - total++ - } - } - - for _, id := range existIds { - taskConf, err := this.module.configure.getDispatchTaskConf(int32(id)) - if err != nil { - return nil - } - - //公告持续截至时间 - duration := configure.Now().Unix() + int64(taskConf.Taskcd) - dt := &pb.DispatchTask{ - TaskId: int32(id), - Duration: duration, - } - tasks = append(tasks, dt) - } - - return + return this.randomTask(dispatch, n) } // 替换指定的已完成任务 func (this *modelDispatch) replaceTask(uid string, taskId int32, dispatch *pb.DBDispatch) (tasks []*pb.DispatchTask, oldTask *pb.DispatchTask) { - tasks = dispatch.Nb.Tasks var randCount int - for i := 0; i < len(tasks); i++ { + for i := 0; i < len(dispatch.Nb.Tasks); i++ { //替换状态是完成的任务 - if tasks[i].Status == 2 { - if taskId != tasks[i].TaskId { + if dispatch.Nb.Tasks[i].Status == 2 { + if taskId != dispatch.Nb.Tasks[i].TaskId { continue } - oldTask = tasks[i] + oldTask = dispatch.Nb.Tasks[i] //删除 - tasks = append(tasks[:i], tasks[i+1:]...) + dispatch.Nb.Tasks = append(dispatch.Nb.Tasks[:i], dispatch.Nb.Tasks[i+1:]...) i-- randCount++ break } } - tasks = append(tasks, this.addRandomTask(uid, dispatch, randCount)...) - + tasks = append(tasks, this.addRandomTask(dispatch, randCount)...) return } // 替换所有完成的任务 func (this *modelDispatch) replaceFinishedTask(uid string, dispatch *pb.DBDispatch) (tasks []*pb.DispatchTask, oldtasks []*pb.DispatchTask) { var randCount int - tmp := dispatch.Nb.Tasks - for i := 0; i < len(tmp); i++ { + for i := 0; i < len(dispatch.Nb.Tasks); i++ { //替换状态是完成的任务 - if tmp[i].Status == 2 { + if dispatch.Nb.Tasks[i].Status == 2 { //删除 - oldtasks = append(oldtasks, tmp[i]) + oldtasks = append(oldtasks, dispatch.Nb.Tasks[i]) dispatch.Nb.Tasks = append(dispatch.Nb.Tasks[:i], dispatch.Nb.Tasks[i+1:]...) i-- randCount++ } else { - tasks = append(tasks, tmp[i]) + tasks = append(tasks, dispatch.Nb.Tasks[i]) } } - tasks = append(tasks, this.addRandomTask(uid, dispatch, randCount)...) + tasks = append(tasks, this.addRandomTask(dispatch, randCount)...) return } @@ -420,9 +399,9 @@ func (this *modelDispatch) updateNotice(uid string, dispatch *pb.DBDispatch) err //刷新任务 count := len(dispatch.Nb.Tasks) - if count < 6 { - randCount = 6 - count - dispatch.Nb.Tasks = append(dispatch.Nb.Tasks, this.addRandomTask(uid, dispatch, randCount)...) + if count < NOTICE_NUM { + randCount = NOTICE_NUM - count + dispatch.Nb.Tasks = append(dispatch.Nb.Tasks, this.addRandomTask(dispatch, randCount)...) } //判断是否有下一等级 diff --git a/modules/dispatch/module.go b/modules/dispatch/module.go index 444974531..6469e9aac 100644 --- a/modules/dispatch/module.go +++ b/modules/dispatch/module.go @@ -6,6 +6,9 @@ import ( "go_dreamfactory/modules" ) +// 默认6条公告数量 +const NOTICE_NUM int = 6 + // 派遣 type Dispatch struct { modules.ModuleBase diff --git a/modules/rtask/module.go b/modules/rtask/module.go index 2db168aa3..cbf07b1a7 100644 --- a/modules/rtask/module.go +++ b/modules/rtask/module.go @@ -186,7 +186,7 @@ func (this *ModuleRtask) getHandle(tt comm.TaskType) (condis []*rtaskCondi) { 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.Rtype62, comm.Rtype64, comm.Rtype69, comm.Rtype72, comm.Rtype73, 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: