|
|
|
@ -148,128 +148,146 @@ public class MonitorService
|
|
|
|
|
/// <param name="removeBinNo"></param>
|
|
|
|
|
/// <param name="putBinNo"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public Result<bool> BatteryRelocation(ushort removeBinNo, ushort putBinNo,int type=0)
|
|
|
|
|
public Result<bool> BatteryRelocation(ushort removeBinNo, ushort putBinNo, int type = 0)
|
|
|
|
|
{
|
|
|
|
|
//校验:出仓位
|
|
|
|
|
BinInfo? removeBin = BinInfoRepository.QueryByClause(i =>
|
|
|
|
|
i.No.Equals(removeBinNo) && (i.ChargeStatus != 1) && i.Exists == 1 &&
|
|
|
|
|
i.AmtLock == 0);
|
|
|
|
|
|
|
|
|
|
if (removeBin == null)
|
|
|
|
|
MoveBinRecord moveBinRecord = null;
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
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 =>
|
|
|
|
|
i.No.Equals(putBinNo) && i.Exists == 0 && i.AmtLock == 0 &&
|
|
|
|
|
i.Status == 1);
|
|
|
|
|
if (putBin == null)
|
|
|
|
|
{
|
|
|
|
|
return Result<bool>.Fail("入仓位状态有误");
|
|
|
|
|
}
|
|
|
|
|
if (removeBin == null)
|
|
|
|
|
{
|
|
|
|
|
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);
|
|
|
|
|
BinInfo? putBin = BinInfoRepository.QueryByClause(i =>
|
|
|
|
|
i.No.Equals(putBinNo) && i.Exists == 0 && i.AmtLock == 0 &&
|
|
|
|
|
i.Status == 1);
|
|
|
|
|
if (putBin == null)
|
|
|
|
|
{
|
|
|
|
|
return Result<bool>.Fail("入仓位状态有误");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!result)
|
|
|
|
|
{
|
|
|
|
|
PlcMgr.PlcClient?.ExChangeTaskNo(0);
|
|
|
|
|
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)
|
|
|
|
|
{
|
|
|
|
|
result = PlcMgr.ReadTaskStatus(2);
|
|
|
|
|
if (result)
|
|
|
|
|
|
|
|
|
|
int count = 3;
|
|
|
|
|
while (count > 0)
|
|
|
|
|
{
|
|
|
|
|
break;
|
|
|
|
|
result = PlcMgr.ReadTaskStatus(2);
|
|
|
|
|
if (result)
|
|
|
|
|
{
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
count--;
|
|
|
|
|
Thread.Sleep(1000);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
count--;
|
|
|
|
|
Thread.Sleep(1000);
|
|
|
|
|
}
|
|
|
|
|
if (!result)
|
|
|
|
|
{
|
|
|
|
|
PlcMgr.PlcClient?.ExChangeTaskNo(0);
|
|
|
|
|
Log.Error("BatteryRelocation PlcMgr.ReadTaskStatus(2) =false");
|
|
|
|
|
return Result<bool>.Fail();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!result)
|
|
|
|
|
{
|
|
|
|
|
PlcMgr.PlcClient?.ExChangeTaskNo(0);
|
|
|
|
|
Log.Error("BatteryRelocation PlcMgr.ReadTaskStatus(2) =false");
|
|
|
|
|
return Result<bool>.Fail();
|
|
|
|
|
}
|
|
|
|
|
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)
|
|
|
|
|
{
|
|
|
|
|
moveBinRecord.Status = 3;
|
|
|
|
|
MoveBinRecordRepository.Update(moveBinRecord);
|
|
|
|
|
PlcMgr.PlcClient?.ExChangeTaskNo(0);
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
Log.Error("BatteryRelocation PlcMgr.HoldOn() =false");
|
|
|
|
|
return Result<bool>.Fail();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
result = PlcMgr.HoldOn();
|
|
|
|
|
if (!result)
|
|
|
|
|
{
|
|
|
|
|
moveBinRecord.Status = 3;
|
|
|
|
|
Log.Info($"battery move task Manual removeBinNo={removeBinNo}, putBinNo={putBinNo} type={type} ");
|
|
|
|
|
moveBinRecord.Status = 1;
|
|
|
|
|
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;
|
|
|
|
|
MoveBinRecordRepository.Update(moveBinRecord);
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
if (removeBin.CacheBinFlag == 1)
|
|
|
|
|
{
|
|
|
|
|
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);
|
|
|
|
|
return Result<bool>.Fail();
|
|
|
|
|
PlcMgr.PlcClient?.ExChangeTaskNo(0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//如果是缓存仓 更新缓存仓的数据
|
|
|
|
|
if (putBin.CacheBinFlag == 1)
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
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.Error($"move battery fail e={e.Message}");
|
|
|
|
|
if (moveBinRecord != null)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
moveBinRecord.Status = 3;
|
|
|
|
|
MoveBinRecordRepository.Update(moveBinRecord);
|
|
|
|
|
}
|
|
|
|
|
PlcMgr.PlcClient?.ResetTaskNo();
|
|
|
|
|
|
|
|
|
|
if (removeBin.CacheBinFlag == 1)
|
|
|
|
|
{
|
|
|
|
|
removeBin.Exists = 0;
|
|
|
|
|
removeBin.BatteryNo = "-1";
|
|
|
|
|
removeBin.Soc = -1;
|
|
|
|
|
removeBin.Soe = -1;
|
|
|
|
|
removeBin.Soh = -1;
|
|
|
|
|
return Result<bool>.Fail();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|