Пример #1
0
        /// <summary>
        /// 查询交易列表
        /// </summary>
        /// <param name="user"></param>
        /// <param name="searchDealRequest"></param>
        /// <param name="requestAborted"></param>
        /// <returns></returns>
        public async Task <PagingResponseMessage <SearchDealResponse> > SearchDealAsync(UserInfo user, SearchDealRequest searchDealRequest, CancellationToken requestAborted)
        {
            var response = new PagingResponseMessage <SearchDealResponse>();
            var query    = _iDealStore.GetSearchDeal(searchDealRequest.PeriodId);

            if (!string.IsNullOrWhiteSpace(searchDealRequest.Theme)) //交易标题
            {
                query = query.Where(deal => deal.Theme.Contains(searchDealRequest.Theme));
            }
            if (!string.IsNullOrWhiteSpace(searchDealRequest.UserName))//交易用户姓名
            {
                query = query.Where(deal => deal.UserName.Contains(searchDealRequest.UserName));
            }
            if (!string.IsNullOrWhiteSpace(searchDealRequest.DealUserName)) //交易对象用户姓名
            {
                query = query.Where(deal => deal.DealUserName.Contains(searchDealRequest.DealUserName));
            }
            if (searchDealRequest.DealType != null) //交易类型
            {
                query = query.Where(deal => deal.DealType == searchDealRequest.DealType);
            }
            if (searchDealRequest.StartTime.HasValue)//交易开始时间
            {
                query = query.Where(deal => deal.CreateTime >= searchDealRequest.StartTime);
            }
            if (searchDealRequest.EndTime.HasValue)//交易结束时间
            {
                query = query.Where(deal => deal.CreateTime <= searchDealRequest.EndTime);
            }
            response.TotalCount = await query.CountAsync(requestAborted);

            query = query.Skip((searchDealRequest.PageIndex) * searchDealRequest.PageSize).Take(searchDealRequest.PageSize);
            response.PageIndex = searchDealRequest.PageIndex;
            response.PageSize  = searchDealRequest.PageSize;

            response.Extension = await query.ToListAsync(requestAborted);

            return(response);
        }
Пример #2
0
        public async Task <PagingResponseMessage <SearchDealResponse> > SearchDeal(Models.UserInfo user, [FromBody] SearchDealRequest searchDealRequest)
        {
            Logger.Trace($"用户{user?.UserName ?? ""}({user?.Id ?? ""})查询交易列表,请求参数为:\r\n" + (searchDealRequest != null ? JsonHelper.ToJson(searchDealRequest) : ""));
            var response = new PagingResponseMessage <SearchDealResponse>();

            if (!ModelState.IsValid)
            {
                response.Code    = ResponseCodeDefines.ArgumentNullError;
                response.Message = "模型验证失败" + ModelState.GetAllErrors();
                Logger.Warn("查询交易列表模型验证失败:\r\n{0}", response.Message ?? "");
                return(response);
            }
            try
            {
                response = await _dealManager.SearchDealAsync(user, searchDealRequest, HttpContext.RequestAborted);
            }
            catch (Exception e)
            {
                response.Code    = ResponseCodeDefines.ServiceError;
                response.Message = e.Message;
                Logger.Error($"用户{user?.UserName ?? ""}({user?.Id ?? ""})查询交易列表,报错:{e.Message}\r\n{e.StackTrace}");
            }
            return(response);
        }