关于并行任务的更改

master
rszn 5 months ago
parent 0e34dab0ca
commit 4fb7cbfbf4

@ -0,0 +1,70 @@
using SqlSugar;
namespace Entity.DbModel.Station;
///<summary>
///充电订单;充电订单表
///</summary>
[SugarTable("move_bin_record")]
public class MoveBinRecord : BaseModel
{
/// <summary>
/// Desc:id
/// Default:
/// Nullable:False
/// </summary>
[SugarColumn(IsPrimaryKey = true, ColumnName = "id")]
public int Id { get; set; }
/// <summary>
/// in_bin_no
/// </summary>
[SugarColumn(IsPrimaryKey = true, ColumnName = "in_bin_no")]
public string? InBinNo { get; set; }
/// <summary>
/// in_battery_no
/// </summary>
[SugarColumn(IsPrimaryKey = true, ColumnName = "in_battery_no")]
public string? InBatteryNo { get; set; }
/// <summary>
/// in_battery_soc
/// </summary>
[SugarColumn(IsPrimaryKey = true, ColumnName = "in_battery_soc")]
public string? InBatterySoc { get; set; }
/// <summary>
/// in_bin_no
/// </summary>
[SugarColumn(IsPrimaryKey = true, ColumnName = "up_bin_no")]
public string? UpBinNo { get; set; }
/// <summary>
/// in_battery_no
/// </summary>
[SugarColumn(IsPrimaryKey = true, ColumnName = "up_battery_no")]
public string? UpBatteryNo { get; set; }
/// <summary>
/// in_battery_soc
/// </summary>
[SugarColumn(IsPrimaryKey = true, ColumnName = "up_battery_soc")]
public string? UpBatterySoc { get; set; }
/// <summary>
/// 狀態 0初始化 1進行中 2成功 3失敗
/// </summary>
[SugarColumn(IsPrimaryKey = true, ColumnName = "status")]
public int Status { get; set; }
/// <summary>
/// 类型 0自动 1:手动
/// </summary>
[SugarColumn(IsPrimaryKey = true, ColumnName = "type")]
public int Type { get; set; }
}

