master
tq 5 months ago
parent c0098a226b
commit 76a456eecd

@ -59,5 +59,19 @@ public class QuerySwapOrderPageReq : QueryPageModel
/// Nullable:True
/// </summary>
public int? SwapWay { get; set; }
/// <summary>
/// Desc:亏电包编码
/// Default:
/// Nullable:True
/// </summary>
public string? DownBatteryNo { get; set; }
/// <summary>
/// Desc:满电包编码
/// Default:
/// Nullable:True
/// </summary>
public string? UpBatteryNo { get; set; }
}

@ -253,5 +253,14 @@ namespace Entity.Api.Resp
/// Nullable:True
/// </summary>
public int? CanUpload { get; set; }
/// <summary>
/// Desc:交流电表量
/// Default:
/// Nullable:True
/// </summary>
public decimal? AcElecCount { get; set; }
}
}

@ -21,4 +21,7 @@ public class ElecPriceModelVersionDetailResp
/// Nullable:True
/// </summary>
public int? Type {get;set;}
public int Id {get;set;}
}

@ -203,6 +203,12 @@ namespace Entity.Api.Resp
/// Nullable:True
/// </summary>
public DateTime? UpdatedTime { get; set; }
/// <summary>
/// Desc:车辆总里程 单位kwh 保留2位有效数
/// Default:
/// Nullable:True
/// </summary>
public float? Vtm {get;set;}
}
}

@ -83,13 +83,13 @@ namespace Entity.DbModel.Station
/// 换电总时长
/// </summary>
[SugarColumn(ColumnName = "toltal_swap_all_time")]
public float ToltalSwapAllTime { get; set; }
public double ToltalSwapAllTime { get; set; }
/// <summary>
/// 站运行总时长
/// </summary>
[SugarColumn(ColumnName = "toltal_time_count")]
public float ToltalTimeCount { get; set; }
public double ToltalTimeCount { get; set; }
}

@ -233,4 +233,22 @@ public class SwapOrderDto
[ExporterHeader(DisplayName = "满电包真实soc", IsBold = true)]
public decimal? UpBatteryRealSoc { get; set; }
/// <summary>
/// Desc:放电池仓位号 亏电包仓号
/// Default:
/// Nullable:True
/// </summary>
[ExporterHeader(DisplayName = "放电池仓位号", IsBold = true)]
public int? DownBatteryBinNo { get; set; }
/// <summary>
/// Desc:取电池仓位号 满电包仓号
/// Default:
/// Nullable:True
/// </summary>
[ExporterHeader(DisplayName = "取电池仓位号", IsBold = true)]
public int? UpBatteryBinNo { get; set; }
}

@ -1,5 +1,8 @@
using System.Linq.Expressions;
using Entity.DbModel.Station;
using HybirdFrameworkCore.Autofac.Attribute;
using HybirdFrameworkCore.Entity;
using OfficeOpenXml.FormulaParsing.Excel.Functions.Text;
using SqlSugar;
namespace Repository.Station;
@ -11,4 +14,43 @@ public class SwapOrderStepRepository:BaseRepository<SwapOrderStep>
public SwapOrderStepRepository(ISqlSugarClient sqlSugar) : base(sqlSugar)
{
}
public IPage<SwapOrderStep> QueryIPage(QueryPageModel page, Expression<Func<SwapOrderStep, bool>> predicate)
{
if (null == predicate)
{
return QueryPage(page);
}
int totalCount = 0;
List<SwapOrderStep> pageList = DbBaseClient
.Queryable<SwapOrderStep>()
.Where(predicate)
.OrderByDescending(x => x.CreatedTime)
.WithNoLockOrNot(false)
.ToPageList(page.PageNum, page.PageSize, ref totalCount);
return new IPage<SwapOrderStep>(totalCount, page, pageList);
}
public IPage<SwapOrderStep> QueryPage(QueryPageModel page)
{
int totalCount = 0;
List<SwapOrderStep> pageList = DbBaseClient
.Queryable<SwapOrderStep>()
.OrderByDescending(x => x.CreatedTime)
.WithNoLockOrNot(false)
.ToPageList(page.PageNum, page.PageSize, ref totalCount);
return new IPage<SwapOrderStep>(totalCount, page, pageList);
}
}

