关于并行任务的更改

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="swapFinishChargeTime">StaticStationInfo.SwapFinishChargeTime</param>
/// <returns></returns>
public SelectPackDto SelectPack(int swapSoc, int swapFinishChargeTime)
public SelectPackDto SelectPack(int swapSoc, int swapFinishChargeTime, string upMoveNo)
{
SelectPackDto selectPackDto = new()
{
SuccessFlag = false,
};
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,
"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;
return selectPackDto;
}
list = list.OrderBy(i => i.CacheBinFlag).ToList();
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 && cacheBinBattery == null)
if (list.Count <= 0)
{
selectPackDto.Info = InfoEnum.SelectBinStatusInfo.LessOfFinishCharging;
return selectPackDto;
@ -45,7 +56,7 @@ public class BinInfoRepository : BaseRepository<BinInfo>
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;
return selectPackDto;
@ -54,20 +65,15 @@ public class BinInfoRepository : BaseRepository<BinInfo>
list = list.Where(i => i.LastChargeFinishTime != null && new TimeSpan(DateTime.Now.Ticks -
i.LastChargeFinishTime.ToDateTime().Ticks)
.TotalMinutes > swapFinishChargeTime).ToList();
if (list.Count <= 0 && cacheBinBattery == null)
if (list.Count <= 0)
{
selectPackDto.Info = InfoEnum.SelectBinStatusInfo.LessOf3Minute;
return selectPackDto;
}
if (list.Count > 0)
{
selectPackDto.BinInfo = list[0];
}
else
{
selectPackDto.BinInfo = cacheBinBattery;
}
selectPackDto.Info = InfoEnum.SelectBinStatusInfo.Success;
selectPackDto.SuccessFlag = true;

@ -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>
public static bool ReadTaskStatus(ushort taskNo)
{
PlcMgr.ResetPlc();
Log.Info($"PlcApi ReadTaskStatus param= taskNo={taskNo}");
var readTaskStatus = PlcMgr.ReadTaskStatus(taskNo);
Log.Info($"PlcApi ReadTaskStatus resp={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>
/// plc上使能
/// </summary>
@ -162,6 +176,7 @@ public class PlcApi
/// <returns>6未连接</returns>
public static int ReadPlcTaskStatus()
{
PlcMgr.ResetPlc();
Log.Info($"PlcApi start ReadPlcTaskStatus ");
var readPlcTaskStatus = PlcMgr.ReadPlcTaskStatus();
Log.Info($"PlcApi ReadPlcTaskStatus resp= {readPlcTaskStatus}");

@ -6,9 +6,12 @@ using Entity.Dto;
using HybirdFrameworkCore.Autofac;
using HybirdFrameworkCore.Autofac.Attribute;
using Repository.Station;
using Service.Execute.Api;
using Service.Execute.Model;
using Service.Init;
using Service.Plc.Client;
using Service.Station;
using SqlSugar;
namespace Service.Execute.Utils;
@ -24,6 +27,8 @@ public class CommonMgr
public SwapOrderReportCloudRepository _swapOrderReportCloudRepository { get; set; }
public MoveBinRecordRepository MoveBinRecordRepository { get; set; }
/// <summary>
/// 新增小步状态
/// </summary>
@ -156,17 +161,43 @@ public class CommonMgr
/// <summary>
/// 取电池判断
/// 不能选正在执行移仓的电池
/// </summary>
/// <param name="orderBatteryInfo"></param>
public void UpBin(SwapOrderBatteryInfo orderBatteryInfo)
{
SelectPackDto selectPack =
_binInfoRepository.SelectPack(StaticStationInfo.SwapSoc, StaticStationInfo.SwapFinishChargeTime);
_binInfoRepository.SelectPack(StaticStationInfo.SwapSoc, StaticStationInfo.SwapFinishChargeTime,
queryMoveBinNo()[0]);
orderBatteryInfo.UpBinInfo = selectPack.BinInfo;
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>
@ -185,6 +216,17 @@ public class CommonMgr
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.BatteryNo = "-1";
orderBatteryInfo.InBinInfo.Soc = -1;

@ -11,6 +11,7 @@ using Service.Execute.StaticTools;
using Service.Execute.SwapException;
using Service.Execute.Utils;
using Service.Init;
using Service.Plc.Client;
using Service.Station;
namespace Service.Execute.Step;
@ -100,6 +101,7 @@ public class DoSwappingState : IState
{
return SwappingStateMachine.ReturnWithInvokeErr(toInvokeStatus, ExceptionReason.None);
}
//查询换电任务是否结束
return new StateResult()
@ -121,6 +123,12 @@ public class DoSwappingState : IState
bool unLock = result.Result;
if (unLock)
{
//查询当前是否有任务执行
var readTaskNo = PlcMgr.PlcClient?.ReadTaskNo();
if (readTaskNo == 0 || readTaskNo==1)
{
PlcMgr.PlcClient?.ExChangeTaskNo(1);
//查询车辆锁止状态
var startSwapping = PlcApi.StartSwapping(machine.SwapOrderBatteryInfo.InBinInfo.No,
machine.SwapOrderBatteryInfo.UpBinInfo.No);
@ -129,6 +137,7 @@ public class DoSwappingState : IState
var readPlcTaskStatus = PlcApi.ReadTaskStatus(1);
if (startSwapping && readPlcTaskStatus)
{
machine.SwapOrder.SwapBeginTime = DateTime.Now;
_CommonMgr.UpdateSwapOrder(machine);
machine.SwapStatus = 0;
@ -137,10 +146,13 @@ public class DoSwappingState : IState
machine);
}
}
}, () =>
else
{
SoundApi.PlayOneSound((int)InfoEnum.SwapInfo.ErrStartSwap);
},false, () => { },10,InvokeStatus.None);
_log.Info("当前有任务在执行");
}
}
}, () => { SoundApi.PlayOneSound((int)InfoEnum.SwapInfo.ErrStartSwap); }, false, () => { }, 10,
InvokeStatus.None);
}
@ -240,7 +252,6 @@ public class DoSwappingState : IState
if (PlcApi.ReadPlcTaskStatus() == 1004)
{
}
else
{
@ -265,7 +276,6 @@ public class DoSwappingState : IState
// machine.LedTool?.WriteProgramContent(InfoEnum.SwapInfo.InfoPack.GetLed());
if (PlcApi.ReadPlcTaskStatus() == 1005)
{
}
else
{
@ -277,10 +287,7 @@ public class DoSwappingState : IState
_CommonMgr.InsertStep(InfoEnum.BusinessSwappingStep.InstallNewBatteryFlag,
machine);
}
}, () =>
{
SoundApi.PlayOneSound((int)InfoEnum.SwapInfo.InfoPack);
},false, () => { },
}, () => { SoundApi.PlayOneSound((int)InfoEnum.SwapInfo.InfoPack); }, false, () => { },
10, InvokeStatus.None);
}
@ -321,12 +328,16 @@ public class DoSwappingState : IState
if (PlcApi.ReadPlcTaskStatus() == 1007)
{
if (PlcApi.ReadTaskStatusReset())
{
PlcMgr.PlcClient?.ResetTaskNo();
SoundApi.PlayOneSound((int)InfoEnum.SwapInfo.InfoToSafePosition);
machine.ToSafePositionFlag = true;
machine.BusinessSwappingStateUpdateTime = DateTime.Now;
machine.SwapStatus = 1;
}
}
}, () => { });
}
@ -344,7 +355,6 @@ public class DoSwappingState : IState
int count = 0;
while (!machine.ChannelStatusOkFlag)
{
if (machine.CancelFlag)
{
_log.Info($" CheckChannelStatus canceled");

@ -12,6 +12,7 @@ using Service.Execute.Model.Tbox;
using Service.Execute.StaticTools;
using Service.Execute.Step;
using Service.Execute.SwapException;
using Service.Plc.Client;
namespace Service.Execute;
@ -249,6 +250,11 @@ public class SwappingStateMachine : IDisposable
public void Reset()
{
Log.Info("reset data");
if (PlcMgr.PlcClient?.ReadTaskNo() == 1)
{
PlcMgr.PlcClient?.ExChangeTaskNo(0);
}
ResetOrderAmtStatus();
if (RfidReadModel != null)
{
@ -298,7 +304,6 @@ public class SwappingStateMachine : IDisposable
}
private void ResetData()
{
BusinessSwappingForCloudState = InfoEnum.BusinessSwappingForCloudState.Idle;

@ -57,6 +57,11 @@ public class BatteryMoveTask : ITask
return;
}
//不能进行移仓
if (PlcMgr.PlcClient?.ReadTaskNo() != 0)
{
return;
}
var binInfo = queryListByClause[0];
Result<bool> success =
@ -70,6 +75,7 @@ public class BatteryMoveTask : ITask
}
catch (Exception e)
{
PlcMgr.PlcClient?.ExChangeTaskNo(0);
Log.Error($" SwapOrderReportCloudTask err e={e}");
}
}

@ -17,11 +17,33 @@ public class PlcClient : ModbusTcpMaster
{
private static readonly ILog Log = LogManager.GetLogger(typeof(PlcClient));
private long TaskNo=0;
public BinInfoRepository BinInfoRepository { get; set; }
public EquipAlarmDefineRepository EquipAlarmDefineRepository { get; set; }
public EquipAlarmRecordRepository EquipAlarmRecordRepository { 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()
{
ReadAction = BatchRead;
@ -35,6 +57,7 @@ public class PlcClient : ModbusTcpMaster
private void BatchRead(ModbusTcpMaster master)
{
PlcMgr.SendHear();
var bytes01 = master.BatchReadHolderRegister(1, 115);
if (bytes01 != null)

@ -18,6 +18,8 @@ public class PlcMgr
public static readonly PlcFault PlcFaultData = new PlcFault();
public
/// <summary>
/// 数据有效时间。单位秒
/// </summary>

@ -172,7 +172,7 @@ namespace Service.Plc.Msg
/// <para>1020红灯</para>
/// <para>1030红灯闪烁</para>
/// <para>1040黄灯</para>
/// <para>1050黄灯闪烁</para>
/// <para>1050黄灯闪烁</para>移舱任务
/// <para>1100所有灯亮</para>
/// </summary>
public ModbusProperty<ushort> LightOut { get; set; } = new(40406);

@ -27,6 +27,8 @@ public class MonitorService
public ChargeOrderRepository ChargeOrderRepository { get; set; }
public PlcTaskMgr PlcTaskMgr { get; set; }
public MoveBinRecordRepository MoveBinRecordRepository { get; set; }
public Result<SwapMonitorScreenResp> GetSwapMonitorData()
{
var configBinInfo =
@ -145,7 +147,7 @@ public class MonitorService
/// <param name="removeBinNo"></param>
/// <param name="putBinNo"></param>
/// <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 =>
@ -165,13 +167,22 @@ public class MonitorService
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);
if (!result)
{
PlcMgr.PlcClient?.ExChangeTaskNo(0);
return Result<bool>.Fail();
}
int count = 3;
while (count > 0)
{
@ -187,22 +198,40 @@ public class MonitorService
if (!result)
{
PlcMgr.PlcClient?.ExChangeTaskNo(0);
Log.Error("BatteryRelocation PlcMgr.ReadTaskStatus(2) =false");
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();
if (!result)
{
{ PlcMgr.PlcClient?.ExChangeTaskNo(0);
Log.Error("BatteryRelocation PlcMgr.HoldOn() =false");
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);
if (!queryPlcTask)
{
PlcMgr.PlcClient?.ExChangeTaskNo(0);
moveBinRecord.Status = 3;
MoveBinRecordRepository.Update(moveBinRecord);
return Result<bool>.Fail();
}
@ -231,8 +260,9 @@ public class MonitorService
removeBin.BatteryEnterSeq = 0;
BinInfoRepository.Update(removeBin);
moveBinRecord.Status = 2;
MoveBinRecordRepository.Update(moveBinRecord);
PlcMgr.PlcClient?.ExChangeTaskNo(0);
return Result<bool>.Success();
}

@ -119,7 +119,7 @@ public class ChargeMonitorController
[HttpGet("BatteryRelocation")]
public async Task<Result<bool>> BatteryRelocation(ushort removeBinNo, ushort putBinNo)
{
return _monitorService.BatteryRelocation(removeBinNo, putBinNo);
return _monitorService.BatteryRelocation(removeBinNo, putBinNo,1);
}
/// <summary>

Loading…
Cancel
Save