提出选包,将枚举挪到entity .换电站reslove Autofac bean

master
lxw 6 months ago
parent de9d5ae6fc
commit 3a8de78a25

@ -1,8 +1,8 @@
using System.Reflection; using System.Reflection;
namespace Swapping.Business.Tech; namespace Entity.Attr;
public class InfoAttribute : Attribute public class InfoAttribute : System.Attribute
{ {
private string _Led; private string _Led;
private string _Sound; private string _Sound;
@ -32,7 +32,7 @@ public static class InfoExtend
FieldInfo? fieldInfo = type.GetField(value.ToString()); FieldInfo? fieldInfo = type.GetField(value.ToString());
if (fieldInfo != null && fieldInfo.IsDefined(typeof(InfoAttribute), true)) if (fieldInfo != null && fieldInfo.IsDefined(typeof(InfoAttribute), true))
{ {
Attribute? attribute = fieldInfo.GetCustomAttribute(typeof(InfoAttribute)); System.Attribute? attribute = fieldInfo.GetCustomAttribute(typeof(InfoAttribute));
if (attribute != null) if (attribute != null)
{ {
return ((InfoAttribute)attribute).GetLed(); return ((InfoAttribute)attribute).GetLed();
@ -48,7 +48,7 @@ public static class InfoExtend
FieldInfo? fieldInfo = type.GetField(value.ToString()); FieldInfo? fieldInfo = type.GetField(value.ToString());
if (fieldInfo != null && fieldInfo.IsDefined(typeof(InfoAttribute), true)) if (fieldInfo != null && fieldInfo.IsDefined(typeof(InfoAttribute), true))
{ {
Attribute? attribute = fieldInfo.GetCustomAttribute(typeof(InfoAttribute)); System.Attribute? attribute = fieldInfo.GetCustomAttribute(typeof(InfoAttribute));
if (attribute != null) if (attribute != null)
{ {
return ((InfoAttribute)attribute).GetSound(); return ((InfoAttribute)attribute).GetSound();

@ -1,8 +1,8 @@
using System.Reflection; using System.Reflection;
namespace Service.Execute.Tech; namespace Entity.Attr;
public class RemarkAttribute : Attribute public class RemarkAttribute : System.Attribute
{ {
private string _Remark; private string _Remark;
@ -25,7 +25,7 @@ public static class RemarkExtend
FieldInfo? fieldInfo = type.GetField(value.ToString()); FieldInfo? fieldInfo = type.GetField(value.ToString());
if (fieldInfo != null && fieldInfo.IsDefined(typeof(RemarkAttribute), true)) if (fieldInfo != null && fieldInfo.IsDefined(typeof(RemarkAttribute), true))
{ {
Attribute? attribute = fieldInfo.GetCustomAttribute(typeof(RemarkAttribute)); System.Attribute? attribute = fieldInfo.GetCustomAttribute(typeof(RemarkAttribute));
if (attribute != null) if (attribute != null)
{ {
return ((RemarkAttribute)attribute).GetRemark(); return ((RemarkAttribute)attribute).GetRemark();

@ -1,7 +1,6 @@
using Service.Execute.Tech; using Entity.Attr;
using Swapping.Business.Tech;
namespace Service.Execute.Enum; namespace Entity.Constant;
public class InfoEnum public class InfoEnum
{ {

@ -40,7 +40,7 @@ namespace Entity.DbModel.Station
public string BatteryType {get;set;} public string BatteryType {get;set;}
/// <summary> /// <summary>
/// Desc:车辆vin码 /// Desc:车牌号
/// Default: /// Default:
/// Nullable:True /// Nullable:True
/// </summary> /// </summary>
@ -151,10 +151,6 @@ namespace Entity.DbModel.Station
[SugarColumn(ColumnName="updated_time")] [SugarColumn(ColumnName="updated_time")]
public DateTime? UpdatedTime {get;set;} public DateTime? UpdatedTime {get;set;}
/// <summary>
/// 车牌
/// </summary>
public string VehicleNo { get; set; }
} }
} }

@ -0,0 +1,16 @@
using Entity.Constant;
using Entity.DbModel.Station;
namespace Entity.Dto;
/// <summary>
/// 选包dto
/// </summary>
public class SelectPackDto
{
public bool SuccessFlag { get; set; }
public InfoEnum.SelectBinStatusInfo Info { get; set; }
public BinInfo BinInfo { get; set; }
}

@ -1,14 +1,67 @@
using Entity.Constant;
using Entity.DbModel.Station; using Entity.DbModel.Station;
using Entity.Dto;
using HybirdFrameworkCore.Autofac.Attribute; using HybirdFrameworkCore.Autofac.Attribute;
using SqlSugar; using SqlSugar;
namespace Repository.Station; namespace Repository.Station;
[Scope("SingleInstance")] [Scope("SingleInstance")]
public class BinInfoRepository:BaseRepository<BinInfo> public class BinInfoRepository : BaseRepository<BinInfo>
{ {
public BinInfoRepository(ISqlSugarClient sqlSugar) : base(sqlSugar) public BinInfoRepository(ISqlSugarClient sqlSugar) : base(sqlSugar)
{ {
} }
/// <summary>
/// 选包
/// </summary>
/// <param name="swapSoc"> StaticStationInfo.SwapSoc </param>
/// <param name="swapFinishChargeTime">StaticStationInfo.SwapFinishChargeTime</param>
/// <returns></returns>
public SelectPackDto SelectPack(string swapSoc, string swapFinishChargeTime)
{
SelectPackDto selectPackDto = new()
{
SuccessFlag = false,
};
List<BinInfo> 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;
}
} }

@ -1,11 +1,11 @@
using Entity.DbModel.Station; using Entity.Constant;
using Entity.DbModel.Station;
using HybirdFrameworkCore.Autofac.Attribute; using HybirdFrameworkCore.Autofac.Attribute;
using Newtonsoft.Json; using Newtonsoft.Json;
using Repository.Station; using Repository.Station;
using Service.Cloud.Common; using Service.Cloud.Common;
using Service.Cloud.Msg.Cloud.Req; using Service.Cloud.Msg.Cloud.Req;
using Service.Cloud.Msg.Host.Resp; using Service.Cloud.Msg.Host.Resp;
using Service.Execute.Enum;
using Service.Init; using Service.Init;
namespace Service.Cloud.Handler; namespace Service.Cloud.Handler;

@ -1,8 +1,8 @@
using Entity.Constant;
using Entity.DbModel.Station; using Entity.DbModel.Station;
using log4net; using log4net;
using Service.Cloud.Client; using Service.Cloud.Client;
using Service.Cloud.Msg.Cloud.Req; using Service.Cloud.Msg.Cloud.Req;
using Service.Execute.Enum;
using Service.Execute.Model; using Service.Execute.Model;
namespace Service.Execute.Api; namespace Service.Execute.Api;

@ -1,6 +1,6 @@
using Entity.Constant;
using Entity.DbModel.Station; using Entity.DbModel.Station;
using NewLife.Common; using NewLife.Common;
using Service.Execute.Enum;
namespace Service.Execute.Model; namespace Service.Execute.Model;

@ -1,14 +1,16 @@
using log4net; using Autofac;
using Entity.Constant;
using HybirdFrameworkCore.Autofac;
using log4net;
using Repository.Station; using Repository.Station;
using Service.Execute.Enum;
namespace Service.Execute.Step; namespace Service.Execute.Step;
public class CancelState : IState public class CancelState : IState
{ {
private SwapOrderRepository SwapOrderRepository { get; set; } private readonly SwapOrderRepository _swapOrderRepository= AppInfo.Container.Resolve<SwapOrderRepository>();
private SwapAmtOrderRepository SwapAmtOrderRepository { get; set; } private readonly SwapAmtOrderRepository _swapAmtOrderRepository = AppInfo.Container.Resolve<SwapAmtOrderRepository>();
private static readonly ILog _log = LogManager.GetLogger(typeof(CancelState)); private static readonly ILog _log = LogManager.GetLogger(typeof(CancelState));
public StateResult Handle(SwappingStateMachine machine) public StateResult Handle(SwappingStateMachine machine)
@ -18,13 +20,13 @@ public class CancelState : IState
if (machine.SwapOrderBatteryInfo.swapAmtOrder != null) if (machine.SwapOrderBatteryInfo.swapAmtOrder != null)
{ {
machine.SwapOrderBatteryInfo.swapAmtOrder.Status = (byte)InfoEnum.AmtOrderStatus.SwapFail; machine.SwapOrderBatteryInfo.swapAmtOrder.Status = (byte)InfoEnum.AmtOrderStatus.SwapFail;
SwapAmtOrderRepository.Update(machine.SwapOrderBatteryInfo.swapAmtOrder); _swapAmtOrderRepository.Update(machine.SwapOrderBatteryInfo.swapAmtOrder);
} }
if (machine.SwapOrder != null) if (machine.SwapOrder != null)
{ {
machine.SwapOrder.SwapResult = (byte)InfoEnum.SwapOrderResult.Fail; machine.SwapOrder.SwapResult = (byte)InfoEnum.SwapOrderResult.Fail;
SwapOrderRepository.Update(machine.SwapOrder); _swapOrderRepository.Update(machine.SwapOrder);
} }
machine.Reset(); machine.Reset();

@ -1,11 +1,11 @@
using log4net; using Entity.Attr;
using Entity.Constant;
using log4net;
using Service.Execute.Api; using Service.Execute.Api;
using Service.Execute.Enum;
using Service.Execute.Model; using Service.Execute.Model;
using Service.Execute.StaticTools; using Service.Execute.StaticTools;
using Service.Execute.SwapException; using Service.Execute.SwapException;
using Service.Station; using Service.Station;
using Swapping.Business.Tech;
namespace Service.Execute.Step; namespace Service.Execute.Step;

@ -1,16 +1,18 @@
using AutoMapper; using Autofac;
using AutoMapper;
using Entity.Attr;
using Entity.Constant; using Entity.Constant;
using Entity.DbModel.Station; using Entity.DbModel.Station;
using Entity.Dto;
using HybirdFrameworkCore.Autofac;
using log4net; using log4net;
using Repository.Station; using Repository.Station;
using Service.Execute.Api; using Service.Execute.Api;
using Service.Execute.Enum;
using Service.Execute.Model; using Service.Execute.Model;
using Service.Execute.StaticTools; using Service.Execute.StaticTools;
using Service.Execute.SwapException; using Service.Execute.SwapException;
using Service.Init; using Service.Init;
using Service.Station; using Service.Station;
using Swapping.Business.Tech;
namespace Service.Execute.Step; namespace Service.Execute.Step;
@ -19,11 +21,11 @@ public class CarPrepareState : IState
private readonly ILog _log = LogManager.GetLogger(typeof(CarPrepareState)); private readonly ILog _log = LogManager.GetLogger(typeof(CarPrepareState));
private BinInfoRepository BinInfoRepository { get; set; } private readonly BinInfoRepository _binInfoRepository = AppInfo.Container.Resolve<BinInfoRepository>();
public SwapOrderStepService SwapOrderStepService { get; set; } private readonly SwapOrderStepService _swapOrderStepService = AppInfo.Container.Resolve<SwapOrderStepService>();
private SwapAmtOrderRepository AmtOrderRepository { get; set; } private readonly SwapAmtOrderRepository _amtOrderRepository = AppInfo.Container.Resolve<SwapAmtOrderRepository>();
private SwapOrderBatteryRepository SwapOrderBatteryRepository { get; set; } private readonly SwapOrderBatteryRepository _swapOrderBatteryRepository = AppInfo.Container.Resolve<SwapOrderBatteryRepository>();
public StateResult Handle(SwappingStateMachine machine) public StateResult Handle(SwappingStateMachine machine)
{ {
@ -119,7 +121,7 @@ public class CarPrepareState : IState
//清除下发的指令,等待新的指令 //清除下发的指令,等待新的指令
CloudApi.ClearCarCanStartInfo(); CloudApi.ClearCarCanStartInfo();
SwapOrderStepService.InsertSwapStepForSwapMain(InfoEnum.BusinessSwappingStep.CarInPositionFlag, _swapOrderStepService.InsertSwapStepForSwapMain(InfoEnum.BusinessSwappingStep.CarInPositionFlag,
machine.StepSort++, machine.SwapOrder.Sn); machine.StepSort++, machine.SwapOrder.Sn);
} }
} }
@ -158,7 +160,7 @@ public class CarPrepareState : IState
machine.CloudVelCheckFlag = true; machine.CloudVelCheckFlag = true;
machine.LedTool.WriteProgramContent("换电准备中:云平台车辆验证完成"); machine.LedTool.WriteProgramContent("换电准备中:云平台车辆验证完成");
SwapOrderStepService.InsertSwapStepForSwapMain(InfoEnum.BusinessSwappingStep.CloudVelCheckFlag, _swapOrderStepService.InsertSwapStepForSwapMain(InfoEnum.BusinessSwappingStep.CloudVelCheckFlag,
machine.StepSort++, machine.SwapOrder.Sn); machine.StepSort++, machine.SwapOrder.Sn);
} }
} }
@ -266,8 +268,8 @@ public class CarPrepareState : IState
public InvokeStatus SelectPack(SwappingStateMachine machine) public InvokeStatus SelectPack(SwappingStateMachine machine)
{ {
SwapAmtOrder? swapAmtOrder = SwapAmtOrder? swapAmtOrder =
AmtOrderRepository.QueryByClause(i => _amtOrderRepository.QueryByClause(i =>
i.Status == (int)InfoEnum.AmtOrderStatus.Success && i.VehicleNo.Equals(machine.BoxCarInfoModel.CarNo)); i.Status == (int)InfoEnum.AmtOrderStatus.Success && i.CarNo.Equals(machine.BoxCarInfoModel.CarNo));
return Invoker.Invoke("selectPack", 500, 20, machine.IsCanceled, return Invoker.Invoke("selectPack", 500, 20, machine.IsCanceled,
@ -315,7 +317,7 @@ public class CarPrepareState : IState
UpBatteryBinNo = int.Parse(UpBin.No), UpBatteryBinNo = int.Parse(UpBin.No),
DownBatteryBinNo = int.Parse(InBin.No), DownBatteryBinNo = int.Parse(InBin.No),
}; };
SwapOrderBatteryRepository.Insert(swapOrderBattery); _swapOrderBatteryRepository.Insert(swapOrderBattery);
} }
/// <summary> /// <summary>
@ -330,7 +332,7 @@ public class CarPrepareState : IState
BinInfo dbBinInfo = mapperBinInfo.Map<BinInfo>(orderBatteryInfo.UpBinInfo); BinInfo dbBinInfo = mapperBinInfo.Map<BinInfo>(orderBatteryInfo.UpBinInfo);
dbBinInfo.AmtLock = (int)InfoEnum.AmtBatLockStatus.Lock; dbBinInfo.AmtLock = (int)InfoEnum.AmtBatLockStatus.Lock;
BinInfoRepository.Update(dbBinInfo); _binInfoRepository.Update(dbBinInfo);
if (!orderBatteryInfo.isAmt) if (!orderBatteryInfo.isAmt)
{ {
return; return;
@ -341,7 +343,7 @@ public class CarPrepareState : IState
IMapper mapperAmt = configAmt.CreateMapper(); IMapper mapperAmt = configAmt.CreateMapper();
SwapAmtOrder swapAmtOrder = mapperAmt.Map<SwapAmtOrder>(orderBatteryInfo.swapAmtOrder); SwapAmtOrder swapAmtOrder = mapperAmt.Map<SwapAmtOrder>(orderBatteryInfo.swapAmtOrder);
swapAmtOrder.Status = (int)InfoEnum.AmtOrderStatus.Swapping; swapAmtOrder.Status = (int)InfoEnum.AmtOrderStatus.Swapping;
AmtOrderRepository.Update(swapAmtOrder); _amtOrderRepository.Update(swapAmtOrder);
} }
/// 1.仓位状态:启动 /// 1.仓位状态:启动
@ -377,7 +379,7 @@ public class CarPrepareState : IState
SwapOrderBatteryInfo orderBatteryInfo = new SwapOrderBatteryInfo(); SwapOrderBatteryInfo orderBatteryInfo = new SwapOrderBatteryInfo();
orderBatteryInfo.swapAmtOrder = swapAmtOrder; orderBatteryInfo.swapAmtOrder = swapAmtOrder;
orderBatteryInfo.isAmt = true; 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 bool CanSwap = UpBin.Exists == 1 && UpBin.Status == 1 && UpBin.ChargeStatus == 2
&& UpBin.AmtLock == (int)InfoEnum.AmtBatLockStatus.Lock && new TimeSpan(DateTime.Now.Ticks - && UpBin.AmtLock == (int)InfoEnum.AmtBatLockStatus.Lock && new TimeSpan(DateTime.Now.Ticks -
UpBin.LastChargeFinishTime.ToDateTime() UpBin.LastChargeFinishTime.ToDateTime()
@ -402,53 +404,23 @@ public class CarPrepareState : IState
/// <param name="orderBatteryInfo"></param> /// <param name="orderBatteryInfo"></param>
private void UpBin(SwapOrderBatteryInfo orderBatteryInfo) private void UpBin(SwapOrderBatteryInfo orderBatteryInfo)
{ {
List<BinInfo> list = SelectPackDto selectPack =
BinInfoRepository.QueryListByClause(i => _binInfoRepository.SelectPack(StaticStationInfo.SwapSoc, StaticStationInfo.SwapFinishChargeTime);
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;
}
list = list.Where(i => i.Soc > int.Parse(StaticStationInfo.SwapSoc)).ToList(); orderBatteryInfo.UpBinInfo = selectPack.BinInfo;
if (list.Count <= 0) orderBatteryInfo.CanSwap = selectPack.Info;
{
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;
} }
/// <summary> /// <summary>
/// 放电池判断 /// 放电池判断:取出来的电池仓位能不能放
/// </summary> /// </summary>
/// <param name="orderBatteryInfo"></param> /// <param name="orderBatteryInfo"></param>
private void InBin(SwapOrderBatteryInfo orderBatteryInfo) private void InBin(SwapOrderBatteryInfo orderBatteryInfo)
{ {
List<BinInfo> list = List<BinInfo> list =
BinInfoRepository.QueryListByClause(i => _binInfoRepository.QueryListByClause(i =>
i.Exists == 1 && i.Status == 1 && i.AmtLock == (int)InfoEnum.AmtBatLockStatus.UnLock i.Status == 1 && i.AmtLock == (int)InfoEnum.AmtBatLockStatus.UnLock
&& i.Exists == 0); && i.Exists == 0);
if (list.Count <= 0) if (list.Count <= 0)
{ {
orderBatteryInfo.CanSwap = InfoEnum.SelectBinStatusInfo.LessOfEmptyBin; orderBatteryInfo.CanSwap = InfoEnum.SelectBinStatusInfo.LessOfEmptyBin;

@ -1,20 +1,22 @@
using log4net; using Autofac;
using Entity.Attr;
using Entity.Constant;
using HybirdFrameworkCore.Autofac;
using log4net;
using Repository.Station; using Repository.Station;
using Service.Execute.Api; using Service.Execute.Api;
using Service.Execute.Enum;
using Service.Execute.Model; using Service.Execute.Model;
using Service.Execute.StaticTools; using Service.Execute.StaticTools;
using Service.Execute.SwapException; using Service.Execute.SwapException;
using Service.Station; using Service.Station;
using Swapping.Business.Tech;
namespace Service.Execute.Step; namespace Service.Execute.Step;
public class DoSwappingState : IState public class DoSwappingState : IState
{ {
private readonly ILog _log = LogManager.GetLogger(typeof(DoSwappingState)); private readonly ILog _log = LogManager.GetLogger(typeof(DoSwappingState));
private SwapOrderRepository SwapOrderRepository { get; set; } private readonly SwapOrderRepository _swapOrderRepository = AppInfo.Container.Resolve<SwapOrderRepository>();
public SwapOrderStepService SwapOrderStepService { get; set; } private readonly SwapOrderStepService _swapOrderStepService = AppInfo.Container.Resolve<SwapOrderStepService>();
public StateResult Handle(SwappingStateMachine machine) public StateResult Handle(SwappingStateMachine machine)
{ {
@ -107,10 +109,10 @@ public class DoSwappingState : IState
if (startSwapping) if (startSwapping)
{ {
machine.SwapOrder.SwapBeginTime = DateTime.Now; machine.SwapOrder.SwapBeginTime = DateTime.Now;
SwapOrderRepository.Update(machine.SwapOrder); _swapOrderRepository.Update(machine.SwapOrder);
machine.SwapStatus = 0; machine.SwapStatus = 0;
machine.StartSwappingFlag = true; machine.StartSwappingFlag = true;
SwapOrderStepService.InsertSwapStepForSwapMain(InfoEnum.BusinessSwappingStep.StartSwappingFlag, _swapOrderStepService.InsertSwapStepForSwapMain(InfoEnum.BusinessSwappingStep.StartSwappingFlag,
machine.StepSort++, machine.SwapOrder.Sn); machine.StepSort++, machine.SwapOrder.Sn);
} }
} }
@ -138,7 +140,7 @@ public class DoSwappingState : IState
if (machine.UnOldBatteryFlag) if (machine.UnOldBatteryFlag)
{ {
SwapOrderStepService.InsertSwapStepForSwapMain(InfoEnum.BusinessSwappingStep.UnOldBatteryFlag, _swapOrderStepService.InsertSwapStepForSwapMain(InfoEnum.BusinessSwappingStep.UnOldBatteryFlag,
machine.StepSort++, machine.SwapOrder.Sn); machine.StepSort++, machine.SwapOrder.Sn);
} }
}, () => { }); }, () => { });
@ -156,7 +158,7 @@ public class DoSwappingState : IState
if (machine.StorageOldBatteryFlag) if (machine.StorageOldBatteryFlag)
{ {
SwapOrderStepService.InsertSwapStepForSwapMain(InfoEnum.BusinessSwappingStep.StorageOldBatteryFlag, _swapOrderStepService.InsertSwapStepForSwapMain(InfoEnum.BusinessSwappingStep.StorageOldBatteryFlag,
machine.StepSort++, machine.SwapOrder.Sn); machine.StepSort++, machine.SwapOrder.Sn);
} }
}, () => { }); }, () => { });
@ -173,7 +175,7 @@ public class DoSwappingState : IState
machine.OutNewBatteryFlag = PlcApi.ReadPlcTaskStatus() == 1004; machine.OutNewBatteryFlag = PlcApi.ReadPlcTaskStatus() == 1004;
if (machine.OutNewBatteryFlag) if (machine.OutNewBatteryFlag)
{ {
SwapOrderStepService.InsertSwapStepForSwapMain(InfoEnum.BusinessSwappingStep.OutNewBatteryFlag, _swapOrderStepService.InsertSwapStepForSwapMain(InfoEnum.BusinessSwappingStep.OutNewBatteryFlag,
machine.StepSort++, machine.SwapOrder.Sn); machine.StepSort++, machine.SwapOrder.Sn);
} }
}, () => { }); }, () => { });
@ -192,7 +194,7 @@ public class DoSwappingState : IState
if (machine.InstallNewBatteryFlag) if (machine.InstallNewBatteryFlag)
{ {
SwapOrderStepService.InsertSwapStepForSwapMain(InfoEnum.BusinessSwappingStep.InstallNewBatteryFlag, _swapOrderStepService.InsertSwapStepForSwapMain(InfoEnum.BusinessSwappingStep.InstallNewBatteryFlag,
machine.StepSort++, machine.SwapOrder.Sn); machine.StepSort++, machine.SwapOrder.Sn);
} }
}, () => { }); }, () => { });
@ -215,7 +217,7 @@ public class DoSwappingState : IState
//上报云平台换电完成 //上报云平台换电完成
machine.SwapStatus = 1; machine.SwapStatus = 1;
SwapOrderStepService.InsertSwapStepForSwapMain(InfoEnum.BusinessSwappingStep.FinishNewBatteryFlag, _swapOrderStepService.InsertSwapStepForSwapMain(InfoEnum.BusinessSwappingStep.FinishNewBatteryFlag,
machine.StepSort++, machine.SwapOrder.Sn); machine.StepSort++, machine.SwapOrder.Sn);
} }
}, () => { }); }, () => { });

