diff --git a/Entity/DbModel/Station/ChargeOrder.cs b/Entity/DbModel/Station/ChargeOrder.cs index 668f865..c8bed15 100644 --- a/Entity/DbModel/Station/ChargeOrder.cs +++ b/Entity/DbModel/Station/ChargeOrder.cs @@ -1,7 +1,4 @@ -using System; -using System.Linq; -using System.Text; -using SqlSugar; +using SqlSugar; namespace Entity.DbModel.Station { @@ -11,289 +8,304 @@ namespace Entity.DbModel.Station [SugarTable("charge_order")] public partial class ChargeOrder { - public ChargeOrder(){ - - - } - /// - /// Desc:id - /// Default: - /// Nullable:False - /// - [SugarColumn(IsPrimaryKey=true,IsIdentity=true,ColumnName="id")] - public int Id {get;set;} - - /// - /// Desc:订单编号 - /// Default: - /// Nullable:True - /// - [SugarColumn(ColumnName="sn")] - public string Sn {get;set;} - - /// - /// Desc:电池编号 - /// Default: - /// Nullable:True - /// - [SugarColumn(ColumnName="battery_no")] - public string BatteryNo {get;set;} - - /// - /// Desc:启动报文状态;0-初始化;1-启动成功 - /// Default:0 - /// Nullable:True - /// - [SugarColumn(ColumnName="cmd_status")] - public int? CmdStatus {get;set;} - - /// - /// Desc:充电机编号 - /// Default: - /// Nullable:True - /// - [SugarColumn(ColumnName="charger_no")] - public string ChargerNo {get;set;} - - /// - /// Desc:充电枪编号 - /// Default: - /// Nullable:True - /// - [SugarColumn(ColumnName="charger_gun_no")] - public string ChargerGunNo {get;set;} - - /// - /// Desc:0:站内充电 1:站外充电 - /// Default: - /// Nullable:True - /// - [SugarColumn(ColumnName="charge_mode")] - public int? ChargeMode {get;set;} - - /// - /// Desc:1:站控启动 2:本地启动 - /// Default: - /// Nullable:True - /// - [SugarColumn(ColumnName="start_mode")] - public int? StartMode {get;set;} - - /// - /// Desc:充电开始时间 - /// Default: - /// Nullable:True - /// - [SugarColumn(ColumnName="start_time")] - public DateTime? StartTime {get;set;} - - /// - /// Desc:充电结束时间 - /// Default: - /// Nullable:True - /// - [SugarColumn(ColumnName="end_time")] - public DateTime? EndTime {get;set;} - - /// - /// Desc:充电开始soc - /// Default: - /// Nullable:True - /// - [SugarColumn(ColumnName="start_soc")] - public int? StartSoc {get;set;} - - /// - /// Desc:充电结束soc - /// Default: - /// Nullable:True - /// - [SugarColumn(ColumnName="stop_soc")] - public int? StopSoc {get;set;} - - /// - /// Desc:充电时长 - /// Default: - /// Nullable:True - /// - [SugarColumn(ColumnName="charge_time_count")] - public int? ChargeTimeCount {get;set;} - - /// - /// Desc:充电电量 - /// Default: - /// Nullable:True - /// - [SugarColumn(ColumnName="elec_count")] - public decimal? ElecCount {get;set;} - - /// - /// Desc:交流电表量 - /// Default: - /// Nullable:True - /// - [SugarColumn(ColumnName="ac_elec_count")] - public decimal? AcElecCount {get;set;} - - /// - /// Desc:充电开始交流表电量 - /// Default: - /// Nullable:True - /// - [SugarColumn(ColumnName="start_ac_elec")] - public decimal? StartAcElec {get;set;} - - /// - /// Desc:充电结束交流表电量 - /// Default: - /// Nullable:True - /// - [SugarColumn(ColumnName="stop_ac_elec")] - public decimal? StopAcElec {get;set;} - - /// - /// Desc:充电开始直流表电量 - /// Default: - /// Nullable:True - /// - [SugarColumn(ColumnName="start_dc_elec")] - public decimal? StartDcElec {get;set;} - - /// - /// Desc:充电结束直流表电量 - /// Default: - /// Nullable:True - /// - [SugarColumn(ColumnName="stop_dc_elec")] - public decimal? StopDcElec {get;set;} - - /// - /// Desc:停止原因;0:满电自动停止;1-人工停止 - /// Default:0 - /// Nullable:True - /// - [SugarColumn(ColumnName="stop_reason")] - public int? StopReason {get;set;} - - /// - /// Desc:尖时段电量 - /// Default: - /// Nullable:True - /// - [SugarColumn(ColumnName="sharp_elec_count")] - public decimal? SharpElecCount {get;set;} - - /// - /// Desc:峰时段电量 - /// Default: - /// Nullable:True - /// - [SugarColumn(ColumnName="peak_elec_count")] - public decimal? PeakElecCount {get;set;} - - /// - /// Desc:平时段电量 - /// Default: - /// Nullable:True - /// - [SugarColumn(ColumnName="flat_elec_count")] - public decimal? FlatElecCount {get;set;} - - /// - /// Desc:谷时段电量 - /// Default: - /// Nullable:True - /// - [SugarColumn(ColumnName="valley_elec_count")] - public decimal? ValleyElecCount {get;set;} - - /// - /// Desc:尖时段交流电量 - /// Default: - /// Nullable:True - /// - [SugarColumn(ColumnName="ac_sharp_elec_count")] - public decimal? AcSharpElecCount {get;set;} - - /// - /// Desc:峰时段交流电量 - /// Default: - /// Nullable:True - /// - [SugarColumn(ColumnName="ac_peak_elec_count")] - public decimal? AcPeakElecCount {get;set;} - - /// - /// Desc:平时段交流电量 - /// Default: - /// Nullable:True - /// - [SugarColumn(ColumnName="ac_flat_elec_count")] - public decimal? AcFlatElecCount {get;set;} - - /// - /// Desc:谷时段交流电量 - /// Default: - /// Nullable:True - /// - [SugarColumn(ColumnName="ac_valley_elec_count")] - public decimal? AcValleyElecCount {get;set;} - - /// - /// Desc:电价版本号 - /// Default: - /// Nullable:True - /// - [SugarColumn(ColumnName="elec_price_model_version")] - public string ElecPriceModelVersion {get;set;} - - /// - /// Desc:换电订单编号 - /// Default: - /// Nullable:True - /// - [SugarColumn(ColumnName="swap_order_sn")] - public string SwapOrderSn {get;set;} - - /// - /// Desc:上传云平台状态;0-未上传;1-已上传 - /// Default:0 - /// Nullable:True - /// - [SugarColumn(ColumnName="cloud_report_status")] - public int? CloudReportStatus {get;set;} - - /// - /// Desc:创建人 - /// Default: - /// Nullable:True - /// - [SugarColumn(ColumnName="created_by")] - public string CreatedBy {get;set;} - - /// - /// Desc:创建时间 - /// Default:CURRENT_TIMESTAMP - /// Nullable:True - /// - [SugarColumn(ColumnName="created_time")] - public DateTime? CreatedTime {get;set;} - - /// - /// Desc:更新人 - /// Default: - /// Nullable:True - /// - [SugarColumn(ColumnName="updated_by")] - public string UpdatedBy {get;set;} - - /// - /// Desc:更新时间 - /// Default:CURRENT_TIMESTAMP - /// Nullable:True - /// - [SugarColumn(ColumnName="updated_time")] - public DateTime? UpdatedTime {get;set;} - + public ChargeOrder() + { + } + + /// + /// Desc:id + /// Default: + /// Nullable:False + /// + [SugarColumn(IsPrimaryKey = true, IsIdentity = true, ColumnName = "id")] + public int Id { get; set; } + + /// + /// Desc:订单编号 + /// Default: + /// Nullable:True + /// + [SugarColumn(ColumnName = "sn")] + public string Sn { get; set; } + + /// + /// Desc:电池编号 + /// Default: + /// Nullable:True + /// + [SugarColumn(ColumnName = "battery_no")] + public string BatteryNo { get; set; } + + /// + /// Desc:启动报文状态;0-初始化;1-启动成功 + /// Default:0 + /// Nullable:True + /// + [SugarColumn(ColumnName = "cmd_status")] + public int? CmdStatus { get; set; } + + /// + /// Desc:充电机编号 + /// Default: + /// Nullable:True + /// + [SugarColumn(ColumnName = "charger_no")] + public string ChargerNo { get; set; } + + /// + /// Desc:充电枪编号 + /// Default: + /// Nullable:True + /// + [SugarColumn(ColumnName = "charger_gun_no")] + public string ChargerGunNo { get; set; } + + /// + /// Desc:0:站内充电 1:站外充电 + /// Default: + /// Nullable:True + /// + [SugarColumn(ColumnName = "charge_mode")] + public int? ChargeMode { get; set; } + + /// + /// Desc:1:站控启动 2:本地启动 + /// Default: + /// Nullable:True + /// + [SugarColumn(ColumnName = "start_mode")] + public int? StartMode { get; set; } + + /// + /// Desc:充电开始时间 + /// Default: + /// Nullable:True + /// + [SugarColumn(ColumnName = "start_time")] + public DateTime? StartTime { get; set; } + + /// + /// Desc:充电结束时间 + /// Default: + /// Nullable:True + /// + [SugarColumn(ColumnName = "end_time")] + public DateTime? EndTime { get; set; } + + /// + /// Desc:充电开始soc + /// Default: + /// Nullable:True + /// + [SugarColumn(ColumnName = "start_soc")] + public int? StartSoc { get; set; } + + /// + /// Desc:充电结束soc + /// Default: + /// Nullable:True + /// + [SugarColumn(ColumnName = "stop_soc")] + public int? StopSoc { get; set; } + + /// + /// Desc:充电时长 + /// Default: + /// Nullable:True + /// + [SugarColumn(ColumnName = "charge_time_count")] + public int? ChargeTimeCount { get; set; } + + /// + /// Desc:充电电量 + /// Default: + /// Nullable:True + /// + [SugarColumn(ColumnName = "elec_count")] + public decimal? ElecCount { get; set; } + + /// + /// Desc:交流电表量 + /// Default: + /// Nullable:True + /// + [SugarColumn(ColumnName = "ac_elec_count")] + public decimal? AcElecCount { get; set; } + + /// + /// Desc:充电开始交流表电量 + /// Default: + /// Nullable:True + /// + [SugarColumn(ColumnName = "start_ac_elec")] + public decimal? StartAcElec { get; set; } + + /// + /// Desc:充电结束交流表电量 + /// Default: + /// Nullable:True + /// + [SugarColumn(ColumnName = "stop_ac_elec")] + public decimal? StopAcElec { get; set; } + + /// + /// Desc:充电开始直流表电量 + /// Default: + /// Nullable:True + /// + [SugarColumn(ColumnName = "start_dc_elec")] + public decimal? StartDcElec { get; set; } + + /// + /// Desc:充电结束直流表电量 + /// Default: + /// Nullable:True + /// + [SugarColumn(ColumnName = "stop_dc_elec")] + public decimal? StopDcElec { get; set; } + + /// + /// Desc:停止原因;0:满电自动停止;1-人工停止 + /// Default:0 + /// Nullable:True + /// + [SugarColumn(ColumnName = "stop_reason")] + public int? StopReason { get; set; } + + /// + /// Desc:尖时段电量 + /// Default: + /// Nullable:True + /// + [SugarColumn(ColumnName = "sharp_elec_count")] + public decimal? SharpElecCount { get; set; } + + /// + /// Desc:峰时段电量 + /// Default: + /// Nullable:True + /// + [SugarColumn(ColumnName = "peak_elec_count")] + public decimal? PeakElecCount { get; set; } + + /// + /// Desc:平时段电量 + /// Default: + /// Nullable:True + /// + [SugarColumn(ColumnName = "flat_elec_count")] + public decimal? FlatElecCount { get; set; } + + /// + /// Desc:谷时段电量 + /// Default: + /// Nullable:True + /// + [SugarColumn(ColumnName = "valley_elec_count")] + public decimal? ValleyElecCount { get; set; } + + /// + /// Desc:尖时段交流电量 + /// Default: + /// Nullable:True + /// + [SugarColumn(ColumnName = "ac_sharp_elec_count")] + public decimal? AcSharpElecCount { get; set; } + + /// + /// Desc:峰时段交流电量 + /// Default: + /// Nullable:True + /// + [SugarColumn(ColumnName = "ac_peak_elec_count")] + public decimal? AcPeakElecCount { get; set; } + + /// + /// Desc:平时段交流电量 + /// Default: + /// Nullable:True + /// + [SugarColumn(ColumnName = "ac_flat_elec_count")] + public decimal? AcFlatElecCount { get; set; } + + /// + /// Desc:谷时段交流电量 + /// Default: + /// Nullable:True + /// + [SugarColumn(ColumnName = "ac_valley_elec_count")] + public decimal? AcValleyElecCount { get; set; } + + /// + /// Desc:电价版本号 + /// Default: + /// Nullable:True + /// + [SugarColumn(ColumnName = "elec_price_model_version")] + public string ElecPriceModelVersion { get; set; } + + /// + /// Desc:换电订单编号 + /// Default: + /// Nullable:True + /// + [SugarColumn(ColumnName = "swap_order_sn")] + public string SwapOrderSn { get; set; } + + /// + /// Desc:上传云平台状态;0-未上传;1-已上传 + /// Default:0 + /// Nullable:True + /// + [SugarColumn(ColumnName = "cloud_report_status")] + public int? CloudReportStatus { get; set; } + + /// + /// Desc:创建人 + /// Default: + /// Nullable:True + /// + [SugarColumn(ColumnName = "created_by")] + public string CreatedBy { get; set; } + + /// + /// Desc:创建时间 + /// Default:CURRENT_TIMESTAMP + /// Nullable:True + /// + [SugarColumn(ColumnName = "created_time")] + public DateTime CreatedTime { get; set; } + + /// + /// Desc:更新人 + /// Default: + /// Nullable:True + /// + [SugarColumn(ColumnName = "updated_by")] + public string UpdatedBy { get; set; } + + /// + /// Desc:更新时间 + /// Default:CURRENT_TIMESTAMP + /// Nullable:True + /// + [SugarColumn(ColumnName = "updated_time")] + public DateTime? UpdatedTime { get; set; } + + /// + /// Desc:云平台订单编号 + /// Default: + /// Nullable:True + /// + [SugarColumn(ColumnName = "cloud_charge_order")] + public string CloudChargeOrder { get; set; } + + /// + /// Desc:是否可以上传云平台 + /// Default: + /// Nullable:True + /// + [SugarColumn(ColumnName = "can_upload")] + public int? CanUpload { get; set; } } -} +} \ No newline at end of file diff --git a/Entity/DbModel/Station/SwapOrderBattery.cs b/Entity/DbModel/Station/SwapOrderBattery.cs new file mode 100644 index 0000000..989f054 --- /dev/null +++ b/Entity/DbModel/Station/SwapOrderBattery.cs @@ -0,0 +1,240 @@ +using System; +using System.Linq; +using System.Text; +using SqlSugar; + +namespace Entity.DbModel.Station +{ + /// + ///换电订单电池 + /// + [SugarTable("swap_order_battery")] + public partial class SwapOrderBattery + { + + /// + /// Desc:id + /// Default: + /// Nullable:False + /// + [SugarColumn(IsPrimaryKey = true, IsIdentity = true, ColumnName = "id")] + public int Id { get; set; } + + /// + /// Desc:换电订单编号 + /// Default: + /// Nullable:True + /// + [SugarColumn(ColumnName = "swap_order_sn")] + public string? SwapOrderSn { get; set; } + + /// + /// Desc:亏电包编码 + /// Default: + /// Nullable:True + /// + [SugarColumn(ColumnName = "down_battery_no")] + public string? DownBatteryNo { get; set; } + + /// + /// Desc:亏电包soc + /// Default: + /// Nullable:True + /// + [SugarColumn(ColumnName = "down_battery_soc")] + public decimal? DownBatterySoc { get; set; } + + /// + /// Desc:亏电包soe + /// Default: + /// Nullable:True + /// + [SugarColumn(ColumnName = "down_battery_soe")] + public decimal? DownBatterySoe { get; set; } + + /// + /// Desc:亏电包真实soc + /// Default: + /// Nullable:True + /// + [SugarColumn(ColumnName = "down_battery_real_soc")] + public decimal? DownBatteryRealSoc { get; set; } + + /// + /// Desc:亏电包上次换电结算时soc + /// Default: + /// Nullable:True + /// + [SugarColumn(ColumnName = "down_battery_last_soc")] + public decimal? DownBatteryLastSoc { get; set; } + + /// + /// Desc:亏电包上次换电结算时soe + /// Default: + /// Nullable:True + /// + [SugarColumn(ColumnName = "down_battery_last_soe")] + public decimal? DownBatteryLastSoe { get; set; } + + /// + /// Desc:亏电包站内充电能量(累计) + /// Default: + /// Nullable:True + /// + [SugarColumn(ColumnName = "down_battery_in_chage_elec_count")] + public decimal? DownBatteryInChageElecCount { get; set; } + + /// + /// Desc:亏电包站外插枪充电能量(累计) + /// Default: + /// Nullable:True + /// + [SugarColumn(ColumnName = "down_battery_out_chage_elec_count")] + public decimal? DownBatteryOutChageElecCount { get; set; } + + /// + /// Desc:亏电包站外回充能量(累计) + /// Default: + /// Nullable:True + /// + [SugarColumn(ColumnName = "down_battery_out_re_chagre_count")] + public decimal? DownBatteryOutReChagreCount { get; set; } + + /// + /// Desc:亏电包站外放电能量(累计) + /// Default: + /// Nullable:True + /// + [SugarColumn(ColumnName = "down_battery_in_dischage_elec_count")] + public decimal? DownBatteryInDischageElecCount { get; set; } + + /// + /// Desc:亏电包站内放电电能量(累计) + /// Default: + /// Nullable:True + /// + [SugarColumn(ColumnName = "down_battery_out_dischage_elec_count")] + public decimal? DownBatteryOutDischageElecCount { get; set; } + + /// + /// Desc:放电池仓位号 亏电包仓号 + /// Default: + /// Nullable:True + /// + [SugarColumn(ColumnName = "down_battery_bin_no")] + public int? DownBatteryBinNo { get; set; } + + /// + /// Desc:满电包编码 + /// Default: + /// Nullable:True + /// + [SugarColumn(ColumnName = "up_battery_no")] + public string? UpBatteryNo { get; set; } + + /// + /// Desc:满电包soc + /// Default: + /// Nullable:True + /// + [SugarColumn(ColumnName = "up_battery_soc")] + public decimal? UpBatterySoc { get; set; } + + /// + /// Desc:满电包soe + /// Default: + /// Nullable:True + /// + [SugarColumn(ColumnName = "up_battery_soe")] + public decimal? UpBatterySoe { get; set; } + + /// + /// Desc:满电包真实soc + /// Default: + /// Nullable:True + /// + [SugarColumn(ColumnName = "up_battery_real_soc")] + public decimal? UpBatteryRealSoc { get; set; } + + /// + /// Desc:满电包站内充电能量(累计) + /// Default: + /// Nullable:True + /// + [SugarColumn(ColumnName = "up_battery_in_chage_elec_count")] + public decimal? UpBatteryInChageElecCount { get; set; } + + /// + /// Desc:满电包站外插枪充电能量(累计) + /// Default: + /// Nullable:True + /// + [SugarColumn(ColumnName = "up_battery_out_chage_elec_count")] + public decimal? UpBatteryOutChageElecCount { get; set; } + + /// + /// Desc:满电包站外回充能量(累计) + /// Default: + /// Nullable:True + /// + [SugarColumn(ColumnName = "up_battery_out_re_chagre_count")] + public decimal? UpBatteryOutReChagreCount { get; set; } + + /// + /// Desc:满电包站外放电能量(累计) + /// Default: + /// Nullable:True + /// + [SugarColumn(ColumnName = "up_battery_in_dischage_elec_count")] + public decimal? UpBatteryInDischageElecCount { get; set; } + + /// + /// Desc:满电包站内放电电能量(累计) + /// Default: + /// Nullable:True + /// + [SugarColumn(ColumnName = "up_battery_out_dischage_elec_count")] + public decimal? UpBatteryOutDischageElecCount { get; set; } + + /// + /// Desc:取电池仓位号 满电包仓号 + /// Default: + /// Nullable:True + /// + [SugarColumn(ColumnName = "up_battery_bin_no")] + public int? UpBatteryBinNo { get; set; } + + /// + /// Desc:创建人 + /// Default: + /// Nullable:True + /// + [SugarColumn(ColumnName = "created_by")] + public string? CreatedBy { get; set; } + + /// + /// Desc:创建时间 + /// Default:CURRENT_TIMESTAMP + /// Nullable:True + /// + [SugarColumn(ColumnName = "created_time")] + public DateTime CreatedTime { get; set; } + + /// + /// Desc:更新人 + /// Default: + /// Nullable:True + /// + [SugarColumn(ColumnName = "updated_by")] + public string? UpdatedBy { get; set; } + + /// + /// Desc:更新时间 + /// Default:CURRENT_TIMESTAMP + /// Nullable:True + /// + [SugarColumn(ColumnName = "updated_time")] + public DateTime? UpdatedTime { get; set; } + + } +} diff --git a/HybirdFrameworkCore/Entity/Result.cs b/HybirdFrameworkCore/Entity/Result.cs index 3bc3134..3cd3831 100644 --- a/HybirdFrameworkCore/Entity/Result.cs +++ b/HybirdFrameworkCore/Entity/Result.cs @@ -54,7 +54,7 @@ /// /// 消息 /// - public static Result Fail(string msg = "失败") + public static Result Fail(string? msg = "失败") { return Message(false, msg, default); } diff --git a/HybirdFrameworkCore/Utils/ObjUtils.cs b/HybirdFrameworkCore/Utils/ObjUtils.cs new file mode 100644 index 0000000..fb39f97 --- /dev/null +++ b/HybirdFrameworkCore/Utils/ObjUtils.cs @@ -0,0 +1,71 @@ +namespace HybirdFrameworkCore.Utils; + +/// +/// +/// +public static class ObjUtils +{ + /// + /// + /// + /// + /// + public static bool IsNull(object? o) + { + return o == null; + } + + /// + /// + /// + /// + /// + public static bool IsNotNull(object? o) + { + return o != null; + } + + /// + /// + /// + /// + /// + /// + public static bool IsEmpty(List? list) + { + return list == null || list.Count == 0; + } + + /// + /// + /// + /// + /// + /// + public static bool IsNotEmpty(List? list) + { + return list is { Count: >= 0 }; + } + + /// + /// + /// + /// + /// + public static bool IsNullOrWhiteSpace(string? o) + { + return string.IsNullOrWhiteSpace(o); + } + + /// + /// + /// + /// + /// + public static bool IsNotNullOrWhiteSpace(string? o) + { + return !string.IsNullOrWhiteSpace(o); + } + + public static readonly List EmptyList = new List(0); +} \ No newline at end of file diff --git a/Repository/Station/ChargeOrderRepository.cs b/Repository/Station/ChargeOrderRepository.cs index 9df6c56..7d3833f 100644 --- a/Repository/Station/ChargeOrderRepository.cs +++ b/Repository/Station/ChargeOrderRepository.cs @@ -3,10 +3,37 @@ using HybirdFrameworkCore.Autofac.Attribute; using SqlSugar; namespace Repository.Station; + [Scope("SingleInstance")] -public class ChargeOrderRepository:BaseRepository +public class ChargeOrderRepository : BaseRepository { public ChargeOrderRepository(ISqlSugarClient sqlSugar) : base(sqlSugar) { } + + public ChargeOrder? QueryLatestByBatterySn(string? batterySn) + { + if (string.IsNullOrWhiteSpace(batterySn)) + { + return null; + } + + return QueryByClause(it => it.BatteryNo == batterySn, it => it.CreatedTime, OrderByType.Desc); + } + + /// + /// + /// + /// + /// + /// + public List QueryBySwapOrderAndBatterySn(string? swapOrderNo, string? batteryNo) + { + if (string.IsNullOrWhiteSpace(swapOrderNo) || string.IsNullOrWhiteSpace(batteryNo)) + { + return new List(0); + } + return QueryListByClause(it => it.SwapOrderSn == swapOrderNo && it.BatteryNo == batteryNo, it => it.CreatedTime, + OrderByType.Asc); + } } \ No newline at end of file diff --git a/Repository/Station/SwapOrderBatteryRepository.cs b/Repository/Station/SwapOrderBatteryRepository.cs new file mode 100644 index 0000000..d6c11cc --- /dev/null +++ b/Repository/Station/SwapOrderBatteryRepository.cs @@ -0,0 +1,28 @@ +using Entity.DbModel.Station; +using HybirdFrameworkCore.Autofac.Attribute; +using SqlSugar; + +namespace Repository.Station; + +[Scope] +public class SwapOrderBatteryRepository:BaseRepository +{ + + public SwapOrderBatteryRepository(ISqlSugarClient sqlSugar) : base(sqlSugar) + { + } + + /// + /// + /// + /// + /// + public SwapOrderBattery? QueryLatestOrderNoByBatterySn(string? batterySn) + { + if (string.IsNullOrWhiteSpace(batterySn)) + { + return null; + } + return QueryByClause(it => it.DownBatteryNo == batterySn, it => it.CreatedTime, OrderByType.Desc); + } +} \ No newline at end of file diff --git a/Service/Charger/Client/ChargerClient.cs b/Service/Charger/Client/ChargerClient.cs index e17726f..91a37b8 100644 --- a/Service/Charger/Client/ChargerClient.cs +++ b/Service/Charger/Client/ChargerClient.cs @@ -245,7 +245,7 @@ public class ChargerClient : TcpClient { if (!Connected) { - return Result.Fail($"charger-{BinNo} disconnect"); + return Result.Fail($"充电机{BinNo}未连接"); } if (string.IsNullOrWhiteSpace(chargeOrderNo)) @@ -511,10 +511,15 @@ public class ChargerClient : TcpClient byte chargeSoc = StaticStationInfo.ChargeSoc; float chargePower = StaticStationInfo.ChargePower; Result chargeOrderNo = SendRemoteStartCharging(chargeSoc, chargePower); + if (!chargeOrderNo.IsSuccess) + { + return Result.Fail(chargeOrderNo.Msg); + } + ChargeOrderNo = chargeOrderNo.Data; _chargeOrderRepository.Insert(new ChargeOrder() { - Sn = chargeOrderNo.Data, + Sn = ChargeOrderNo, BatteryNo = BatteryNo, CmdStatus = 0, ChargerNo = BinNo, diff --git a/Service/Charger/Handler/FinishStartChargingHandler.cs b/Service/Charger/Handler/FinishStartChargingHandler.cs index 951631f..9ea4c71 100644 --- a/Service/Charger/Handler/FinishStartChargingHandler.cs +++ b/Service/Charger/Handler/FinishStartChargingHandler.cs @@ -1,9 +1,11 @@ using System.Text; using DotNetty.Transport.Channels; +using Entity.DbModel.Station; using HybirdFrameworkCore.Autofac.Attribute; using log4net; using Repository.Station; using Service.Charger.Client; +using Service.Charger.Common; using Service.Charger.Handler; using Service.Charger.Msg.Charger.Req; using Service.Charger.Msg.Host.Resp; @@ -24,6 +26,8 @@ namespace HybirdFrameworkServices.Charger.Handler public class FinishStartChargingHandler : SimpleChannelInboundHandler, IBaseHandler { public BinInfoRepository BinInfoRepository { get; set; } + public ChargeOrderRepository ChargeOrderRepository { get; set; } + public SwapOrderBatteryRepository SwapOrderBatteryRepository { get; set; } private static readonly ILog Log = LogManager.GetLogger(typeof(FinishStartChargingHandler)); protected override void ChannelRead0(IChannelHandlerContext ctx, FinishStartCharging msg) @@ -36,7 +40,45 @@ namespace HybirdFrameworkServices.Charger.Handler if (msg.Result == 0) { client.IsCharged = true; + client.IsStopped = false; chargeStatus = 1; + SwapOrderBattery? swapOrderBattery = SwapOrderBatteryRepository.QueryLatestOrderNoByBatterySn(client.BatteryNo); + if (swapOrderBattery != null) + { + ChargeOrderRepository.Update(it => it.SwapOrderSn == swapOrderBattery.SwapOrderSn, + it => it.Sn == client.ChargeOrderNo); + + List orders = ChargeOrderRepository.QueryBySwapOrderAndBatterySn(swapOrderBattery.SwapOrderSn, + client.BatteryNo); + if (orders.Count > 0) + { + string? cloudChargeOrder = null; + foreach (ChargeOrder order in orders) + { + if (!string.IsNullOrWhiteSpace(order.CloudChargeOrder)) + { + cloudChargeOrder = order.CloudChargeOrder; + } + + } + + if (string.IsNullOrWhiteSpace(cloudChargeOrder)) + { + cloudChargeOrder = ChargerUtils.GenChargeOrderSn(); + } + + HashSet hashSet = orders.Select(it => it.Id).ToHashSet(); + ChargeOrderRepository.Update(it => it.CloudChargeOrder == cloudChargeOrder, + it => hashSet.Contains(it.Id)); + } + + + } + else + { + Log.Error($"can not find swapOrderBattery by {client.BatteryNo}"); + } + } else if (msg.Result == 1) { diff --git a/Service/Charger/Handler/FinishStopChargingHandler.cs b/Service/Charger/Handler/FinishStopChargingHandler.cs index 8e4b768..65a189e 100644 --- a/Service/Charger/Handler/FinishStopChargingHandler.cs +++ b/Service/Charger/Handler/FinishStopChargingHandler.cs @@ -1,10 +1,13 @@ using DotNetty.Transport.Channels; +using Entity.DbModel.Station; using HybirdFrameworkCore.Autofac.Attribute; +using HybirdFrameworkCore.Utils; using log4net; using Repository.Station; using Service.Charger.Client; using Service.Charger.Msg.Charger.Req; using Service.Charger.Msg.Host.Resp; +using Service.Init; namespace Service.Charger.Handler { @@ -22,6 +25,8 @@ namespace Service.Charger.Handler public BinInfoRepository BinInfoRepository { get; set; } + public ChargeOrderRepository ChargeOrderRepository { get; set; } + private static readonly ILog Log = LogManager.GetLogger(typeof(FinishStopChargingHandler)); protected override void ChannelRead0(IChannelHandlerContext ctx, FinishStopCharging msg) { @@ -33,7 +38,22 @@ namespace Service.Charger.Handler if (msg.Result == 0) { client.IsStopped = true; + client.IsCharged = false; chargeStatus = 4; + if (msg.SuspendTheStateOfCharge >= StaticStationInfo.SwapSoc) + { + ChargeOrder? chargeOrder = ChargeOrderRepository.QueryLatestByBatterySn(client.BatteryNo); + if (chargeOrder != null) + { + List orders = ChargeOrderRepository.QueryBySwapOrderAndBatterySn(chargeOrder.SwapOrderSn, + chargeOrder.BatteryNo); + if (ObjUtils.IsNotEmpty(orders)) + { + List list = orders.Select(it => it.Id).ToList(); + ChargeOrderRepository.Update(it => it.CanUpload == 1, it => list.Contains(it.Id)); + } + } + } } else {