换电流程增加小步状态存储

master
lxw 6 months ago
parent 1e48495e41
commit 4715153df9

@ -64,5 +64,12 @@ namespace Entity.Api.Resp
/// </summary>
public DateTime? UpdatedTime {get;set;}
/// <summary>
/// Desc:排序
/// Default:
/// Nullable:True
/// </summary>
public int Sort { get; set; }
}
}

@ -27,4 +27,9 @@ public class BaseEnumExtensions
{
return GetDescription((T)Enum.ToObject(typeof(T), code));
}
public static string GetNameByEnum<T>(Enum value) where T : Enum
{
return Enum.GetName(typeof(T), value);
}
}

@ -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
///<summary>
///换电步序表
///</summary>
[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
/// </summary>
[SugarColumn(ColumnName = "created_by")]
public string ?CreatedBy { get; set; }
public string? CreatedBy { get; set; }
/// <summary>
/// Desc:创建时间
@ -61,7 +58,7 @@ namespace Entity.DbModel.Station
/// Nullable:True
/// </summary>
[SugarColumn(ColumnName = "updated_by")]
public string ?UpdatedBy { get; set; }
public string? UpdatedBy { get; set; }
/// <summary>
/// Desc:更新时间
@ -71,5 +68,13 @@ namespace Entity.DbModel.Station
[SugarColumn(ColumnName = "updated_time")]
public DateTime? UpdatedTime { get; set; }
/// <summary>
/// Desc:排序
/// Default:
/// Nullable:True
/// </summary>
[SugarColumn(ColumnName = "sort")]
public int Sort { get; set; }
}
}

@ -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,
}

@ -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()); });
}
}

@ -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

@ -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);
}
}, () => { });
}

@ -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;
@ -24,6 +25,8 @@ public class StationReadyState : IState
public SwapOrderRepository SwapOrderRepository { get; set; }
public SwapOrderStepService SwapOrderStepService { get; set; }
public StateResult Handle(SwappingStateMachine machine)
{
_log.Info($"'goto stationReady");
@ -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");

@ -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
{

@ -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);
}
}
});

@ -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()

@ -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<SwapOrderStep>
{
SwapOrderStepRepository _swapOrderStepRepository;
public SwapOrderStepService(SwapOrderStepRepository dal)
{
_swapOrderStepRepository = dal;
@ -21,43 +24,70 @@ public class SwapOrderStepService : BaseServices<SwapOrderStep>
/// <summary>
/// 根据条件查询换电步序信息分页
/// <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѯ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD><EFBFBD>ҳ
/// </summary>
/// <param name="swapOrderStep"></param>
/// <returns></returns>
public PageResult<SwapOrderStepResp> QueryEqmFaultInfo(QuerySwapOrderStepReq swapOrderStep)
{
//创建一个空的表达式树
//<2F><><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD>յı<D5B5><C4B1>ʽ<EFBFBD><CABD>
Expression<Func<SwapOrderStep, bool>> where = null;
//// 定义参数表达式
//// <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʽ
ParameterExpression parameter = Expression.Parameter(typeof(SwapOrderStep), "u");
if (swapOrderStep.Id!=0)
if (swapOrderStep.Id != 0)
{
Expression<Func<SwapOrderStep, bool>> condition1Expr = u => u.Id == swapOrderStep.Id;
where = condition1Expr;
}
if (swapOrderStep.Step !=null)
{
Expression<Func<SwapOrderStep, bool>> condition2Expr = u => u.Step == swapOrderStep.Step;
where = where == null ? condition2Expr : Expression.Lambda<Func<SwapOrderStep, bool>>(Expression.AndAlso(where.Body, condition2Expr.Body), parameter);
where = where == null
? condition2Expr
: Expression.Lambda<Func<SwapOrderStep, bool>>(Expression.AndAlso(where.Body, condition2Expr.Body),
parameter);
}
if (!string.IsNullOrEmpty(swapOrderStep.SwapOrderSn))
{
Expression<Func<SwapOrderStep, bool>> condition2Expr = u => u.SwapOrderSn == swapOrderStep.SwapOrderSn;
where = where == null ? condition2Expr : Expression.Lambda<Func<SwapOrderStep, bool>>(Expression.AndAlso(where.Body, condition2Expr.Body), parameter);
where = where == null
? condition2Expr
: Expression.Lambda<Func<SwapOrderStep, bool>>(Expression.AndAlso(where.Body, condition2Expr.Body),
parameter);
}
// 构建查询条件
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѯ<EFBFBD><D1AF><EFBFBD><EFBFBD>
if (!string.IsNullOrEmpty(swapOrderStep.StepName))
{
Expression<Func<SwapOrderStep, bool>> condition2Expr = u => u.StepName == swapOrderStep.StepName;
where = where == null ? condition2Expr : Expression.Lambda<Func<SwapOrderStep, bool>>(Expression.AndAlso(where.Body, condition2Expr.Body), parameter);
where = where == null
? condition2Expr
: Expression.Lambda<Func<SwapOrderStep, bool>>(Expression.AndAlso(where.Body, condition2Expr.Body),
parameter);
}
//查询
return PageResult<SwapOrderStepResp>.ConvertPage(_swapOrderStepRepository.QueryIPageByCause(swapOrderStep, where));
//<2F><>ѯ
return PageResult<SwapOrderStepResp>.ConvertPage(
_swapOrderStepRepository.QueryIPageByCause(swapOrderStep, where));
}
/// <summary>
/// 换电小步新增---换电主流程
/// </summary>
public void InsertSwapStepForSwapMain(InfoEnum.BusinessSwappingStep step, int sort, String swapOrderSn)
{
SwapOrderStep swapOrderStep = new ()
{
StepName = BaseEnumExtensions.GetNameByEnum<InfoEnum.BusinessSwappingStep>(step),
Step = (int)step,
Sort = sort,
SwapOrderSn = swapOrderSn,
};
_swapOrderStepRepository.Insert(swapOrderStep);
}
}
Loading…
Cancel
Save