@ -1,6 +1,7 @@
using Entity.Ammeter;
using HybirdFrameworkCore.Autofac.Attribute;
using Repository.Ammeter;
using SqlSugar;
namespace Service.Ammeter;
@ -187,22 +188,35 @@ ORDER BY
/// 获取交流电表实时数据
/// </summary>
/// <returns></returns>
public async Task<List<EmeterEnergyChange>> GetEnergyMeterRealTime()
public async Task<List<EmeterEnergyChange>> GetEnergyMeterRealTime(string endTime)
{
// 将传入的时间参数转换为DateTime类型
DateTime endDateTime = DateTime.Parse(endTime);
// 根据传入的时间参数计算7天前的时间
DateTime startDateTime = endDateTime.AddDays(-7);
// 根据code分组,取最新时间的一条数据,数据范围7天
string sql = @"
SELECT t1.*
FROM emeter_energy_change t1
JOIN (
SELECT code, MAX(upload_time) as latest_upload_time
FROM emeter_energy_change
WHERE upload_time >= NOW() - INTERVAL 7 DAY
GROUP BY code
) t2 ON t1.code = t2.code AND t1.upload_time = t2.latest_upload_time
WHERE t1.upload_time >= NOW() - INTERVAL 7 DAY;
";
SELECT t1.*
FROM emeter_energy_change t1
JOIN (
SELECT code, MAX(upload_time) as latest_upload_time
FROM emeter_energy_change
WHERE upload_time >= @StartDateTime AND upload_time <= @EndDateTime
GROUP BY code
) t2 ON t1.code = t2.code AND t1.upload_time = t2.latest_upload_time
WHERE t1.upload_time >= @StartDateTime AND t1.upload_time <= @EndDateTime;
";
List<EmeterEnergyChange> emeterEnergies = await _emeterEnergyChangeRep.SqlQueryable(sql);
return emeterEnergies;
// 使用参数化查询防止SQL注入
var parameters = new List<SugarParameter>
{
new SugarParameter("@StartDateTime", startDateTime),
new SugarParameter("@EndDateTime", endDateTime)
};
List<EmeterEnergyChange> emeterEnergyChanges = _emeterEnergyChangeRep.SqlQuery(sql, parameters);
return emeterEnergyChanges;
}
}

@ -1,6 +1,7 @@
using Entity.Ammeter;
using Entity.Api.Resp;
using HybirdFrameworkCore.Autofac.Attribute;
using Microsoft.Data.SqlClient;
using Repository.Ammeter;
using SqlSugar;
@ -199,22 +200,35 @@ ORDER BY
/// 获取直流电表实时数据
/// </summary>
/// <returns></returns>
public async Task<List<EmeterEnergy>> GetEnergyMeterRealTime()
public async Task<List<EmeterEnergy>> GetEnergyMeterRealTime(string endTime)
{
// 将传入的时间参数转换为DateTime类型
DateTime endDateTime = DateTime.Parse(endTime);
// 根据传入的时间参数计算7天前的时间
DateTime startDateTime = endDateTime.AddDays(-7);
// 根据code分组,取最新时间的一条数据,数据范围7天
string sql = @"
SELECT t1.*
FROM emeter_energy t1
JOIN (
SELECT code, MAX(upload_time) as latest_upload_time
FROM emeter_energy
WHERE upload_time >= NOW() - INTERVAL 7 DAY
GROUP BY code
) t2 ON t1.code = t2.code AND t1.upload_time = t2.latest_upload_time
WHERE t1.upload_time >= NOW() - INTERVAL 7 DAY;
";
SELECT t1.*
FROM emeter_energy t1
JOIN (
SELECT code, MAX(upload_time) as latest_upload_time
FROM emeter_energy
WHERE upload_time >= @StartDateTime AND upload_time <= @EndDateTime
GROUP BY code
) t2 ON t1.code = t2.code AND t1.upload_time = t2.latest_upload_time
WHERE t1.upload_time >= @StartDateTime AND t1.upload_time <= @EndDateTime;
";
List<EmeterEnergy> emeterEnergies = await this.BaseDal.SqlQueryable(sql);
// 使用参数化查询防止SQL注入
var parameters = new List<SugarParameter>
{
new SugarParameter("@StartDateTime", startDateTime),
new SugarParameter("@EndDateTime", endDateTime)
};
List<EmeterEnergy> emeterEnergies = this.BaseDal.SqlQuery(sql, parameters);
return emeterEnergies;
}
}

