移库功能

master
lxw 1 month ago
parent 44a8fd1d8c
commit d087d6940d

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

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

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

@ -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<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]));
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.granary02, "2");
UpdateBinInfo(msg.granary03, "3");
UpdateBinInfo(msg.granary04, "4");
@ -55,6 +59,8 @@ public class BatteryStatusReportedReqHandler : SimpleChannelInboundHandler<Batte
UpdateBinInfo(msg.granary08, "8");
// UpdateBinInfo(msg.granary09, "9");
}
private void UpdateBinInfo(int exists, string binNo)

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

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

@ -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)
@ -204,7 +201,6 @@ public class MonitorService
TimeSpan duration = DateTime.Now - swapOrder.SwapBeginTime.Value;
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("请勿选择同一指令");
}
//TODO::判断是否存在其他任务
/*if (PlcMgr.PlcClient?.ReadTaskNo() != 0)
MoveBinRecord moveBinRecord = null;
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;
}

@ -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<ChargeMonitorController> _localizer;
public ChargeMonitorController(IStringLocalizer<ChargeMonitorController> localizer,BinInfoService binInfoService, MonitorService monitorService)
public ChargeMonitorController(IStringLocalizer<ChargeMonitorController> localizer, BinInfoService binInfoService,
MonitorService monitorService)
{
_localizer = localizer;
@ -86,13 +93,14 @@ public class ChargeMonitorController
[FromBody] ChargePositionQueryReq chargePositionQueryReq)
{
PageResult<BinInfo> 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<PageResult<BinInfo>>.Success(respList);
}
@ -127,18 +135,32 @@ public class ChargeMonitorController
[HttpGet("BatteryRelocation")]
public async Task<Result<bool>> BatteryRelocation(ushort removeBinNo, ushort putBinNo)
{
Result<bool> res = Result<bool>.Fail();
try
{
return _monitorService.BatteryRelocation(removeBinNo, putBinNo);
}
res = _monitorService.BatteryRelocation(removeBinNo, putBinNo, 1);
}
catch (Exception e)
{
Result<bool>.Fail();
}
/// <summary>
/// 移库
/// </summary>
/// <param name="removeBinNo">取仓号</param>
/// <param name="putBinNo">放仓号</param>
/// <returns></returns>
[HttpGet("Relocation")]
public async Task<Result<bool>> Relocation(ushort removeBinNo, ushort putBinNo)
{
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>
/// 移仓时下拉项 仓位电池状态
@ -147,13 +169,86 @@ public class ChargeMonitorController
public Result<List<BinInfoResp>> 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)
{
resp.Name = _localizer[resp.Name];
}
}
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);
}
}
/// <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">
<value>Storage No. 8</value>
</data>
<data name="维修仓" xml:space="preserve">
<value>Storage No. 9</value>
</data>
<data name="车辆" xml:space="preserve">
<value>Storage No. 10</value>
</data>
</root>
Loading…
Cancel
Save