充电订单添加手动自动生成,

实时通讯
zw
rszn 7 months ago
parent 9b1e35b56f
commit 67d493c5bb

@ -37,7 +37,7 @@ namespace Entity.DbModel.Station
public string BatteryNo { get; set; }
/// <summary>
/// Desc:启动报文状态;0-初始化1-启动成功
/// Desc:启动报文状态;0-初始化1-启动成功2-启动失败
/// Default:0
/// Nullable:True
/// </summary>
@ -284,5 +284,11 @@ namespace Entity.DbModel.Station
/// </summary>
[SugarColumn(ColumnName = "can_upload")]
public int CanUpload { get; set; }
/// <summary>
/// 启动方式0-站控自动启动1-站控手动启动2-充电机启动
/// </summary>
[SugarColumn(ColumnName = "start_type")]
public int StartType { get; set; }
}
}

@ -50,7 +50,7 @@ public class ChargerService
float? chargePower = EquipInfoRepository.QueryPowerByCode(binInfo.ChargerNo);
float? power = chargePower == null ? StaticStationInfo.ChargePower : chargePower;
return chargerClient.StartCharge(chargeSoc,(float)power);
return chargerClient.StartCharge(chargeSoc,(float)power, 1);
}
/// <summary>
@ -138,7 +138,7 @@ public class ChargerService
TimePeak6 = (byte)(elecPriceModelVersionDetails.Count > 5?Convert.ToByte(elecPriceModelVersionDetails[5].Type):0),
TimePeak7 = (byte)(elecPriceModelVersionDetails.Count > 6?Convert.ToByte(elecPriceModelVersionDetails[6].Type):0),
TimePeak8 = (byte)(elecPriceModelVersionDetails.Count > 7?Convert.ToByte(elecPriceModelVersionDetails[7].Type):0)
};
};
return setPeakValleyTime;
}
@ -162,4 +162,4 @@ public class ChargerService
batteryStatusInfoResp.chargingCount = chargingCounts.Count();
return Result<BatteryStatusInfoResp>.Success(batteryStatusInfoResp);
}
}
}

@ -611,7 +611,7 @@ public class ChargerClient : TcpClient<IBaseHandler, Decoder, Encoder>
/// <summary>
///
/// </summary>
public Result<bool> StartCharge(byte chargeSoc, float chargePower)
public Result<bool> StartCharge(byte chargeSoc, float chargePower, int startType)
{
if (string.IsNullOrWhiteSpace(BinNo))
{
@ -673,7 +673,8 @@ public class ChargerClient : TcpClient<IBaseHandler, Decoder, Encoder>
ChargerNo = BinNo,
ChargeMode = 1,
SwapOrderSn = swapOrder?.SwapOrderSn,
StartMode = 1
StartMode = 1,
StartType = startType
});
return Result<bool>.Success(true, "发送成功");

@ -97,7 +97,8 @@ namespace Service.Charger.Handler
AcFlatElecCount = Convert.ToDecimal(acPowersPeriods[2]),
AcValleyElecCount = Convert.ToDecimal(acPowersPeriods[3]),
ChargeMode = msg.ChargeMode,
StartMode = msg.StartMode
StartMode = msg.StartMode,
StartType = 2
};
_chargeOrderRepository.Insert(chargeOrder);

