Exemple #1
0
        /// <summary>
        /// 获取我发布的任务列表
        /// </summary>
        /// <param name="user"></param>
        /// <param name="request"></param>
        /// <returns></returns>
        public async Task <PagingResponseMessage <MyPushTaskResponse> > MyPushTaskAsync(UserInfo user, MyTaskRequest request)
        {
            var response = new PagingResponseMessage <MyPushTaskResponse>();

            var myTaskQuery = _iTaskStore.GetMyPushTasksAsync(user.Id, request.PeriodId);

            if (!string.IsNullOrWhiteSpace(request.TaskName))//任务名称
            {
                myTaskQuery = myTaskQuery.Where(task => task.TaskName.Contains(request.TaskName));
            }
            if (request.TaskState != null) //任务状态
            {
                myTaskQuery = myTaskQuery.Where(task => task.TaskState == request.TaskState);
            }
            if (!string.IsNullOrWhiteSpace(request.CreateUser))//发布人
            {
                myTaskQuery = myTaskQuery.Where(task => task.CreateUser.Contains(request.CreateUser));
            }
            if (request.StartTime.HasValue)//发布开始时间
            {
                myTaskQuery = myTaskQuery.Where(task => task.CreateTime >= request.StartTime);
            }
            if (request.EndTime.HasValue)//发布开始时间
            {
                myTaskQuery = myTaskQuery.Where(task => task.CreateTime <= request.EndTime);
            }
            response.TotalCount = await myTaskQuery.CountAsync();

            var myTaskList = await myTaskQuery.Skip(request.PageIndex *request.PageSize).Take(request.PageSize).ToListAsync();

            response.PageIndex = request.PageIndex;
            response.PageSize  = request.PageSize;

            // 19-12-10 查询任务接取人
            var taskIds   = myTaskList.Select(a => a.Id);
            var periodId  = request.PeriodId;
            var taskUsers = await(from tu in _iTaskStore.GetTaskUsers()
                                  where taskIds.Contains(tu.TaskId)
                                  join u in _iUserStore.GetUserInfos() on tu.UserId equals u.Id
                                  select new MyPushTaskResponse.TaskUserDetails2
            {
                TaskId           = tu.TaskId,
                UserId           = tu.UserId,
                UserName         = u.UserName,
                OrganizationName = u.OrganizationName,
                GroupName        = u.GroupName,
            })
                            //.OrderBy(a => a.TaskId)
                            //// 20200107-修复-王森 一个格子里面显示两行每行3个总共6个人,多的不显示
                            //.Take(6)
                            .ToListAsync();
            //任务人员关系表
            var taskUserIdQuery = _iTaskStore.GetTaskUsers().Where(w => taskIds.Contains(w.TaskId)).Select(s => s.UserId);
            //参与人员积分(任务对应赛季的积分)
            var scoreInfoList = await _iTaskStore.GetScoreInfos().Where(w => taskUserIdQuery.Contains(w.UserId) && w.PeriodId == periodId).ToListAsync();

            //称号信息
            var titleList = await _iTaskStore.GetScoreTitles().Where(w => !w.IsDelete && w.PeriodId == periodId).ToListAsync();

            titleList.ForEach(fo => fo.Icon = _config["FileUrl"] + fo.Icon);
            taskUsers.ForEach(task =>
            {
                task.ScoreTitle = (titleList.FirstOrDefault(fi => fi.StartScore <= scoreInfoList.First(f => f.UserId == task.UserId).Score&& fi.EndScore >= scoreInfoList.First(f => f.UserId == task.UserId).Score)?.Title) ?? "未知称号";
                task.Icon       = titleList.FirstOrDefault(fi => fi.StartScore <= scoreInfoList.First(f => f.UserId == task.UserId).Score&& fi.EndScore >= scoreInfoList.First(f => f.UserId == task.UserId).Score)?.Icon;
            });

            myTaskList.ForEach(fo => fo.TaskUsers = taskUsers.Where(a => a.TaskId == fo.Id));

            response.Extension = myTaskList;

            return(response);
        }