diff --git a/Entity/Api/Req/AddSwapOrderReq.cs b/Entity/Api/Req/AddSwapOrderReq.cs index 89f3462..7fe788a 100644 --- a/Entity/Api/Req/AddSwapOrderReq.cs +++ b/Entity/Api/Req/AddSwapOrderReq.cs @@ -117,5 +117,15 @@ /// 云平台订单号 /// public string? CloudSn { get;set;} + /// + /// Desc:换电类型:;0手动换电;1自动换电 + /// Default:0 + /// Nullable:True + /// + public int? SwapModel { get; set; } + /// + /// 换电电池 + /// + public List batteryList; } } diff --git a/Entity/Api/Req/ElecPriceModelVersionDetailReq.cs b/Entity/Api/Req/ElecPriceModelVersionDetailReq.cs index cb1a620..5eb8cd4 100644 --- a/Entity/Api/Req/ElecPriceModelVersionDetailReq.cs +++ b/Entity/Api/Req/ElecPriceModelVersionDetailReq.cs @@ -1,3 +1,5 @@ +using System.ComponentModel.DataAnnotations; + namespace Entity.Api.Req; public partial class ElecPriceModelVersionDetailReq @@ -11,7 +13,11 @@ public partial class ElecPriceModelVersionDetailReq /// /// 价格 /// - public int? Price {get;set;} + // public int? Price {get;set;} + public double Price { get; set; } + + + /// /// Desc:尖峰平谷类型;1-尖;2-峰;3-平;4-谷 /// diff --git a/Entity/Api/Req/ModifySwapOrderReq.cs b/Entity/Api/Req/ModifySwapOrderReq.cs index c62d9a7..68770dd 100644 --- a/Entity/Api/Req/ModifySwapOrderReq.cs +++ b/Entity/Api/Req/ModifySwapOrderReq.cs @@ -124,6 +124,16 @@ namespace Entity.Api.Req /// 云平台订单号 /// public string? CloudSn { get; set; } - + + /// + /// Desc:换电类型:;0手动换电;1自动换电 + /// Default:0 + /// Nullable:True + /// + public int? SwapModel { get; set; } + /// + /// 换电电池 + /// + public List batteryList; } } diff --git a/Entity/Api/Req/SwapOrderBatteryReq.cs b/Entity/Api/Req/SwapOrderBatteryReq.cs new file mode 100644 index 0000000..8950cee --- /dev/null +++ b/Entity/Api/Req/SwapOrderBatteryReq.cs @@ -0,0 +1,162 @@ +namespace Entity.Api.Req; + +/// +///换电订单电池 +/// +public class SwapOrderBatteryReq +{ + + /// + /// Desc:亏电包编码 + /// Default: + /// Nullable:True + /// + public string? DownBatteryNo { get; set; } + + /// + /// Desc:亏电包soc + /// Default: + /// Nullable:True + /// + public decimal? DownBatterySoc { get; set; } + + /// + /// Desc:亏电包soe + /// Default: + /// Nullable:True + /// + public decimal? DownBatterySoe { get; set; } + + /// + /// Desc:亏电包真实soc + /// Default: + /// Nullable:True + /// + public decimal? DownBatteryRealSoc { get; set; } + + /// + /// Desc:亏电包上次换电结算时soc + /// Default: + /// Nullable:True + /// + public decimal? DownBatteryLastSoc { get; set; } + + /// + /// Desc:亏电包上次换电结算时soe + /// Default: + /// Nullable:True + /// + public decimal? DownBatteryLastSoe { get; set; } + + /// + /// Desc:亏电包站内充电能量(累计) + /// Default: + /// Nullable:True + /// + public decimal? DownBatteryInChageElecCount { get; set; } + + /// + /// Desc:亏电包站外插枪充电能量(累计) + /// Default: + /// Nullable:True + /// + public decimal? DownBatteryOutChageElecCount { get; set; } + + /// + /// Desc:亏电包站外回充能量(累计) + /// Default: + /// Nullable:True + /// + public decimal? DownBatteryOutReChagreCount { get; set; } + + /// + /// Desc:亏电包站外放电能量(累计) + /// Default: + /// Nullable:True + /// + public decimal? DownBatteryInDischageElecCount { get; set; } + + /// + /// Desc:亏电包站内放电电能量(累计) + /// Default: + /// Nullable:True + /// + public decimal? DownBatteryOutDischageElecCount { get; set; } + + /// + /// Desc:放电池仓位号 亏电包仓号 + /// Default: + /// Nullable:True + /// + public int? DownBatteryBinNo { get; set; } + + /// + /// Desc:满电包编码 + /// Default: + /// Nullable:True + /// + public string? UpBatteryNo { get; set; } + + /// + /// Desc:满电包soc + /// Default: + /// Nullable:True + /// + public decimal? UpBatterySoc { get; set; } + + /// + /// Desc:满电包soe + /// Default: + /// Nullable:True + /// + public decimal? UpBatterySoe { get; set; } + + /// + /// Desc:满电包真实soc + /// Default: + /// Nullable:True + /// + public decimal? UpBatteryRealSoc { get; set; } + + /// + /// Desc:满电包站内充电能量(累计) + /// Default: + /// Nullable:True + /// + public decimal? UpBatteryInChageElecCount { get; set; } + + /// + /// Desc:满电包站外插枪充电能量(累计) + /// Default: + /// Nullable:True + /// + public decimal? UpBatteryOutChageElecCount { get; set; } + + /// + /// Desc:满电包站外回充能量(累计) + /// Default: + /// Nullable:True + /// + public decimal? UpBatteryOutReChagreCount { get; set; } + + /// + /// Desc:满电包站外放电能量(累计) + /// Default: + /// Nullable:True + /// + public decimal? UpBatteryInDischageElecCount { get; set; } + + /// + /// Desc:满电包站内放电电能量(累计) + /// Default: + /// Nullable:True + /// + public decimal? UpBatteryOutDischageElecCount { get; set; } + + /// + /// Desc:取电池仓位号 满电包仓号 + /// Default: + /// Nullable:True + /// + public int? UpBatteryBinNo { get; set; } +} \ No newline at end of file diff --git a/Entity/Api/Req/UpdateSwapOrderBatteryReq.cs b/Entity/Api/Req/UpdateSwapOrderBatteryReq.cs new file mode 100644 index 0000000..bcf656c --- /dev/null +++ b/Entity/Api/Req/UpdateSwapOrderBatteryReq.cs @@ -0,0 +1,14 @@ +using System.ComponentModel.DataAnnotations; + +namespace Entity.Api.Req; + +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/ElecPriceModelVersionDetailResp.cs b/Entity/Api/Resp/ElecPriceModelVersionDetailResp.cs index 07131c4..4b93e6d 100644 --- a/Entity/Api/Resp/ElecPriceModelVersionDetailResp.cs +++ b/Entity/Api/Resp/ElecPriceModelVersionDetailResp.cs @@ -13,8 +13,8 @@ public class ElecPriceModelVersionDetailResp /// Default: /// Nullable:True /// - public int? Price {get;set;} - + // public int? Price {get;set;} + public double Price { get; set; } /// /// Desc:尖峰平谷类型;1-尖;2-峰;3-平;4-谷 /// Default: diff --git a/Entity/DbModel/Station/ElecPriceModelVersionDetail.cs b/Entity/DbModel/Station/ElecPriceModelVersionDetail.cs index 806ecf3..4c79012 100644 --- a/Entity/DbModel/Station/ElecPriceModelVersionDetail.cs +++ b/Entity/DbModel/Station/ElecPriceModelVersionDetail.cs @@ -66,8 +66,9 @@ namespace Entity.DbModel.Station /// Default: /// Nullable:True /// - [SugarColumn(ColumnName="price")] - public int? Price {get;set;} + // [SugarColumn(ColumnName="price")] + // public int? Price {get;set;} + public double Price { get; set; } /// /// Desc:尖峰平谷类型;1-尖;2-峰;3-平;4-谷 diff --git a/Service/Station/SwapOrderBatteryService.cs b/Service/Station/SwapOrderBatteryService.cs index 2279eef..a78c175 100644 --- a/Service/Station/SwapOrderBatteryService.cs +++ b/Service/Station/SwapOrderBatteryService.cs @@ -9,7 +9,7 @@ using System.Linq.Expressions; namespace Service.Station; /// -/// 綩 +/// 换电订单电池 /// [Scope("SingleInstance")] public class SwapOrderBatteryService : BaseServices @@ -23,19 +23,19 @@ public class SwapOrderBatteryService : BaseServices /// - /// ѯҳ + /// 根据条件查询分页数据 /// /// /// public PageResult QuerySwapOrderBattery(QuerySwapOrderBatteryReq swapOrderBattery) { - //һյıʽ + //创建一个空的表达式树 Expression> where = null; - //// ʽ + //// 定义参数表达式 ParameterExpression parameter = Expression.Parameter(typeof(SwapOrderBattery), "u"); - #region ̬ѯ + #region 构建动态查询树 if (swapOrderBattery.Id != 0) { Expression> condition1Expr = u => u.Id == swapOrderBattery.Id; @@ -79,7 +79,7 @@ public class SwapOrderBatteryService : BaseServices } #endregion - //ѯ + //查询 return PageResult.ConvertPage(_swapOrderBatteryRepository.QueryIPageByCause(swapOrderBattery, where)); diff --git a/WebStarter/Controllers/ChargeOrderController.cs b/WebStarter/Controllers/ChargeOrderController.cs index 8e122c8..477f7d5 100644 --- a/WebStarter/Controllers/ChargeOrderController.cs +++ b/WebStarter/Controllers/ChargeOrderController.cs @@ -29,7 +29,8 @@ public class ChargeOrderController : ControllerBase [HttpPost("QueryPage")] public async Task>> QueryPage([FromBody] QueryChargeOrderReq req) { - return Result>.Success(chargeOrderService.QueryChargeOrder(req)); + PageResult queryChargeOrder = chargeOrderService.QueryChargeOrder(req); + return Result>.Success(queryChargeOrder); } /// diff --git a/WebStarter/Controllers/SwapOrderController.cs b/WebStarter/Controllers/SwapOrderController.cs index 1d42082..a38657f 100644 --- a/WebStarter/Controllers/SwapOrderController.cs +++ b/WebStarter/Controllers/SwapOrderController.cs @@ -1,10 +1,13 @@ +using System.Transactions; using AutoMapper; using Entity.Api.Req; using Entity.Api.Resp; using Entity.DbModel.Station; using HybirdFrameworkCore.Entity; using Microsoft.AspNetCore.Mvc; +using Service.Init; using Service.Station; +using Swapping.Business.Common; namespace WebStarter.Controllers; @@ -84,20 +87,44 @@ public class SwapOrderController : ControllerBase [HttpPost("Add")] public async Task> Add([FromBody] AddSwapOrderReq req) { - //映射数据 - var config = new MapperConfiguration(cfg => cfg.CreateMap().ReverseMap()); - IMapper mapper = config.CreateMapper(); - SwapOrder swapOrder = mapper.Map(req); - - var swap = swapOrderService.QueryByClause(u => u.Sn == req.Sn); - if (swap != null) - { - return Result.Fail("新增失败!订单号重复"); - } - else + using (var transactionScope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled)) { - swapOrderService.Insert(swapOrder); - return Result.Success(true,"新增成功"); + // 映射数据 + var config = new MapperConfiguration(cfg => + { + cfg.CreateMap().ReverseMap(); + cfg.CreateMap().ReverseMap(); + }); + + IMapper mapper = config.CreateMapper(); + + // 转换换电订单 + SwapOrder swapOrder = mapper.Map(req); + swapOrder.Sn = SwapOrderNoGenerator.GenerateOrderNo(StaticStationInfo.StationNo); + SwapOrder order = await swapOrderService.InsertAsync(swapOrder); + + bool batteriesInserted = true; + + if (req.batteryList.Any()) + { + // 绑定订单 + List swapOrderBatteries = mapper.Map>(req.batteryList); + foreach (var swapOrderBattery in swapOrderBatteries) + { + swapOrderBattery.SwapOrderSn = swapOrder.Sn; + } + + batteriesInserted = await swapOrderBatteryService.InsertAsync(swapOrderBatteries); + } + + if (order != null && batteriesInserted) + { + // 提交 + transactionScope.Complete(); + return Result.Success(true, "新增成功"); + } + + return Result.Fail(false, "新增失败"); } } @@ -109,17 +136,47 @@ public class SwapOrderController : ControllerBase [HttpPost("Modify")] public async Task> Modify([FromBody] ModifySwapOrderReq req) { - //映射数据 - var config = new MapperConfiguration(cfg => cfg.CreateMap().ReverseMap()); - IMapper mapper = config.CreateMapper(); - SwapOrder swapOrder = mapper.Map(req); - - if (swapOrderService.Update(swapOrder)) - { - return Result.Success(true,"更改成功"); - } - else + using (var transactionScope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled)) { + var existingOrder = await swapOrderService.QueryByClauseAsync(u => u.Sn == req.Sn && u.Id != req.Id); + if (existingOrder != null) + { + return Result.Fail("订单号已存在"); + } + + // 映射数据 + var config = new MapperConfiguration(cfg => + { + cfg.CreateMap().ReverseMap(); + cfg.CreateMap().ReverseMap(); + }); + + IMapper mapper = config.CreateMapper(); + SwapOrder swapOrder = mapper.Map(req); + + bool orderUpdated = swapOrderService.Update(swapOrder); + bool batteriesUpdated = true; + + if ( req.batteryList.Any()) + { + // 绑定订单 + List swapOrderBatteries = mapper.Map>(req.batteryList); + foreach (var swapOrderBattery in swapOrderBatteries) + { + swapOrderBattery.SwapOrderSn = swapOrder.Sn; + } + + // 更新电池订单 + batteriesUpdated = await swapOrderBatteryService.UpdateAsync(swapOrderBatteries); + } + + if (orderUpdated && batteriesUpdated) + { + // 提交 + transactionScope.Complete(); + return Result.Success(true, "更改成功"); + } + return Result.Fail("更改失败"); } }