@ -19,25 +19,36 @@ public class BinInfoRepository : BaseRepository<BinInfo>
/// <param name="swapSoc"> StaticStationInfo.SwapSoc </param> /// <param name="swapSoc"> StaticStationInfo.SwapSoc </param>
/// <param name="swapFinishChargeTime">StaticStationInfo.SwapFinishChargeTime</param> /// <param name="swapFinishChargeTime">StaticStationInfo.SwapFinishChargeTime</param>
/// <returns></returns> /// <returns></returns>
public SelectPackDto SelectPack(int swapSoc, int swapFinishChargeTime) public SelectPackDto SelectPack(int swapSoc, int swapFinishChargeTime, string upMoveNo)
{ {
SelectPackDto selectPackDto = new() SelectPackDto selectPackDto = new()
{ {
SuccessFlag = false, SuccessFlag = false,
}; };
List<BinInfo> list = List<BinInfo> list =
QueryListByClause(i => i.CacheBinFlag == 0 && i.CanSwapFlag==1 && QueryListByClause(i => i.CanSwapFlag == 1 &&
i.Exists == 1 && i.Status == 1 && i.AmtLock == (int)InfoEnum.AmtBatLockStatus.UnLock, i.Exists == 1 && i.Status == 1 && i.AmtLock == (int)InfoEnum.AmtBatLockStatus.UnLock,
"in_time asc"); "in_time asc");
BinInfo? cacheBinBattery = ChooseCacheBinBattery(swapSoc);
if (list.Count <= 0 && cacheBinBattery == null)
// BinInfo? cacheBinBattery = ChooseCacheBinBattery(swapSoc);
if (list.Count <= 0)
{ {
selectPackDto.Info = InfoEnum.SelectBinStatusInfo.NoBattery; selectPackDto.Info = InfoEnum.SelectBinStatusInfo.NoBattery;
return selectPackDto; return selectPackDto;
} }
list = list.Where(i => i.ChargeStatus == 2 || i.ChargeStatus==4).ToList(); list = list.OrderBy(i => i.CacheBinFlag).ToList();
if (list.Count <= 0 && cacheBinBattery == null)
if (!string.IsNullOrWhiteSpace(upMoveNo))
{
list = list.Where(i => !upMoveNo.Equals(i.No) && (i.No != "" || i.No != "-1")).ToList();
}
list = list.Where(i => i.ChargeStatus == 2 || i.ChargeStatus == 4).ToList();
if (list.Count <= 0)
{ {
selectPackDto.Info = InfoEnum.SelectBinStatusInfo.LessOfFinishCharging; selectPackDto.Info = InfoEnum.SelectBinStatusInfo.LessOfFinishCharging;
return selectPackDto; return selectPackDto;
@ -45,7 +56,7 @@ public class BinInfoRepository : BaseRepository<BinInfo>
list = list.Where(i => i.Soc != null && i.Soc >= swapSoc).ToList(); list = list.Where(i => i.Soc != null && i.Soc >= swapSoc).ToList();
if (list.Count <= 0 && cacheBinBattery == null) if (list.Count <= 0)
{ {
selectPackDto.Info = InfoEnum.SelectBinStatusInfo.LessOfSoc; selectPackDto.Info = InfoEnum.SelectBinStatusInfo.LessOfSoc;
return selectPackDto; return selectPackDto;
@ -54,20 +65,15 @@ public class BinInfoRepository : BaseRepository<BinInfo>
list = list.Where(i => i.LastChargeFinishTime != null && new TimeSpan(DateTime.Now.Ticks - list = list.Where(i => i.LastChargeFinishTime != null && new TimeSpan(DateTime.Now.Ticks -
i.LastChargeFinishTime.ToDateTime().Ticks) i.LastChargeFinishTime.ToDateTime().Ticks)
.TotalMinutes > swapFinishChargeTime).ToList(); .TotalMinutes > swapFinishChargeTime).ToList();
if (list.Count <= 0 && cacheBinBattery == null) if (list.Count <= 0)
{ {
selectPackDto.Info = InfoEnum.SelectBinStatusInfo.LessOf3Minute; selectPackDto.Info = InfoEnum.SelectBinStatusInfo.LessOf3Minute;
return selectPackDto; return selectPackDto;
} }
if (list.Count > 0)
{ selectPackDto.BinInfo = list[0];
selectPackDto.BinInfo = list[0];
}
else
{
selectPackDto.BinInfo = cacheBinBattery;
}
selectPackDto.Info = InfoEnum.SelectBinStatusInfo.Success; selectPackDto.Info = InfoEnum.SelectBinStatusInfo.Success;
selectPackDto.SuccessFlag = true; selectPackDto.SuccessFlag = true;
@ -84,7 +90,7 @@ public class BinInfoRepository : BaseRepository<BinInfo>
public BinInfo? ChooseCacheBinBattery(int swapSoc) public BinInfo? ChooseCacheBinBattery(int swapSoc)
{ {
return return
QueryByClause(i => i.CacheBinFlag == 1 && i.CanSwapFlag==1 && i.Soc >= swapSoc && QueryByClause(i => i.CacheBinFlag == 1 && i.CanSwapFlag == 1 && i.Soc >= swapSoc &&
i.Exists == 1 && i.Status == 1 && i.AmtLock == (int)InfoEnum.AmtBatLockStatus.UnLock); i.Exists == 1 && i.Status == 1 && i.AmtLock == (int)InfoEnum.AmtBatLockStatus.UnLock);
} }
} }

@ -0,0 +1,14 @@
using Entity.DbModel.Station;
using HybirdFrameworkCore.Autofac.Attribute;
using SqlSugar;
namespace Repository.Station;
[Scope("SingleInstance")]
public class MoveBinRecordRepository:BaseRepository<MoveBinRecord>
{
public MoveBinRecordRepository(ISqlSugarClient sqlSugar) : base(sqlSugar)
{
}
}

@ -123,12 +123,26 @@ public class PlcApi
/// <returns></returns> /// <returns></returns>
public static bool ReadTaskStatus(ushort taskNo) public static bool ReadTaskStatus(ushort taskNo)
{ {
PlcMgr.ResetPlc();
Log.Info($"PlcApi ReadTaskStatus param= taskNo={taskNo}"); Log.Info($"PlcApi ReadTaskStatus param= taskNo={taskNo}");
var readTaskStatus = PlcMgr.ReadTaskStatus(taskNo); var readTaskStatus = PlcMgr.ReadTaskStatus(taskNo);
Log.Info($"PlcApi ReadTaskStatus resp={readTaskStatus}"); Log.Info($"PlcApi ReadTaskStatus resp={readTaskStatus}");
return readTaskStatus; return readTaskStatus;
} }
/// <summary>
/// 读取任务状态
/// </summary>
/// <returns></returns>
public static bool ReadTaskStatusReset()
{
PlcMgr.ResetPlc();
Log.Info($"PlcApi ReadTaskStatus param= taskNo={0}");
var readTaskStatus = PlcMgr.ReadTaskStatus(0);
Log.Info($"PlcApi ReadTaskStatus resp={readTaskStatus}");
return readTaskStatus;
}
/// <summary> /// <summary>
/// plc上使能 /// plc上使能
/// </summary> /// </summary>
@ -162,6 +176,7 @@ public class PlcApi
/// <returns>6未连接</returns> /// <returns>6未连接</returns>
public static int ReadPlcTaskStatus() public static int ReadPlcTaskStatus()
{ {
PlcMgr.ResetPlc();
Log.Info($"PlcApi start ReadPlcTaskStatus "); Log.Info($"PlcApi start ReadPlcTaskStatus ");
var readPlcTaskStatus = PlcMgr.ReadPlcTaskStatus(); var readPlcTaskStatus = PlcMgr.ReadPlcTaskStatus();
Log.Info($"PlcApi ReadPlcTaskStatus resp= {readPlcTaskStatus}"); Log.Info($"PlcApi ReadPlcTaskStatus resp= {readPlcTaskStatus}");

@ -6,9 +6,12 @@ using Entity.Dto;
using HybirdFrameworkCore.Autofac; using HybirdFrameworkCore.Autofac;
using HybirdFrameworkCore.Autofac.Attribute; using HybirdFrameworkCore.Autofac.Attribute;
using Repository.Station; using Repository.Station;
using Service.Execute.Api;
using Service.Execute.Model; using Service.Execute.Model;
using Service.Init; using Service.Init;
using Service.Plc.Client;
using Service.Station; using Service.Station;
using SqlSugar;
namespace Service.Execute.Utils; namespace Service.Execute.Utils;
@ -24,6 +27,8 @@ public class CommonMgr
public SwapOrderReportCloudRepository _swapOrderReportCloudRepository { get; set; } public SwapOrderReportCloudRepository _swapOrderReportCloudRepository { get; set; }
public MoveBinRecordRepository MoveBinRecordRepository { get; set; }
/// <summary> /// <summary>
/// 新增小步状态 /// 新增小步状态
/// </summary> /// </summary>
@ -156,17 +161,43 @@ public class CommonMgr
/// <summary> /// <summary>
/// 取电池判断 /// 取电池判断
/// 不能选正在执行移仓的电池
/// </summary> /// </summary>
/// <param name="orderBatteryInfo"></param> /// <param name="orderBatteryInfo"></param>
public void UpBin(SwapOrderBatteryInfo orderBatteryInfo) public void UpBin(SwapOrderBatteryInfo orderBatteryInfo)
{ {
SelectPackDto selectPack = SelectPackDto selectPack =
_binInfoRepository.SelectPack(StaticStationInfo.SwapSoc, StaticStationInfo.SwapFinishChargeTime); _binInfoRepository.SelectPack(StaticStationInfo.SwapSoc, StaticStationInfo.SwapFinishChargeTime,
queryMoveBinNo()[0]);
orderBatteryInfo.UpBinInfo = selectPack.BinInfo; orderBatteryInfo.UpBinInfo = selectPack.BinInfo;
orderBatteryInfo.CanSwap = selectPack.Info; orderBatteryInfo.CanSwap = selectPack.Info;
} }
private List<string> queryMoveBinNo()
{
string moveUp = "";
string moveIn = "";
//当前有移仓任务
if (PlcMgr.PlcClient.ReadTaskNo() == 2)
{
MoveBinRecord queryByClause = MoveBinRecordRepository.QueryByClause(i => i.Status == 0 || i.Status == 1,
i => i.CreatedTime,
OrderByType.Desc);
if (queryByClause != null)
{
moveUp = queryByClause.UpBinNo;
moveIn = queryByClause.InBinNo;
}
}
return new List<string>()
{
moveUp, moveIn
};
}
/// <summary> /// <summary>
/// 放电池判断:取出来的电池仓位能不能放 /// 放电池判断:取出来的电池仓位能不能放
/// </summary> /// </summary>
@ -185,6 +216,17 @@ public class CommonMgr
return; return;
} }
var value = queryMoveBinNo()[1];
if (!string.IsNullOrWhiteSpace(value))
{
list = list.Where(i => i.No != value).ToList();
}
if (list.Count <= 0)
{
orderBatteryInfo.CanSwap = InfoEnum.SelectBinStatusInfo.LessOfEmptyBin;
return;
}
orderBatteryInfo.InBinInfo = list[0]; orderBatteryInfo.InBinInfo = list[0];
orderBatteryInfo.InBinInfo.BatteryNo = "-1"; orderBatteryInfo.InBinInfo.BatteryNo = "-1";
orderBatteryInfo.InBinInfo.Soc = -1; orderBatteryInfo.InBinInfo.Soc = -1;
@ -194,7 +236,7 @@ public class CommonMgr
if (carInfoBatteryInfos != null && carInfoBatteryInfos.Count > 0) if (carInfoBatteryInfos != null && carInfoBatteryInfos.Count > 0)
{ {
orderBatteryInfo.InBinInfo.BatteryNo = carInfoBatteryInfos[0].BatteryNo; orderBatteryInfo.InBinInfo.BatteryNo = carInfoBatteryInfos[0].BatteryNo;
// orderBatteryInfo.InBinInfo.Soc = carInfoBatteryInfos[0].Soc; // orderBatteryInfo.InBinInfo.Soc = carInfoBatteryInfos[0].Soc;
orderBatteryInfo.InBinInfo.Soe = carInfoBatteryInfos[0].Soe; orderBatteryInfo.InBinInfo.Soe = carInfoBatteryInfos[0].Soe;
orderBatteryInfo.InBinInfo.Soh = carInfoBatteryInfos[0].Soh; orderBatteryInfo.InBinInfo.Soh = carInfoBatteryInfos[0].Soh;
} }
@ -277,4 +319,4 @@ public class CommonMgr
Vtm = Convert.ToSingle(machine.BoxCarInfoModel?.ElecMsg?.TotalMile), Vtm = Convert.ToSingle(machine.BoxCarInfoModel?.ElecMsg?.TotalMile),
}); });
} }
} }

