导出新增电池开始电量、电池结束电量

master
tq 2 months ago
parent d797edd37d
commit 76b6562eb5

@ -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; }
/// <summary>
/// Desc:订单编号
/// Default:
@ -26,8 +30,7 @@ public class ChargeOrderDto
public string ChargerNo { get; set; }
[ExporterHeader(DisplayName = "仓位号", IsBold = true)]
public string BinNO { get; set; }
/// <summary>
/// Desc:电池编号
@ -82,7 +85,17 @@ public class ChargeOrderDto
public int? StopSoc { get; set; }
/// <summary>
/// 开始电池电量/kwh
/// </summary>
[ExporterHeader(DisplayName = "开始电池电量/kwh", IsBold = true)]
public int? StartBattery { get; set; }
/// <summary>
/// 结束电池电量/kwh
/// </summary>
[ExporterHeader(DisplayName = "结束电池电量/kwh", IsBold = true)]
public int? StopBattery { get; set; }
/// <summary>
/// Desc:充电开始交流表电量

@ -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",
@ -45,6 +48,19 @@ public class ChargeOrderDto2
public int? StopSoc { get; set; }
/// <summary>
/// 开始电池电量/kwh
/// </summary>
[ExporterHeader(DisplayName = "START BATTERY LEVEL/kwh", IsBold = true)]
public int? StartBattery { get; set; }
/// <summary>
/// 结束电池电量/kwh
/// </summary>
[ExporterHeader(DisplayName = "END BATTERY LEVEL/kwh", IsBold = true)]
public int? StopBattery { get; set; }
[ExporterHeader(DisplayName = "START ALTERNATING METER POWER/kWh", IsBold = true)]
public decimal? StartAcElec1 { get; set; }