@ -0,0 +1,126 @@
using Entity.Constant;
using Entity.DbModel.Station;
using HybirdFrameworkCore.Autofac.Attribute;
using HybirdFrameworkCore.AutoTask;
using log4net;
using Service.Init;
using Service.Station;
namespace Service.MyTask;
/// <summary>
/// 统计每日运行
/// </summary>
[Scope]
public class CountDayOrderTask : ITask
{
private static readonly ILog Log = LogManager.GetLogger(typeof(CountDayOrderTask));
private volatile bool _stop;
public ChargeOrderService _ChargeOrderService { get; set; }
public SwapOrderService _SwapOrderService { get; set; }
public ExStationDayRunResultService _ExStationDayRunResultService { get; set; }
public string Name()
{
return "CountDayOrderTask";
}
public int Interval()
{
return 1000 * 86400;
}
public void Handle()
{
// 统计每日运行
CountOrder();
}
public bool Stoped()
{
return _stop;
}
public void Stop()
{
_stop = true;
}
public void ResetStop()
{
_stop = false;
}
public void CountOrder()
{
// 获取 ChargeOrder 和 SwapOrder 列表
List<ChargeOrder> orders = _ChargeOrderService.DayChargeOrder();
List<SwapOrder> daySwapOrder = _SwapOrderService.DaySwapOrder();
// 创建 ExchangeStationDayRunResult 实例
ExchangeStationDayRunResult dayCount = new ExchangeStationDayRunResult();
// 计算平均充电时间(分钟)
double avgMinutes = orders
.Where(order => order.StartTime.HasValue && order.EndTime.HasValue)
.Select(order => (order.EndTime.Value - order.StartTime.Value).TotalMinutes)
.DefaultIfEmpty(0.0)
.Average();
// 计算平均换电时间(分钟)
double avgRepTime = daySwapOrder
.Where(order => order.SwapBeginTime.HasValue && order.SwapEndTime.HasValue)
.Select(order => (order.SwapEndTime.Value - order.SwapBeginTime.Value).TotalMinutes)
.DefaultIfEmpty(0.0)
.Average();
// 找到最早的换电时间
SwapOrder firstSwapOrder = daySwapOrder
.Where(order => order.SwapBeginTime.HasValue)
.OrderBy(order => order.SwapBeginTime)
.FirstOrDefault();
// 找到最晚的换电时间
SwapOrder lastSwapOrder = daySwapOrder
.Where(order => order.SwapEndTime.HasValue)
.OrderByDescending(order => order.SwapEndTime)
.FirstOrDefault();
// 统计充电次数
int chgCount = orders
.Where(order => !string.IsNullOrEmpty(order.Sn))
.Select(order => order.Sn)
.Distinct()
.Count();
// 统计换电次数
int totalSwapCount = daySwapOrder
.Where(order => !string.IsNullOrEmpty(order.Sn))
.Select(order => order.Sn)
.Distinct()
.Count();
// 计算总共换电多少分钟
double totalMinutes = daySwapOrder
.Where(order => order.SwapBeginTime.HasValue && order.SwapEndTime.HasValue)
.Sum(order => (order.SwapEndTime.Value - order.SwapBeginTime.Value).TotalMinutes);
// 赋值
dayCount.AvgChgTime = avgMinutes.ToString();
dayCount.AvgRepTime = avgRepTime.ToString();
dayCount.SwapDate = DateTime.Now.ToString();
dayCount.FristSwapTime = firstSwapOrder?.SwapBeginTime?.ToString() ?? null;
dayCount.StopTime = lastSwapOrder?.SwapEndTime?.ToString() ?? null;
dayCount.ChgCount = chgCount;
dayCount.ToltalSwapCount = totalSwapCount;
dayCount.ToltalSwapAllTime = totalMinutes;
dayCount.State = StaticStationInfo.StationStatus;
_ExStationDayRunResultService.Insert(dayCount);
}
}

