订单导出优化

master
tq 6 months ago
parent b12add6688
commit 5c58db7ac3

@ -30,6 +30,25 @@ public class ChargeOrderDto
/// Nullable:True /// Nullable:True
/// </summary> /// </summary>
[ExporterHeader(DisplayName = "启动报文状态", IsBold = true)] [ExporterHeader(DisplayName = "启动报文状态", IsBold = true)]
public string CmdStatusDisplay
{
get
{
return CmdStatus switch
{
0 => "初始化",
1 => "启动成功",
_ => "未知"
};
}
}
/// <summary>
/// Desc:启动报文状态;0-初始化1-启动成功
/// Default:0
/// Nullable:True
/// </summary>
[ExporterHeader(IsIgnore = true)]
public int? CmdStatus { get; set; } public int? CmdStatus { get; set; }
@ -51,10 +70,28 @@ public class ChargeOrderDto
public string ChargerGunNo { get; set; } public string ChargerGunNo { get; set; }
/// <summary> /// <summary>
/// 0站内充电 1站外充电 /// 0站内充电 1站外充电
/// </summary> /// </summary>
[ExporterHeader(DisplayName = "充电位置", IsBold = true)] [ExporterHeader(DisplayName = "充电位置", IsBold = true)]
public string ChargeModeDisplay
{
get
{
return ChargeMode switch
{
0 => "站内充电",
1 => "站外充电",
_ => "未知"
};
}
}
/// <summary>
/// 0站内充电 1站外充电
/// </summary>
[ExporterHeader(IsIgnore = true)]
public int ChargeMode { get; set; } public int ChargeMode { get; set; }
@ -62,13 +99,30 @@ public class ChargeOrderDto
/// 1站控启动 2本地启动 /// 1站控启动 2本地启动
/// </summary> /// </summary>
[ExporterHeader(DisplayName = "启动方式", IsBold = true)] [ExporterHeader(DisplayName = "启动方式", IsBold = true)]
public string StartModeDisplay
{
get
{
return StartMode switch
{
1 => "站控启动",
2 => "本地启动",
_ => "未知"
};
}
}
/// <summary>
/// 1站控启动 2本地启动
/// </summary>
[ExporterHeader(IsIgnore = true)]
public int StartMode { get; set; } public int StartMode { get; set; }
/// <summary> /// <summary>
/// 充电开始时间 /// 充电开始时间
/// </summary> /// </summary>
[ExporterHeader(DisplayName = "充电开始时间", IsBold = true,Width = 25)] [ExporterHeader(DisplayName = "充电开始时间", IsBold = true,Width = 30, Format = "yyyy-MM-dd HH:mm:ss", AutoCenterColumn = true)]
public DateTime? StartTime { get; set; } public DateTime? StartTime { get; set; }
@ -77,7 +131,7 @@ public class ChargeOrderDto
/// Default: /// Default:
/// Nullable:True /// Nullable:True
/// </summary> /// </summary>
[ExporterHeader(DisplayName = "充电结束时间", IsBold = true,Width = 25)] [ExporterHeader(DisplayName = "充电结束时间", IsBold = true,Width = 30, Format = "yyyy-MM-dd HH:mm:ss", AutoCenterColumn = true)]
public DateTime? EndTime { get; set; } public DateTime? EndTime { get; set; }
@ -159,6 +213,24 @@ public class ChargeOrderDto
/// Nullable:True /// Nullable:True
/// </summary> /// </summary>
[ExporterHeader(DisplayName = "停止原因", IsBold = true)] [ExporterHeader(DisplayName = "停止原因", IsBold = true)]
public string StopReasonDisplay
{
get
{
return StopReason switch
{
0 => "满电自动停止",
1 => "人工停止",
_ => "未知"
};
}
}
/// <summary>
/// Desc:停止原因;0满电自动停止1-人工停止
/// Default:0
/// Nullable:True
/// </summary>
[ExporterHeader(IsIgnore = true)]
public int? StopReason { get; set; } public int? StopReason { get; set; }
@ -258,6 +330,21 @@ public class ChargeOrderDto
/// Nullable:True /// Nullable:True
/// </summary> /// </summary>
[ExporterHeader(DisplayName = "上传云平台状态", IsBold = true)] [ExporterHeader(DisplayName = "上传云平台状态", IsBold = true)]
public string CloudReportStatusDisplay
{
get
{
return CloudReportStatus switch
{
0 => "未上传",
1 => "已上传",
_ => "未知"
};
}
}
[ExporterHeader(IsIgnore = true)]
public int? CloudReportStatus { get; set; } public int? CloudReportStatus { get; set; }
@ -275,7 +362,7 @@ public class ChargeOrderDto
/// Default:CURRENT_TIMESTAMP /// Default:CURRENT_TIMESTAMP
/// Nullable:True /// Nullable:True
/// </summary> /// </summary>
[ExporterHeader(DisplayName = "创建时间", IsBold = true,Width = 25)] [ExporterHeader(DisplayName = "创建时间", IsBold = true,Width = 30, Format = "yyyy-MM-dd HH:mm:ss", AutoCenterColumn = true)]
public DateTime? CreatedTime { get; set; } public DateTime? CreatedTime { get; set; }
@ -293,7 +380,7 @@ public class ChargeOrderDto
/// Default:CURRENT_TIMESTAMP /// Default:CURRENT_TIMESTAMP
/// Nullable:True /// Nullable:True
/// </summary> /// </summary>
[ExporterHeader(DisplayName = "更新时间", IsBold = true,Width = 25)] [ExporterHeader(DisplayName = "更新时间", IsBold = true,Width = 30, Format = "yyyy-MM-dd HH:mm:ss", AutoCenterColumn = true)]
public DateTime? UpdatedTime { get; set; } public DateTime? UpdatedTime { get; set; }
@ -310,6 +397,25 @@ public class ChargeOrderDto
/// Nullable:True /// Nullable:True
/// </summary> /// </summary>
[ExporterHeader(DisplayName = "是否可以上传云平台", IsBold = true)] [ExporterHeader(DisplayName = "是否可以上传云平台", IsBold = true)]
public string CanUploadDisplay
{
get
{
return CanUpload switch
{
0 => "不可用",
1 => "可以",
_ => "未知"
};
}
}
/// <summary>
/// Desc:是否可以上传云平台
/// Default:
/// Nullable:True
/// </summary>
[ExporterHeader(IsIgnore = true)]
public int? CanUpload { get; set; } public int? CanUpload { get; set; }
} }

