diff --git a/BPA.SAAS.KitChenManage.Application/BPA.SAAS.KitChenManage.Application.xml b/BPA.SAAS.KitChenManage.Application/BPA.SAAS.KitChenManage.Application.xml
index b089751..de8299e 100644
--- a/BPA.SAAS.KitChenManage.Application/BPA.SAAS.KitChenManage.Application.xml
+++ b/BPA.SAAS.KitChenManage.Application/BPA.SAAS.KitChenManage.Application.xml
@@ -18,6 +18,13 @@
+
+
+ 修改
+
+
+
+
删除
@@ -25,6 +32,26 @@
+
+
+ Topics类
+
+
+
+
+ TopicsType类型 0发布 1订阅 2发布和订阅
+
+
+
+
+ 描述
+
+
+
+
+ 是否默认Topics
+
+
下发类型1商品 2物料 3配方
@@ -70,6 +97,13 @@
+
+
+ 更新
+
+
+
+
删除
diff --git a/BPA.SAAS.KitChenManage.Application/Device/DevicePushRecodeServices.cs b/BPA.SAAS.KitChenManage.Application/Device/DevicePushRecodeServices.cs
index 4b55156..cadf73e 100644
--- a/BPA.SAAS.KitChenManage.Application/Device/DevicePushRecodeServices.cs
+++ b/BPA.SAAS.KitChenManage.Application/Device/DevicePushRecodeServices.cs
@@ -37,7 +37,16 @@ namespace BPA.SAAS.KitChenManage.Application.Device
{
return await _devicePushRecodeService.Add(input);
}
-
+ ///
+ /// 修改
+ ///
+ ///
+ ///
+ [HttpGet("/api/devicepushrecode/update")]
+ public async Task Update(string id)
+ {
+ return await _devicePushRecodeService.Update(id);
+ }
///
/// 删除
///
diff --git a/BPA.SAAS.KitChenManage.Application/Device/Dtos/DevicePushRecodeDtoInput.cs b/BPA.SAAS.KitChenManage.Application/Device/Dtos/DevicePushRecodeDtoInput.cs
index 50e39db..64f5b1d 100644
--- a/BPA.SAAS.KitChenManage.Application/Device/Dtos/DevicePushRecodeDtoInput.cs
+++ b/BPA.SAAS.KitChenManage.Application/Device/Dtos/DevicePushRecodeDtoInput.cs
@@ -9,9 +9,34 @@ namespace BPA.SAAS.KitChenManage.Application.Device.Dtos
public class DevicePushRecodeDtoInput
{
public string DeviceId { get; set; }
+ public string ProductVersion { get; set; }
+ public string ProductKey { get; set; }
public string DeviceName { get; set; }
public int DeviceAutoKey { get; set; }
public object Data { get; set; }
public int Type { get; set; }
+ public List TopicsData { get; set; }
+ }
+ public class ProductTopics
+ {
+ public string Id { get; set; }
+ ///
+ /// Topics类
+ ///
+ public string Topics { get; set; }
+ ///
+ /// TopicsType类型 0发布 1订阅 2发布和订阅
+ ///
+ public int TopicsType { get; set; }
+ ///
+ /// 描述
+ ///
+ public string Description { get; set; }
+ public string ProductId { get; set; }
+ public string ProductVesionId { get; set; }
+ ///
+ /// 是否默认Topics
+ ///
+ public bool IsDefault { get; set; }
}
}
diff --git a/BPA.SAAS.KitChenManage.Application/Device/Dtos/DevicePushRecodeDtoPageInput.cs b/BPA.SAAS.KitChenManage.Application/Device/Dtos/DevicePushRecodeDtoPageInput.cs
index 2a74115..f00cede 100644
--- a/BPA.SAAS.KitChenManage.Application/Device/Dtos/DevicePushRecodeDtoPageInput.cs
+++ b/BPA.SAAS.KitChenManage.Application/Device/Dtos/DevicePushRecodeDtoPageInput.cs
@@ -13,5 +13,7 @@ namespace BPA.SAAS.KitChenManage.Application.Device.Dtos
/// 下发类型1商品 2物料 3配方
///
public int Type { get; set; }
+ public string DeviceName { get; set; }
+ public string Status { get; set; }
}
}
diff --git a/BPA.SAAS.KitChenManage.Application/Device/Services/DevicePushRecodeService.cs b/BPA.SAAS.KitChenManage.Application/Device/Services/DevicePushRecodeService.cs
index 497ad9e..e58a265 100644
--- a/BPA.SAAS.KitChenManage.Application/Device/Services/DevicePushRecodeService.cs
+++ b/BPA.SAAS.KitChenManage.Application/Device/Services/DevicePushRecodeService.cs
@@ -5,6 +5,7 @@ using BPA.SAAS.KitChenManage.Application.Store.Dtos;
using BPA.SAAS.KitChenManage.Core.Base;
using BPA.SAAS.KitChenManage.Core.Model;
using Furion.LinqBuilder;
+using Microsoft.CodeAnalysis.Operations;
using Microsoft.Extensions.Hosting;
using MQTTnet;
using MQTTnet.Client;
@@ -36,6 +37,8 @@ namespace BPA.SAAS.KitChenManage.Application.Device.Services
{
RefAsync total = 0;
var res = await _db.Queryable().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==Convert.ToInt32(input.Status))
.Select(t => new
{
CreateAt = t.CreateAt,
@@ -46,6 +49,8 @@ namespace BPA.SAAS.KitChenManage.Application.Device.Services
Type =t.Type,
Topic=t.Topic,
DataResore=t.DataResore,
+ Status=t.Status,
+ Description=t.Description,
}).OrderBy(x => x.CreateAt, OrderByType.Desc).ToPageListAsync(input.Current, input.PageSize, total);
PageUtil util = new PageUtil()
{
@@ -63,16 +68,53 @@ namespace BPA.SAAS.KitChenManage.Application.Device.Services
public async Task Add(DevicePushRecodeDtoInput input)
{
var data = input.Adapt();
- string Topic = GetTopic(input.Type, input.DeviceAutoKey.ToString());
+ string topstr = "";
+ string Topic = GetTopic(input.Type, input.DeviceAutoKey.ToString(), input.ProductVersion, input.ProductKey, out topstr);
if (string.IsNullOrEmpty(Topic)) throw Oops.Oh("请配置相关topic");
+
data.Topic= Topic;
+ data.Status = 1;
data.DataResore = JsonConvert.SerializeObject(JsonConvert.DeserializeObject(input.Data.ToString()));
- var res=await Push(Topic, new PushData() { Data = data.DataResore, DeviceId = input.DeviceAutoKey });
- if (res)
+ data.DeviceAutoKey= input.DeviceAutoKey;
+ data.Description = "成功";
+ if (input.TopicsData.Count > 0)
{
- await _db.Insertable(data).CallEntityMethod(t => t.Create()).ExecuteCommandAsync();
+ var chaeck = input.TopicsData.Any(x => x.Topics.Trim() == topstr.Trim());
+ if (!chaeck)
+ {
+ data.Status =2;
+ data.Description = "下发数据失败,该产品还未配置对应的topic,请联系管理员进行配置";
+ }
+ }
+ else
+ {
+ data.Status = 2;
+ data.Description = "下发数据失败,该产品还未配置对应的topic,请联系管理员进行配置";
+ }
+ if (data.Status == 1)
+ {
+ var respush = await Push(Topic, new PushData() { Data = data.DataResore, DeviceId = input.DeviceAutoKey });
+ if (respush != "success")
+ {
+ data.Description = respush;
+ data.Status =2;
+ }
}
- return res;
+ var res = await _db.Insertable(data).CallEntityMethod(t => t.Create()).ExecuteCommandAsync();
+ return res>0;
+ }
+ public async Task Update(string id)
+ {
+ var data = _db.Queryable().Where(x => x.Id == id).First();
+ data.Status = 1;
+ var respush = await Push(data.Topic, new PushData() { Data = data.DataResore, DeviceId = data.DeviceAutoKey });
+ if (respush!= "success")
+ {
+ data.Description = respush;
+ data.Status = 2;
+ }
+ var res = await _db.Updateable(data).ExecuteCommandAsync();
+ return res > 0;
}
///
/// 删除
@@ -94,11 +136,10 @@ namespace BPA.SAAS.KitChenManage.Application.Device.Services
throw Oops.Oh("删除失败");
}
}
- private async Task Push(string Topic,PushData data)
+ private async Task Push(string Topic,PushData data)
{
try
{
-
// Topic = TOPIC.GetInstance.GetBusinessTopic(x, storeInfo.FirstOrDefault(a => a.Id == item.OrgId).AutoKey) + "/" + item.AutoKey;
BPAPackage bPAPackage = new BPAPackage
{
@@ -114,26 +155,31 @@ namespace BPA.SAAS.KitChenManage.Application.Device.Services
//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)
+ private string GetTopic(int type,string deviceKey, string productVersion, string productKey,out string topstr )
{
string topic = "";
+ topstr = "";
switch (type)
{
case 1: //商品下发
- topic = $"/da4bfff042c656210/${deviceKey}/use/goodspush";
+ topic = $"/{productKey}/{productVersion}/{deviceKey}/defaul/goodspush";
+ topstr = "/"+productKey+"/"+productVersion+"/${deviceKey}/defaul/goodspush";
break;
case 2://物料下发
- topic = $"/da4bfff042c656210/${deviceKey}/use/batvhingpush";
+ topic = $"/{productKey}/{productVersion}/{deviceKey}/defaul/batvhingpush";
+ topstr = "/" + productKey + "/" + productVersion + "/${deviceKey}/defaul/batvhingpush";
break;
case 4:
- topic = $"/da4bfff042c656210/${deviceKey}/use/chnologypush";
+ topic = $"/{productKey}/{productVersion}/{deviceKey}/defaul/chnologypush";
+ topstr = "/" + productKey + "/" + productVersion + "/${deviceKey}/defaul/chnologypush";
break;
}
return topic;
diff --git a/BPA.SAAS.KitChenManage.Application/Device/Services/IDevicePushRecodeService.cs b/BPA.SAAS.KitChenManage.Application/Device/Services/IDevicePushRecodeService.cs
index 1528b96..695b288 100644
--- a/BPA.SAAS.KitChenManage.Application/Device/Services/IDevicePushRecodeService.cs
+++ b/BPA.SAAS.KitChenManage.Application/Device/Services/IDevicePushRecodeService.cs
@@ -22,7 +22,12 @@ namespace BPA.SAAS.KitChenManage.Application.Device.Services
///
///
Task Add(DevicePushRecodeDtoInput input);
-
+ ///
+ /// 更新
+ ///
+ ///
+ ///
+ Task Update(string id);
///
/// 删除
///
diff --git a/BPA.SAAS.KitChenManage.Core/BPA.SAAS.KitChenManage.Core.xml b/BPA.SAAS.KitChenManage.Core/BPA.SAAS.KitChenManage.Core.xml
index f377eac..97f099a 100644
--- a/BPA.SAAS.KitChenManage.Core/BPA.SAAS.KitChenManage.Core.xml
+++ b/BPA.SAAS.KitChenManage.Core/BPA.SAAS.KitChenManage.Core.xml
@@ -65,6 +65,11 @@
下发类型1商品 2物料 3配方 4工艺
+
+
+ 下发状态 1成功 2失败
+
+
菜谱id
diff --git a/BPA.SAAS.KitChenManage.Core/Model/BPA_DevicePushRecode.cs b/BPA.SAAS.KitChenManage.Core/Model/BPA_DevicePushRecode.cs
index f4acbf5..18a331c 100644
--- a/BPA.SAAS.KitChenManage.Core/Model/BPA_DevicePushRecode.cs
+++ b/BPA.SAAS.KitChenManage.Core/Model/BPA_DevicePushRecode.cs
@@ -20,5 +20,11 @@ namespace BPA.SAAS.KitChenManage.Core.Model
public string GroupId { get; set; }
public string Topic { get; set; }
public string DataResore { get; set; }
+ ///
+ /// 下发状态 1成功 2失败
+ ///
+ public int Status { get; set; }
+ public int DeviceAutoKey { get; set; }
+ public string Description { get; set; }
}
}