选包选中在充电的包,需要停止充电

master
wyy 2 months ago
parent 53f085da53
commit 71c5d519ae

@ -16,6 +16,21 @@ public class BinInfoRepository : BaseRepository<BinInfo>
{ {
} }
/// <summary>
///
/// </summary>
/// <param name="binNo"></param>
/// <returns></returns>
public BinInfo? SelectByBinNo(string? binNo)
{
if (string.IsNullOrWhiteSpace(binNo))
{
return null;
}
return this.QueryByClause(info => info.No == binNo);
}
/// <summary> /// <summary>
/// 选包 /// 选包
/// </summary> /// </summary>
@ -53,31 +68,28 @@ public class BinInfoRepository : BaseRepository<BinInfo>
list = list.Where(i => !upMoveNo.Equals(i.No) && i.No != "" && i.No != "-1").ToList(); list = list.Where(i => !upMoveNo.Equals(i.No) && i.No != "" && i.No != "-1").ToList();
_log.Info($"BinInfoRepository SelectPack list3={JsonConvert.SerializeObject(list)},upMoveNo={upMoveNo}"); _log.Info($"BinInfoRepository SelectPack list3={JsonConvert.SerializeObject(list)},upMoveNo={upMoveNo}");
} }
list = list.Where(i => i.ChargeStatus == 2 || i.ChargeStatus == 4).ToList(); list = list.Where(i => i.Soc != null &&i.Soc >= swapSoc).OrderByDescending(i => i.Soc).ToList();
if (list.Count <= 0) if (list.Count <= 0)
{ {
selectPackDto.Info = InfoEnum.SelectBinStatusInfo.LessOfFinishCharging; selectPackDto.Info = InfoEnum.SelectBinStatusInfo.LessOfSoc;
return selectPackDto; return selectPackDto;
} }
// 符合soc不在充电
list = list.Where(i => i.Soc != null &&i.Soc >= swapSoc).ToList(); var socList = list.Where(i => i.ChargeStatus == 2 || i.ChargeStatus == 4).ToList();
if (list.Count <= 0) if (socList.Count <= 0)
{ {
selectPackDto.Info = InfoEnum.SelectBinStatusInfo.LessOfSoc; // 符合soc在充电
return selectPackDto; socList= list.Where(i => i.ChargeStatus == 1).ToList();
if (socList.Count <= 0)
{
selectPackDto.Info = InfoEnum.SelectBinStatusInfo.LessOfFinishCharging;
return selectPackDto;
}
} }
list = socList;
/*list = list.Where(i => i.LastChargeFinishTime != null || new TimeSpan(DateTime.Now.Ticks -
i.LastChargeFinishTime.ToDateTime().Ticks)
.TotalMinutes > swapFinishChargeTime).ToList();
if (list.Count <= 0)
{ selectPackDto.Info = InfoEnum.SelectBinStatusInfo.LessOf3Minute;
return selectPackDto;
}*/
selectPackDto.BinInfo = list[0]; selectPackDto.BinInfo = list[0];