@ -11,6 +11,7 @@ using Service.Execute.StaticTools;
using Service.Execute.SwapException; using Service.Execute.SwapException;
using Service.Execute.Utils; using Service.Execute.Utils;
using Service.Init; using Service.Init;
using Service.Plc.Client;
using Service.Station; using Service.Station;
namespace Service.Execute.Step; namespace Service.Execute.Step;
@ -100,6 +101,7 @@ public class DoSwappingState : IState
{ {
return SwappingStateMachine.ReturnWithInvokeErr(toInvokeStatus, ExceptionReason.None); return SwappingStateMachine.ReturnWithInvokeErr(toInvokeStatus, ExceptionReason.None);
} }
//查询换电任务是否结束
return new StateResult() return new StateResult()
@ -121,26 +123,36 @@ public class DoSwappingState : IState
bool unLock = result.Result; bool unLock = result.Result;
if (unLock) if (unLock)
{ {
//查询车辆锁止状态 //查询当前是否有任务执行
var startSwapping = PlcApi.StartSwapping(machine.SwapOrderBatteryInfo.InBinInfo.No,
machine.SwapOrderBatteryInfo.UpBinInfo.No);
//查詢當前任務狀態是否被更改 var readTaskNo = PlcMgr.PlcClient?.ReadTaskNo();
var readPlcTaskStatus = PlcApi.ReadTaskStatus(1); if (readTaskNo == 0 || readTaskNo==1)
if (startSwapping && readPlcTaskStatus)
{ {
machine.SwapOrder.SwapBeginTime = DateTime.Now; PlcMgr.PlcClient?.ExChangeTaskNo(1);
_CommonMgr.UpdateSwapOrder(machine); //查询车辆锁止状态
machine.SwapStatus = 0; var startSwapping = PlcApi.StartSwapping(machine.SwapOrderBatteryInfo.InBinInfo.No,
machine.StartSwappingFlag = true; machine.SwapOrderBatteryInfo.UpBinInfo.No);
_CommonMgr.InsertStep(InfoEnum.BusinessSwappingStep.StartSwappingFlag,
machine); //查詢當前任務狀態是否被更改
var readPlcTaskStatus = PlcApi.ReadTaskStatus(1);
if (startSwapping && readPlcTaskStatus)
{
machine.SwapOrder.SwapBeginTime = DateTime.Now;
_CommonMgr.UpdateSwapOrder(machine);
machine.SwapStatus = 0;
machine.StartSwappingFlag = true;
_CommonMgr.InsertStep(InfoEnum.BusinessSwappingStep.StartSwappingFlag,
machine);
}
}
else
{
_log.Info("当前有任务在执行");
} }
} }
}, () => }, () => { SoundApi.PlayOneSound((int)InfoEnum.SwapInfo.ErrStartSwap); }, false, () => { }, 10,
{ InvokeStatus.None);
SoundApi.PlayOneSound((int)InfoEnum.SwapInfo.ErrStartSwap);
},false, () => { },10,InvokeStatus.None);
} }
@ -240,7 +252,6 @@ public class DoSwappingState : IState
if (PlcApi.ReadPlcTaskStatus() == 1004) if (PlcApi.ReadPlcTaskStatus() == 1004)
{ {
} }
else else
{ {
@ -252,7 +263,7 @@ public class DoSwappingState : IState
_CommonMgr.InsertStep(InfoEnum.BusinessSwappingStep.OutNewBatteryFlag, _CommonMgr.InsertStep(InfoEnum.BusinessSwappingStep.OutNewBatteryFlag,
machine); machine);
} }
}, () => { SoundApi.PlayOneSound((int)InfoEnum.SwapInfo.InfoNewBatteryCarryOut);}, false, () => { }, 10, }, () => { SoundApi.PlayOneSound((int)InfoEnum.SwapInfo.InfoNewBatteryCarryOut); }, false, () => { }, 10,
InvokeStatus.None); InvokeStatus.None);
} }
@ -265,7 +276,6 @@ public class DoSwappingState : IState
// machine.LedTool?.WriteProgramContent(InfoEnum.SwapInfo.InfoPack.GetLed()); // machine.LedTool?.WriteProgramContent(InfoEnum.SwapInfo.InfoPack.GetLed());
if (PlcApi.ReadPlcTaskStatus() == 1005) if (PlcApi.ReadPlcTaskStatus() == 1005)
{ {
} }
else else
{ {
@ -277,11 +287,8 @@ public class DoSwappingState : IState
_CommonMgr.InsertStep(InfoEnum.BusinessSwappingStep.InstallNewBatteryFlag, _CommonMgr.InsertStep(InfoEnum.BusinessSwappingStep.InstallNewBatteryFlag,
machine); machine);
} }
}, () => }, () => { SoundApi.PlayOneSound((int)InfoEnum.SwapInfo.InfoPack); }, false, () => { },
{ 10, InvokeStatus.None);
SoundApi.PlayOneSound((int)InfoEnum.SwapInfo.InfoPack);
},false, () => { },
10,InvokeStatus.None);
} }
public InvokeStatus PackFinish(SwappingStateMachine machine) public InvokeStatus PackFinish(SwappingStateMachine machine)
@ -303,8 +310,8 @@ public class DoSwappingState : IState
_CommonMgr.InsertStep(InfoEnum.BusinessSwappingStep.FinishNewBatteryFlag, _CommonMgr.InsertStep(InfoEnum.BusinessSwappingStep.FinishNewBatteryFlag,
machine); machine);
} }
}, () => { },false, () => { }, }, () => { }, false, () => { },
10,InvokeStatus.None); 10, InvokeStatus.None);
} }
/// <summary> /// <summary>
@ -318,14 +325,18 @@ public class DoSwappingState : IState
() => machine.ToSafePositionFlag, () => () => machine.ToSafePositionFlag, () =>
{ {
// machine.LedTool?.WriteProgramContent(InfoEnum.SwapInfo.InfoPackFinish.GetLed()); // machine.LedTool?.WriteProgramContent(InfoEnum.SwapInfo.InfoPackFinish.GetLed());
if (PlcApi.ReadPlcTaskStatus() == 1007) if (PlcApi.ReadPlcTaskStatus() == 1007)
{ {
SoundApi.PlayOneSound((int)InfoEnum.SwapInfo.InfoToSafePosition); if (PlcApi.ReadTaskStatusReset())
machine.ToSafePositionFlag = true; {
machine.BusinessSwappingStateUpdateTime = DateTime.Now; PlcMgr.PlcClient?.ResetTaskNo();
SoundApi.PlayOneSound((int)InfoEnum.SwapInfo.InfoToSafePosition);
machine.ToSafePositionFlag = true;
machine.BusinessSwappingStateUpdateTime = DateTime.Now;
machine.SwapStatus = 1; machine.SwapStatus = 1;
}
} }
}, () => { }); }, () => { });
} }
@ -344,13 +355,12 @@ public class DoSwappingState : IState
int count = 0; int count = 0;
while (!machine.ChannelStatusOkFlag) while (!machine.ChannelStatusOkFlag)
{ {
if (machine.CancelFlag) if (machine.CancelFlag)
{ {
_log.Info($" CheckChannelStatus canceled"); _log.Info($" CheckChannelStatus canceled");
return StateResult.Cancel; return StateResult.Cancel;
} }
_log.Info("begin plc CheckChannelStatus"); _log.Info("begin plc CheckChannelStatus");
Thread.Sleep(2000); Thread.Sleep(2000);
var channelStatus = PlcApi.ChannelStatus(); var channelStatus = PlcApi.ChannelStatus();
@ -375,7 +385,7 @@ public class DoSwappingState : IState
// machine.LedTool?.WriteProgramContent(InfoEnum.SwapInfo.ErrChannelStatus.GetLed()); // machine.LedTool?.WriteProgramContent(InfoEnum.SwapInfo.ErrChannelStatus.GetLed());
SoundApi.PlayOneSound((int)InfoEnum.SwapInfo.ErrChannelStatus); SoundApi.PlayOneSound((int)InfoEnum.SwapInfo.ErrChannelStatus);
//等待2分钟 //等待2分钟
Thread.Sleep(3*60 *1000); Thread.Sleep(3 * 60 * 1000);
machine.VehiclesInPlace2Flag = false; machine.VehiclesInPlace2Flag = false;
machine.StartSwappingFlag = false; machine.StartSwappingFlag = false;
machine.PlcHoldFlag = false; machine.PlcHoldFlag = false;
@ -448,8 +458,8 @@ public class DoSwappingState : IState
succCount++; succCount++;
} }
} }
if (succCount==successCount) if (succCount == successCount)
{ {
machine.VehiclesInPlace2Flag = true; machine.VehiclesInPlace2Flag = true;
} }
@ -461,4 +471,4 @@ public class DoSwappingState : IState
}, false, () => { } }, false, () => { }
, 20, InvokeStatus.None); , 20, InvokeStatus.None);
} }
} }

