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 SwapOrderService : BaseServices
{
SwapOrderRepository swapOrderRepository;
public SwapOrderService(SwapOrderRepository dal)
{
swapOrderRepository = dal;
BaseDal = dal;
}
///
/// 根据条件查询分页数据
///
///
///
public PageResult QuerySwapOrder(QuerySwapOrderPageReq swapOrder)
{
//创建一个空的表达式树
Expression> where = null;
//// 定义参数表达式
ParameterExpression parameter = Expression.Parameter(typeof(SwapOrder), "u");
#region 构建动态查询树
if (!string.IsNullOrEmpty(swapOrder.Sn))
{
Expression> condition2Expr = u => u.Sn == swapOrder.Sn;
where = where == null ? condition2Expr : Expression.Lambda>(Expression.AndAlso(where.Body, condition2Expr.Body), parameter);
}
if (!string.IsNullOrEmpty(swapOrder.VehicleNo))
{
Expression> condition2Expr = u => u.VehicleNo == swapOrder.VehicleNo;
where = where == null ? condition2Expr : Expression.Lambda>(Expression.AndAlso(where.Body, condition2Expr.Body), parameter);
}
if (!string.IsNullOrEmpty(swapOrder.VehicleMac))
{
Expression> condition2Expr = u => u.VehicleMac == swapOrder.VehicleMac;
where = where == null ? condition2Expr : Expression.Lambda>(Expression.AndAlso(where.Body, condition2Expr.Body), parameter);
}
if (!string.IsNullOrEmpty(swapOrder.VehicleVin))
{
Expression> condition2Expr = u => u.VehicleVin == swapOrder.VehicleVin;
where = where == null ? condition2Expr : Expression.Lambda>(Expression.AndAlso(where.Body, condition2Expr.Body), parameter);
}
if (swapOrder.SwapBeginTime != null && swapOrder.SwapBeginTime != DateTime.MinValue)
{
Expression> condition2Expr = u => u.SwapBeginTime == swapOrder.SwapBeginTime;
where = where == null ? condition2Expr : Expression.Lambda>(Expression.AndAlso(where.Body, condition2Expr.Body), parameter);
}
if (swapOrder.SwapEndTime != null && swapOrder.SwapEndTime != DateTime.MinValue)
{
Expression> condition2Expr = u => u.SwapEndTime == swapOrder.SwapEndTime;
where = where == null ? condition2Expr : Expression.Lambda>(Expression.AndAlso(where.Body, condition2Expr.Body), parameter);
}
if (swapOrder.SwapResult != 0)
{
Expression> condition2Expr = u => u.SwapResult == swapOrder.SwapResult;
where = where == null ? condition2Expr : Expression.Lambda>(Expression.AndAlso(where.Body, condition2Expr.Body), parameter);
}
#endregion
//查询
//var swapOrderResp = PageResult.ConvertPage(swapOrderRepository.QueryIPageByCause(swapOrder, where));
//for (int i = 0; i < swapOrderResp.Rows.Count; i++)
//{
// swapOrderResp.Rows[0].BatteryList.AddRange()
//}
//List BatteryList = new List();
//List StepList = new List();
return PageResult.ConvertPage(swapOrderRepository.QueryIPageByCause(swapOrder, where));
}
}