diff --git a/Entity/Constant/SwapConstant.cs b/Entity/Constant/SwapConstant.cs
index e679e6f..4160148 100644
--- a/Entity/Constant/SwapConstant.cs
+++ b/Entity/Constant/SwapConstant.cs
@@ -58,6 +58,8 @@ public class SwapConstant
Init,
[Const("下发启动换电")]
StartSwap,
+ [Const("电池搬运")]
+ StartBatteryMove
}
diff --git a/Service/Execute/Api/PlcApi.cs b/Service/Execute/Api/PlcApi.cs
index 3b365ce..938dd3a 100644
--- a/Service/Execute/Api/PlcApi.cs
+++ b/Service/Execute/Api/PlcApi.cs
@@ -24,7 +24,7 @@ public class PlcApi
///
public static bool IsRemote()
{
- return ClientMgr.PlcClient.Remote;
+ return ClientMgr.PlcClient!.Remote;
}
///
@@ -33,7 +33,7 @@ public class PlcApi
///
public static bool IsInit()
{
- return ClientMgr.PlcClient.Init;
+ return ClientMgr.PlcClient!.Init;
}
///
@@ -68,6 +68,26 @@ public class PlcApi
return ClientMgr.PlcClient.SwapStart;
}
+ ///
+ /// 电池搬运
+ ///
+ ///
+ public static bool StartBatteryMove(string inBinNo, string outBinNo)
+ {
+
+ StationSoftMgr.PutDeviceLog((int)StationConstant.DeviceCode.Plc,SwapConstant.PlcProtocol.StartBatteryMove,
+
+ $"出仓位:{outBinNo},入仓位:{inBinNo}" ,(int)SwapConstant.CommunicationType.Send);
+
+ Log.Info($"PlcApi StartBatteryMove param= inBinNo={inBinNo}, outBinNo={outBinNo}");
+ ClientMgr.PlcClient?.SendMoveCommandReq(Convert.ToByte(outBinNo), Convert.ToByte(inBinNo));
+
+
+ Log.Info($"PlcApi StartBatteryMove done");
+ return ClientMgr.PlcClient.SwapStart;
+ }
+
+
///
/// 发送初始化命令
diff --git a/Service/Plc/Client/PlcClient.cs b/Service/Plc/Client/PlcClient.cs
index 49b822b..c3e7f18 100644
--- a/Service/Plc/Client/PlcClient.cs
+++ b/Service/Plc/Client/PlcClient.cs
@@ -41,6 +41,11 @@ public class PlcClient : TcpClient
/// 换电开始标记
///
public bool SwapStart { get; set; }
+
+ ///
+ /// 电池搬运结束
+ ///
+ public bool BatteryMoveDone { get; set; }
public bool DisassembleDone { get; set; }
@@ -54,7 +59,8 @@ public class PlcClient : TcpClient
public bool Init { get; set; }
-
+ //9号仓是否有电池
+ public bool Is9Exist { get; set; }
private readonly BinInfoRepository _binInfoRepository;
diff --git a/Service/Plc/Handler/BatteryStatusReportedReqHandler.cs b/Service/Plc/Handler/BatteryStatusReportedReqHandler.cs
index 2b7c3d4..bda9092 100644
--- a/Service/Plc/Handler/BatteryStatusReportedReqHandler.cs
+++ b/Service/Plc/Handler/BatteryStatusReportedReqHandler.cs
@@ -5,6 +5,7 @@ using Entity.DbModel.Station;
using HybirdFrameworkCore.Autofac.Attribute;
using log4net;
using Repository.Station;
+using Service.Charger.Client;
using Service.Charger.Msg.Charger.Req;
@@ -46,6 +47,9 @@ public class BatteryStatusReportedReqHandler : SimpleChannelInboundHandler 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
///
///
///
- public Result BatteryRelocation(ushort removeBinNo, ushort putBinNo, int type = 0)
+ public Result 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.Fail("出仓位状态有误");
}
+ if (!JudgeCanMove(putBinNo, 0))
+ {
+ return Result.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.Fail();
+ }
+
+ return moveBinRecord.Status == 2 ? Result.Success() : Result.Fail();
+ }
+
+
+ ///
+ /// 维修仓校验 /车辆
+ ///
+ ///
+ private bool JudgeMaintenBin(ushort removeBinNo, ushort putBinNo, ushort no)
+ {
+ //当前存在一个维修仓
+ HashSet set = new HashSet();
+ set.Add(removeBinNo);
+ set.Add(putBinNo);
+ return set.Contains(no);
+ }
+
+ ///
+ /// 电池仓
+ ///
+ ///
+ private bool JudgeBin(ushort removeBinNo, ushort putBinNo)
+ {
+ //当前存在一个维修仓
+ List set = new List();
+ set.Add(removeBinNo.ToString());
+ set.Add(putBinNo.ToString());
+ var bin = BinInfoRepository.Query().Select(i => i.No).ToList();
+ return set.Intersect(bin).Count() > 0;
+ }
+
+
+ ///
+ /// type : 0:入仓 1:出仓
+ ///
+ ///
+ ///
+ ///
+ 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;
+ }
+ }
+
+
+ ///
+ /// 维修仓<->电池仓
+ /// code : 1代表电池仓与维修仓交互 2;代表车辆与维修仓交互
+ ///
+ ///
+ ///
+ ///
+ public Result Relocation(ushort removeBinNo, ushort putBinNo, int code=1)
+ {
+ /*if (!JudgeMaintenBin(removeBinNo, putBinNo, 9))
+ {
+ return Result.Fail("请选择一个维修仓号");
+ }
+
+ if (code == 2)
+ {
+ if (!JudgeMaintenBin(removeBinNo, putBinNo,10))
{
- return Result.Fail("入仓位状态有误");
+ return Result.Fail("请选择一个车辆仓位");
+ }
+ }
+ else
+ {
+ if (!JudgeBin(removeBinNo, putBinNo))
+ {
+ return Result.Fail("请选择一个电池仓位");
}
+ }*/
+ if (removeBinNo == putBinNo)
+ {
+ return Result.Fail("请勿选择同一指令");
+ }
+
+
+ MoveBinRecord moveBinRecord = null;
- //TODO::判断是否存在其他任务
- /*if (PlcMgr.PlcClient?.ReadTaskNo() != 0)
+ try
+ {
+ if (!JudgeCanMove(removeBinNo, 1))
{
- Log.Info("当前存在其他任务");
- return Result.Fail("当前存在其他任务");
- }*/
+ return Result.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.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.Fail();
}
- return Result.Success();
+ return moveBinRecord.Status == 2 ? Result.Success() : Result.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;
}
diff --git a/WebStarter/Controllers/ChargeMonitorController.cs b/WebStarter/Controllers/ChargeMonitorController.cs
index 33dbc1d..d6b07b7 100644
--- a/WebStarter/Controllers/ChargeMonitorController.cs
+++ b/WebStarter/Controllers/ChargeMonitorController.cs
@@ -1,11 +1,17 @@
+using Autofac;
using Entity.Api.Req;
using Entity.Api.Resp;
using Entity.DbModel.Station;
+using HybirdFrameworkCore.Autofac;
using HybirdFrameworkCore.Entity;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Localization;
+using Newtonsoft.Json;
using Service.Charger.Msg.Host.Req;
using Service.Charger.Server;
+using Service.Execute.Api;
+using Service.RealTime;
+using Service.Sound.SoundClient;
using Service.Station;
namespace WebStarter.Controllers;
@@ -21,7 +27,8 @@ public class ChargeMonitorController
private readonly MonitorService _monitorService;
private readonly IStringLocalizer _localizer;
- public ChargeMonitorController(IStringLocalizer localizer,BinInfoService binInfoService, MonitorService monitorService)
+ public ChargeMonitorController(IStringLocalizer localizer, BinInfoService binInfoService,
+ MonitorService monitorService)
{
_localizer = localizer;
@@ -86,13 +93,14 @@ public class ChargeMonitorController
[FromBody] ChargePositionQueryReq chargePositionQueryReq)
{
PageResult respList = await _binInfoService.ChargePositionQuery(chargePositionQueryReq);
- if (respList.Rows!=null)
+ if (respList.Rows != null)
{
foreach (var resp in respList.Rows)
{
resp.Name = _localizer[resp.Name];
}
}
+
return Result>.Success(respList);
}
@@ -127,18 +135,32 @@ public class ChargeMonitorController
[HttpGet("BatteryRelocation")]
public async Task> BatteryRelocation(ushort removeBinNo, ushort putBinNo)
{
- Result res = Result.Fail();
- try
- {
-
- res = _monitorService.BatteryRelocation(removeBinNo, putBinNo, 1);
- }
- catch (Exception e)
- {
- Result.Fail();
- }
+ return _monitorService.BatteryRelocation(removeBinNo, putBinNo);
+ }
+
+ ///
+ /// 移库
+ ///
+ /// 取仓号
+ /// 放仓号
+ ///
+ [HttpGet("Relocation")]
+ public async Task> Relocation(ushort removeBinNo, ushort putBinNo)
+ {
+ return _monitorService.Relocation(removeBinNo, putBinNo, 1);
+ }
- return res; }
+ /*///
+ /// 维修仓-车辆
+ ///
+ /// 取仓号
+ /// 放仓号
+ ///
+ [HttpGet("MaintenanceVehicle")]
+ public async Task> MaintenanceVehicle(ushort removeBinNo, ushort putBinNo)
+ {
+ return _monitorService.Maintenance(removeBinNo, putBinNo, 2);
+ }*/
///
/// 移仓时下拉项 仓位电池状态
@@ -147,13 +169,86 @@ public class ChargeMonitorController
public Result> GetChargeBinOption()
{
Result> respList = _monitorService.GetChargeBinOption();
- if (respList.Data!=null)
+ if (respList.Data != null)
{
foreach (var resp in respList.Data)
{
resp.Name = _localizer[resp.Name];
}
}
+
return respList;
}
+
+
+ ///
+ /// 增加维修仓 车辆仓
+ ///
+ [HttpGet("GetMaintenanceBinNo")]
+ public Result> GetMaintenanceBinNo()
+ {
+ Result> respList = _monitorService.GetChargeBinOption();
+ BinInfoResp weiXiu = new BinInfoResp()
+ {
+ No = "9",
+ Name = "维修仓",
+ Id = 777,
+ };
+ BinInfoResp vehicle = new BinInfoResp()
+ {
+ No = "10",
+ Name = "车辆",
+ Id = 888,
+ };
+ BinInfoResp self = new BinInfoResp()
+ {
+ No = "0",
+ Name = "主体",
+ Id = 999,
+ };
+ respList.Data.Add(weiXiu);
+ respList.Data.Add(vehicle);
+ respList.Data.Add(self);
+ if (respList.Data != null)
+ {
+ foreach (var resp in respList.Data)
+ {
+ resp.Name = _localizer[resp.Name];
+ }
+ }
+
+ return respList;
+ }
+
+ ///
+ /// 消防出仓
+ ///
+ [HttpGet("FireRemoval")]
+ public Result FireRemoval(int level, string levelStr, string binNo)
+ {
+ HubHolder.S2CMsg(JsonConvert.SerializeObject(new RtMsg
+ {
+ Cmd = "BatteryAlarm",
+ Msg = $"电池过温报警,等级:{levelStr},仓位号:{binNo},请人工检查电池是否异常"
+ })).Wait();
+
+ if (level != 3)
+ {
+ return Result.Success();
+ }
+
+ //报警提示
+ var soundClient = AppInfo.Container.Resolve();
+
+ //TODO:: 录入播报素材
+ soundClient.SoundPlay(SoundEnum.music110);
+ Thread.Sleep(4000);
+ soundClient.SoundPlay(SoundEnum.music111);
+ //判断是否在换电中 通道是否有车
+
+
+
+
+ return Result.Success();
+ }
}
\ No newline at end of file
diff --git a/WebStarter/Resources/Controllers.ChargeMonitorController.en.Designer.cs b/WebStarter/Resources/Controllers.ChargeMonitorController.en.Designer.cs
index 585234e..33eb193 100644
--- a/WebStarter/Resources/Controllers.ChargeMonitorController.en.Designer.cs
+++ b/WebStarter/Resources/Controllers.ChargeMonitorController.en.Designer.cs
@@ -130,5 +130,23 @@ namespace WebStarter.Resources {
return ResourceManager.GetString("仓位8", resourceCulture);
}
}
+
+ ///
+ /// Looks up a localized string similar to Storage No. 9.
+ ///
+ internal static string 维修仓 {
+ get {
+ return ResourceManager.GetString("维修仓", resourceCulture);
+ }
+ }
+
+ ///
+ /// Looks up a localized string similar to Storage No. 10.
+ ///
+ internal static string 车辆 {
+ get {
+ return ResourceManager.GetString("车辆", resourceCulture);
+ }
+ }
}
}
diff --git a/WebStarter/Resources/Controllers.ChargeMonitorController.en.resx b/WebStarter/Resources/Controllers.ChargeMonitorController.en.resx
index 0c3bf7c..4f5d148 100644
--- a/WebStarter/Resources/Controllers.ChargeMonitorController.en.resx
+++ b/WebStarter/Resources/Controllers.ChargeMonitorController.en.resx
@@ -43,4 +43,11 @@
Storage No. 8
+
+ Storage No. 9
+
+
+ Storage No. 10
+
+
\ No newline at end of file