关于 通讯日志 和 记录小步数据 功能

master
lxw 2 months ago
parent d9ca91aa2c
commit e58a89760d

@ -18,4 +18,15 @@ public class DeviceStateResp
/// Plc连接状态
/// </summary>
public bool PlcConnectFlag{ get; set; }
/// <summary>
/// rfid连接状态
/// </summary>
public bool RfidConnectFlag { get; set; }
/// <summary>
/// 雷达连接状态
/// </summary>
public bool RadarConnectFlag { get; set; }
}

@ -0,0 +1,38 @@
namespace Service.Execute.Model;
/**
*
*/
public class SwapDeviceLog
{
/// <summary>
/// 1雷达 2rfid 3:tbox 4:plc
/// </summary>
public int Device { get; set; }
/// <summary>
/// 描述
/// </summary>
public String desc { get; set; }
/// <summary>
/// 数据
/// </summary>
public String Data { get; set; }
/// <summary>
/// 发生时间
/// </summary>
public DateTime Time { get; set; }
/// <summary>
/// 类型 1发送 2接受
/// /// </summary>
public int Type { get; set; }
}

@ -1,4 +1,5 @@
using Microsoft.AspNetCore.Mvc;
using Service.Execute.Model;
namespace Entity.Api.Resp;
@ -26,4 +27,9 @@ public class SwapMonitorScreenResp
/// 电池数据
/// </summary>
public BinBatteryResp? BatteryInfo { get; set; }
/// <summary>
/// 换电设备业务日志
/// </summary>
public Dictionary<int, List<SwapDeviceLog>> DeviceLogs { get; set; }
}

@ -174,5 +174,11 @@ namespace Entity.Api.Resp
/// </summary>
public int? TotalFee { get; set; }
/// <summary>
/// 手动操作
/// </summary>
/// <returns></returns>
public string? ManualStep { get; set; }
}
}

@ -7,62 +7,61 @@ namespace Entity.Api.Resp
///</summary>
public partial class SwapOrderStepResp
{
/// <summary>
/// Desc:id
/// Default:
/// Nullable:False
/// </summary>
public int Id {get;set;}
public int Id { get; set; }
/// <summary>
/// Desc:换电订单编号
/// Default:
/// Nullable:True
/// </summary>
public string SwapOrderSn {get;set;}
public string SwapOrderSn { get; set; }
/// <summary>
/// Desc:步序;0-未知1-空闲200-rfid扫描300-云平台验证;
/// Default:
/// Nullable:True
/// </summary>
public int? Step {get;set;}
public int? Step { get; set; }
/// <summary>
/// Desc:步序名称
/// Default:
/// Nullable:True
/// </summary>
public string StepName {get;set;}
public string StepName { get; set; }
/// <summary>
/// Desc:创建人
/// Default:
/// Nullable:True
/// </summary>
public string CreatedBy {get;set;}
public string CreatedBy { get; set; }
/// <summary>
/// Desc:创建时间
/// Default:CURRENT_TIMESTAMP
/// Nullable:True
/// </summary>
public DateTime? CreatedTime {get;set;}
public DateTime? CreatedTime { get; set; }
/// <summary>
/// Desc:更新人
/// Default:
/// Nullable:True
/// </summary>
public string UpdatedBy {get;set;}
public string UpdatedBy { get; set; }
/// <summary>
/// Desc:更新时间
/// Default:CURRENT_TIMESTAMP
/// Nullable:True
/// </summary>
public DateTime? UpdatedTime {get;set;}
public DateTime? UpdatedTime { get; set; }
/// <summary>
/// Desc:排序
@ -71,5 +70,27 @@ namespace Entity.Api.Resp
/// </summary>
public int Sort { get; set; }
/// <summary>
/// Desc:步骤类型
/// Default: 1自动 2:手动
/// Nullable:True
/// </summary>
public int? StepType { get; set; }
/// <summary>
/// Desc:参数
/// Default:
/// Nullable:True
/// </summary>
public string? Param { get; set; }
/// <summary>
/// Desc:描述
/// Default:
/// Nullable:True
/// </summary>
public string? StepDesc { get; set; }
}
}