@ -1,20 +1,21 @@
using System.Text; using System.Text;
using Autofac;
using Entity.Attr;
using Entity.Constant; using Entity.Constant;
using Entity.DbModel.Station; using Entity.DbModel.Station;
using HybirdFrameworkCore.Autofac;
using log4net; using log4net;
using Microsoft.OpenApi.Extensions; using Microsoft.OpenApi.Extensions;
using Microsoft.VisualBasic; using Microsoft.VisualBasic;
using Newtonsoft.Json; using Newtonsoft.Json;
using Repository.Station; using Repository.Station;
using Service.Execute.Api; using Service.Execute.Api;
using Service.Execute.Enum;
using Service.Execute.Model; using Service.Execute.Model;
using Service.Execute.StaticTools; using Service.Execute.StaticTools;
using Service.Execute.SwapException; using Service.Execute.SwapException;
using Service.Init; using Service.Init;
using Service.Station; using Service.Station;
using Swapping.Business.Common; using Swapping.Business.Common;
using Swapping.Business.Tech;
namespace Service.Execute.Step; namespace Service.Execute.Step;
@ -23,9 +24,9 @@ public class StationReadyState : IState
private readonly ILog _log = LogManager.GetLogger(typeof(StationReadyState)); private readonly ILog _log = LogManager.GetLogger(typeof(StationReadyState));
public SwapOrderRepository SwapOrderRepository { get; set; } private readonly SwapOrderRepository _swapOrderRepository = AppInfo.Container.Resolve<SwapOrderRepository>();
public SwapOrderStepService SwapOrderStepService { get; set; } private readonly SwapOrderStepService _swapOrderStepService = AppInfo.Container.Resolve<SwapOrderStepService>();
public StateResult Handle(SwappingStateMachine machine) public StateResult Handle(SwappingStateMachine machine)
{ {
@ -203,11 +204,11 @@ public class StationReadyState : IState
//新增换电订单 //新增换电订单
machine.SwapOrder = SaveOrder(BuildOrder(machine.RfidReadModel)); machine.SwapOrder = SaveOrder(BuildOrder(machine.RfidReadModel));
//新增小步 //新增小步
SwapOrderStepService.InsertSwapStepForSwapMain(InfoEnum.BusinessSwappingStep.Idel, _swapOrderStepService.InsertSwapStepForSwapMain(InfoEnum.BusinessSwappingStep.Idel,
machine.StepSort++, machine.SwapOrder.Sn); machine.StepSort++, machine.SwapOrder.Sn);
SwapOrderStepService.InsertSwapStepForSwapMain(InfoEnum.BusinessSwappingStep.RadarInFlag, _swapOrderStepService.InsertSwapStepForSwapMain(InfoEnum.BusinessSwappingStep.RadarInFlag,
machine.StepSort++, machine.SwapOrder.Sn); machine.StepSort++, machine.SwapOrder.Sn);
SwapOrderStepService.InsertSwapStepForSwapMain(InfoEnum.BusinessSwappingStep.RfidReadFlag, _swapOrderStepService.InsertSwapStepForSwapMain(InfoEnum.BusinessSwappingStep.RfidReadFlag,
machine.StepSort++, machine.SwapOrder.Sn); machine.StepSort++, machine.SwapOrder.Sn);
RfidApi.StopRead(); RfidApi.StopRead();
_log.Info("stop read rfid"); _log.Info("stop read rfid");
@ -239,7 +240,7 @@ public class StationReadyState : IState
private SwapOrder SaveOrder(SwapOrder swapOrder) private SwapOrder SaveOrder(SwapOrder swapOrder)
{ {
SwapOrderRepository.Insert(swapOrder); _swapOrderRepository.Insert(swapOrder);
return swapOrder; return swapOrder;
} }
} }

