diff --git a/.vs/BPA.KitChen.GroupMeal/v17/.suo b/.vs/BPA.KitChen.GroupMeal/v17/.suo
index 048e879..98fabec 100644
Binary files a/.vs/BPA.KitChen.GroupMeal/v17/.suo and b/.vs/BPA.KitChen.GroupMeal/v17/.suo differ
diff --git a/BPA.KitChen.GroupMeal.Application/Service/Device/DevicePushRecodeServices.cs b/BPA.KitChen.GroupMeal.Application/Service/Device/DevicePushRecodeServices.cs
index e4c5395..22b0c85 100644
--- a/BPA.KitChen.GroupMeal.Application/Service/Device/DevicePushRecodeServices.cs
+++ b/BPA.KitChen.GroupMeal.Application/Service/Device/DevicePushRecodeServices.cs
@@ -37,18 +37,16 @@ namespace BPA.KitChen.GroupMeal.Application.Service.Device.Dtos
{
return await _devicePushRecodeService.Add(input);
}
-
///
/// 修改
///
///
///
[HttpGet("/api/devicepushrecode/update")]
- public async Task Update(string id)
+ public async Task Update(string id)
{
return await _devicePushRecodeService.Update(id);
}
-
///
/// 删除
///
diff --git a/BPA.KitChen.GroupMeal.Application/Service/Device/Dtos/Class1.cs b/BPA.KitChen.GroupMeal.Application/Service/Device/Dtos/Class1.cs
deleted file mode 100644
index b49d35b..0000000
--- a/BPA.KitChen.GroupMeal.Application/Service/Device/Dtos/Class1.cs
+++ /dev/null
@@ -1,12 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
-namespace BPA.KitChen.GroupMeal.Application.Service.Device.Dtos
-{
- internal class Class1
- {
- }
-}
diff --git a/BPA.KitChen.GroupMeal.Application/Service/Device/Dtos/DevicePushRecodeDtoInput.cs b/BPA.KitChen.GroupMeal.Application/Service/Device/Dtos/DevicePushRecodeDtoInput.cs
index 9b61bae..07459cd 100644
--- a/BPA.KitChen.GroupMeal.Application/Service/Device/Dtos/DevicePushRecodeDtoInput.cs
+++ b/BPA.KitChen.GroupMeal.Application/Service/Device/Dtos/DevicePushRecodeDtoInput.cs
@@ -9,9 +9,34 @@ namespace BPA.KitChen.GroupMeal.Application.Service.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.KitChen.GroupMeal.Application/Service/Device/Dtos/DevicePushRecodeDtoPageInput.cs b/BPA.KitChen.GroupMeal.Application/Service/Device/Dtos/DevicePushRecodeDtoPageInput.cs
index 6aca6d2..48b94b6 100644
--- a/BPA.KitChen.GroupMeal.Application/Service/Device/Dtos/DevicePushRecodeDtoPageInput.cs
+++ b/BPA.KitChen.GroupMeal.Application/Service/Device/Dtos/DevicePushRecodeDtoPageInput.cs
@@ -13,5 +13,7 @@ namespace BPA.KitChen.GroupMeal.Application.Service.Device.Dtos
/// 下发类型1商品 2物料 3配方
///
public int Type { get; set; }
+ public string DeviceName { get; set; }
+ public string Status { get; set; }
}
}
diff --git a/BPA.KitChen.GroupMeal.Application/Service/Device/Services/DevicePushRecodeService.cs b/BPA.KitChen.GroupMeal.Application/Service/Device/Services/DevicePushRecodeService.cs
index 2d9b862..faf2534 100644
--- a/BPA.KitChen.GroupMeal.Application/Service/Device/Services/DevicePushRecodeService.cs
+++ b/BPA.KitChen.GroupMeal.Application/Service/Device/Services/DevicePushRecodeService.cs
@@ -7,6 +7,7 @@ using Furion.DependencyInjection;
using Furion.FriendlyException;
using Furion.LinqBuilder;
using Mapster;
+using Microsoft.CodeAnalysis.Operations;
using Microsoft.Extensions.Hosting;
using MQTTnet;
using MQTTnet.Client;
@@ -28,7 +29,7 @@ namespace BPA.KitChen.GroupMeal.Application.Service.Device.Dtos
public DevicePushRecodeService(ISqlSugarClient db, IMqttClient mqttClient)
{
_db = db;
- _mqttClient=mqttClient;
+ _mqttClient = mqttClient;
}
///
/// 分页
@@ -39,6 +40,8 @@ namespace BPA.KitChen.GroupMeal.Application.Service.Device.Dtos
{
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 == (CommonStatus)Convert.ToInt32(input.Status) )
.Select(t => new
{
CreateAt = t.CreateAt,
@@ -49,8 +52,10 @@ namespace BPA.KitChen.GroupMeal.Application.Service.Device.Dtos
Type = t.Type,
Topic = t.Topic,
DataResore = t.DataResore,
- t.Status
- }).OrderBy(x => x.CreateAt, OrderByType.Desc).ToPageListAsync(input.Current, input.PageSize, total);
+ Status = t.Status,
+ Description = t.Description,
+ }).OrderBy(x => x.CreateAt, OrderByType.Desc)
+ .ToPageListAsync(input.Current, input.PageSize, total);
PageUtil util = new PageUtil()
{
Total = total,
@@ -67,33 +72,54 @@ namespace BPA.KitChen.GroupMeal.Application.Service.Device.Dtos
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 = CommonStatus.ENABLE;
data.DataResore = JsonConvert.SerializeObject(JsonConvert.DeserializeObject(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 Update(string id)
{
var data = _db.Queryable().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;
+ if (respush!= "success")
{
- data.Description = respush;
data.Status = CommonStatus.DISABLE;
}
var res = await _db.Updateable(data).ExecuteCommandAsync();
return res > 0;
}
-
-
-
///
/// 删除
///
@@ -118,7 +144,6 @@ namespace BPA.KitChen.GroupMeal.Application.Service.Device.Dtos
{
try
{
-
// Topic = TOPIC.GetInstance.GetBusinessTopic(x, storeInfo.FirstOrDefault(a => a.Id == item.OrgId).AutoKey) + "/" + item.AutoKey;
BPAPackage bPAPackage = new BPAPackage
{
@@ -138,22 +163,27 @@ namespace BPA.KitChen.GroupMeal.Application.Service.Device.Dtos
}
catch (Exception e)
{
- return "下发错误,错误信息:" + 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.KitChen.GroupMeal.Application/Service/Device/Services/IDevicePushRecodeService.cs b/BPA.KitChen.GroupMeal.Application/Service/Device/Services/IDevicePushRecodeService.cs
index 4e4526c..02c993c 100644
--- a/BPA.KitChen.GroupMeal.Application/Service/Device/Services/IDevicePushRecodeService.cs
+++ b/BPA.KitChen.GroupMeal.Application/Service/Device/Services/IDevicePushRecodeService.cs
@@ -1,4 +1,5 @@
-using BPA.KitChen.GroupMeal.Application.BaseDto;
+
+using BPA.KitChen.GroupMeal.Application.BaseDto;
using System;
using System.Collections.Generic;
using System.Linq;
@@ -21,8 +22,11 @@ namespace BPA.KitChen.GroupMeal.Application.Service.Device.Dtos
///
///
Task Add(DevicePushRecodeDtoInput input);
-
-
+ ///
+ /// 更新
+ ///
+ ///
+ ///
Task Update(string id);
///
/// 删除