@@ -9,6 +9,13 @@ | |||
</PropertyGroup> | |||
<ItemGroup> | |||
<Compile Remove="AExternalPlatform\**" /> | |||
<EmbeddedResource Remove="AExternalPlatform\**" /> | |||
<None Remove="AExternalPlatform\**" /> | |||
</ItemGroup> | |||
<ItemGroup> | |||
<None Remove="BPA.SAAS.KitChenManage.Application.xml" /> | |||
@@ -26,9 +33,4 @@ | |||
<ProjectReference Include="..\BPA.SAAS.KitChenManage.Core\BPA.SAAS.KitChenManage.Core.csproj" /> | |||
</ItemGroup> | |||
<ItemGroup> | |||
<Folder Include="AExternalPlatform\Service\CheckService\Dtos\" /> | |||
<Folder Include="AExternalPlatform\Service\Platform\Material\Dtos\" /> | |||
</ItemGroup> | |||
</Project> |
@@ -4,114 +4,6 @@ | |||
<name>BPA.SAAS.KitChenManage.Application</name> | |||
</assembly> | |||
<members> | |||
<member name="P:BPA.SAAS.KitChenManage.Application.AExternalPlatform.BaseDto.BaseEPDto.TenantId"> | |||
<summary> | |||
租户Id | |||
</summary> | |||
</member> | |||
<member name="T:BPA.SAAS.KitChenManage.Application.AExternalPlatform.BaseDto.DtoValidator"> | |||
<summary> | |||
Dto参数验证 | |||
</summary> | |||
</member> | |||
<member name="M:BPA.SAAS.KitChenManage.Application.AExternalPlatform.BaseDto.DtoValidator.CheckTenant(System.String)"> | |||
<summary> | |||
检查租户 | |||
</summary> | |||
<param name="id"></param> | |||
<returns></returns> | |||
</member> | |||
<member name="T:BPA.SAAS.KitChenManage.Application.AExternalPlatform.Enum.ErrorCodeEnum"> | |||
<summary> | |||
系统错误码 | |||
</summary> | |||
</member> | |||
<member name="F:BPA.SAAS.KitChenManage.Application.AExternalPlatform.Enum.ErrorCodeEnum.Code1000"> | |||
<summary> | |||
用户没有注册 | |||
</summary> | |||
</member> | |||
<member name="M:BPA.SAAS.KitChenManage.Application.AExternalPlatform.Service.Authorization.AuthServices.GetListStoreAuthKey(BPA.SAAS.KitChenManage.Application.AExternalPlatform.BaseDto.BaseEPDto)"> | |||
<summary> | |||
获取店铺授权码列表 | |||
</summary> | |||
<param name="input"></param> | |||
<returns></returns> | |||
</member> | |||
<member name="M:BPA.SAAS.KitChenManage.Application.AExternalPlatform.Service.Authorization.AuthServices.GetStoreAuthKey(BPA.SAAS.KitChenManage.Application.AExternalPlatform.Service.Authorization.Dtos.StoreAuthDto)"> | |||
<summary> | |||
获取店铺授权码 | |||
</summary> | |||
<param name="input"></param> | |||
<returns></returns> | |||
</member> | |||
<member name="M:BPA.SAAS.KitChenManage.Application.AExternalPlatform.Service.Authorization.AuthServices.AddStoreAuthKey(BPA.SAAS.KitChenManage.Application.AExternalPlatform.Service.Authorization.Dtos.StoreAuthDto)"> | |||
<summary> | |||
添加店铺授权码 | |||
</summary> | |||
<returns></returns> | |||
</member> | |||
<member name="M:BPA.SAAS.KitChenManage.Application.AExternalPlatform.Service.Authorization.AuthServices.UpdateStoreAuthKey(BPA.SAAS.KitChenManage.Application.AExternalPlatform.Service.Authorization.Dtos.StoreAuthDto)"> | |||
<summary> | |||
修改店铺授权码 | |||
</summary> | |||
<param name="id"></param> | |||
<returns></returns> | |||
</member> | |||
<member name="M:BPA.SAAS.KitChenManage.Application.AExternalPlatform.Service.Authorization.Services.AuthService.GetListStoreAuthKey(BPA.SAAS.KitChenManage.Application.AExternalPlatform.BaseDto.BaseEPDto)"> | |||
<summary> | |||
获取店铺授权码列表 | |||
</summary> | |||
<param name="input"></param> | |||
<returns></returns> | |||
</member> | |||
<member name="M:BPA.SAAS.KitChenManage.Application.AExternalPlatform.Service.Authorization.Services.AuthService.GetStoreAuthKey(BPA.SAAS.KitChenManage.Application.AExternalPlatform.Service.Authorization.Dtos.StoreAuthDto)"> | |||
<summary> | |||
获取店铺授权码 | |||
</summary> | |||
<param name="input"></param> | |||
<returns></returns> | |||
</member> | |||
<member name="M:BPA.SAAS.KitChenManage.Application.AExternalPlatform.Service.Authorization.Services.AuthService.AddStoreAuthKey(BPA.SAAS.KitChenManage.Application.AExternalPlatform.Service.Authorization.Dtos.StoreAuthDto)"> | |||
<summary> | |||
添加店铺授权码 | |||
</summary> | |||
<returns></returns> | |||
</member> | |||
<member name="M:BPA.SAAS.KitChenManage.Application.AExternalPlatform.Service.Authorization.Services.AuthService.UpdateStoreAuthKey(BPA.SAAS.KitChenManage.Application.AExternalPlatform.Service.Authorization.Dtos.StoreAuthDto)"> | |||
<summary> | |||
修改店铺授权码 | |||
</summary> | |||
<param name="id"></param> | |||
<returns></returns> | |||
</member> | |||
<member name="M:BPA.SAAS.KitChenManage.Application.AExternalPlatform.Service.Authorization.Services.IAuthService.GetListStoreAuthKey(BPA.SAAS.KitChenManage.Application.AExternalPlatform.BaseDto.BaseEPDto)"> | |||
<summary> | |||
获取店铺授权码列表 | |||
</summary> | |||
<param name="input"></param> | |||
<returns></returns> | |||
</member> | |||
<member name="M:BPA.SAAS.KitChenManage.Application.AExternalPlatform.Service.Authorization.Services.IAuthService.GetStoreAuthKey(BPA.SAAS.KitChenManage.Application.AExternalPlatform.Service.Authorization.Dtos.StoreAuthDto)"> | |||
<summary> | |||
获取店铺授权码 | |||
</summary> | |||
<param name="input"></param> | |||
<returns></returns> | |||
</member> | |||
<member name="M:BPA.SAAS.KitChenManage.Application.AExternalPlatform.Service.Authorization.Services.IAuthService.AddStoreAuthKey(BPA.SAAS.KitChenManage.Application.AExternalPlatform.Service.Authorization.Dtos.StoreAuthDto)"> | |||
<summary> | |||
添加店铺授权码 | |||
</summary> | |||
<returns></returns> | |||
</member> | |||
<member name="M:BPA.SAAS.KitChenManage.Application.AExternalPlatform.Service.Authorization.Services.IAuthService.UpdateStoreAuthKey(BPA.SAAS.KitChenManage.Application.AExternalPlatform.Service.Authorization.Dtos.StoreAuthDto)"> | |||
<summary> | |||
修改店铺授权码 | |||
</summary> | |||
<param name="id"></param> | |||
<returns></returns> | |||
</member> | |||
<member name="M:BPA.SAAS.KitChenManage.Application.Authorization.AuthorizationServices.PageStoreAuthorization(BPA.SAAS.KitChenManage.Core.Base.PageInputBase)"> | |||
<summary> | |||
分页店铺授权码 | |||
@@ -197,7 +89,7 @@ | |||
<param name="input"></param> | |||
<returns></returns> | |||
</member> | |||
<member name="M:BPA.SAAS.KitChenManage.Application.Device.DevicePushRecodeServices.Add(BPA.SAAS.KitChenManage.Application.Device.Dtos.DevicePushRecodeDtoInput)"> | |||
<member name="M:BPA.SAAS.KitChenManage.Application.Device.DevicePushRecodeServices.Add(System.Collections.Generic.List{BPA.SAAS.KitChenManage.Application.Device.Dtos.DevicePushRecodeDtoInput})"> | |||
<summary> | |||
添加 | |||
</summary> | |||
@@ -340,7 +232,7 @@ | |||
<param name="input"></param> | |||
<returns></returns> | |||
</member> | |||
<member name="M:BPA.SAAS.KitChenManage.Application.Device.Services.DevicePushRecodeService.Add(BPA.SAAS.KitChenManage.Application.Device.Dtos.DevicePushRecodeDtoInput)"> | |||
<member name="M:BPA.SAAS.KitChenManage.Application.Device.Services.DevicePushRecodeService.Add(System.Collections.Generic.List{BPA.SAAS.KitChenManage.Application.Device.Dtos.DevicePushRecodeDtoInput})"> | |||
<summary> | |||
添加 | |||
</summary> | |||
@@ -362,6 +254,14 @@ | |||
<param name="input"></param> | |||
<returns></returns> | |||
</member> | |||
<member name="M:BPA.SAAS.KitChenManage.Application.Device.Services.DevicePushRecodeService.BindMqReceived(System.String,System.String)"> | |||
<summary> | |||
监听订阅的topic主题 | |||
</summary> | |||
<param name="messageId"></param> | |||
<param name="groupId"></param> | |||
<returns></returns> | |||
</member> | |||
<member name="M:BPA.SAAS.KitChenManage.Application.Device.Services.IDevicePushRecodeService.Page(BPA.SAAS.KitChenManage.Application.Device.Dtos.DevicePushRecodeDtoPageInput)"> | |||
<summary> | |||
分页 | |||
@@ -369,7 +269,7 @@ | |||
<param name="input"></param> | |||
<returns></returns> | |||
</member> | |||
<member name="M:BPA.SAAS.KitChenManage.Application.Device.Services.IDevicePushRecodeService.Add(BPA.SAAS.KitChenManage.Application.Device.Dtos.DevicePushRecodeDtoInput)"> | |||
<member name="M:BPA.SAAS.KitChenManage.Application.Device.Services.IDevicePushRecodeService.Add(System.Collections.Generic.List{BPA.SAAS.KitChenManage.Application.Device.Dtos.DevicePushRecodeDtoInput})"> | |||
<summary> | |||
添加 | |||
</summary> | |||
@@ -651,7 +551,7 @@ | |||
属性值 | |||
</summary> | |||
</member> | |||
<member name="M:BPA.SAAS.KitChenManage.Application.Push.Comm.MqttServer.Publish(System.String,BPA.SAAS.KitChenManage.Application.Device.Dtos.PushData,System.Int32)"> | |||
<member name="M:BPA.SAAS.KitChenManage.Application.Push.Comm.MqttServer.Publish(System.String,BPA.SAAS.KitChenManage.Application.Device.Dtos.PushData,System.String)"> | |||
<summary> | |||
发布mq(发送数据) | |||
</summary> | |||
@@ -33,7 +33,7 @@ namespace BPA.SAAS.KitChenManage.Application.Device | |||
/// <param name="input"></param> | |||
/// <returns></returns> | |||
[HttpPost("/api/devicepushrecode/add")] | |||
public async Task<bool> Add(DevicePushRecodeDtoInput input) | |||
public async Task<bool> Add(List<DevicePushRecodeDtoInput> input) | |||
{ | |||
return await _devicePushRecodeService.Add(input); | |||
} | |||
@@ -8,6 +8,7 @@ namespace BPA.SAAS.KitChenManage.Application.Device.Dtos | |||
{ | |||
public class DevicePushRecodeDtoInput | |||
{ | |||
public string MessageId { get; set; } | |||
public string DeviceId { get; set; } | |||
public string ProductVersion { get; set; } | |||
public string ProductKey { get; set; } | |||
@@ -33,6 +33,7 @@ namespace BPA.SAAS.KitChenManage.Application.Device.Services | |||
private readonly ISqlSugarClient _db; | |||
private readonly IMqttClient _mqttClient; | |||
CommDefaultHandle commDefaultHandle = new(); | |||
private string BaseServerUrl = App.GetConfig<string>("baseurl"); | |||
MqttServer mqttServer; | |||
public DevicePushRecodeService(ISqlSugarClient db, IMqttClient mqttClient) | |||
{ | |||
@@ -81,40 +82,44 @@ namespace BPA.SAAS.KitChenManage.Application.Device.Services | |||
/// </summary> | |||
/// <param name="input"></param> | |||
/// <returns></returns> | |||
public async Task<bool> Add(DevicePushRecodeDtoInput input) | |||
public async Task<bool> Add(List<DevicePushRecodeDtoInput> input) | |||
{ | |||
var data = input.Adapt<BPA_DevicePushRecode>(); | |||
var DataResore =await commDefaultHandle.GetParm(input.Type, input.Data.ToString(), input.DeviceId, input.ProductName, input.ProductVersion, input.DeviceAutoKey.ToString()); | |||
if(DataResore==null) throw Oops.Oh("解析参数失败"); | |||
string Topic = DataResore.TopicsStr; | |||
if (string.IsNullOrEmpty(Topic)) throw Oops.Oh("请配置相关topic"); | |||
var maxmessageId=_db.Queryable<BPA_DevicePushRecode>().Max(x => x.MessageId); | |||
int messageId = maxmessageId+1; | |||
var data = input.Adapt<List<BPA_DevicePushRecode>>(); | |||
var groupId = App.User?.FindFirst(ClaimConst.GroupId)?.Value; | |||
data.Topic= Topic; | |||
data.Status = 0; | |||
data.DataResore = JsonConvert.SerializeObject(DataResore.Data); | |||
data.DeviceAutoKey= input.DeviceAutoKey; | |||
data.Description = "下发中,等待设备响应"; | |||
data.MessageId= messageId; | |||
data.TopicRely = DataResore.TopicsStrRely; | |||
data.DescriptionRely = "等待回调"; | |||
var respush = await mqttServer.Publish(Topic, new PushData() { Data = data.DataResore, DeviceId = input.DeviceAutoKey }, messageId); | |||
if (respush != "success") | |||
for (int i = 0; i < input.Count; i++) | |||
{ | |||
data.Description = respush; | |||
data.Status = 2; | |||
var DataResore = await commDefaultHandle.GetParm(input[i].Type, input[i].Data.ToString(), input[i].DeviceId, input[i].ProductName, input[i].ProductVersion, input[i].DeviceAutoKey.ToString()); | |||
if (DataResore == null) throw Oops.Oh("解析参数失败"); | |||
string Topic = DataResore.TopicsStr; | |||
if (string.IsNullOrEmpty(Topic)) throw Oops.Oh("请配置相关topic"); | |||
//var maxmessageId=_db.Queryable<BPA_DevicePushRecode>().Max(x => x.MessageId); | |||
if (string.IsNullOrWhiteSpace(input[i].MessageId)) input[i].MessageId = Guid.NewGuid().ToString(); | |||
// var messageId = Guid.NewGuid().ToString(); | |||
data[i].Topic = Topic; | |||
data[i].Status = 0; | |||
data[i].DataResore = JsonConvert.SerializeObject(DataResore.Data); | |||
data[i].DeviceAutoKey = input[i].DeviceAutoKey; | |||
data[i].Description = "下发中,等待设备响应"; | |||
data[i].MessageId = input[i].MessageId; | |||
data[i].TopicRely = DataResore.TopicsStrRely; | |||
data[i].DescriptionRely = "等待回调"; | |||
var respush = await mqttServer.Publish(Topic, new PushData() { Data = data[i].DataResore, DeviceId = input[i].DeviceAutoKey }, input[i].MessageId); | |||
if (respush != "success") | |||
{ | |||
data[i].Description = respush; | |||
data[i].Status = 2; | |||
} | |||
var res = await _db.Insertable(data).CallEntityMethod(t => t.Create()).ExecuteCommandAsync(); | |||
//周期性任务 (10 秒后执行1次任务) | |||
var trigger = TriggerBuilder.Default.WithInterval(TimeSpan.FromSeconds(10)).WithRepeatCount(1).Build(); | |||
TaskServicesManager.GetOrAdd(input[i].MessageId.ToString(), async (provider, token) => { | |||
await CallBackDevicePushRecode(input[i].MessageId.ToString(), groupId); | |||
}, trigger); | |||
//订阅回复数据下发topics | |||
await mqttServer.Subscribe(DataResore.TopicsStrRely); | |||
await BindMqReceived(input[i].MessageId.ToString(), groupId); | |||
} | |||
var res = await _db.Insertable(data).CallEntityMethod(t => t.Create()).ExecuteCommandAsync(); | |||
//周期性任务 (10 秒后执行1次任务) | |||
var trigger = TriggerBuilder.Default.WithInterval(TimeSpan.FromSeconds(10)).WithRepeatCount(1).Build(); | |||
TaskServicesManager.GetOrAdd(messageId.ToString(), async (provider, token) => { | |||
await CallBackDevicePushRecode(messageId.ToString(), groupId); | |||
}, trigger); | |||
//订阅回复数据下发topics | |||
await mqttServer.Subscribe(DataResore.TopicsStrRely); | |||
await BindMqReceived(messageId.ToString(), groupId); | |||
return res>0; | |||
return true; | |||
} | |||
/// <summary> | |||
/// 数据下发回调更新数据 | |||
@@ -131,6 +136,9 @@ namespace BPA.SAAS.KitChenManage.Application.Device.Services | |||
model.Description = "下发成功,设备未回调"; | |||
model.DescriptionRely = "响应数据失败"; | |||
_db.Updateable(model).ExecuteCommand(); | |||
var status = false; | |||
var getGoodsAttributeurl = BaseServerUrl + "api/device/updatethirdpartypushrecord";//获取商品属性 | |||
await getGoodsAttributeurl.SetHttpMethod(HttpMethod.Post).SetBody("{\"messageId\":" + messageId + ",\"isPush\":" + status + ",\"pushTime\":" + DateTime.Now + "}").PostAsStringAsync(); | |||
} | |||
} | |||
public async Task<bool> Update(string id) | |||
@@ -176,8 +184,15 @@ namespace BPA.SAAS.KitChenManage.Application.Device.Services | |||
throw Oops.Oh("删除失败"); | |||
} | |||
} | |||
/// <summary> | |||
/// 监听订阅的topic主题 | |||
/// </summary> | |||
/// <param name="messageId"></param> | |||
/// <param name="groupId"></param> | |||
/// <returns></returns> | |||
private async Task BindMqReceived(string messageId,string groupId) | |||
{ | |||
var status = true; | |||
_mqttClient.UseApplicationMessageReceivedHandler(async e => | |||
{ | |||
var model = await _db.Queryable<BPA_DevicePushRecode>().Where(x => x.MessageId.ToString() == messageId.ToString() && x.GroupId == groupId).FirstAsync(); | |||
@@ -206,6 +221,7 @@ namespace BPA.SAAS.KitChenManage.Application.Device.Services | |||
{ | |||
model.Status = 1; | |||
model.DescriptionRely = re.Errors; | |||
status = false; | |||
} | |||
} | |||
} | |||
@@ -216,6 +232,8 @@ namespace BPA.SAAS.KitChenManage.Application.Device.Services | |||
model.DescriptionRely = "响应数据异常,异常信息:" + ex.Message; | |||
} | |||
var getGoodsAttributeurl = BaseServerUrl + "api/device/updatethirdpartypushrecord";//修改第三方订单的回调 | |||
await getGoodsAttributeurl.SetHttpMethod(HttpMethod.Post).SetBody("{\"messageId\":"+ messageId + ",\"isPush\":"+ status + ",\"pushTime\":"+DateTime.Now+"}").PostAsStringAsync(); | |||
_db.Updateable(model).ExecuteCommand(); | |||
} | |||
}); | |||
@@ -21,7 +21,7 @@ namespace BPA.SAAS.KitChenManage.Application.Device.Services | |||
/// </summary> | |||
/// <param name="input"></param> | |||
/// <returns></returns> | |||
Task<bool> Add(DevicePushRecodeDtoInput input); | |||
Task<bool> Add(List<DevicePushRecodeDtoInput> input); | |||
/// <summary> | |||
/// 更新 | |||
/// </summary> | |||
@@ -0,0 +1,35 @@ | |||
using BPA.Message.Enum; | |||
using BPA.Message; | |||
using System; | |||
using System.Collections.Generic; | |||
using System.Linq; | |||
using System.Text; | |||
using System.Threading.Tasks; | |||
namespace BPA.SAAS.KitChenManage.Application.Push.Comm.Dto | |||
{ | |||
public class BPAPackage | |||
{ | |||
public string MessageId { get; set; } | |||
public byte MessageVersion { get; set; } | |||
public int ClientId { get; set; } | |||
public string ClientType { get; set; } | |||
public DateTime Timestamp { get; set; } = DateTime.Now; | |||
public IMessage Message { get; set; } | |||
public string Serialize(bool isEncode = true) | |||
{ | |||
if (isEncode) | |||
{ | |||
return this.ToJSON().Encode(); | |||
} | |||
return this.ToJSON(); | |||
} | |||
} | |||
} |
@@ -1,5 +1,4 @@ | |||
using BPA.Message; | |||
using BPA.SAAS.KitChenManage.Application.Device.Dtos; | |||
using BPA.SAAS.KitChenManage.Application.Device.Dtos; | |||
using MQTTnet.Client.Subscribing; | |||
using MQTTnet; | |||
using System; | |||
@@ -9,6 +8,7 @@ using System.Text; | |||
using System.Threading.Tasks; | |||
using MQTTnet.Client; | |||
using uPLibrary.Networking.M2Mqtt; | |||
using BPA.SAAS.KitChenManage.Application.Push.Comm.Dto; | |||
namespace BPA.SAAS.KitChenManage.Application.Push.Comm | |||
{ | |||
@@ -26,7 +26,7 @@ namespace BPA.SAAS.KitChenManage.Application.Push.Comm | |||
/// <param name="data"></param> | |||
/// <param name="MessageId"></param> | |||
/// <returns></returns> | |||
public async Task<string> Publish(string Topic, PushData data, int MessageId) | |||
public async Task<string> Publish(string Topic, PushData data, string MessageId) | |||
{ | |||
try | |||
{ | |||
@@ -54,6 +54,7 @@ namespace BPA.SAAS.KitChenManage.Application.Push.Comm | |||
//每次下发暂停200毫秒 by 王刚 2022-06-08 测试提出修改 | |||
// Thread.Sleep(200); | |||
//string aa = bPAPackage.Serialize(false); | |||
//var fd = bPAPackage.Serialize(false); | |||
var applictionmessage = new MqttApplicationMessageBuilder().WithTopic(Topic).WithPayload(bPAPackage.Serialize(false)).WithAtLeastOnceQoS().Build(); | |||
await _mqttClient.PublishAsync(applictionmessage); | |||
return "success"; | |||
@@ -26,7 +26,7 @@ namespace BPA.SAAS.KitChenManage.Core.Model | |||
public int Status { get; set; } | |||
public int DeviceAutoKey { get; set; } | |||
public string Description { get; set; } | |||
public int MessageId { get; set; } | |||
public string MessageId { get; set; } | |||
public string TopicRely { get; set; } | |||
public string DataResoreRely { get; set; } | |||
public string DescriptionRely { get; set; } | |||