@ -1,15 +1,16 @@
using Entity.Constant; using Autofac;
using Entity.Attr;
using Entity.Constant;
using HybirdFrameworkCore.Autofac;
using log4net; using log4net;
using Repository.Station; using Repository.Station;
using Service.Cloud.Client; using Service.Cloud.Client;
using Service.Cloud.Msg.Cloud.Req; using Service.Cloud.Msg.Cloud.Req;
using Service.Execute.Api; using Service.Execute.Api;
using Service.Execute.Enum;
using Service.Execute.StaticTools; using Service.Execute.StaticTools;
using Service.Execute.SwapException; using Service.Execute.SwapException;
using Service.Init; using Service.Init;
using Service.Station; using Service.Station;
using Swapping.Business.Tech;
namespace Service.Execute.Step; namespace Service.Execute.Step;
@ -20,8 +21,8 @@ public class SwapCanStartState : IState
{ {
private readonly ILog _log = LogManager.GetLogger(typeof(SwapCanStartState)); private readonly ILog _log = LogManager.GetLogger(typeof(SwapCanStartState));
public SwapOrderStepService SwapOrderStepService { get; set; } private readonly SwapOrderStepService _swapOrderStepService = AppInfo.Container.Resolve<SwapOrderStepService>();
private SwapOrderRepository SwapOrderRepository { get; set; } private readonly SwapOrderRepository _swapOrderRepository = AppInfo.Container.Resolve<SwapOrderRepository>();
public StateResult Handle(SwappingStateMachine machine) public StateResult Handle(SwappingStateMachine machine)
{ {
@ -65,10 +66,10 @@ public class SwapCanStartState : IState
_log.Info("SwapCanStart ok"); _log.Info("SwapCanStart ok");
//更新换电订单 //更新换电订单
machine.SwapOrder.CloudSn = carCanStart.on; machine.SwapOrder.CloudSn = carCanStart.on;
SwapOrderRepository.Update(machine.SwapOrder.CloudSn); _swapOrderRepository.Update(machine.SwapOrder.CloudSn);
machine.CloudCarCanStartFlag = true; machine.CloudCarCanStartFlag = true;
SwapOrderStepService.InsertSwapStepForSwapMain(InfoEnum.BusinessSwappingStep.CloudCarCanStartFlag, _swapOrderStepService.InsertSwapStepForSwapMain(InfoEnum.BusinessSwappingStep.CloudCarCanStartFlag,
machine.StepSort++, machine.SwapOrder.Sn); machine.StepSort++, machine.SwapOrder.Sn);
} }
else else

@ -1,20 +1,22 @@
using log4net; using Autofac;
using Entity.Attr;
using Entity.Constant;
using HybirdFrameworkCore.Autofac;
using log4net;
using Repository.Station; using Repository.Station;
using Service.Execute.Api; using Service.Execute.Api;
using Service.Execute.Enum;
using Service.Execute.Model; using Service.Execute.Model;
using Service.Execute.StaticTools; using Service.Execute.StaticTools;
using Service.Execute.SwapException; using Service.Execute.SwapException;
using Service.Station; using Service.Station;
using Swapping.Business.Tech;
namespace Service.Execute.Step; namespace Service.Execute.Step;
public class SwapDoneState : IState public class SwapDoneState : IState
{ {
private SwapOrderRepository SwapOrderRepository { get; set; } private readonly SwapOrderRepository _swapOrderRepository = AppInfo.Container.Resolve<SwapOrderRepository>();
public SwapOrderStepService SwapOrderStepService { get; set; } private readonly SwapOrderStepService _swapOrderStepService = AppInfo.Container.Resolve<SwapOrderStepService>();
private SwapAmtOrderRepository SwapAmtOrderRepository { get; set; } private readonly SwapAmtOrderRepository _swapAmtOrderRepository = AppInfo.Container.Resolve<SwapAmtOrderRepository>();
private readonly ILog _log = LogManager.GetLogger(typeof(SwapDoneState)); private readonly ILog _log = LogManager.GetLogger(typeof(SwapDoneState));
@ -30,7 +32,7 @@ public class SwapDoneState : IState
machine.SwapOrder.SwapResult = machine.SwapStatus; machine.SwapOrder.SwapResult = machine.SwapStatus;
machine.SwapOrder.SwapEndTime = DateTime.Now; machine.SwapOrder.SwapEndTime = DateTime.Now;
machine.SwapOrder.FailReason = machine.SwapFailReason; machine.SwapOrder.FailReason = machine.SwapFailReason;
SwapOrderRepository.Update(machine.SwapOrder); _swapOrderRepository.Update(machine.SwapOrder);
if (machine.SwapStatus == (int)InfoEnum.SwapOrderResult.Success) if (machine.SwapStatus == (int)InfoEnum.SwapOrderResult.Success)
@ -92,7 +94,7 @@ public class SwapDoneState : IState
machine.VelLockFlag = true; machine.VelLockFlag = true;
SwapOrderStepService.InsertSwapStepForSwapMain(InfoEnum.BusinessSwappingStep.VelLockFlag, _swapOrderStepService.InsertSwapStepForSwapMain(InfoEnum.BusinessSwappingStep.VelLockFlag,
machine.StepSort++, machine.SwapOrder.Sn); machine.StepSort++, machine.SwapOrder.Sn);
} }
} }
@ -128,19 +130,19 @@ public class SwapDoneState : IState
machine.BusinessSwappingForCloudState = machine.BusinessSwappingForCloudState =
InfoEnum.BusinessSwappingForCloudState.SwapDoneWithoutVel; InfoEnum.BusinessSwappingForCloudState.SwapDoneWithoutVel;
machine.SwapOrder!.VehicleLeaveTime = DateTime.Now; machine.SwapOrder!.VehicleLeaveTime = DateTime.Now;
SwapOrderRepository.Update(machine.SwapOrder); _swapOrderRepository.Update(machine.SwapOrder);
if (machine.SwapOrderBatteryInfo!.swapAmtOrder != null) if (machine.SwapOrderBatteryInfo!.swapAmtOrder != null)
{ {
machine.SwapOrderBatteryInfo.swapAmtOrder.Status = machine.SwapOrderBatteryInfo.swapAmtOrder.Status =
machine.SwapStatus == (int)InfoEnum.SwapOrderResult.Success machine.SwapStatus == (int)InfoEnum.SwapOrderResult.Success
? (int)InfoEnum.AmtOrderStatus.SwapFinish ? (int)InfoEnum.AmtOrderStatus.SwapFinish
: (int)InfoEnum.AmtOrderStatus.SwapFail; : (int)InfoEnum.AmtOrderStatus.SwapFail;
SwapAmtOrderRepository.Update(machine.SwapOrderBatteryInfo.swapAmtOrder); _swapAmtOrderRepository.Update(machine.SwapOrderBatteryInfo.swapAmtOrder);
} }
machine.RadarOutFlag = true; machine.RadarOutFlag = true;
SwapOrderStepService.InsertSwapStepForSwapMain( _swapOrderStepService.InsertSwapStepForSwapMain(
machine.SwapStatus == (int)InfoEnum.SwapOrderResult.Success machine.SwapStatus == (int)InfoEnum.SwapOrderResult.Success
? InfoEnum.BusinessSwappingStep.RadarOutFlag ? InfoEnum.BusinessSwappingStep.RadarOutFlag
: InfoEnum.BusinessSwappingStep.RadarOutFailFlag, : InfoEnum.BusinessSwappingStep.RadarOutFailFlag,

@ -1,15 +1,16 @@
using DotNetty.Common.Utilities; using Autofac;
using DotNetty.Common.Utilities;
using Entity.Constant;
using Entity.DbModel.Station; using Entity.DbModel.Station;
using HybirdFrameworkCore.Autofac;
using log4net; using log4net;
using Newtonsoft.Json; using Newtonsoft.Json;
using Repository.Station; using Repository.Station;
using Service.Execute.Api; using Service.Execute.Api;
using Service.Execute.Enum;
using Service.Execute.Model; using Service.Execute.Model;
using Service.Execute.StaticTools; using Service.Execute.StaticTools;
using Service.Execute.Step; using Service.Execute.Step;
using Service.Execute.SwapException; using Service.Execute.SwapException;
using Service.Execute.Tech;
namespace Service.Execute; namespace Service.Execute;
@ -17,9 +18,12 @@ public class SwappingStateMachine : IDisposable
{ {
private static readonly ILog Log = LogManager.GetLogger(typeof(SwappingStateMachine)); private static readonly ILog Log = LogManager.GetLogger(typeof(SwappingStateMachine));
private static readonly SwappingStateMachine SwappingMachine = new SwappingStateMachine(); private static readonly SwappingStateMachine SwappingMachine = new SwappingStateMachine();
private BinInfoRepository BinInfoRepository { get; set; } private BinInfoRepository BinInfoRepository { get; set; }
private SwapAmtOrderRepository AmtOrderRepository { get; set; } private SwapAmtOrderRepository AmtOrderRepository { get; set; }
public bool CancelFlag { get; set; } = false; public bool CancelFlag { get; set; } = false;
public bool StopFlag { get; set; } = false; public bool StopFlag { get; set; } = false;
@ -137,6 +141,9 @@ public class SwappingStateMachine : IDisposable
_dictionary[SwappingState.Canceled] = new CancelState(); _dictionary[SwappingState.Canceled] = new CancelState();
LedTool = new LedTool(); LedTool = new LedTool();
BinInfoRepository = AppInfo.Container.Resolve<BinInfoRepository>();
AmtOrderRepository = AppInfo.Container.Resolve<SwapAmtOrderRepository>();
} }
public static SwappingStateMachine GetInstance() public static SwappingStateMachine GetInstance()

@ -39,4 +39,8 @@
<ProjectReference Include="..\Repository\Repository.csproj" /> <ProjectReference Include="..\Repository\Repository.csproj" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<Folder Include="Execute\Tech\" />
</ItemGroup>
</Project> </Project>

@ -7,7 +7,6 @@ using Repository.Station;
using SqlSugar; using SqlSugar;
using System.Linq.Expressions; using System.Linq.Expressions;
using Entity.Constant; using Entity.Constant;
using Service.Execute.Enum;
namespace Service.Station; namespace Service.Station;

@ -446,7 +446,7 @@ namespace Service.System
var typeList = GetConstAttributeList(); var typeList = GetConstAttributeList();
var type = typeList.FirstOrDefault(u => u.Name == typeName); var type = typeList.FirstOrDefault(u => u.Name == typeName);
var isEnum = type.BaseType.Name == "Enum"; var isEnum = type.BaseType.Name == "Utils";
constlist = type.GetFields()? constlist = type.GetFields()?
.Where(isEnum, u => u.FieldType.Name == typeName) .Where(isEnum, u => u.FieldType.Name == typeName)
.Select(u => new ConstResp .Select(u => new ConstResp

@ -28,7 +28,7 @@ builder.Host.ConfigureContainer<ContainerBuilder>(cb =>
ConnectionString = AppSettingsConstVars.DbSqlConnection, // 设置数据库连接字符串 ConnectionString = AppSettingsConstVars.DbSqlConnection, // 设置数据库连接字符串
DbType = AppSettingsConstVars.DbDbType == IocDbType.MySql.ToString() ? DbType.MySql : DbType.SqlServer, DbType = AppSettingsConstVars.DbDbType == IocDbType.MySql.ToString() ? DbType.MySql : DbType.SqlServer,
IsAutoCloseConnection = true, IsAutoCloseConnection = true,
InitKeyType = InitKeyType.Attribute // 如果使用实体类的属性进行主键标识,请设置为 InitKeyType.Attribute InitKeyType = InitKeyType.Attribute // 如果使用实体类的属性进行主键标识,请设置为 InitKeyType.Attr
}); });
return db; return db;
}).As<ISqlSugarClient>().SingleInstance(); }).As<ISqlSugarClient>().SingleInstance();

