From 5c58db7ac30ab76c0a03e9130bc975747d18170c Mon Sep 17 00:00:00 2001
From: tq <1916474859@qq,com>
Date: Tue, 11 Jun 2024 13:40:50 +0800
Subject: [PATCH] =?UTF-8?q?=E8=AE=A2=E5=8D=95=E5=AF=BC=E5=87=BA=E4=BC=98?=
=?UTF-8?q?=E5=8C=96?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
Entity/Dto/ChargeOrderDto.cs | 116 +++++++++++++++++-
Entity/Dto/SwapOrderDto.cs | 96 ++++++++++++++-
Service/Station/ChargeOrderService.cs | 1 -
Service/Station/SwapOrderService.cs | 21 ----
WebStarter/Controllers/SwapOrderController.cs | 46 ++++++-
5 files changed, 245 insertions(+), 35 deletions(-)
diff --git a/Entity/Dto/ChargeOrderDto.cs b/Entity/Dto/ChargeOrderDto.cs
index 9b80f09..3ae9620 100644
--- a/Entity/Dto/ChargeOrderDto.cs
+++ b/Entity/Dto/ChargeOrderDto.cs
@@ -30,6 +30,25 @@ public class ChargeOrderDto
/// Nullable:True
///
[ExporterHeader(DisplayName = "启动报文状态", IsBold = true)]
+ public string CmdStatusDisplay
+ {
+ get
+ {
+ return CmdStatus switch
+ {
+ 0 => "初始化",
+ 1 => "启动成功",
+ _ => "未知"
+ };
+ }
+ }
+
+ ///
+ /// Desc:启动报文状态;0-初始化;1-启动成功
+ /// Default:0
+ /// Nullable:True
+ ///
+ [ExporterHeader(IsIgnore = true)]
public int? CmdStatus { get; set; }
@@ -51,24 +70,59 @@ public class ChargeOrderDto
public string ChargerGunNo { get; set; }
+
///
/// 0:站内充电 1:站外充电
///
[ExporterHeader(DisplayName = "充电位置", IsBold = true)]
+ public string ChargeModeDisplay
+ {
+ get
+ {
+ return ChargeMode switch
+ {
+ 0 => "站内充电",
+ 1 => "站外充电",
+ _ => "未知"
+ };
+ }
+ }
+
+ ///
+ /// 0:站内充电 1:站外充电
+ ///
+ [ExporterHeader(IsIgnore = true)]
public int ChargeMode { get; set; }
-
+
///
/// 1:站控启动 2:本地启动
///
[ExporterHeader(DisplayName = "启动方式", IsBold = true)]
+ public string StartModeDisplay
+ {
+ get
+ {
+ return StartMode switch
+ {
+ 1 => "站控启动",
+ 2 => "本地启动",
+ _ => "未知"
+ };
+ }
+ }
+
+ ///
+ /// 1:站控启动 2:本地启动
+ ///
+ [ExporterHeader(IsIgnore = true)]
public int StartMode { get; set; }
///
/// 充电开始时间
///
- [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
///
- [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
///
[ExporterHeader(DisplayName = "停止原因", IsBold = true)]
+ public string StopReasonDisplay
+ {
+ get
+ {
+ return StopReason switch
+ {
+ 0 => "满电自动停止",
+ 1 => "人工停止",
+ _ => "未知"
+ };
+ }
+ }
+ ///
+ /// Desc:停止原因;0:满电自动停止;1-人工停止
+ /// Default:0
+ /// Nullable:True
+ ///
+ [ExporterHeader(IsIgnore = true)]
public int? StopReason { get; set; }
@@ -258,6 +330,21 @@ public class ChargeOrderDto
/// Nullable:True
///
[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
///
- [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
///
- [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
///
[ExporterHeader(DisplayName = "是否可以上传云平台", IsBold = true)]
+ public string CanUploadDisplay
+ {
+ get
+ {
+ return CanUpload switch
+ {
+ 0 => "不可用",
+ 1 => "可以",
+ _ => "未知"
+ };
+ }
+ }
+
+ ///
+ /// Desc:是否可以上传云平台
+ /// Default:
+ /// Nullable:True
+ ///
+ [ExporterHeader(IsIgnore = true)]
public int? CanUpload { get; set; }
}
\ No newline at end of file
diff --git a/Entity/Dto/SwapOrderDto.cs b/Entity/Dto/SwapOrderDto.cs
index 96ed701..692c23e 100644
--- a/Entity/Dto/SwapOrderDto.cs
+++ b/Entity/Dto/SwapOrderDto.cs
@@ -46,7 +46,7 @@ public class SwapOrderDto
/// Default:
/// Nullable:True
///
- [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; }
///
@@ -54,7 +54,7 @@ public class SwapOrderDto
/// Default:
/// Nullable:True
///
- [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; }
///
@@ -62,7 +62,7 @@ public class SwapOrderDto
/// Default:
/// Nullable:True
///
- [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; }
///
@@ -70,15 +70,36 @@ public class SwapOrderDto
/// Default:
/// Nullable:True
///
- [ExporterHeader(DisplayName = "换电结束时间", IsBold = true,Width = 25)]
+ [ExporterHeader(DisplayName = "换电结束时间",Width = 30, Format = "yyyy-MM-dd HH:mm:ss", AutoCenterColumn = true)]
public DateTime? SwapEndTime { get; set; }
-
+
///
/// Desc:换电结果;0-未知;1-成功;2-失败
/// Default:0
/// Nullable:True
///
[ExporterHeader(DisplayName = "换电结果", IsBold = true)]
+ public string SwapResultDisplay
+ {
+ get
+ {
+ return SwapResult switch
+ {
+ 0 => "未知",
+ 1 => "成功",
+ 2 => "失败",
+ _ => "未知"
+ };
+ }
+ }
+
+ ///
+ /// Desc:换电结果;0-未知;1-成功;2-失败
+ /// Default:0
+ /// Nullable:True
+ ///
+ // [ExporterHeader(DisplayName = "换电结果", IsBold = true)]
+ [ExporterHeader(IsIgnore = true)]
public int? SwapResult { get; set; }
///
@@ -89,12 +110,29 @@ public class SwapOrderDto
[ExporterHeader(DisplayName = "失败原因", IsBold = true)]
public string FailReason { get; set; }
+
///
/// Desc:上传云平台状态;0-未上传;1-已上传
/// Default:0
/// Nullable: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; }
@@ -103,12 +141,58 @@ public class SwapOrderDto
///
[ExporterHeader(DisplayName = "云平台订单号", IsBold = true)]
public string? CloudSn { get; set; }
-
+
///
/// Desc:换电类型:;1自动换电;2手动换电
/// Default:0
/// Nullable:True
///
[ExporterHeader(DisplayName = "换电类型", IsBold = true)]
+ public string SwapWayDisplay
+ {
+ get
+ {
+ return SwapWay switch
+ {
+ 1 => "自动换电",
+ 2 => "手动换电",
+ _ => "未知"
+ };
+ }
+ }
+ ///
+ /// Desc:换电类型:;1自动换电;2手动换电
+ /// Default:0
+ /// Nullable:True
+ ///
+ [ExporterHeader(IsIgnore = true)]
public int? SwapWay { get; set; }
+
+
+
+ ///
+ /// Desc:亏电包soc
+ /// Default:
+ /// Nullable:True
+ ///
+ [ExporterHeader(DisplayName = "亏电包soc", IsBold = true)]
+
+ public decimal? DownBatterySoc { get; set; }
+ ///
+ /// Desc:亏电包真实soc
+ /// Default:
+ /// Nullable:True
+ ///
+ [ExporterHeader(DisplayName = "亏电包真实soc", IsBold = true)]
+
+ public decimal? DownBatteryRealSoc { get; set; }
+
+ ///
+ /// Desc:亏电包上次换电结算时soc
+ /// Default:
+ /// Nullable:True
+ ///
+ [ExporterHeader(DisplayName = "亏电包上次换电结算时soc", IsBold = true)]
+
+ public decimal? DownBatteryLastSoc { get; set; }
}
\ No newline at end of file
diff --git a/Service/Station/ChargeOrderService.cs b/Service/Station/ChargeOrderService.cs
index 8473cd6..e2064a7 100644
--- a/Service/Station/ChargeOrderService.cs
+++ b/Service/Station/ChargeOrderService.cs
@@ -59,7 +59,6 @@ public class ChargeOrderService : BaseServices
{
// 查询订单
List chargeOrders = await QueryChargeOrderListAsync(chargeOrder);
-
var config = new MapperConfiguration(cfg =>
{ cfg.CreateMap().ReverseMap(); });
diff --git a/Service/Station/SwapOrderService.cs b/Service/Station/SwapOrderService.cs
index 5c74171..f2bd209 100644
--- a/Service/Station/SwapOrderService.cs
+++ b/Service/Station/SwapOrderService.cs
@@ -45,27 +45,6 @@ public class SwapOrderService : BaseServices
return SwapOrderMgr.UploadCloud(list,2) ? Result.Success() : Result.Fail();
}
///
- /// 导出充电订单
- ///
- ///
- ///
- public async Task ExportSwapOrder(QuerySwapOrderPageReq swapOrder)
- {
- // 查询订单
- List swapOrders = await QuerySwapOrderListAsync(swapOrder);
-
-
- var config = new MapperConfiguration(cfg => { cfg.CreateMap().ReverseMap(); });
- IMapper mapper = config.CreateMapper();
-
- List list = mapper.Map>(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" };
- }
- ///
/// 查询需要导出换电订单
///
///
diff --git a/WebStarter/Controllers/SwapOrderController.cs b/WebStarter/Controllers/SwapOrderController.cs
index 1ab5997..d4c9e3a 100644
--- a/WebStarter/Controllers/SwapOrderController.cs
+++ b/WebStarter/Controllers/SwapOrderController.cs
@@ -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(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.Fail("删除失败");
}
}
-
+
+
///
/// 换电订单导出
///
@@ -208,7 +212,45 @@ public class SwapOrderController : ControllerBase
[Route("export")]
public async Task ExportSwapOrder([FromBody] QuerySwapOrderPageReq req)
{
- return await swapOrderService.ExportSwapOrder(req);
+ List orderList = await swapOrderService.QuerySwapOrderListAsync(req);
+
+ //获取所有订单号
+ var orderSns = orderList.Select(row => row.Sn).ToList();
+
+ //查询订单电池数据
+ List batteryList =
+ swapOrderBatteryService.QueryListByClause(u => orderSns.Contains(u.SwapOrderSn));
+
+ //映射
+ var config = new MapperConfiguration(cfg =>
+ {
+ cfg.CreateMap().ReverseMap();
+ cfg.CreateMap().ReverseMap();
+ });
+ IMapper mapper = config.CreateMapper();
+
+ List swapOrderBattery = mapper.Map>(batteryList);
+ List list = mapper.Map>(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" };
}
///
/// 换电订单上报云端