|
|
@@ -72,11 +72,28 @@ namespace BPA.KitChen.GroupMeal.Application.Service.Device.Dtos |
|
|
|
data.Topic= Topic; |
|
|
|
data.DataResore = JsonConvert.SerializeObject(JsonConvert.DeserializeObject<dynamic>(input.Data.ToString())); |
|
|
|
var res=await Push(Topic, new PushData() { Data=input.Data, DeviceId= input.DeviceAutoKey }); |
|
|
|
data.Status = res ? CommonStatus.ENABLE : CommonStatus.DISABLE; |
|
|
|
data.Status = res == "success" ? CommonStatus.ENABLE : CommonStatus.DISABLE; |
|
|
|
await _db.Insertable(data).CallEntityMethod(t => t.Create()).ExecuteCommandAsync(); |
|
|
|
|
|
|
|
return res; |
|
|
|
return res == "success"; |
|
|
|
} |
|
|
|
|
|
|
|
public async Task<bool> Update(string id) |
|
|
|
{ |
|
|
|
var data = _db.Queryable<BPA_DevicePushRecode>().Where(x => x.Id == id).First(); |
|
|
|
data.Status = CommonStatus.ENABLE; |
|
|
|
var respush = await Push(data.Topic, new PushData() { Data = data.DataResore, DeviceId = data.DeviceAutoKey }); |
|
|
|
if (respush != "success") |
|
|
|
{ |
|
|
|
data.Description = respush; |
|
|
|
data.Status = CommonStatus.DISABLE; |
|
|
|
} |
|
|
|
var res = await _db.Updateable(data).ExecuteCommandAsync(); |
|
|
|
return res > 0; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary> |
|
|
|
/// 删除 |
|
|
|
/// </summary> |
|
|
@@ -97,7 +114,7 @@ namespace BPA.KitChen.GroupMeal.Application.Service.Device.Dtos |
|
|
|
throw Oops.Oh("删除失败"); |
|
|
|
} |
|
|
|
} |
|
|
|
private async Task<bool> Push(string Topic,PushData data) |
|
|
|
private async Task<string> Push(string Topic,PushData data) |
|
|
|
{ |
|
|
|
try |
|
|
|
{ |
|
|
@@ -117,11 +134,11 @@ namespace BPA.KitChen.GroupMeal.Application.Service.Device.Dtos |
|
|
|
//string aa = bPAPackage.Serialize(false); |
|
|
|
var applictionmessage = new MqttApplicationMessageBuilder().WithTopic(Topic).WithPayload(bPAPackage.Serialize(false)).WithAtLeastOnceQoS().Build(); |
|
|
|
await _mqttClient.PublishAsync(applictionmessage); |
|
|
|
return true; |
|
|
|
return "success"; |
|
|
|
} |
|
|
|
catch (Exception e) |
|
|
|
{ |
|
|
|
throw Oops.Oh("下发错误,错误信息:"+e.Message); |
|
|
|
return "下发错误,错误信息:" + e.Message; |
|
|
|
} |
|
|
|
} |
|
|
|
private string GetTopic(int type,string deviceKey) |
|
|
|