@ -46,7 +46,7 @@ public class SwapOrderDto
/// Default: /// Default:
/// Nullable:True /// Nullable:True
/// </summary> /// </summary>
[ExporterHeader(DisplayName = "车辆进场时间", IsBold = true,Width = 25)] [ExporterHeader(DisplayName = "车辆进场时间", IsBold = true,Width = 30, Format = "yyyy-MM-dd HH:mm:ss", AutoCenterColumn = true)]
public DateTime? VehicleEnterTime { get; set; } public DateTime? VehicleEnterTime { get; set; }
/// <summary> /// <summary>
@ -54,7 +54,7 @@ public class SwapOrderDto
/// Default: /// Default:
/// Nullable:True /// Nullable:True
/// </summary> /// </summary>
[ExporterHeader(DisplayName = "车辆离场时间", IsBold = true,Width = 25)] [ExporterHeader(DisplayName = "车辆离场时间", IsBold = true,Width = 30, Format = "yyyy-MM-dd HH:mm:ss", AutoCenterColumn = true)]
public DateTime? VehicleLeaveTime { get; set; } public DateTime? VehicleLeaveTime { get; set; }
/// <summary> /// <summary>
@ -62,7 +62,7 @@ public class SwapOrderDto
/// Default: /// Default:
/// Nullable:True /// Nullable:True
/// </summary> /// </summary>
[ExporterHeader(DisplayName = "换电开始时间", IsBold = true,Width = 25)] [ExporterHeader(DisplayName = "换电开始时间", IsBold = true,Width = 30, Format = "yyyy-MM-dd HH:mm:ss", AutoCenterColumn = true)]
public DateTime? SwapBeginTime { get; set; } public DateTime? SwapBeginTime { get; set; }
/// <summary> /// <summary>
@ -70,7 +70,7 @@ public class SwapOrderDto
/// Default: /// Default:
/// Nullable:True /// Nullable:True
/// </summary> /// </summary>
[ExporterHeader(DisplayName = "换电结束时间", IsBold = true,Width = 25)] [ExporterHeader(DisplayName = "换电结束时间",Width = 30, Format = "yyyy-MM-dd HH:mm:ss", AutoCenterColumn = true)]
public DateTime? SwapEndTime { get; set; } public DateTime? SwapEndTime { get; set; }
/// <summary> /// <summary>
@ -79,6 +79,27 @@ public class SwapOrderDto
/// Nullable:True /// Nullable:True
/// </summary> /// </summary>
[ExporterHeader(DisplayName = "换电结果", IsBold = true)] [ExporterHeader(DisplayName = "换电结果", IsBold = true)]
public string SwapResultDisplay
{
get
{
return SwapResult switch
{
0 => "未知",
1 => "成功",
2 => "失败",
_ => "未知"
};
}
}
/// <summary>
/// Desc:换电结果;0-未知1-成功2-失败
/// Default:0
/// Nullable:True
/// </summary>
// [ExporterHeader(DisplayName = "换电结果", IsBold = true)]
[ExporterHeader(IsIgnore = true)]
public int? SwapResult { get; set; } public int? SwapResult { get; set; }
/// <summary> /// <summary>
@ -89,12 +110,29 @@ public class SwapOrderDto
[ExporterHeader(DisplayName = "失败原因", IsBold = true)] [ExporterHeader(DisplayName = "失败原因", IsBold = true)]
public string FailReason { get; set; } public string FailReason { get; set; }
/// <summary> /// <summary>
/// Desc:上传云平台状态;0-未上传1-已上传 /// Desc:上传云平台状态;0-未上传1-已上传
/// Default:0 /// Default:0
/// Nullable:True /// Nullable:True
/// </summary> /// </summary>
[ExporterHeader(DisplayName = "上传云平台状态", IsBold = true)] [ExporterHeader(DisplayName = "上传云平台状态", IsBold = true)]
public string CloudReportStatusDisplay
{
get
{
return CloudReportStatus switch
{
0 => "未上传",
1 => "已上传",
_ => "未上传"
};
}
}
// [ExporterHeader(DisplayName = "上传云平台状态", IsBold = true)]
[ExporterHeader(IsIgnore = true)]
public int? CloudReportStatus { get; set; } public int? CloudReportStatus { get; set; }
@ -110,5 +148,51 @@ public class SwapOrderDto
/// Nullable:True /// Nullable:True
/// </summary> /// </summary>
[ExporterHeader(DisplayName = "换电类型", IsBold = true)] [ExporterHeader(DisplayName = "换电类型", IsBold = true)]
public string SwapWayDisplay
{
get
{
return SwapWay switch
{
1 => "自动换电",
2 => "手动换电",
_ => "未知"
};
}
}
/// <summary>
/// Desc:换电类型:;1自动换电;2手动换电
/// Default:0
/// Nullable:True
/// </summary>
[ExporterHeader(IsIgnore = true)]
public int? SwapWay { get; set; } public int? SwapWay { get; set; }
/// <summary>
/// Desc:亏电包soc
/// Default:
/// Nullable:True
/// </summary>
[ExporterHeader(DisplayName = "亏电包soc", IsBold = true)]
public decimal? DownBatterySoc { get; set; }
/// <summary>
/// Desc:亏电包真实soc
/// Default:
/// Nullable:True
/// </summary>
[ExporterHeader(DisplayName = "亏电包真实soc", IsBold = true)]
public decimal? DownBatteryRealSoc { get; set; }
/// <summary>
/// Desc:亏电包上次换电结算时soc
/// Default:
/// Nullable:True
/// </summary>
[ExporterHeader(DisplayName = "亏电包上次换电结算时soc", IsBold = true)]
public decimal? DownBatteryLastSoc { get; set; }
} }