@ -5,6 +5,26 @@ namespace Entity.Constant;
public class StationConstant
{
/// <summary>
/// 换电站状态: 1营运中 2歇业中 3设备维护状态 4暂停营业
/// </summary>
public enum DeviceCode
{
[Description("雷达")]
Radar=1,
[Description("Rfid")]
Rfid,
[Description("Tbox")]
Tbox,
[Description("Plc")]
Plc,
}
/// <summary>
/// 换电站状态: 1营运中 2歇业中 3设备维护状态 4暂停营业
/// </summary>

@ -0,0 +1,98 @@
using System.ComponentModel;
using System.Reflection;
namespace Entity.Constant;
public class SwapConstant
{
/// <summary>
/// 通讯类型
/// </summary>
public enum CommunicationType
{
[Description("发送")]
Send=1,
[Description("接受")]
Receive,
}
/// <summary>
/// 步骤类型
/// </summary>
public enum StepType
{
[Description("自动")]
AUTO=1,
[Description("手动")]
MANUAL,
}
/// <summary>
/// 换电plc 通讯
/// </summary>
public enum PlcProtocol
{
[Description("初始化")]
Init,
[Description("下发启动换电")]
StartSwap,
}
/// <summary>
/// 雷达 通讯
/// </summary>
public enum RadarProtocol
{
[Description("开启雷达")]
Open,
[Description("关闭雷达")]
Close,
[Description("车辆状态")]
CarStatus,
}
/// <summary>
/// Rfid 通讯
/// </summary>
public enum RfidProtocol
{
[Description("连接Rfid")]
Connect,
[Description("开始读")]
BeginRead,
[Description("读取Rfid数据")]
ReadRfidData,
[Description("停止读Rfid")]
StopRead,
[Description("断开连接")]
DisConnect,
}
/// <summary>
/// Tbox 通讯
/// </summary>
public enum TboxProtocol
{
[Description("心跳数据")]
Heart,
[Description("加锁")]
Lock,
[Description("解锁")]
UnLock,
}
}

@ -1,5 +1,4 @@

using SqlSugar;
using SqlSugar;
namespace Entity.DbModel.Station
{
@ -37,8 +36,6 @@ namespace Entity.DbModel.Station
public string? StepName { get; set; }
/// <summary>
/// Desc:排序
/// Default:
@ -46,5 +43,27 @@ namespace Entity.DbModel.Station
/// </summary>
[SugarColumn(ColumnName = "sort")]
public int Sort { get; set; }
/// <summary>
/// Desc:步骤类型
/// Default: 1自动 2:手动
/// Nullable:True
/// </summary>
[SugarColumn(ColumnName = "step_type")]
public int? StepType { get; set; }
/// <summary>
/// Desc:参数
/// Default:
/// Nullable:True
/// </summary>
[SugarColumn(ColumnName = "param")] public string? Param { get; set; }
/// <summary>
/// Desc:描述
/// Default:
/// Nullable:True
/// </summary>
[SugarColumn(ColumnName = "step_desc")]
public string? StepDesc { get; set; }
}
}

