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

master
lxw 2 months ago
parent d9ca91aa2c
commit e58a89760d

@ -18,4 +18,15 @@ public class DeviceStateResp
/// Plc连接状态 /// Plc连接状态
/// </summary> /// </summary>
public bool PlcConnectFlag{ get; set; } 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 Microsoft.AspNetCore.Mvc;
using Service.Execute.Model;
namespace Entity.Api.Resp; namespace Entity.Api.Resp;
@ -26,4 +27,9 @@ public class SwapMonitorScreenResp
/// 电池数据 /// 电池数据
/// </summary> /// </summary>
public BinBatteryResp? BatteryInfo { get; set; } public BinBatteryResp? BatteryInfo { get; set; }
/// <summary>
/// 换电设备业务日志
/// </summary>
public Dictionary<int, List<SwapDeviceLog>> DeviceLogs { get; set; }
} }

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

@ -7,69 +7,90 @@ namespace Entity.Api.Resp
///</summary> ///</summary>
public partial class SwapOrderStepResp public partial class SwapOrderStepResp
{ {
/// <summary>
/// <summary> /// Desc:id
/// Desc:id /// Default:
/// Default: /// Nullable:False
/// Nullable:False /// </summary>
/// </summary> public int Id { get; set; }
public int Id {get;set;}
/// <summary> /// <summary>
/// Desc:换电订单编号 /// Desc:换电订单编号
/// Default: /// Default:
/// Nullable:True /// Nullable:True
/// </summary> /// </summary>
public string SwapOrderSn {get;set;} public string SwapOrderSn { get; set; }
/// <summary> /// <summary>
/// Desc:步序;0-未知1-空闲200-rfid扫描300-云平台验证; /// Desc:步序;0-未知1-空闲200-rfid扫描300-云平台验证;
/// Default: /// Default:
/// Nullable:True /// Nullable:True
/// </summary> /// </summary>
public int? Step {get;set;} public int? Step { get; set; }
/// <summary> /// <summary>
/// Desc:步序名称 /// Desc:步序名称
/// Default: /// Default:
/// Nullable:True /// Nullable:True
/// </summary> /// </summary>
public string StepName {get;set;} public string StepName { get; set; }
/// <summary> /// <summary>
/// Desc:创建人 /// Desc:创建人
/// Default: /// Default:
/// Nullable:True /// Nullable:True
/// </summary> /// </summary>
public string CreatedBy {get;set;} public string CreatedBy { get; set; }
/// <summary> /// <summary>
/// Desc:创建时间 /// Desc:创建时间
/// Default:CURRENT_TIMESTAMP /// Default:CURRENT_TIMESTAMP
/// Nullable:True /// Nullable:True
/// </summary> /// </summary>
public DateTime? CreatedTime {get;set;} public DateTime? CreatedTime { get; set; }
/// <summary> /// <summary>
/// Desc:更新人 /// Desc:更新人
/// Default: /// Default:
/// Nullable:True /// Nullable:True
/// </summary> /// </summary>
public string UpdatedBy {get;set;} public string UpdatedBy { get; set; }
/// <summary> /// <summary>
/// Desc:更新时间 /// Desc:更新时间
/// Default:CURRENT_TIMESTAMP /// Default:CURRENT_TIMESTAMP
/// Nullable:True /// Nullable:True
/// </summary> /// </summary>
public DateTime? UpdatedTime {get;set;} public DateTime? UpdatedTime { get; set; }
/// <summary>
/// Desc:排序
/// Default:
/// Nullable:True
/// </summary>
public int Sort { get; set; }
/// <summary>
/// Desc:排序
/// Default:
/// Nullable:True
/// </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 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> /// <summary>
/// 换电站状态: 1营运中 2歇业中 3设备维护状态 4暂停营业 /// 换电站状态: 1营运中 2歇业中 3设备维护状态 4暂停营业
/// </summary> /// </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 namespace Entity.DbModel.Station
{ {
@ -36,8 +35,6 @@ namespace Entity.DbModel.Station
[SugarColumn(ColumnName = "step_name")] [SugarColumn(ColumnName = "step_name")]
public string? StepName { get; set; } public string? StepName { get; set; }
/// <summary> /// <summary>
/// Desc:排序 /// Desc:排序
@ -46,5 +43,27 @@ namespace Entity.DbModel.Station
/// </summary> /// </summary>
[SugarColumn(ColumnName = "sort")] [SugarColumn(ColumnName = "sort")]
public int Sort { get; set; } 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 log4net;
using Service.Charger.Client; using Service.Charger.Client;
using Service.Mgr; using Service.Mgr;
@ -54,6 +55,11 @@ public class PlcApi
/// <returns></returns> /// <returns></returns>
public static bool StartSwapping(string inBinNo, string outBinNo) 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}"); Log.Info($"PlcApi StartSwapping param= inBinNo={inBinNo}, outBinNo={outBinNo}");
ClientMgr.PlcClient?.SendStartBatterySwapReq(Convert.ToByte(outBinNo), Convert.ToByte(inBinNo)); ClientMgr.PlcClient?.SendStartBatterySwapReq(Convert.ToByte(outBinNo), Convert.ToByte(inBinNo));

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

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

@ -36,7 +36,8 @@ public class CommonMgr
/// <summary> /// <summary>
/// 新增小步状态 /// 新增小步状态
/// </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 var stepModel = new StepModel
{ {
@ -53,7 +54,8 @@ public class CommonMgr
if (machine.SwapOrder != null) if (machine.SwapOrder != null)
{ {
if (!string.IsNullOrEmpty(machine.SwapOrder.Sn)) 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:执行完成 /// 0:初始化 1:执行完成
/// </summary> /// </summary>
public int Status{ get; set; } public int Status{ get; set; }
}
}

@ -1,5 +1,7 @@
 
using Entity.Constant;
using HybirdFrameworkCore.Configuration; using HybirdFrameworkCore.Configuration;
using Service.Execute.Model;
namespace Service.Execute namespace Service.Execute
{ {
@ -11,6 +13,20 @@ namespace Service.Execute
public static readonly SwappingStateMachine SwappingStateMachine = SwappingStateMachine.GetInstance(); 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"); public static readonly string addr1 = AppSettingsHelper.GetContent("SoundAddr", "Address1");
#region 换电流程 #region 换电流程
@ -39,5 +55,51 @@ namespace Service.Execute
} }
#endregion 换电流程启动 #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.Autofac;
using HybirdFrameworkCore.Configuration; using HybirdFrameworkCore.Configuration;
using log4net; using log4net;
using Newtonsoft.Json;
using Service.Execute.Api; using Service.Execute.Api;
using Service.Execute.Model; using Service.Execute.Model;
using Service.Execute.Model.Tbox; using Service.Execute.Model.Tbox;
@ -65,7 +66,9 @@ public class CarCtrlState : IState
machine.VelUnlockFlag = true; machine.VelUnlockFlag = true;
_CommonMgr.InsertStep(InfoEnum.BusinessSwappingStep.VelUnlockFlag, _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 = AppInfo.Container.Resolve<SoundClient>();
SoundClient.SoundPlay(SoundEnum.music93); SoundClient.SoundPlay(SoundEnum.music93);

@ -16,6 +16,9 @@ using Service.Led;
using Service.Padar.Client; using Service.Padar.Client;
using Service.RealTime; using Service.RealTime;
using Service.Sound.SoundClient; using Service.Sound.SoundClient;
using Service.Station;
using System.Runtime.CompilerServices;
using Newtonsoft.Json;
namespace Service.Execute.Step; namespace Service.Execute.Step;
@ -52,6 +55,7 @@ public class CarPrepareState : IState
{ {
return SwappingStateMachine.ReturnWithInvokeErr(checkTBoxConnect, ExceptionReason.None); return SwappingStateMachine.ReturnWithInvokeErr(checkTBoxConnect, ExceptionReason.None);
} }
//车辆本地验证 //车辆本地验证
InvokeStatus checkTBoxVelLocal = CheckTBoxVelLocalFlag(machine); InvokeStatus checkTBoxVelLocal = CheckTBoxVelLocalFlag(machine);
@ -59,6 +63,7 @@ public class CarPrepareState : IState
{ {
return SwappingStateMachine.ReturnWithInvokeErr(checkTBoxVelLocal, ExceptionReason.None); return SwappingStateMachine.ReturnWithInvokeErr(checkTBoxVelLocal, ExceptionReason.None);
} }
machine.ExceptionReason = ExceptionReason.None; machine.ExceptionReason = ExceptionReason.None;
@ -75,14 +80,9 @@ public class CarPrepareState : IState
{ {
return SwappingStateMachine.ReturnWithInvokeErr(selectPack, ExceptionReason.StopChargingError); 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); var adjustCarByRadar = AdjustCarByRadar(machine);
@ -91,6 +91,15 @@ public class CarPrepareState : IState
return SwappingStateMachine.ReturnWithInvokeErr(adjustCarByRadar, ExceptionReason.None); 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; machine.VehiclesInPlaceFlag = true;
_CommonMgr.InsertStep(InfoEnum.BusinessSwappingStep.CarInPositionFlag, _CommonMgr.InsertStep(InfoEnum.BusinessSwappingStep.CarInPositionFlag,
machine); machine,param:JsonConvert.SerializeObject(tboxCarInfoModel));
} }
}, () => }, () =>
{ {
@ -396,7 +405,7 @@ public class CarPrepareState : IState
//选包成功 //选包成功
_CommonMgr.LockBinAndUpdateAmt(orderBatteryInfo); _CommonMgr.LockBinAndUpdateAmt(orderBatteryInfo);
machine.SwapOrderBatteryInfo = orderBatteryInfo; machine.SwapOrderBatteryInfo = orderBatteryInfo;
_CommonMgr.SaveSwapBattery(machine);
machine.SelectPackFlag = true; machine.SelectPackFlag = true;
} }
}, () => }, () =>

@ -6,6 +6,7 @@ using Entity.DbModel.Station;
using HybirdFrameworkCore.Autofac; using HybirdFrameworkCore.Autofac;
using HybirdFrameworkCore.Configuration; using HybirdFrameworkCore.Configuration;
using log4net; using log4net;
using Newtonsoft.Json;
using Repository.Station; using Repository.Station;
using Service.Charger.Client; using Service.Charger.Client;
using Service.Execute.Api; 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> /// <summary>
/// 下发plc启动换电 /// 下发plc启动换电
@ -157,7 +136,9 @@ public class DoSwappingState : IState
machine.SwapOrderBatteryInfo.UpBinInfo.No); machine.SwapOrderBatteryInfo.UpBinInfo.No);
_CommonMgr.InsertStep(InfoEnum.BusinessSwappingStep.DistributeSelectPackFlag, _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, _CommonMgr.InsertStep(InfoEnum.BusinessSwappingStep.StartSwappingFlag,
machine); machine);

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