@ -0,0 +1,330 @@
namespace Entity.Dto.Resp;
public class ChargeOrderExportResp
{
/// <summary>
/// Desc:id
/// Default:
/// Nullable:False
/// </summary>
public int Id { get; set; }
/// <summary>
/// Desc:订单编号
/// Default:
/// Nullable:True
/// </summary>
public string Sn { get; set; }
/// <summary>
/// Desc:电池编号
/// Default:
/// Nullable:True
/// </summary>
public string BatteryNo { get; set; }
/// <summary>
/// Desc:启动报文状态;0-初始化1-启动成功
/// Default:0
/// Nullable:True
/// </summary>
public int? CmdStatus { get; set; }
/// <summary>
/// Desc:充电机编号
/// Default:
/// Nullable:True
/// </summary>
public string ChargerNo { get; set; }
/// <summary>
/// Desc:充电枪编号
/// Default:
/// Nullable:True
/// </summary>
public string ChargerGunNo { get; set; }
/// <summary>
/// Desc:站外充电枪编号,1枪或2枪
/// Default:
/// Nullable:True
/// </summary>
public string OutChargerGunNo { get; set; }
/// <summary>
/// 0站内充电 1站外充电
/// </summary>
public int ChargeMode { get; set; }
/// <summary>
/// 1站控启动 2本地启动
/// </summary>
public int StartMode { get; set; }
/// <summary>
/// Desc:充电开始时间
/// Default:
/// Nullable:True
/// </summary>
public DateTime? StartTime { get; set; }
/// <summary>
/// Desc:充电结束时间
/// Default:
/// Nullable:True
/// </summary>
public DateTime? EndTime { get; set; }
/// <summary>
/// Desc:充电开始soc
/// Default:
/// Nullable:True
/// </summary>
public int? StartSoc { get; set; }
/// <summary>
/// Desc:充电结束soc
/// Default:
/// Nullable:True
/// </summary>
public int? StopSoc { get; set; }
/// <summary>
/// 开始电池电量/kwh
/// </summary>
public int? StartBattery { get; set; }
/// <summary>
/// 结束电池电量/kwh
/// </summary>
public int? StopBattery { get; set; }
/// <summary>
/// Desc:充电时长
/// Default:
/// Nullable:True
/// </summary>
public int? ChargeTimeCount { get; set; }
/// <summary>
/// Desc:充电电量
/// Default:
/// Nullable:True
/// </summary>
public decimal? ElecCount { get; set; }
/// <summary>
/// Desc:交流电表量
/// Default:
/// Nullable:True
/// </summary>
public decimal? AcElecCount { get; set; }
/*/// <summary>
/// Desc:充电开始交流表电量
/// Default:
/// Nullable:True
/// </summary>
[SugarColumn(ColumnName = "start_ac_elec")]
public decimal? StartAcElec { get; set; }*/
/*/// <summary>
/// Desc:充电结束交流表电量
/// Default:
/// Nullable:True
/// </summary>
[SugarColumn(ColumnName = "stop_ac_elec")]
public decimal? StopAcElec { get; set; }*/
/*/// <summary>
/// Desc:充电开始直流表电量
/// Default:
/// Nullable:True
/// </summary>
[SugarColumn(ColumnName = "start_dc_elec")]
public decimal? StartDcElec { get; set; }*/
/*/// <summary>
/// Desc:充电结束直流表电量
/// Default:
/// Nullable:True
/// </summary>
[SugarColumn(ColumnName = "stop_dc_elec")]
public decimal? StopDcElec { get; set; }*/
/// <summary>
/// Desc:停止原因;0满电自动停止1-人工停止
/// Default:0
/// Nullable:True
/// </summary>
public int? StopReason { get; set; }
/*/// <summary>
/// Desc:尖时段电量
/// Default:
/// Nullable:True
/// </summary>
[SugarColumn(ColumnName = "sharp_elec_count")]
public decimal? SharpElecCount { get; set; }
/// <summary>
/// Desc:峰时段电量
/// Default:
/// Nullable:True
/// </summary>
[SugarColumn(ColumnName = "peak_elec_count")]
public decimal? PeakElecCount { get; set; }
/// <summary>
/// Desc:平时段电量
/// Default:
/// Nullable:True
/// </summary>
[SugarColumn(ColumnName = "flat_elec_count")]
public decimal? FlatElecCount { get; set; }
/// <summary>
/// Desc:谷时段电量
/// Default:
/// Nullable:True
/// </summary>
[SugarColumn(ColumnName = "valley_elec_count")]
public decimal? ValleyElecCount { get; set; }
/// <summary>
/// Desc:尖时段交流电量
/// Default:
/// Nullable:True
/// </summary>
[SugarColumn(ColumnName = "ac_sharp_elec_count")]
public decimal? ACSharpElecCount { get; set; }
/// <summary>
/// Desc:峰时段交流电量
/// Default:
/// Nullable:True
/// </summary>
[SugarColumn(ColumnName = "ac_peak_elec_count")]
public decimal? ACPeakElecCount { get; set; }
/// <summary>
/// Desc:平时段交流电量
/// Default:
/// Nullable:True
/// </summary>
[SugarColumn(ColumnName = "ac_flat_elec_count")]
public decimal? ACFlatElecCount { get; set; }
/// <summary>
/// Desc:谷时段交流电量
/// Default:
/// Nullable:True
/// </summary>
[SugarColumn(ColumnName = "ac_valley_elec_count")]
public decimal? ACValleyElecCount { get; set; }*/
/*/// <summary>
/// Desc:电价版本号
/// Default:
/// Nullable:True
/// </summary>
[SugarColumn(ColumnName = "elec_price_model_version")]
public string ElecPriceModelVersion { get; set; }*/
/// <summary>
/// Desc:换电订单编号
/// Default:
/// Nullable:True
/// </summary>
public string SwapOrderSn { get; set; }
/// <summary>
/// Desc:上传云平台状态;0-未上传1-已上传
/// Default:0
/// Nullable:True
/// </summary>
public int CloudReportStatus { get; set; }
/// <summary>
/// Desc:云平台订单编号
/// Default:
/// Nullable:True
/// </summary>
public string CloudChargeOrder { get; set; }
/// <summary>
/// Desc:是否可以上传云平台 0-不可用1-可以
/// Default:
/// Nullable:True
/// </summary>
public int CanUpload { get; set; }
/// <summary>
/// 启动方式0-站控自动启动1-站控手动启动2-充电机启动
/// </summary>
public int StartType { get; set; }
/*/// <summary>
/// 上报次数
/// </summary>
[SugarColumn(ColumnName = "reporting_times")]
public int ReportingTimes { get; set; }*/
/// <summary>
/// Desc:充电开始交流表电量
/// Default:
/// Nullable:True
/// </summary>
public decimal? StartAcElec1 { get; set; }
public decimal? StartAcElec2 { get; set; }
/// <summary>
/// Desc:充电结束交流表电量
/// Default:
/// Nullable:True
/// </summary>
public decimal? StopAcElec1 { get; set; }
public decimal? StopAcElec2 { get; set; }
/// <summary>
/// Desc:充电开始直流表电量
/// Default:
/// Nullable:True
/// </summary>
public decimal? StartDcElec1 { get; set; }
public decimal? StartDcElec2 { get; set; }
/// <summary>
/// Desc:充电结束直流表电量
/// Default:
/// Nullable:True
/// </summary>
public decimal? StopDcElec1 { get; set; }
public decimal? StopDcElec2 { get; set; }
/// <summary>
/// 充电金额
/// </summary>
public decimal? ChargeAmount { get; set; }
/// <summary>
/// 充电前卡余额
/// </summary>
public decimal? CardBalanceBefore { get; set; }
/// <summary>
/// 充电后卡余额
/// </summary>
public decimal? CardBalanceBehind { get; set; }
/// <summary>
/// 交易流水号
/// </summary>
public string TransactionSerialNum { get; set; }
}