@ -37,7 +37,7 @@ internal static class Program
ConnectionString = AppSettingsConstVars.DbSqlConnection, // 设置数据库连接字符串 ConnectionString = AppSettingsConstVars.DbSqlConnection, // 设置数据库连接字符串
DbType = AppSettingsConstVars.DbDbType == IocDbType.MySql.ToString() ? DbType.MySql : DbType.SqlServer, DbType = AppSettingsConstVars.DbDbType == IocDbType.MySql.ToString() ? DbType.MySql : DbType.SqlServer,
IsAutoCloseConnection = true, IsAutoCloseConnection = true,
InitKeyType = InitKeyType.Attribute // 如果使用实体类的属性进行主键标识,请设置为 InitKeyType.Attribute InitKeyType = InitKeyType.Attribute // 如果使用实体类的属性进行主键标识,请设置为 InitKeyType.Attr
}); });
return db; return db;
}).As<ISqlSugarClient>().InstancePerLifetimeScope(); }).As<ISqlSugarClient>().InstancePerLifetimeScope();

@ -25,7 +25,7 @@ public partial class App : Application
? DbType.MySql ? DbType.MySql
: DbType.SqlServer, : DbType.SqlServer,
IsAutoCloseConnection = true, IsAutoCloseConnection = true,
InitKeyType = InitKeyType.Attribute // 如果使用实体类的属性进行主键标识,请设置为 InitKeyType.Attribute InitKeyType = InitKeyType.Attribute // 如果使用实体类的属性进行主键标识,请设置为 InitKeyType.Attr
}); });
return db; return db;
}).As<ISqlSugarClient>().InstancePerLifetimeScope(); }).As<ISqlSugarClient>().InstancePerLifetimeScope();

Loading…
Cancel
Save