From 4568ec8aaab72126979847cc84f67dd61f6d7947 Mon Sep 17 00:00:00 2001 From: tq <1916474859@qq,com> Date: Thu, 6 Jun 2024 15:16:58 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E7=94=B5=E4=BB=B7=E7=B1=BB?= =?UTF-8?q?=E5=9E=8B,=E5=A2=9E=E5=8A=A0=E8=AE=A2=E5=8D=95=E5=AF=BC?= =?UTF-8?q?=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Entity/Api/Req/AddSwapOrderReq.cs | 4 +- .../Api/Req/ElecPriceModelVersionDetailReq.cs | 20 +- Entity/Api/Req/ModifySwapOrderReq.cs | 4 +- Entity/Api/Req/QuerySwapOrderPageReq.cs | 7 + Entity/Api/Req/SwapOrderBatteryReq.cs | 7 +- Entity/Api/Req/UpdateSwapOrderBatteryReq.cs | 11 +- Entity/Api/Resp/SwapOrderResp.cs | 5 + .../Station/ElecPriceModelVersionDetail.cs | 18 +- Entity/Dto/ChargeOrderDto.cs | 315 ++++++++++++++++++ Entity/Dto/SwapOrderDto.cs | 114 +++++++ Repository/Station/ChargeOrderRepository.cs | 55 +++ Repository/Station/SwapOrderRepository.cs | 63 +++- Service/Station/ChargeOrderService.cs | 61 +++- Service/Station/SwapOrderService.cs | 73 +++- .../Controllers/ChargeOrderController.cs | 12 +- WebStarter/Controllers/SwapOrderController.cs | 12 +- WebStarter/db/lxw0527.sql | 2 + 17 files changed, 743 insertions(+), 40 deletions(-) create mode 100644 Entity/Dto/ChargeOrderDto.cs create mode 100644 Entity/Dto/SwapOrderDto.cs diff --git a/Entity/Api/Req/AddSwapOrderReq.cs b/Entity/Api/Req/AddSwapOrderReq.cs index 7fe788a..bcf34b8 100644 --- a/Entity/Api/Req/AddSwapOrderReq.cs +++ b/Entity/Api/Req/AddSwapOrderReq.cs @@ -122,10 +122,10 @@ /// Default:0 /// Nullable:True /// - public int? SwapModel { get; set; } + public int? SwapWay { get; set; } /// /// 换电电池 /// - public List batteryList; + public List batteryList { get; set; } } } diff --git a/Entity/Api/Req/ElecPriceModelVersionDetailReq.cs b/Entity/Api/Req/ElecPriceModelVersionDetailReq.cs index 5eb8cd4..7912b89 100644 --- a/Entity/Api/Req/ElecPriceModelVersionDetailReq.cs +++ b/Entity/Api/Req/ElecPriceModelVersionDetailReq.cs @@ -10,11 +10,25 @@ public partial class ElecPriceModelVersionDetailReq /// 版本 /// public int Version {get;set;} + private double _price; /// - /// 价格 + /// Desc:价格;以分为单位存储 + /// Default: + /// Nullable:True /// - // public int? Price {get;set;} - public double Price { get; set; } + // [SugarColumn(ColumnName="price")] + public double Price + { + get => _price; + set + { + if (value < 0) + { + throw new ArgumentException("电价不能为负数"); + } + _price = Math.Round(value, 4); + } + } diff --git a/Entity/Api/Req/ModifySwapOrderReq.cs b/Entity/Api/Req/ModifySwapOrderReq.cs index 68770dd..63468d3 100644 --- a/Entity/Api/Req/ModifySwapOrderReq.cs +++ b/Entity/Api/Req/ModifySwapOrderReq.cs @@ -130,10 +130,10 @@ namespace Entity.Api.Req /// Default:0 /// Nullable:True /// - public int? SwapModel { get; set; } + public int? SwapWay { get; set; } /// /// 换电电池 /// - public List batteryList; + public List batteryList { get; set; } } } diff --git a/Entity/Api/Req/QuerySwapOrderPageReq.cs b/Entity/Api/Req/QuerySwapOrderPageReq.cs index e7dd063..1c36a6a 100644 --- a/Entity/Api/Req/QuerySwapOrderPageReq.cs +++ b/Entity/Api/Req/QuerySwapOrderPageReq.cs @@ -53,4 +53,11 @@ public class QuerySwapOrderPageReq : QueryPageModel /// Nullable:True /// public int SwapResult { get; set; } + /// + /// Desc:换电类型 + /// Default:0 + /// Nullable:True + /// + public int? SwapWay { get; set; } + } \ No newline at end of file diff --git a/Entity/Api/Req/SwapOrderBatteryReq.cs b/Entity/Api/Req/SwapOrderBatteryReq.cs index 8950cee..1d0f00c 100644 --- a/Entity/Api/Req/SwapOrderBatteryReq.cs +++ b/Entity/Api/Req/SwapOrderBatteryReq.cs @@ -5,7 +5,12 @@ /// public class SwapOrderBatteryReq { - + /// + /// Desc:id + /// Default: + /// Nullable:False + /// + public int Id { get; set; } /// /// Desc:亏电包编码 /// Default: diff --git a/Entity/Api/Req/UpdateSwapOrderBatteryReq.cs b/Entity/Api/Req/UpdateSwapOrderBatteryReq.cs index bcf656c..8974b3d 100644 --- a/Entity/Api/Req/UpdateSwapOrderBatteryReq.cs +++ b/Entity/Api/Req/UpdateSwapOrderBatteryReq.cs @@ -2,13 +2,8 @@ namespace Entity.Api.Req; -public class UpdateSwapOrderBatteryReq:SwapOrderBatteryReq +public class UpdateSwapOrderBatteryReq :SwapOrderBatteryReq { - /// - /// Desc:id - /// Default: - /// Nullable:False - /// - [Required] - public int Id { get; set; } + + } \ No newline at end of file diff --git a/Entity/Api/Resp/SwapOrderResp.cs b/Entity/Api/Resp/SwapOrderResp.cs index f691e38..f77888d 100644 --- a/Entity/Api/Resp/SwapOrderResp.cs +++ b/Entity/Api/Resp/SwapOrderResp.cs @@ -124,6 +124,11 @@ namespace Entity.Api.Resp /// 云平台订单号 /// public string? CloudSn { get; set; } + /// + /// 换电类型 + /// + public int? SwapWay { get; set; } + ///// ///// 换电电池 ///// diff --git a/Entity/DbModel/Station/ElecPriceModelVersionDetail.cs b/Entity/DbModel/Station/ElecPriceModelVersionDetail.cs index 4c79012..b0557a8 100644 --- a/Entity/DbModel/Station/ElecPriceModelVersionDetail.cs +++ b/Entity/DbModel/Station/ElecPriceModelVersionDetail.cs @@ -61,14 +61,26 @@ namespace Entity.DbModel.Station [SugarColumn(ColumnName = "end_second")] public int EndSecond { get; set; } + + private double _price; /// /// Desc:价格;以分为单位存储 /// Default: /// Nullable:True /// - // [SugarColumn(ColumnName="price")] - // public int? Price {get;set;} - public double Price { get; set; } + // [SugarColumn(ColumnName="price")] + public double Price + { + get => _price; + set + { + if (value < 0) + { + throw new ArgumentException("电价不能为负数"); + } + _price = Math.Round(value, 4); + } + } /// /// Desc:尖峰平谷类型;1-尖;2-峰;3-平;4-谷 diff --git a/Entity/Dto/ChargeOrderDto.cs b/Entity/Dto/ChargeOrderDto.cs new file mode 100644 index 0000000..4ad17bb --- /dev/null +++ b/Entity/Dto/ChargeOrderDto.cs @@ -0,0 +1,315 @@ +using Magicodes.ExporterAndImporter.Core; +using Magicodes.ExporterAndImporter.Excel; + +namespace Entity.Dto; + +[ExcelExporter(Name = "充电订单", TableStyle = OfficeOpenXml.Table.TableStyles.None, AutoFitAllColumn = true)] +public class ChargeOrderDto +{ + /// + /// Desc:订单编号 + /// Default: + /// Nullable:True + /// + [ExporterHeader(DisplayName = "订单编号", IsBold = true)] + + public string Sn { get; set; } + + /// + /// Desc:电池编号 + /// Default: + /// Nullable:True + /// + [ExporterHeader(DisplayName = "电池编号", IsBold = true)] + + public string BatteryNo { get; set; } + + /// + /// Desc:启动报文状态;0-初始化;1-启动成功 + /// Default:0 + /// Nullable:True + /// + [ExporterHeader(DisplayName = "启动报文状态", IsBold = true)] + + public int? CmdStatus { get; set; } + + /// + /// Desc:充电机编号 + /// Default: + /// Nullable:True + /// + [ExporterHeader(DisplayName = "充电机编号", IsBold = true)] + + public string ChargerNo { get; set; } + + /// + /// Desc:充电枪编号 + /// Default: + /// Nullable:True + /// + [ExporterHeader(DisplayName = "充电枪编号", IsBold = true)] + + public string ChargerGunNo { get; set; } + + /// + /// 0:站内充电 1:站外充电 + /// + [ExporterHeader(DisplayName = "充电位置", IsBold = true)] + + public int ChargeMode { get; set; } + + /// + /// 1:站控启动 2:本地启动 + /// + [ExporterHeader(DisplayName = "启动方式", IsBold = true)] + + public int StartMode { get; set; } + + /// + /// 充电开始时间 + /// + [ExporterHeader(DisplayName = "充电开始时间", IsBold = true,Width = 25)] + + public DateTime? StartTime { get; set; } + + /// + /// Desc:充电结束时间 + /// Default: + /// Nullable:True + /// + [ExporterHeader(DisplayName = "充电结束时间", IsBold = true,Width = 25)] + + public DateTime? EndTime { get; set; } + + /// + /// Desc:充电开始soc + /// Default: + /// Nullable:True + /// + [ExporterHeader(DisplayName = "充电开始soc", IsBold = true)] + + public int? StartSoc { get; set; } + + /// + /// Desc:充电结束soc + /// Default: + /// Nullable:True + /// + [ExporterHeader(DisplayName = "充电结束soc", IsBold = true)] + + public int? StopSoc { get; set; } + + /// + /// Desc:充电时长 + /// Default: + /// Nullable:True + /// + [ExporterHeader(DisplayName = "充电时长", IsBold = true)] + + public int ChargeTimeCount { get; set; } + + /// + /// Desc:充电电量 + /// Default: + /// Nullable:True + /// + [ExporterHeader(DisplayName = "充电电量", IsBold = true)] + + public decimal? ElecCount { get; set; } + + /// + /// Desc:充电开始交流表电量 + /// Default: + /// Nullable:True + /// + [ExporterHeader(DisplayName = "充电开始交流表电量", IsBold = true)] + + public decimal? StartAcElec { get; set; } + + /// + /// Desc:充电结束交流表电量 + /// Default: + /// Nullable:True + /// + [ExporterHeader(DisplayName = "充电结束交流表电量", IsBold = true)] + + public decimal? StopAcElec { get; set; } + + /// + /// Desc:充电开始直流表电量 + /// Default: + /// Nullable:True + /// + [ExporterHeader(DisplayName = "充电开始直流表电量", IsBold = true)] + + public decimal? StartDcElec { get; set; } + + /// + /// Desc:充电结束直流表电量 + /// Default: + /// Nullable:True + /// + [ExporterHeader(DisplayName = "充电结束直流表电量", IsBold = true)] + + public decimal? StopDcElec { get; set; } + + /// + /// Desc:停止原因;0:满电自动停止;1-人工停止 + /// Default:0 + /// Nullable:True + /// + [ExporterHeader(DisplayName = "停止原因", IsBold = true)] + + public int? StopReason { get; set; } + + /// + /// Desc:尖时段电量 + /// Default: + /// Nullable:True + /// + [ExporterHeader(DisplayName = "尖时段电量", IsBold = true)] + + public decimal? SharpElecCount { get; set; } + + /// + /// Desc:峰时段电量 + /// Default: + /// Nullable:True + /// + [ExporterHeader(DisplayName = "峰时段电量", IsBold = true)] + + public decimal? PeakElecCount { get; set; } + + /// + /// Desc:平时段电量 + /// Default: + /// Nullable:True + /// + [ExporterHeader(DisplayName = "平时段电量", IsBold = true)] + + public decimal? FlatElecCount { get; set; } + + /// + /// Desc:谷时段电量 + /// Default: + /// Nullable:True + /// + [ExporterHeader(DisplayName = "谷时段电量", IsBold = true)] + + public decimal? ValleyElecCount { get; set; } + + /// + /// Desc:尖时段交流电量 + /// Default: + /// Nullable:True + /// + [ExporterHeader(DisplayName = "尖时段交流电量", IsBold = true)] + + public decimal? ACSharpElecCount { get; set; } + + /// + /// Desc:峰时段交流电量 + /// Default: + /// Nullable:True + /// + [ExporterHeader(DisplayName = "峰时段交流电量", IsBold = true)] + + public decimal? ACPeakElecCount { get; set; } + + /// + /// Desc:平时段交流电量 + /// Default: + /// Nullable:True + /// + [ExporterHeader(DisplayName = "平时段交流电量", IsBold = true)] + + public decimal? ACFlatElecCount { get; set; } + + /// + /// Desc:谷时段交流电量 + /// Default: + /// Nullable:True + /// + [ExporterHeader(DisplayName = "谷时段交流电量", IsBold = true)] + + public decimal? ACValleyElecCount { get; set; } + + /// + /// Desc:电价版本号 + /// Default: + /// Nullable:True + /// + [ExporterHeader(DisplayName = "电价版本号", IsBold = true)] + + public string ElecPriceModelVersion { get; set; } + + /// + /// Desc:换电订单编号 + /// Default: + /// Nullable:True + /// + [ExporterHeader(DisplayName = "换电订单编号", IsBold = true)] + + public string SwapOrderSn { get; set; } + + /// + /// Desc:上传云平台状态;0-未上传;1-已上传 + /// Default:0 + /// Nullable:True + /// + [ExporterHeader(DisplayName = "上传云平台状态", IsBold = true)] + + public int? CloudReportStatus { get; set; } + + /// + /// Desc:创建人 + /// Default: + /// Nullable:True + /// + [ExporterHeader(DisplayName = "创建人", IsBold = true)] + + public string CreatedBy { get; set; } + + /// + /// Desc:创建时间 + /// Default:CURRENT_TIMESTAMP + /// Nullable:True + /// + [ExporterHeader(DisplayName = "创建时间", IsBold = true,Width = 25)] + + public DateTime? CreatedTime { get; set; } + + /// + /// Desc:更新人 + /// Default: + /// Nullable:True + /// + [ExporterHeader(DisplayName = "更新人", IsBold = true,Width = 25)] + + public string UpdatedBy { get; set; } + + /// + /// Desc:更新时间 + /// Default:CURRENT_TIMESTAMP + /// Nullable:True + /// + [ExporterHeader(DisplayName = "更新时间", IsBold = true)] + + public DateTime? UpdatedTime { get; set; } + + /// + /// 云平台充电订单 + /// + [ExporterHeader(DisplayName = "云平台充电订单", IsBold = true)] + + public string? CloudChargeOrder { get; set; } + + /// + /// Desc:是否可以上传云平台 + /// Default: + /// Nullable:True + /// + [ExporterHeader(DisplayName = "是否可以上传云平台", IsBold = true)] + + public int? CanUpload { get; set; } +} \ No newline at end of file diff --git a/Entity/Dto/SwapOrderDto.cs b/Entity/Dto/SwapOrderDto.cs new file mode 100644 index 0000000..96ed701 --- /dev/null +++ b/Entity/Dto/SwapOrderDto.cs @@ -0,0 +1,114 @@ +using Magicodes.ExporterAndImporter.Core; +using Magicodes.ExporterAndImporter.Excel; + +namespace Entity.Dto; + +/// +/// 换电订单导出 +/// +[ExcelExporter(Name = "换电订单", TableStyle = OfficeOpenXml.Table.TableStyles.None, AutoFitAllColumn = true)] +public class SwapOrderDto +{ + /// + /// Desc:订单编号 + /// Default: + /// Nullable:True + /// + [ExporterHeader(DisplayName = "订单编号", IsBold = true)] + public string Sn { get; set; } + + /// + /// Desc:车牌号 + /// Default: + /// Nullable:True + /// + [ExporterHeader(DisplayName = "车牌号", IsBold = true)] + public string VehicleNo { get; set; } + + /// + /// Desc:车辆mac + /// Default: + /// Nullable:True + /// + [ExporterHeader(DisplayName = "车辆mac", IsBold = true)] + public string VehicleMac { get; set; } + + /// + /// Desc:车辆vin码 + /// Default: + /// Nullable:True + /// + [ExporterHeader(DisplayName = "车辆vin码", IsBold = true)] + public string VehicleVin { get; set; } + + /// + /// Desc:车辆进场时间 + /// Default: + /// Nullable:True + /// + [ExporterHeader(DisplayName = "车辆进场时间", IsBold = true,Width = 25)] + public DateTime? VehicleEnterTime { get; set; } + + /// + /// Desc:车辆离场时间 + /// Default: + /// Nullable:True + /// + [ExporterHeader(DisplayName = "车辆离场时间", IsBold = true,Width = 25)] + public DateTime? VehicleLeaveTime { get; set; } + + /// + /// Desc:换电开始时间 + /// Default: + /// Nullable:True + /// + [ExporterHeader(DisplayName = "换电开始时间", IsBold = true,Width = 25)] + public DateTime? SwapBeginTime { get; set; } + + /// + /// Desc:换电结束时间 + /// Default: + /// Nullable:True + /// + [ExporterHeader(DisplayName = "换电结束时间", IsBold = true,Width = 25)] + public DateTime? SwapEndTime { get; set; } + + /// + /// Desc:换电结果;0-未知;1-成功;2-失败 + /// Default:0 + /// Nullable:True + /// + [ExporterHeader(DisplayName = "换电结果", IsBold = true)] + public int? SwapResult { get; set; } + + /// + /// Desc:失败原因 + /// Default: + /// Nullable:True + /// + [ExporterHeader(DisplayName = "失败原因", IsBold = true)] + public string FailReason { get; set; } + + /// + /// Desc:上传云平台状态;0-未上传;1-已上传 + /// Default:0 + /// Nullable:True + /// + [ExporterHeader(DisplayName = "上传云平台状态", IsBold = true)] + public int? CloudReportStatus { get; set; } + + + /// + /// 云平台订单号 + /// + [ExporterHeader(DisplayName = "云平台订单号", IsBold = true)] + public string? CloudSn { get; set; } + + /// + /// Desc:换电类型:;1自动换电;2手动换电 + /// Default:0 + /// Nullable:True + /// + [ExporterHeader(DisplayName = "换电类型", IsBold = true)] + public int? SwapWay { get; set; } +} \ No newline at end of file diff --git a/Repository/Station/ChargeOrderRepository.cs b/Repository/Station/ChargeOrderRepository.cs index 71738ab..3b2ed44 100644 --- a/Repository/Station/ChargeOrderRepository.cs +++ b/Repository/Station/ChargeOrderRepository.cs @@ -1,5 +1,7 @@ +using System.Linq.Expressions; using Entity.DbModel.Station; using HybirdFrameworkCore.Autofac.Attribute; +using HybirdFrameworkCore.Entity; using SqlSugar; namespace Repository.Station; @@ -11,4 +13,57 @@ public class ChargeOrderRepository : BaseRepository public ChargeOrderRepository(ISqlSugarClient sqlSugar) : base(sqlSugar) { } + public IPage QueryIPage(QueryPageModel page, Expression> predicate) + { + if (null == predicate) + { + return QueryPage(page); + } + + int totalCount = 0; + + + List pageList = DbBaseClient + .Queryable() + .Where(predicate) + .OrderByDescending(x => x.CreatedTime) + .WithNoLockOrNot(false) + .ToPageList(page.PageNum, page.PageSize, ref totalCount); + + return new IPage(totalCount, page, pageList); + } + /// + /// 查询需要导出充电订单 + /// + /// + /// + public async Task> QueryChargeOrderList(Expression> predicate) + { + if (predicate == null) + { + return await QueryAsync(); + } + + List resultList = await DbBaseClient + .Queryable() + .Where(predicate) + .WithNoLockOrNot(false) + .ToListAsync(); + + return resultList; + } + + public IPage QueryPage(QueryPageModel page) + { + int totalCount = 0; + + + List pageList = DbBaseClient + .Queryable() + .OrderByDescending(x => x.CreatedTime) + .WithNoLockOrNot(false) + .ToPageList(page.PageNum, page.PageSize, ref totalCount); + + return new IPage(totalCount, page, pageList); + } } \ No newline at end of file diff --git a/Repository/Station/SwapOrderRepository.cs b/Repository/Station/SwapOrderRepository.cs index 1d80947..fa40225 100644 --- a/Repository/Station/SwapOrderRepository.cs +++ b/Repository/Station/SwapOrderRepository.cs @@ -1,14 +1,73 @@ +using System.Linq.Expressions; using Entity.DbModel.Station; using HybirdFrameworkCore.Autofac.Attribute; +using HybirdFrameworkCore.Entity; using SqlSugar; namespace Repository.Station; [Scope("SingleInstance")] -public class SwapOrderRepository:BaseRepository +public class SwapOrderRepository : BaseRepository { - public SwapOrderRepository(ISqlSugarClient sqlSugar) : base(sqlSugar) { } + + /// + /// 查询需要导出换电订单 + /// + /// + /// + public async Task> QuerySwapOrderList(Expression> predicate) + { + if (predicate == null) + { + return await QueryAsync(); + } + + List resultList = await DbBaseClient + .Queryable() + .Where(predicate) + .WithNoLockOrNot(false) + .ToListAsync(); + + return resultList; + } + + + public IPage QueryIPage(QueryPageModel page, Expression> predicate) + { + if (null == predicate) + { + return QueryPage(page); + } + + int totalCount = 0; + + + List pageList = DbBaseClient + .Queryable() + .Where(predicate) + .OrderByDescending(x => x.CreatedTime) + .WithNoLockOrNot(false) + .ToPageList(page.PageNum, page.PageSize, ref totalCount); + + return new IPage(totalCount, page, pageList); + } + + public IPage QueryPage(QueryPageModel page) + { + int totalCount = 0; + + + List pageList = DbBaseClient + .Queryable() + .OrderByDescending(x => x.CreatedTime) + .WithNoLockOrNot(false) + .ToPageList(page.PageNum, page.PageSize, ref totalCount); + + return new IPage(totalCount, page, pageList); + } + + } \ No newline at end of file diff --git a/Service/Station/ChargeOrderService.cs b/Service/Station/ChargeOrderService.cs index 84cebe3..8473cd6 100644 --- a/Service/Station/ChargeOrderService.cs +++ b/Service/Station/ChargeOrderService.cs @@ -1,10 +1,15 @@ using System.Linq.Expressions; +using AutoMapper; using Entity.Api.Req; using Entity.Api.Resp; using Entity.DbModel.Station; +using Entity.Dto; +using Entity.Dto.Req; using HybirdFrameworkCore.Autofac.Attribute; using HybirdFrameworkCore.Entity; using HybirdFrameworkCore.Utils; +using Magicodes.ExporterAndImporter.Excel; +using Microsoft.AspNetCore.Mvc; using Repository.Station; using Service.Cloud.Client; @@ -35,8 +40,58 @@ public class ChargeOrderService : BaseServices Expression> where = null; //// 定义参数表达式 ParameterExpression parameter = Expression.Parameter(typeof(ChargeOrder), "u"); + + #region 构建动态查询树 + where = queryTree(chargeOrder, where, parameter); + + #endregion + + //查询 + return PageResult.ConvertPage(chargeOrderRepository.QueryIPage(chargeOrder, where)); + + } + /// + /// 导出充电订单 + /// + /// + /// + public async Task ExportChargeOrder(QueryChargeOrderReq chargeOrder) + { + // 查询订单 + List chargeOrders = await QueryChargeOrderListAsync(chargeOrder); + + + var config = new MapperConfiguration(cfg => + { cfg.CreateMap().ReverseMap(); }); + IMapper mapper = config.CreateMapper(); + + List list = mapper.Map>(chargeOrders); + + 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" }; + } + /// + /// 查询需要导出订单 + /// + /// + /// + public async Task> QueryChargeOrderListAsync(QueryChargeOrderReq chargeOrder) + { + Expression> where = null; + ParameterExpression parameter = Expression.Parameter(typeof(ChargeOrder), "u"); #region 构建动态查询树 + where = queryTree(chargeOrder, where, parameter); + #endregion + + // 查询需要导出充电订单 不分页 + return await chargeOrderRepository.QueryChargeOrderList(where); + } + + private static Expression>? queryTree(QueryChargeOrderReq chargeOrder, Expression>? where, ParameterExpression parameter) + { if (chargeOrder.Id != 0) { Expression> condition1Expr = u => u.Id == chargeOrder.Id; @@ -101,13 +156,11 @@ public class ChargeOrderService : BaseServices Expression> condition2Expr = u => u.CloudChargeOrder == chargeOrder.CloudChargeOrder; where = where == null ? condition2Expr : Expression.Lambda>(Expression.AndAlso(where.Body, condition2Expr.Body), parameter); } - #endregion - - //查询 - return PageResult.ConvertPage(chargeOrderRepository.QueryIPageByCause(chargeOrder, where)); + return where; } + /// /// /// diff --git a/Service/Station/SwapOrderService.cs b/Service/Station/SwapOrderService.cs index 203e612..5c74171 100644 --- a/Service/Station/SwapOrderService.cs +++ b/Service/Station/SwapOrderService.cs @@ -6,6 +6,10 @@ using HybirdFrameworkCore.Entity; using Repository.Station; using SqlSugar; using System.Linq.Expressions; +using AutoMapper; +using Entity.Dto; +using Magicodes.ExporterAndImporter.Excel; +using Microsoft.AspNetCore.Mvc; using Service.Mgr; namespace Service.Station; @@ -40,8 +44,44 @@ 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" }; + } + /// + /// 查询需要导出换电订单 + /// + /// + /// + public async Task> QuerySwapOrderListAsync(QuerySwapOrderPageReq swapOrder) + { + Expression> where = null; + ParameterExpression parameter = Expression.Parameter(typeof(SwapOrder), "u"); + + #region 构建动态查询树 + where = queryTree(swapOrder, where, parameter); + #endregion + + // 查询需要导出充电订单 不分页 + return await swapOrderRepository.QuerySwapOrderList(where); + } /// /// 根据条件查询分页数据 /// @@ -56,6 +96,25 @@ public class SwapOrderService : BaseServices #region 构建动态查询树 + where = queryTree(swapOrder, where, parameter); + + #endregion + + //查询 + + //var swapOrderResp = PageResult.ConvertPage(swapOrderRepository.QueryIPageByCause(swapOrder, where)); + //for (int i = 0; i < swapOrderResp.Rows.Count; i++) + //{ + // swapOrderResp.Rows[0].BatteryList.AddRange() + //} + + //List BatteryList = new List(); + //List StepList = new List(); + return PageResult.ConvertPage(swapOrderRepository.QueryIPage(swapOrder, where)); + } + + private static Expression>? queryTree(QuerySwapOrderPageReq swapOrder, Expression>? where, ParameterExpression parameter) + { if (!string.IsNullOrEmpty(swapOrder.Sn)) { Expression> condition2Expr = u => u.Sn == swapOrder.Sn; @@ -119,18 +178,6 @@ public class SwapOrderService : BaseServices parameter); } - #endregion - - //查询 - - //var swapOrderResp = PageResult.ConvertPage(swapOrderRepository.QueryIPageByCause(swapOrder, where)); - //for (int i = 0; i < swapOrderResp.Rows.Count; i++) - //{ - // swapOrderResp.Rows[0].BatteryList.AddRange() - //} - - //List BatteryList = new List(); - //List StepList = new List(); - return PageResult.ConvertPage(swapOrderRepository.QueryIPageByCause(swapOrder, where)); + return where; } } \ No newline at end of file diff --git a/WebStarter/Controllers/ChargeOrderController.cs b/WebStarter/Controllers/ChargeOrderController.cs index 477f7d5..375d58e 100644 --- a/WebStarter/Controllers/ChargeOrderController.cs +++ b/WebStarter/Controllers/ChargeOrderController.cs @@ -56,7 +56,17 @@ public class ChargeOrderController : ControllerBase } } - + /// + /// 充电订单导出 + /// + /// + /// + [HttpPost] + [Route("export")] + public async Task ExportChargeOrder([FromBody] QueryChargeOrderReq req) + { + return await chargeOrderService.ExportChargeOrder(req); + } /// /// 充电订单上报云端,入参传 CloudChargeOrder /// diff --git a/WebStarter/Controllers/SwapOrderController.cs b/WebStarter/Controllers/SwapOrderController.cs index a38657f..1ab5997 100644 --- a/WebStarter/Controllers/SwapOrderController.cs +++ b/WebStarter/Controllers/SwapOrderController.cs @@ -199,7 +199,17 @@ public class SwapOrderController : ControllerBase } } - + /// + /// 换电订单导出 + /// + /// + /// + [HttpPost] + [Route("export")] + public async Task ExportSwapOrder([FromBody] QuerySwapOrderPageReq req) + { + return await swapOrderService.ExportSwapOrder(req); + } /// /// 换电订单上报云端 /// diff --git a/WebStarter/db/lxw0527.sql b/WebStarter/db/lxw0527.sql index d78af52..b390f04 100644 --- a/WebStarter/db/lxw0527.sql +++ b/WebStarter/db/lxw0527.sql @@ -24,3 +24,5 @@ CREATE TABLE `manual_operation_record` ( `type` int DEFAULT NULL COMMENT '人工操作;1人工确认成功;2人工确认失败', PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; +-- 修改电价模型表,字段类型 +ALTER TABLE elec_price_model_version_detail MODIFY COLUMN price DOUBLE;