移库功能

master
lxw 1 month ago
parent 44a8fd1d8c
commit d087d6940d

@ -58,6 +58,8 @@ public class SwapConstant
Init, Init,
[Const("下发启动换电")] [Const("下发启动换电")]
StartSwap, StartSwap,
[Const("电池搬运")]
StartBatteryMove
} }

@ -24,7 +24,7 @@ public class PlcApi
/// <returns></returns> /// <returns></returns>
public static bool IsRemote() public static bool IsRemote()
{ {
return ClientMgr.PlcClient.Remote; return ClientMgr.PlcClient!.Remote;
} }
/// <summary> /// <summary>
@ -33,7 +33,7 @@ public class PlcApi
/// <returns></returns> /// <returns></returns>
public static bool IsInit() public static bool IsInit()
{ {
return ClientMgr.PlcClient.Init; return ClientMgr.PlcClient!.Init;
} }
/// <summary> /// <summary>
@ -68,6 +68,26 @@ public class PlcApi
return ClientMgr.PlcClient.SwapStart; return ClientMgr.PlcClient.SwapStart;
} }
/// <summary>
/// 电池搬运
/// </summary>
/// <returns></returns>
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;
}
/// <summary> /// <summary>
/// 发送初始化命令 /// 发送初始化命令

@ -42,6 +42,11 @@ public class PlcClient : TcpClient<IBaseHandler, Decoder, Encoder>
/// </summary> /// </summary>
public bool SwapStart { get; set; } public bool SwapStart { get; set; }
/// <summary>
/// 电池搬运结束
/// </summary>
public bool BatteryMoveDone { get; set; }
public bool DisassembleDone { get; set; } public bool DisassembleDone { get; set; }
//自动模式 //自动模式
@ -54,7 +59,8 @@ public class PlcClient : TcpClient<IBaseHandler, Decoder, Encoder>
public bool Init { get; set; } public bool Init { get; set; }
//9号仓是否有电池
public bool Is9Exist { get; set; }
private readonly BinInfoRepository _binInfoRepository; private readonly BinInfoRepository _binInfoRepository;

@ -5,6 +5,7 @@ using Entity.DbModel.Station;
using HybirdFrameworkCore.Autofac.Attribute; using HybirdFrameworkCore.Autofac.Attribute;
using log4net; using log4net;
using Repository.Station; using Repository.Station;
using Service.Charger.Client;
using Service.Charger.Msg.Charger.Req; using Service.Charger.Msg.Charger.Req;
@ -45,6 +46,9 @@ public class BatteryStatusReportedReqHandler : SimpleChannelInboundHandler<Batte
} }
ctx.Channel.WriteAndFlushAsync(message: new Msg.Host.Resp.WhetherChargedResq(granaries[0], granaries[1], granaries[2], granaries[3], granaries[4], granaries[5], granaries[6], granaries[7])); ctx.Channel.WriteAndFlushAsync(message: new Msg.Host.Resp.WhetherChargedResq(granaries[0], granaries[1], granaries[2], granaries[3], granaries[4], granaries[5], granaries[6], granaries[7]));
UpdateBinInfo(msg.granary01, "1");
ClientMgr.PlcClient!.Is9Exist = msg.granary09==1;
// ctx.Channel.WriteAndFlushAsync(message: new Msg.Host.Req.WhetherChargedReq());
UpdateBinInfo(msg.granary01, "1"); UpdateBinInfo(msg.granary01, "1");
UpdateBinInfo(msg.granary02, "2"); UpdateBinInfo(msg.granary02, "2");
UpdateBinInfo(msg.granary03, "3"); UpdateBinInfo(msg.granary03, "3");
@ -55,6 +59,8 @@ public class BatteryStatusReportedReqHandler : SimpleChannelInboundHandler<Batte
UpdateBinInfo(msg.granary08, "8"); UpdateBinInfo(msg.granary08, "8");
// UpdateBinInfo(msg.granary09, "9"); // UpdateBinInfo(msg.granary09, "9");
} }
private void UpdateBinInfo(int exists, string binNo) private void UpdateBinInfo(int exists, string binNo)

@ -33,6 +33,7 @@ public class MigrationCompleteReqHandler : SimpleChannelInboundHandler<Migration
Log.Info("Move library finish"); Log.Info("Move library finish");
ctx.Channel.WriteAndFlushAsync(message: new Msg.Host.Resp.MigrationCompleteResq()); ctx.Channel.WriteAndFlushAsync(message: new Msg.Host.Resp.MigrationCompleteResq());
ClientMgr.PlcClient!.BatteryMoveDone = true;
} }