@ -85,7 +85,7 @@ public class AutoChargeTask : ITask
foreach (var VARIABLE in elecPriceModelVersionDetails)
{
// 构造开始和结束的DateTime对象使用当前日期的年月日
// 构造开始和结束的DateTime对象使用当前日期的年月日
DateTime startTime = new DateTime(now.Year, now.Month, now.Day, VARIABLE.StartHour,
VARIABLE.StartMinute, 0);
DateTime endTime = new DateTime(now.Year, now.Month, now.Day, VARIABLE.EndHour, VARIABLE.EndMinute, 0);
@ -185,7 +185,7 @@ public class AutoChargeTask : ITask
{
//没有充电时候在充电
Result<bool>? result = ClientMgr.GetBySn(binInfo.ChargerNo)
?.StartCharge(chargeSoc, (float)power);
?.StartCharge(chargeSoc, (float)power, 0);
if (result is { IsSuccess: true })
{
Log.Info($"auto start charge {binInfo.ChargerNo}");
@ -236,4 +236,4 @@ public class AutoChargeTask : ITask
{
_stop = false;
}
}
}

@ -0,0 +1,90 @@
using log4net;
using Microsoft.AspNetCore.SignalR.Client;
using Newtonsoft.Json;
namespace Service.RealTime;
public class RealtimeClient
{
/// <summary>
/// 循环时用的随机数值
/// </summary>
private static UInt16 _cysSeqNum = 0;
/// <summary>
/// 计算循环用UInt16随机数值
/// </summary>
/// <returns></returns>
public static UInt16 GetUInt16SeqNum()
{
if (_cysSeqNum < 65535)
{
_cysSeqNum += 1;
}
else
{
_cysSeqNum = 1;
}
return _cysSeqNum;
}
private static readonly ILog Log = LogManager.GetLogger(typeof(RealtimeClient));
private static readonly JsonSerializerSettings settings = new JsonSerializerSettings()
{
ReferenceLoopHandling = ReferenceLoopHandling.Ignore,
DateFormatString = "yyyy-MM-dd HH:mm:ss",
NullValueHandling = NullValueHandling.Ignore
};
private static HubConnection? hubConnection;
public static void Init()
{
hubConnection = new HubConnectionBuilder().WithUrl("http://127.0.0.1:5034/realtime").WithAutomaticReconnect()
.Build();
hubConnection.ServerTimeout = TimeSpan.FromMinutes(1);
hubConnection.KeepAliveInterval = TimeSpan.FromMinutes(1);
hubConnection.StartAsync();
hubConnection.Reconnected += (s) =>
{
Log.Info($"{s} connected");
return Task.CompletedTask;
};
hubConnection.On("ReceiveMsg", (string msg) => { Log.Info($"receive {msg}"); });
}
public static void SendMsg(string msg)
{
hubConnection?.SendAsync("SendMsg", "host", msg);
}
public static void SendWithoutResult(string msg)
{
hubConnection?.SendAsync("InvokeWithoutResult", JsonConvert.SerializeObject(new RtMsg()
{
Id = GetUInt16SeqNum(),
Cmd = "cmd",
Datetime = DateTime.Now,
FromUser = "charger",
Msg = msg
}));
}
public static string? SendWithResult(string msg)
{
var result = hubConnection?.InvokeAsync<RtMsg>("Invoke", new RtMsg()
{
Id = GetUInt16SeqNum(),
Cmd = "cmd",
Datetime = DateTime.Now,
FromUser = "charger",
Msg = msg
}).Result;
Log.Info($"result={result}");
return result.FromUser;
}
}

@ -0,0 +1,11 @@
namespace Service.RealTime;
public class RtMsg
{
public int Id { get; set; }
public string FromUser { get; set; }
public string ToUser { get; set; }
public DateTime Datetime { get; set; }
public string Cmd { get; set; }
public string Msg { get; set; }
}

@ -27,6 +27,7 @@
<PackageReference Include="HslCommunication" Version="11.1.1" />
<PackageReference Include="log4net" Version="2.0.15" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Core" Version="2.2.5" />
<PackageReference Include="Microsoft.AspNetCore.SignalR.Client" Version="6.0.31" />
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="7.0.0" />
<PackageReference Include="Quartz" Version="3.8.1" />

@ -1,5 +1,5 @@
using Microsoft.AspNetCore.Mvc;
using Repository.Station;
using Service.RealTime;
using SqlSugar;
namespace WebStarter.Controllers.Test;
@ -13,7 +13,7 @@ public class GenController : ControllerBase
public GenController(ISqlSugarClient sqlSugarClient)
{
_sqlSugarClient = sqlSugarClient;
}
/// <summary>
@ -35,8 +35,28 @@ public class GenController : ControllerBase
Console.WriteLine("生成完毕");
}
/// <summary>
/// 测试发送
/// </summary>
/// <param name="msg"></param>
/// <returns></returns>
[HttpGet("send/{msg}")]
public string? Send(string msg)
{
return RealtimeClient.SendWithResult(msg);
}
/// <summary>
/// 测试发送
/// </summary>
/// <param name="msg"></param>
/// <returns></returns>
[HttpGet("send3/{msg}")]
public void Send3(string msg)
{
RealtimeClient.SendMsg(msg);
}
static string ToPascalCase(string input)
@ -54,4 +74,6 @@ public class GenController : ControllerBase
return res;
}
}
}

