移仓内部增加try catch

master
rszn 5 months ago
parent 47d2522c2b
commit 5aac8e7f0b

@ -148,128 +148,146 @@ 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,int type=0) public Result<bool> BatteryRelocation(ushort removeBinNo, ushort putBinNo, int type = 0)
{ {
//校验:出仓位 MoveBinRecord moveBinRecord = null;
BinInfo? removeBin = BinInfoRepository.QueryByClause(i => try
i.No.Equals(removeBinNo) && (i.ChargeStatus != 1) && i.Exists == 1 &&
i.AmtLock == 0);
if (removeBin == null)
{ {
return Result<bool>.Fail("出仓位状态有误"); //校验:出仓位
} BinInfo? removeBin = BinInfoRepository.QueryByClause(i =>
i.No.Equals(removeBinNo) && (i.ChargeStatus != 1) && i.Exists == 1 &&
i.AmtLock == 0);
BinInfo? putBin = BinInfoRepository.QueryByClause(i => if (removeBin == null)
i.No.Equals(putBinNo) && i.Exists == 0 && i.AmtLock == 0 && {
i.Status == 1); return Result<bool>.Fail("出仓位状态有误");
if (putBin == null) }
{
return Result<bool>.Fail("入仓位状态有误");
}
if (PlcMgr.PlcClient?.ReadTaskNo() != 0) BinInfo? putBin = BinInfoRepository.QueryByClause(i =>
{ i.No.Equals(putBinNo) && i.Exists == 0 && i.AmtLock == 0 &&
Log.Info("当前存在其他任务"); i.Status == 1);
return Result<bool>.Fail("当前存在其他任务"); if (putBin == null)
} {
PlcMgr.PlcClient?.ExChangeTaskNo(2); return Result<bool>.Fail("入仓位状态有误");
var result = PlcMgr.DistributeTask(putBinNo, removeBinNo, 2); }
if (!result) if (PlcMgr.PlcClient?.ReadTaskNo() != 0)
{ {
PlcMgr.PlcClient?.ExChangeTaskNo(0); Log.Info("当前存在其他任务");
return Result<bool>.Fail(); 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) int count = 3;
{ while (count > 0)
result = PlcMgr.ReadTaskStatus(2);
if (result)
{ {
break; result = PlcMgr.ReadTaskStatus(2);
if (result)
{
break;
}
count--;
Thread.Sleep(1000);
} }
count--; if (!result)
Thread.Sleep(1000); {
} PlcMgr.PlcClient?.ExChangeTaskNo(0);
Log.Error("BatteryRelocation PlcMgr.ReadTaskStatus(2) =false");
return Result<bool>.Fail();
}
if (!result) moveBinRecord = new MoveBinRecord()
{ {
PlcMgr.PlcClient?.ExChangeTaskNo(0); UpBinNo = removeBinNo.ToString(),
Log.Error("BatteryRelocation PlcMgr.ReadTaskStatus(2) =false"); UpBatteryNo = removeBin.BatteryNo,
return Result<bool>.Fail(); 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)
{
moveBinRecord.Status = 3;
MoveBinRecordRepository.Update(moveBinRecord);
PlcMgr.PlcClient?.ExChangeTaskNo(0);
MoveBinRecord moveBinRecord = new MoveBinRecord() Log.Error("BatteryRelocation PlcMgr.HoldOn() =false");
{ return Result<bool>.Fail();
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(); Log.Info($"battery move task Manual removeBinNo={removeBinNo}, putBinNo={putBinNo} type={type} ");
if (!result) moveBinRecord.Status = 1;
{
moveBinRecord.Status = 3;
MoveBinRecordRepository.Update(moveBinRecord); MoveBinRecordRepository.Update(moveBinRecord);
PlcMgr.PlcClient?.ExChangeTaskNo(0); var queryPlcTask = PlcTaskMgr.QueryPlcTask(2, 1200, 1201);
if (!queryPlcTask)
{
PlcMgr.PlcClient?.ExChangeTaskNo(0);
Log.Info($"move battery fail update moveBin={JsonConvert.SerializeObject(moveBinRecord)}");
moveBinRecord.Status = 3;
MoveBinRecordRepository.Update(moveBinRecord);
return Result<bool>.Fail();
}
Log.Error("BatteryRelocation PlcMgr.HoldOn() =false"); //如果是缓存仓 更新缓存仓的数据
return Result<bool>.Fail(); if (putBin.CacheBinFlag == 1)
} {
putBin.Exists = 1;
putBin.BatteryNo = removeBin.BatteryNo;
putBin.Soc = removeBin.Soc;
putBin.Soe = removeBin.Soe;
putBin.Soh = removeBin.Soh;
putBin.BatteryEnterSeq = removeBin.BatteryEnterSeq;
putBin.InTime = removeBin.InTime;
BinInfoRepository.Update(putBin);
}
Log.Info($"battery move task Manual removeBinNo={removeBinNo}, putBinNo={putBinNo} type={type} ");
moveBinRecord.Status = 1; if (removeBin.CacheBinFlag == 1)
MoveBinRecordRepository.Update(moveBinRecord); {
var queryPlcTask = PlcTaskMgr.QueryPlcTask(2, 1200, 1201); removeBin.Exists = 0;
if (!queryPlcTask) removeBin.BatteryNo = "-1";
{ removeBin.Soc = -1;
PlcMgr.PlcClient?.ExChangeTaskNo(0); removeBin.Soe = -1;
Log.Info($"move battery fail update moveBin={JsonConvert.SerializeObject(moveBinRecord)}"); removeBin.Soh = -1;
moveBinRecord.Status = 3; }
removeBin.BatteryEnterSeq = 0;
BinInfoRepository.Update(removeBin);
moveBinRecord.Status = 2;
Log.Info($"move battery success update moveBin={JsonConvert.SerializeObject(moveBinRecord)}");
MoveBinRecordRepository.Update(moveBinRecord); MoveBinRecordRepository.Update(moveBinRecord);
return Result<bool>.Fail(); PlcMgr.PlcClient?.ExChangeTaskNo(0);
} }
catch (Exception e)
//如果是缓存仓 更新缓存仓的数据
if (putBin.CacheBinFlag == 1)
{ {
putBin.Exists = 1; Log.Error($"move battery fail e={e.Message}");
putBin.BatteryNo = removeBin.BatteryNo; if (moveBinRecord != null)
putBin.Soc = removeBin.Soc; {
putBin.Soe = removeBin.Soe;
putBin.Soh = removeBin.Soh;
putBin.BatteryEnterSeq = removeBin.BatteryEnterSeq;
putBin.InTime = removeBin.InTime;
BinInfoRepository.Update(putBin);
}
moveBinRecord.Status = 3;
MoveBinRecordRepository.Update(moveBinRecord);
}
PlcMgr.PlcClient?.ResetTaskNo();
if (removeBin.CacheBinFlag == 1) return Result<bool>.Fail();
{
removeBin.Exists = 0;
removeBin.BatteryNo = "-1";
removeBin.Soc = -1;
removeBin.Soe = -1;
removeBin.Soh = -1;
} }
removeBin.BatteryEnterSeq = 0;
BinInfoRepository.Update(removeBin);
moveBinRecord.Status = 2;
Log.Info($"move battery success update moveBin={JsonConvert.SerializeObject(moveBinRecord)}");
MoveBinRecordRepository.Update(moveBinRecord);
PlcMgr.PlcClient?.ExChangeTaskNo(0);
return Result<bool>.Success(); return Result<bool>.Success();
} }

Loading…
Cancel
Save