using Entity.Api.Req; using Entity.Api.Resp; using Entity.DbModel.Station; using HybirdFrameworkCore.Autofac.Attribute; using HybirdFrameworkCore.Entity; using Repository.Station; using SqlSugar; using System.Linq.Expressions; namespace Service.Station; /// /// 换电订单电池 /// [Scope("SingleInstance")] public class SwapOrderBatteryService : BaseServices { SwapOrderBatteryRepository _swapOrderBatteryRepository; public SwapOrderBatteryService(SwapOrderBatteryRepository dal) { _swapOrderBatteryRepository = dal; BaseDal = dal; } /// /// 根据条件查询分页数据 /// /// /// public PageResult QuerySwapOrderBattery(QuerySwapOrderBatteryReq swapOrderBattery) { //创建一个空的表达式树 Expression> where = null; //// 定义参数表达式 ParameterExpression parameter = Expression.Parameter(typeof(SwapOrderBattery), "u"); #region 构建动态查询树 if (swapOrderBattery.Id != 0) { Expression> condition1Expr = u => u.Id == swapOrderBattery.Id; where = condition1Expr; } if (!string.IsNullOrEmpty(swapOrderBattery.SwapOrderSn)) { Expression> condition2Expr = u => u.SwapOrderSn == swapOrderBattery.SwapOrderSn; where = where == null ? condition2Expr : Expression.Lambda>(Expression.AndAlso(where.Body, condition2Expr.Body), parameter); } if (!string.IsNullOrEmpty(swapOrderBattery.DownBatteryNo)) { Expression> condition2Expr = u => u.DownBatteryNo == swapOrderBattery.DownBatteryNo; where = where == null ? condition2Expr : Expression.Lambda>(Expression.AndAlso(where.Body, condition2Expr.Body), parameter); } if (swapOrderBattery.DownBatteryBinNo != 0) { Expression> condition2Expr = u => u.DownBatteryBinNo == swapOrderBattery.DownBatteryBinNo; where = where == null ? condition2Expr : Expression.Lambda>(Expression.AndAlso(where.Body, condition2Expr.Body), parameter); } if (!string.IsNullOrEmpty(swapOrderBattery.UpBatteryNo)) { Expression> condition2Expr = u => u.UpBatteryNo == swapOrderBattery.UpBatteryNo; where = where == null ? condition2Expr : Expression.Lambda>(Expression.AndAlso(where.Body, condition2Expr.Body), parameter); } if (swapOrderBattery.UpBatteryBinNo != 0) { Expression> condition2Expr = u => u.UpBatteryBinNo == swapOrderBattery.UpBatteryBinNo; where = where == null ? condition2Expr : Expression.Lambda>(Expression.AndAlso(where.Body, condition2Expr.Body), parameter); } if (swapOrderBattery.CreatedTime != null && swapOrderBattery.CreatedTime != DateTime.MinValue) { Expression> condition2Expr = u => u.CreatedTime == swapOrderBattery.CreatedTime; where = where == null ? condition2Expr : Expression.Lambda>(Expression.AndAlso(where.Body, condition2Expr.Body), parameter); } if (swapOrderBattery.UpdatedTime != null && swapOrderBattery.UpdatedTime != DateTime.MinValue) { Expression> condition2Expr = u => u.UpdatedTime == swapOrderBattery.UpdatedTime; where = where == null ? condition2Expr : Expression.Lambda>(Expression.AndAlso(where.Body, condition2Expr.Body), parameter); } #endregion //查询 return PageResult.ConvertPage(_swapOrderBatteryRepository.QueryIPageByCause(swapOrderBattery, where)); } public PageResult QuerySwapOrderBatteryList(QuerySwapOrderPageReq swapOrderBattery) { //创建一个空的表达式树 Expression> where = null; //// 定义参数表达式 ParameterExpression parameter = Expression.Parameter(typeof(SwapOrderBattery), "u"); if (!string.IsNullOrEmpty(swapOrderBattery.DownBatteryNo)) { Expression> condition2Expr = u => u.DownBatteryNo == swapOrderBattery.DownBatteryNo; where = where == null ? condition2Expr : Expression.Lambda>(Expression.AndAlso(where.Body, condition2Expr.Body), parameter); } if (!string.IsNullOrEmpty(swapOrderBattery.UpBatteryNo)) { Expression> condition2Expr = u => u.UpBatteryNo == swapOrderBattery.UpBatteryNo; where = where == null ? condition2Expr : Expression.Lambda>(Expression.AndAlso(where.Body, condition2Expr.Body), parameter); } if (swapOrderBattery.SwapBeginTime != null && swapOrderBattery.SwapEndTime != null) { Expression> condition2Expr = u => u.CreatedTime >= swapOrderBattery.SwapBeginTime && u.CreatedTime <= swapOrderBattery.SwapEndTime; where = where == null ? condition2Expr : Expression.Lambda>(Expression.AndAlso(where.Body, condition2Expr.Body), parameter); } return PageResult.ConvertPage(_swapOrderBatteryRepository.QueryIPageByCause(swapOrderBattery, where)); //查询 } }