diff --git a/Entity/Api/Resp/SwapOrderStepResp.cs b/Entity/Api/Resp/SwapOrderStepResp.cs index 3770822..617716b 100644 --- a/Entity/Api/Resp/SwapOrderStepResp.cs +++ b/Entity/Api/Resp/SwapOrderStepResp.cs @@ -63,6 +63,13 @@ namespace Entity.Api.Resp /// Nullable:True /// public DateTime? UpdatedTime {get;set;} + + /// + /// Desc:排序 + /// Default: + /// Nullable:True + /// + public int Sort { get; set; } } } diff --git a/Entity/Constant/BaseEnumExtensions.cs b/Entity/Constant/BaseEnumExtensions.cs index 119004f..e2988a3 100644 --- a/Entity/Constant/BaseEnumExtensions.cs +++ b/Entity/Constant/BaseEnumExtensions.cs @@ -27,4 +27,9 @@ public class BaseEnumExtensions { return GetDescription((T)Enum.ToObject(typeof(T), code)); } + + public static string GetNameByEnum(Enum value) where T : Enum + { + return Enum.GetName(typeof(T), value); + } } \ No newline at end of file diff --git a/Entity/DbModel/Station/SwapOrderStep.cs b/Entity/DbModel/Station/SwapOrderStep.cs index bca4eeb..715019e 100644 --- a/Entity/DbModel/Station/SwapOrderStep.cs +++ b/Entity/DbModel/Station/SwapOrderStep.cs @@ -1,6 +1,4 @@ -using System; -using System.Linq; -using System.Text; + using SqlSugar; namespace Entity.DbModel.Station @@ -8,10 +6,9 @@ namespace Entity.DbModel.Station /// ///换电步序表 /// - [SugarTable("swap_order_step")] + [SugarTable("swap_order_step")] public partial class SwapOrderStep { - [SugarColumn(IsPrimaryKey = true, IsIdentity = true, ColumnName = "id")] public int Id { get; set; } @@ -45,7 +42,7 @@ namespace Entity.DbModel.Station /// Nullable:True /// [SugarColumn(ColumnName = "created_by")] - public string ?CreatedBy { get; set; } + public string? CreatedBy { get; set; } /// /// Desc:创建时间 @@ -61,7 +58,7 @@ namespace Entity.DbModel.Station /// Nullable:True /// [SugarColumn(ColumnName = "updated_by")] - public string ?UpdatedBy { get; set; } + public string? UpdatedBy { get; set; } /// /// Desc:更新时间 @@ -71,5 +68,13 @@ namespace Entity.DbModel.Station [SugarColumn(ColumnName = "updated_time")] public DateTime? UpdatedTime { get; set; } + + /// + /// Desc:排序 + /// Default: + /// Nullable:True + /// + [SugarColumn(ColumnName = "sort")] + public int Sort { get; set; } } -} +} \ No newline at end of file diff --git a/Service/Execute/Enum/InfoEnum.cs b/Service/Execute/Enum/InfoEnum.cs index 782c516..04bc262 100644 --- a/Service/Execute/Enum/InfoEnum.cs +++ b/Service/Execute/Enum/InfoEnum.cs @@ -81,17 +81,17 @@ public class InfoEnum } //小步状态 - public enum BusinessSwappingStep : byte + public enum BusinessSwappingStep { [Remark("空闲")] Idel, [Remark("车辆到站(入口雷达检测到车辆驶入)")] RadarInFlag, [Remark("rfid扫描完成")] RfidReadFlag, [Remark("云平台车辆认证")] CloudVelCheckFlag, - [Remark("Tbox数据获取")] BoxConnectFlag, - [Remark("车辆数据上传云平台")] CloudTBoxFlag, + [Remark("车辆到位")] CarInPositionFlag, [Remark("云平台下发换电指令")] CloudCarCanStartFlag, - [Remark("下发plc选包")] DistributeSelectPackFlag, [Remark("车辆解锁")] VelUnlockFlag, + [Remark("下发plc选包")] DistributeSelectPackFlag, + [Remark("开始换电")] StartSwappingFlag, [Remark("拆旧电池")] UnOldBatteryFlag, [Remark("入库旧电池")] StorageOldBatteryFlag, @@ -100,6 +100,7 @@ public class InfoEnum [Remark("安装完成")] FinishNewBatteryFlag, [Remark("车辆上锁")] VelLockFlag, [Remark("换电完成(车辆驶离)")] RadarOutFlag, + [Remark("换电失败(车辆驶离)")] RadarOutFailFlag, } diff --git a/Service/Execute/Step/CarCtrlState.cs b/Service/Execute/Step/CarCtrlState.cs index f797873..3d00df9 100644 --- a/Service/Execute/Step/CarCtrlState.cs +++ b/Service/Execute/Step/CarCtrlState.cs @@ -4,6 +4,7 @@ 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; @@ -12,6 +13,7 @@ public class CarCtrlState : IState { private readonly ILog _log = LogManager.GetLogger(typeof(CarCtrlState)); + public SwapOrderStepService SwapOrderStepService { get; set; } public StateResult Handle(SwappingStateMachine machine) { //解锁车辆 @@ -53,6 +55,8 @@ public class CarCtrlState : IState if (carInfo.Result.HeartBeatMsg.LockStatus == 1) { machine.VelUnlockFlag = true; + SwapOrderStepService.InsertSwapStepForSwapMain(InfoEnum.BusinessSwappingStep.VelUnlockFlag, + machine.StepSort++, machine.SwapOrder.Sn); } } }, () => @@ -76,6 +80,12 @@ public class CarCtrlState : IState var swapOrderBatteryInfo = machine.SwapOrderBatteryInfo; machine.DistributeSelectPackFlag = PlcApi.DistributeSelectPack(swapOrderBatteryInfo.InBinInfo.No, swapOrderBatteryInfo.UpBinInfo.No); + + if (machine.DistributeSelectPackFlag) + { + SwapOrderStepService.InsertSwapStepForSwapMain(InfoEnum.BusinessSwappingStep.DistributeSelectPackFlag, + machine.StepSort++, machine.SwapOrder.Sn); + } }, () => { machine.LedTool?.WriteProgramContent(InfoEnum.SwapInfo.ErrDistributeSelectPack.GetLed()); }); } } \ No newline at end of file diff --git a/Service/Execute/Step/CarPrepareState.cs b/Service/Execute/Step/CarPrepareState.cs index de0d463..4e4fa3b 100644 --- a/Service/Execute/Step/CarPrepareState.cs +++ b/Service/Execute/Step/CarPrepareState.cs @@ -9,6 +9,7 @@ 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,7 +20,7 @@ public class CarPrepareState : IState private BinInfoRepository BinInfoRepository { get; set; } - + public SwapOrderStepService SwapOrderStepService { get; set; } private SwapAmtOrderRepository AmtOrderRepository { get; set; } private SwapOrderBatteryRepository SwapOrderBatteryRepository { get; set; } @@ -117,6 +118,9 @@ public class CarPrepareState : IState CloudApi.SendStateLog(machine.SwapOrder, machine.BusinessSwappingForCloudState); //清除下发的指令,等待新的指令 CloudApi.ClearCarCanStartInfo(); + + SwapOrderStepService.InsertSwapStepForSwapMain(InfoEnum.BusinessSwappingStep.CarInPositionFlag, + machine.StepSort++, machine.SwapOrder.Sn); } } }, () => @@ -153,6 +157,9 @@ public class CarPrepareState : IState _log.Info("cloud check vehicle done"); machine.CloudVelCheckFlag = true; machine.LedTool.WriteProgramContent("换电准备中:云平台车辆验证完成"); + + SwapOrderStepService.InsertSwapStepForSwapMain(InfoEnum.BusinessSwappingStep.CloudVelCheckFlag, + machine.StepSort++, machine.SwapOrder.Sn); } } else diff --git a/Service/Execute/Step/DoSwappingState.cs b/Service/Execute/Step/DoSwappingState.cs index ab1d626..50ed76b 100644 --- a/Service/Execute/Step/DoSwappingState.cs +++ b/Service/Execute/Step/DoSwappingState.cs @@ -5,6 +5,7 @@ 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; @@ -13,6 +14,7 @@ public class DoSwappingState : IState { private readonly ILog _log = LogManager.GetLogger(typeof(DoSwappingState)); private SwapOrderRepository SwapOrderRepository { get; set; } + public SwapOrderStepService SwapOrderStepService { get; set; } public StateResult Handle(SwappingStateMachine machine) { @@ -22,6 +24,7 @@ public class DoSwappingState : IState _log.Info($"BusinessSwappingForCloudState={machine.BusinessSwappingForCloudState}"); CloudApi.SendStateLog(machine.SwapOrder, InfoEnum.BusinessSwappingForCloudState.BeginSwap); + //再次读锁止状态,防止plc需要挪车 InvokeStatus carInPosition2 = CarInPosition2(machine); if (carInPosition2 != InvokeStatus.Done) @@ -29,6 +32,7 @@ public class DoSwappingState : IState return SwappingStateMachine.ReturnWithInvokeErr(carInPosition2, ExceptionReason.None); } + //下发启动换电 InvokeStatus startSwapping = StartSwapping(machine); if (startSwapping != InvokeStatus.Done) @@ -106,6 +110,8 @@ public class DoSwappingState : IState SwapOrderRepository.Update(machine.SwapOrder); machine.SwapStatus = 0; machine.StartSwappingFlag = true; + SwapOrderStepService.InsertSwapStepForSwapMain(InfoEnum.BusinessSwappingStep.StartSwappingFlag, + machine.StepSort++, machine.SwapOrder.Sn); } } }, () => { }); @@ -129,6 +135,12 @@ public class DoSwappingState : IState SoundTool.PlayOneSound((int)InfoEnum.SwapInfo.InfoUnPack); machine.UnOldBatteryFlag = PlcApi.ReadPlcTaskStatus() == 1002; + + if (machine.UnOldBatteryFlag) + { + SwapOrderStepService.InsertSwapStepForSwapMain(InfoEnum.BusinessSwappingStep.UnOldBatteryFlag, + machine.StepSort++, machine.SwapOrder.Sn); + } }, () => { }); } @@ -141,6 +153,12 @@ public class DoSwappingState : IState SoundTool.PlayOneSound((int)InfoEnum.SwapInfo.InfoOldBatteryCarryIn); machine.StorageOldBatteryFlag = PlcApi.ReadPlcTaskStatus() == 1003; + + if (machine.StorageOldBatteryFlag) + { + SwapOrderStepService.InsertSwapStepForSwapMain(InfoEnum.BusinessSwappingStep.StorageOldBatteryFlag, + machine.StepSort++, machine.SwapOrder.Sn); + } }, () => { }); } @@ -153,6 +171,11 @@ public class DoSwappingState : IState SoundTool.PlayOneSound((int)InfoEnum.SwapInfo.InfoNewBatteryCarryOut); machine.OutNewBatteryFlag = PlcApi.ReadPlcTaskStatus() == 1004; + if (machine.OutNewBatteryFlag) + { + SwapOrderStepService.InsertSwapStepForSwapMain(InfoEnum.BusinessSwappingStep.OutNewBatteryFlag, + machine.StepSort++, machine.SwapOrder.Sn); + } }, () => { }); } @@ -166,6 +189,12 @@ public class DoSwappingState : IState SoundTool.PlayOneSound((int)InfoEnum.SwapInfo.InfoPack); machine.InstallNewBatteryFlag = PlcApi.ReadPlcTaskStatus() == 1005; + + if (machine.InstallNewBatteryFlag) + { + SwapOrderStepService.InsertSwapStepForSwapMain(InfoEnum.BusinessSwappingStep.InstallNewBatteryFlag, + machine.StepSort++, machine.SwapOrder.Sn); + } }, () => { }); } @@ -181,10 +210,13 @@ public class DoSwappingState : IState machine.FinishNewBatteryFlag = true; machine.BusinessSwappingForCloudState = InfoEnum.BusinessSwappingForCloudState.SwapFinish; - CloudApi.SendStateLog(machine.SwapOrder,machine.BusinessSwappingForCloudState); + CloudApi.SendStateLog(machine.SwapOrder, machine.BusinessSwappingForCloudState); machine.BusinessSwappingStateUpdateTime = DateTime.Now; //上报云平台换电完成 machine.SwapStatus = 1; + + 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 88e8a1e..575f15d 100644 --- a/Service/Execute/Step/StationReadyState.cs +++ b/Service/Execute/Step/StationReadyState.cs @@ -12,6 +12,7 @@ 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; @@ -23,6 +24,8 @@ public class StationReadyState : IState public SwapOrderRepository SwapOrderRepository { get; set; } + + public SwapOrderStepService SwapOrderStepService { get; set; } public StateResult Handle(SwappingStateMachine machine) { @@ -197,8 +200,15 @@ public class StationReadyState : IState machine.BusinessSwappingStateUpdateTime = DateTime.Now; _log.Info($"BusinessSwappingForCloudState={machine.BusinessSwappingForCloudState}"); + //新增换电订单 machine.SwapOrder = SaveOrder(BuildOrder(machine.RfidReadModel)); - + //新增小步 + SwapOrderStepService.InsertSwapStepForSwapMain(InfoEnum.BusinessSwappingStep.Idel, + machine.StepSort++, machine.SwapOrder.Sn); + SwapOrderStepService.InsertSwapStepForSwapMain(InfoEnum.BusinessSwappingStep.RadarInFlag, + machine.StepSort++, machine.SwapOrder.Sn); + SwapOrderStepService.InsertSwapStepForSwapMain(InfoEnum.BusinessSwappingStep.RfidReadFlag, + machine.StepSort++, machine.SwapOrder.Sn); RfidApi.StopRead(); _log.Info("stop read rfid"); diff --git a/Service/Execute/Step/SwapCanStartState.cs b/Service/Execute/Step/SwapCanStartState.cs index 2d653c2..b0a1bc9 100644 --- a/Service/Execute/Step/SwapCanStartState.cs +++ b/Service/Execute/Step/SwapCanStartState.cs @@ -8,6 +8,7 @@ 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; @@ -19,6 +20,7 @@ public class SwapCanStartState : IState { private readonly ILog _log = LogManager.GetLogger(typeof(SwapCanStartState)); + public SwapOrderStepService SwapOrderStepService { get; set; } private SwapOrderRepository SwapOrderRepository { get; set; } public StateResult Handle(SwappingStateMachine machine) @@ -65,6 +67,9 @@ public class SwapCanStartState : IState machine.SwapOrder.CloudSn = carCanStart.on; SwapOrderRepository.Update(machine.SwapOrder.CloudSn); machine.CloudCarCanStartFlag = true; + + 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 6e2d8bd..40ae2d1 100644 --- a/Service/Execute/Step/SwapDoneState.cs +++ b/Service/Execute/Step/SwapDoneState.cs @@ -5,6 +5,7 @@ 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; @@ -12,7 +13,7 @@ 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 ILog _log = LogManager.GetLogger(typeof(SwapDoneState)); @@ -89,6 +90,10 @@ public class SwapDoneState : IState ? (int)InfoEnum.SwapInfo.InfoCarLeave : (int)InfoEnum.SwapInfo.ErrInfoCarLeave); machine.VelLockFlag = true; + + + SwapOrderStepService.InsertSwapStepForSwapMain(InfoEnum.BusinessSwappingStep.VelLockFlag, + machine.StepSort++, machine.SwapOrder.Sn); } } } @@ -134,6 +139,12 @@ public class SwapDoneState : IState } machine.RadarOutFlag = true; + + SwapOrderStepService.InsertSwapStepForSwapMain( + machine.SwapStatus == (int)InfoEnum.SwapOrderResult.Success + ? InfoEnum.BusinessSwappingStep.RadarOutFlag + : InfoEnum.BusinessSwappingStep.RadarOutFailFlag, + machine.StepSort++, machine.SwapOrder.Sn); } } }); diff --git a/Service/Execute/SwappingStateMachine.cs b/Service/Execute/SwappingStateMachine.cs index 9ad13a1..3551c49 100644 --- a/Service/Execute/SwappingStateMachine.cs +++ b/Service/Execute/SwappingStateMachine.cs @@ -39,6 +39,7 @@ public class SwappingStateMachine : IDisposable //换电实时状态 0:开始 1:成功 2:失败 public int? SwapStatus = null; public string SwapFailReason = ""; + public int StepSort = 0; public RfidReadModel? RfidReadModel = null; public TboxCarInfoModel? BoxCarInfoModel = null; @@ -245,6 +246,8 @@ public class SwappingStateMachine : IDisposable SwapOrder = null; SwapOrderBatteryInfo = null; + StepSort = 0; + } private void ResetStep() diff --git a/Service/Station/SwapOrderStepService.cs b/Service/Station/SwapOrderStepService.cs index 9459d7d..28d6575 100644 --- a/Service/Station/SwapOrderStepService.cs +++ b/Service/Station/SwapOrderStepService.cs @@ -6,6 +6,8 @@ using HybirdFrameworkCore.Entity; using Repository.Station; using SqlSugar; using System.Linq.Expressions; +using Entity.Constant; +using Service.Execute.Enum; namespace Service.Station; @@ -13,6 +15,7 @@ namespace Service.Station; public class SwapOrderStepService : BaseServices { SwapOrderStepRepository _swapOrderStepRepository; + public SwapOrderStepService(SwapOrderStepRepository dal) { _swapOrderStepRepository = dal; @@ -21,43 +24,70 @@ public class SwapOrderStepService : BaseServices /// - /// ѯ粽Ϣҳ + /// ����������ѯ���粽����Ϣ��ҳ /// /// /// public PageResult QueryEqmFaultInfo(QuerySwapOrderStepReq swapOrderStep) { - - //һյıʽ + //����һ���յı��ʽ�� Expression> where = null; - //// ʽ + //// ����������ʽ ParameterExpression parameter = Expression.Parameter(typeof(SwapOrderStep), "u"); - if (swapOrderStep.Id!=0) + if (swapOrderStep.Id != 0) { Expression> condition1Expr = u => u.Id == swapOrderStep.Id; where = condition1Expr; } + + if (swapOrderStep.Step !=null) { Expression> condition2Expr = u => u.Step == swapOrderStep.Step; - where = where == null ? condition2Expr : Expression.Lambda>(Expression.AndAlso(where.Body, condition2Expr.Body), parameter); + where = where == null + ? condition2Expr + : Expression.Lambda>(Expression.AndAlso(where.Body, condition2Expr.Body), + parameter); } if (!string.IsNullOrEmpty(swapOrderStep.SwapOrderSn)) { Expression> condition2Expr = u => u.SwapOrderSn == swapOrderStep.SwapOrderSn; - where = where == null ? condition2Expr : Expression.Lambda>(Expression.AndAlso(where.Body, condition2Expr.Body), parameter); + where = where == null + ? condition2Expr + : Expression.Lambda>(Expression.AndAlso(where.Body, condition2Expr.Body), + parameter); } - // ѯ + + // ������ѯ���� if (!string.IsNullOrEmpty(swapOrderStep.StepName)) { Expression> condition2Expr = u => u.StepName == swapOrderStep.StepName; - where = where == null ? condition2Expr : Expression.Lambda>(Expression.AndAlso(where.Body, condition2Expr.Body), parameter); + where = where == null + ? condition2Expr + : Expression.Lambda>(Expression.AndAlso(where.Body, condition2Expr.Body), + parameter); } - //ѯ - return PageResult.ConvertPage(_swapOrderStepRepository.QueryIPageByCause(swapOrderStep, where)); + + //��ѯ + return PageResult.ConvertPage( + _swapOrderStepRepository.QueryIPageByCause(swapOrderStep, where)); + } + /// + /// 换电小步新增---换电主流程 + /// + public void InsertSwapStepForSwapMain(InfoEnum.BusinessSwappingStep step, int sort, String swapOrderSn) + { + SwapOrderStep swapOrderStep = new () + { + StepName = BaseEnumExtensions.GetNameByEnum(step), + Step = (int)step, + Sort = sort, + SwapOrderSn = swapOrderSn, + }; + _swapOrderStepRepository.Insert(swapOrderStep); } } \ No newline at end of file