diff --git a/Entity/Dto/ChargeOrderDto.cs b/Entity/Dto/ChargeOrderDto.cs index 25cb6ce..7d3d14f 100644 --- a/Entity/Dto/ChargeOrderDto.cs +++ b/Entity/Dto/ChargeOrderDto.cs @@ -8,6 +8,10 @@ public class ChargeOrderDto { [ExporterHeader(DisplayName = "换电站名称", IsBold = true)] public string stationName { get; set; } = "2号站"; + + + [ExporterHeader(DisplayName = "仓位号", IsBold = true)] + public string BinNO { get; set; } /// /// Desc:订单编号 /// Default: @@ -26,8 +30,7 @@ public class ChargeOrderDto public string ChargerNo { get; set; } - [ExporterHeader(DisplayName = "仓位号", IsBold = true)] - public string BinNO { get; set; } + /// /// Desc:电池编号 @@ -82,7 +85,17 @@ public class ChargeOrderDto public int? StopSoc { get; set; } - + /// + /// 开始电池电量/kwh + /// + [ExporterHeader(DisplayName = "开始电池电量/kwh", IsBold = true)] + public int? StartBattery { get; set; } + + /// + /// 结束电池电量/kwh + /// + [ExporterHeader(DisplayName = "结束电池电量/kwh", IsBold = true)] + public int? StopBattery { get; set; } /// /// Desc:充电开始交流表电量 diff --git a/Entity/Dto/ChargeOrderDto2.cs b/Entity/Dto/ChargeOrderDto2.cs index 2eda1b7..c3d7034 100644 --- a/Entity/Dto/ChargeOrderDto2.cs +++ b/Entity/Dto/ChargeOrderDto2.cs @@ -12,6 +12,10 @@ public class ChargeOrderDto2 [ExporterHeader(DisplayName = "NAME OF CHANGING STATION", IsBold = true)] public string stationName { get; set; } = "STATION 2"; + + [ExporterHeader(DisplayName = "Location Number", IsBold = true)] + public string BinNO { get; set; } + [ExporterHeader(DisplayName = "Order Number", IsBold = true)] public string Sn { get; set; } @@ -23,8 +27,7 @@ public class ChargeOrderDto2 [ExporterHeader(DisplayName = "Charger Number", IsBold = true)] public string ChargerNo { get; set; } - [ExporterHeader(DisplayName = "Location Number", IsBold = true)] - public string BinNO { get; set; } + [ExporterHeader(DisplayName = "Start Time", IsBold = true, Width = 30, Format = "yyyy-MM-dd HH:mm:ss", @@ -43,6 +46,19 @@ public class ChargeOrderDto2 [ExporterHeader(DisplayName = "End SOC", IsBold = true)] public int? StopSoc { get; set; } + + + /// + /// 开始电池电量/kwh + /// + [ExporterHeader(DisplayName = "START BATTERY LEVEL/kwh", IsBold = true)] + public int? StartBattery { get; set; } + + /// + /// 结束电池电量/kwh + /// + [ExporterHeader(DisplayName = "END BATTERY LEVEL/kwh", IsBold = true)] + public int? StopBattery { get; set; } [ExporterHeader(DisplayName = "START ALTERNATING METER POWER/kWh", IsBold = true)] diff --git a/Entity/Dto/Resp/ChargeOrderExportResp.cs b/Entity/Dto/Resp/ChargeOrderExportResp.cs new file mode 100644 index 0000000..87b5484 --- /dev/null +++ b/Entity/Dto/Resp/ChargeOrderExportResp.cs @@ -0,0 +1,330 @@ +namespace Entity.Dto.Resp; + +public class ChargeOrderExportResp +{ + /// + /// Desc:id + /// Default: + /// Nullable:False + /// + public int Id { get; set; } + + /// + /// Desc:订单编号 + /// Default: + /// Nullable:True + /// + public string Sn { get; set; } + + /// + /// Desc:电池编号 + /// Default: + /// Nullable:True + /// + public string BatteryNo { get; set; } + + /// + /// Desc:启动报文状态;0-初始化;1-启动成功 + /// Default:0 + /// Nullable:True + /// + public int? CmdStatus { get; set; } + + /// + /// Desc:充电机编号 + /// Default: + /// Nullable:True + /// + public string ChargerNo { get; set; } + + /// + /// Desc:充电枪编号 + /// Default: + /// Nullable:True + /// + public string ChargerGunNo { get; set; } + + /// + /// Desc:站外充电枪编号,1枪或2枪 + /// Default: + /// Nullable:True + /// + public string OutChargerGunNo { get; set; } + + /// + /// 0:站内充电 1:站外充电 + /// + public int ChargeMode { get; set; } + + /// + /// 1:站控启动 2:本地启动 + /// + public int StartMode { get; set; } + + /// + /// Desc:充电开始时间 + /// Default: + /// Nullable:True + /// + public DateTime? StartTime { get; set; } + + /// + /// Desc:充电结束时间 + /// Default: + /// Nullable:True + /// + public DateTime? EndTime { get; set; } + + /// + /// Desc:充电开始soc + /// Default: + /// Nullable:True + /// + public int? StartSoc { get; set; } + + /// + /// Desc:充电结束soc + /// Default: + /// Nullable:True + /// + public int? StopSoc { get; set; } + + /// + /// 开始电池电量/kwh + /// + public int? StartBattery { get; set; } + + /// + /// 结束电池电量/kwh + /// + public int? StopBattery { get; set; } + + /// + /// Desc:充电时长 + /// Default: + /// Nullable:True + /// + public int? ChargeTimeCount { get; set; } + + /// + /// Desc:充电电量 + /// Default: + /// Nullable:True + /// + public decimal? ElecCount { get; set; } + + /// + /// Desc:交流电表量 + /// Default: + /// Nullable:True + /// + public decimal? AcElecCount { get; set; } + + /*/// + /// Desc:充电开始交流表电量 + /// Default: + /// Nullable:True + /// + [SugarColumn(ColumnName = "start_ac_elec")] + public decimal? StartAcElec { get; set; }*/ + + /*/// + /// Desc:充电结束交流表电量 + /// Default: + /// Nullable:True + /// + [SugarColumn(ColumnName = "stop_ac_elec")] + public decimal? StopAcElec { get; set; }*/ + + /*/// + /// Desc:充电开始直流表电量 + /// Default: + /// Nullable:True + /// + [SugarColumn(ColumnName = "start_dc_elec")] + public decimal? StartDcElec { get; set; }*/ + + /*/// + /// Desc:充电结束直流表电量 + /// Default: + /// Nullable:True + /// + [SugarColumn(ColumnName = "stop_dc_elec")] + public decimal? StopDcElec { get; set; }*/ + + /// + /// Desc:停止原因;0:满电自动停止;1-人工停止 + /// Default:0 + /// Nullable:True + /// + public int? StopReason { get; set; } + + /*/// + /// Desc:尖时段电量 + /// Default: + /// Nullable:True + /// + [SugarColumn(ColumnName = "sharp_elec_count")] + public decimal? SharpElecCount { get; set; } + + /// + /// Desc:峰时段电量 + /// Default: + /// Nullable:True + /// + [SugarColumn(ColumnName = "peak_elec_count")] + public decimal? PeakElecCount { get; set; } + + /// + /// Desc:平时段电量 + /// Default: + /// Nullable:True + /// + [SugarColumn(ColumnName = "flat_elec_count")] + public decimal? FlatElecCount { get; set; } + + /// + /// Desc:谷时段电量 + /// Default: + /// Nullable:True + /// + [SugarColumn(ColumnName = "valley_elec_count")] + public decimal? ValleyElecCount { get; set; } + + /// + /// Desc:尖时段交流电量 + /// Default: + /// Nullable:True + /// + [SugarColumn(ColumnName = "ac_sharp_elec_count")] + public decimal? ACSharpElecCount { get; set; } + + /// + /// Desc:峰时段交流电量 + /// Default: + /// Nullable:True + /// + [SugarColumn(ColumnName = "ac_peak_elec_count")] + public decimal? ACPeakElecCount { get; set; } + + /// + /// Desc:平时段交流电量 + /// Default: + /// Nullable:True + /// + [SugarColumn(ColumnName = "ac_flat_elec_count")] + public decimal? ACFlatElecCount { get; set; } + + /// + /// Desc:谷时段交流电量 + /// Default: + /// Nullable:True + /// + [SugarColumn(ColumnName = "ac_valley_elec_count")] + public decimal? ACValleyElecCount { get; set; }*/ + + /*/// + /// Desc:电价版本号 + /// Default: + /// Nullable:True + /// + [SugarColumn(ColumnName = "elec_price_model_version")] + public string ElecPriceModelVersion { get; set; }*/ + + /// + /// Desc:换电订单编号 + /// Default: + /// Nullable:True + /// + public string SwapOrderSn { get; set; } + + /// + /// Desc:上传云平台状态;0-未上传;1-已上传 + /// Default:0 + /// Nullable:True + /// + public int CloudReportStatus { get; set; } + + + /// + /// Desc:云平台订单编号 + /// Default: + /// Nullable:True + /// + public string CloudChargeOrder { get; set; } + + /// + /// Desc:是否可以上传云平台 0-不可用;1-可以 + /// Default: + /// Nullable:True + /// + public int CanUpload { get; set; } + + /// + /// 启动方式:0-站控自动启动,1-站控手动启动,2-充电机启动 + /// + public int StartType { get; set; } + + /*/// + /// 上报次数 + /// + [SugarColumn(ColumnName = "reporting_times")] + public int ReportingTimes { get; set; }*/ + + /// + /// Desc:充电开始交流表电量 + /// Default: + /// Nullable:True + /// + public decimal? StartAcElec1 { get; set; } + + public decimal? StartAcElec2 { get; set; } + + /// + /// Desc:充电结束交流表电量 + /// Default: + /// Nullable:True + /// + public decimal? StopAcElec1 { get; set; } + + public decimal? StopAcElec2 { get; set; } + + /// + /// Desc:充电开始直流表电量 + /// Default: + /// Nullable:True + /// + public decimal? StartDcElec1 { get; set; } + + public decimal? StartDcElec2 { get; set; } + + /// + /// Desc:充电结束直流表电量 + /// Default: + /// Nullable:True + /// + public decimal? StopDcElec1 { get; set; } + + public decimal? StopDcElec2 { get; set; } + + /// + /// 充电金额 + /// + public decimal? ChargeAmount { get; set; } + + /// + /// 充电前卡余额 + /// + public decimal? CardBalanceBefore { get; set; } + + /// + /// 充电后卡余额 + /// + public decimal? CardBalanceBehind { get; set; } + + + /// + /// 交易流水号 + /// + public string TransactionSerialNum { get; set; } +} \ No newline at end of file diff --git a/Service/Station/ChargeOrderService.cs b/Service/Station/ChargeOrderService.cs index e9859f5..b623500 100644 --- a/Service/Station/ChargeOrderService.cs +++ b/Service/Station/ChargeOrderService.cs @@ -5,6 +5,7 @@ using Entity.Api.Resp; using Entity.DbModel.Station; using Entity.Dto; using Entity.Dto.Req; +using Entity.Dto.Resp; using HybirdFrameworkCore.Autofac.Attribute; using HybirdFrameworkCore.Entity; using HybirdFrameworkCore.Utils; @@ -20,9 +21,11 @@ namespace Service.Station; public class ChargeOrderService : BaseServices { ChargeOrderRepository chargeOrderRepository; - public ChargeOrderService(ChargeOrderRepository dal) + SwapOrderBatteryRepository _swapOrderBatteryRepository; + public ChargeOrderService(ChargeOrderRepository dal,SwapOrderBatteryRepository swapOrderBatteryRepository) { chargeOrderRepository = dal; + _swapOrderBatteryRepository = swapOrderBatteryRepository; BaseDal = dal; } @@ -62,19 +65,74 @@ public class ChargeOrderService : BaseServices var config = new MapperConfiguration(cfg => { - cfg.CreateMap().ReverseMap(); - cfg.CreateMap().ReverseMap(); + cfg.CreateMap().ReverseMap(); + cfg.CreateMap().ReverseMap(); + cfg.CreateMap().ReverseMap(); }); IMapper mapper = config.CreateMapper(); + + List chargeOrderExportList = mapper.Map>(chargeOrders); + + if (chargeOrderExportList.Count > 0) + { + List orderSnList = chargeOrderExportList.Select(resp => resp.SwapOrderSn).ToList(); + + List swapOrderBatteryList = await _swapOrderBatteryRepository + .Queryable() + .In(swapOrderBattery => swapOrderBattery.SwapOrderSn, orderSnList) + .ToListAsync(); + + var swapOrderBatteryMap = new Dictionary(); + + foreach (var swapOrderBattery in swapOrderBatteryList) + { + if (!string.IsNullOrEmpty(swapOrderBattery.SwapOrderSn)) swapOrderBatteryMap.Add(swapOrderBattery.SwapOrderSn, swapOrderBattery); + } + + foreach (var order in chargeOrderExportList) + { + if (order.SwapOrderSn!=null&&swapOrderBatteryMap.TryGetValue(order.SwapOrderSn, out var swapOrderBattery)) + { + try + { + int startSoc = order.StartSoc ?? 0; + int stopSoc = order.StopSoc ?? 0; + decimal downNominalEnergy = swapOrderBattery.DownNominalEnergy ?? 0; + + order.StartBattery = downNominalEnergy > 0 ? (int?)(startSoc * downNominalEnergy) : 0; + order.StopBattery = downNominalEnergy > 0 ? (int?)(stopSoc * downNominalEnergy) : 0; + } + catch (Exception ex) + { + order.StartBattery = 0; + order.StopBattery = 0; + } + } + } + } + + + if (language == "en") { - List list2 = mapper.Map>(chargeOrders); + List list2 = mapper.Map>(chargeOrderExportList); foreach (var chargeOrderDto in list2) { if (!string.IsNullOrEmpty(chargeOrderDto.ChargerNo)) { - chargeOrderDto.BinNO = chargeOrderDto.ChargerNo; + try + { + string lastTwoDigits = chargeOrderDto.ChargerNo.Substring(chargeOrderDto.ChargerNo.Length - 2); + if (int.TryParse(lastTwoDigits, out int binNo)) + { + chargeOrderDto.BinNO = binNo.ToString(); + } + } + catch (Exception e) + { + chargeOrderDto.BinNO = "-1"; + } } } IExcelExporter excelExporter = new ExcelExporter(); @@ -84,12 +142,23 @@ public class ChargeOrderService : BaseServices } else { - List list = mapper.Map>(chargeOrders); + List list = mapper.Map>(chargeOrderExportList); foreach (var chargeOrderDto in list) { if (!string.IsNullOrEmpty(chargeOrderDto.ChargerNo)) { - chargeOrderDto.BinNO = chargeOrderDto.ChargerNo; + try + { + string lastTwoDigits = chargeOrderDto.ChargerNo.Substring(chargeOrderDto.ChargerNo.Length - 2); + if (int.TryParse(lastTwoDigits, out int binNo)) + { + chargeOrderDto.BinNO = binNo.ToString(); + } + } + catch (Exception e) + { + chargeOrderDto.BinNO = "-1"; + } } } IExcelExporter excelExporter = new ExcelExporter(); @@ -102,7 +171,11 @@ public class ChargeOrderService : BaseServices public async Task ExportElectricityChargerNoConsumption(ChargeCountReq req,string language) { // 查询订单 - List resp = await GetElectricityConsumption(req, false); + List resp = await GetElectricityConsumptionExport(req, false); + if (resp.Count>0) + { + resp = resp.OrderBy(x => x.Time).ToList(); + } var config = new MapperConfiguration(cfg => { cfg.CreateMap().ReverseMap(); @@ -174,7 +247,7 @@ public class ChargeOrderService : BaseServices // 构建时间范围条件 if (chargeOrder.StartTime != null && chargeOrder.StartTime != DateTime.MinValue && chargeOrder.EndTime != null && chargeOrder.EndTime != DateTime.MinValue) { - Expression> conditionExpr = u => u.CreatedTime >= chargeOrder.StartTime && u.CreatedTime <= chargeOrder.EndTime; + Expression> conditionExpr = u => u.StartTime >= chargeOrder.StartTime && u.StartTime <= chargeOrder.EndTime; where = conditionExpr; } @@ -378,6 +451,124 @@ public class ChargeOrderService : BaseServices return result; } + + + public async Task> GetElectricityConsumptionExport(ChargeCountReq req, + bool groupByChargerNo = false) + { + // 设置时间范围 + SetTime(req); + + Expression> predicate = x => x.EndTime >= req.StartTime && x.EndTime <= req.EndTime; + + if (!string.IsNullOrEmpty(req.ChargerNo)) + { + Expression> condition2Expr = u => u.ChargerNo == req.ChargerNo; + predicate = Expression.Lambda>( + Expression.AndAlso(predicate.Body, condition2Expr.Body), + predicate.Parameters[0]); + } + + List chargeOrders = await QueryListByClauseAsync(predicate); + + List result = new List(); + + if (req.TimeType == 1) + { + // 按小时分组统计 + if (groupByChargerNo) + { + // 按 ChargerNo 和小时分组 + result = chargeOrders + .Where(order => order.EndTime.HasValue && !string.IsNullOrEmpty(order.ChargerNo)) + .GroupBy(order => new { order.ChargerNo, DateHour = order.EndTime.Value.ToString("yyyy-MM-dd HH") }) + .Select(group => new ChargeCountResp + { + ChargerNo = group.Key.ChargerNo, + Time = group.Key.DateHour + ":00", // 保留年月日和小时 + ChargeCount = group.Sum(order => order.ElecCount ?? 0) + }) + .ToList(); + } + else + { + // 仅按小时分组 + result = chargeOrders + .Where(order => order.EndTime.HasValue) + .GroupBy(order => order.EndTime.Value.ToString("yyyy-MM-dd HH")) + .Select(group => new ChargeCountResp + { + Time = group.Key + ":00", // 保留年月日和小时 + ChargeCount = group.Sum(order => order.ElecCount ?? 0) + }) + .ToList(); + } + } + else if (req.TimeType == 2) + { + // 按天分组统计 + if (groupByChargerNo) + { + // 按 ChargerNo 和日期分组 + result = chargeOrders + .Where(order => order.EndTime.HasValue && !string.IsNullOrEmpty(order.ChargerNo)) + .GroupBy(order => new { order.ChargerNo, Date = order.EndTime.Value.Date }) + .Select(group => new ChargeCountResp + { + ChargerNo = group.Key.ChargerNo, + Time = group.Key.Date.ToString("yyyy-MM-dd"), + ChargeCount = group.Sum(order => order.ElecCount ?? 0) + }) + .ToList(); + } + else + { + // 仅按日期分组 + result = chargeOrders + .Where(order => order.EndTime.HasValue) + .GroupBy(order => order.EndTime.Value.Date) + .Select(group => new ChargeCountResp + { + Time = group.Key.ToString("yyyy-MM-dd"), + ChargeCount = group.Sum(order => order.ElecCount ?? 0) + }) + .ToList(); + } + } + else if (req.TimeType == 3) + { + // 按月分组统计 + if (groupByChargerNo) + { + // 按 ChargerNo、年和月分组 + result = chargeOrders + .Where(order => order.EndTime.HasValue && !string.IsNullOrEmpty(order.ChargerNo)) + .GroupBy(order => new { order.ChargerNo, order.EndTime.Value.Year, order.EndTime.Value.Month }) + .Select(group => new ChargeCountResp + { + ChargerNo = group.Key.ChargerNo, + Time = group.Key.Year + "-" + group.Key.Month.ToString("00"), + ChargeCount = group.Sum(order => order.ElecCount ?? 0) + }) + .ToList(); + } + else + { + // 仅按年和月分组 + result = chargeOrders + .Where(order => order.EndTime.HasValue) + .GroupBy(order => new { order.EndTime.Value.Year, order.EndTime.Value.Month }) + .Select(group => new ChargeCountResp + { + Time = group.Key.Year + "-" + group.Key.Month.ToString("00"), + ChargeCount = group.Sum(order => order.ElecCount ?? 0) + }) + .ToList(); + } + } + + return result; + } private static void SetTime(ChargeCountReq req) diff --git a/WebStarter/Controllers/EquipAlarmRecordController.cs b/WebStarter/Controllers/EquipAlarmRecordController.cs index 2cfce97..cdc749f 100644 --- a/WebStarter/Controllers/EquipAlarmRecordController.cs +++ b/WebStarter/Controllers/EquipAlarmRecordController.cs @@ -112,7 +112,7 @@ public class EquipAlarmRecordController : ControllerBase IMapper mapper = config.CreateMapper(); - if (req.EquipTypeCode==(int)EquipmentType.Plc) + if (req.EquipTypeCode==(int)EquipmentType.Plc||req.EquipTypeCode==(int)EquipmentType.Bms) { if (language == "en") { @@ -251,7 +251,7 @@ public class EquipAlarmRecordController : ControllerBase IMapper mapper = config.CreateMapper(); - if (req.EquipTypeCode==(int)EquipmentType.Plc) + if (req.EquipTypeCode==(int)EquipmentType.Plc||req.EquipTypeCode==(int)EquipmentType.Bms) { if (language == "en") {