diff --git a/Entity/Api/Req/QuerySwapOrderPageReq.cs b/Entity/Api/Req/QuerySwapOrderPageReq.cs index 1c36a6a..60b1a73 100644 --- a/Entity/Api/Req/QuerySwapOrderPageReq.cs +++ b/Entity/Api/Req/QuerySwapOrderPageReq.cs @@ -59,5 +59,19 @@ public class QuerySwapOrderPageReq : QueryPageModel /// Nullable:True /// public int? SwapWay { get; set; } - + + + /// + /// Desc:亏电包编码 + /// Default: + /// Nullable:True + /// + public string? DownBatteryNo { get; set; } + + /// + /// Desc:满电包编码 + /// Default: + /// Nullable:True + /// + public string? UpBatteryNo { get; set; } } \ No newline at end of file diff --git a/Entity/Api/Resp/ChargeOrderResp.cs b/Entity/Api/Resp/ChargeOrderResp.cs index 8689341..6b9e545 100644 --- a/Entity/Api/Resp/ChargeOrderResp.cs +++ b/Entity/Api/Resp/ChargeOrderResp.cs @@ -253,5 +253,14 @@ namespace Entity.Api.Resp /// Nullable:True /// public int? CanUpload { get; set; } + + + /// + /// Desc:交流电表量 + /// Default: + /// Nullable:True + /// + public decimal? AcElecCount { get; set; } + } } diff --git a/Entity/Api/Resp/ElecPriceModelVersionDetailResp.cs b/Entity/Api/Resp/ElecPriceModelVersionDetailResp.cs index 4b93e6d..f88d349 100644 --- a/Entity/Api/Resp/ElecPriceModelVersionDetailResp.cs +++ b/Entity/Api/Resp/ElecPriceModelVersionDetailResp.cs @@ -21,4 +21,7 @@ public class ElecPriceModelVersionDetailResp /// Nullable:True /// public int? Type {get;set;} + + public int Id {get;set;} + } \ No newline at end of file diff --git a/Entity/Api/Resp/SwapOrderBatteryResp.cs b/Entity/Api/Resp/SwapOrderBatteryResp.cs index b25b77f..76dd6b9 100644 --- a/Entity/Api/Resp/SwapOrderBatteryResp.cs +++ b/Entity/Api/Resp/SwapOrderBatteryResp.cs @@ -203,6 +203,12 @@ namespace Entity.Api.Resp /// Nullable:True /// public DateTime? UpdatedTime { get; set; } - + + /// + /// Desc:车辆总里程 单位:kwh 保留2位有效数 + /// Default: + /// Nullable:True + /// + public float? Vtm {get;set;} } } diff --git a/Entity/DbModel/Station/ExchangeStationDayRunResult.cs b/Entity/DbModel/Station/ExchangeStationDayRunResult.cs index 0ee0f07..a0465de 100644 --- a/Entity/DbModel/Station/ExchangeStationDayRunResult.cs +++ b/Entity/DbModel/Station/ExchangeStationDayRunResult.cs @@ -83,13 +83,13 @@ namespace Entity.DbModel.Station /// 换电总时长 /// [SugarColumn(ColumnName = "toltal_swap_all_time")] - public float ToltalSwapAllTime { get; set; } + public double ToltalSwapAllTime { get; set; } /// /// 站运行总时长 /// [SugarColumn(ColumnName = "toltal_time_count")] - public float ToltalTimeCount { get; set; } + public double ToltalTimeCount { get; set; } } diff --git a/Entity/Dto/SwapOrderDto.cs b/Entity/Dto/SwapOrderDto.cs index e2d25b7..349b6d3 100644 --- a/Entity/Dto/SwapOrderDto.cs +++ b/Entity/Dto/SwapOrderDto.cs @@ -233,4 +233,22 @@ public class SwapOrderDto [ExporterHeader(DisplayName = "满电包真实soc", IsBold = true)] public decimal? UpBatteryRealSoc { get; set; } + + + /// + /// Desc:放电池仓位号 亏电包仓号 + /// Default: + /// Nullable:True + /// + [ExporterHeader(DisplayName = "放电池仓位号", IsBold = true)] + public int? DownBatteryBinNo { get; set; } + + /// + /// Desc:取电池仓位号 满电包仓号 + /// Default: + /// Nullable:True + /// + [ExporterHeader(DisplayName = "取电池仓位号", IsBold = true)] + + public int? UpBatteryBinNo { get; set; } } \ No newline at end of file diff --git a/Repository/Station/SwapOrderStepRepository.cs b/Repository/Station/SwapOrderStepRepository.cs index 9c03534..0241b58 100644 --- a/Repository/Station/SwapOrderStepRepository.cs +++ b/Repository/Station/SwapOrderStepRepository.cs @@ -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 public SwapOrderStepRepository(ISqlSugarClient sqlSugar) : base(sqlSugar) { } + + public IPage QueryIPage(QueryPageModel page, Expression> predicate) + { + if (null == predicate) + { + return QueryPage(page); + } + + int totalCount = 0; + + + List pageList = DbBaseClient + .Queryable() + .Where(predicate) + .OrderByDescending(x => x.CreatedTime) + .WithNoLockOrNot(false) + .ToPageList(page.PageNum, page.PageSize, ref totalCount); + + return new IPage(totalCount, page, pageList); + } + + public IPage QueryPage(QueryPageModel page) + { + int totalCount = 0; + + + List pageList = DbBaseClient + .Queryable() + .OrderByDescending(x => x.CreatedTime) + .WithNoLockOrNot(false) + .ToPageList(page.PageNum, page.PageSize, ref totalCount); + + return new IPage(totalCount, page, pageList); + } + + + + + } \ No newline at end of file diff --git a/Service/Ammeter/EmeterEnergyChangeService.cs b/Service/Ammeter/EmeterEnergyChangeService.cs index bba64a0..eaef956 100644 --- a/Service/Ammeter/EmeterEnergyChangeService.cs +++ b/Service/Ammeter/EmeterEnergyChangeService.cs @@ -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 /// 获取交流电表实时数据 /// /// - public async Task> GetEnergyMeterRealTime() + public async Task> 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 emeterEnergies = await _emeterEnergyChangeRep.SqlQueryable(sql); - return emeterEnergies; + // 使用参数化查询防止SQL注入 + var parameters = new List + { + new SugarParameter("@StartDateTime", startDateTime), + new SugarParameter("@EndDateTime", endDateTime) + }; + + List emeterEnergyChanges = _emeterEnergyChangeRep.SqlQuery(sql, parameters); + return emeterEnergyChanges; } } \ No newline at end of file diff --git a/Service/Ammeter/EmeterEnergyService.cs b/Service/Ammeter/EmeterEnergyService.cs index ee33709..09bdeaa 100644 --- a/Service/Ammeter/EmeterEnergyService.cs +++ b/Service/Ammeter/EmeterEnergyService.cs @@ -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 /// 获取直流电表实时数据 /// /// - public async Task> GetEnergyMeterRealTime() + public async Task> 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 emeterEnergies = await this.BaseDal.SqlQueryable(sql); + // 使用参数化查询防止SQL注入 + var parameters = new List + { + new SugarParameter("@StartDateTime", startDateTime), + new SugarParameter("@EndDateTime", endDateTime) + }; + + List emeterEnergies = this.BaseDal.SqlQuery(sql, parameters); return emeterEnergies; } } \ No newline at end of file diff --git a/Service/MyTask/CountDayOrderTask.cs b/Service/MyTask/CountDayOrderTask.cs new file mode 100644 index 0000000..a3c7ff5 --- /dev/null +++ b/Service/MyTask/CountDayOrderTask.cs @@ -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; + +/// +/// 统计每日运行 +/// +[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 orders = _ChargeOrderService.DayChargeOrder(); + List 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); + } +} \ No newline at end of file diff --git a/Service/Station/ChargeOrderService.cs b/Service/Station/ChargeOrderService.cs index e2064a7..61c04a8 100644 --- a/Service/Station/ChargeOrderService.cs +++ b/Service/Station/ChargeOrderService.cs @@ -112,19 +112,18 @@ public class ChargeOrderService : BaseServices 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) + // 构建时间范围条件 + if (chargeOrder.StartTime != null && chargeOrder.StartTime != DateTime.MinValue && chargeOrder.EndTime != null && chargeOrder.EndTime != 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); + Expression> conditionExpr = u => u.CreatedTime >= chargeOrder.StartTime && u.CreatedTime <= chargeOrder.EndTime; + where = conditionExpr; } + + if (chargeOrder.ChargeTimeCount!=null) { Expression> condition2Expr = u => u.ChargeTimeCount == chargeOrder.ChargeTimeCount; @@ -181,4 +180,23 @@ public class ChargeOrderService : BaseServices CloudClientMgr.CloudClient?.PublishChargeOrder(orders, 2); return Result.Success(); } + /// + /// 获取每日充电订单 + /// + /// + public List DayChargeOrder() + { + // 获取今天的日期 + DateTime today = DateTime.Today; + + // 昨天 00:00 + DateTime startOfYesterday = today.AddDays(-1); + + // 昨天 23:59:59 + DateTime endOfYesterday = startOfYesterday.AddDays(1).AddTicks(-1); + + Expression> predicate = x => x.CreatedTime >= startOfYesterday && x.CreatedTime <= endOfYesterday; + + return QueryListByClause(predicate); + } } diff --git a/Service/Station/SwapOrderBatteryService.cs b/Service/Station/SwapOrderBatteryService.cs index a78c175..b554607 100644 --- a/Service/Station/SwapOrderBatteryService.cs +++ b/Service/Station/SwapOrderBatteryService.cs @@ -84,4 +84,36 @@ public class SwapOrderBatteryService : BaseServices } + + public PageResult QuerySwapOrderBatteryList(QuerySwapOrderPageReq swapOrderBattery) + { + + //创建一个空的表达式树 + Expression> where = null; + //// 定义参数表达式 + ParameterExpression parameter = Expression.Parameter(typeof(SwapOrderBattery), "u"); + + if (!string.IsNullOrEmpty(swapOrderBattery.DownBatteryNo)) + { + Expression> condition2Expr = u => u.DownBatteryNo == swapOrderBattery.DownBatteryNo; + where = where == null ? condition2Expr : Expression.Lambda>(Expression.AndAlso(where.Body, condition2Expr.Body), parameter); + } + + if (!string.IsNullOrEmpty(swapOrderBattery.UpBatteryNo)) + { + Expression> condition2Expr = u => u.UpBatteryNo == swapOrderBattery.UpBatteryNo; + where = where == null ? condition2Expr : Expression.Lambda>(Expression.AndAlso(where.Body, condition2Expr.Body), parameter); + } + + if (swapOrderBattery.SwapBeginTime != null && swapOrderBattery.SwapEndTime != null) + { + Expression> condition2Expr = u => u.CreatedTime >= swapOrderBattery.SwapBeginTime && u.CreatedTime <= swapOrderBattery.SwapEndTime; + where = where == null + ? condition2Expr + : Expression.Lambda>(Expression.AndAlso(where.Body, condition2Expr.Body), parameter); + } + + return PageResult.ConvertPage(_swapOrderBatteryRepository.QueryIPageByCause(swapOrderBattery, where)); + //查询 + } } \ No newline at end of file diff --git a/Service/Station/SwapOrderService.cs b/Service/Station/SwapOrderService.cs index f1c04d8..319927b 100644 --- a/Service/Station/SwapOrderService.cs +++ b/Service/Station/SwapOrderService.cs @@ -151,23 +151,13 @@ public class SwapOrderService : BaseServices : Expression.Lambda>(Expression.AndAlso(where.Body, condition2Expr.Body), parameter); } - - if (swapOrder.SwapBeginTime != null && swapOrder.SwapBeginTime != DateTime.MinValue) - { - Expression> condition2Expr = u => u.SwapBeginTime == swapOrder.SwapBeginTime; - where = where == null - ? condition2Expr - : Expression.Lambda>(Expression.AndAlso(where.Body, condition2Expr.Body), - parameter); - } - - if (swapOrder.SwapEndTime != null && swapOrder.SwapEndTime != DateTime.MinValue) + + if (swapOrder.SwapBeginTime != null && swapOrder.SwapEndTime != null) { - Expression> condition2Expr = u => u.SwapEndTime == swapOrder.SwapEndTime; + Expression> condition2Expr = u => u.CreatedTime >= swapOrder.SwapBeginTime && u.CreatedTime <= swapOrder.SwapEndTime; where = where == null ? condition2Expr - : Expression.Lambda>(Expression.AndAlso(where.Body, condition2Expr.Body), - parameter); + : Expression.Lambda>(Expression.AndAlso(where.Body, condition2Expr.Body), parameter); } if (swapOrder.SwapResult != 0) @@ -181,4 +171,24 @@ public class SwapOrderService : BaseServices return where; } + + /// + /// 获取每日换电订单 + /// + /// + public List DaySwapOrder() + { + // 获取今天的日期 + DateTime today = DateTime.Today; + + // 昨天 00:00 + DateTime startOfYesterday = today.AddDays(-1); + + // 昨天 23:59:59 + DateTime endOfYesterday = startOfYesterday.AddDays(1).AddTicks(-1); + + Expression> predicate = x => x.CreatedTime >= startOfYesterday && x.CreatedTime <= endOfYesterday; + + return QueryListByClause(predicate); + } } \ No newline at end of file diff --git a/Service/Station/SwapOrderStepService.cs b/Service/Station/SwapOrderStepService.cs index fd44d4b..7a7110e 100644 --- a/Service/Station/SwapOrderStepService.cs +++ b/Service/Station/SwapOrderStepService.cs @@ -69,9 +69,21 @@ public class SwapOrderStepService : BaseServices parameter); } - //��ѯ - return PageResult.ConvertPage( - _swapOrderStepRepository.QueryIPageByCause(swapOrderStep, where)); + // 查询结果 + IPage queryResult = _swapOrderStepRepository.QueryIPage(swapOrderStep, where); + + + // 增加排序 + var sortedList = queryResult.Rows + .OrderBy(u => u.SwapOrderSn) + .ThenBy(u => u.Step) + .ToList(); + + + // 构建新的 IPage 对象 + var sortedResult = new IPage(queryResult.Total, swapOrderStep, sortedList); + return PageResult.ConvertPage(sortedResult); + } diff --git a/WebStarter/Controllers/Ammeter/AmmeterController.cs b/WebStarter/Controllers/Ammeter/AmmeterController.cs index 9a4977f..ac075ae 100644 --- a/WebStarter/Controllers/Ammeter/AmmeterController.cs +++ b/WebStarter/Controllers/Ammeter/AmmeterController.cs @@ -158,11 +158,19 @@ namespace WebStarter.Controllers.Ammeter /// /// [HttpGet("GetEnergyMeterRealTime")] - public async Task> GetEnergyMeterRealTime() + public async Task> GetEnergyMeterRealTime(string endTime) { + // 不传值时查实时 + if (!DateTime.TryParse(endTime, out DateTime parsedEndTime)) + { + parsedEndTime = DateTime.Now; + } + + endTime = parsedEndTime.ToString("yyyy-MM-dd HH:mm:ss"); + // 获取实时直流和交流表数据 - List minutesElectrical = await _emeterEnergyService.GetEnergyMeterRealTime(); - List minutesElectricalChange = await _emeterEnergyChangeService.GetEnergyMeterRealTime(); + List minutesElectrical = await _emeterEnergyService.GetEnergyMeterRealTime(endTime); + List minutesElectricalChange = await _emeterEnergyChangeService.GetEnergyMeterRealTime(endTime); EmeterEnergyResp resp = new EmeterEnergyResp(); diff --git a/WebStarter/Controllers/BasicConfig/BaseConfigController.cs b/WebStarter/Controllers/BasicConfig/BaseConfigController.cs index d6c183a..dc2e4bd 100644 --- a/WebStarter/Controllers/BasicConfig/BaseConfigController.cs +++ b/WebStarter/Controllers/BasicConfig/BaseConfigController.cs @@ -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; } + + /// + /// 删除电价信息 + /// + /// + /// + [HttpPost] + [Route("RemovePriceConfig/{id}")] + public Result RemovePriceConfig(int id) + { + if (_elecPriceModelVersionDetailServices.DeleteById(id)) + { + return Result.Success(true,"删除成功"); + } + else + { + return Result.Fail("删除失败"); + } + } /// /// 设置类属性 diff --git a/WebStarter/Controllers/SwapOrderController.cs b/WebStarter/Controllers/SwapOrderController.cs index a56c37c..e1aadc9 100644 --- a/WebStarter/Controllers/SwapOrderController.cs +++ b/WebStarter/Controllers/SwapOrderController.cs @@ -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; } /// @@ -39,11 +42,84 @@ public class SwapOrderController : ControllerBase [HttpPost("QueryPage")] public async Task>> QueryPage([FromBody] QuerySwapOrderPageReq req) { - var swapOrderResp = swapOrderService.QuerySwapOrder(req); + + if (!string.IsNullOrEmpty(req.DownBatteryNo)||!string.IsNullOrEmpty(req.UpBatteryNo)) + { + var result = BatteryCodeList(req); + return Result>.Success(result); + } + var swapOrderResp = swapOrderService.QuerySwapOrder(req); + //获取所有订单号 var orderSns = swapOrderResp.Rows.Select(row => row.Sn).ToList(); + + //查询上报云平台次数 + Dictionary queryReportCloudNumBySn = swapOrderService.QueryReportCloudNumBySn(orderSns); + + + ////查询订单电池数据 + List batteryList = + swapOrderBatteryService.QueryListByClause(u => orderSns.Contains(u.SwapOrderSn)); + + //映射 + var config = + new MapperConfiguration(cfg => cfg.CreateMap().ReverseMap()); + IMapper mapper = config.CreateMapper(); + + List swapOrderBattery = mapper.Map>(batteryList); + + + List 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().ReverseMap()); + IMapper mapper2 = config2.CreateMapper(); + List swapOrderStep = mapper2.Map>(stepList); + + + //将步序数据添加到换电订单数据中 + for (int i = 0; i < swapOrderResp.Rows.Count; i++) + { + swapOrderResp.Rows[i].StepList = new List(); + swapOrderResp.Rows[i].StepList + .AddRange(swapOrderStep.Where(step => step.SwapOrderSn == swapOrderResp.Rows[i].Sn).ToList()); + } + return Result>.Success(swapOrderResp); + } + + private PageResult BatteryCodeList(QuerySwapOrderPageReq req) + { + PageResult batteryCodeList = swapOrderBatteryService.QuerySwapOrderBatteryList(req); + + var batteryOrderSn = batteryCodeList.Rows.Select(row => row.SwapOrderSn).ToList(); + + List swapOrderRespList = swapOrderService.QueryListByClause(u => batteryOrderSn.Contains(u.Sn)); + //获取所有订单号 + var orderSns = swapOrderRespList.Select(row => row.Sn).ToList(); + //查询上报云平台次数 Dictionary queryReportCloudNumBySn = swapOrderService.QueryReportCloudNumBySn(orderSns); @@ -51,27 +127,37 @@ public class SwapOrderController : ControllerBase ////查询订单电池数据 List batteryList = swapOrderBatteryService.QueryListByClause(u => orderSns.Contains(u.SwapOrderSn)); - + + var config = new MapperConfiguration(cfg => + { + cfg.CreateMap().ReverseMap(); + cfg.CreateMap().ReverseMap(); + }); //映射 - var config = - new MapperConfiguration(cfg => cfg.CreateMap().ReverseMap()); IMapper mapper = config.CreateMapper(); + List swapOrderBattery = mapper.Map>(batteryList); + + List swapOrderResp = mapper.Map>(swapOrderRespList); + + List 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(); - 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(); - swapOrderResp.Rows[i].StepList - .AddRange(swapOrderStep.Where(step => step.SwapOrderSn == swapOrderResp.Rows[i].Sn).ToList()); + swapOrderResp[i].StepList = new List(); + swapOrderResp[i].StepList + .AddRange(swapOrderStep.Where(step => step.SwapOrderSn == swapOrderResp[i].Sn).ToList()); } - return Result>.Success(swapOrderResp); + PageResult result = new PageResult() + { + PageNum = req.PageNum, + PageSize = req.PageSize, + ToTal = batteryCodeList.ToTal, + Rows = swapOrderResp + }; + return result; } /// @@ -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; } } diff --git a/WebStarter/db/lxw0607.sql b/WebStarter/db/lxw0607.sql index 9ba19be..829b9c6 100644 --- a/WebStarter/db/lxw0607.sql +++ b/WebStarter/db/lxw0607.sql @@ -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; + + +