|
|
|
@ -180,9 +180,6 @@ public class MonitorService
|
|
|
|
|
|
|
|
|
|
if (monitorScreenResp.VehicleInfo.OrderNo != null)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
SwapOrderBattery queryByClauseAsync =
|
|
|
|
|
_SwapOrderBatteryRepository.QueryByClause(u => u.SwapOrderSn == monitorScreenResp.VehicleInfo.OrderNo);
|
|
|
|
|
if (queryByClauseAsync != null)
|
|
|
|
@ -202,9 +199,8 @@ public class MonitorService
|
|
|
|
|
else if (swapOrder != null && swapOrder.SwapBeginTime.HasValue)
|
|
|
|
|
{
|
|
|
|
|
TimeSpan duration = DateTime.Now - swapOrder.SwapBeginTime.Value;
|
|
|
|
|
monitorScreenResp.VehicleInfo.SwapDuration = duration.ToString(@"hh\:mm\:ss");
|
|
|
|
|
monitorScreenResp.VehicleInfo.SwapDuration = duration.ToString(@"hh\:mm\:ss");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -279,59 +275,166 @@ 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)
|
|
|
|
|
{
|
|
|
|
|
MoveBinRecord moveBinRecord = null;
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
//校验:出仓位
|
|
|
|
|
BinInfo? removeBin = BinInfoRepository.QueryByClause(i =>
|
|
|
|
|
i.No.Equals(removeBinNo) && (i.ChargeStatus != 1) && i.Exists == 1 &&
|
|
|
|
|
i.AmtLock == 0);
|
|
|
|
|
|
|
|
|
|
if (removeBin == null)
|
|
|
|
|
if (!JudgeCanMove(removeBinNo, 1))
|
|
|
|
|
{
|
|
|
|
|
return Result<bool>.Fail("出仓位状态有误");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!JudgeCanMove(putBinNo, 0))
|
|
|
|
|
{
|
|
|
|
|
return Result<bool>.Fail("入仓位状态有误");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
moveBinRecord= BatteryMove(removeBinNo, putBinNo, 1);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
Log.Error($" BatteryRelocation move battery fail e={e.Message}");
|
|
|
|
|
ClientMgr.PlcClient.BatteryMoveDone = false;
|
|
|
|
|
if (moveBinRecord != null)
|
|
|
|
|
{
|
|
|
|
|
moveBinRecord.Status = 3;
|
|
|
|
|
MoveBinRecordRepository.Update(moveBinRecord);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return Result<bool>.Fail();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return moveBinRecord.Status == 2 ? Result<bool>.Success() : Result<bool>.Fail();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 维修仓校验 /车辆
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
private bool JudgeMaintenBin(ushort removeBinNo, ushort putBinNo, ushort no)
|
|
|
|
|
{
|
|
|
|
|
//当前存在一个维修仓
|
|
|
|
|
HashSet<ushort> set = new HashSet<ushort>();
|
|
|
|
|
set.Add(removeBinNo);
|
|
|
|
|
set.Add(putBinNo);
|
|
|
|
|
return set.Contains(no);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 电池仓
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
private bool JudgeBin(ushort removeBinNo, ushort putBinNo)
|
|
|
|
|
{
|
|
|
|
|
//当前存在一个维修仓
|
|
|
|
|
List<string> set = new List<string>();
|
|
|
|
|
set.Add(removeBinNo.ToString());
|
|
|
|
|
set.Add(putBinNo.ToString());
|
|
|
|
|
var bin = BinInfoRepository.Query().Select(i => i.No).ToList();
|
|
|
|
|
return set.Intersect(bin).Count() > 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// type : 0:入仓 1:出仓
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="binNo"></param>
|
|
|
|
|
/// <param name="type"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public bool JudgeCanMove(ushort binNo, int type)
|
|
|
|
|
{
|
|
|
|
|
if (binNo == 10)
|
|
|
|
|
{
|
|
|
|
|
//车辆未有校验
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
if (binNo == 0)
|
|
|
|
|
{
|
|
|
|
|
//本体未有校验 ,未有协议知道本体上是否有电池
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (binNo == 9)
|
|
|
|
|
{
|
|
|
|
|
//判断维修仓是否有电池
|
|
|
|
|
return (type == 0 && !ClientMgr.PlcClient.Is9Exist) || (type == 1 && ClientMgr.PlcClient.Is9Exist);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (type == 0)
|
|
|
|
|
{
|
|
|
|
|
BinInfo? putBin = BinInfoRepository.QueryByClause(i =>
|
|
|
|
|
i.No.Equals(putBinNo) && i.Exists == 0 && i.AmtLock == 0 &&
|
|
|
|
|
i.No.Equals(binNo) && i.Exists == 0 && i.AmtLock == 0 &&
|
|
|
|
|
i.Status == 1);
|
|
|
|
|
if (putBin == null)
|
|
|
|
|
return putBin != null;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
//校验:出仓位
|
|
|
|
|
BinInfo? removeBin = BinInfoRepository.QueryByClause(i =>
|
|
|
|
|
i.No.Equals(binNo) && (i.ChargeStatus != 1) && i.Exists == 1 &&
|
|
|
|
|
i.AmtLock == 0);
|
|
|
|
|
return removeBin != null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 维修仓<->电池仓
|
|
|
|
|
/// code : 1代表电池仓与维修仓交互 2;代表车辆与维修仓交互
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="removeBinNo"></param>
|
|
|
|
|
/// <param name="putBinNo"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public Result<bool> Relocation(ushort removeBinNo, ushort putBinNo, int code=1)
|
|
|
|
|
{
|
|
|
|
|
/*if (!JudgeMaintenBin(removeBinNo, putBinNo, 9))
|
|
|
|
|
{
|
|
|
|
|
return Result<bool>.Fail("请选择一个维修仓号");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (code == 2)
|
|
|
|
|
{
|
|
|
|
|
if (!JudgeMaintenBin(removeBinNo, putBinNo,10))
|
|
|
|
|
{
|
|
|
|
|
return Result<bool>.Fail("入仓位状态有误");
|
|
|
|
|
return Result<bool>.Fail("请选择一个车辆仓位");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (!JudgeBin(removeBinNo, putBinNo))
|
|
|
|
|
{
|
|
|
|
|
return Result<bool>.Fail("请选择一个电池仓位");
|
|
|
|
|
}
|
|
|
|
|
}*/
|
|
|
|
|
if (removeBinNo == putBinNo)
|
|
|
|
|
{
|
|
|
|
|
return Result<bool>.Fail("请勿选择同一指令");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
MoveBinRecord moveBinRecord = null;
|
|
|
|
|
|
|
|
|
|
//TODO::判断是否存在其他任务
|
|
|
|
|
/*if (PlcMgr.PlcClient?.ReadTaskNo() != 0)
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
if (!JudgeCanMove(removeBinNo, 1))
|
|
|
|
|
{
|
|
|
|
|
Log.Info("当前存在其他任务");
|
|
|
|
|
return Result<bool>.Fail("当前存在其他任务");
|
|
|
|
|
}*/
|
|
|
|
|
return Result<bool>.Fail("出仓位状态有误");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
moveBinRecord = new MoveBinRecord()
|
|
|
|
|
if (!JudgeCanMove(putBinNo, 0))
|
|
|
|
|
{
|
|
|
|
|
UpBinNo = removeBinNo.ToString(),
|
|
|
|
|
UpBatteryNo = removeBin.BatteryNo,
|
|
|
|
|
UpBatterySoc = removeBin.Soc.ToString(),
|
|
|
|
|
InBatteryNo = putBin.BatteryNo,
|
|
|
|
|
InBatterySoc = putBin.Soc.ToString(),
|
|
|
|
|
InBinNo = putBinNo.ToString(),
|
|
|
|
|
Status = 0,
|
|
|
|
|
Type = type,
|
|
|
|
|
CreatedTime = DateTime.Now
|
|
|
|
|
};
|
|
|
|
|
moveBinRecord = MoveBinRecordRepository.Insert(moveBinRecord);
|
|
|
|
|
|
|
|
|
|
//发送移仓任务
|
|
|
|
|
MoveCommandReq MoveCommandReq = new MoveCommandReq((byte)removeBinNo, (byte)putBinNo);
|
|
|
|
|
PlcServer PlcServer = new PlcServer();
|
|
|
|
|
PlcServer.SendMoveCommandReq(MoveCommandReq);
|
|
|
|
|
//TODO::判断任务是否执行
|
|
|
|
|
return Result<bool>.Fail("入仓位状态有误");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
moveBinRecord = BatteryMove(removeBinNo, putBinNo, 1);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
Log.Error($"move battery fail e={e.Message}");
|
|
|
|
|
Log.Error($" Maintenance code={code} move battery fail e={e.Message}");
|
|
|
|
|
ClientMgr.PlcClient.BatteryMoveDone = false;
|
|
|
|
|
if (moveBinRecord != null)
|
|
|
|
|
{
|
|
|
|
|
moveBinRecord.Status = 3;
|
|
|
|
@ -341,7 +444,47 @@ public class MonitorService
|
|
|
|
|
return Result<bool>.Fail();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return Result<bool>.Success();
|
|
|
|
|
return moveBinRecord.Status == 2 ? Result<bool>.Success() : Result<bool>.Fail();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public MoveBinRecord BatteryMove(ushort removeBinNo, ushort putBinNo, int type)
|
|
|
|
|
{
|
|
|
|
|
MoveBinRecord moveBinRecord = null;
|
|
|
|
|
BinInfo? removeBin = BinInfoRepository.QueryByClause(i => i.No.Equals(removeBinNo));
|
|
|
|
|
BinInfo? putBin = BinInfoRepository.QueryByClause(i => i.No.Equals(putBinNo));
|
|
|
|
|
|
|
|
|
|
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,
|
|
|
|
|
CreatedTime = DateTime.Now
|
|
|
|
|
};
|
|
|
|
|
moveBinRecord = MoveBinRecordRepository.Insert(moveBinRecord);
|
|
|
|
|
moveBinRecord.Status = 2;
|
|
|
|
|
int timeOut = 60; //接受指令完成时间
|
|
|
|
|
|
|
|
|
|
int count = 0;
|
|
|
|
|
//发送移仓任务
|
|
|
|
|
PlcApi.StartBatteryMove(removeBinNo.ToString(), putBinNo.ToString());
|
|
|
|
|
while (!ClientMgr.PlcClient.BatteryMoveDone || count < timeOut)
|
|
|
|
|
{
|
|
|
|
|
count++;
|
|
|
|
|
Thread.Sleep(3000);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!ClientMgr.PlcClient.BatteryMoveDone)
|
|
|
|
|
{
|
|
|
|
|
moveBinRecord.Status = 3;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MoveBinRecordRepository.Update(moveBinRecord);
|
|
|
|
|
return moveBinRecord;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|