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.
148 lines
7.2 KiB
148 lines
7.2 KiB
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;
|
|
/// <summary>
|
|
/// 充电订单
|
|
/// </summary>
|
|
[Scope("SingleInstance")]
|
|
public class ChargeOrderService : BaseServices<ChargeOrder>
|
|
{
|
|
ChargeOrderRepository chargeOrderRepository;
|
|
public ChargeOrderService(ChargeOrderRepository dal)
|
|
{
|
|
chargeOrderRepository = dal;
|
|
BaseDal = dal;
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 根据条件查询分页数据
|
|
/// </summary>
|
|
/// <param name="equipAlarmLevel"></param>
|
|
/// <returns></returns>
|
|
public PageResult<ChargeOrderResp> QueryChargeOrder(QueryChargeOrderReq chargeOrder)
|
|
{
|
|
|
|
//创建一个空的表达式树
|
|
Expression<Func<ChargeOrder, bool>> where = null;
|
|
//// 定义参数表达式
|
|
ParameterExpression parameter = Expression.Parameter(typeof(ChargeOrder), "u");
|
|
|
|
#region 构建动态查询树
|
|
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);
|
|
}
|
|
if (chargeOrder.CmdStatus!=0)
|
|
{
|
|
Expression<Func<ChargeOrder, bool>> condition2Expr = u => u.CmdStatus == chargeOrder.CmdStatus;
|
|
where = where == null ? condition2Expr : Expression.Lambda<Func<ChargeOrder, bool>>(Expression.AndAlso(where.Body, condition2Expr.Body), parameter);
|
|
}
|
|
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);
|
|
}
|
|
if (!string.IsNullOrEmpty(chargeOrder.ChargerGunNo))
|
|
{
|
|
Expression<Func<ChargeOrder, bool>> condition2Expr = u => u.ChargerGunNo == chargeOrder.ChargerGunNo;
|
|
where = where == null ? condition2Expr : Expression.Lambda<Func<ChargeOrder, bool>>(Expression.AndAlso(where.Body, condition2Expr.Body), parameter);
|
|
}
|
|
if (chargeOrder.ChargeMode != 0)
|
|
{
|
|
Expression<Func<ChargeOrder, bool>> condition2Expr = u => u.ChargeMode == chargeOrder.ChargeMode;
|
|
where = where == null ? condition2Expr : Expression.Lambda<Func<ChargeOrder, bool>>(Expression.AndAlso(where.Body, condition2Expr.Body), parameter);
|
|
}
|
|
if (chargeOrder.StartMode!=0)
|
|
{
|
|
Expression<Func<ChargeOrder, bool>> condition2Expr = u => u.StartMode == chargeOrder.StartMode;
|
|
where = where == null ? condition2Expr : Expression.Lambda<Func<ChargeOrder, bool>>(Expression.AndAlso(where.Body, condition2Expr.Body), parameter);
|
|
}
|
|
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!=0)
|
|
{
|
|
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 != 0)
|
|
{
|
|
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 != 0)
|
|
{
|
|
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.CloudSn))
|
|
{
|
|
Expression<Func<ChargeOrder, bool>> condition2Expr = u => u.CloudSn == chargeOrder.CloudSn;
|
|
where = where == null ? condition2Expr : Expression.Lambda<Func<ChargeOrder, bool>>(Expression.AndAlso(where.Body, condition2Expr.Body), parameter);
|
|
}
|
|
#endregion
|
|
|
|
//查询
|
|
return PageResult<ChargeOrderResp>.ConvertPage(chargeOrderRepository.QueryIPageByCause(chargeOrder, where));
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="id"></param>
|
|
/// <returns></returns>
|
|
public Result<bool> Upload2Cloud(string cloudChargerOrder)
|
|
{
|
|
List<ChargeOrder> orders = BaseDal.QueryListByClause(it => it.CloudChargeOrder == cloudChargerOrder);
|
|
if (ObjUtils.IsEmpty(orders))
|
|
{
|
|
return Result<bool>.Fail("数据不存在");
|
|
}
|
|
|
|
if ( orders[0].CloudReportStatus == 1)
|
|
{
|
|
return Result<bool>.Success("已经上传到云平台");
|
|
}
|
|
|
|
CloudClientMgr.CloudClient?.PublishChargeOrder(orders, 2);
|
|
return Result<bool>.Success();
|
|
}
|
|
} |