@ -12,6 +12,7 @@ using Service.Execute.Model.Tbox;
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.Plc.Client;
namespace Service.Execute; namespace Service.Execute;
@ -249,6 +250,11 @@ public class SwappingStateMachine : IDisposable
public void Reset() public void Reset()
{ {
Log.Info("reset data"); Log.Info("reset data");
if (PlcMgr.PlcClient?.ReadTaskNo() == 1)
{
PlcMgr.PlcClient?.ExChangeTaskNo(0);
}
ResetOrderAmtStatus(); ResetOrderAmtStatus();
if (RfidReadModel != null) if (RfidReadModel != null)
{ {
@ -280,7 +286,7 @@ public class SwappingStateMachine : IDisposable
Log.Info($"ManualSwapSuccFlag machine ok"); Log.Info($"ManualSwapSuccFlag machine ok");
return true; return true;
} }
public bool ManualConfirmLockCar() public bool ManualConfirmLockCar()
{ {
ManualConfirmCarLockFlag = true; ManualConfirmCarLockFlag = true;
@ -288,7 +294,7 @@ public class SwappingStateMachine : IDisposable
Log.Info($"ManualConfirmLockCar ok"); Log.Info($"ManualConfirmLockCar ok");
return true; return true;
} }
public bool ManualConfirmUnLockCar() public bool ManualConfirmUnLockCar()
{ {
ManualConfirmCarUnlockFlag = true; ManualConfirmCarUnlockFlag = true;
@ -298,7 +304,6 @@ public class SwappingStateMachine : IDisposable
} }
private void ResetData() private void ResetData()
{ {
BusinessSwappingForCloudState = InfoEnum.BusinessSwappingForCloudState.Idle; BusinessSwappingForCloudState = InfoEnum.BusinessSwappingForCloudState.Idle;
@ -417,7 +422,7 @@ public class SwappingStateMachine : IDisposable
} }
} }
//预约单 //预约单
List<SwapAmtOrder> amtOrderInfos = AmtOrderRepository.QueryListByClause(it => List<SwapAmtOrder> amtOrderInfos = AmtOrderRepository.QueryListByClause(it =>
it.ExpireTime < DateTime.Now it.ExpireTime < DateTime.Now
&& it.Status == (byte)InfoEnum.AmtOrderStatus.Success).ToList(); && it.Status == (byte)InfoEnum.AmtOrderStatus.Success).ToList();
@ -454,4 +459,4 @@ public enum SwappingState
Exception, Exception,
Canceled, Canceled,
ManualSucc, ManualSucc,
} }