@ -1,3 +1,4 @@
using Entity.Constant;
using log4net;
using Service.Charger.Client;
using Service.Mgr;
@ -54,6 +55,11 @@ public class PlcApi
/// <returns></returns>
public static bool StartSwapping(string inBinNo, string outBinNo)
{
StationSoftMgr.PutDeviceLog((int)StationConstant.DeviceCode.Plc,SwapConstant.PlcProtocol.StartSwap,
$"出仓位:{outBinNo},入仓位:{inBinNo}" ,(int)SwapConstant.CommunicationType.Send);
Log.Info($"PlcApi StartSwapping param= inBinNo={inBinNo}, outBinNo={outBinNo}");
ClientMgr.PlcClient?.SendStartBatterySwapReq(Convert.ToByte(outBinNo), Convert.ToByte(inBinNo));

@ -1,3 +1,4 @@
using Entity.Constant;
using log4net;
using Newtonsoft.Json;
using Service.Execute.Model;
@ -32,8 +33,16 @@ public class RfidApi
string url = BASE_URL + "/Api/BeginRead";
try
{
StationSoftMgr.PutDeviceLog((int)StationConstant.DeviceCode.Rfid,SwapConstant.RfidProtocol.BeginRead,
null,(int)SwapConstant.CommunicationType.Send);
string s = await _httpClient.GetStringAsync(url);
Log.Info($"BeginRead resp = {s}");
StationSoftMgr.PutDeviceLog((int)StationConstant.DeviceCode.Rfid,SwapConstant.RfidProtocol.BeginRead,
s,(int)SwapConstant.CommunicationType.Receive);
return bool.Parse(s);
}
catch (Exception e)
@ -49,7 +58,15 @@ public class RfidApi
string url = BASE_URL + "/Api/StopRead";
try
{
StationSoftMgr.PutDeviceLog((int)StationConstant.DeviceCode.Rfid,SwapConstant.RfidProtocol.StopRead,
null,(int)SwapConstant.CommunicationType.Send);
string s = await _httpClient.GetStringAsync(url);
StationSoftMgr.PutDeviceLog((int)StationConstant.DeviceCode.Rfid,SwapConstant.RfidProtocol.ReadRfidData,
s,(int)SwapConstant.CommunicationType.Receive);
Log.Info($"StopRead resp = {s}");
return bool.Parse(s);
}
@ -68,8 +85,15 @@ public class RfidApi
string url = BASE_URL + "/Api/Close";
try
{
StationSoftMgr.PutDeviceLog((int)StationConstant.DeviceCode.Rfid,SwapConstant.RfidProtocol.DisConnect,
null,(int)SwapConstant.CommunicationType.Send);
string s = await _httpClient.GetStringAsync(url);
Log.Info($"DisConnect resp={s}");
StationSoftMgr.PutDeviceLog((int)StationConstant.DeviceCode.Rfid,SwapConstant.RfidProtocol.DisConnect,
s,(int)SwapConstant.CommunicationType.Receive);
return bool.Parse(s);
}
catch (Exception e)
@ -81,14 +105,24 @@ public class RfidApi
public static async Task<bool> Connect()
{
var disConnect = await DisConnect();
// var disConnect = await DisConnect();
Log.Info("RfidApi Connect");
string url = BASE_URL + "/Api/Open";
try
{
StationSoftMgr.PutDeviceLog((int)StationConstant.DeviceCode.Rfid,SwapConstant.RfidProtocol.Connect,
null,(int)SwapConstant.CommunicationType.Send);
string s = await _httpClient.GetStringAsync(url);
Log.Info($"Connect resp={s}");
StationSoftMgr.PutDeviceLog((int)StationConstant.DeviceCode.Rfid,SwapConstant.RfidProtocol.Connect,
s,(int)SwapConstant.CommunicationType.Receive);
return bool.Parse(s);
}
catch (Exception e)
@ -102,14 +136,23 @@ public class RfidApi
{
Log.Info("RfidApi ReadRfid");
string readUrl = BASE_URL + "/Api/BeginRead";
// string readUrl = BASE_URL + "/Api/BeginRead";
string url = BASE_URL + "/Api/ReadRfidData";
Log.Info($"url={url}");
try
{
var vBeginRead = await _httpClient.GetStringAsync(readUrl);
// var vBeginRead = await _httpClient.GetStringAsync(readUrl);
StationSoftMgr.PutDeviceLog((int)StationConstant.DeviceCode.Rfid,SwapConstant.RfidProtocol.ReadRfidData,
null,(int)SwapConstant.CommunicationType.Send);
string s = await _httpClient.GetStringAsync(url);
Log.Info($"ReadRfid resp={s}");
StationSoftMgr.PutDeviceLog((int)StationConstant.DeviceCode.Rfid,SwapConstant.RfidProtocol.ReadRfidData,
s,(int)SwapConstant.CommunicationType.Receive);
if (s != String.Empty)
{
RfidReadModel? model = JsonConvert.DeserializeObject<RfidReadModel>(s);

@ -1,3 +1,4 @@
using Entity.Constant;
using log4net;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
@ -33,9 +34,15 @@ public class TBoxApi
string url = BASE_URL + StaticStationInfo.TboxUrlCarInfo + carNo;
try
{
string s = await _httpClient.GetStringAsync(url);
Log.Info($"TBoxApi GetCarInfo resp = {s}");
StationSoftMgr.PutDeviceLog((int)StationConstant.DeviceCode.Tbox,SwapConstant.TboxProtocol.Heart,
s,(int)SwapConstant.CommunicationType.Receive);
TboxCarInfoModel tboxCarInfoModel = null;
if (!String.IsNullOrWhiteSpace(s))
@ -137,8 +144,14 @@ public class TBoxApi
string url = BASE_URL + StaticStationInfo.TboxUrlUnLock + carNo;
try
{
StationSoftMgr.PutDeviceLog((int)StationConstant.DeviceCode.Tbox,SwapConstant.TboxProtocol.UnLock,
carNo ,(int)SwapConstant.CommunicationType.Send);
string s = await _httpClient.GetStringAsync(url);
StationSoftMgr.PutDeviceLog((int)StationConstant.DeviceCode.Tbox,SwapConstant.TboxProtocol.Lock,
s ,(int)SwapConstant.CommunicationType.Receive);
Log.Info($"UnLockCar resp = {s}");
return bool.Parse(s);
@ -233,9 +246,14 @@ public class TBoxApi
Log.Info("LockCar");
string url = BASE_URL +StaticStationInfo.TboxUrlLock + carNo;
try
{
{ StationSoftMgr.PutDeviceLog((int)StationConstant.DeviceCode.Tbox,SwapConstant.TboxProtocol.Lock,
carNo ,(int)SwapConstant.CommunicationType.Send);
string s = await _httpClient.GetStringAsync(url);
StationSoftMgr.PutDeviceLog((int)StationConstant.DeviceCode.Tbox,SwapConstant.TboxProtocol.Lock,
s ,(int)SwapConstant.CommunicationType.Receive);
Log.Info($"LockCar resp = {s}");
return bool.Parse(s);

@ -36,7 +36,8 @@ public class CommonMgr
/// <summary>
/// 新增小步状态
/// </summary>
public void InsertStep(InfoEnum.BusinessSwappingStep step, SwappingStateMachine machine)
public void InsertStep(InfoEnum.BusinessSwappingStep step, SwappingStateMachine machine,
string desc="" ,string param=null,int type=(int)SwapConstant.StepType.AUTO)
{
var stepModel = new StepModel
{
@ -53,7 +54,8 @@ public class CommonMgr
if (machine.SwapOrder != null)
{
if (!string.IsNullOrEmpty(machine.SwapOrder.Sn))
_swapOrderStepService.InsertSwapStepForSwapMain(step, machine.StepSort++, machine.SwapOrder.Sn);
_swapOrderStepService.InsertSwapStepForSwapMain(step, machine.StepSort++, machine.SwapOrder.Sn,
desc,param,type);
}

@ -25,4 +25,5 @@ public class StepModel
/// 0:初始化 1:执行完成
/// </summary>
public int Status{ get; set; }
}
}

@ -1,5 +1,7 @@

using Entity.Constant;
using HybirdFrameworkCore.Configuration;
using Service.Execute.Model;
namespace Service.Execute
{
@ -11,6 +13,20 @@ namespace Service.Execute
public static readonly SwappingStateMachine SwappingStateMachine = SwappingStateMachine.GetInstance();
public static Dictionary<int, List<SwapDeviceLog>> DeviceLogs = new ()
{
[(int)StationConstant.DeviceCode.Radar] = new (),
[(int)StationConstant.DeviceCode.Rfid] = new (),
[(int)StationConstant.DeviceCode.Tbox] = new (),
[(int)StationConstant.DeviceCode.Plc] = new(),
};
public static readonly string addr1 = AppSettingsHelper.GetContent("SoundAddr", "Address1");
#region 换电流程
@ -39,5 +55,51 @@ namespace Service.Execute
}
#endregion 换电流程启动
#region 设备业务数据日志
public static void PutDeviceLog(int key, Enum @enum,string data,int type)
{
SwapDeviceLog deviceLog = BuildDeviceLog(@enum, data,key, type);
DeviceLogs.TryGetValue(key, out var value);
if (value == null)
{
List<SwapDeviceLog> list = new List<SwapDeviceLog>() { deviceLog };
DeviceLogs[key] = list;
}
else
{
value.Add(deviceLog);
if (value.Count > 10)
{
var swapDeviceLogs = value.OrderByDescending(i => i.Time).ToList();
var deviceLogs = swapDeviceLogs.Take(10).ToList();
value = deviceLogs.OrderBy(i => i.Time).ToList();
}
DeviceLogs[key] = value;
}
}
public static SwapDeviceLog BuildDeviceLog(Enum @enum,string data,int device,int type)
{
return new()
{
Time = DateTime.Now,
desc = BaseEnumExtensions.GetDescription(@enum),
Data = data,
Device = device,
Type = type
};
}
#endregion
}
}

@ -4,6 +4,7 @@ using Entity.Constant;
using HybirdFrameworkCore.Autofac;
using HybirdFrameworkCore.Configuration;
using log4net;
using Newtonsoft.Json;
using Service.Execute.Api;
using Service.Execute.Model;
using Service.Execute.Model.Tbox;
@ -65,7 +66,9 @@ public class CarCtrlState : IState
machine.VelUnlockFlag = true;
_CommonMgr.InsertStep(InfoEnum.BusinessSwappingStep.VelUnlockFlag,
machine);
machine,param: $"unlock: {unLock} ; heartMsg: {JsonConvert.SerializeObject(resultHeartBeatMsg)}",type:
machine.ManualConfirmCarUnlockFlag? (int)SwapConstant.StepType.MANUAL :
(int)SwapConstant.StepType.AUTO);
SoundClient = AppInfo.Container.Resolve<SoundClient>();
SoundClient.SoundPlay(SoundEnum.music93);

@ -16,6 +16,9 @@ using Service.Led;
using Service.Padar.Client;
using Service.RealTime;
using Service.Sound.SoundClient;
using Service.Station;
using System.Runtime.CompilerServices;
using Newtonsoft.Json;
namespace Service.Execute.Step;
@ -53,6 +56,7 @@ public class CarPrepareState : IState
return SwappingStateMachine.ReturnWithInvokeErr(checkTBoxConnect, ExceptionReason.None);
}
//车辆本地验证
InvokeStatus checkTBoxVelLocal = CheckTBoxVelLocalFlag(machine);
if (checkTBoxVelLocal != InvokeStatus.Done)
@ -60,6 +64,7 @@ public class CarPrepareState : IState
return SwappingStateMachine.ReturnWithInvokeErr(checkTBoxVelLocal, ExceptionReason.None);
}
machine.ExceptionReason = ExceptionReason.None;
//选包
@ -75,14 +80,9 @@ public class CarPrepareState : IState
{
return SwappingStateMachine.ReturnWithInvokeErr(selectPack, ExceptionReason.StopChargingError);
}
_CommonMgr.SaveSwapBattery(machine);
//车辆到位
InvokeStatus carInPosition = CarInPosition(machine);
if (carInPosition != InvokeStatus.Done)
{
return SwappingStateMachine.ReturnWithInvokeErr(carInPosition, ExceptionReason.None);
}
////调整车辆
var adjustCarByRadar = AdjustCarByRadar(machine);
@ -91,6 +91,15 @@ public class CarPrepareState : IState
return SwappingStateMachine.ReturnWithInvokeErr(adjustCarByRadar, ExceptionReason.None);
}
//车辆到位
InvokeStatus carInPosition = CarInPosition(machine);
if (carInPosition != InvokeStatus.Done)
{
return SwappingStateMachine.ReturnWithInvokeErr(carInPosition, ExceptionReason.None);
}
@ -142,7 +151,7 @@ public class CarPrepareState : IState
{
machine.VehiclesInPlaceFlag = true;
_CommonMgr.InsertStep(InfoEnum.BusinessSwappingStep.CarInPositionFlag,
machine);
machine,param:JsonConvert.SerializeObject(tboxCarInfoModel));
}
}, () =>
{
@ -396,7 +405,7 @@ public class CarPrepareState : IState
//选包成功
_CommonMgr.LockBinAndUpdateAmt(orderBatteryInfo);
machine.SwapOrderBatteryInfo = orderBatteryInfo;
_CommonMgr.SaveSwapBattery(machine);
machine.SelectPackFlag = true;
}
}, () =>