@ -60,7 +60,6 @@ public class ChargeOrderService : BaseServices<ChargeOrder>
// 查询订单 // 查询订单
List<ChargeOrder> chargeOrders = await QueryChargeOrderListAsync(chargeOrder); List<ChargeOrder> chargeOrders = await QueryChargeOrderListAsync(chargeOrder);
var config = new MapperConfiguration(cfg => var config = new MapperConfiguration(cfg =>
{ cfg.CreateMap<ChargeOrderDto, ChargeOrder>().ReverseMap(); }); { cfg.CreateMap<ChargeOrderDto, ChargeOrder>().ReverseMap(); });
IMapper mapper = config.CreateMapper(); IMapper mapper = config.CreateMapper();

@ -45,27 +45,6 @@ public class SwapOrderService : BaseServices<SwapOrder>
return SwapOrderMgr.UploadCloud(list,2) ? Result<bool>.Success() : Result<bool>.Fail(); return SwapOrderMgr.UploadCloud(list,2) ? Result<bool>.Success() : Result<bool>.Fail();
} }
/// <summary> /// <summary>
/// 导出充电订单
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
public async Task<IActionResult> ExportSwapOrder(QuerySwapOrderPageReq swapOrder)
{
// 查询订单
List<SwapOrder> swapOrders = await QuerySwapOrderListAsync(swapOrder);
var config = new MapperConfiguration(cfg => { cfg.CreateMap<SwapOrderDto, SwapOrder>().ReverseMap(); });
IMapper mapper = config.CreateMapper();
List<SwapOrderDto> list = mapper.Map<List<SwapOrderDto>>(swapOrders);
IExcelExporter excelExporter = new ExcelExporter();
var res = await excelExporter.ExportAsByteArray(list);
return new FileStreamResult(new MemoryStream(res), "application/octet-stream")
{ FileDownloadName = DateTime.Now.ToString("yyyyMMddHHmm") + "换电订单.xlsx" };
}
/// <summary>
/// 查询需要导出换电订单 /// 查询需要导出换电订单
/// </summary> /// </summary>
/// <param name="swapOrder"></param> /// <param name="swapOrder"></param>

