You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

136 lines
4.9 KiB

6 months ago
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;
using Service.Mgr;
6 months ago
namespace Service.Station;
6 months ago
/// <summary>
/// 充电订单
6 months ago
/// </summary>
[Scope("SingleInstance")]
public class SwapOrderService : BaseServices<SwapOrder>
{
public SwapOrderRepository swapOrderRepository { get; set; }
public SwapOrderReportCloudRepository SwapOrderReportCloudRepository { get; set; }
public SwapOrderMgr SwapOrderMgr { get; set; }
6 months ago
public SwapOrderService(SwapOrderRepository dal)
{
BaseDal = dal;
}
public Result<bool> UploadCloud(int id)
{
List<SwapOrderReportCloud> list =
SwapOrderReportCloudRepository.QueryListByClause(i => i.CloudReportStatus == 0 && i.SwapOrderId == id);
if (list.Count <= 0)
{
return Result<bool>.Fail("当前换电订单不满足上报云平台的条件");
}
return SwapOrderMgr.UploadCloud(list,2) ? Result<bool>.Success() : Result<bool>.Fail();
}
6 months ago
/// <summary>
/// 根据条件查询分页数据
6 months ago
/// </summary>
/// <param name="equipAlarmLevel"></param>
/// <returns></returns>
public PageResult<SwapOrderResp> QuerySwapOrder(QuerySwapOrderPageReq swapOrder)
{
//创建一个空的表达式树
6 months ago
Expression<Func<SwapOrder, bool>> where = null;
//// 定义参数表达式
6 months ago
ParameterExpression parameter = Expression.Parameter(typeof(SwapOrder), "u");
#region 构建动态查询树
6 months ago
if (!string.IsNullOrEmpty(swapOrder.Sn))
{
Expression<Func<SwapOrder, bool>> condition2Expr = u => u.Sn == swapOrder.Sn;
where = where == null
? condition2Expr
: Expression.Lambda<Func<SwapOrder, bool>>(Expression.AndAlso(where.Body, condition2Expr.Body),
parameter);
6 months ago
}
6 months ago
if (!string.IsNullOrEmpty(swapOrder.VehicleNo))
{
Expression<Func<SwapOrder, bool>> condition2Expr = u => u.VehicleNo == swapOrder.VehicleNo;
where = where == null
? condition2Expr
: Expression.Lambda<Func<SwapOrder, bool>>(Expression.AndAlso(where.Body, condition2Expr.Body),
parameter);
6 months ago
}
6 months ago
if (!string.IsNullOrEmpty(swapOrder.VehicleMac))
{
Expression<Func<SwapOrder, bool>> condition2Expr = u => u.VehicleMac == swapOrder.VehicleMac;
where = where == null
? condition2Expr
: Expression.Lambda<Func<SwapOrder, bool>>(Expression.AndAlso(where.Body, condition2Expr.Body),
parameter);
6 months ago
}
6 months ago
if (!string.IsNullOrEmpty(swapOrder.VehicleVin))
{
Expression<Func<SwapOrder, bool>> condition2Expr = u => u.VehicleVin == swapOrder.VehicleVin;
where = where == null
? condition2Expr
: Expression.Lambda<Func<SwapOrder, bool>>(Expression.AndAlso(where.Body, condition2Expr.Body),
parameter);
6 months ago
}
6 months ago
if (swapOrder.SwapBeginTime != null && swapOrder.SwapBeginTime != DateTime.MinValue)
{
Expression<Func<SwapOrder, bool>> condition2Expr = u => u.SwapBeginTime == swapOrder.SwapBeginTime;
where = where == null
? condition2Expr
: Expression.Lambda<Func<SwapOrder, bool>>(Expression.AndAlso(where.Body, condition2Expr.Body),
parameter);
6 months ago
}
6 months ago
if (swapOrder.SwapEndTime != null && swapOrder.SwapEndTime != DateTime.MinValue)
{
Expression<Func<SwapOrder, bool>> condition2Expr = u => u.SwapEndTime == swapOrder.SwapEndTime;
where = where == null
? condition2Expr
: Expression.Lambda<Func<SwapOrder, bool>>(Expression.AndAlso(where.Body, condition2Expr.Body),
parameter);
6 months ago
}
6 months ago
if (swapOrder.SwapResult != 0)
{
Expression<Func<SwapOrder, bool>> condition2Expr = u => u.SwapResult == swapOrder.SwapResult;
where = where == null
? condition2Expr
: Expression.Lambda<Func<SwapOrder, bool>>(Expression.AndAlso(where.Body, condition2Expr.Body),
parameter);
6 months ago
}
6 months ago
#endregion
//查询
6 months ago
//var swapOrderResp = PageResult<SwapOrderResp>.ConvertPage(swapOrderRepository.QueryIPageByCause(swapOrder, where));
//for (int i = 0; i < swapOrderResp.Rows.Count; i++)
//{
// swapOrderResp.Rows[0].BatteryList.AddRange()
//}
6 months ago
//List<SwapOrderBatteryResp> BatteryList = new List<SwapOrderBatteryResp>();
//List<SwapOrderStepResp> StepList = new List<SwapOrderStepResp>();
6 months ago
return PageResult<SwapOrderResp>.ConvertPage(swapOrderRepository.QueryIPageByCause(swapOrder, where));
}
}