@ -6,6 +6,7 @@ using Entity.DbModel.Station;
using HybirdFrameworkCore.Autofac;
using HybirdFrameworkCore.Configuration;
using log4net;
using Newtonsoft.Json;
using Repository.Station;
using Service.Charger.Client;
using Service.Execute.Api;
@ -115,29 +116,7 @@ public class DoSwappingState : IState
//}
public InvokeStatus AdjustCarByRadar(SwappingStateMachine machine)
{
return Invoker.Invoke("begin Radar", 1000, 20, machine.IsCanceled,
() =>
{
//新增小步
_CommonMgr.InsertStep(InfoEnum.BusinessSwappingStep.RadarOutFlag,
machine);
var carState = PadarMgr._PadarClient?.CarState;
return carState.HasValue && (carState.Value == 1 || carState.Value == 2 || carState.Value == 3 || carState.Value == 4 || carState.Value == 5);
},
() =>
{
switch (PadarMgr._PadarClient?.CarState)
{
case 6:
_log.Info("车辆未驶离");
break;
}
});
}
/// <summary>
/// 下发plc启动换电
@ -157,7 +136,9 @@ public class DoSwappingState : IState
machine.SwapOrderBatteryInfo.UpBinInfo.No);
_CommonMgr.InsertStep(InfoEnum.BusinessSwappingStep.DistributeSelectPackFlag,
machine);
machine,param: $"InBin:{JsonConvert.SerializeObject(machine.SwapOrderBatteryInfo.InBinInfo)};" +
$"UpBin: {JsonConvert.SerializeObject(machine.SwapOrderBatteryInfo.UpBinInfo)}");
_CommonMgr.InsertStep(InfoEnum.BusinessSwappingStep.StartSwappingFlag,
machine);

