diff --git a/BPA.SAAS.KitChenManage.Application/Device/DevicePushRecodeServices.cs b/BPA.SAAS.KitChenManage.Application/Device/DevicePushRecodeServices.cs
index 511dd10..f170dec 100644
--- a/BPA.SAAS.KitChenManage.Application/Device/DevicePushRecodeServices.cs
+++ b/BPA.SAAS.KitChenManage.Application/Device/DevicePushRecodeServices.cs
@@ -42,6 +42,17 @@ namespace BPA.SAAS.KitChenManage.Application.Device
return await _devicePushRecodeService.Add(input);
}
///
+ /// 下发数据(对外接口)
+ ///
+ ///
+ ///
+ [HttpPost("/api/devicepushrecode/add_alm")]
+ [AllowAnonymous]
+ public async Task Add_alm(List input)
+ {
+ return await _devicePushRecodeService.Add_alm(input);
+ }
+ ///
/// 修改
///
///
diff --git a/BPA.SAAS.KitChenManage.Application/Device/Services/DevicePushRecodeService.cs b/BPA.SAAS.KitChenManage.Application/Device/Services/DevicePushRecodeService.cs
index 1002aef..8772889 100644
--- a/BPA.SAAS.KitChenManage.Application/Device/Services/DevicePushRecodeService.cs
+++ b/BPA.SAAS.KitChenManage.Application/Device/Services/DevicePushRecodeService.cs
@@ -91,6 +91,46 @@ namespace BPA.SAAS.KitChenManage.Application.Device.Services
};
return util;
}
+ public async Task Add_alm(List input)
+ {
+ var data = input.Adapt>();
+ string groupId = App.HttpContext.Request.Headers["groupId"].ToString();
+ if (string.IsNullOrWhiteSpace(groupId)) throw Oops.Oh("加盟商id不能为空");
+ for (int i = 0; i < input.Count; i++)
+ {
+ 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().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);
+ }
+ return true;
+ }
///
/// 添加
///
diff --git a/BPA.SAAS.KitChenManage.Application/Device/Services/IDevicePushRecodeService.cs b/BPA.SAAS.KitChenManage.Application/Device/Services/IDevicePushRecodeService.cs
index 2554132..1bfbace 100644
--- a/BPA.SAAS.KitChenManage.Application/Device/Services/IDevicePushRecodeService.cs
+++ b/BPA.SAAS.KitChenManage.Application/Device/Services/IDevicePushRecodeService.cs
@@ -17,6 +17,7 @@ namespace BPA.SAAS.KitChenManage.Application.Device.Services
///
///
Task Page(DevicePushRecodeDtoPageInput input);
+ Task Add_alm(List input);
///
/// 添加
///
diff --git a/BPA.SAAS.KitChenManage.Application/TestServices.cs b/BPA.SAAS.KitChenManage.Application/TestServices.cs
new file mode 100644
index 0000000..5f0a775
--- /dev/null
+++ b/BPA.SAAS.KitChenManage.Application/TestServices.cs
@@ -0,0 +1,12 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace BPA.SAAS.KitChenManage.Application
+{
+ public class TestServices: IDynamicApiController
+ {
+ }
+}