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

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>
@ -54,30 +69,27 @@ public class BinInfoRepository : BaseRepository<BinInfo>
_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)
{
selectPackDto.Info = InfoEnum.SelectBinStatusInfo.LessOfFinishCharging;
selectPackDto.Info = InfoEnum.SelectBinStatusInfo.LessOfSoc;
return selectPackDto;
}
list = list.Where(i => i.Soc != null &&i.Soc >= swapSoc).ToList();
if (list.Count <= 0)
// 符合soc不在充电
var socList = list.Where(i => i.ChargeStatus == 2 || i.ChargeStatus == 4).ToList();
if (socList.Count <= 0)
{
selectPackDto.Info = InfoEnum.SelectBinStatusInfo.LessOfSoc;
// 符合soc在充电
socList= list.Where(i => i.ChargeStatus == 1).ToList();
if (socList.Count <= 0)
{
selectPackDto.Info = InfoEnum.SelectBinStatusInfo.LessOfFinishCharging;
return selectPackDto;
}
}
/*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;
}*/
list = socList;
selectPackDto.BinInfo = list[0];

@ -1,10 +1,9 @@
using HybirdFrameworkCore.Entity;
using log4net;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Service.Execute.Model;
namespace Service.Execute.Api;
/// <summary>
/// chargeApi
/// </summary>
@ -19,9 +18,14 @@ public class ChargeApi
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}");
if (string.IsNullOrWhiteSpace(binNo))
{
return false;
}
string url = BASE_URL + "/api/Charge/StopChargeByBinNo/" + binNo;
try
{

@ -1,26 +1,21 @@
using Autofac;
using AutoMapper;
using Entity.Attr;
using Entity.Constant;
using Entity.DbModel.Station;
using Entity.Dto;
using HybirdFrameworkCore.Autofac;
using HybirdFrameworkCore.Configuration;
using log4net;
using OfficeOpenXml.FormulaParsing.Excel.Functions.Text;
using Newtonsoft.Json;
using Repository.Station;
using Service.Execute.Api;
using Service.Execute.Model;
using Service.Execute.Model.Tbox;
using Service.Execute.StaticTools;
using Service.Execute.SwapException;
using Service.Execute.Utils;
using Service.Init;
using Service.Led;
using Service.Padar.Client;
using Service.RealTime;
using Service.Sound.SoundClient;
using Service.Station;
using System.Runtime.CompilerServices;
namespace Service.Execute.Step;
@ -74,6 +69,13 @@ public class CarPrepareState : IState
return SwappingStateMachine.ReturnWithInvokeErr(selectPack, ExceptionReason.None);
}
//在充电的包停止充电
InvokeStatus stopChargingForUpBin = StopChargingForUpBin(machine);
if (stopChargingForUpBin != InvokeStatus.Done)
{
return SwappingStateMachine.ReturnWithInvokeErr(selectPack, ExceptionReason.StopChargingError);
}
//车辆到位
InvokeStatus carInPosition = CarInPosition(machine);
@ -412,5 +414,46 @@ public class CarPrepareState : IState
, 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,
LvPwrOffError,
SelfCheckError,
TimeOutError
TimeOutError,
StopChargingError,
}

@ -97,6 +97,9 @@ public class SwappingStateMachine : IDisposable
//选包
public bool SelectPackFlag = false;
//选包
public bool SelectPackStopChargingFlag = false;
//车辆到位
public bool VehiclesInPlaceFlag = false;
@ -380,6 +383,7 @@ public class SwappingStateMachine : IDisposable
SelectPackFlag = false;
SelectPackStopChargingFlag = 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
public async Task S2CMsg(string message)
{
await Clients.All.SendAsync("s2cMsg", message);
}
public async Task SendMsg(string toUser, string msg)
{
Log.Info($"receive {msg}");

@ -1,4 +1,6 @@
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json;
using Service.RealTime;
using Service.System;
namespace WebStarter.Controllers.Test;
@ -22,7 +24,7 @@ public class WeatherForecastController : ControllerBase
_sysUserServices = sysUserServices;
}
[HttpGet(Name = "GetWeatherForecast")]
[HttpGet("GetWeatherForecast")]
public IEnumerable<WeatherForecast> Get()
{
@ -37,4 +39,35 @@ public class WeatherForecastController : ControllerBase
})
.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 =>
{
options.AddPolicy
(name: "myCors",
builde =>
options.AddDefaultPolicy
(builde =>
{
builde.WithOrigins("*", "*", "*")
.AllowAnyOrigin()
builde
.SetIsOriginAllowed(_ => true)
.AllowAnyHeader()
.AllowAnyMethod();
.AllowAnyMethod()
.AllowCredentials();
}
);
});
@ -103,7 +103,7 @@ builder.Services.AddSwaggerGen(c =>
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)
{
builder.Services.AddSignalR(options =>
@ -151,7 +151,7 @@ app.UseSwaggerUI();
app.UseStaticFiles();
app.UseAuthorization();
app.UseCors("myCors");
app.UseCors();
app.MapControllers();
if (signalrEnabled)
{

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

Loading…
Cancel
Save