@ -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<ChargeOrder>
{
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<ChargeOrder>
var config = new MapperConfiguration(cfg =>
{
cfg.CreateMap<ChargeOrderDto, ChargeOrder>().ReverseMap();
cfg.CreateMap<ChargeOrderDto2, ChargeOrder>().ReverseMap();
cfg.CreateMap<ChargeOrderDto, ChargeOrderExportResp>().ReverseMap();
cfg.CreateMap<ChargeOrderDto2, ChargeOrderExportResp>().ReverseMap();
cfg.CreateMap<ChargeOrderExportResp, ChargeOrder>().ReverseMap();
});
IMapper mapper = config.CreateMapper();
List<ChargeOrderExportResp> chargeOrderExportList = mapper.Map<List<ChargeOrderExportResp>>(chargeOrders);
if (chargeOrderExportList.Count > 0)
{
List<string> orderSnList = chargeOrderExportList.Select(resp => resp.SwapOrderSn).ToList();
List<SwapOrderBattery> swapOrderBatteryList = await _swapOrderBatteryRepository
.Queryable()
.In(swapOrderBattery => swapOrderBattery.SwapOrderSn, orderSnList)
.ToListAsync();
var swapOrderBatteryMap = new Dictionary<string, SwapOrderBattery>();
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<ChargeOrderDto2> list2 = mapper.Map<List<ChargeOrderDto2>>(chargeOrders);
List<ChargeOrderDto2> list2 = mapper.Map<List<ChargeOrderDto2>>(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<ChargeOrder>
}
else
{
List<ChargeOrderDto> list = mapper.Map<List<ChargeOrderDto>>(chargeOrders);
List<ChargeOrderDto> list = mapper.Map<List<ChargeOrderDto>>(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<ChargeOrder>
public async Task<IActionResult> ExportElectricityChargerNoConsumption(ChargeCountReq req,string language)
{
// 查询订单
List<ChargeCountResp> resp = await GetElectricityConsumption(req, false);
List<ChargeCountResp> resp = await GetElectricityConsumptionExport(req, false);
if (resp.Count>0)
{
resp = resp.OrderBy(x => x.Time).ToList();
}
var config = new MapperConfiguration(cfg =>
{
cfg.CreateMap<ChargeCountDto, ChargeCountResp>().ReverseMap();
@ -174,7 +247,7 @@ public class ChargeOrderService : BaseServices<ChargeOrder>
// 构建时间范围条件
if (chargeOrder.StartTime != null && chargeOrder.StartTime != DateTime.MinValue && chargeOrder.EndTime != null && chargeOrder.EndTime != DateTime.MinValue)
{
Expression<Func<ChargeOrder, bool>> conditionExpr = u => u.CreatedTime >= chargeOrder.StartTime && u.CreatedTime <= chargeOrder.EndTime;
Expression<Func<ChargeOrder, bool>> conditionExpr = u => u.StartTime >= chargeOrder.StartTime && u.StartTime <= chargeOrder.EndTime;
where = conditionExpr;
}
@ -380,6 +453,124 @@ public class ChargeOrderService : BaseServices<ChargeOrder>
}
public async Task<List<ChargeCountResp>> GetElectricityConsumptionExport(ChargeCountReq req,
bool groupByChargerNo = false)
{
// 设置时间范围
SetTime(req);
Expression<Func<ChargeOrder, bool>> predicate = x => x.EndTime >= req.StartTime && x.EndTime <= req.EndTime;
if (!string.IsNullOrEmpty(req.ChargerNo))
{
Expression<Func<ChargeOrder, bool>> condition2Expr = u => u.ChargerNo == req.ChargerNo;
predicate = Expression.Lambda<Func<ChargeOrder, bool>>(
Expression.AndAlso(predicate.Body, condition2Expr.Body),
predicate.Parameters[0]);
}
List<ChargeOrder> chargeOrders = await QueryListByClauseAsync(predicate);
List<ChargeCountResp> result = new List<ChargeCountResp>();
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)
{
if (req.StartTime.HasValue && req.EndTime.HasValue)

@ -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")
{

Loading…
Cancel
Save