public async Task <PagingResponseMessage <CustomerLossResponse> > Search(string userid, CustomerLossCondition condition, CancellationToken cancellationToken = default(CancellationToken)) { if (condition == null) { throw new ArgumentNullException(nameof(condition)); } PagingResponseMessage <CustomerLossResponse> pagingResponse = new PagingResponseMessage <CustomerLossResponse>(); var q = Store.SimpleQuery().Where(a => !a.IsDeleted); if (!string.IsNullOrEmpty(condition.KeyWords)) { q = q.Where(a => a.CustomerInfo.CustomerName.Contains(condition.KeyWords)); } if (condition.LossTimeStart != null) { q = q.Where(a => a.LossTime >= condition.LossTimeStart); } if (condition.LossTimeEnd != null) { q = q.Where(a => a.LossTime <= condition.LossTimeEnd); } if (condition.Types?.Count > 0) { q = q.Where(a => condition.Types.Contains(a.LossTypeId)); } pagingResponse.TotalCount = await q.CountAsync(cancellationToken); var qlist = await q.OrderByDescending(a => a.LossTime).Skip(condition.PageIndex * condition.PageSize).Take(condition.PageSize).ToListAsync(cancellationToken); var resulte = qlist.Select(a => new CustomerLossResponse { Id = a.Id, CustomerId = a.CustomerId, CustomerName = a.CustomerInfo.CustomerName, LossTime = a.LossTime, LossDepartmentId = a.LossDepartmentId, LossRemark = a.LossRemark, LossTypeId = a.LossTypeId, LossUserId = a.LossUserId, LossUserTrueName = a.LossUser.TrueName }); pagingResponse.PageIndex = condition.PageIndex; pagingResponse.PageSize = condition.PageSize; pagingResponse.Extension = resulte.ToList(); return(pagingResponse); }
public async Task <PagingResponseMessage <CustomerLossResponse> > GetList(UserInfo user, [FromBody] CustomerLossCondition condition) { Logger.Trace($"用户{user?.UserName ?? ""}({user?.Id ?? ""})获取失效列表(GetList):\r\n请求参数为:\r\n" + (condition != null ? JsonHelper.ToJson(condition) : "")); PagingResponseMessage <CustomerLossResponse> response = new PagingResponseMessage <CustomerLossResponse>(); if (!ModelState.IsValid) { response.Code = ResponseCodeDefines.ModelStateInvalid; response.Message = ModelState.GetAllErrors(); Logger.Warn($"用户{user?.UserName ?? ""}({user?.Id ?? ""})获取失效列表(GetList)模型验证失败:\r\n{response.Message ?? ""},\r\n请求参数为:\r\n" + (condition != null ? JsonHelper.ToJson(condition) : "")); return(response); } try { if (await _permissionExpansionManager.HavePermission(user.Id, "CustomerLossRetrieve")) { return(await _customerLossManager.Search(user.Id, condition, HttpContext.RequestAborted)); } else { response.Code = ResponseCodeDefines.ServiceError; response.Message = "权限不足"; } } catch (Exception e) { response.Code = ResponseCodeDefines.ServiceError; response.Message = e.ToString(); Logger.Error($"用户{user?.UserName ?? ""}({user?.Id ?? ""})获取失效列表(GetList)请求失败:\r\n{response.Message ?? ""},\r\n请求参数为:\r\n" + (condition != null ? JsonHelper.ToJson(condition) : "")); } return(response); }