@ -112,19 +112,18 @@ public class ChargeOrderService : BaseServices<ChargeOrder>
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 (chargeOrder.StartTime != null && chargeOrder.StartTime != DateTime.MinValue)
// 构建时间范围条件
if (chargeOrder.StartTime != null && chargeOrder.StartTime != DateTime.MinValue && chargeOrder.EndTime != null && chargeOrder.EndTime != 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);
Expression<Func<ChargeOrder, bool>> conditionExpr = u => u.CreatedTime >= chargeOrder.StartTime && u.CreatedTime <= chargeOrder.EndTime;
where = conditionExpr;
}
if (chargeOrder.ChargeTimeCount!=null)
{
Expression<Func<ChargeOrder, bool>> condition2Expr = u => u.ChargeTimeCount == chargeOrder.ChargeTimeCount;
@ -181,4 +180,23 @@ public class ChargeOrderService : BaseServices<ChargeOrder>
CloudClientMgr.CloudClient?.PublishChargeOrder(orders, 2);
return Result<bool>.Success();
}
/// <summary>
/// 获取每日充电订单
/// </summary>
/// <returns></returns>
public List<ChargeOrder> DayChargeOrder()
{
// 获取今天的日期
DateTime today = DateTime.Today;
// 昨天 00:00
DateTime startOfYesterday = today.AddDays(-1);
// 昨天 23:59:59
DateTime endOfYesterday = startOfYesterday.AddDays(1).AddTicks(-1);
Expression<Func<ChargeOrder, bool>> predicate = x => x.CreatedTime >= startOfYesterday && x.CreatedTime <= endOfYesterday;
return QueryListByClause(predicate);
}
}

@ -84,4 +84,36 @@ public class SwapOrderBatteryService : BaseServices<SwapOrderBattery>
}
public PageResult<SwapOrderBatteryResp> QuerySwapOrderBatteryList(QuerySwapOrderPageReq swapOrderBattery)
{
//创建一个空的表达式树
Expression<Func<SwapOrderBattery, bool>> where = null;
//// 定义参数表达式
ParameterExpression parameter = Expression.Parameter(typeof(SwapOrderBattery), "u");
if (!string.IsNullOrEmpty(swapOrderBattery.DownBatteryNo))
{
Expression<Func<SwapOrderBattery, bool>> condition2Expr = u => u.DownBatteryNo == swapOrderBattery.DownBatteryNo;
where = where == null ? condition2Expr : Expression.Lambda<Func<SwapOrderBattery, bool>>(Expression.AndAlso(where.Body, condition2Expr.Body), parameter);
}
if (!string.IsNullOrEmpty(swapOrderBattery.UpBatteryNo))
{
Expression<Func<SwapOrderBattery, bool>> condition2Expr = u => u.UpBatteryNo == swapOrderBattery.UpBatteryNo;
where = where == null ? condition2Expr : Expression.Lambda<Func<SwapOrderBattery, bool>>(Expression.AndAlso(where.Body, condition2Expr.Body), parameter);
}
if (swapOrderBattery.SwapBeginTime != null && swapOrderBattery.SwapEndTime != null)
{
Expression<Func<SwapOrderBattery, bool>> condition2Expr = u => u.CreatedTime >= swapOrderBattery.SwapBeginTime && u.CreatedTime <= swapOrderBattery.SwapEndTime;
where = where == null
? condition2Expr
: Expression.Lambda<Func<SwapOrderBattery, bool>>(Expression.AndAlso(where.Body, condition2Expr.Body), parameter);
}
return PageResult<SwapOrderBatteryResp>.ConvertPage(_swapOrderBatteryRepository.QueryIPageByCause(swapOrderBattery, where));
//查询
}
}

@ -151,23 +151,13 @@ public class SwapOrderService : BaseServices<SwapOrder>
: Expression.Lambda<Func<SwapOrder, bool>>(Expression.AndAlso(where.Body, condition2Expr.Body),
parameter);
}
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);
}
if (swapOrder.SwapEndTime != null && swapOrder.SwapEndTime != DateTime.MinValue)
if (swapOrder.SwapBeginTime != null && swapOrder.SwapEndTime != null)
{
Expression<Func<SwapOrder, bool>> condition2Expr = u => u.SwapEndTime == swapOrder.SwapEndTime;
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);
: Expression.Lambda<Func<SwapOrder, bool>>(Expression.AndAlso(where.Body, condition2Expr.Body), parameter);
}
if (swapOrder.SwapResult != 0)
@ -181,4 +171,24 @@ public class SwapOrderService : BaseServices<SwapOrder>
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);
}
}

