diff --git a/Common/Util/HttpUtil.cs b/Common/Util/HttpUtil.cs new file mode 100644 index 0000000..0ba10df --- /dev/null +++ b/Common/Util/HttpUtil.cs @@ -0,0 +1,22 @@ +using System.Text; +using Newtonsoft.Json; + +namespace Common.Util; + +public static class HttpUtil +{ + private static readonly HttpClient httpClient = new HttpClient(); + + public static async void SendPostRequest(T data, string url) + { + string jsonStr = JsonConvert.SerializeObject(data); + var content = new StringContent(jsonStr, Encoding.UTF8, "application/json"); + + HttpResponseMessage response = await httpClient.PostAsync(url, content); + + if (response.IsSuccessStatusCode) + { + await response.Content.ReadAsStringAsync(); + } + } +} \ No newline at end of file diff --git a/Entity/DbModel/Station/ChargeOrder.cs b/Entity/DbModel/Station/ChargeOrder.cs index fb64653..d204226 100644 --- a/Entity/DbModel/Station/ChargeOrder.cs +++ b/Entity/DbModel/Station/ChargeOrder.cs @@ -60,6 +60,14 @@ namespace Entity.DbModel.Station [SugarColumn(ColumnName = "charger_gun_no")] public string ChargerGunNo { get; set; } + /// + /// Desc:站外充电枪编号,1枪或2枪 + /// Default: + /// Nullable:True + /// + [SugarColumn(ColumnName = "out_charger_gun_no")] + public string OutChargerGunNo { get; set; } + /// /// 0:站内充电 1:站外充电 /// diff --git a/Service/Cloud/Common/CloudConst.cs b/Service/Cloud/Common/CloudConst.cs index c4e741d..8a95053 100644 --- a/Service/Cloud/Common/CloudConst.cs +++ b/Service/Cloud/Common/CloudConst.cs @@ -59,6 +59,14 @@ public class CloudConst public static readonly string eqmStateEndLogInfoRes = "eqmStateEndLogInfoRes"; public static readonly string chargeDevDataInfo = "chargeDevDataInfo"; public static readonly string chargeDevDataInfoRes = "chargeDevDataInfoRes"; + + /// + /// 站外 + /// + public static readonly string pileStartCharge = "pileStartCharge"; + public static readonly string pileStartChargeRes = "pileStartChargeRes"; + public static readonly string pileStopCharge = "pileStopCharge"; + public static readonly string pileRealtimeRes = "pileRealtimeRes"; #endregion } \ No newline at end of file diff --git a/Service/Cloud/Handler/OutCharger/PileStartChargeHandler.cs b/Service/Cloud/Handler/OutCharger/PileStartChargeHandler.cs new file mode 100644 index 0000000..3c09d8c --- /dev/null +++ b/Service/Cloud/Handler/OutCharger/PileStartChargeHandler.cs @@ -0,0 +1,27 @@ +using System.Text; +using Common.Util; +using HybirdFrameworkCore.Autofac.Attribute; +using NewLife.Remoting; +using Newtonsoft.Json; +using Service.Cloud.Common; +using Service.Cloud.Msg.Cloud.OutCharger.Req; + +namespace Service.Cloud.Handler.OutCharger; + +[Scope("InstancePerDependency")] +public class PileStartChargeHandler : IBaseHandler +{ + public bool CanHandle(string cmd) + { + return CloudConst.pileStartCharge == cmd; + } + + public void Handle(string t) + { + PileStartCharge? pileStartCharge = JsonConvert.DeserializeObject(t); + if (pileStartCharge != null) + { + HttpUtil.SendPostRequest(pileStartCharge, "http://127.0.0.1:5035/api/OutCharger/SendStartOutCharger"); + } + } +} \ No newline at end of file diff --git a/Service/Cloud/Handler/OutCharger/PileStopChargeHandler.cs b/Service/Cloud/Handler/OutCharger/PileStopChargeHandler.cs new file mode 100644 index 0000000..03030ae --- /dev/null +++ b/Service/Cloud/Handler/OutCharger/PileStopChargeHandler.cs @@ -0,0 +1,26 @@ +using System.Text; +using Common.Util; +using HybirdFrameworkCore.Autofac.Attribute; +using Newtonsoft.Json; +using Service.Cloud.Common; +using Service.Cloud.Msg.Cloud.OutCharger.Req; + +namespace Service.Cloud.Handler.OutCharger; + +[Scope("InstancePerDependency")] +public class PileStopChargeHandler : IBaseHandler +{ + public bool CanHandle(string cmd) + { + return CloudConst.pileStopCharge == cmd; + } + + public void Handle(string t) + { + PileStopCharge? pileStopCharge = JsonConvert.DeserializeObject(t); + if (pileStopCharge != null) + { + HttpUtil.SendPostRequest(pileStopCharge, "http://127.0.0.1:5035/api/OutCharger/SendStartOutCharger"); + } + } +} \ No newline at end of file diff --git a/Service/Cloud/Msg/Cloud/Req/OutCharger/Req/PileStartCharge.cs b/Service/Cloud/Msg/Cloud/Req/OutCharger/Req/PileStartCharge.cs new file mode 100644 index 0000000..ac77b08 --- /dev/null +++ b/Service/Cloud/Msg/Cloud/Req/OutCharger/Req/PileStartCharge.cs @@ -0,0 +1,50 @@ +using Service.Cloud.Common; + +namespace Service.Cloud.Msg.Cloud.OutCharger.Req; + +/// +/// 9.2.1.1 云平台下发开始充电操作 +/// +public class PileStartCharge : ICmd +{ + /// + /// 换电站编码 + /// 换电站唯一码 + /// + public string sn { get; set; } + + /// + /// 充电订单号 + /// 云平台下发的充电订单编号,;当启动模式为本地主动启动(即插即充)时,该 值以 0 填充 + /// + public string con { get; set; } + + /// + /// 充电枪编号 + /// 充电枪的唯一标识码 + /// + public string pn { get; set; } + + /// + /// 充电方式 + /// 0:自动(充满为止);1:按电量; + /// + public int ct { get; set; } + + /// + /// 充电参数 + /// 按充电方式判断,除0外 电量:单位 kWh,精确到 0.01 时间:单位 min,精确到 0.01 金额:单位 元,精确到 0.01 + /// + public string cp { get; set; } + + /// + /// 启动类型 + /// 0:运营平台启动;1:APP 启动;2: 本地启动 + /// + public int st { get; set; } + + public string GetCmd() + { + return CloudConst.pileStartCharge; + } +} \ No newline at end of file diff --git a/Service/Cloud/Msg/Cloud/Req/OutCharger/Req/PileStopCharge.cs b/Service/Cloud/Msg/Cloud/Req/OutCharger/Req/PileStopCharge.cs new file mode 100644 index 0000000..bdb589f --- /dev/null +++ b/Service/Cloud/Msg/Cloud/Req/OutCharger/Req/PileStopCharge.cs @@ -0,0 +1,27 @@ +using Service.Cloud.Common; + +namespace Service.Cloud.Msg.Cloud.OutCharger.Req; + +/// +/// 9.2.17 云端下发充电枪停止充电 +/// +public class PileStopCharge : ICmd +{ + /// + /// 换电站编码 + /// 换电站唯一码 + /// + public string sn { get; set; } + + + /// + /// 充电枪编号 + /// 充电枪的唯一标识码 + /// + public string pn { get; set; } + + public string GetCmd() + { + return CloudConst.pileStopCharge; + } +} \ No newline at end of file diff --git a/Service/Cloud/Msg/Host/Resp/OutCharger/PileStartChargeResp.cs b/Service/Cloud/Msg/Host/Resp/OutCharger/PileStartChargeResp.cs new file mode 100644 index 0000000..a6fcbe6 --- /dev/null +++ b/Service/Cloud/Msg/Host/Resp/OutCharger/PileStartChargeResp.cs @@ -0,0 +1,34 @@ +using Service.Cloud.Common; + +namespace Service.Cloud.Msg.Host.Resp.OutCharger; + +/// +/// 9.2.1.2 站控应答开始充电操作 +/// +public class PileStartChargeResp : ICmd +{ + /// + /// 执行结果 + /// + public string? rs { get; set; } + + /// + /// 充电订单号 + /// + public string? con { get; set; } + + /// + /// 充电枪编号 + /// + public string? pn { get; set; } + + /// + /// 故障码 + /// + public string? ec { get; set; } + + public string GetCmd() + { + return CloudConst.pileStartChargeRes; + } +} \ No newline at end of file diff --git a/Service/Cloud/Msg/Host/Resp/OutCharger/PileStopChargeResp.cs b/Service/Cloud/Msg/Host/Resp/OutCharger/PileStopChargeResp.cs new file mode 100644 index 0000000..89c2519 --- /dev/null +++ b/Service/Cloud/Msg/Host/Resp/OutCharger/PileStopChargeResp.cs @@ -0,0 +1,24 @@ +using Service.Cloud.Common; + +namespace Service.Cloud.Msg.Host.Resp.OutCharger; +/// +/// 9.2.1.8 站控响应充电枪停止充电操作 +/// +public class PileStopChargeResp : ICmd +{ + /// + /// 充电枪ID + /// 0x01:充电枪1;0x02:充电枪2;0x03:双枪充电;(0x00&0xFF无效) + /// + public string pn { get; set; } + + /// + /// 启动结果 0 成功 1 设备已停机 0xFF 其他 + /// + public string rs { get; set; } + + public string GetCmd() + { + return CloudConst.pileRealtimeRes; + } +} \ No newline at end of file diff --git a/WebStarter/Controllers/OutChargerController.cs b/WebStarter/Controllers/OutChargerController.cs new file mode 100644 index 0000000..3857444 --- /dev/null +++ b/WebStarter/Controllers/OutChargerController.cs @@ -0,0 +1,42 @@ +using HybirdFrameworkCore.Entity; +using Microsoft.AspNetCore.Mvc; +using Service.Cloud.Client; +using Service.Cloud.Msg.Host.Resp.OutCharger; +using Service.Init; + +namespace WebStarter.Controllers; + +/// +/// 站外充电机管理 +/// +[Produces("application/json")] +[ApiController] +[Route("api/[controller]")] +public class OutChargerController +{ + /// + /// 9.2.1.2 站控应答开始充电操作 + /// + /// + /// + [HttpPost] + [Route("ResStartOutCharger")] + public Result ResStartOutCharger([FromBody] PileStartChargeResp req) + { + CloudClientMgr.CloudClient?.Publish(req); + return Result.Success(true); + } + + /// + /// 9.2.1.8 站控响应充电枪停止充电操作 + /// + /// + /// + [HttpPost] + [Route("ResStopOutCharger")] + public Result ResStopOutCharger([FromBody] PileStopChargeResp req) + { + CloudClientMgr.CloudClient?.Publish(req); + return Result.Success(true); + } +} \ No newline at end of file diff --git a/WebStarter/db/lxw0607.sql b/WebStarter/db/lxw0607.sql index 240c92a..9ba19be 100644 --- a/WebStarter/db/lxw0607.sql +++ b/WebStarter/db/lxw0607.sql @@ -45,3 +45,7 @@ ALTER TABLE swap_order_report_cloud ADD `upload_time` datetime DEFAULT NULL COM -- 添加入仓时间 ALTER TABLE bin_info ADD `in_time` datetime DEFAULT NULL COMMENT "入仓时间" ; + +-- 添加站外充电枪编号 +ALTER TABLE charge_order ADD COLUMN out_charger_gun_no VARCHAR(255) COMMENT '站外充电枪编号,1枪或2枪'; +