@ -4,6 +4,7 @@ using Entity.Constant;
using HybirdFrameworkCore.Autofac; using HybirdFrameworkCore.Autofac;
using HybirdFrameworkCore.Configuration; using HybirdFrameworkCore.Configuration;
using log4net; using log4net;
using Newtonsoft.Json;
using Service.Execute.Api; using Service.Execute.Api;
using Service.Execute.Model.Tbox; using Service.Execute.Model.Tbox;
using Service.Execute.SwapException; using Service.Execute.SwapException;
@ -198,7 +199,10 @@ public class SwapDoneState : IState
if (carInfo.Result?.CarStatus?.LockStatus == 2 || machine.ManualConfirmCarLockFlag) if (carInfo.Result?.CarStatus?.LockStatus == 2 || machine.ManualConfirmCarLockFlag)
{ {
_CommonMgr.InsertStep(InfoEnum.BusinessSwappingStep.VelLockFlag, _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, //_CommonMgr.InsertStep(InfoEnum.BusinessSwappingStep.VelLockFlag,
// machine); // machine);
var SoundClient = AppInfo.Container.Resolve<SoundClient>(); 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 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; }
@ -70,12 +72,16 @@ public class SwappingStateMachine : IDisposable
public ConcurrentDictionary<string, StepModel> StepModel = public ConcurrentDictionary<string, StepModel> StepModel =
new ConcurrentDictionary<string, StepModel> new ConcurrentDictionary<string, StepModel>
(); ();
#region 小步状态 #region 小步状态
//雷达检测/车辆进入 //雷达检测/车辆进入
public bool RadarInFlag = false; public bool RadarInFlag = false;
public bool RfidConnectFlag = false;
//开始读rf //开始读rf
public bool BeginRfidReadFlag = false; public bool BeginRfidReadFlag = false;
@ -253,10 +259,8 @@ public class SwappingStateMachine : IDisposable
public void Reset() public void Reset()
{ {
Log.Info("reset data"); Log.Info("reset data");
/*if (PlcMgr.PlcClient?.ReadTaskNo() == 1) /*if (PlcMgr.PlcClient?.ReadTaskNo() == 1)
{ {
PlcMgr.PlcClient?.ExChangeTaskNo(0); PlcMgr.PlcClient?.ExChangeTaskNo(0);
@ -338,9 +342,7 @@ public class SwappingStateMachine : IDisposable
Array values = Enum.GetValues(typeof(InfoEnum.BusinessSwappingStep)); Array values = Enum.GetValues(typeof(InfoEnum.BusinessSwappingStep));
foreach (var value in values) foreach (var value in values)
{ {
StepModel[value.ToInt() + ""] = new StepModel()
StepModel[value.ToInt()+""] = new StepModel()
{ {
StepNo = (int)value, StepNo = (int)value,
Status = 0, Status = 0,
@ -363,7 +365,7 @@ public class SwappingStateMachine : IDisposable
{ {
RadarInFlag = false; RadarInFlag = false;
RfidConnectFlag = false;
BeginRfidReadFlag = false; BeginRfidReadFlag = false;
@ -437,22 +439,20 @@ public class SwappingStateMachine : IDisposable
//关于仓库锁定相关重置 //关于仓库锁定相关重置
private void ResetOrderAmtStatus() private void ResetOrderAmtStatus()
{ {
// SoundApi.PlayOneSound((int)InfoEnum.SwapInfo.ErrorTBoxConn); // SoundApi.PlayOneSound((int)InfoEnum.SwapInfo.ErrorTBoxConn);
LedClient.SendMsgByKey(InfoEnum.SwapInfo.WelcomeInfo.GetLed()); LedClient.SendMsgByKey(InfoEnum.SwapInfo.WelcomeInfo.GetLed());
BinInfoRepository.Update(it => new BinInfo { AmtLock = 0 }, BinInfoRepository.Update(it => new BinInfo { AmtLock = 0 },
it => it.AmtLock == 1); it => it.AmtLock == 1);
//仓库解锁 //仓库解锁
if (SwapOrderBatteryInfo != null) if (SwapOrderBatteryInfo != null)
{ {
if (SwapOrderBatteryInfo?.UpBinInfo != null) ; 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; CancelFlag = true;
Thread.Sleep(2000); Thread.Sleep(2000);
} }
} }
public enum SwappingState public enum SwappingState
@ -493,4 +495,4 @@ public enum SwappingState
Exception, Exception,
Canceled, Canceled,
ManualSucc, ManualSucc,
} }

@ -1,7 +1,11 @@
using Entity.Constant;
using HslCommunication.Enthernet;
using HybirdFrameworkCore.Autofac.Attribute; using HybirdFrameworkCore.Autofac.Attribute;
using HybirdFrameworkCore.Entity; using HybirdFrameworkCore.Entity;
using HybirdFrameworkDriver.TcpClient; using HybirdFrameworkDriver.TcpClient;
using log4net; using log4net;
using Service.Execute;
using Service.Execute.Model;
using Decoder = Service.Padar.Codec.Decoder; using Decoder = Service.Padar.Codec.Decoder;
using Encoder = Service.Padar.Codec.Encoder; using Encoder = Service.Padar.Codec.Encoder;
@ -10,10 +14,12 @@ namespace Service.Padar.Client;
[Scope] [Scope]
public class PadarClient : TcpClient<IBaseHandler, Decoder, Encoder> public class PadarClient : TcpClient<IBaseHandler, Decoder, Encoder>
{ {
private readonly String DEVICE_CODE = "radar";
/// <summary> /// <summary>
/// 0-雷达不工作1-无车2-无电池3-角度偏移过大4-车辆靠后5-车辆靠前6-车辆到位 /// 0-雷达不工作1-无车2-无电池3-角度偏移过大4-车辆靠后5-车辆靠前6-车辆到位
/// </summary> /// </summary>
public byte CarState =new byte(); public byte CarState = new byte();
public static readonly byte[] StartChar = { 0xFE, 0x68 }; public static readonly byte[] StartChar = { 0xFE, 0x68 };
@ -28,7 +34,7 @@ public class PadarClient : TcpClient<IBaseHandler, Decoder, Encoder>
Log.Info($"padar connect succeed"); Log.Info($"padar connect succeed");
return Connected; return Connected;
} }
public override ILog Logger() public override ILog Logger()
{ {
return Log; return Log;
@ -50,6 +56,12 @@ public class PadarClient : TcpClient<IBaseHandler, Decoder, Encoder>
serialNum++; serialNum++;
sendBytes[3] = byte3; sendBytes[3] = byte3;
this.Channel.WriteAndFlushAsync(sendBytes); 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(); 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 Entity.DbModel.Station;
using HybirdFrameworkCore.Autofac; using HybirdFrameworkCore.Autofac;
using HybirdFrameworkCore.Autofac.Attribute; using HybirdFrameworkCore.Autofac.Attribute;
@ -6,11 +8,13 @@ using HybirdFrameworkCore.Entity;
using HybirdFrameworkDriver.Session; using HybirdFrameworkDriver.Session;
using HybirdFrameworkDriver.TcpClient; using HybirdFrameworkDriver.TcpClient;
using log4net; using log4net;
using Newtonsoft.Json;
using Repository.Station; using Repository.Station;
using Service.Charger.Client; using Service.Charger.Client;
using Service.Charger.Codec; using Service.Charger.Codec;
using Service.Charger.Handler; using Service.Charger.Handler;
using Service.Charger.Msg.Host.Req; using Service.Charger.Msg.Host.Req;
using Service.Execute;
namespace Service.Charger.Server; namespace Service.Charger.Server;
@ -70,6 +74,11 @@ public class PlcClient : TcpClient<IBaseHandler, Decoder, Encoder>
InitializeCommandReq req = new InitializeCommandReq(); InitializeCommandReq req = new InitializeCommandReq();
this.Channel.WriteAndFlushAsync(req); this.Channel.WriteAndFlushAsync(req);
StationSoftMgr.PutDeviceLog((int)StationConstant.DeviceCode.Plc,SwapConstant.PlcProtocol.Init,
JsonConvert.SerializeObject(req),(int)SwapConstant.CommunicationType.Send);
return Result<bool>.Success(); return Result<bool>.Success();
} }

@ -23,6 +23,7 @@ using Service.Execute.Model;
using Service.Execute.Utils; using Service.Execute.Utils;
using Service.Init; using Service.Init;
using Service.Mgr; using Service.Mgr;
using Service.Padar.Client;
using SqlSugar; using SqlSugar;
namespace Service.Station; namespace Service.Station;
@ -145,43 +146,9 @@ public class MonitorService
monitorScreenResp.VehicleInfo.DownBatteryBinNo = queryByClauseAsync.DownBatteryBinNo; monitorScreenResp.VehicleInfo.DownBatteryBinNo = queryByClauseAsync.DownBatteryBinNo;
monitorScreenResp.VehicleInfo.UpBatteryBinNo = queryByClauseAsync.UpBatteryBinNo; monitorScreenResp.VehicleInfo.UpBatteryBinNo = queryByClauseAsync.UpBatteryBinNo;
} }
//SwapMonitorScreenResp monitorScreenResp = new()
//{
monitorScreenResp.DeviceLogs = StationSoftMgr.DeviceLogs;
// 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()
// }
//};
return Result<SwapMonitorScreenResp>.Success(monitorScreenResp); return Result<SwapMonitorScreenResp>.Success(monitorScreenResp);
} }
@ -217,7 +184,9 @@ public class MonitorService
{ {
BoxConnectFlag = isConnected, BoxConnectFlag = isConnected,
// CloudConnectFlag = CloudClientMgr.CloudClient == null ? false : CloudClientMgr.CloudClient.Connected, // 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); return Result<DeviceStateResp>.Success(resp);

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

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

@ -3,6 +3,7 @@ using System.Transactions;
using AutoMapper; using AutoMapper;
using Entity.Api.Req; using Entity.Api.Req;
using Entity.Api.Resp; using Entity.Api.Resp;
using Entity.Constant;
using Entity.DbModel.Station; using Entity.DbModel.Station;
using Entity.Dto; using Entity.Dto;
using HybirdFrameworkCore.Entity; using HybirdFrameworkCore.Entity;
@ -23,7 +24,6 @@ namespace WebStarter.Controllers;
[Route("api/[controller]")] [Route("api/[controller]")]
public class SwapOrderController : ControllerBase public class SwapOrderController : ControllerBase
{ {
private static readonly ILog Log = LogManager.GetLogger(typeof(SwapOrderController)); private static readonly ILog Log = LogManager.GetLogger(typeof(SwapOrderController));
private readonly SwapOrderService swapOrderService; private readonly SwapOrderService swapOrderService;
private readonly SwapOrderBatteryService swapOrderBatteryService; private readonly SwapOrderBatteryService swapOrderBatteryService;
@ -33,8 +33,9 @@ public class SwapOrderController : ControllerBase
private readonly BaseVehicleRepository _baseVehicleRepository; private readonly BaseVehicleRepository _baseVehicleRepository;
public SwapOrderController(SwapOrderService swapOrderService, SwapOrderBatteryService swapOrderBatteryService, public SwapOrderController(SwapOrderService swapOrderService, SwapOrderBatteryService swapOrderBatteryService,
SwapOrderStepService swapOrderStepService,SwapOrderReportCloudRepository swapOrderReportCloudRepository,BaseVehicleRepository baseVehicleRepository SwapOrderStepService swapOrderStepService, SwapOrderReportCloudRepository swapOrderReportCloudRepository,
) BaseVehicleRepository baseVehicleRepository
)
{ {
this.swapOrderService = swapOrderService; this.swapOrderService = swapOrderService;
this.swapOrderBatteryService = swapOrderBatteryService; this.swapOrderBatteryService = swapOrderBatteryService;
@ -51,17 +52,18 @@ public class SwapOrderController : ControllerBase
public async Task<Result<PageResult<SwapOrderResp>>> QueryPage([FromBody] QuerySwapOrderPageReq req) public async Task<Result<PageResult<SwapOrderResp>>> QueryPage([FromBody] QuerySwapOrderPageReq req)
{ {
Log.Info($"SwapOrderController QueryPage req={req}"); 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); var result = BatteryCodeList(req);
return Result<PageResult<SwapOrderResp>>.Success(result); return Result<PageResult<SwapOrderResp>>.Success(result);
} }
Log.Info($"查询换电订单 SwapOrderController start QueryPage swapOrderService.QuerySwapOrder req={req}"); Log.Info($"查询换电订单 SwapOrderController start QueryPage swapOrderService.QuerySwapOrder req={req}");
var swapOrderResp = swapOrderService.QuerySwapOrder(req); var swapOrderResp = swapOrderService.QuerySwapOrder(req);
Log.Info($"查询换电订单 SwapOrderController end QueryPage swapOrderService.QuerySwapOrder req={req}"); Log.Info($"查询换电订单 SwapOrderController end QueryPage swapOrderService.QuerySwapOrder req={req}");
PackageSwapOrder(swapOrderResp); PackageSwapOrder(swapOrderResp);
List<SwapOrderResp>? list = swapOrderResp.Rows; List<SwapOrderResp>? list = swapOrderResp.Rows;
List<string> vehicleNoList = list?.Select(resp => resp.VehicleNo).ToList() ?? new List<string>(); List<string> vehicleNoList = list?.Select(resp => resp.VehicleNo).ToList() ?? new List<string>();
// 查询车辆的部门 // 查询车辆的部门
@ -74,16 +76,17 @@ public class SwapOrderController : ControllerBase
foreach (var swapOrder in list) foreach (var swapOrder in list)
{ {
var matchingVehicle = vehicleList.FirstOrDefault(v => v.VehicleNo == swapOrder.VehicleNo); var matchingVehicle = vehicleList.FirstOrDefault(v => v.VehicleNo == swapOrder.VehicleNo);
if (matchingVehicle != null) if (matchingVehicle != null)
{ {
swapOrder.Company = matchingVehicle.Company; swapOrder.Company = matchingVehicle.Company;
swapOrder.Departments = matchingVehicle.Departments; swapOrder.Departments = matchingVehicle.Departments;
} }
} }
return Result<PageResult<SwapOrderResp>>.Success(swapOrderResp); return Result<PageResult<SwapOrderResp>>.Success(swapOrderResp);
} }
/// <summary> /// <summary>
/// app查询换电订单 /// app查询换电订单
/// </summary> /// </summary>
@ -93,11 +96,11 @@ public class SwapOrderController : ControllerBase
public async Task<Result<PageResult<SwapOrderResp>>> AppSwapOrder([FromBody] QuerySwapOrderPageReq req) public async Task<Result<PageResult<SwapOrderResp>>> AppSwapOrder([FromBody] QuerySwapOrderPageReq req)
{ {
Log.Info($"SwapOrderController QueryPage req={req}"); Log.Info($"SwapOrderController QueryPage req={req}");
Log.Info($"查询换电订单 SwapOrderController start QueryPage swapOrderService.QuerySwapOrder req={req}"); Log.Info($"查询换电订单 SwapOrderController start QueryPage swapOrderService.QuerySwapOrder req={req}");
var swapOrderResp = swapOrderService.AppQuerySwapOrder(req); var swapOrderResp = swapOrderService.AppQuerySwapOrder(req);
Log.Info($"查询换电订单 SwapOrderController end QueryPage swapOrderService.QuerySwapOrder req={req}"); Log.Info($"查询换电订单 SwapOrderController end QueryPage swapOrderService.QuerySwapOrder req={req}");
PackageSwapOrder(swapOrderResp); PackageSwapOrder(swapOrderResp);
return Result<PageResult<SwapOrderResp>>.Success(swapOrderResp); return Result<PageResult<SwapOrderResp>>.Success(swapOrderResp);
} }
@ -106,31 +109,28 @@ public class SwapOrderController : ControllerBase
{ {
//获取所有订单号 //获取所有订单号
var orderSns = swapOrderResp.Rows.Select(row => row.Sn).ToList(); 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); //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 = List<SwapOrderBattery> batteryList =
swapOrderBatteryService.QueryListByClause(u => orderSns.Contains(u.SwapOrderSn)); swapOrderBatteryService.QueryListByClause(u => orderSns.Contains(u.SwapOrderSn));
Log.Info($"查询订单电池数据 SwapOrderController end QueryPage swapOrderBatteryService.QueryListByClause req={orderSns}");
//映射 //映射
var config = var config =
new MapperConfiguration(cfg => cfg.CreateMap<SwapOrderBatteryResp, SwapOrderBattery>().ReverseMap()); new MapperConfiguration(cfg => cfg.CreateMap<SwapOrderBatteryResp, SwapOrderBattery>().ReverseMap());
IMapper mapper = config.CreateMapper(); IMapper mapper = config.CreateMapper();
List<SwapOrderBatteryResp> swapOrderBattery = mapper.Map<List<SwapOrderBatteryResp>>(batteryList); List<SwapOrderBatteryResp> swapOrderBattery = mapper.Map<List<SwapOrderBatteryResp>>(batteryList);
Log.Info($"查询公里数 SwapOrderController start QueryPage swapOrderReportCloudRepository.QueryListByClause req={orderSns}"); List<SwapOrderReportCloud> swapOrderReportClouds =
List<SwapOrderReportCloud> swapOrderReportClouds = swapOrderReportCloudRepository.QueryListByClause(u => orderSns.Contains(u.SwapOrderSn)); swapOrderReportCloudRepository.QueryListByClause(u => orderSns.Contains(u.SwapOrderSn));
Log.Info($"查询公里数 SwapOrderController end QueryPage swapOrderReportCloudRepository.QueryListByClause req={orderSns}");
//将电池数据添加到换电订单数据中 //将电池数据添加到换电订单数据中
foreach (var row in swapOrderResp.Rows) foreach (var row in swapOrderResp.Rows)
{ {
row.BatteryList = swapOrderBattery.Where(battery => battery.SwapOrderSn == row.Sn).ToList(); row.BatteryList = swapOrderBattery.Where(battery => battery.SwapOrderSn == row.Sn).ToList();
var matchingReport = swapOrderReportClouds.FirstOrDefault(r => r.SwapOrderSn == row.Sn); var matchingReport = swapOrderReportClouds.FirstOrDefault(r => r.SwapOrderSn == row.Sn);
if (matchingReport != null) if (matchingReport != null)
@ -141,44 +141,48 @@ public class SwapOrderController : ControllerBase
} }
} }
} }
Log.Info($"查询订单步序数据 SwapOrderController start QueryPage swapOrderStepService.QueryListByClause req={orderSns}");
//查询订单步序数据 //查询订单步序数据
var stepList = swapOrderStepService.QueryListByClause(u => orderSns.Contains(u.SwapOrderSn)); 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(); stepList = stepList.OrderBy(s => s.Sort).ToList();
//映射 //映射
var config2 = new MapperConfiguration(cfg => cfg.CreateMap<SwapOrderStep, SwapOrderStepResp>().ReverseMap()); var config2 = new MapperConfiguration(cfg => cfg.CreateMap<SwapOrderStep, SwapOrderStepResp>().ReverseMap());
IMapper mapper2 = config2.CreateMapper(); IMapper mapper2 = config2.CreateMapper();
List<SwapOrderStepResp> swapOrderStep = mapper2.Map<List<SwapOrderStepResp>>(stepList); List<SwapOrderStepResp> swapOrderStep = mapper2.Map<List<SwapOrderStepResp>>(stepList);
//将步序数据添加到换电订单数据中 //将步序数据添加到换电订单数据中
for (int i = 0; i < swapOrderResp.Rows.Count; i++) for (int i = 0; i < swapOrderResp.Rows.Count; i++)
{ {
swapOrderResp.Rows[i].StepList = new List<SwapOrderStepResp>(); swapOrderResp.Rows[i].StepList = new List<SwapOrderStepResp>();
var swapOrderStepResps = swapOrderStep.Where(step => step.SwapOrderSn == swapOrderResp.Rows[i].Sn).ToList();
swapOrderResp.Rows[i].StepList 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());
} }
} }
private PageResult<SwapOrderResp> BatteryCodeList(QuerySwapOrderPageReq req) private PageResult<SwapOrderResp> BatteryCodeList(QuerySwapOrderPageReq req)
{ {
PageResult<SwapOrderBatteryResp> batteryCodeList = swapOrderBatteryService.QuerySwapOrderBatteryList(req); PageResult<SwapOrderBatteryResp> batteryCodeList = swapOrderBatteryService.QuerySwapOrderBatteryList(req);
var batteryOrderSn = batteryCodeList.Rows.Select(row => row.SwapOrderSn).ToList(); var batteryOrderSn = batteryCodeList.Rows.Select(row => row.SwapOrderSn).ToList();
List<SwapOrder> swapOrderRespList = swapOrderService.QueryListByClause(u => batteryOrderSn.Contains(u.Sn)); List<SwapOrder> swapOrderRespList = swapOrderService.QueryListByClause(u => batteryOrderSn.Contains(u.Sn));
//获取所有订单号 //获取所有订单号
var orderSns = swapOrderRespList.Select(row => row.Sn).ToList(); var orderSns = swapOrderRespList.Select(row => row.Sn).ToList();
////查询订单电池数据 ////查询订单电池数据
List<SwapOrderBattery> batteryList = List<SwapOrderBattery> batteryList =
swapOrderBatteryService.QueryListByClause(u => orderSns.Contains(u.SwapOrderSn)); swapOrderBatteryService.QueryListByClause(u => orderSns.Contains(u.SwapOrderSn));
var config = new MapperConfiguration(cfg => var config = new MapperConfiguration(cfg =>
{ {
cfg.CreateMap<SwapOrderResp, SwapOrder>().ReverseMap(); cfg.CreateMap<SwapOrderResp, SwapOrder>().ReverseMap();
@ -186,12 +190,13 @@ public class SwapOrderController : ControllerBase
}); });
//映射 //映射
IMapper mapper = config.CreateMapper(); IMapper mapper = config.CreateMapper();
List<SwapOrderBatteryResp> swapOrderBattery = mapper.Map<List<SwapOrderBatteryResp>>(batteryList); List<SwapOrderBatteryResp> swapOrderBattery = mapper.Map<List<SwapOrderBatteryResp>>(batteryList);
List<SwapOrderResp> swapOrderResp = mapper.Map<List<SwapOrderResp>>(swapOrderRespList); 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++) for (int i = 0; i < list.Count; i++)
{ {
if (language == "en") if (language == "en")
{ {
SwapLoseOrderDto2 dto = list2[i]; SwapLoseOrderDto2 dto = list2[i];
@ -507,7 +511,6 @@ public class SwapOrderController : ControllerBase
{ {
dto.DownBatteryBinNo = swapOrderBatteryResp.DownBatteryBinNo; dto.DownBatteryBinNo = swapOrderBatteryResp.DownBatteryBinNo;
dto.UpBatteryBinNo = swapOrderBatteryResp.UpBatteryBinNo; dto.UpBatteryBinNo = swapOrderBatteryResp.UpBatteryBinNo;
} }
} }
else else
@ -519,7 +522,6 @@ public class SwapOrderController : ControllerBase
{ {
dto.DownBatteryBinNo = swapOrderBatteryResp.DownBatteryBinNo; dto.DownBatteryBinNo = swapOrderBatteryResp.DownBatteryBinNo;
dto.UpBatteryBinNo = swapOrderBatteryResp.UpBatteryBinNo; 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 '总费用(所有的总费用)'; 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 ALTER TABLE swap_order_battery
ADD COLUMN nominal_energy DECIMAL(24, 2) COMMENT '电池标称能量'; ADD COLUMN nominal_energy DECIMAL(24, 2) COMMENT '电池标称能量';

Loading…
Cancel
Save