@ -69,9 +69,21 @@ public class SwapOrderStepService : BaseServices<SwapOrderStep>
parameter);
}
//<2F><>ѯ
return PageResult<SwapOrderStepResp>.ConvertPage(
_swapOrderStepRepository.QueryIPageByCause(swapOrderStep, where));
// 查询结果
IPage<SwapOrderStep> queryResult = _swapOrderStepRepository.QueryIPage(swapOrderStep, where);
// 增加排序
var sortedList = queryResult.Rows
.OrderBy(u => u.SwapOrderSn)
.ThenBy(u => u.Step)
.ToList();
// 构建新的 IPage 对象
var sortedResult = new IPage<SwapOrderStep>(queryResult.Total, swapOrderStep, sortedList);
return PageResult<SwapOrderStepResp>.ConvertPage(sortedResult);
}

@ -158,11 +158,19 @@ namespace WebStarter.Controllers.Ammeter
/// </summary>
/// <returns></returns>
[HttpGet("GetEnergyMeterRealTime")]
public async Task<Result<EmeterEnergyResp>> GetEnergyMeterRealTime()
public async Task<Result<EmeterEnergyResp>> GetEnergyMeterRealTime(string endTime)
{
// 不传值时查实时
if (!DateTime.TryParse(endTime, out DateTime parsedEndTime))
{
parsedEndTime = DateTime.Now;
}
endTime = parsedEndTime.ToString("yyyy-MM-dd HH:mm:ss");
// 获取实时直流和交流表数据
List<EmeterEnergy> minutesElectrical = await _emeterEnergyService.GetEnergyMeterRealTime();
List<EmeterEnergyChange> minutesElectricalChange = await _emeterEnergyChangeService.GetEnergyMeterRealTime();
List<EmeterEnergy> minutesElectrical = await _emeterEnergyService.GetEnergyMeterRealTime(endTime);
List<EmeterEnergyChange> minutesElectricalChange = await _emeterEnergyChangeService.GetEnergyMeterRealTime(endTime);
EmeterEnergyResp resp = new EmeterEnergyResp();

@ -189,6 +189,7 @@ namespace WebStarter.Controllers.BasicConfig
{
elecPriceModelVersionDetailResps.Add(new ElecPriceModelVersionDetailResp()
{
Id = item.Id,
Version = item.Version,
StartTime = new TimeSpan(item.StartHour, item.StartMinute, item.StartSecond),
EndTime = new TimeSpan(item.EndHour, item.EndMinute, item.EndSecond),
@ -321,6 +322,25 @@ namespace WebStarter.Controllers.BasicConfig
return notHasOverlap;
}
/// <summary>
/// 删除电价信息
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
[HttpPost]
[Route("RemovePriceConfig/{id}")]
public Result<bool> RemovePriceConfig(int id)
{
if (_elecPriceModelVersionDetailServices.DeleteById(id))
{
return Result<bool>.Success(true,"删除成功");
}
else
{
return Result<bool>.Fail("删除失败");
}
}
/// <summary>
/// 设置类属性

@ -7,6 +7,7 @@ using Entity.Dto;
using HybirdFrameworkCore.Entity;
using Magicodes.ExporterAndImporter.Excel;
using Microsoft.AspNetCore.Mvc;
using Repository.Station;
using Service.Init;
using Service.Station;
using Swapping.Business.Common;
@ -23,13 +24,15 @@ public class SwapOrderController : ControllerBase
private readonly SwapOrderService swapOrderService;
private readonly SwapOrderBatteryService swapOrderBatteryService;
private readonly SwapOrderStepService swapOrderStepService;
private readonly SwapOrderReportCloudRepository swapOrderReportCloudRepository;
public SwapOrderController(SwapOrderService swapOrderService, SwapOrderBatteryService swapOrderBatteryService,
SwapOrderStepService swapOrderStepService)
SwapOrderStepService swapOrderStepService,SwapOrderReportCloudRepository swapOrderReportCloudRepository)
{
this.swapOrderService = swapOrderService;
this.swapOrderBatteryService = swapOrderBatteryService;
this.swapOrderStepService = swapOrderStepService;
this.swapOrderReportCloudRepository = swapOrderReportCloudRepository;
}
/// <summary>
@ -39,11 +42,84 @@ public class SwapOrderController : ControllerBase
[HttpPost("QueryPage")]
public async Task<Result<PageResult<SwapOrderResp>>> QueryPage([FromBody] QuerySwapOrderPageReq req)
{
var swapOrderResp = swapOrderService.QuerySwapOrder(req);
if (!string.IsNullOrEmpty(req.DownBatteryNo)||!string.IsNullOrEmpty(req.UpBatteryNo))
{
var result = BatteryCodeList(req);
return Result<PageResult<SwapOrderResp>>.Success(result);
}
var swapOrderResp = swapOrderService.QuerySwapOrder(req);
//获取所有订单号
var orderSns = swapOrderResp.Rows.Select(row => row.Sn).ToList();
//查询上报云平台次数
Dictionary<string, int?> queryReportCloudNumBySn = swapOrderService.QueryReportCloudNumBySn(orderSns);
////查询订单电池数据
List<SwapOrderBattery> batteryList =
swapOrderBatteryService.QueryListByClause(u => orderSns.Contains(u.SwapOrderSn));
//映射
var config =
new MapperConfiguration(cfg => cfg.CreateMap<SwapOrderBatteryResp, SwapOrderBattery>().ReverseMap());
IMapper mapper = config.CreateMapper();
List<SwapOrderBatteryResp> swapOrderBattery = mapper.Map<List<SwapOrderBatteryResp>>(batteryList);
List<SwapOrderReportCloud> swapOrderReportClouds = swapOrderReportCloudRepository.QueryListByClause(u => orderSns.Contains(u.SwapOrderSn));
//将电池数据添加到换电订单数据中
foreach (var row in swapOrderResp.Rows)
{
row.BatteryList = swapOrderBattery.Where(battery => battery.SwapOrderSn == row.Sn).ToList();
queryReportCloudNumBySn.TryGetValue(row.Sn, out int? num);
row.ReportCloudNum = num ?? 0;
var matchingReport = swapOrderReportClouds.FirstOrDefault(r => r.SwapOrderSn == row.Sn);
if (matchingReport != null)
{
foreach (var battery in row.BatteryList)
{
battery.Vtm = matchingReport.Vtm;
}
}
}
//查询订单步序数据
var stepList = swapOrderStepService.QueryListByClause(u => orderSns.Contains(u.SwapOrderSn));
stepList = stepList.OrderBy(s => s.Sort).ToList();
//映射
var config2 = new MapperConfiguration(cfg => cfg.CreateMap<SwapOrderStep, SwapOrderStepResp>().ReverseMap());
IMapper mapper2 = config2.CreateMapper();
List<SwapOrderStepResp> swapOrderStep = mapper2.Map<List<SwapOrderStepResp>>(stepList);
//将步序数据添加到换电订单数据中
for (int i = 0; i < swapOrderResp.Rows.Count; i++)
{
swapOrderResp.Rows[i].StepList = new List<SwapOrderStepResp>();
swapOrderResp.Rows[i].StepList
.AddRange(swapOrderStep.Where(step => step.SwapOrderSn == swapOrderResp.Rows[i].Sn).ToList());
}
return Result<PageResult<SwapOrderResp>>.Success(swapOrderResp);
}
private PageResult<SwapOrderResp> BatteryCodeList(QuerySwapOrderPageReq req)
{
PageResult<SwapOrderBatteryResp> batteryCodeList = swapOrderBatteryService.QuerySwapOrderBatteryList(req);
var batteryOrderSn = batteryCodeList.Rows.Select(row => row.SwapOrderSn).ToList();
List<SwapOrder> swapOrderRespList = swapOrderService.QueryListByClause(u => batteryOrderSn.Contains(u.Sn));
//获取所有订单号
var orderSns = swapOrderRespList.Select(row => row.Sn).ToList();
//查询上报云平台次数
Dictionary<string, int?> queryReportCloudNumBySn = swapOrderService.QueryReportCloudNumBySn(orderSns);
@ -51,27 +127,37 @@ public class SwapOrderController : ControllerBase
////查询订单电池数据
List<SwapOrderBattery> batteryList =
swapOrderBatteryService.QueryListByClause(u => orderSns.Contains(u.SwapOrderSn));
var config = new MapperConfiguration(cfg =>
{
cfg.CreateMap<SwapOrderResp, SwapOrder>().ReverseMap();
cfg.CreateMap<SwapOrderBatteryResp, SwapOrderBattery>().ReverseMap();
});
//映射
var config =
new MapperConfiguration(cfg => cfg.CreateMap<SwapOrderBatteryResp, SwapOrderBattery>().ReverseMap());
IMapper mapper = config.CreateMapper();
List<SwapOrderBatteryResp> swapOrderBattery = mapper.Map<List<SwapOrderBatteryResp>>(batteryList);
List<SwapOrderResp> swapOrderResp = mapper.Map<List<SwapOrderResp>>(swapOrderRespList);
List<SwapOrderReportCloud> swapOrderReportClouds = swapOrderReportCloudRepository.QueryListByClause(u => orderSns.Contains(u.SwapOrderSn));
//将电池数据添加到换电订单数据中
for (int i = 0; i < swapOrderResp.Rows.Count; i++)
foreach (var row in swapOrderResp)
{
swapOrderResp.Rows[i].BatteryList = new List<SwapOrderBatteryResp>();
swapOrderResp.Rows[i].BatteryList.AddRange(swapOrderBattery
.Where(battery => battery.SwapOrderSn == swapOrderResp.Rows[i].Sn).ToList());
queryReportCloudNumBySn.TryGetValue(swapOrderResp.Rows[i].Sn, out int? num);
if (num == null)
row.BatteryList = swapOrderBattery.Where(battery => battery.SwapOrderSn == row.Sn).ToList();
queryReportCloudNumBySn.TryGetValue(row.Sn, out int? num);
row.ReportCloudNum = num ?? 0;
var matchingReport = swapOrderReportClouds.FirstOrDefault(r => r.SwapOrderSn == row.Sn);
if (matchingReport != null)
{
num = 0;
foreach (var battery in row.BatteryList)
{
battery.Vtm = matchingReport.Vtm;
}
}
swapOrderResp.Rows[i].ReportCloudNum = num;
}
//查询订单步序数据
@ -85,14 +171,21 @@ public class SwapOrderController : ControllerBase
//将步序数据添加到换电订单数据中
for (int i = 0; i < swapOrderResp.Rows.Count; i++)
for (int i = 0; i < swapOrderResp.Count; i++)
{
swapOrderResp.Rows[i].StepList = new List<SwapOrderStepResp>();
swapOrderResp.Rows[i].StepList
.AddRange(swapOrderStep.Where(step => step.SwapOrderSn == swapOrderResp.Rows[i].Sn).ToList());
swapOrderResp[i].StepList = new List<SwapOrderStepResp>();
swapOrderResp[i].StepList
.AddRange(swapOrderStep.Where(step => step.SwapOrderSn == swapOrderResp[i].Sn).ToList());
}
return Result<PageResult<SwapOrderResp>>.Success(swapOrderResp);
PageResult<SwapOrderResp> result = new PageResult<SwapOrderResp>()
{
PageNum = req.PageNum,
PageSize = req.PageSize,
ToTal = batteryCodeList.ToTal,
Rows = swapOrderResp
};
return result;
}
/// <summary>
@ -261,6 +354,8 @@ public class SwapOrderController : ControllerBase
dto.UpBatteryNo = swapOrderBatteryResp.UpBatteryNo;
dto.UpBatterySoc = swapOrderBatteryResp.UpBatterySoc;
dto.UpBatteryRealSoc = swapOrderBatteryResp.UpBatteryRealSoc;
dto.DownBatteryBinNo = swapOrderBatteryResp.DownBatteryBinNo;
dto.UpBatteryBinNo = swapOrderBatteryResp.UpBatteryBinNo;
}
}

@ -49,3 +49,9 @@ ALTER TABLE bin_info ADD `in_time` datetime DEFAULT NULL COMMENT "入仓时间"
-- 添加站外充电枪编号
ALTER TABLE charge_order ADD COLUMN out_charger_gun_no VARCHAR(255) COMMENT '站外充电枪编号,1枪或2枪';
-- 每日运行double
ALTER TABLE exchange_station_day_count_result MODIFY COLUMN toltal_swap_all_time DOUBLE;
ALTER TABLE exchange_station_day_count_result MODIFY COLUMN toltal_time_count DOUBLE;

Loading…
Cancel
Save