订单导出优化

zw
tq 6 months ago
parent b12add6688
commit 5c58db7ac3

@ -30,6 +30,25 @@ public class ChargeOrderDto
/// Nullable:True
/// </summary>
[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; }
@ -51,24 +70,59 @@ public class ChargeOrderDto
public string ChargerGunNo { get; set; }
/// <summary>
/// 0站内充电 1站外充电
/// </summary>
[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; }
/// <summary>
/// 1站控启动 2本地启动
/// </summary>
[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; }
/// <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; }
@ -77,7 +131,7 @@ public class ChargeOrderDto
/// Default:
/// Nullable:True
/// </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; }
@ -159,6 +213,24 @@ public class ChargeOrderDto
/// Nullable:True
/// </summary>
[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; }
@ -258,6 +330,21 @@ public class ChargeOrderDto
/// Nullable:True
/// </summary>
[ExporterHeader(DisplayName = "上传云平台状态", IsBold = true)]
public string CloudReportStatusDisplay
{
get
{
return CloudReportStatus switch
{
0 => "未上传",
1 => "已上传",
_ => "未知"
};
}
}
[ExporterHeader(IsIgnore = true)]
public int? CloudReportStatus { get; set; }
@ -275,7 +362,7 @@ public class ChargeOrderDto
/// Default:CURRENT_TIMESTAMP
/// Nullable:True
/// </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; }
@ -293,7 +380,7 @@ public class ChargeOrderDto
/// Default:CURRENT_TIMESTAMP
/// Nullable:True
/// </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; }
@ -310,6 +397,25 @@ public class ChargeOrderDto
/// Nullable:True
/// </summary>
[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; }
}

@ -46,7 +46,7 @@ public class SwapOrderDto
/// Default:
/// Nullable:True
/// </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; }
/// <summary>
@ -54,7 +54,7 @@ public class SwapOrderDto
/// Default:
/// Nullable:True
/// </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; }
/// <summary>
@ -62,7 +62,7 @@ public class SwapOrderDto
/// Default:
/// Nullable:True
/// </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; }
/// <summary>
@ -70,15 +70,36 @@ public class SwapOrderDto
/// Default:
/// Nullable:True
/// </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; }
/// <summary>
/// Desc:换电结果;0-未知1-成功2-失败
/// Default:0
/// Nullable:True
/// </summary>
[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; }
/// <summary>
@ -89,12 +110,29 @@ public class SwapOrderDto
[ExporterHeader(DisplayName = "失败原因", IsBold = true)]
public string FailReason { get; set; }
/// <summary>
/// Desc:上传云平台状态;0-未上传1-已上传
/// Default:0
/// Nullable:True
/// </summary>
[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; }
@ -103,12 +141,58 @@ public class SwapOrderDto
/// </summary>
[ExporterHeader(DisplayName = "云平台订单号", IsBold = true)]
public string? CloudSn { get; set; }
/// <summary>
/// Desc:换电类型:;1自动换电;2手动换电
/// Default:0
/// Nullable:True
/// </summary>
[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; }
/// <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; }
}

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

@ -45,27 +45,6 @@ public class SwapOrderService : BaseServices<SwapOrder>
return SwapOrderMgr.UploadCloud(list,2) ? Result<bool>.Success() : Result<bool>.Fail();
}
/// <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>
/// <param name="swapOrder"></param>

@ -3,7 +3,9 @@ using AutoMapper;
using Entity.Api.Req;
using Entity.Api.Resp;
using Entity.DbModel.Station;
using Entity.Dto;
using HybirdFrameworkCore.Entity;
using Magicodes.ExporterAndImporter.Excel;
using Microsoft.AspNetCore.Mvc;
using Service.Init;
using Service.Station;
@ -101,6 +103,7 @@ public class SwapOrderController : ControllerBase
// 转换换电订单
SwapOrder swapOrder = mapper.Map<SwapOrder>(req);
swapOrder.Sn = SwapOrderNoGenerator.GenerateOrderNo(StaticStationInfo.StationNo);
swapOrder.CloudReportStatus = 0;
SwapOrder order = await swapOrderService.InsertAsync(swapOrder);
bool batteriesInserted = true;
@ -198,7 +201,8 @@ public class SwapOrderController : ControllerBase
return Result<bool>.Fail("删除失败");
}
}
/// <summary>
/// 换电订单导出
/// </summary>
@ -208,7 +212,45 @@ public class SwapOrderController : ControllerBase
[Route("export")]
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>
/// 换电订单上报云端

Loading…
Cancel
Save