@ -198,11 +198,16 @@ public class StationReadyState : IState
public InvokeStatus AdjustCarByRadar(SwappingStateMachine machine)
{
int che = 0;
return Invoker.Invoke("begin Radar", 1000, 20, machine.IsCanceled,
return Invoker.Invoke("adjust Radar", 1000, 20, machine.IsCanceled,
() =>
{
LedClient.SendMsgByKey(InfoEnum.SwapInfo.InfoCarInPosition.GetLed());
StationSoftMgr.PutDeviceLog((int)StationConstant.DeviceCode.Radar,SwapConstant.RadarProtocol.CarStatus,
null,(int)SwapConstant.CommunicationType.Receive);
if (PadarMgr._PadarClient?.CarState == 6)
{
LedClient.SendMsgByKey(InfoEnum.SwapInfo.diparkir.GetLed());
@ -252,7 +257,11 @@ public class StationReadyState : IState
return Invoker.Invoke(" BeginRead read rfid", 1000, 20, machine.IsCanceled,
() => machine.BeginRfidReadFlag, () =>
{
// Task<bool> open = RfidApi.Connect();
Task<bool> open = RfidApi.Connect();
if (open.Result)
{
machine.RfidConnectFlag = true;
Task<bool> beginRead = RfidApi.BeginRead();
beginRead.Wait();
if (!beginRead.Result)
@ -265,6 +274,9 @@ public class StationReadyState : IState
_log.Info("begin read done");
machine.BeginRfidReadFlag = true;
}
}
}, () =>
{
machine.LedTool.WriteProgramContent(InfoEnum.SwapInfo.ErrorReadRfid.GetLed());
@ -329,11 +341,12 @@ public class StationReadyState : IState
machine.SwapOrder = _CommonMgr.SaveOrder(BuildOrder(machine.RfidReadModel));
//新增小步
_CommonMgr.InsertStep(InfoEnum.BusinessSwappingStep.RfidReadFlag,
machine);
machine,param:JsonConvert.SerializeObject(machine.RfidReadModel));
//RfidApi.StopRead();
RfidApi.StopRead();
_log.Info("stop read rfid");
// RfidApi.DisConnect();
RfidApi.DisConnect();
machine.RfidConnectFlag = false;
machine.RfidReadFlag = true;
}
}, () =>
@ -365,7 +378,8 @@ public class StationReadyState : IState
machine.SwapOrder = _CommonMgr.SaveOrder(BuildOrder(machine.RfidReadModel));
//新增小步
_CommonMgr.InsertStep(InfoEnum.BusinessSwappingStep.RfidReadFlag,
machine);
machine,"手动填写车辆vin",JsonConvert.SerializeObject(machine.RfidReadModel),
(int)SwapConstant.StepType.MANUAL);
_log.Info("stop Wait Vin Prepare");

@ -4,6 +4,7 @@ using Entity.Constant;
using HybirdFrameworkCore.Autofac;
using HybirdFrameworkCore.Configuration;
using log4net;
using Newtonsoft.Json;
using Service.Execute.Api;
using Service.Execute.Model.Tbox;
using Service.Execute.SwapException;
@ -198,7 +199,10 @@ public class SwapDoneState : IState
if (carInfo.Result?.CarStatus?.LockStatus == 2 || machine.ManualConfirmCarLockFlag)
{
_CommonMgr.InsertStep(InfoEnum.BusinessSwappingStep.VelLockFlag,
machine);
machine,param: $"lock: {unLock} ; heartMsg: {JsonConvert.SerializeObject(carInfo.Result)}",type:
machine.ManualConfirmCarLockFlag? (int)SwapConstant.StepType.MANUAL :
(int)SwapConstant.StepType.AUTO);
//_CommonMgr.InsertStep(InfoEnum.BusinessSwappingStep.VelLockFlag,
// machine);
var SoundClient = AppInfo.Container.Resolve<SoundClient>();

@ -23,6 +23,8 @@ 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; }
@ -71,11 +73,15 @@ public class SwappingStateMachine : IDisposable
public ConcurrentDictionary<string, StepModel> StepModel =
new ConcurrentDictionary<string, StepModel>
();
#region 小步状态
//雷达检测/车辆进入
public bool RadarInFlag = false;
public bool RfidConnectFlag = false;
//开始读rf
public bool BeginRfidReadFlag = false;
@ -253,8 +259,6 @@ public class SwappingStateMachine : IDisposable
public void Reset()
{
Log.Info("reset data");
/*if (PlcMgr.PlcClient?.ReadTaskNo() == 1)
@ -338,9 +342,7 @@ public class SwappingStateMachine : IDisposable
Array values = Enum.GetValues(typeof(InfoEnum.BusinessSwappingStep));
foreach (var value in values)
{
StepModel[value.ToInt()+""] = new StepModel()
StepModel[value.ToInt() + ""] = new StepModel()
{
StepNo = (int)value,
Status = 0,
@ -363,7 +365,7 @@ public class SwappingStateMachine : IDisposable
{
RadarInFlag = false;
RfidConnectFlag = false;
BeginRfidReadFlag = false;
@ -437,9 +439,6 @@ public class SwappingStateMachine : IDisposable
//关于仓库锁定相关重置
private void ResetOrderAmtStatus()
{
// SoundApi.PlayOneSound((int)InfoEnum.SwapInfo.ErrorTBoxConn);
LedClient.SendMsgByKey(InfoEnum.SwapInfo.WelcomeInfo.GetLed());
@ -452,7 +451,8 @@ public class SwappingStateMachine : IDisposable
{
if (SwapOrderBatteryInfo?.UpBinInfo != null) ;
{
BinInfoRepository.Update(i=>i.AmtLock==(int)InfoEnum.AmtBatLockStatus.UnLock,i=>i.Id==SwapOrderBatteryInfo.UpBinInfo.Id);
BinInfoRepository.Update(i => i.AmtLock == (int)InfoEnum.AmtBatLockStatus.UnLock,
i => i.Id == SwapOrderBatteryInfo.UpBinInfo.Id);
}
}
@ -479,6 +479,8 @@ public class SwappingStateMachine : IDisposable
CancelFlag = true;
Thread.Sleep(2000);
}
}
public enum SwappingState

@ -1,7 +1,11 @@
using Entity.Constant;
using HslCommunication.Enthernet;
using HybirdFrameworkCore.Autofac.Attribute;
using HybirdFrameworkCore.Entity;
using HybirdFrameworkDriver.TcpClient;
using log4net;
using Service.Execute;
using Service.Execute.Model;
using Decoder = Service.Padar.Codec.Decoder;
using Encoder = Service.Padar.Codec.Encoder;
@ -10,10 +14,12 @@ namespace Service.Padar.Client;
[Scope]
public class PadarClient : TcpClient<IBaseHandler, Decoder, Encoder>
{
private readonly String DEVICE_CODE = "radar";
/// <summary>
/// 0-雷达不工作1-无车2-无电池3-角度偏移过大4-车辆靠后5-车辆靠前6-车辆到位
/// </summary>
public byte CarState =new byte();
public byte CarState = new byte();
public static readonly byte[] StartChar = { 0xFE, 0x68 };
@ -50,6 +56,12 @@ public class PadarClient : TcpClient<IBaseHandler, Decoder, Encoder>
serialNum++;
sendBytes[3] = byte3;
this.Channel.WriteAndFlushAsync(sendBytes);
StationSoftMgr.PutDeviceLog((int)StationConstant.DeviceCode.Radar,
byte3 == 0 ? SwapConstant.RadarProtocol.Close : SwapConstant.RadarProtocol.Open,
sendBytes.ToString(), (int)SwapConstant.CommunicationType.Send);
return Result<bool>.Success();
}
}

@ -1,4 +1,6 @@
using Autofac;
using System.Text.Json.Nodes;
using Autofac;
using Entity.Constant;
using Entity.DbModel.Station;
using HybirdFrameworkCore.Autofac;
using HybirdFrameworkCore.Autofac.Attribute;
@ -6,11 +8,13 @@ using HybirdFrameworkCore.Entity;
using HybirdFrameworkDriver.Session;
using HybirdFrameworkDriver.TcpClient;
using log4net;
using Newtonsoft.Json;
using Repository.Station;
using Service.Charger.Client;
using Service.Charger.Codec;
using Service.Charger.Handler;
using Service.Charger.Msg.Host.Req;
using Service.Execute;
namespace Service.Charger.Server;
@ -70,6 +74,11 @@ public class PlcClient : TcpClient<IBaseHandler, Decoder, Encoder>
InitializeCommandReq req = new InitializeCommandReq();
this.Channel.WriteAndFlushAsync(req);
StationSoftMgr.PutDeviceLog((int)StationConstant.DeviceCode.Plc,SwapConstant.PlcProtocol.Init,
JsonConvert.SerializeObject(req),(int)SwapConstant.CommunicationType.Send);
return Result<bool>.Success();
}

@ -23,6 +23,7 @@ using Service.Execute.Model;
using Service.Execute.Utils;
using Service.Init;
using Service.Mgr;
using Service.Padar.Client;
using SqlSugar;
namespace Service.Station;
@ -145,44 +146,10 @@ public class MonitorService
monitorScreenResp.VehicleInfo.DownBatteryBinNo = queryByClauseAsync.DownBatteryBinNo;
monitorScreenResp.VehicleInfo.UpBatteryBinNo = queryByClauseAsync.UpBatteryBinNo;
}
//SwapMonitorScreenResp monitorScreenResp = new()
//{
// PlcSwapModel = plcSwapModel,
// StateInfo = stateInfoList,
// VehicleInfo = new SwapVehicleResp()
// {
// OrderNo = StationSoftMgr.SwappingStateMachine.SwapOrder != null
// ? StationSoftMgr.SwappingStateMachine.SwapOrder.Sn
// : null,
// VelMac = StationSoftMgr.SwappingStateMachine.RfidReadModel != null
// ? StationSoftMgr.SwappingStateMachine.RfidReadModel.VelMac
// : null,
// LockStatus = tboxCarInfoModel != null ? tboxCarInfoModel.CarStatus.LockStatus : null,
// KeyStatus = tboxCarInfoModel != null ? tboxCarInfoModel.CarStatus.Keys : null,
// VelNo = StationSoftMgr.SwappingStateMachine.RfidReadModel != null
// ? StationSoftMgr.SwappingStateMachine.RfidReadModel.VelNo
// : null,
// VelVin = StationSoftMgr.SwappingStateMachine.RfidReadModel != null
// ? StationSoftMgr.SwappingStateMachine.RfidReadModel.VelVin
// : null,
// Break = StationSoftMgr.SwappingStateMachine.BoxCarInfoModel?.CarStatus?.Break,
// Gear = StationSoftMgr.SwappingStateMachine.BoxCarInfoModel?.CarStatus?.Gear,
// },
// BatteryInfo = new()
// {
// BatteryTotalCount = binInfos.Count,
// UsingSwapBatteryCount = binInfos.Select(i => i.ChargeStatus == 2 &&
// i.AmtLock == (int)InfoEnum.AmtBatLockStatus.UnLock &&
// i.Soc > StaticStationInfo.SwapSoc &&
// new TimeSpan(DateTime.Now.Ticks -
// i.LastChargeFinishTime.ToDateTime().Ticks)
// .TotalMinutes >
// StaticStationInfo.SwapFinishChargeTime).Count()
// }
//};
monitorScreenResp.DeviceLogs = StationSoftMgr.DeviceLogs;
return Result<SwapMonitorScreenResp>.Success(monitorScreenResp);
}
@ -217,7 +184,9 @@ public class MonitorService
{
BoxConnectFlag = isConnected,
// CloudConnectFlag = CloudClientMgr.CloudClient == null ? false : CloudClientMgr.CloudClient.Connected,
PlcConnectFlag = ClientMgr.PlcClient != null && ClientMgr.PlcClient.Connected
PlcConnectFlag = ClientMgr.PlcClient != null && ClientMgr.PlcClient!.Connected,
RfidConnectFlag = StationSoftMgr.SwappingStateMachine!.RfidConnectFlag,
RadarConnectFlag =PadarMgr._PadarClient != null && PadarMgr._PadarClient!.Connected
};
return Result<DeviceStateResp>.Success(resp);

@ -7,6 +7,8 @@ using Repository.Station;
using SqlSugar;
using System.Linq.Expressions;
using Entity.Constant;
using HybirdFrameworkCore.Utils;
using Quartz.Util;
namespace Service.Station;
@ -90,7 +92,8 @@ public class SwapOrderStepService : BaseServices<SwapOrderStep>
/// <summary>
/// 换电小步新增---换电主流程
/// </summary>
public void InsertSwapStepForSwapMain(InfoEnum.BusinessSwappingStep step, int sort, String swapOrderSn)
public void InsertSwapStepForSwapMain(InfoEnum.BusinessSwappingStep step, int sort, String swapOrderSn,
string desc="" ,string param=null,int type=(int)SwapConstant.StepType.AUTO)
{
SwapOrderStep swapOrderStep = new ()
{
@ -98,6 +101,9 @@ public class SwapOrderStepService : BaseServices<SwapOrderStep>
Step = (int)step,
Sort = sort,
SwapOrderSn = swapOrderSn,
StepType = type,
Param = param,
StepDesc = ObjUtils.IsNullOrWhiteSpace(desc)?BaseEnumExtensions.GetDescription(step):desc,
};
_swapOrderStepRepository.Insert(swapOrderStep);
}

@ -161,7 +161,7 @@ namespace WebStarter.Controllers.BasicConfig
/// <summary>
/// 提交换电策略设置
///
/// </summary>
/// <param name="input"></param>
/// <returns></returns>

@ -3,6 +3,7 @@ using System.Transactions;
using AutoMapper;
using Entity.Api.Req;
using Entity.Api.Resp;
using Entity.Constant;
using Entity.DbModel.Station;
using Entity.Dto;
using HybirdFrameworkCore.Entity;
@ -23,7 +24,6 @@ namespace WebStarter.Controllers;
[Route("api/[controller]")]
public class SwapOrderController : ControllerBase
{
private static readonly ILog Log = LogManager.GetLogger(typeof(SwapOrderController));
private readonly SwapOrderService swapOrderService;
private readonly SwapOrderBatteryService swapOrderBatteryService;
@ -33,7 +33,8 @@ public class SwapOrderController : ControllerBase
private readonly BaseVehicleRepository _baseVehicleRepository;
public SwapOrderController(SwapOrderService swapOrderService, SwapOrderBatteryService swapOrderBatteryService,
SwapOrderStepService swapOrderStepService,SwapOrderReportCloudRepository swapOrderReportCloudRepository,BaseVehicleRepository baseVehicleRepository
SwapOrderStepService swapOrderStepService, SwapOrderReportCloudRepository swapOrderReportCloudRepository,
BaseVehicleRepository baseVehicleRepository
)
{
this.swapOrderService = swapOrderService;
@ -52,11 +53,12 @@ public class SwapOrderController : ControllerBase
{
Log.Info($"SwapOrderController QueryPage req={req}");
if (!string.IsNullOrEmpty(req.DownBatteryNo)||!string.IsNullOrEmpty(req.UpBatteryNo))
if (!string.IsNullOrEmpty(req.DownBatteryNo) || !string.IsNullOrEmpty(req.UpBatteryNo))
{
var result = BatteryCodeList(req);
return Result<PageResult<SwapOrderResp>>.Success(result);
}
Log.Info($"查询换电订单 SwapOrderController start QueryPage swapOrderService.QuerySwapOrder req={req}");
var swapOrderResp = swapOrderService.QuerySwapOrder(req);
Log.Info($"查询换电订单 SwapOrderController end QueryPage swapOrderService.QuerySwapOrder req={req}");
@ -81,6 +83,7 @@ public class SwapOrderController : ControllerBase
swapOrder.Departments = matchingVehicle.Departments;
}
}
return Result<PageResult<SwapOrderResp>>.Success(swapOrderResp);
}
@ -106,16 +109,12 @@ public class SwapOrderController : ControllerBase
{
//获取所有订单号
var orderSns = swapOrderResp.Rows.Select(row => row.Sn).ToList();
Log.Info($"查询上报云平台次数 SwapOrderController start QueryPage swapOrderService.QueryReportCloudNumBySn req={orderSns}");
//查询上报云平台次数
//Dictionary<string, int?> queryReportCloudNumBySn = swapOrderService.QueryReportCloudNumBySn(orderSns);
Log.Info($"查询上报云平台次数 SwapOrderController end QueryPage swapOrderService.QueryReportCloudNumBySn req={orderSns}");
Log.Info($"查询订单电池数据 SwapOrderController start QueryPage swapOrderBatteryService.QueryListByClause req={orderSns}");
////查询订单电池数据
List<SwapOrderBattery> batteryList =
swapOrderBatteryService.QueryListByClause(u => orderSns.Contains(u.SwapOrderSn));
Log.Info($"查询订单电池数据 SwapOrderController end QueryPage swapOrderBatteryService.QueryListByClause req={orderSns}");
//映射
var config =
new MapperConfiguration(cfg => cfg.CreateMap<SwapOrderBatteryResp, SwapOrderBattery>().ReverseMap());
@ -123,9 +122,10 @@ public class SwapOrderController : ControllerBase
List<SwapOrderBatteryResp> swapOrderBattery = mapper.Map<List<SwapOrderBatteryResp>>(batteryList);
Log.Info($"查询公里数 SwapOrderController start QueryPage swapOrderReportCloudRepository.QueryListByClause req={orderSns}");
List<SwapOrderReportCloud> swapOrderReportClouds = swapOrderReportCloudRepository.QueryListByClause(u => orderSns.Contains(u.SwapOrderSn));
Log.Info($"查询公里数 SwapOrderController end QueryPage swapOrderReportCloudRepository.QueryListByClause req={orderSns}");
List<SwapOrderReportCloud> swapOrderReportClouds =
swapOrderReportCloudRepository.QueryListByClause(u => orderSns.Contains(u.SwapOrderSn));
//将电池数据添加到换电订单数据中
foreach (var row in swapOrderResp.Rows)
{
@ -141,10 +141,9 @@ public class SwapOrderController : ControllerBase
}
}
}
Log.Info($"查询订单步序数据 SwapOrderController start QueryPage swapOrderStepService.QueryListByClause req={orderSns}");
//查询订单步序数据
var stepList = swapOrderStepService.QueryListByClause(u => orderSns.Contains(u.SwapOrderSn));
Log.Info($"查询订单步序数据 SwapOrderController end QueryPage swapOrderStepService.QueryListByClause req={orderSns}");
stepList = stepList.OrderBy(s => s.Sort).ToList();
//映射
@ -157,8 +156,14 @@ public class SwapOrderController : ControllerBase
for (int i = 0; i < swapOrderResp.Rows.Count; i++)
{
swapOrderResp.Rows[i].StepList = new List<SwapOrderStepResp>();
var swapOrderStepResps = swapOrderStep.Where(step => step.SwapOrderSn == swapOrderResp.Rows[i].Sn).ToList();
swapOrderResp.Rows[i].StepList
.AddRange(swapOrderStep.Where(step => step.SwapOrderSn == swapOrderResp.Rows[i].Sn).ToList());
.AddRange(swapOrderStepResps);
;
swapOrderResp.Rows[i].ManualStep = String.Join(",",
swapOrderStepResps.Where(i => i.StepType == (int)SwapConstant.StepType.MANUAL).Select(i => i.StepDesc)
.ToList());
}
}
@ -174,7 +179,6 @@ public class SwapOrderController : ControllerBase
var orderSns = swapOrderRespList.Select(row => row.Sn).ToList();
////查询订单电池数据
List<SwapOrderBattery> batteryList =
swapOrderBatteryService.QueryListByClause(u => orderSns.Contains(u.SwapOrderSn));
@ -191,7 +195,8 @@ public class SwapOrderController : ControllerBase
List<SwapOrderResp> swapOrderResp = mapper.Map<List<SwapOrderResp>>(swapOrderRespList);
List<SwapOrderReportCloud> swapOrderReportClouds = swapOrderReportCloudRepository.QueryListByClause(u => orderSns.Contains(u.SwapOrderSn));
List<SwapOrderReportCloud> swapOrderReportClouds =
swapOrderReportCloudRepository.QueryListByClause(u => orderSns.Contains(u.SwapOrderSn));
//将电池数据添加到换电订单数据中
@ -496,7 +501,6 @@ public class SwapOrderController : ControllerBase
// 将电池数据添加到换电订单数据中
for (int i = 0; i < list.Count; i++)
{
if (language == "en")
{
SwapLoseOrderDto2 dto = list2[i];
@ -507,7 +511,6 @@ public class SwapOrderController : ControllerBase
{
dto.DownBatteryBinNo = swapOrderBatteryResp.DownBatteryBinNo;
dto.UpBatteryBinNo = swapOrderBatteryResp.UpBatteryBinNo;
}
}
else
@ -519,7 +522,6 @@ public class SwapOrderController : ControllerBase
{
dto.DownBatteryBinNo = swapOrderBatteryResp.DownBatteryBinNo;
dto.UpBatteryBinNo = swapOrderBatteryResp.UpBatteryBinNo;
}
}
}
@ -536,6 +538,4 @@ public class SwapOrderController : ControllerBase
};
}
}
}

@ -4,6 +4,12 @@ ADD COLUMN append_total_fee INT COMMENT '附加费',
ADD COLUMN total_fee INT COMMENT '总费用(所有的总费用)';
ALTER TABLE swap_order_step
ADD COLUMN step_type INT COMMENT '步骤类型1自动 2手动',
ADD COLUMN step_desc varchar(255) COMMENT '描述',
ADD COLUMN param text COMMENT '参数';
ALTER TABLE swap_order_battery
ADD COLUMN nominal_energy DECIMAL(24, 2) COMMENT '电池标称能量';

Loading…
Cancel
Save