diff --git a/Entity/Api/Resp/SwapOrderResp.cs b/Entity/Api/Resp/SwapOrderResp.cs index b36617f..5c9f521 100644 --- a/Entity/Api/Resp/SwapOrderResp.cs +++ b/Entity/Api/Resp/SwapOrderResp.cs @@ -159,6 +159,11 @@ namespace Entity.Api.Resp /// public string? Departments {get;set;} + /// + /// 换电服务费用 + /// + public int? ServiceTotalFee { get; set; } + /// /// 电费 /// diff --git a/Entity/DbModel/Station/BinInfo.cs b/Entity/DbModel/Station/BinInfo.cs index a57d71c..285b213 100644 --- a/Entity/DbModel/Station/BinInfo.cs +++ b/Entity/DbModel/Station/BinInfo.cs @@ -199,5 +199,11 @@ namespace Entity.DbModel.Station /// [SugarColumn(ColumnName = "in_time")] public DateTime? InTime { get; set; } + + /// + /// 电池标称能量 + /// + [SugarColumn(ColumnName = "nominal_energy")] + public decimal? NominalEnergy { get; set; } } } \ No newline at end of file diff --git a/Entity/DbModel/Station/SwapOrder.cs b/Entity/DbModel/Station/SwapOrder.cs index 64f7cf5..89881f9 100644 --- a/Entity/DbModel/Station/SwapOrder.cs +++ b/Entity/DbModel/Station/SwapOrder.cs @@ -125,6 +125,12 @@ namespace Entity.DbModel.Station [SugarColumn(ColumnName = "swap_way")] public int? SwapWay { get; set; } + /// + /// 换电服务费用(单位分) + /// + [SugarColumn(ColumnName = "service_total_fee")] + public int? ServiceTotalFee { get; set; } + /// /// 电费(单位分) /// diff --git a/Entity/DbModel/Station/SwapOrderBattery.cs b/Entity/DbModel/Station/SwapOrderBattery.cs index e3d824a..8ab984e 100644 --- a/Entity/DbModel/Station/SwapOrderBattery.cs +++ b/Entity/DbModel/Station/SwapOrderBattery.cs @@ -205,10 +205,21 @@ namespace Entity.DbModel.Station public int? UpBatteryBinNo { get; set; } /// - /// 标称能量 + /// 放电池标称能量 /// - /// - [SugarColumn(ColumnName = "nominal_energy")] - public float? NominalEnergy { get; set; } + [SugarColumn(ColumnName = "down_nominal_energy")] + public decimal? DownNominalEnergy { get; set; } + + /// + /// 取电池标称能量 + /// + [SugarColumn(ColumnName = "up_nominal_energy")] + public decimal? UpNominalEnergy { get; set; } + + /// + /// 是否算费;0未结算,1已结算 + /// + [SugarColumn(ColumnName = "settle_an_account_flag")] + public int? SettleAnAccountFlag { get; set; } } } diff --git a/Entity/Dto/SwapOrderDto.cs b/Entity/Dto/SwapOrderDto.cs index c051ca0..5e7fd24 100644 --- a/Entity/Dto/SwapOrderDto.cs +++ b/Entity/Dto/SwapOrderDto.cs @@ -220,6 +220,11 @@ public class SwapOrderDto public string Sn { get; set; } + /// + /// 换电服务费用 + /// + [ExporterHeader(DisplayName = "换电服务费用", IsBold = true)] + public int? ServiceTotalFee { get; set; } /// /// 电费 diff --git a/Service/Execute/Mgr/CommonMgr.cs b/Service/Execute/Mgr/CommonMgr.cs index fe8cfd4..a3ce5ab 100644 --- a/Service/Execute/Mgr/CommonMgr.cs +++ b/Service/Execute/Mgr/CommonMgr.cs @@ -89,6 +89,7 @@ public class CommonMgr UpBatteryNo = upBin.BatteryNo, UpBatterySoe = upBin.Soe, UpBatteryBinNo = int.Parse(upBin.No), + UpNominalEnergy = upBin.NominalEnergy, DownBatteryBinNo = int.Parse(inBin.No), DownBatteryNo = inBin.BatteryNo, DownBatterySoc = inBin.Soc, diff --git a/Service/MyTask/SwapOrderSettleAnAccountTask.cs b/Service/MyTask/SwapOrderSettleAnAccountTask.cs new file mode 100644 index 0000000..1967f3a --- /dev/null +++ b/Service/MyTask/SwapOrderSettleAnAccountTask.cs @@ -0,0 +1,107 @@ +using Entity.DbModel.Station; +using HybirdFrameworkCore.Autofac.Attribute; +using HybirdFrameworkCore.AutoTask; +using log4net; +using Repository.Station; +using Service.Init; + +namespace Service.MyTask; + +/// +/// 换电订单算费用 +/// +[Scope] +public class SwapOrderSettleAnAccountTask : ITask +{ + private static readonly ILog Log = LogManager.GetLogger(typeof(SwapOrderSettleAnAccountTask)); + + private volatile bool _stop; + + + private SwapOrderBatteryRepository SwapOrderBatteryRepository { get; set; } + + private SwapOrderRepository SwapOrderRepository { get; set; } + + + public SwapOrderSettleAnAccountTask(SwapOrderBatteryRepository swapOrderBatteryRepository, + SwapOrderRepository swapOrderRepository) + { + SwapOrderBatteryRepository = swapOrderBatteryRepository; + SwapOrderRepository = swapOrderRepository; + } + + + public string Name() + { + return "SwapOrderSettleAnAccountTask"; + } + + public int Interval() + { + return 1000 * 2; + } + + public void Handle() + { + Log.Info("Begin SwapOrderSettleAnAccountTask"); + + List listSwapOrderBattery = SwapOrderBatteryRepository.QueryListByClause(i => + i.DownNominalEnergy != null && i.UpNominalEnergy != null && i.SettleAnAccountFlag == 0); + + if (listSwapOrderBattery.Count > 0) + { + List list = listSwapOrderBattery.Select(resp => resp.SwapOrderSn).ToList(); + + List swapOrderList = SwapOrderRepository + .Queryable() + .In(swapOrder => swapOrder.Sn, list) + .ToList(); + // 电费单价 + int electricityTotalFee = StaticStationInfo.ElectricityTotalFee; + // 换电服务费用 + int serviceTotalFee = StaticStationInfo.ServiceTotalFee; + // 附加费用 + int appendTotalFee = StaticStationInfo.AppendTotalFee; + foreach (var swapOrderBattery in listSwapOrderBattery) + { + // 换上的满电包soc*满电包的电池标量 + decimal? upNominalEnergy = swapOrderBattery.UpBatterySoc * swapOrderBattery.UpNominalEnergy; + // 换下的亏电包soc*亏电包的电池标量 + decimal? downNominalEnergy = swapOrderBattery.DownBatterySoc * swapOrderBattery.DownNominalEnergy; + + // 电量费用 + decimal? electricCharge = (upNominalEnergy - downNominalEnergy) * electricityTotalFee; + + var matchingOrder = swapOrderList.FirstOrDefault(order => order.Sn == swapOrderBattery.SwapOrderSn); + if (matchingOrder != null) + { + matchingOrder.ServiceTotalFee = serviceTotalFee; + matchingOrder.ElectricityTotalFee = (int?)electricCharge; + matchingOrder.AppendTotalFee = appendTotalFee; + matchingOrder.TotalFee = matchingOrder.ServiceTotalFee + matchingOrder.ElectricityTotalFee + + matchingOrder.AppendTotalFee; + // 标记换电订单已经算了订单价钱 + swapOrderBattery.SettleAnAccountFlag = 1; + } + } + + SwapOrderRepository.Update(swapOrderList); + SwapOrderBatteryRepository.Update(listSwapOrderBattery); + } + } + + public bool Stoped() + { + return _stop; + } + + public void Stop() + { + _stop = true; + } + + public void ResetStop() + { + _stop = false; + } +} \ No newline at end of file diff --git a/Service/MyTask/UpdateDownBatteryInfoTask.cs b/Service/MyTask/UpdateDownBatteryInfoTask.cs index fee7d83..0ab5d58 100644 --- a/Service/MyTask/UpdateDownBatteryInfoTask.cs +++ b/Service/MyTask/UpdateDownBatteryInfoTask.cs @@ -17,7 +17,7 @@ public class UpdateDownBatteryInfoTask : ITask private static readonly ILog Log = LogManager.GetLogger(typeof(UpdateDownBatteryInfoTask)); private volatile bool _stop; - + public SwapOrderBatteryRepository _swapOrderBatteryRepository { get; set; } @@ -55,6 +55,7 @@ public class UpdateDownBatteryInfoTask : ITask _swapOrderBatteryRepository.Update(i => new SwapOrderBattery() { DownBatterySoc = lstBinInfo.Soc, + DownNominalEnergy = lstBinInfo.NominalEnergy, DownBatteryNo = lstBinInfo.BatteryNo }, i => i.SwapOrderSn.ToString() == UpSwapOrderBattery.SwapOrderSn diff --git a/WebStarter/db/换电订单新增计费字段.sql b/WebStarter/db/换电订单新增计费字段.sql index 10030e2..553b933 100644 --- a/WebStarter/db/换电订单新增计费字段.sql +++ b/WebStarter/db/换电订单新增计费字段.sql @@ -10,11 +10,20 @@ ADD COLUMN step_desc varchar(255) COMMENT '描述', ADD COLUMN param text COMMENT '参数'; +INSERT INTO `sys_config` VALUES (1300000000180, 'Station.ServiceTotalFee', 'ServiceTotalFee', '10000', 2, 'Station', 100, NULL, NULL, NULL, NULL, NULL, NULL, NULL, b'0'); +INSERT INTO `sys_config` VALUES (1300000000181, 'Station.ElectricityTotalFee', 'ElectricityTotalFee', '100000', 2, 'Station', 100, NULL, NULL, NULL, NULL, NULL, NULL, NULL, b'0'); +INSERT INTO `sys_config` VALUES (1300000000182, 'Station.AppendTotalFee', 'AppendTotalFee', '10000', 2, 'Station', 100, NULL, NULL, NULL, NULL, NULL, NULL, NULL, b'0'); + + +ALTER TABLE swap_order_battery + DROP COLUMN nominal_energy; ALTER TABLE swap_order_battery - ADD COLUMN nominal_energy DECIMAL(24, 2) COMMENT '电池标称能量'; + ADD COLUMN down_nominal_energy DECIMAL(24,2) COMMENT '放电池标称能量', + ADD COLUMN up_nominal_energy DECIMAL(24,2) COMMENT '取电池标称能量'; +ALTER TABLE bin_info + ADD COLUMN nominal_energy DECIMAL(24,2) COMMENT '电池标称能量'; -INSERT INTO `sys_config` VALUES (1300000000180, 'Station.ServiceTotalFee', 'ServiceTotalFee', '10000', 2, 'Station', 100, NULL, NULL, NULL, NULL, NULL, NULL, NULL, b'0'); -INSERT INTO `sys_config` VALUES (1300000000181, 'Station.ElectricityTotalFee', 'ElectricityTotalFee', '100000', 2, 'Station', 100, NULL, NULL, NULL, NULL, NULL, NULL, NULL, b'0'); -INSERT INTO `sys_config` VALUES (1300000000182, 'Station.AppendTotalFee', 'AppendTotalFee', '10000', 2, 'Station', 100, NULL, NULL, NULL, NULL, NULL, NULL, NULL, b'0'); \ No newline at end of file +ALTER TABLE swap_order + ADD COLUMN service_total_fee INT COMMENT '换电服务费'; \ No newline at end of file