@ -1,10 +1,9 @@
using HybirdFrameworkCore.Entity; using HybirdFrameworkCore.Entity;
using log4net; using log4net;
using Newtonsoft.Json; using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Service.Execute.Model;
namespace Service.Execute.Api; namespace Service.Execute.Api;
/// <summary> /// <summary>
/// chargeApi /// chargeApi
/// </summary> /// </summary>
@ -19,9 +18,14 @@ public class ChargeApi
Timeout = TimeSpan.FromSeconds(60) Timeout = TimeSpan.FromSeconds(60)
}; };
public static async Task<bool> StopCharge(string binNo) public static async Task<bool> StopCharge(string? binNo)
{ {
Log.Info($" ChargeApi StopCharge binNo={binNo}"); Log.Info($" ChargeApi StopCharge binNo={binNo}");
if (string.IsNullOrWhiteSpace(binNo))
{
return false;
}
string url = BASE_URL + "/api/Charge/StopChargeByBinNo/" + binNo; string url = BASE_URL + "/api/Charge/StopChargeByBinNo/" + binNo;
try try
{ {

@ -1,26 +1,21 @@
using Autofac; using Autofac;
using AutoMapper;
using Entity.Attr; using Entity.Attr;
using Entity.Constant; using Entity.Constant;
using Entity.DbModel.Station; using Entity.DbModel.Station;
using Entity.Dto;
using HybirdFrameworkCore.Autofac; using HybirdFrameworkCore.Autofac;
using HybirdFrameworkCore.Configuration;
using log4net; using log4net;
using OfficeOpenXml.FormulaParsing.Excel.Functions.Text; using Newtonsoft.Json;
using Repository.Station; using Repository.Station;
using Service.Execute.Api; using Service.Execute.Api;
using Service.Execute.Model; using Service.Execute.Model;
using Service.Execute.Model.Tbox; using Service.Execute.Model.Tbox;
using Service.Execute.StaticTools;
using Service.Execute.SwapException; using Service.Execute.SwapException;
using Service.Execute.Utils; using Service.Execute.Utils;
using Service.Init; using Service.Init;
using Service.Led; using Service.Led;
using Service.Padar.Client; using Service.Padar.Client;
using Service.RealTime;
using Service.Sound.SoundClient; using Service.Sound.SoundClient;
using Service.Station;
using System.Runtime.CompilerServices;
namespace Service.Execute.Step; namespace Service.Execute.Step;
@ -74,8 +69,15 @@ public class CarPrepareState : IState
return SwappingStateMachine.ReturnWithInvokeErr(selectPack, ExceptionReason.None); return SwappingStateMachine.ReturnWithInvokeErr(selectPack, ExceptionReason.None);
} }
//在充电的包停止充电
InvokeStatus stopChargingForUpBin = StopChargingForUpBin(machine);
if (stopChargingForUpBin != InvokeStatus.Done)
{
return SwappingStateMachine.ReturnWithInvokeErr(selectPack, ExceptionReason.StopChargingError);
}
//车辆到位 //车辆到位
InvokeStatus carInPosition = CarInPosition(machine); InvokeStatus carInPosition = CarInPosition(machine);
if (carInPosition != InvokeStatus.Done) if (carInPosition != InvokeStatus.Done)
{ {
@ -412,5 +414,46 @@ public class CarPrepareState : IState
, false, () => { }, 20, InvokeStatus.None); , false, () => { }, 20, InvokeStatus.None);
} }
public InvokeStatus StopChargingForUpBin(SwappingStateMachine machine)
{
return Invoker.Invoke("select pack - stop charging", 1000, 60, machine.IsCanceled,
() => machine.SelectPackStopChargingFlag,
() =>
{
if (machine is { SelectPackFlag: true, SwapOrderBatteryInfo.UpBinInfo.ChargeStatus: 1 })
{
var binNo = machine.SwapOrderBatteryInfo?.UpBinInfo.No;
BinInfo? binInfo = _CommonMgr._binInfoRepository.SelectByBinNo(binNo);
if (binInfo is { ChargeStatus: 4 })
{
machine.SwapOrderBatteryInfo.UpBinInfo = binInfo;
machine.SelectPackStopChargingFlag = true;
HubHolder.S2CMsg(JsonConvert.SerializeObject(new RtMsg
{
Cmd = "BeginStopChargingDone",
Msg = $"{binNo}"
})).Wait();
return;
}
//停止充电
HubHolder.S2CMsg(JsonConvert.SerializeObject(new RtMsg
{
Cmd = "BeginStopCharging",
Msg = $"{binNo}"
})).Wait();
Task<bool> stopCharge = ChargeApi.StopCharge(binNo);
stopCharge.Wait(TimeSpan.FromSeconds(10));
}
else
{
machine.SelectPackStopChargingFlag = true;
}
});
}
} }

@ -21,5 +21,6 @@ namespace Service.Execute.SwapException;
LockCarError, LockCarError,
LvPwrOffError, LvPwrOffError,
SelfCheckError, SelfCheckError,
TimeOutError TimeOutError,
StopChargingError,
} }

@ -96,6 +96,9 @@ public class SwappingStateMachine : IDisposable
//选包 //选包
public bool SelectPackFlag = false; public bool SelectPackFlag = false;
//选包
public bool SelectPackStopChargingFlag = false;
//车辆到位 //车辆到位
public bool VehiclesInPlaceFlag = false; public bool VehiclesInPlaceFlag = false;
@ -380,6 +383,7 @@ public class SwappingStateMachine : IDisposable
SelectPackFlag = false; SelectPackFlag = false;
SelectPackStopChargingFlag = false;
VehiclesInPlaceFlag = false; VehiclesInPlaceFlag = false;

