|
|
@@ -1,5 +1,4 @@ |
|
|
|
|
|
|
|
using BPA.KitChen.StoreManagement.Application.BaseDto; |
|
|
|
using BPA.KitChen.StoreManagement.Application.BaseDto; |
|
|
|
using BPA.KitChen.StoreManagement.Application.Service.Device.Dtos; |
|
|
|
using BPA.KitChen.StoreManagement.Core.Entity; |
|
|
|
using BPA.KitChen.StoreManagement.Core.Enum; |
|
|
@@ -31,7 +30,7 @@ namespace BPA.KitChen.StoreManagement.Application.Service.Device |
|
|
|
public DevicePushRecodeService(ISqlSugarClient db, IMqttClient mqttClient) |
|
|
|
{ |
|
|
|
_db = db; |
|
|
|
_mqttClient = mqttClient; |
|
|
|
_mqttClient=mqttClient; |
|
|
|
} |
|
|
|
/// <summary> |
|
|
|
/// 分页 |
|
|
@@ -43,7 +42,7 @@ namespace BPA.KitChen.StoreManagement.Application.Service.Device |
|
|
|
RefAsync<int> total = 0; |
|
|
|
var res = await _db.Queryable<BPA_DevicePushRecode>().Where(x => x.Type == input.Type) |
|
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.DeviceName), x => x.DeviceName.Contains(input.DeviceName)) |
|
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.Status), x => x.Status == (CommonStatus)Convert.ToInt32(input.Status) ) |
|
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.Status), x => x.Status == (CommonStatus)Convert.ToInt32(input.Status)) |
|
|
|
.Select(t => new |
|
|
|
{ |
|
|
|
CreateAt = t.CreateAt, |
|
|
@@ -81,20 +80,42 @@ namespace BPA.KitChen.StoreManagement.Application.Service.Device |
|
|
|
data.Topic= Topic; |
|
|
|
data.Status = CommonStatus.ENABLE; |
|
|
|
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 == "success" ? CommonStatus.ENABLE : CommonStatus.DISABLE; |
|
|
|
await _db.Insertable(data).CallEntityMethod(t => t.Create()).ExecuteCommandAsync(); |
|
|
|
|
|
|
|
return res == "success"; |
|
|
|
data.DeviceAutoKey= input.DeviceAutoKey; |
|
|
|
data.Description = "成功"; |
|
|
|
if (input.TopicsData.Count > 0) |
|
|
|
{ |
|
|
|
var chaeck = input.TopicsData.Any(x => x.Topics.Trim() == topstr.Trim()); |
|
|
|
if (!chaeck) |
|
|
|
{ |
|
|
|
data.Status = CommonStatus.DISABLE; |
|
|
|
data.Description = "下发数据失败,该产品还未配置对应的topic,请联系管理员进行配置"; |
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
data.Status = CommonStatus.DISABLE; |
|
|
|
data.Description = "下发数据失败,该产品还未配置对应的topic,请联系管理员进行配置"; |
|
|
|
} |
|
|
|
if (data.Status == CommonStatus.ENABLE) |
|
|
|
{ |
|
|
|
var respush = await Push(Topic, new PushData() { Data = data.DataResore, DeviceId = input.DeviceAutoKey }); |
|
|
|
if (respush != "success") |
|
|
|
{ |
|
|
|
data.Description = respush; |
|
|
|
data.Status = CommonStatus.DISABLE; |
|
|
|
} |
|
|
|
} |
|
|
|
var res = await _db.Insertable(data).CallEntityMethod(t => t.Create()).ExecuteCommandAsync(); |
|
|
|
return res>0; |
|
|
|
} |
|
|
|
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 }); |
|
|
|
data.Description = respush; |
|
|
|
if (respush!= "success") |
|
|
|
{ |
|
|
|
data.Description = respush; |
|
|
|
data.Status = CommonStatus.DISABLE; |
|
|
|
} |
|
|
|
var res = await _db.Updateable(data).ExecuteCommandAsync(); |
|
|
|