From 3a8de78a25616ec076012d3972d80dc2d5aaf1ee Mon Sep 17 00:00:00 2001 From: lxw Date: Fri, 24 May 2024 10:54:27 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E5=87=BA=E9=80=89=E5=8C=85=EF=BC=8C?= =?UTF-8?q?=E5=B0=86=E6=9E=9A=E4=B8=BE=E6=8C=AA=E5=88=B0entity=20.?= =?UTF-8?q?=E6=8D=A2=E7=94=B5=E7=AB=99reslove=20Autofac=20bean?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Tech => Entity/Attr}/InfoAttribute.cs | 8 +- .../Tech => Entity/Attr}/RemarkAttribute.cs | 6 +- .../Enum => Entity/Constant}/InfoEnum.cs | 5 +- Entity/DbModel/Station/SwapAmtOrder.cs | 8 +- Entity/Dto/SelectPackDto.cs | 16 ++++ HybirdFrameworkCore/Entity/IPage.cs | 2 +- Repository/Station/BinInfoRepository.cs | 57 ++++++++++++- Service/Cloud/Handler/AmtBatHandler.cs | 4 +- Service/Execute/Api/CloudApi.cs | 2 +- Service/Execute/Model/SwapOrderBatteryInfo.cs | 2 +- Service/Execute/Step/CancelState.cs | 14 ++-- Service/Execute/Step/CarCtrlState.cs | 6 +- Service/Execute/Step/CarPrepareState.cs | 82 ++++++------------- Service/Execute/Step/DoSwappingState.cs | 26 +++--- Service/Execute/Step/StationReadyState.cs | 17 ++-- Service/Execute/Step/SwapCanStartState.cs | 15 ++-- Service/Execute/Step/SwapDoneState.cs | 24 +++--- Service/Execute/SwappingStateMachine.cs | 13 ++- .../{Enum => Utils}/SwapOrderNoGenerator.cs | 0 Service/Service.csproj | 4 + Service/Station/SwapOrderStepService.cs | 1 - Service/System/LoginService.cs | 2 +- WebStarter/Program.cs | 2 +- WinFormStarter/Program.cs | 2 +- WpfStarter/App.xaml.cs | 2 +- 25 files changed, 187 insertions(+), 133 deletions(-) rename {Service/Execute/Tech => Entity/Attr}/InfoAttribute.cs (82%) rename {Service/Execute/Tech => Entity/Attr}/RemarkAttribute.cs (80%) rename {Service/Execute/Enum => Entity/Constant}/InfoEnum.cs (98%) create mode 100644 Entity/Dto/SelectPackDto.cs rename Service/Execute/{Enum => Utils}/SwapOrderNoGenerator.cs (100%) diff --git a/Service/Execute/Tech/InfoAttribute.cs b/Entity/Attr/InfoAttribute.cs similarity index 82% rename from Service/Execute/Tech/InfoAttribute.cs rename to Entity/Attr/InfoAttribute.cs index 7857ae5..b5de10a 100644 --- a/Service/Execute/Tech/InfoAttribute.cs +++ b/Entity/Attr/InfoAttribute.cs @@ -1,8 +1,8 @@ using System.Reflection; -namespace Swapping.Business.Tech; +namespace Entity.Attr; -public class InfoAttribute : Attribute +public class InfoAttribute : System.Attribute { private string _Led; private string _Sound; @@ -32,7 +32,7 @@ public static class InfoExtend FieldInfo? fieldInfo = type.GetField(value.ToString()); if (fieldInfo != null && fieldInfo.IsDefined(typeof(InfoAttribute), true)) { - Attribute? attribute = fieldInfo.GetCustomAttribute(typeof(InfoAttribute)); + System.Attribute? attribute = fieldInfo.GetCustomAttribute(typeof(InfoAttribute)); if (attribute != null) { return ((InfoAttribute)attribute).GetLed(); @@ -48,7 +48,7 @@ public static class InfoExtend FieldInfo? fieldInfo = type.GetField(value.ToString()); if (fieldInfo != null && fieldInfo.IsDefined(typeof(InfoAttribute), true)) { - Attribute? attribute = fieldInfo.GetCustomAttribute(typeof(InfoAttribute)); + System.Attribute? attribute = fieldInfo.GetCustomAttribute(typeof(InfoAttribute)); if (attribute != null) { return ((InfoAttribute)attribute).GetSound(); diff --git a/Service/Execute/Tech/RemarkAttribute.cs b/Entity/Attr/RemarkAttribute.cs similarity index 80% rename from Service/Execute/Tech/RemarkAttribute.cs rename to Entity/Attr/RemarkAttribute.cs index 1ec3e7c..eaf60b6 100644 --- a/Service/Execute/Tech/RemarkAttribute.cs +++ b/Entity/Attr/RemarkAttribute.cs @@ -1,8 +1,8 @@ using System.Reflection; -namespace Service.Execute.Tech; +namespace Entity.Attr; -public class RemarkAttribute : Attribute +public class RemarkAttribute : System.Attribute { private string _Remark; @@ -25,7 +25,7 @@ public static class RemarkExtend FieldInfo? fieldInfo = type.GetField(value.ToString()); if (fieldInfo != null && fieldInfo.IsDefined(typeof(RemarkAttribute), true)) { - Attribute? attribute = fieldInfo.GetCustomAttribute(typeof(RemarkAttribute)); + System.Attribute? attribute = fieldInfo.GetCustomAttribute(typeof(RemarkAttribute)); if (attribute != null) { return ((RemarkAttribute)attribute).GetRemark(); diff --git a/Service/Execute/Enum/InfoEnum.cs b/Entity/Constant/InfoEnum.cs similarity index 98% rename from Service/Execute/Enum/InfoEnum.cs rename to Entity/Constant/InfoEnum.cs index 04bc262..5821d96 100644 --- a/Service/Execute/Enum/InfoEnum.cs +++ b/Entity/Constant/InfoEnum.cs @@ -1,7 +1,6 @@ -using Service.Execute.Tech; -using Swapping.Business.Tech; +using Entity.Attr; -namespace Service.Execute.Enum; +namespace Entity.Constant; public class InfoEnum { diff --git a/Entity/DbModel/Station/SwapAmtOrder.cs b/Entity/DbModel/Station/SwapAmtOrder.cs index f0115f8..0776180 100644 --- a/Entity/DbModel/Station/SwapAmtOrder.cs +++ b/Entity/DbModel/Station/SwapAmtOrder.cs @@ -40,7 +40,7 @@ namespace Entity.DbModel.Station public string BatteryType {get;set;} /// - /// Desc:车辆vin码 + /// Desc:车牌号 /// Default: /// Nullable:True /// @@ -151,10 +151,6 @@ namespace Entity.DbModel.Station [SugarColumn(ColumnName="updated_time")] public DateTime? UpdatedTime {get;set;} - /// - /// 车牌 - /// - public string VehicleNo { get; set; } - + } } diff --git a/Entity/Dto/SelectPackDto.cs b/Entity/Dto/SelectPackDto.cs new file mode 100644 index 0000000..2716dd1 --- /dev/null +++ b/Entity/Dto/SelectPackDto.cs @@ -0,0 +1,16 @@ +using Entity.Constant; +using Entity.DbModel.Station; + +namespace Entity.Dto; + +/// +/// 选包dto +/// +public class SelectPackDto +{ + public bool SuccessFlag { get; set; } + + public InfoEnum.SelectBinStatusInfo Info { get; set; } + + public BinInfo BinInfo { get; set; } +} \ No newline at end of file diff --git a/HybirdFrameworkCore/Entity/IPage.cs b/HybirdFrameworkCore/Entity/IPage.cs index b9a8d4a..4b7cdde 100644 --- a/HybirdFrameworkCore/Entity/IPage.cs +++ b/HybirdFrameworkCore/Entity/IPage.cs @@ -9,7 +9,7 @@ public class IPage public int PageSize; public List? Rows; - + public IPage(int total, QueryPageModel page, List? rows) { Total = total; diff --git a/Repository/Station/BinInfoRepository.cs b/Repository/Station/BinInfoRepository.cs index 71580e6..e5b5a7e 100644 --- a/Repository/Station/BinInfoRepository.cs +++ b/Repository/Station/BinInfoRepository.cs @@ -1,14 +1,67 @@ +using Entity.Constant; using Entity.DbModel.Station; +using Entity.Dto; using HybirdFrameworkCore.Autofac.Attribute; using SqlSugar; namespace Repository.Station; [Scope("SingleInstance")] -public class BinInfoRepository:BaseRepository +public class BinInfoRepository : BaseRepository { - public BinInfoRepository(ISqlSugarClient sqlSugar) : base(sqlSugar) { } + + /// + /// 选包 + /// + /// StaticStationInfo.SwapSoc + /// StaticStationInfo.SwapFinishChargeTime + /// + public SelectPackDto SelectPack(string swapSoc, string swapFinishChargeTime) + { + SelectPackDto selectPackDto = new() + { + SuccessFlag = false, + }; + List list = + QueryListByClause(i => + i.Exists == 1 && i.Status == 1 && i.AmtLock == (int)InfoEnum.AmtBatLockStatus.UnLock); + if (list.Count <= 0) + { + selectPackDto.Info = InfoEnum.SelectBinStatusInfo.NoBattery; + return selectPackDto; + } + + list = list.Where(i => i.ChargeStatus == 2).ToList(); + if (list.Count <= 0) + { + selectPackDto.Info = InfoEnum.SelectBinStatusInfo.LessOfFinishCharging; + return selectPackDto; + } + + + list = list.Where(i => i.Soc > int.Parse(swapSoc)).ToList(); + if (list.Count <= 0) + { + selectPackDto.Info = InfoEnum.SelectBinStatusInfo.LessOfSoc; + return selectPackDto; + } + + list = list.Where(i => new TimeSpan(DateTime.Now.Ticks - + i.LastChargeFinishTime.ToDateTime().Ticks) + .TotalMinutes > int.Parse(swapFinishChargeTime)).ToList(); + if (list.Count <= 0) + { + selectPackDto.Info = InfoEnum.SelectBinStatusInfo.LessOf3Minute; + return selectPackDto; + } + + selectPackDto.BinInfo = list[0]; + selectPackDto.Info = InfoEnum.SelectBinStatusInfo.Success; + selectPackDto.SuccessFlag = true; + + return selectPackDto; + } } \ No newline at end of file diff --git a/Service/Cloud/Handler/AmtBatHandler.cs b/Service/Cloud/Handler/AmtBatHandler.cs index e288648..7d5900f 100644 --- a/Service/Cloud/Handler/AmtBatHandler.cs +++ b/Service/Cloud/Handler/AmtBatHandler.cs @@ -1,11 +1,11 @@ -using Entity.DbModel.Station; +using Entity.Constant; +using Entity.DbModel.Station; using HybirdFrameworkCore.Autofac.Attribute; using Newtonsoft.Json; using Repository.Station; using Service.Cloud.Common; using Service.Cloud.Msg.Cloud.Req; using Service.Cloud.Msg.Host.Resp; -using Service.Execute.Enum; using Service.Init; namespace Service.Cloud.Handler; diff --git a/Service/Execute/Api/CloudApi.cs b/Service/Execute/Api/CloudApi.cs index f497df8..8378017 100644 --- a/Service/Execute/Api/CloudApi.cs +++ b/Service/Execute/Api/CloudApi.cs @@ -1,8 +1,8 @@ +using Entity.Constant; using Entity.DbModel.Station; using log4net; using Service.Cloud.Client; using Service.Cloud.Msg.Cloud.Req; -using Service.Execute.Enum; using Service.Execute.Model; namespace Service.Execute.Api; diff --git a/Service/Execute/Model/SwapOrderBatteryInfo.cs b/Service/Execute/Model/SwapOrderBatteryInfo.cs index 1fc3337..a9ab377 100644 --- a/Service/Execute/Model/SwapOrderBatteryInfo.cs +++ b/Service/Execute/Model/SwapOrderBatteryInfo.cs @@ -1,6 +1,6 @@ +using Entity.Constant; using Entity.DbModel.Station; using NewLife.Common; -using Service.Execute.Enum; namespace Service.Execute.Model; diff --git a/Service/Execute/Step/CancelState.cs b/Service/Execute/Step/CancelState.cs index f3bb553..089e6c4 100644 --- a/Service/Execute/Step/CancelState.cs +++ b/Service/Execute/Step/CancelState.cs @@ -1,14 +1,16 @@ -using log4net; +using Autofac; +using Entity.Constant; +using HybirdFrameworkCore.Autofac; +using log4net; using Repository.Station; -using Service.Execute.Enum; namespace Service.Execute.Step; public class CancelState : IState { - private SwapOrderRepository SwapOrderRepository { get; set; } + private readonly SwapOrderRepository _swapOrderRepository= AppInfo.Container.Resolve(); - private SwapAmtOrderRepository SwapAmtOrderRepository { get; set; } + private readonly SwapAmtOrderRepository _swapAmtOrderRepository = AppInfo.Container.Resolve(); private static readonly ILog _log = LogManager.GetLogger(typeof(CancelState)); public StateResult Handle(SwappingStateMachine machine) @@ -18,13 +20,13 @@ public class CancelState : IState if (machine.SwapOrderBatteryInfo.swapAmtOrder != null) { machine.SwapOrderBatteryInfo.swapAmtOrder.Status = (byte)InfoEnum.AmtOrderStatus.SwapFail; - SwapAmtOrderRepository.Update(machine.SwapOrderBatteryInfo.swapAmtOrder); + _swapAmtOrderRepository.Update(machine.SwapOrderBatteryInfo.swapAmtOrder); } if (machine.SwapOrder != null) { machine.SwapOrder.SwapResult = (byte)InfoEnum.SwapOrderResult.Fail; - SwapOrderRepository.Update(machine.SwapOrder); + _swapOrderRepository.Update(machine.SwapOrder); } machine.Reset(); diff --git a/Service/Execute/Step/CarCtrlState.cs b/Service/Execute/Step/CarCtrlState.cs index 3d00df9..277a6e4 100644 --- a/Service/Execute/Step/CarCtrlState.cs +++ b/Service/Execute/Step/CarCtrlState.cs @@ -1,11 +1,11 @@ -using log4net; +using Entity.Attr; +using Entity.Constant; +using log4net; using Service.Execute.Api; -using Service.Execute.Enum; using Service.Execute.Model; using Service.Execute.StaticTools; using Service.Execute.SwapException; using Service.Station; -using Swapping.Business.Tech; namespace Service.Execute.Step; diff --git a/Service/Execute/Step/CarPrepareState.cs b/Service/Execute/Step/CarPrepareState.cs index 4e4fa3b..81f5392 100644 --- a/Service/Execute/Step/CarPrepareState.cs +++ b/Service/Execute/Step/CarPrepareState.cs @@ -1,16 +1,18 @@ -using AutoMapper; +using Autofac; +using AutoMapper; +using Entity.Attr; using Entity.Constant; using Entity.DbModel.Station; +using Entity.Dto; +using HybirdFrameworkCore.Autofac; using log4net; using Repository.Station; using Service.Execute.Api; -using Service.Execute.Enum; using Service.Execute.Model; using Service.Execute.StaticTools; using Service.Execute.SwapException; using Service.Init; using Service.Station; -using Swapping.Business.Tech; namespace Service.Execute.Step; @@ -19,11 +21,11 @@ public class CarPrepareState : IState private readonly ILog _log = LogManager.GetLogger(typeof(CarPrepareState)); - private BinInfoRepository BinInfoRepository { get; set; } - public SwapOrderStepService SwapOrderStepService { get; set; } - private SwapAmtOrderRepository AmtOrderRepository { get; set; } + private readonly BinInfoRepository _binInfoRepository = AppInfo.Container.Resolve(); + private readonly SwapOrderStepService _swapOrderStepService = AppInfo.Container.Resolve(); + private readonly SwapAmtOrderRepository _amtOrderRepository = AppInfo.Container.Resolve(); - private SwapOrderBatteryRepository SwapOrderBatteryRepository { get; set; } + private readonly SwapOrderBatteryRepository _swapOrderBatteryRepository = AppInfo.Container.Resolve(); public StateResult Handle(SwappingStateMachine machine) { @@ -118,8 +120,8 @@ public class CarPrepareState : IState CloudApi.SendStateLog(machine.SwapOrder, machine.BusinessSwappingForCloudState); //清除下发的指令,等待新的指令 CloudApi.ClearCarCanStartInfo(); - - SwapOrderStepService.InsertSwapStepForSwapMain(InfoEnum.BusinessSwappingStep.CarInPositionFlag, + + _swapOrderStepService.InsertSwapStepForSwapMain(InfoEnum.BusinessSwappingStep.CarInPositionFlag, machine.StepSort++, machine.SwapOrder.Sn); } } @@ -157,8 +159,8 @@ public class CarPrepareState : IState _log.Info("cloud check vehicle done"); machine.CloudVelCheckFlag = true; machine.LedTool.WriteProgramContent("换电准备中:云平台车辆验证完成"); - - SwapOrderStepService.InsertSwapStepForSwapMain(InfoEnum.BusinessSwappingStep.CloudVelCheckFlag, + + _swapOrderStepService.InsertSwapStepForSwapMain(InfoEnum.BusinessSwappingStep.CloudVelCheckFlag, machine.StepSort++, machine.SwapOrder.Sn); } } @@ -266,8 +268,8 @@ public class CarPrepareState : IState public InvokeStatus SelectPack(SwappingStateMachine machine) { SwapAmtOrder? swapAmtOrder = - AmtOrderRepository.QueryByClause(i => - i.Status == (int)InfoEnum.AmtOrderStatus.Success && i.VehicleNo.Equals(machine.BoxCarInfoModel.CarNo)); + _amtOrderRepository.QueryByClause(i => + i.Status == (int)InfoEnum.AmtOrderStatus.Success && i.CarNo.Equals(machine.BoxCarInfoModel.CarNo)); return Invoker.Invoke("selectPack", 500, 20, machine.IsCanceled, @@ -315,7 +317,7 @@ public class CarPrepareState : IState UpBatteryBinNo = int.Parse(UpBin.No), DownBatteryBinNo = int.Parse(InBin.No), }; - SwapOrderBatteryRepository.Insert(swapOrderBattery); + _swapOrderBatteryRepository.Insert(swapOrderBattery); } /// @@ -330,7 +332,7 @@ public class CarPrepareState : IState BinInfo dbBinInfo = mapperBinInfo.Map(orderBatteryInfo.UpBinInfo); dbBinInfo.AmtLock = (int)InfoEnum.AmtBatLockStatus.Lock; - BinInfoRepository.Update(dbBinInfo); + _binInfoRepository.Update(dbBinInfo); if (!orderBatteryInfo.isAmt) { return; @@ -341,7 +343,7 @@ public class CarPrepareState : IState IMapper mapperAmt = configAmt.CreateMapper(); SwapAmtOrder swapAmtOrder = mapperAmt.Map(orderBatteryInfo.swapAmtOrder); swapAmtOrder.Status = (int)InfoEnum.AmtOrderStatus.Swapping; - AmtOrderRepository.Update(swapAmtOrder); + _amtOrderRepository.Update(swapAmtOrder); } /// 1.仓位状态:启动 @@ -377,7 +379,7 @@ public class CarPrepareState : IState SwapOrderBatteryInfo orderBatteryInfo = new SwapOrderBatteryInfo(); orderBatteryInfo.swapAmtOrder = swapAmtOrder; orderBatteryInfo.isAmt = true; - BinInfo UpBin = BinInfoRepository.QueryByClause(i => i.No.Equals(swapAmtOrder.AmtBinNoList)); + BinInfo UpBin = _binInfoRepository.QueryByClause(i => i.No.Equals(swapAmtOrder.AmtBinNoList)); bool CanSwap = UpBin.Exists == 1 && UpBin.Status == 1 && UpBin.ChargeStatus == 2 && UpBin.AmtLock == (int)InfoEnum.AmtBatLockStatus.Lock && new TimeSpan(DateTime.Now.Ticks - UpBin.LastChargeFinishTime.ToDateTime() @@ -402,53 +404,23 @@ public class CarPrepareState : IState /// private void UpBin(SwapOrderBatteryInfo orderBatteryInfo) { - List list = - BinInfoRepository.QueryListByClause(i => - i.Exists == 1 && i.Status == 1 && i.AmtLock == (int)InfoEnum.AmtBatLockStatus.UnLock); - if (list.Count <= 0) - { - orderBatteryInfo.CanSwap = InfoEnum.SelectBinStatusInfo.NoBattery; - return; - } - - list = list.Where(i => i.ChargeStatus == 2).ToList(); - if (list.Count <= 0) - { - orderBatteryInfo.CanSwap = InfoEnum.SelectBinStatusInfo.LessOfFinishCharging; - return; - } + SelectPackDto selectPack = + _binInfoRepository.SelectPack(StaticStationInfo.SwapSoc, StaticStationInfo.SwapFinishChargeTime); - - list = list.Where(i => i.Soc > int.Parse(StaticStationInfo.SwapSoc)).ToList(); - if (list.Count <= 0) - { - orderBatteryInfo.CanSwap = InfoEnum.SelectBinStatusInfo.LessOfSoc; - return; - } - - list = list.Where(i => new TimeSpan(DateTime.Now.Ticks - - i.LastChargeFinishTime.ToDateTime().Ticks) - .TotalMinutes > int.Parse(StaticStationInfo.SwapFinishChargeTime)).ToList(); - if (list.Count <= 0) - { - orderBatteryInfo.CanSwap = InfoEnum.SelectBinStatusInfo.LessOf3Minute; - return; - } - - orderBatteryInfo.UpBinInfo = list[0]; - orderBatteryInfo.CanSwap = InfoEnum.SelectBinStatusInfo.Success; + orderBatteryInfo.UpBinInfo = selectPack.BinInfo; + orderBatteryInfo.CanSwap = selectPack.Info; } /// - /// 放电池判断 + /// 放电池判断:取出来的电池仓位能不能放 /// /// private void InBin(SwapOrderBatteryInfo orderBatteryInfo) { List list = - BinInfoRepository.QueryListByClause(i => - i.Exists == 1 && i.Status == 1 && i.AmtLock == (int)InfoEnum.AmtBatLockStatus.UnLock - && i.Exists == 0); + _binInfoRepository.QueryListByClause(i => + i.Status == 1 && i.AmtLock == (int)InfoEnum.AmtBatLockStatus.UnLock + && i.Exists == 0); if (list.Count <= 0) { orderBatteryInfo.CanSwap = InfoEnum.SelectBinStatusInfo.LessOfEmptyBin; diff --git a/Service/Execute/Step/DoSwappingState.cs b/Service/Execute/Step/DoSwappingState.cs index 50ed76b..d4b2237 100644 --- a/Service/Execute/Step/DoSwappingState.cs +++ b/Service/Execute/Step/DoSwappingState.cs @@ -1,20 +1,22 @@ -using log4net; +using Autofac; +using Entity.Attr; +using Entity.Constant; +using HybirdFrameworkCore.Autofac; +using log4net; using Repository.Station; using Service.Execute.Api; -using Service.Execute.Enum; using Service.Execute.Model; using Service.Execute.StaticTools; using Service.Execute.SwapException; using Service.Station; -using Swapping.Business.Tech; namespace Service.Execute.Step; public class DoSwappingState : IState { private readonly ILog _log = LogManager.GetLogger(typeof(DoSwappingState)); - private SwapOrderRepository SwapOrderRepository { get; set; } - public SwapOrderStepService SwapOrderStepService { get; set; } + private readonly SwapOrderRepository _swapOrderRepository = AppInfo.Container.Resolve(); + private readonly SwapOrderStepService _swapOrderStepService = AppInfo.Container.Resolve(); public StateResult Handle(SwappingStateMachine machine) { @@ -107,10 +109,10 @@ public class DoSwappingState : IState if (startSwapping) { machine.SwapOrder.SwapBeginTime = DateTime.Now; - SwapOrderRepository.Update(machine.SwapOrder); + _swapOrderRepository.Update(machine.SwapOrder); machine.SwapStatus = 0; machine.StartSwappingFlag = true; - SwapOrderStepService.InsertSwapStepForSwapMain(InfoEnum.BusinessSwappingStep.StartSwappingFlag, + _swapOrderStepService.InsertSwapStepForSwapMain(InfoEnum.BusinessSwappingStep.StartSwappingFlag, machine.StepSort++, machine.SwapOrder.Sn); } } @@ -138,7 +140,7 @@ public class DoSwappingState : IState if (machine.UnOldBatteryFlag) { - SwapOrderStepService.InsertSwapStepForSwapMain(InfoEnum.BusinessSwappingStep.UnOldBatteryFlag, + _swapOrderStepService.InsertSwapStepForSwapMain(InfoEnum.BusinessSwappingStep.UnOldBatteryFlag, machine.StepSort++, machine.SwapOrder.Sn); } }, () => { }); @@ -156,7 +158,7 @@ public class DoSwappingState : IState if (machine.StorageOldBatteryFlag) { - SwapOrderStepService.InsertSwapStepForSwapMain(InfoEnum.BusinessSwappingStep.StorageOldBatteryFlag, + _swapOrderStepService.InsertSwapStepForSwapMain(InfoEnum.BusinessSwappingStep.StorageOldBatteryFlag, machine.StepSort++, machine.SwapOrder.Sn); } }, () => { }); @@ -173,7 +175,7 @@ public class DoSwappingState : IState machine.OutNewBatteryFlag = PlcApi.ReadPlcTaskStatus() == 1004; if (machine.OutNewBatteryFlag) { - SwapOrderStepService.InsertSwapStepForSwapMain(InfoEnum.BusinessSwappingStep.OutNewBatteryFlag, + _swapOrderStepService.InsertSwapStepForSwapMain(InfoEnum.BusinessSwappingStep.OutNewBatteryFlag, machine.StepSort++, machine.SwapOrder.Sn); } }, () => { }); @@ -192,7 +194,7 @@ public class DoSwappingState : IState if (machine.InstallNewBatteryFlag) { - SwapOrderStepService.InsertSwapStepForSwapMain(InfoEnum.BusinessSwappingStep.InstallNewBatteryFlag, + _swapOrderStepService.InsertSwapStepForSwapMain(InfoEnum.BusinessSwappingStep.InstallNewBatteryFlag, machine.StepSort++, machine.SwapOrder.Sn); } }, () => { }); @@ -215,7 +217,7 @@ public class DoSwappingState : IState //上报云平台换电完成 machine.SwapStatus = 1; - SwapOrderStepService.InsertSwapStepForSwapMain(InfoEnum.BusinessSwappingStep.FinishNewBatteryFlag, + _swapOrderStepService.InsertSwapStepForSwapMain(InfoEnum.BusinessSwappingStep.FinishNewBatteryFlag, machine.StepSort++, machine.SwapOrder.Sn); } }, () => { }); diff --git a/Service/Execute/Step/StationReadyState.cs b/Service/Execute/Step/StationReadyState.cs index 575f15d..8b080c3 100644 --- a/Service/Execute/Step/StationReadyState.cs +++ b/Service/Execute/Step/StationReadyState.cs @@ -1,20 +1,21 @@ using System.Text; +using Autofac; +using Entity.Attr; using Entity.Constant; using Entity.DbModel.Station; +using HybirdFrameworkCore.Autofac; using log4net; using Microsoft.OpenApi.Extensions; using Microsoft.VisualBasic; using Newtonsoft.Json; using Repository.Station; using Service.Execute.Api; -using Service.Execute.Enum; using Service.Execute.Model; using Service.Execute.StaticTools; using Service.Execute.SwapException; using Service.Init; using Service.Station; using Swapping.Business.Common; -using Swapping.Business.Tech; namespace Service.Execute.Step; @@ -23,9 +24,9 @@ public class StationReadyState : IState private readonly ILog _log = LogManager.GetLogger(typeof(StationReadyState)); - public SwapOrderRepository SwapOrderRepository { get; set; } + private readonly SwapOrderRepository _swapOrderRepository = AppInfo.Container.Resolve(); - public SwapOrderStepService SwapOrderStepService { get; set; } + private readonly SwapOrderStepService _swapOrderStepService = AppInfo.Container.Resolve(); public StateResult Handle(SwappingStateMachine machine) { @@ -203,11 +204,11 @@ public class StationReadyState : IState //新增换电订单 machine.SwapOrder = SaveOrder(BuildOrder(machine.RfidReadModel)); //新增小步 - SwapOrderStepService.InsertSwapStepForSwapMain(InfoEnum.BusinessSwappingStep.Idel, + _swapOrderStepService.InsertSwapStepForSwapMain(InfoEnum.BusinessSwappingStep.Idel, machine.StepSort++, machine.SwapOrder.Sn); - SwapOrderStepService.InsertSwapStepForSwapMain(InfoEnum.BusinessSwappingStep.RadarInFlag, + _swapOrderStepService.InsertSwapStepForSwapMain(InfoEnum.BusinessSwappingStep.RadarInFlag, machine.StepSort++, machine.SwapOrder.Sn); - SwapOrderStepService.InsertSwapStepForSwapMain(InfoEnum.BusinessSwappingStep.RfidReadFlag, + _swapOrderStepService.InsertSwapStepForSwapMain(InfoEnum.BusinessSwappingStep.RfidReadFlag, machine.StepSort++, machine.SwapOrder.Sn); RfidApi.StopRead(); _log.Info("stop read rfid"); @@ -239,7 +240,7 @@ public class StationReadyState : IState private SwapOrder SaveOrder(SwapOrder swapOrder) { - SwapOrderRepository.Insert(swapOrder); + _swapOrderRepository.Insert(swapOrder); return swapOrder; } } \ No newline at end of file diff --git a/Service/Execute/Step/SwapCanStartState.cs b/Service/Execute/Step/SwapCanStartState.cs index b0a1bc9..36c7a31 100644 --- a/Service/Execute/Step/SwapCanStartState.cs +++ b/Service/Execute/Step/SwapCanStartState.cs @@ -1,15 +1,16 @@ -using Entity.Constant; +using Autofac; +using Entity.Attr; +using Entity.Constant; +using HybirdFrameworkCore.Autofac; using log4net; using Repository.Station; using Service.Cloud.Client; using Service.Cloud.Msg.Cloud.Req; using Service.Execute.Api; -using Service.Execute.Enum; using Service.Execute.StaticTools; using Service.Execute.SwapException; using Service.Init; using Service.Station; -using Swapping.Business.Tech; namespace Service.Execute.Step; @@ -20,8 +21,8 @@ public class SwapCanStartState : IState { private readonly ILog _log = LogManager.GetLogger(typeof(SwapCanStartState)); - public SwapOrderStepService SwapOrderStepService { get; set; } - private SwapOrderRepository SwapOrderRepository { get; set; } + private readonly SwapOrderStepService _swapOrderStepService = AppInfo.Container.Resolve(); + private readonly SwapOrderRepository _swapOrderRepository = AppInfo.Container.Resolve(); public StateResult Handle(SwappingStateMachine machine) { @@ -65,10 +66,10 @@ public class SwapCanStartState : IState _log.Info("SwapCanStart ok"); //更新换电订单 machine.SwapOrder.CloudSn = carCanStart.on; - SwapOrderRepository.Update(machine.SwapOrder.CloudSn); + _swapOrderRepository.Update(machine.SwapOrder.CloudSn); machine.CloudCarCanStartFlag = true; - SwapOrderStepService.InsertSwapStepForSwapMain(InfoEnum.BusinessSwappingStep.CloudCarCanStartFlag, + _swapOrderStepService.InsertSwapStepForSwapMain(InfoEnum.BusinessSwappingStep.CloudCarCanStartFlag, machine.StepSort++, machine.SwapOrder.Sn); } else diff --git a/Service/Execute/Step/SwapDoneState.cs b/Service/Execute/Step/SwapDoneState.cs index 40ae2d1..162f82e 100644 --- a/Service/Execute/Step/SwapDoneState.cs +++ b/Service/Execute/Step/SwapDoneState.cs @@ -1,20 +1,22 @@ -using log4net; +using Autofac; +using Entity.Attr; +using Entity.Constant; +using HybirdFrameworkCore.Autofac; +using log4net; using Repository.Station; using Service.Execute.Api; -using Service.Execute.Enum; using Service.Execute.Model; using Service.Execute.StaticTools; using Service.Execute.SwapException; using Service.Station; -using Swapping.Business.Tech; namespace Service.Execute.Step; public class SwapDoneState : IState { - private SwapOrderRepository SwapOrderRepository { get; set; } - public SwapOrderStepService SwapOrderStepService { get; set; } - private SwapAmtOrderRepository SwapAmtOrderRepository { get; set; } + private readonly SwapOrderRepository _swapOrderRepository = AppInfo.Container.Resolve(); + private readonly SwapOrderStepService _swapOrderStepService = AppInfo.Container.Resolve(); + private readonly SwapAmtOrderRepository _swapAmtOrderRepository = AppInfo.Container.Resolve(); private readonly ILog _log = LogManager.GetLogger(typeof(SwapDoneState)); @@ -30,7 +32,7 @@ public class SwapDoneState : IState machine.SwapOrder.SwapResult = machine.SwapStatus; machine.SwapOrder.SwapEndTime = DateTime.Now; machine.SwapOrder.FailReason = machine.SwapFailReason; - SwapOrderRepository.Update(machine.SwapOrder); + _swapOrderRepository.Update(machine.SwapOrder); if (machine.SwapStatus == (int)InfoEnum.SwapOrderResult.Success) @@ -92,7 +94,7 @@ public class SwapDoneState : IState machine.VelLockFlag = true; - SwapOrderStepService.InsertSwapStepForSwapMain(InfoEnum.BusinessSwappingStep.VelLockFlag, + _swapOrderStepService.InsertSwapStepForSwapMain(InfoEnum.BusinessSwappingStep.VelLockFlag, machine.StepSort++, machine.SwapOrder.Sn); } } @@ -128,19 +130,19 @@ public class SwapDoneState : IState machine.BusinessSwappingForCloudState = InfoEnum.BusinessSwappingForCloudState.SwapDoneWithoutVel; machine.SwapOrder!.VehicleLeaveTime = DateTime.Now; - SwapOrderRepository.Update(machine.SwapOrder); + _swapOrderRepository.Update(machine.SwapOrder); if (machine.SwapOrderBatteryInfo!.swapAmtOrder != null) { machine.SwapOrderBatteryInfo.swapAmtOrder.Status = machine.SwapStatus == (int)InfoEnum.SwapOrderResult.Success ? (int)InfoEnum.AmtOrderStatus.SwapFinish : (int)InfoEnum.AmtOrderStatus.SwapFail; - SwapAmtOrderRepository.Update(machine.SwapOrderBatteryInfo.swapAmtOrder); + _swapAmtOrderRepository.Update(machine.SwapOrderBatteryInfo.swapAmtOrder); } machine.RadarOutFlag = true; - SwapOrderStepService.InsertSwapStepForSwapMain( + _swapOrderStepService.InsertSwapStepForSwapMain( machine.SwapStatus == (int)InfoEnum.SwapOrderResult.Success ? InfoEnum.BusinessSwappingStep.RadarOutFlag : InfoEnum.BusinessSwappingStep.RadarOutFailFlag, diff --git a/Service/Execute/SwappingStateMachine.cs b/Service/Execute/SwappingStateMachine.cs index 3551c49..a6e27d2 100644 --- a/Service/Execute/SwappingStateMachine.cs +++ b/Service/Execute/SwappingStateMachine.cs @@ -1,15 +1,16 @@ -using DotNetty.Common.Utilities; +using Autofac; +using DotNetty.Common.Utilities; +using Entity.Constant; using Entity.DbModel.Station; +using HybirdFrameworkCore.Autofac; using log4net; using Newtonsoft.Json; using Repository.Station; using Service.Execute.Api; -using Service.Execute.Enum; using Service.Execute.Model; using Service.Execute.StaticTools; using Service.Execute.Step; using Service.Execute.SwapException; -using Service.Execute.Tech; namespace Service.Execute; @@ -17,9 +18,12 @@ public class SwappingStateMachine : IDisposable { private static readonly ILog Log = LogManager.GetLogger(typeof(SwappingStateMachine)); private static readonly SwappingStateMachine SwappingMachine = new SwappingStateMachine(); + private BinInfoRepository BinInfoRepository { get; set; } + private SwapAmtOrderRepository AmtOrderRepository { get; set; } + public bool CancelFlag { get; set; } = false; public bool StopFlag { get; set; } = false; @@ -137,6 +141,9 @@ public class SwappingStateMachine : IDisposable _dictionary[SwappingState.Canceled] = new CancelState(); LedTool = new LedTool(); + + BinInfoRepository = AppInfo.Container.Resolve(); + AmtOrderRepository = AppInfo.Container.Resolve(); } public static SwappingStateMachine GetInstance() diff --git a/Service/Execute/Enum/SwapOrderNoGenerator.cs b/Service/Execute/Utils/SwapOrderNoGenerator.cs similarity index 100% rename from Service/Execute/Enum/SwapOrderNoGenerator.cs rename to Service/Execute/Utils/SwapOrderNoGenerator.cs diff --git a/Service/Service.csproj b/Service/Service.csproj index b4cce1f..7f81982 100644 --- a/Service/Service.csproj +++ b/Service/Service.csproj @@ -39,4 +39,8 @@ + + + + diff --git a/Service/Station/SwapOrderStepService.cs b/Service/Station/SwapOrderStepService.cs index 28d6575..65300ee 100644 --- a/Service/Station/SwapOrderStepService.cs +++ b/Service/Station/SwapOrderStepService.cs @@ -7,7 +7,6 @@ using Repository.Station; using SqlSugar; using System.Linq.Expressions; using Entity.Constant; -using Service.Execute.Enum; namespace Service.Station; diff --git a/Service/System/LoginService.cs b/Service/System/LoginService.cs index 25c6de9..dc1ccc8 100644 --- a/Service/System/LoginService.cs +++ b/Service/System/LoginService.cs @@ -446,7 +446,7 @@ namespace Service.System var typeList = GetConstAttributeList(); var type = typeList.FirstOrDefault(u => u.Name == typeName); - var isEnum = type.BaseType.Name == "Enum"; + var isEnum = type.BaseType.Name == "Utils"; constlist = type.GetFields()? .Where(isEnum, u => u.FieldType.Name == typeName) .Select(u => new ConstResp diff --git a/WebStarter/Program.cs b/WebStarter/Program.cs index 45e9c90..47bb01e 100644 --- a/WebStarter/Program.cs +++ b/WebStarter/Program.cs @@ -28,7 +28,7 @@ builder.Host.ConfigureContainer(cb => ConnectionString = AppSettingsConstVars.DbSqlConnection, // 设置数据库连接字符串 DbType = AppSettingsConstVars.DbDbType == IocDbType.MySql.ToString() ? DbType.MySql : DbType.SqlServer, IsAutoCloseConnection = true, - InitKeyType = InitKeyType.Attribute // 如果使用实体类的属性进行主键标识,请设置为 InitKeyType.Attribute + InitKeyType = InitKeyType.Attribute // 如果使用实体类的属性进行主键标识,请设置为 InitKeyType.Attr }); return db; }).As().SingleInstance(); diff --git a/WinFormStarter/Program.cs b/WinFormStarter/Program.cs index e574e9c..b443774 100644 --- a/WinFormStarter/Program.cs +++ b/WinFormStarter/Program.cs @@ -37,7 +37,7 @@ internal static class Program ConnectionString = AppSettingsConstVars.DbSqlConnection, // 设置数据库连接字符串 DbType = AppSettingsConstVars.DbDbType == IocDbType.MySql.ToString() ? DbType.MySql : DbType.SqlServer, IsAutoCloseConnection = true, - InitKeyType = InitKeyType.Attribute // 如果使用实体类的属性进行主键标识,请设置为 InitKeyType.Attribute + InitKeyType = InitKeyType.Attribute // 如果使用实体类的属性进行主键标识,请设置为 InitKeyType.Attr }); return db; }).As().InstancePerLifetimeScope(); diff --git a/WpfStarter/App.xaml.cs b/WpfStarter/App.xaml.cs index 2e55232..db8fed8 100644 --- a/WpfStarter/App.xaml.cs +++ b/WpfStarter/App.xaml.cs @@ -25,7 +25,7 @@ public partial class App : Application ? DbType.MySql : DbType.SqlServer, IsAutoCloseConnection = true, - InitKeyType = InitKeyType.Attribute // 如果使用实体类的属性进行主键标识,请设置为 InitKeyType.Attribute + InitKeyType = InitKeyType.Attribute // 如果使用实体类的属性进行主键标识,请设置为 InitKeyType.Attr }); return db; }).As().InstancePerLifetimeScope();