|
|
@@ -91,6 +91,46 @@ namespace BPA.SAAS.KitChenManage.Application.Device.Services |
|
|
|
}; |
|
|
|
return util; |
|
|
|
} |
|
|
|
public async Task<bool> Add_alm(List<DevicePushRecodeDtoInput> input) |
|
|
|
{ |
|
|
|
var data = input.Adapt<List<BPA_DevicePushRecode>>(); |
|
|
|
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<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); |
|
|
|
} |
|
|
|
return true; |
|
|
|
} |
|
|
|
/// <summary> |
|
|
|
/// 添加 |
|
|
|
/// </summary> |
|
|
|