@ -48,7 +48,7 @@ public class BatteryMoveTask : ITask
} }
List<BinInfo> queryListByClause = List<BinInfo> queryListByClause =
_binInfoRepository.QueryListByClause(i => i.ChargeStatus == 4 && i.CacheBinFlag == 0 && i.Soc>=StaticStationInfo.SwapSoc _binInfoRepository.QueryListByClause(i => i.ChargeStatus == 4 && i.CacheBinFlag == 0 && i.Soc>=StaticStationInfo.SwapSoc
&& i.AmtLock == 0 && i.Status == 1, "battery_enter_seq asc"); && i.AmtLock == 0 && i.Status == 1, "battery_enter_seq asc");
@ -57,6 +57,11 @@ public class BatteryMoveTask : ITask
return; return;
} }
//不能进行移仓
if (PlcMgr.PlcClient?.ReadTaskNo() != 0)
{
return;
}
var binInfo = queryListByClause[0]; var binInfo = queryListByClause[0];
Result<bool> success = Result<bool> success =
@ -70,6 +75,7 @@ public class BatteryMoveTask : ITask
} }
catch (Exception e) catch (Exception e)
{ {
PlcMgr.PlcClient?.ExChangeTaskNo(0);
Log.Error($" SwapOrderReportCloudTask err e={e}"); Log.Error($" SwapOrderReportCloudTask err e={e}");
} }
} }
@ -88,4 +94,4 @@ public class BatteryMoveTask : ITask
{ {
_stop = false; _stop = false;
} }
} }

