/// <summary> /// Get order list for mobile /// </summary> /// <param name="orderInput"></param> public PagedList <MerchantOrderList> GetOrderList(MerchantOrderListInput orderInput) { //query express var query = new ExpressionQuery <MerchantOrder>(); if (orderInput.OrderStatus > 0) { query.And(e => e.OrderStatus == orderInput.OrderStatus); } if (!string.IsNullOrWhiteSpace(orderInput.MerchantStoreId)) { query.And(e => e.MerchantStoreId == orderInput.MerchantStoreId); } if (orderInput.UserId > 0) { query.And(e => e.UserId == orderInput.UserId); } query.PageIndex = (int)orderInput.PageIndex; query.PageSize = (int)orderInput.PageSize; query.EnablePaging = true; query.OrderByDescending(e => e.Id); var orders = Resolve <IMerchantOrderService>().GetPagedList(query); if (orders.Count < 0) { return(new PagedList <MerchantOrderList>()); } //all stores var merchantStores = Resolve <IMerchantStoreService>().GetList().ToList(); //query var result = new List <MerchantOrderList>(); var apiService = Resolve <IApiService>(); orders.ForEach(item => { var store = merchantStores.Find(s => s.Id == item.MerchantStoreId.ToObjectId()); if (store == null) { return; } var extension = item.Extension.DeserializeJson <MerchantOrderExtension>(); var temp = new MerchantOrderList(); temp = AutoMapping.SetValue(item, temp); temp.MerchantOrderStatus = item.OrderStatus; temp.MerchantStoreName = store.Name; temp.ThumbnailUrl = apiService.ApiImageUrl(store.Logo); temp.Products = extension?.MerchantProducts; temp.Products?.ForEach(product => { product.ThumbnailUrl = apiService.ApiImageUrl(product.ThumbnailUrl); }); result.Add(temp); }); return(PagedList <MerchantOrderList> .Create(result, orders.RecordCount, orders.PageSize, orders.PageIndex)); }
public ApiResult <PagedList <ProductBrief> > GetProductList([FromQuery] ProductListInput input) { var query = new ExpressionQuery <Product>(); query.And(e => e.StoreId == input.StoreId.ToString()); query.PageIndex = (int)input.PageIndex; query.PageSize = (int)input.PageSize; query.EnablePaging = true; query.OrderByDescending(e => e.Id); var list = Resolve <IProductService>().GetPagedList(query); if (list.Count < 0) { return(ApiResult.Success(new PagedList <ProductBrief>())); } var catDict = Resolve <ICategoryService>().GetList().ToDictionary(c => c.Id); var ret = list.Select(prd => { var brief = new ProductBrief(); AutoMapping.SetValue(prd, brief); brief.CategoryName = catDict.ContainsKey(prd.CategoryId) ? catDict[prd.CategoryId].Name : "未定义"; return(brief); }); return(ApiResult.Success(PagedList <ProductBrief> .Create(ret, list.RecordCount, list.PageSize, list.PageIndex))); }
public PagedList <ApiOrderListOutput> GetPageList(object query, ExpressionQuery <Order> expressionQuery) { //query.PageIndex = (int)orderInput.PageIndex; // query.PageSize = (int)orderInput.PageSize; expressionQuery.OrderByDescending(e => e.Id); //所有的绑定都使用快照数据,而不是使用当前数据库中的数据 var orders = Resolve <IOrderService>().GetPagedList(query, expressionQuery.BuildExpression()); var model = new List <ApiOrderListOutput>(); if (orders.Count < 0) { return(new PagedList <ApiOrderListOutput>()); } foreach (var item in orders) { var listOutput = new ApiOrderListOutput { CreateTime = item?.CreateTime.ToString("yyyy-MM-dd HH:mm:ss"), Id = item.Id, OrderStatuName = item?.OrderStatus.GetDisplayName(), User = item?.OrderExtension?.User, Address = item?.OrderExtension?.UserAddress?.Address }; if (item.OrderExtension != null) { if (item.OrderExtension.UserAddress != null) { listOutput.RegionName = Resolve <IRegionService>() .GetRegionNameById(item.OrderExtension.UserAddress.RegionId); } } else { listOutput.RegionName = null; } listOutput = AutoMapping.SetValue(item, listOutput); var orderExtension = item.Extension.DeserializeJson <OrderExtension>(); if (orderExtension != null && orderExtension.Store != null) { listOutput.StoreName = orderExtension.Store.Name; listOutput.ExpressAmount = orderExtension.OrderAmount.ExpressAmount; } listOutput.OutOrderProducts = orderExtension.ProductSkuItems; listOutput.OutOrderProducts?.ToList().ForEach(c => { c.ThumbnailUrl = Resolve <IApiService>().ApiImageUrl(c.ThumbnailUrl); }); model.Add(listOutput); } return(PagedList <ApiOrderListOutput> .Create(model, orders.RecordCount, orders.PageSize, orders.PageIndex)); }
public TEntity GetSingleOrderByDescending(Expression <Func <TEntity, TKey> > keySelector, Expression <Func <TEntity, bool> > predicate) { var queryCriteria = new ExpressionQuery <TEntity>(); queryCriteria.OrderByDescending(keySelector); if (predicate != null) { queryCriteria.And(predicate); } var find = queryCriteria.Execute(Set); return(find.FirstOrDefault()); }
public ApiResult <PageResult <Product> > ProductList([FromQuery] PagedInputDto parameter) { var query = new ExpressionQuery <Product> { PageIndex = (int)parameter.PageIndex, PageSize = (int)parameter.PageSize, EnablePaging = true }; //query.And(e => e.StoreId == parameter.StoreId); if (!parameter.StoreId.IsObjectIdNullOrEmpty()) { query.And(s => s.StoreId == parameter.StoreId.ToString()); } if (parameter.Bn != null) { query.And(s => s.Bn.Contains(parameter.Bn)); } if (parameter.Name != null) { query.And(s => s.Name.Contains(parameter.Name)); } query.OrderByDescending(e => e.Id); var list = Resolve <IProductService>().GetPagedList(query); var apiRusult = new PageResult <Product> { PageCount = list.PageCount, Result = list, RecordCount = list.RecordCount, CurrentSize = list.CurrentSize, PageIndex = list.PageIndex, PageSize = list.PageSize }; if (list.Count < 0) { return(ApiResult.Success(new PageResult <Product>())); } return(ApiResult.Success(apiRusult)); //return ApiResult.Success(list); }
public PageResult <AutoListItem> PageList(object query, AutoBaseModel autoModel) { var dic = query.ToObject <Dictionary <string, string> >(); dic.TryGetValue("loginUserId", out var userId); dic.TryGetValue("pageIndex", out var pageIndexStr); var pageIndex = pageIndexStr.ToInt64(); if (pageIndex <= 0) { pageIndex = 1; } var temp = new ExpressionQuery <Reward> { EnablePaging = true, PageIndex = (int)pageIndex, PageSize = 15 }; temp.And(e => e.UserId == userId.ToInt64()); temp.OrderByDescending(s => s.CreateTime); //temp.And(u => u.Type == TradeType.Withraw); var moneyTypes = Resolve <IAutoConfigService>().GetList <MoneyTypeConfig>(); var model = Resolve <IRewardService>().GetPagedList(temp); var users = Resolve <IUserDetailService>().GetList(); var list = new List <AutoListItem>(); foreach (var item in model) { var apiData = new AutoListItem { Title = moneyTypes.FirstOrDefault(u => u.Id == item.MoneyTypeId) ?.Name, // + " - " + item.Type.GetDisplayName(), Intro = item.Intro, //$"{item.CreateTime}", Value = item.Amount, Image = users.FirstOrDefault(u => u.UserId == item.UserId)?.Avator, Id = item.Id, Url = $"/pages/index?path=share_show&id={item.Id}" }; list.Add(apiData); } return(ToPageList(list, model)); }
public TEntity Prex(TEntity model) { var dynamic = (dynamic)model; var query = new ExpressionQuery <TEntity>(); var dynamicWhere = LinqHelper.GetExpression <TEntity, bool>($"entity.Id < {dynamic.Id}", "entity"); query.And(dynamicWhere); //排序方式 var orderExpression = LinqHelper.GetExpression <TEntity, long>("entity.Id", "entity"); query.OrderByDescending(orderExpression); var prex = GetSingle(query); if (prex == null) { prex = model; } return(prex); }
public List <ArticleItem> GetArticleList(ArticleInput articleInput) { var query = new ExpressionQuery <Article>(); query.OrderByAscending(e => e.CreateTime); if (!articleInput.ChannelId.IsNullOrEmpty()) { query.And(r => r.ChannelId == articleInput.ChannelId.ToObjectId()); } if (articleInput.OrderType == 0) { query.OrderByAscending(a => a.ViewCount); } else { query.OrderByDescending(a => a.ViewCount); } var list = GetList(query); var result = new List <ArticleItem>(); foreach (var item in list) { if (articleInput.TotalCount > 0 && result.Count >= articleInput.TotalCount) { break; } var articleItem = AutoMapping.SetValue <ArticleItem>(item); articleItem.RelationId = item.RelationId; result.Add(articleItem); } return(result); }
/// <summary> /// 获取订单列表,包括供应商订单,会员订单,后台订单 /// </summary> /// <param name="orderInput"></param> public PagedList <OrderListOutput> GetPageList(OrderListInput orderInput) { var query = new ExpressionQuery <Order>(); if (orderInput.OrderStatus > 0) { query.And(e => e.OrderStatus == orderInput.OrderStatus); } if (orderInput.OrderType.HasValue) { query.And(e => e.OrderType == orderInput.OrderType); } if (!orderInput.StoreId.IsObjectIdNullOrEmpty()) { query.And(e => e.StoreId == orderInput.StoreId.ToString()); } if (orderInput.DeliverUserId > 0) // 发货记录 { query.And(e => e.DeliverUserId == orderInput.DeliverUserId); } if (orderInput.UserId > 0) //订单记录 { query.And(e => e.UserId == orderInput.UserId); } else if (orderInput.UserId > 0) //订单记录 { query.And(e => e.UserId == orderInput.UserId); } if (orderInput.OrderType > 0) { query.And(e => e.OrderType == orderInput.OrderType); } query.PageIndex = (int)orderInput.PageIndex; query.PageSize = (int)orderInput.PageSize; query.EnablePaging = true; query.OrderByDescending(e => e.Id); var orders = Resolve <IOrderService>().GetPagedList(query); if (orders.Count < 0) { return(new PagedList <OrderListOutput>()); } var model = new List <OrderListOutput>(); foreach (var item in orders) { var listOutput = new OrderListOutput { CreateTime = item?.CreateTime.ToString("yyyy-MM-dd HH:mm:ss"), Id = item.Id, OrderStatuName = item?.OrderStatus.GetDisplayName(), User = item?.OrderExtension?.User, Address = item?.OrderExtension?.UserAddress?.Address }; if (item.OrderExtension != null) { if (item.OrderExtension.UserAddress != null) { listOutput.RegionName = Resolve <IRegionService>() .GetRegionNameById(item.OrderExtension.UserAddress.RegionId); } } else { listOutput.RegionName = null; } listOutput = AutoMapping.SetValue(item, listOutput); var orderExtension = item.Extension.DeserializeJson <OrderExtension>(); if (orderExtension != null && orderExtension.Store != null) { listOutput.StoreName = orderExtension.Store.Name; listOutput.ExpressAmount = orderExtension.OrderAmount.ExpressAmount; } if (item.OrderStatus == OrderStatus.WaitingBuyerPay) { var proids = orderExtension.ProductSkuItems.Select(s => s.ProductId); var productNotOnline = Resolve <IProductService>().GetList(s => s.ProductStatus != GoodsStatus.Online && proids.Contains(s.Id)); foreach (var product in productNotOnline) { var ext = orderExtension.ProductSkuItems.SingleOrDefault(s => s.ProductId == product.Id); if (ext != null) { ext.ProductStatus = product.ProductStatus; listOutput.OrderStatus = OrderStatus.UnderShelf; //标识为下架订单 } } } listOutput.OutOrderProducts = orderExtension.ProductSkuItems; listOutput.OutOrderProducts?.ToList().ForEach(c => { c.ThumbnailUrl = Resolve <IApiService>().ApiImageUrl(c.ThumbnailUrl); }); model.Add(listOutput); } return(PagedList <OrderListOutput> .Create(model, orders.RecordCount, orders.PageSize, orders.PageIndex)); }
public PagedList <TEntity> GetPagedList(object paramater, Type searchView, Expression <Func <TEntity, bool> > predicate = null) { var query = new ExpressionQuery <TEntity> { EnablePaging = true }; #region 构建查询页数 var dictionary = paramater.DeserializeJson <Dictionary <string, string> >(); if (dictionary != null) { var pagedInput = AutoMapping.SetValue <PagedInputDto>(dictionary); if (pagedInput != null) { query.PageIndex = (int)pagedInput.PageIndex; query.PageSize = (int)pagedInput.PageSize; } } #endregion 构建查询页数 if (predicate != null) { query.And(predicate); } var result = HanderDictionary(ref dictionary); // 获取搜索范围相关的字段 var rangList = result.Item1; var interpreter = new Interpreter(); var classDescription = new ClassDescription(searchView); var propertyResults = searchView.GetPropertyResultFromCache(); var propertyInfos = propertyResults.Select(r => r.PropertyInfo); #region 普通字段搜索 foreach (var item in dictionary) { var name = item.Key.Replace("_Start", "").Replace("_End", ""); var value = item.Value.SafeString(); if (value.IsNullOrEmpty() || name.IsNullOrEmpty()) { continue; } if (name.Equals("UserName", StringComparison.OrdinalIgnoreCase)) { #region 搜索用户名 var property = propertyInfos.FirstOrDefault(r => r.Name.Equals("UserId", StringComparison.OrdinalIgnoreCase)); if (property == null) { continue; } var user = EntityDynamicService.GetSingleUser(value); // 动态获取用户名 if (user != null) { var expression = Lambda.Equal <TEntity>(property.Name, user.Id); query.And(expression); } #endregion 搜索用户名 } else if (name.Equals("Serial", StringComparison.OrdinalIgnoreCase)) { #region 搜索序号 // 序号处理,适合序号是通过Id生成的方式,比如Bill,Order,Reard表 var property = propertyInfos.FirstOrDefault(r => r.Name.Equals("Id", StringComparison.OrdinalIgnoreCase)); if (property == null) { continue; } if (value.Length > 7 && value.StartsWith("9")) { value = value.Substring(1, value.Length - 1); } // 去掉前面的0 var reg = new Regex(@"^0+"); value = reg.Replace(value, ""); var idValue = value.ConvertToLong(0); if (idValue > 0) { var expression = Lambda.Equal <TEntity>(property.Name, idValue); query.And(expression); } #endregion 搜索序号 } else { var property = propertyInfos.FirstOrDefault(r => r.Name.Equals(name, StringComparison.OrdinalIgnoreCase)); if (property == null) { continue; } if (property.PropertyType.IsEnum) { if (value == "-1") { continue; } } var fieldAttribute = propertyResults.FirstOrDefault(r => r.PropertyInfo.Name == property.Name) .FieldAttribute; var valueList = value.ToSplitList(); foreach (var itemValue in valueList) { if (!itemValue.IsNullOrEmpty()) { Expression <Func <TEntity, bool> > expression = null; if (fieldAttribute != null) { if (fieldAttribute.Operator == Operator.Contains) { expression = Lambda.Contains <TEntity>(property.Name, itemValue); } if (fieldAttribute.Operator == Operator.Equal) { expression = Lambda.Equal <TEntity>(property.Name, itemValue); } } // 字段中包含name和title,一般都可以模糊搜索 else if (property.Name.Contains("name", StringComparison.OrdinalIgnoreCase) || property.Name.Contains("intro", StringComparison.OrdinalIgnoreCase) || property.Name.Contains("desc", StringComparison.OrdinalIgnoreCase) || property.Name.Contains("remark", StringComparison.OrdinalIgnoreCase) || property.Name.Contains("title", StringComparison.OrdinalIgnoreCase)) { expression = Lambda.Contains <TEntity>(property.Name, itemValue); } else { expression = Lambda.Equal <TEntity>(property.Name, itemValue); } if (expression != null) { query.And(expression); } } } } } #endregion 普通字段搜索 #region 搜索范围字段搜索 foreach (var item in rangList) { var property = propertyInfos.FirstOrDefault(r => r.Name.Equals(item.Name, StringComparison.OrdinalIgnoreCase)); if (property == null || item.StartValue.IsNullOrEmpty() && item.EndValue.IsNullOrEmpty()) { continue; } // 大于等于 if (!item.StartValue.IsNullOrEmpty()) { var expression = Lambda.GreaterEqual <TEntity>(property.Name, item.StartValue); if (expression != null) { query.And(expression); } } // 小于等于 if (!item.EndValue.IsNullOrEmpty()) { var expression = Lambda.LessEqual <TEntity>(property.Name, item.EndValue); if (expression != null) { query.And(expression); } } } #endregion 搜索范围字段搜索 #region 排序 var sortType = result.Item2; var propertySort = propertyInfos.FirstOrDefault(r => r.Name.Equals(sortType.Name, StringComparison.OrdinalIgnoreCase)); if (propertySort != null) { var selectExpression = $"entity.{propertySort.Name}"; var expression = interpreter.ParseAsExpression <Func <TEntity, object> >(selectExpression, "entity"); if (sortType.OrderType == OrderType.Descending) { query.OrderByDescending(expression); } else { query.OrderByAscending(expression); } } #endregion 排序 var pageList = Store.GetPagedList(query); pageList = PagedListStyle(pageList); return(pageList); }