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.

133 lines
5.9 KiB

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