@ -17,11 +17,33 @@ public class PlcClient : ModbusTcpMaster
{ {
private static readonly ILog Log = LogManager.GetLogger(typeof(PlcClient)); private static readonly ILog Log = LogManager.GetLogger(typeof(PlcClient));
private long TaskNo=0;
public BinInfoRepository BinInfoRepository { get; set; } public BinInfoRepository BinInfoRepository { get; set; }
public EquipAlarmDefineRepository EquipAlarmDefineRepository { get; set; } public EquipAlarmDefineRepository EquipAlarmDefineRepository { get; set; }
public EquipAlarmRecordRepository EquipAlarmRecordRepository { get; set; } public EquipAlarmRecordRepository EquipAlarmRecordRepository { get; set; }
public EquipAlarmProcessRecordRepository EquipAlarmProcessRecordRepository { get; set; } public EquipAlarmProcessRecordRepository EquipAlarmProcessRecordRepository { get; set; }
//修改当前任务
public void ExChangeTaskNo(long taskNo)
{
Interlocked.Exchange(ref TaskNo, taskNo);
}
//重置当前任务
public void ResetTaskNo()
{
Interlocked.Exchange(ref TaskNo, 0);
}
//读取当前任务
public long ReadTaskNo()
{
return Interlocked.Read( ref TaskNo);
}
public PlcClient() public PlcClient()
{ {
ReadAction = BatchRead; ReadAction = BatchRead;
@ -35,6 +57,7 @@ public class PlcClient : ModbusTcpMaster
private void BatchRead(ModbusTcpMaster master) private void BatchRead(ModbusTcpMaster master)
{ {
PlcMgr.SendHear(); PlcMgr.SendHear();
var bytes01 = master.BatchReadHolderRegister(1, 115); var bytes01 = master.BatchReadHolderRegister(1, 115);
if (bytes01 != null) if (bytes01 != null)
@ -139,14 +162,14 @@ public class PlcClient : ModbusTcpMaster
if (lstAlarm.Count > 0) if (lstAlarm.Count > 0)
{ {
#region 有报警比较两边差异,新出现的报警就添加,消失的报警就处理并记录 #region 有报警比较两边差异,新出现的报警就添加,消失的报警就处理并记录
var lstEquipAlarmRecord=EquipAlarmRecordRepository.Query(); var lstEquipAlarmRecord=EquipAlarmRecordRepository.Query();
var sqllstAlarm=lstEquipAlarmRecord.Select(obj => obj.ErrorCode).ToList(); var sqllstAlarm=lstEquipAlarmRecord.Select(obj => obj.ErrorCode).ToList();
// 找出实时报警中存在但数据库中不存在的元素 // 找出实时报警中存在但数据库中不存在的元素
List<string> uniqueToList1 = lstAlarm.Except(sqllstAlarm).ToList(); List<string> uniqueToList1 = lstAlarm.Except(sqllstAlarm).ToList();
// 找出数据库中存在但实时报警中不存在的元素 // 找出数据库中存在但实时报警中不存在的元素
List<string> uniqueToList2 = sqllstAlarm.Except(lstAlarm).ToList(); List<string> uniqueToList2 = sqllstAlarm.Except(lstAlarm).ToList();
if (uniqueToList1.Count > 0) if (uniqueToList1.Count > 0)
@ -165,7 +188,7 @@ public class PlcClient : ModbusTcpMaster
ErrorMsg = alarmDefine.ErrorMsg, ErrorMsg = alarmDefine.ErrorMsg,
ProcessMethod = alarmDefine.ProcessMethod, ProcessMethod = alarmDefine.ProcessMethod,
StartTime= DateTime.Now StartTime= DateTime.Now
}; };
EquipAlarmRecordRepository.Insert(record); EquipAlarmRecordRepository.Insert(record);
} }
} }
@ -173,9 +196,9 @@ public class PlcClient : ModbusTcpMaster
if (uniqueToList2.Count > 0) if (uniqueToList2.Count > 0)
{//这些是要清除实时报警,并且处理记录的。 {//这些是要清除实时报警,并且处理记录的。
// 使用LINQ找出ErrorCode在uniqueToList2中的EquipAlarmRecord对象 // 使用LINQ找出ErrorCode在uniqueToList2中的EquipAlarmRecord对象
List<EquipAlarmRecord> filteredObjectList = lstEquipAlarmRecord List<EquipAlarmRecord> filteredObjectList = lstEquipAlarmRecord
.Where(obj => uniqueToList2.Contains(obj.ErrorCode)) .Where(obj => uniqueToList2.Contains(obj.ErrorCode))
.ToList(); .ToList();
foreach (var VARIABLE in filteredObjectList) foreach (var VARIABLE in filteredObjectList)
{ {
@ -193,7 +216,7 @@ public class PlcClient : ModbusTcpMaster
} }
EquipAlarmRecordRepository.Delete(filteredObjectList); EquipAlarmRecordRepository.Delete(filteredObjectList);
} }
#endregion #endregion
} }
else else
@ -219,10 +242,10 @@ public class PlcClient : ModbusTcpMaster
} }
} }
EquipAlarmRecordRepository.Delete(i=>i.Id>0); EquipAlarmRecordRepository.Delete(i=>i.Id>0);
#endregion #endregion
} }
} }
@ -245,7 +268,7 @@ public class PlcClient : ModbusTcpMaster
it => it.No == binNo); it => it.No == binNo);
} }
private void UpdateBinInfoCache(int exists, string binNo) private void UpdateBinInfoCache(int exists, string binNo)
{ {
if (exists == 0) if (exists == 0)
@ -253,7 +276,7 @@ public class PlcClient : ModbusTcpMaster
it => it =>
new BinInfo(){ new BinInfo(){
Exists = 0, Exists = 0,
}, },
it => it.No == binNo); it => it.No == binNo);
else else

