|
|
|
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 AutoMapper;
|
|
|
|
using Entity.Dto;
|
|
|
|
using Magicodes.ExporterAndImporter.Excel;
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
using Service.Mgr;
|
|
|
|
|
|
|
|
namespace Service.Station;
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 充电订单
|
|
|
|
/// </summary>
|
|
|
|
[Scope("SingleInstance")]
|
|
|
|
public class SwapOrderService : BaseServices<SwapOrder>
|
|
|
|
{
|
|
|
|
public SwapOrderRepository swapOrderRepository { get; set; }
|
|
|
|
public SwapOrderReportCloudRepository SwapOrderReportCloudRepository { get; set; }
|
|
|
|
|
|
|
|
public SwapOrderMgr SwapOrderMgr { get; set; }
|
|
|
|
|
|
|
|
public SwapOrderService(SwapOrderRepository dal)
|
|
|
|
{
|
|
|
|
BaseDal = dal;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public Dictionary<string, int?> QueryReportCloudNumBySn(List<string> swapOrderSns)
|
|
|
|
{
|
|
|
|
if (swapOrderSns.Count <= 0)
|
|
|
|
{
|
|
|
|
return new Dictionary<string, int?>();
|
|
|
|
}
|
|
|
|
|
|
|
|
List<SwapOrderReportCloud> swapOrderReportClouds =
|
|
|
|
SwapOrderReportCloudRepository.QueryListByClause(i => swapOrderSns.Contains(i.SwapOrderSn));
|
|
|
|
|
|
|
|
if (swapOrderReportClouds.Count <= 0)
|
|
|
|
{
|
|
|
|
return new Dictionary<string, int?>();
|
|
|
|
}
|
|
|
|
|
|
|
|
return swapOrderReportClouds.ToDictionary(i => i.SwapOrderSn, i => i.CloudReportStatus++);
|
|
|
|
}
|
|
|
|
|
|
|
|
public Result<bool> UploadCloud(int id)
|
|
|
|
{
|
|
|
|
List<SwapOrderReportCloud> list =
|
|
|
|
SwapOrderReportCloudRepository.QueryListByClause(i => i.CloudReportStatus < 100 && i.SwapOrderId == id);
|
|
|
|
|
|
|
|
if (list.Count <= 0)
|
|
|
|
{
|
|
|
|
return Result<bool>.Fail("当前换电订单不满足上报云平台的条件");
|
|
|
|
}
|
|
|
|
|
|
|
|
return SwapOrderMgr.UploadCloud(list, 2) ? Result<bool>.Success() : Result<bool>.Fail();
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 查询需要导出换电订单
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="swapOrder"></param>
|
|
|
|
/// <returns></returns>
|
|
|
|
public async Task<List<SwapOrder>> QuerySwapOrderListAsync(QuerySwapOrderPageReq swapOrder)
|
|
|
|
{
|
|
|
|
Expression<Func<SwapOrder, bool>> where = null;
|
|
|
|
ParameterExpression parameter = Expression.Parameter(typeof(SwapOrder), "u");
|
|
|
|
|
|
|
|
#region 构建动态查询树
|
|
|
|
|
|
|
|
where = queryTree(swapOrder, where, parameter);
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
// 查询需要导出充电订单 不分页
|
|
|
|
return await swapOrderRepository.QuerySwapOrderList(where);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 根据条件查询分页数据
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="equipAlarmLevel"></param>
|
|
|
|
/// <returns></returns>
|
|
|
|
public PageResult<SwapOrderResp> QuerySwapOrder(QuerySwapOrderPageReq swapOrder)
|
|
|
|
{
|
|
|
|
//创建一个空的表达式树
|
|
|
|
Expression<Func<SwapOrder, bool>> where = null;
|
|
|
|
//// 定义参数表达式
|
|
|
|
ParameterExpression parameter = Expression.Parameter(typeof(SwapOrder), "u");
|
|
|
|
|
|
|
|
#region 构建动态查询树
|
|
|
|
|
|
|
|
where = queryTree(swapOrder, where, parameter);
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
//查询
|
|
|
|
|
|
|
|
//var swapOrderResp = PageResult<SwapOrderResp>.ConvertPage(swapOrderRepository.QueryIPageByCause(swapOrder, where));
|
|
|
|
//for (int i = 0; i < swapOrderResp.Rows.Count; i++)
|
|
|
|
//{
|
|
|
|
// swapOrderResp.Rows[0].BatteryList.AddRange()
|
|
|
|
//}
|
|
|
|
|
|
|
|
//List<SwapOrderBatteryResp> BatteryList = new List<SwapOrderBatteryResp>();
|
|
|
|
//List<SwapOrderStepResp> StepList = new List<SwapOrderStepResp>();
|
|
|
|
return PageResult<SwapOrderResp>.ConvertPage(swapOrderRepository.QueryIPage(swapOrder, where));
|
|
|
|
}
|
|
|
|
|
|
|
|
private static Expression<Func<SwapOrder, bool>>? queryTree(QuerySwapOrderPageReq swapOrder,
|
|
|
|
Expression<Func<SwapOrder, bool>>? where, ParameterExpression parameter)
|
|
|
|
{
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (swapOrder.SwapBeginTime != null && swapOrder.SwapEndTime != null)
|
|
|
|
{
|
|
|
|
Expression<Func<SwapOrder, bool>> condition2Expr = u => u.CreatedTime >= swapOrder.SwapBeginTime && u.CreatedTime <= swapOrder.SwapEndTime;
|
|
|
|
where = where == null
|
|
|
|
? condition2Expr
|
|
|
|
: Expression.Lambda<Func<SwapOrder, bool>>(Expression.AndAlso(where.Body, condition2Expr.Body), parameter);
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
return where;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 获取每日换电订单
|
|
|
|
/// </summary>
|
|
|
|
/// <returns></returns>
|
|
|
|
public List<SwapOrder> DaySwapOrder()
|
|
|
|
{
|
|
|
|
// 获取今天的日期
|
|
|
|
DateTime today = DateTime.Today;
|
|
|
|
|
|
|
|
// 昨天 00:00
|
|
|
|
DateTime startOfYesterday = today.AddDays(-1);
|
|
|
|
|
|
|
|
// 昨天 23:59:59
|
|
|
|
DateTime endOfYesterday = startOfYesterday.AddDays(1).AddTicks(-1);
|
|
|
|
|
|
|
|
Expression<Func<SwapOrder, bool>> predicate = x => x.CreatedTime >= startOfYesterday && x.CreatedTime <= endOfYesterday;
|
|
|
|
|
|
|
|
return QueryListByClause(predicate);
|
|
|
|
}
|
|
|
|
}
|