@ -8,6 +8,7 @@ using HybirdFrameworkCore.Job;
using HybirdFrameworkCore.Redis;
using log4net;
using Service.Charger.Client;
using Service.RealTime;
using SqlSugar;
using SqlSugar.IOC;
@ -105,4 +106,11 @@ ClientMgr.InitClient();
TaskInit.Init();
QuartzSchedulerFactory.Init();
app.Lifetime.ApplicationStopping.Register(QuartzSchedulerFactory.Shutdown);
bool.TryParse(AppSettingsHelper.GetContent("SignalR", "Enabled"), out var signalrEnabled);
if (signalrEnabled)
{
RealtimeClient.Init();
}
app.Run();

@ -3,6 +3,7 @@
<ImportGroup Condition=" '$(ExcludeRestorePackageImports)' != 'true' ">
<Import Project="$(NuGetPackageRoot)system.text.json\7.0.4\buildTransitive\net6.0\System.Text.Json.targets" Condition="Exists('$(NuGetPackageRoot)system.text.json\7.0.4\buildTransitive\net6.0\System.Text.Json.targets')" />
<Import Project="$(NuGetPackageRoot)microsoft.extensions.apidescription.server\6.0.5\build\Microsoft.Extensions.ApiDescription.Server.targets" Condition="Exists('$(NuGetPackageRoot)microsoft.extensions.apidescription.server\6.0.5\build\Microsoft.Extensions.ApiDescription.Server.targets')" />
<Import Project="$(NuGetPackageRoot)microsoft.extensions.logging.abstractions\6.0.4\buildTransitive\netcoreapp3.1\Microsoft.Extensions.Logging.Abstractions.targets" Condition="Exists('$(NuGetPackageRoot)microsoft.extensions.logging.abstractions\6.0.4\buildTransitive\netcoreapp3.1\Microsoft.Extensions.Logging.Abstractions.targets')" />
<Import Project="$(NuGetPackageRoot)sqlitepclraw.lib.e_sqlite3\2.1.4\buildTransitive\net6.0\SQLitePCLRaw.lib.e_sqlite3.targets" Condition="Exists('$(NuGetPackageRoot)sqlitepclraw.lib.e_sqlite3\2.1.4\buildTransitive\net6.0\SQLitePCLRaw.lib.e_sqlite3.targets')" />
</ImportGroup>
</Project>

@ -2,6 +2,7 @@
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ImportGroup Condition=" '$(ExcludeRestorePackageImports)' != 'true' ">
<Import Project="$(NuGetPackageRoot)system.text.json\7.0.0\buildTransitive\net6.0\System.Text.Json.targets" Condition="Exists('$(NuGetPackageRoot)system.text.json\7.0.0\buildTransitive\net6.0\System.Text.Json.targets')" />
<Import Project="$(NuGetPackageRoot)microsoft.extensions.logging.abstractions\6.0.4\buildTransitive\netcoreapp3.1\Microsoft.Extensions.Logging.Abstractions.targets" Condition="Exists('$(NuGetPackageRoot)microsoft.extensions.logging.abstractions\6.0.4\buildTransitive\netcoreapp3.1\Microsoft.Extensions.Logging.Abstractions.targets')" />
<Import Project="$(NuGetPackageRoot)sqlitepclraw.lib.e_sqlite3\2.1.4\buildTransitive\net6.0\SQLitePCLRaw.lib.e_sqlite3.targets" Condition="Exists('$(NuGetPackageRoot)sqlitepclraw.lib.e_sqlite3\2.1.4\buildTransitive\net6.0\SQLitePCLRaw.lib.e_sqlite3.targets')" />
</ImportGroup>
</Project>
</Project>

Loading…
Cancel
Save