@ -18,6 +18,8 @@ public class PlcMgr
public static readonly PlcFault PlcFaultData = new PlcFault(); public static readonly PlcFault PlcFaultData = new PlcFault();
public
/// <summary> /// <summary>
/// 数据有效时间。单位秒 /// 数据有效时间。单位秒
/// </summary> /// </summary>
@ -305,7 +307,7 @@ public class PlcMgr
bool writeCharge6 = PlcClient.WriteValue(writeHostToPlc.ChargingStatus06); bool writeCharge6 = PlcClient.WriteValue(writeHostToPlc.ChargingStatus06);
bool writeCharge7 = PlcClient.WriteValue(writeHostToPlc.ChargingStatus07); bool writeCharge7 = PlcClient.WriteValue(writeHostToPlc.ChargingStatus07);
bool writeCharge8 = PlcClient.WriteValue(writeHostToPlc.ChargingStatus08); bool writeCharge8 = PlcClient.WriteValue(writeHostToPlc.ChargingStatus08);
return write1 && write2 && write3 && write4 && write5 && write6; return write1 && write2 && write3 && write4 && write5 && write6;
} }
@ -396,4 +398,4 @@ public class PlcMgr
return bResult; return bResult;
} }
} }

@ -3,7 +3,7 @@
namespace Service.Plc.Msg namespace Service.Plc.Msg
{ {
/// <summary> /// <summary>
/// ///
/// </summary> /// </summary>
public class PlcToHost public class PlcToHost
{ {
@ -43,14 +43,14 @@ namespace Service.Plc.Msg
/// </summary> /// </summary>
public ModbusProperty<ushort> RemoteLocalControlState { get; set; } = new(40207); public ModbusProperty<ushort> RemoteLocalControlState { get; set; } = new(40207);
/// <summary> /// <summary>
/// 灯光状态 /// 灯光状态
/// <para>0无状态</para> /// <para>0无状态</para>
/// <para>1000已全部打开</para> /// <para>1000已全部打开</para>
/// <para>1010已全部关闭</para> /// <para>1010已全部关闭</para>
/// </summary> /// </summary>
public ModbusProperty<ushort> LightStatus { get; set; } = new(40208); public ModbusProperty<ushort> LightStatus { get; set; } = new(40208);
/// <summary> /// <summary>
/// 排风扇状态 /// 排风扇状态
/// <para>0无状态</para> /// <para>0无状态</para>
/// <para>1000已全部打开</para> /// <para>1000已全部打开</para>
/// <para>1010已全部关闭</para> /// <para>1010已全部关闭</para>
@ -58,7 +58,7 @@ namespace Service.Plc.Msg
public ModbusProperty<ushort> ExhaustFanStatus { get; set; } = new(40209); public ModbusProperty<ushort> ExhaustFanStatus { get; set; } = new(40209);
/// <summary> /// <summary>
/// 站内积水状态 /// 站内积水状态
/// BIT0积水预警 /// BIT0积水预警
/// BIT1积水报警 /// BIT1积水报警
/// </summary> /// </summary>
public ModbusProperty<ushort> WaterStatusStation { get; set; } = new(40210); public ModbusProperty<ushort> WaterStatusStation { get; set; } = new(40210);
@ -172,7 +172,7 @@ namespace Service.Plc.Msg
/// <para>1020红灯</para> /// <para>1020红灯</para>
/// <para>1030红灯闪烁</para> /// <para>1030红灯闪烁</para>
/// <para>1040黄灯</para> /// <para>1040黄灯</para>
/// <para>1050黄灯闪烁</para> /// <para>1050黄灯闪烁</para>移舱任务
/// <para>1100所有灯亮</para> /// <para>1100所有灯亮</para>
/// </summary> /// </summary>
public ModbusProperty<ushort> LightOut { get; set; } = new(40406); public ModbusProperty<ushort> LightOut { get; set; } = new(40406);

@ -27,6 +27,8 @@ public class MonitorService
public ChargeOrderRepository ChargeOrderRepository { get; set; } public ChargeOrderRepository ChargeOrderRepository { get; set; }
public PlcTaskMgr PlcTaskMgr { get; set; } public PlcTaskMgr PlcTaskMgr { get; set; }
public MoveBinRecordRepository MoveBinRecordRepository { get; set; }
public Result<SwapMonitorScreenResp> GetSwapMonitorData() public Result<SwapMonitorScreenResp> GetSwapMonitorData()
{ {
var configBinInfo = var configBinInfo =
@ -145,7 +147,7 @@ public class MonitorService
/// <param name="removeBinNo"></param> /// <param name="removeBinNo"></param>
/// <param name="putBinNo"></param> /// <param name="putBinNo"></param>
/// <returns></returns> /// <returns></returns>
public Result<bool> BatteryRelocation(ushort removeBinNo, ushort putBinNo) public Result<bool> BatteryRelocation(ushort removeBinNo, ushort putBinNo,int type=0)
{ {
//校验:出仓位 //校验:出仓位
BinInfo? removeBin = BinInfoRepository.QueryByClause(i => BinInfo? removeBin = BinInfoRepository.QueryByClause(i =>
@ -165,13 +167,22 @@ public class MonitorService
return Result<bool>.Fail("入仓位状态有误"); return Result<bool>.Fail("入仓位状态有误");
} }
if (PlcMgr.PlcClient?.ReadTaskNo() != 0)
{
Log.Info("当前存在其他任务");
return Result<bool>.Fail("当前存在其他任务");
}
PlcMgr.PlcClient?.ExChangeTaskNo(2);
var result = PlcMgr.DistributeTask(putBinNo, removeBinNo, 2); var result = PlcMgr.DistributeTask(putBinNo, removeBinNo, 2);
if (!result) if (!result)
{ {
PlcMgr.PlcClient?.ExChangeTaskNo(0);
return Result<bool>.Fail(); return Result<bool>.Fail();
} }
int count = 3; int count = 3;
while (count > 0) while (count > 0)
{ {
@ -187,22 +198,40 @@ public class MonitorService
if (!result) if (!result)
{ {
PlcMgr.PlcClient?.ExChangeTaskNo(0);
Log.Error("BatteryRelocation PlcMgr.ReadTaskStatus(2) =false"); Log.Error("BatteryRelocation PlcMgr.ReadTaskStatus(2) =false");
return Result<bool>.Fail(); return Result<bool>.Fail();
} }
MoveBinRecord moveBinRecord = new MoveBinRecord()
{
UpBinNo = removeBinNo.ToString(),
UpBatteryNo = removeBin.BatteryNo,
UpBatterySoc = removeBin.Soc.ToString(),
InBatteryNo = putBin.BatteryNo,
InBatterySoc = putBin.Soc.ToString(),
InBinNo = putBinNo.ToString(),
Status = 0,
Type = type
};
MoveBinRecordRepository.Insert(moveBinRecord);
result = PlcMgr.HoldOn(); result = PlcMgr.HoldOn();
if (!result) if (!result)
{ { PlcMgr.PlcClient?.ExChangeTaskNo(0);
Log.Error("BatteryRelocation PlcMgr.HoldOn() =false"); Log.Error("BatteryRelocation PlcMgr.HoldOn() =false");
return Result<bool>.Fail(); return Result<bool>.Fail();
} }
Log.Info($"battery move task Manual removeBinNo={removeBinNo}, putBinNo={putBinNo} "); Log.Info($"battery move task Manual removeBinNo={removeBinNo}, putBinNo={putBinNo} type={type} ");
moveBinRecord.Status = 1;
MoveBinRecordRepository.Update(moveBinRecord);
var queryPlcTask = PlcTaskMgr.QueryPlcTask(2, 1200, 1201); var queryPlcTask = PlcTaskMgr.QueryPlcTask(2, 1200, 1201);
if (!queryPlcTask) if (!queryPlcTask)
{ {
PlcMgr.PlcClient?.ExChangeTaskNo(0);
moveBinRecord.Status = 3;
MoveBinRecordRepository.Update(moveBinRecord);
return Result<bool>.Fail(); return Result<bool>.Fail();
} }
@ -231,8 +260,9 @@ public class MonitorService
removeBin.BatteryEnterSeq = 0; removeBin.BatteryEnterSeq = 0;
BinInfoRepository.Update(removeBin); BinInfoRepository.Update(removeBin);
moveBinRecord.Status = 2;
MoveBinRecordRepository.Update(moveBinRecord);
PlcMgr.PlcClient?.ExChangeTaskNo(0);
return Result<bool>.Success(); return Result<bool>.Success();
} }
@ -246,4 +276,4 @@ public class MonitorService
return Result<List<BinInfoResp>>.Success(mapperBinInfo.Map<List<BinInfoResp>>(queryListByClause)); return Result<List<BinInfoResp>>.Success(mapperBinInfo.Map<List<BinInfoResp>>(queryListByClause));
} }
} }

@ -28,7 +28,7 @@ public class ChargeMonitorController
_binInfoService = binInfoService; _binInfoService = binInfoService;
_monitorService = monitorService; _monitorService = monitorService;
} }
/// <summary> /// <summary>
/// 仓位预约 /// 仓位预约
/// </summary> /// </summary>
@ -49,7 +49,7 @@ public class ChargeMonitorController
else else
return Result<bool>.Fail(result); return Result<bool>.Fail(result);
} }
/// <summary> /// <summary>
/// 修改仓位电池编码 /// 修改仓位电池编码
/// </summary> /// </summary>
@ -76,8 +76,8 @@ public class ChargeMonitorController
else else
return Result<bool>.Fail(result); return Result<bool>.Fail(result);
} }
/// <summary> /// <summary>
/// 充电仓查询:条件:仓位编号 仓位名称 /// 充电仓查询:条件:仓位编号 仓位名称
/// </summary> /// </summary>
@ -119,7 +119,7 @@ public class ChargeMonitorController
[HttpGet("BatteryRelocation")] [HttpGet("BatteryRelocation")]
public async Task<Result<bool>> BatteryRelocation(ushort removeBinNo, ushort putBinNo) public async Task<Result<bool>> BatteryRelocation(ushort removeBinNo, ushort putBinNo)
{ {
return _monitorService.BatteryRelocation(removeBinNo, putBinNo); return _monitorService.BatteryRelocation(removeBinNo, putBinNo,1);
} }
/// <summary> /// <summary>
@ -130,4 +130,4 @@ public class ChargeMonitorController
{ {
return _monitorService.GetChargeBinOption(); return _monitorService.GetChargeBinOption();
} }
} }

Loading…
Cancel
Save