using System.Linq.Expressions;
using Entity.Api.Req;
using Entity.Api.Resp;
using Entity.DbModel.Station;
using HybirdFrameworkCore.Autofac.Attribute;
using HybirdFrameworkCore.Entity;
using HybirdFrameworkCore.Utils;
using Repository.Station;
using Service.Cloud.Client;
namespace Service.Station;
///
/// 充电订单
///
[Scope("SingleInstance")]
public class ChargeOrderService : BaseServices
{
ChargeOrderRepository chargeOrderRepository;
public ChargeOrderService(ChargeOrderRepository dal)
{
chargeOrderRepository = dal;
BaseDal = dal;
}
///
/// 根据条件查询分页数据
///
///
///
public PageResult QueryChargeOrder(QueryChargeOrderReq chargeOrder)
{
//创建一个空的表达式树
Expression> where = null;
//// 定义参数表达式
ParameterExpression parameter = Expression.Parameter(typeof(ChargeOrder), "u");
#region 构建动态查询树
if (chargeOrder.Id != 0)
{
Expression> condition1Expr = u => u.Id == chargeOrder.Id;
where = condition1Expr;
}
if (!string.IsNullOrEmpty(chargeOrder.Sn))
{
Expression> condition2Expr = u => u.Sn == chargeOrder.Sn;
where = where == null ? condition2Expr : Expression.Lambda>(Expression.AndAlso(where.Body, condition2Expr.Body), parameter);
}
if (!string.IsNullOrEmpty(chargeOrder.BatteryNo))
{
Expression> condition2Expr = u => u.BatteryNo == chargeOrder.BatteryNo;
where = where == null ? condition2Expr : Expression.Lambda>(Expression.AndAlso(where.Body, condition2Expr.Body), parameter);
}
if (!string.IsNullOrEmpty(chargeOrder.ChargerNo))
{
Expression> condition2Expr = u => u.ChargerNo == chargeOrder.ChargerNo;
where = where == null ? condition2Expr : Expression.Lambda>(Expression.AndAlso(where.Body, condition2Expr.Body), parameter);
}
if (chargeOrder.StartTime != null && chargeOrder.StartTime != DateTime.MinValue)
{
Expression> condition2Expr = u => u.StartTime == chargeOrder.StartTime;
where = where == null ? condition2Expr : Expression.Lambda>(Expression.AndAlso(where.Body, condition2Expr.Body), parameter);
}
if (chargeOrder.EndTime != null && chargeOrder.EndTime != DateTime.MinValue)
{
Expression> condition2Expr = u => u.EndTime == chargeOrder.EndTime;
where = where == null ? condition2Expr : Expression.Lambda>(Expression.AndAlso(where.Body, condition2Expr.Body), parameter);
}
if (chargeOrder.ChargeTimeCount!=null)
{
Expression> condition2Expr = u => u.ChargeTimeCount == chargeOrder.ChargeTimeCount;
where = where == null ? condition2Expr : Expression.Lambda>(Expression.AndAlso(where.Body, condition2Expr.Body), parameter);
}
if (chargeOrder.StopReason != null)
{
Expression> condition2Expr = u => u.StopReason == chargeOrder.StopReason;
where = where == null ? condition2Expr : Expression.Lambda>(Expression.AndAlso(where.Body, condition2Expr.Body), parameter);
}
if (!string.IsNullOrEmpty(chargeOrder.ElecPriceModelVersion))
{
Expression> condition2Expr = u => u.ElecPriceModelVersion == chargeOrder.ElecPriceModelVersion;
where = where == null ? condition2Expr : Expression.Lambda>(Expression.AndAlso(where.Body, condition2Expr.Body), parameter);
}
if (!string.IsNullOrEmpty(chargeOrder.SwapOrderSn))
{
Expression> condition2Expr = u => u.SwapOrderSn == chargeOrder.SwapOrderSn;
where = where == null ? condition2Expr : Expression.Lambda>(Expression.AndAlso(where.Body, condition2Expr.Body), parameter);
}
if (chargeOrder.CloudReportStatus != null)
{
Expression> condition2Expr = u => u.CloudReportStatus == chargeOrder.CloudReportStatus;
where = where == null ? condition2Expr : Expression.Lambda>(Expression.AndAlso(where.Body, condition2Expr.Body), parameter);
}
if (!string.IsNullOrEmpty(chargeOrder.CloudChargeOrder))
{
Expression> condition2Expr = u => u.CloudChargeOrder == chargeOrder.CloudChargeOrder;
where = where == null ? condition2Expr : Expression.Lambda>(Expression.AndAlso(where.Body, condition2Expr.Body), parameter);
}
#endregion
//查询
return PageResult.ConvertPage(chargeOrderRepository.QueryIPageByCause(chargeOrder, where));
}
///
///
///
///
///
public Result Upload2Cloud(string cloudChargerOrder)
{
List orders = BaseDal.QueryListByClause(it => it.CloudChargeOrder == cloudChargerOrder);
if (ObjUtils.IsEmpty(orders))
{
return Result.Fail("数据不存在");
}
if ( orders[0].CloudReportStatus == 1)
{
return Result.Success(true, "已经上传到云平台");
}
CloudClientMgr.CloudClient?.PublishChargeOrder(orders, 2);
return Result.Success();
}
}