@ -3,7 +3,9 @@ using AutoMapper;
using Entity.Api.Req; using Entity.Api.Req;
using Entity.Api.Resp; using Entity.Api.Resp;
using Entity.DbModel.Station; using Entity.DbModel.Station;
using Entity.Dto;
using HybirdFrameworkCore.Entity; using HybirdFrameworkCore.Entity;
using Magicodes.ExporterAndImporter.Excel;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Service.Init; using Service.Init;
using Service.Station; using Service.Station;
@ -101,6 +103,7 @@ public class SwapOrderController : ControllerBase
// 转换换电订单 // 转换换电订单
SwapOrder swapOrder = mapper.Map<SwapOrder>(req); SwapOrder swapOrder = mapper.Map<SwapOrder>(req);
swapOrder.Sn = SwapOrderNoGenerator.GenerateOrderNo(StaticStationInfo.StationNo); swapOrder.Sn = SwapOrderNoGenerator.GenerateOrderNo(StaticStationInfo.StationNo);
swapOrder.CloudReportStatus = 0;
SwapOrder order = await swapOrderService.InsertAsync(swapOrder); SwapOrder order = await swapOrderService.InsertAsync(swapOrder);
bool batteriesInserted = true; bool batteriesInserted = true;
@ -199,6 +202,7 @@ public class SwapOrderController : ControllerBase
} }
} }
/// <summary> /// <summary>
/// 换电订单导出 /// 换电订单导出
/// </summary> /// </summary>
@ -208,7 +212,45 @@ public class SwapOrderController : ControllerBase
[Route("export")] [Route("export")]
public async Task<IActionResult> ExportSwapOrder([FromBody] QuerySwapOrderPageReq req) public async Task<IActionResult> ExportSwapOrder([FromBody] QuerySwapOrderPageReq req)
{ {
return await swapOrderService.ExportSwapOrder(req); List<SwapOrder> orderList = await swapOrderService.QuerySwapOrderListAsync(req);
//获取所有订单号
var orderSns = orderList.Select(row => row.Sn).ToList();
//查询订单电池数据
List<SwapOrderBattery> batteryList =
swapOrderBatteryService.QueryListByClause(u => orderSns.Contains(u.SwapOrderSn));
//映射
var config = new MapperConfiguration(cfg =>
{
cfg.CreateMap<SwapOrderBatteryResp, SwapOrderBattery>().ReverseMap();
cfg.CreateMap<SwapOrderDto, SwapOrder>().ReverseMap();
});
IMapper mapper = config.CreateMapper();
List<SwapOrderBatteryResp> swapOrderBattery = mapper.Map<List<SwapOrderBatteryResp>>(batteryList);
List<SwapOrderDto> list = mapper.Map<List<SwapOrderDto>>(orderList);
//将电池数据添加到换电订单数据中
for (int i = 0; i < list.Count; i++)
{
SwapOrderDto dto = list[i];
SwapOrderBatteryResp? swapOrderBatteryResp =
swapOrderBattery.FirstOrDefault(battery => battery.SwapOrderSn == dto.Sn);
if (swapOrderBatteryResp != null)
{
dto.DownBatterySoc = swapOrderBatteryResp.DownBatterySoc;
dto.DownBatteryRealSoc = swapOrderBatteryResp.DownBatteryRealSoc;
dto.DownBatteryLastSoc = swapOrderBatteryResp.DownBatteryLastSoc;
}
}
IExcelExporter excelExporter = new ExcelExporter();
var res = await excelExporter.ExportAsByteArray(list);
return new FileStreamResult(new MemoryStream(res), "application/octet-stream")
{ FileDownloadName = DateTime.Now.ToString("yyyyMMddHHmm") + "换电订单.xlsx" };
} }
/// <summary> /// <summary>
/// 换电订单上报云端 /// 换电订单上报云端

Loading…
Cancel
Save