@ -203,7 +203,8 @@ public enum SoundEnum
music107,//[Info(" 选包失败")] ErrStartSwap, music107,//[Info(" 选包失败")] ErrStartSwap,
music108,//[Info(" 车辆验证失败印尼")] ErrStartSwap, music108,//[Info(" 车辆验证失败印尼")] ErrStartSwap,
music109,//[Info(" 车辆验证失败")] ErrStartSwap, music109,//[Info(" 车辆验证失败")] ErrStartSwap,
music110,// 消防报警,禁止车辆再次进入换电
music111,// 消防报警,禁止车辆再次进入换电 印尼
/* /*

@ -180,9 +180,6 @@ public class MonitorService
if (monitorScreenResp.VehicleInfo.OrderNo != null) if (monitorScreenResp.VehicleInfo.OrderNo != null)
{ {
SwapOrderBattery queryByClauseAsync = SwapOrderBattery queryByClauseAsync =
_SwapOrderBatteryRepository.QueryByClause(u => u.SwapOrderSn == monitorScreenResp.VehicleInfo.OrderNo); _SwapOrderBatteryRepository.QueryByClause(u => u.SwapOrderSn == monitorScreenResp.VehicleInfo.OrderNo);
if (queryByClauseAsync != null) if (queryByClauseAsync != null)
@ -204,7 +201,6 @@ public class MonitorService
TimeSpan duration = DateTime.Now - swapOrder.SwapBeginTime.Value; TimeSpan duration = DateTime.Now - swapOrder.SwapBeginTime.Value;
monitorScreenResp.VehicleInfo.SwapDuration = duration.ToString(@"hh\:mm\:ss"); monitorScreenResp.VehicleInfo.SwapDuration = duration.ToString(@"hh\:mm\:ss");
} }
} }
@ -279,69 +275,216 @@ 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)
{ {
MoveBinRecord moveBinRecord = null; MoveBinRecord moveBinRecord = null;
try try
{
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(binNo) && i.Exists == 0 && i.AmtLock == 0 &&
i.Status == 1);
return putBin != null;
}
else
{ {
//校验:出仓位 //校验:出仓位
BinInfo? removeBin = BinInfoRepository.QueryByClause(i => BinInfo? removeBin = BinInfoRepository.QueryByClause(i =>
i.No.Equals(removeBinNo) && (i.ChargeStatus != 1) && i.Exists == 1 && i.No.Equals(binNo) && (i.ChargeStatus != 1) && i.Exists == 1 &&
i.AmtLock == 0); i.AmtLock == 0);
return removeBin != null;
}
}
if (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("请选择一个车辆仓位");
}
}
else
{
if (!JudgeBin(removeBinNo, putBinNo))
{
return Result<bool>.Fail("请选择一个电池仓位");
}
}*/
if (removeBinNo == putBinNo)
{
return Result<bool>.Fail("请勿选择同一指令");
}
MoveBinRecord moveBinRecord = null;
try
{
if (!JudgeCanMove(removeBinNo, 1))
{ {
return Result<bool>.Fail("出仓位状态有误"); return Result<bool>.Fail("出仓位状态有误");
} }
BinInfo? putBin = BinInfoRepository.QueryByClause(i => if (!JudgeCanMove(putBinNo, 0))
i.No.Equals(putBinNo) && i.Exists == 0 && i.AmtLock == 0 &&
i.Status == 1);
if (putBin == null)
{ {
return Result<bool>.Fail("入仓位状态有误"); return Result<bool>.Fail("入仓位状态有误");
} }
//TODO::判断是否存在其他任务 moveBinRecord = BatteryMove(removeBinNo, putBinNo, 1);
/*if (PlcMgr.PlcClient?.ReadTaskNo() != 0) }
catch (Exception e)
{ {
Log.Info("当前存在其他任务"); Log.Error($" Maintenance code={code} move battery fail e={e.Message}");
return Result<bool>.Fail("当前存在其他任务"); 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();
}
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() moveBinRecord = new MoveBinRecord()
{ {
UpBinNo = removeBinNo.ToString(), UpBinNo = removeBinNo.ToString(),
UpBatteryNo = removeBin.BatteryNo, UpBatteryNo = removeBin!.BatteryNo,
UpBatterySoc = removeBin.Soc.ToString(), UpBatterySoc = removeBin!.Soc.ToString(),
InBatteryNo = putBin.BatteryNo, InBatteryNo = putBin!.BatteryNo,
InBatterySoc = putBin.Soc.ToString(), InBatterySoc = putBin!.Soc.ToString(),
InBinNo = putBinNo.ToString(), InBinNo = putBinNo.ToString(),
Status = 0, Status = 0,
Type = type, Type = type,
CreatedTime = DateTime.Now CreatedTime = DateTime.Now
}; };
moveBinRecord = MoveBinRecordRepository.Insert(moveBinRecord); moveBinRecord = MoveBinRecordRepository.Insert(moveBinRecord);
moveBinRecord.Status = 2;
int timeOut = 60; //接受指令完成时间
int count = 0;
//发送移仓任务 //发送移仓任务
MoveCommandReq MoveCommandReq = new MoveCommandReq((byte)removeBinNo, (byte)putBinNo); PlcApi.StartBatteryMove(removeBinNo.ToString(), putBinNo.ToString());
PlcServer PlcServer = new PlcServer(); while (!ClientMgr.PlcClient.BatteryMoveDone || count < timeOut)
PlcServer.SendMoveCommandReq(MoveCommandReq);
//TODO::判断任务是否执行
}
catch (Exception e)
{
Log.Error($"move battery fail e={e.Message}");
if (moveBinRecord != null)
{ {
moveBinRecord.Status = 3; count++;
MoveBinRecordRepository.Update(moveBinRecord); Thread.Sleep(3000);
} }
return Result<bool>.Fail(); if (!ClientMgr.PlcClient.BatteryMoveDone)
{
moveBinRecord.Status = 3;
} }
return Result<bool>.Success(); MoveBinRecordRepository.Update(moveBinRecord);
return moveBinRecord;
} }

@ -1,11 +1,17 @@
using Autofac;
using Entity.Api.Req; using Entity.Api.Req;
using Entity.Api.Resp; using Entity.Api.Resp;
using Entity.DbModel.Station; using Entity.DbModel.Station;
using HybirdFrameworkCore.Autofac;
using HybirdFrameworkCore.Entity; using HybirdFrameworkCore.Entity;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Localization; using Microsoft.Extensions.Localization;
using Newtonsoft.Json;
using Service.Charger.Msg.Host.Req; using Service.Charger.Msg.Host.Req;
using Service.Charger.Server; using Service.Charger.Server;
using Service.Execute.Api;
using Service.RealTime;
using Service.Sound.SoundClient;
using Service.Station; using Service.Station;
namespace WebStarter.Controllers; namespace WebStarter.Controllers;
@ -21,7 +27,8 @@ public class ChargeMonitorController
private readonly MonitorService _monitorService; private readonly MonitorService _monitorService;
private readonly IStringLocalizer<ChargeMonitorController> _localizer; private readonly IStringLocalizer<ChargeMonitorController> _localizer;
public ChargeMonitorController(IStringLocalizer<ChargeMonitorController> localizer,BinInfoService binInfoService, MonitorService monitorService) public ChargeMonitorController(IStringLocalizer<ChargeMonitorController> localizer, BinInfoService binInfoService,
MonitorService monitorService)
{ {
_localizer = localizer; _localizer = localizer;
@ -86,13 +93,14 @@ public class ChargeMonitorController
[FromBody] ChargePositionQueryReq chargePositionQueryReq) [FromBody] ChargePositionQueryReq chargePositionQueryReq)
{ {
PageResult<BinInfo> respList = await _binInfoService.ChargePositionQuery(chargePositionQueryReq); PageResult<BinInfo> respList = await _binInfoService.ChargePositionQuery(chargePositionQueryReq);
if (respList.Rows!=null) if (respList.Rows != null)
{ {
foreach (var resp in respList.Rows) foreach (var resp in respList.Rows)
{ {
resp.Name = _localizer[resp.Name]; resp.Name = _localizer[resp.Name];
} }
} }
return Result<PageResult<BinInfo>>.Success(respList); return Result<PageResult<BinInfo>>.Success(respList);
} }
@ -127,18 +135,32 @@ public class ChargeMonitorController
[HttpGet("BatteryRelocation")] [HttpGet("BatteryRelocation")]
public async Task<Result<bool>> BatteryRelocation(ushort removeBinNo, ushort putBinNo) public async Task<Result<bool>> BatteryRelocation(ushort removeBinNo, ushort putBinNo)
{ {
Result<bool> res = Result<bool>.Fail(); return _monitorService.BatteryRelocation(removeBinNo, putBinNo);
try
{
res = _monitorService.BatteryRelocation(removeBinNo, putBinNo, 1);
} }
catch (Exception e)
/// <summary>
/// 移库
/// </summary>
/// <param name="removeBinNo">取仓号</param>
/// <param name="putBinNo">放仓号</param>
/// <returns></returns>
[HttpGet("Relocation")]
public async Task<Result<bool>> Relocation(ushort removeBinNo, ushort putBinNo)
{ {
Result<bool>.Fail(); return _monitorService.Relocation(removeBinNo, putBinNo, 1);
} }
return res; } /*/// <summary>
/// 维修仓-车辆
/// </summary>
/// <param name="removeBinNo">取仓号</param>
/// <param name="putBinNo">放仓号</param>
/// <returns></returns>
[HttpGet("MaintenanceVehicle")]
public async Task<Result<bool>> MaintenanceVehicle(ushort removeBinNo, ushort putBinNo)
{
return _monitorService.Maintenance(removeBinNo, putBinNo, 2);
}*/
/// <summary> /// <summary>
/// 移仓时下拉项 仓位电池状态 /// 移仓时下拉项 仓位电池状态
@ -147,13 +169,86 @@ public class ChargeMonitorController
public Result<List<BinInfoResp>> GetChargeBinOption() public Result<List<BinInfoResp>> GetChargeBinOption()
{ {
Result<List<BinInfoResp>> respList = _monitorService.GetChargeBinOption(); Result<List<BinInfoResp>> respList = _monitorService.GetChargeBinOption();
if (respList.Data!=null) if (respList.Data != null)
{
foreach (var resp in respList.Data)
{
resp.Name = _localizer[resp.Name];
}
}
return respList;
}
/// <summary>
/// 增加维修仓 车辆仓
/// </summary>
[HttpGet("GetMaintenanceBinNo")]
public Result<List<BinInfoResp>> GetMaintenanceBinNo()
{
Result<List<BinInfoResp>> 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) foreach (var resp in respList.Data)
{ {
resp.Name = _localizer[resp.Name]; resp.Name = _localizer[resp.Name];
} }
} }
return respList; return respList;
} }
/// <summary>
/// 消防出仓
/// </summary>
[HttpGet("FireRemoval")]
public Result<bool> FireRemoval(int level, string levelStr, string binNo)
{
HubHolder.S2CMsg(JsonConvert.SerializeObject(new RtMsg
{
Cmd = "BatteryAlarm",
Msg = $"电池过温报警,等级:{levelStr},仓位号:{binNo},请人工检查电池是否异常"
})).Wait();
if (level != 3)
{
return Result<bool>.Success();
}
//报警提示
var soundClient = AppInfo.Container.Resolve<SoundClient>();
//TODO:: 录入播报素材
soundClient.SoundPlay(SoundEnum.music110);
Thread.Sleep(4000);
soundClient.SoundPlay(SoundEnum.music111);
//判断是否在换电中 通道是否有车
return Result<bool>.Success();
}
} }

@ -130,5 +130,23 @@ namespace WebStarter.Resources {
return ResourceManager.GetString("仓位8", resourceCulture); return ResourceManager.GetString("仓位8", resourceCulture);
} }
} }
/// <summary>
/// Looks up a localized string similar to Storage No. 9.
/// </summary>
internal static string {
get {
return ResourceManager.GetString("维修仓", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Storage No. 10.
/// </summary>
internal static string {
get {
return ResourceManager.GetString("车辆", resourceCulture);
}
}
} }
} }

@ -43,4 +43,11 @@
<data name="仓位8" xml:space="preserve"> <data name="仓位8" xml:space="preserve">
<value>Storage No. 8</value> <value>Storage No. 8</value>
</data> </data>
<data name="维修仓" xml:space="preserve">
<value>Storage No. 9</value>
</data>
<data name="车辆" xml:space="preserve">
<value>Storage No. 10</value>
</data>
</root> </root>
Loading…
Cancel
Save