@ -0,0 +1,15 @@
using Autofac;
using HybirdFrameworkCore.Autofac;
using Microsoft.AspNetCore.SignalR;
namespace Service.RealTime;
public class HubHolder
{
public static IHubContext<MyHub> HubContext { get; set; } = AppInfo.Container.Resolve<IHubContext<MyHub>>();
public static async Task S2CMsg(string msg)
{
await HubContext.Clients.All.SendAsync("s2cMsg", msg);
}
}

@ -23,6 +23,10 @@ public class MyHub : Hub
#region rpc #region rpc
public async Task S2CMsg(string message)
{
await Clients.All.SendAsync("s2cMsg", message);
}
public async Task SendMsg(string toUser, string msg) public async Task SendMsg(string toUser, string msg)
{ {
Log.Info($"receive {msg}"); Log.Info($"receive {msg}");

@ -1,4 +1,6 @@
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json;
using Service.RealTime;
using Service.System; using Service.System;
namespace WebStarter.Controllers.Test; namespace WebStarter.Controllers.Test;
@ -22,7 +24,7 @@ public class WeatherForecastController : ControllerBase
_sysUserServices = sysUserServices; _sysUserServices = sysUserServices;
} }
[HttpGet(Name = "GetWeatherForecast")] [HttpGet("GetWeatherForecast")]
public IEnumerable<WeatherForecast> Get() public IEnumerable<WeatherForecast> Get()
{ {
@ -37,4 +39,35 @@ public class WeatherForecastController : ControllerBase
}) })
.ToArray(); .ToArray();
} }
/// <summary>
/// 停止充电
/// </summary>
/// <returns></returns>
[HttpGet("BeginStopCharging")]
public string BeginStopCharging()
{
HubHolder.S2CMsg(JsonConvert.SerializeObject(new RtMsg()
{
Cmd = "BeginStopCharging",
Msg = "1"
})).Wait();
return "ok";
}
/// <summary>
/// 停止充电成功
/// </summary>
/// <returns></returns>
[HttpGet("EndStopCharging")]
public string EndStopCharging()
{
HubHolder.S2CMsg(JsonConvert.SerializeObject(new RtMsg()
{
Cmd = "BeginStopChargingDone",
Msg = "1"
})).Wait();
return "ok";
}
} }

@ -64,14 +64,14 @@ builder.Services.AddHttpContextAccessor();
//跨域 //跨域
builder.Services.AddCors(options => builder.Services.AddCors(options =>
{ {
options.AddPolicy options.AddDefaultPolicy
(name: "myCors", (builde =>
builde =>
{ {
builde.WithOrigins("*", "*", "*") builde
.AllowAnyOrigin() .SetIsOriginAllowed(_ => true)
.AllowAnyHeader() .AllowAnyHeader()
.AllowAnyMethod(); .AllowAnyMethod()
.AllowCredentials();
} }
); );
}); });
@ -103,7 +103,7 @@ builder.Services.AddSwaggerGen(c =>
c.IncludeXmlComments(Path.Combine(basePath, "HybirdFrameworkCore.xml"), true); c.IncludeXmlComments(Path.Combine(basePath, "HybirdFrameworkCore.xml"), true);
}); });
bool.TryParse(AppSettingsHelper.GetContent("SignalR", "Enabled"), out var signalrEnabled); bool.TryParse(AppSettingsHelper.GetContent("SignalR", "enable"), out var signalrEnabled);
if (signalrEnabled) if (signalrEnabled)
{ {
builder.Services.AddSignalR(options => builder.Services.AddSignalR(options =>
@ -151,7 +151,7 @@ app.UseSwaggerUI();
app.UseStaticFiles(); app.UseStaticFiles();
app.UseAuthorization(); app.UseAuthorization();
app.UseCors("myCors"); app.UseCors();
app.MapControllers(); app.MapControllers();
if (signalrEnabled) if (signalrEnabled)
{ {

@ -142,6 +142,9 @@
} }
} }
}, },
"SignalR": {
"enable": true
},
"cloud": { "cloud": {
"enable": false "enable": false
}, },

Loading…
Cancel
Save