From 76c8dcd65d3ef126d37963e5b566e19311b17b8d Mon Sep 17 00:00:00 2001
From: zhaoy <137053305@qq.com>
Date: Thu, 29 Feb 2024 18:50:45 +0800
Subject: [PATCH] =?UTF-8?q?=E6=95=B0=E6=8D=AE=E4=B8=8B=E5=8F=91?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../BPA.SAAS.KitChenManage.Application.csproj | 1 +
.../BPA.SAAS.KitChenManage.Application.xml | 75 ++++++++
.../Services/DevicePushRecodeService.cs | 180 ++++++++++--------
.../Push/Comm/CommDefaultHandle.cs | 34 ++--
.../Push/Comm/Dto/BaseParmDto.cs | 15 ++
.../Push/Comm/MqttServer.cs | 103 ++++++++++
.../Push/Comm/WorkTask.cs | 34 ++++
.../Push/奶茶机_V1/ProductFunctionData.cs | 33 ++++
.../Push/奶茶机_v1/Dto/ReplyBaseDto.cs | 15 ++
.../Store/Services/IStoreService.cs | 1 +
.../Store/Services/StoreService.cs | 19 ++
.../Store/StoreServices.cs | 9 +
.../BPA.SAAS.KitChenManage.Core.csproj | 6 +-
.../BPA.SAAS.KitChenManage.Core.xml | 2 +-
BPA.SAAS.KitChenManage.Core/DbContext.cs | 2 +-
.../Model/BPA_DevicePushRecode.cs | 6 +-
.../BPA.SAAS.KitChenManage.Web.Core.csproj | 1 +
BPA.SAAS.KitChenManage.Web.Core/Startup.cs | 2 +
18 files changed, 445 insertions(+), 93 deletions(-)
create mode 100644 BPA.SAAS.KitChenManage.Application/Push/Comm/Dto/BaseParmDto.cs
create mode 100644 BPA.SAAS.KitChenManage.Application/Push/Comm/MqttServer.cs
create mode 100644 BPA.SAAS.KitChenManage.Application/Push/Comm/WorkTask.cs
create mode 100644 BPA.SAAS.KitChenManage.Application/Push/奶茶机_v1/Dto/ReplyBaseDto.cs
diff --git a/BPA.SAAS.KitChenManage.Application/BPA.SAAS.KitChenManage.Application.csproj b/BPA.SAAS.KitChenManage.Application/BPA.SAAS.KitChenManage.Application.csproj
index f89edf0..3d85bc8 100644
--- a/BPA.SAAS.KitChenManage.Application/BPA.SAAS.KitChenManage.Application.csproj
+++ b/BPA.SAAS.KitChenManage.Application/BPA.SAAS.KitChenManage.Application.csproj
@@ -19,6 +19,7 @@
+
diff --git a/BPA.SAAS.KitChenManage.Application/BPA.SAAS.KitChenManage.Application.xml b/BPA.SAAS.KitChenManage.Application/BPA.SAAS.KitChenManage.Application.xml
index bb9d29e..6340e07 100644
--- a/BPA.SAAS.KitChenManage.Application/BPA.SAAS.KitChenManage.Application.xml
+++ b/BPA.SAAS.KitChenManage.Application/BPA.SAAS.KitChenManage.Application.xml
@@ -161,6 +161,14 @@
+
+
+ 数据下发回调更新数据
+
+
+
+
+
删除
@@ -457,11 +465,72 @@
属性值
+
+
+ 发布mq(发送数据)
+
+
+
+
+
+
+
+
+ 订阅,mq
+
+
+
+
产品下发数据格式定义
+
+
+ 物料下发topics
+
+
+
+
+ 响应物料下发topics
+
+
+
+
+ 工艺下发topics
+
+
+
+
+ 响应工艺下发topics
+
+
+
+
+ 商品下发topics
+
+
+
+
+ 响应商品下发topics
+
+
+
+
+ 物料下发服务参数格式
+
+
+
+
+ 商品下发服务参数格式
+
+
+
+
+ 工艺下发服务参数格式
+
+
分页
@@ -537,6 +606,12 @@
+
+
+ 查询所有店铺(外部调用)
+
+
+
添加
diff --git a/BPA.SAAS.KitChenManage.Application/Device/Services/DevicePushRecodeService.cs b/BPA.SAAS.KitChenManage.Application/Device/Services/DevicePushRecodeService.cs
index dbe2913..653b9ee 100644
--- a/BPA.SAAS.KitChenManage.Application/Device/Services/DevicePushRecodeService.cs
+++ b/BPA.SAAS.KitChenManage.Application/Device/Services/DevicePushRecodeService.cs
@@ -2,23 +2,29 @@
using BPA.Message.IOT;
using BPA.SAAS.KitChenManage.Application.Device.Dtos;
using BPA.SAAS.KitChenManage.Application.Push.Comm;
+using BPA.SAAS.KitChenManage.Application.Push.奶茶机_v1.Dto;
using BPA.SAAS.KitChenManage.Application.Store.Dtos;
using BPA.SAAS.KitChenManage.Comm.Const;
using BPA.SAAS.KitChenManage.Core.Base;
using BPA.SAAS.KitChenManage.Core.Model;
using Furion.LinqBuilder;
using Furion.RemoteRequest.Extensions;
+using Longbow.Tasks;
using Microsoft.CodeAnalysis.Operations;
using Microsoft.Extensions.Hosting;
using MQTTnet;
using MQTTnet.Client;
+using MQTTnet.Client.Subscribing;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http.Json;
+using System.Reflection;
using System.Text;
+using System.Text.RegularExpressions;
using System.Threading.Tasks;
+using uPLibrary.Networking.M2Mqtt;
namespace BPA.SAAS.KitChenManage.Application.Device.Services
{
@@ -26,11 +32,13 @@ namespace BPA.SAAS.KitChenManage.Application.Device.Services
{
private readonly ISqlSugarClient _db;
private readonly IMqttClient _mqttClient;
- CommDefaultHandle requestParmsHeadlen = new();
+ CommDefaultHandle commDefaultHandle = new();
+ MqttServer mqttServer;
public DevicePushRecodeService(ISqlSugarClient db, IMqttClient mqttClient)
{
_db = db;
_mqttClient=mqttClient;
+ mqttServer = new(mqttClient);
}
///
/// 分页
@@ -55,6 +63,10 @@ namespace BPA.SAAS.KitChenManage.Application.Device.Services
DataResore=t.DataResore,
Status=t.Status,
Description=t.Description,
+ MessageId=t.MessageId,
+ TopicRely=t.TopicRely,
+ DataResoreRely=t.DataResoreRely,
+ DescriptionRely=t.DescriptionRely,
}).OrderBy(x => x.CreateAt, OrderByType.Desc).ToPageListAsync(input.Current, input.PageSize, total);
PageUtil util = new PageUtil()
{
@@ -71,55 +83,77 @@ namespace BPA.SAAS.KitChenManage.Application.Device.Services
///
public async Task Add(DevicePushRecodeDtoInput input)
{
- var DataResore =await requestParmsHeadlen.GetParm(input.Type, input.Data.ToString(), input.DeviceId, input.ProductName, input.ProductVersion);
var data = input.Adapt();
- string topstr = "";
- string Topic = GetTopic(input.Type, input.DeviceAutoKey.ToString(), input.ProductVersion, input.ProductKey, out topstr);
+ var DataResore =await commDefaultHandle.GetParm(input.Type, input.Data.ToString(), input.DeviceId, input.ProductName, input.ProductVersion, input.DeviceAutoKey.ToString());
+ if(DataResore==null) throw Oops.Oh("解析参数失败");
+ string Topic = DataResore.TopicsStr;
if (string.IsNullOrEmpty(Topic)) throw Oops.Oh("请配置相关topic");
-
+ var maxmessageId=_db.Queryable().Max(x => x.MessageId);
+ int messageId = maxmessageId+1;
+ var groupId = App.User?.FindFirst(ClaimConst.GroupId)?.Value;
data.Topic= Topic;
- data.Status = 1;
- data.DataResore = JsonConvert.SerializeObject(DataResore);
+ data.Status = 0;
+ data.DataResore = JsonConvert.SerializeObject(DataResore.Data);
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 =2;
- data.Description = "下发数据失败,该产品还未配置对应的topic,请联系管理员进行配置";
- }
- }
- else
+ data.Description = "下发中,等待设备响应";
+ data.MessageId= messageId;
+ data.TopicRely = DataResore.TopicsStrRely;
+ data.DescriptionRely = "等待回调";
+ var respush = await mqttServer.Publish(Topic, new PushData() { Data = data.DataResore, DeviceId = input.DeviceAutoKey }, messageId);
+ if (respush != "success")
{
+ data.Description = respush;
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 true;
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(messageId.ToString(), async (provider, token) => {
+ await CallBackDevicePushRecode(messageId.ToString(), groupId);
+ }, trigger);
+ //订阅回复数据下发topics
+ await mqttServer.Subscribe(DataResore.TopicsStrRely);
+ await BindMqReceived(messageId.ToString(), groupId);
return res>0;
}
+ ///
+ /// 数据下发回调更新数据
+ ///
+ ///
+ ///
+ ///
+ public async Task CallBackDevicePushRecode(string messageId,string groupId)
+ {
+ var model = await _db.Queryable().Where(x => x.MessageId.ToString() == messageId.ToString() && x.GroupId == groupId).FirstAsync();
+ if (model.Status == 0)
+ {
+ model.Status = 1;
+ model.Description = "下发成功,设备未回调";
+ model.DescriptionRely = "响应数据失败";
+ _db.Updateable(model).ExecuteCommand();
+ }
+ }
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 });
+ var groupId = App.User?.FindFirst(ClaimConst.GroupId)?.Value;
+ data.Status = 0;
+ data.Description = "下发中,等待设备响应";
+ data.DescriptionRely = "等待回调";
+ data.DataResoreRely = "";
+ // data.MessageId= messageId;
+ var respush = await mqttServer.Publish(data.Topic, new PushData() { Data = data.DataResore, DeviceId = data.DeviceAutoKey }, data.MessageId);
if (respush!= "success")
{
data.Description = respush;
data.Status = 2;
}
var res = await _db.Updateable(data).ExecuteCommandAsync();
+ var trigger = TriggerBuilder.Default.WithInterval(TimeSpan.FromSeconds(10)).WithRepeatCount(1).Build();
+ TaskServicesManager.GetOrAdd(data.MessageId.ToString(), async (provider, token) => {
+ await CallBackDevicePushRecode(data.MessageId.ToString(), groupId);
+ }, trigger);
+ await BindMqReceived(data.MessageId.ToString(), groupId);
return res > 0;
}
///
@@ -142,53 +176,49 @@ namespace BPA.SAAS.KitChenManage.Application.Device.Services
throw Oops.Oh("删除失败");
}
}
- private async Task Push(string Topic,PushData data)
+ private async Task BindMqReceived(string messageId,string groupId)
{
- try
+ _mqttClient.UseApplicationMessageReceivedHandler(async e =>
{
- // Topic = TOPIC.GetInstance.GetBusinessTopic(x, storeInfo.FirstOrDefault(a => a.Id == item.OrgId).AutoKey) + "/" + item.AutoKey;
- BPAPackage bPAPackage = new BPAPackage
+ var model = await _db.Queryable().Where(x => x.MessageId.ToString() == messageId.ToString() && x.GroupId == groupId).FirstAsync();
+ if (model != null && model.Status == 0)
{
- MessageId = MessageID.TMC_PUSH_INGREDIENTS,
- ClientId = data.DeviceId,
- //ClientType = Procuct
- MessageVersion = 0x30,
- Timestamp = DateTime.Now,
- Message = data
- };
- //每次下发暂停200毫秒 by 王刚 2022-06-08 测试提出修改
- // Thread.Sleep(200);
- //string aa = bPAPackage.Serialize(false);
- var applictionmessage = new MqttApplicationMessageBuilder().WithTopic(Topic).WithPayload(bPAPackage.Serialize(false)).WithAtLeastOnceQoS().Build();
- await _mqttClient.PublishAsync(applictionmessage);
- return "success";
- }
- catch (Exception e)
- {
- return "下发错误,错误信息:" + e.Message;
-
- }
- }
- private string GetTopic(int type,string deviceKey, string productVersion, string productKey,out string topstr )
- {
- string topic = "";
- topstr = "";
- switch (type)
- {
- case 1: //商品下发
- topic = $"/{productKey}/{productVersion}/{deviceKey}/defaul/goodspush";
- topstr = "/"+productKey+"/"+productVersion+"/${deviceKey}/defaul/goodspush";
- break;
- case 2://物料下发
- topic = $"/{productKey}/{productVersion}/{deviceKey}/defaul/batvhingpush";
- topstr = "/" + productKey + "/" + productVersion + "/${deviceKey}/defaul/batvhingpush";
- break;
- case 4:
- topic = $"/{productKey}/{productVersion}/{deviceKey}/defaul/chnologypush";
- topstr = "/" + productKey + "/" + productVersion + "/${deviceKey}/defaul/chnologypush";
- break;
- }
- return topic;
+ var str = Encoding.UTF8.GetString(e.ApplicationMessage.Payload ?? Array.Empty()).Replace("\r", "").Replace("\n", "").Replace("\t", "");
+ model.DataResoreRely = str;
+ model.Description = "下发成功,设备已回调";
+ try
+ {
+ var re = JsonConvert.DeserializeObject(str);
+ if (re.MessageId != messageId.ToString())
+ {
+ model = await _db.Queryable().Where(x => x.MessageId.ToString() == re.MessageId && x.GroupId == groupId).FirstAsync();
+ model.DataResoreRely = str;
+ model.Description = "下发成功,设备已回调";
+ }
+ if (model != null)
+ {
+ if (re.Success)
+ {
+ model.Status = 1;
+ model.DescriptionRely = "回调成功";
+ }
+ else
+ {
+ model.Status = 1;
+ model.DescriptionRely = re.Errors;
+ }
+ }
+ }
+ catch (Exception ex)
+ {
+ model.Status = 1;
+ model.Description = "下发成功";
+ model.DescriptionRely = "响应数据异常,异常信息:" + ex.Message;
+
+ }
+ _db.Updateable(model).ExecuteCommand();
+ }
+ });
}
}
}
diff --git a/BPA.SAAS.KitChenManage.Application/Push/Comm/CommDefaultHandle.cs b/BPA.SAAS.KitChenManage.Application/Push/Comm/CommDefaultHandle.cs
index 2cbd52d..baae0ee 100644
--- a/BPA.SAAS.KitChenManage.Application/Push/Comm/CommDefaultHandle.cs
+++ b/BPA.SAAS.KitChenManage.Application/Push/Comm/CommDefaultHandle.cs
@@ -1,9 +1,9 @@
using BPA.Message;
using BPA.SAAS.KitChenManage.Application.Device.PushDto.ProductFunction;
+using BPA.SAAS.KitChenManage.Application.Push.Comm.Dto;
using BPA.SAAS.KitChenManage.Application.Push.Comm.Dto.Batching;
using BPA.SAAS.KitChenManage.Application.Push.Comm.Dto.Goods;
using BPA.SAAS.KitChenManage.Application.Push.Comm.Dto.GoodsTechnology;
-using BPA.SAAS.KitChenManage.Application.Push.奶茶机_v1;
using BPA.SAAS.KitChenManage.Comm.Const;
using BPA.SAAS.KitChenManage.Core.Base;
using Furion.JsonSerialization;
@@ -25,28 +25,36 @@ namespace BPA.SAAS.KitChenManage.Application.Push.Comm
public class CommDefaultHandle
{
private string BaseServerUrl = App.GetConfig("baseurl");
- public async Task GetParm(int type, string data, string deviceId,string productName, string productVersion)
+ public async Task GetParm(int type, string data, string deviceId,string productName, string productVersion, string deviceAutoKey)
{
+ string strTopics = "";
+ string TopicsStrRely = "";
dynamic obj = null;
switch (type)
{
case 1: //商品下发
- var GoodsData = GetProduct_VersionData(productName, productVersion, "GoodsData");
- if (string.IsNullOrWhiteSpace(GoodsData)) throw Oops.Oh("系统还未开发【产品名称:" + productName + "-版本号:" + productVersion + "】的商品数据下发功能");
+ var GoodsData = GetProduct_VersionData(productName, productVersion, "GoodsData"); ;//获取对应版本的下发数据参数
+ strTopics = GetProduct_VersionData(productName, productVersion, "GoodsPushTopics").Replace("${deviceKey}", deviceAutoKey); //获取对应版本的下发topics
+ TopicsStrRely = GetProduct_VersionData(productName, productVersion, "GoodsPushTopics_reply").Replace("${deviceKey}", deviceAutoKey);//获取对应版本的下发topics
+ if (string.IsNullOrWhiteSpace(GoodsData)) throw Oops.Oh("系统还未开发【产品名称:" + productName + " 版本号:" + productVersion + "】的商品数据下发功能");
obj = await GetGoods(data, GoodsData);
break;
case 2://物料下发
- var BatchingData = GetProduct_VersionData(productName, productVersion, "BatchingData");
- if (string.IsNullOrWhiteSpace(BatchingData)) throw Oops.Oh("系统还未开发【产品名称:"+ productName + "-版本号:"+ productVersion + "】的物料数据下发功能");
+ var BatchingData = GetProduct_VersionData(productName, productVersion, "BatchingData");//获取对应版本的下发数据参数
+ strTopics = GetProduct_VersionData(productName, productVersion, "BatchingPushTopics").Replace("${deviceKey}", deviceAutoKey);//获取对应版本的下发topics
+ TopicsStrRely= GetProduct_VersionData(productName, productVersion, "BatchingPushTopics_reply").Replace("${deviceKey}", deviceAutoKey);//获取对应版本的下发topics
+ if (string.IsNullOrWhiteSpace(BatchingData)) throw Oops.Oh("系统还未开发【产品名称:"+ productName + " 版本号:"+ productVersion + "】的物料数据下发功能");
obj = await GetBatching(data, BatchingData);
break;
- case 4:
- var TechnologyData = GetProduct_VersionData(productName, productVersion, "TechnologyData");
- if (string.IsNullOrWhiteSpace(TechnologyData)) throw Oops.Oh("系统还未开发【产品名称:" + productName + "-版本号:" + productVersion + "】的工艺数据下发功能");
+ case 4://工艺下发
+ var TechnologyData = GetProduct_VersionData(productName, productVersion, "TechnologyData"); ;//获取对应版本的下发数据参数
+ strTopics = GetProduct_VersionData(productName, productVersion, "TechnologyPushTopics").Replace("${deviceKey}", deviceAutoKey);//获取对应版本的下发topics
+ TopicsStrRely = GetProduct_VersionData(productName, productVersion, "TechnologyPushTopics_reply").Replace("${deviceKey}", deviceAutoKey);//获取对应版本的下发topics
+ if (string.IsNullOrWhiteSpace(TechnologyData)) throw Oops.Oh("系统还未开发【产品名称:" + productName + " 版本号:" + productVersion + "】的工艺数据下发功能");
obj = await GetGoodsTechnology(data, deviceId, TechnologyData);
break;
}
- return obj;
+ return new BaseParmDto() {Data= obj,TopicsStr= strTopics,TopicsStrRely= TopicsStrRely };
}
private async Task GetGoods(string data, string productFunctionData)
{
@@ -201,6 +209,7 @@ namespace BPA.SAAS.KitChenManage.Application.Push.Comm
}
}
+
///
/// 映射数据
///
@@ -266,8 +275,9 @@ namespace BPA.SAAS.KitChenManage.Application.Push.Comm
///
private string GetProduct_VersionData(string productName, string productVersion,string attrubiteName)
{
- string namespaceName = "BPA.SAAS.KitChenManage.Application.Push."+ productName + "_"+ productVersion; // 要查询的命名空间名称
- Assembly assembly = typeof(CommDefaultHandle).Assembly; // 当前程序集(或者其他需要查询的程序集)
+ //判断当前产品版本是否存在下发数据格式定义的类 如果存在则根据属性取出里面定义的数据格式
+ string namespaceName = "BPA.SAAS.KitChenManage.Application.Push."+ productName + "_"+ productVersion;
+ Assembly assembly = typeof(CommDefaultHandle).Assembly;
Type[] typesInNamespace = assembly.GetTypes().Where(t => t.Namespace == namespaceName).ToArray();
var value = "";
foreach (Type type in typesInNamespace)
diff --git a/BPA.SAAS.KitChenManage.Application/Push/Comm/Dto/BaseParmDto.cs b/BPA.SAAS.KitChenManage.Application/Push/Comm/Dto/BaseParmDto.cs
new file mode 100644
index 0000000..a3ef66c
--- /dev/null
+++ b/BPA.SAAS.KitChenManage.Application/Push/Comm/Dto/BaseParmDto.cs
@@ -0,0 +1,15 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace BPA.SAAS.KitChenManage.Application.Push.Comm.Dto
+{
+ public class BaseParmDto
+ {
+ public dynamic Data { get; set; }
+ public string TopicsStr { get; set; }
+ public string TopicsStrRely { get; set; }
+ }
+}
diff --git a/BPA.SAAS.KitChenManage.Application/Push/Comm/MqttServer.cs b/BPA.SAAS.KitChenManage.Application/Push/Comm/MqttServer.cs
new file mode 100644
index 0000000..ff1408d
--- /dev/null
+++ b/BPA.SAAS.KitChenManage.Application/Push/Comm/MqttServer.cs
@@ -0,0 +1,103 @@
+using BPA.Message;
+using BPA.SAAS.KitChenManage.Application.Device.Dtos;
+using MQTTnet.Client.Subscribing;
+using MQTTnet;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using MQTTnet.Client;
+using uPLibrary.Networking.M2Mqtt;
+
+namespace BPA.SAAS.KitChenManage.Application.Push.Comm
+{
+ public class MqttServer
+ {
+ private readonly IMqttClient _mqttClient;
+ public MqttServer(IMqttClient mqttClient)
+ {
+ _mqttClient=mqttClient;
+ }
+ ///
+ /// 发布mq(发送数据)
+ ///
+ ///
+ ///
+ ///
+ ///
+ public async Task Publish(string Topic, PushData data, int MessageId)
+ {
+ try
+ {
+ if (string.IsNullOrEmpty(Topic))
+ {
+ throw Oops.Oh("订阅主题不能为空!");
+ }
+
+ // 判断客户端是否连接
+ if (!_mqttClient.IsConnected)
+ {
+ throw Oops.Oh("MQTT 客户端尚未连接!");
+ }
+
+ // Topic = TOPIC.GetInstance.GetBusinessTopic(x, storeInfo.FirstOrDefault(a => a.Id == item.OrgId).AutoKey) + "/" + item.AutoKey;
+ BPAPackage bPAPackage = new BPAPackage
+ {
+ MessageId = MessageId,// MessageID.TMC_PUSH_INGREDIENTS,
+ ClientId = data.DeviceId,
+ //ClientType = Procuct
+ MessageVersion = 0x30,
+ Timestamp = DateTime.Now,
+ Message = data
+ };
+ //每次下发暂停200毫秒 by 王刚 2022-06-08 测试提出修改
+ // Thread.Sleep(200);
+ //string aa = bPAPackage.Serialize(false);
+ var applictionmessage = new MqttApplicationMessageBuilder().WithTopic(Topic).WithPayload(bPAPackage.Serialize(false)).WithAtLeastOnceQoS().Build();
+ await _mqttClient.PublishAsync(applictionmessage);
+ return "success";
+ }
+ catch (Exception e)
+ {
+ return "下发错误,错误信息:" + e.Message;
+
+ }
+ }
+ ///
+ /// 订阅,mq
+ ///
+ ///
+ ///
+ public async Task Subscribe(string topic)
+ {
+ string str = "success";
+ try
+ {
+ topic = topic.Trim();
+ if (string.IsNullOrEmpty(topic))
+ {
+ throw Oops.Oh("订阅主题不能为空!");
+ }
+
+ // 判断客户端是否连接
+ if (!_mqttClient.IsConnected)
+ {
+ throw Oops.Oh("MQTT 客户端尚未连接!");
+ }
+
+ // 设置订阅参数
+ var subscribeOptions = new MqttClientSubscribeOptionsBuilder()
+ .WithTopicFilter(topic)
+ .Build();
+ await _mqttClient.SubscribeAsync(subscribeOptions, CancellationToken.None);
+ return str;
+ }
+ catch (Exception e)
+ {
+ return "下发错误,错误信息:" + e.Message;
+
+ }
+ }
+ }
+}
diff --git a/BPA.SAAS.KitChenManage.Application/Push/Comm/WorkTask.cs b/BPA.SAAS.KitChenManage.Application/Push/Comm/WorkTask.cs
new file mode 100644
index 0000000..00b662e
--- /dev/null
+++ b/BPA.SAAS.KitChenManage.Application/Push/Comm/WorkTask.cs
@@ -0,0 +1,34 @@
+using BPA.SAAS.KitChenManage.Application.Device.Services;
+using Longbow.Tasks;
+using Microsoft.Extensions.DependencyInjection;
+using MQTTnet.Client;
+using MQTTnet.Server;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using uPLibrary.Networking.M2Mqtt;
+
+namespace BPA.SAAS.KitChenManage.Application.Push.Comm
+{
+ public class WorkTask : ITask, ITransient
+ {
+ // IMqttClient mqttServermqttClient;
+ IDevicePushRecodeService devicePushRecodeService;
+ //MqttServer mqttClient;
+ public async Task Execute(IServiceProvider provider, CancellationToken cancellationToken)
+ {
+ // mqttServermqttClient = provider.GetService();
+ devicePushRecodeService = provider.GetService();
+ //mqttClient = new(mqttServermqttClient);
+ //cancellationToken.Register(devicePushRecodeService.CallBackDevicePushRecode())
+
+ //await devicePushRecodeService.CallBackDevicePushRecode();
+
+ // Console.WriteLine($"订阅消息返回:"+ str);
+
+ // return Task.CompletedTask;
+ }
+ }
+}
diff --git a/BPA.SAAS.KitChenManage.Application/Push/奶茶机_V1/ProductFunctionData.cs b/BPA.SAAS.KitChenManage.Application/Push/奶茶机_V1/ProductFunctionData.cs
index 304b8be..147eedf 100644
--- a/BPA.SAAS.KitChenManage.Application/Push/奶茶机_V1/ProductFunctionData.cs
+++ b/BPA.SAAS.KitChenManage.Application/Push/奶茶机_V1/ProductFunctionData.cs
@@ -11,8 +11,41 @@ namespace BPA.SAAS.KitChenManage.Application.Push.奶茶机_v1
///
public class ProductFunctionData
{
+ ///
+ /// 物料下发topics
+ ///
+ public const string BatchingPushTopics = "/120078739409565e0/v1/${deviceKey}/defaul/batvhingpush";
+ ///
+ /// 响应物料下发topics
+ ///
+ public const string BatchingPushTopics_reply= "/120078739409565e0/v1/${deviceKey}/defaul/batvhingpush_reply";
+ ///
+ /// 工艺下发topics
+ ///
+ public const string TechnologyPushTopics = "/120078739409565e0/v1/${deviceKey}/defaul/chnologypush";
+ ///
+ /// 响应工艺下发topics
+ ///
+ public const string TechnologyPushTopics_reply = "/120078739409565e0/v1/${deviceKey}/defaul/chnologypush_reply";
+ ///
+ /// 商品下发topics
+ ///
+ public const string GoodsPushTopics = "/120078739409565e0/v1/${deviceKey}/defaul/goodspush";
+ ///
+ ///响应商品下发topics
+ ///
+ public const string GoodsPushTopics_reply = "/120078739409565e0/v1/${deviceKey}/defaul/goodspush_reply";
+ ///
+ /// 物料下发服务参数格式
+ ///
public const string BatchingData = "{\r\n\t\"batchinginfo\": [{\r\n\t\t\"id\": \"物料ID\",\r\n\t\t\"name\": \"物料名称\",\r\n\t\t\"typeid\": \"物料类型ID\",\r\n\t\t\"typename\": \"物料类型名称\",\r\n\t\t\"unit\": \"单位\",\r\n\t\t\"createAt\": \"创建时间\"\r\n\t}],\r\n\t\"batchingTypeinfo\": [{\r\n\t\t\"id\": \"ID\",\r\n\t\t\"name\": \"物料类型名称\"\r\n\t}],\r\n\t\"batchingUnitinfo\": [{\r\n\t\t\"id\": \"ID\",\r\n\t\t\"name\": \"物料单位名称\"\r\n\t}]\r\n}";
+ ///
+ /// 商品下发服务参数格式
+ ///
public const string GoodsData = "{\r\n\t\"goodsinfo\": [{\r\n\t\t\"id\": \"商品ID\",\r\n\t\t\"name\": \"商品名称\",\r\n\t\t\"goodsTypeId\": \"商品类型ID\",\r\n\t\t\"goodsTypeName\": \"商品类型名称\",\r\n\t\t\"goodsUintId\": \"单位Id\",\r\n\t\t\"goodsUintName\": \"单位名称\",\r\n\t\t\"createAt\": \"创建时间\",\r\n\t\t\"imgUrl\": \"商品图片路径\",\r\n\t\t\"price\": \"价格\",\r\n\t\t\"design\": \"描述\"\r\n\t}],\r\n\t\"goodsTypeInfo\": [{\r\n\t\t\"id\": \"id\",\r\n\t\t\"name\": \"分类名称\",\r\n\t\t\"PId\": \"父级id\"\r\n\t}],\r\n\t\"goodsUnitInfo\": [{\r\n\t\t\"id\": \"id\",\r\n\t\t\"name\": \"单位名称\"\r\n\t}],\r\n\t\"goodsAttribute\": [{\r\n\t\t\"id\": \"id\",\r\n\t\t\"attributeName\": \"属性名称\",\r\n\t\t\"goodsTypeId\": \"商品分类id\",\r\n\t\t\"attributeValueList\": [{\r\n\t\t\t\"id\": \"id\",\r\n\t\t\t\"goodsAttributeId\": \"商品属性id\",\r\n\t\t\t\"attributeValue\": \"商品属性值\"\r\n\t\t}]\r\n\t}]\r\n}";
+ ///
+ /// 工艺下发服务参数格式
+ ///
public const string TechnologyData = "{\r\n\t\"technologysInfo\": [{\r\n\t\t\"id\": \"id\",\r\n\t\t\"name\": \"工艺步骤名称\",\r\n\t\t\"DeviceVersionId\": \"设备版本id\",\r\n\t\t\"technologyActionInfo\": [{\r\n\t\t\t\"id\": \"id\",\r\n\t\t\t\"technologyId\": \"工艺步骤id\",\r\n\t\t\t\"actionName\": \"模型名称\",\r\n\t\t\t\"actionValue\": \"模型数据\",\r\n\t\t\t\"actionType\": \"数据类型\",\r\n\t\t\t\"technologyType\": \"工艺模型类型(标识是否物料 1标识物料 0标识其他)\"\r\n\t\t}],\r\n\t}],\r\n\t\r\n\t\"goodsTechnologysInfo\": [{\r\n\t\t\"id\": \"id\",\r\n\t\t\"stepName\": \"工艺步骤名称\",\r\n\t\t\"actionJson\": \"工艺模型json\",\r\n\t\t\"goodsAttributeId\": \"商品属性值id组合\",\r\n\t\t\"chnologyId\": \"工艺id\",\r\n\t\t\"goodsId\": \"商品id\",\r\n\t\t\"deviceId\": \"设备id\",\r\n\t\t\"createAt\": \"创建时间\"\r\n\t}]\r\n}";
}
}
diff --git a/BPA.SAAS.KitChenManage.Application/Push/奶茶机_v1/Dto/ReplyBaseDto.cs b/BPA.SAAS.KitChenManage.Application/Push/奶茶机_v1/Dto/ReplyBaseDto.cs
new file mode 100644
index 0000000..c42ff56
--- /dev/null
+++ b/BPA.SAAS.KitChenManage.Application/Push/奶茶机_v1/Dto/ReplyBaseDto.cs
@@ -0,0 +1,15 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace BPA.SAAS.KitChenManage.Application.Push.奶茶机_v1.Dto
+{
+ public class ReplyBaseDto
+ {
+ public string MessageId { get; set; }
+ public bool Success { get; set; }
+ public string Errors { get; set; }
+ }
+}
diff --git a/BPA.SAAS.KitChenManage.Application/Store/Services/IStoreService.cs b/BPA.SAAS.KitChenManage.Application/Store/Services/IStoreService.cs
index ec83b3f..555259e 100644
--- a/BPA.SAAS.KitChenManage.Application/Store/Services/IStoreService.cs
+++ b/BPA.SAAS.KitChenManage.Application/Store/Services/IStoreService.cs
@@ -21,6 +21,7 @@ namespace BPA.SAAS.KitChenManage.Application.Store.Services
///
///
Task> GetStoreList();
+ Task> GetStoreList_alm();
///
/// 添加
///
diff --git a/BPA.SAAS.KitChenManage.Application/Store/Services/StoreService.cs b/BPA.SAAS.KitChenManage.Application/Store/Services/StoreService.cs
index dd6ecd8..6e7db78 100644
--- a/BPA.SAAS.KitChenManage.Application/Store/Services/StoreService.cs
+++ b/BPA.SAAS.KitChenManage.Application/Store/Services/StoreService.cs
@@ -66,6 +66,25 @@ namespace BPA.SAAS.KitChenManage.Application.Store.Services
return res;
}
+ public async Task> GetStoreList_alm()
+ {
+ string groupId = App.HttpContext.Request.Headers["groupId"].ToString();
+ if (string.IsNullOrWhiteSpace(groupId)) throw Oops.Oh("加盟商id不能为空");
+ var res = await _db.Queryable().Where(x=>x.GroupId== groupId)
+ .Select(t => new StoreDtoOutput
+ {
+ CreateAt = t.CreateAt,
+ Id = t.Id,
+ Name = t.Name,
+ Phone = t.Phone,
+ Description = t.Description,
+ OrgName = t.OrgName,
+ OrgId = t.OrgId,
+ Sort = t.Sort,
+ }).OrderBy(t => t.Sort).OrderBy(x => x.CreateAt, OrderByType.Desc).ToListAsync();
+
+ return res;
+ }
///
/// 添加
///
diff --git a/BPA.SAAS.KitChenManage.Application/Store/StoreServices.cs b/BPA.SAAS.KitChenManage.Application/Store/StoreServices.cs
index ee9793a..b3fff53 100644
--- a/BPA.SAAS.KitChenManage.Application/Store/StoreServices.cs
+++ b/BPA.SAAS.KitChenManage.Application/Store/StoreServices.cs
@@ -38,6 +38,15 @@ namespace BPA.SAAS.KitChenManage.Application.Store
return await _storeService.GetStoreList();
}
///
+ /// 查询所有店铺(外部调用)
+ ///
+ ///
+ [HttpGet("/api/store/getstorelist_alm")]
+ public async Task> GetStoreList_alm()
+ {
+ return await _storeService.GetStoreList_alm();
+ }
+ ///
/// 添加
///
///
diff --git a/BPA.SAAS.KitChenManage.Core/BPA.SAAS.KitChenManage.Core.csproj b/BPA.SAAS.KitChenManage.Core/BPA.SAAS.KitChenManage.Core.csproj
index 82e9de3..5602eb0 100644
--- a/BPA.SAAS.KitChenManage.Core/BPA.SAAS.KitChenManage.Core.csproj
+++ b/BPA.SAAS.KitChenManage.Core/BPA.SAAS.KitChenManage.Core.csproj
@@ -14,9 +14,9 @@
-
-
-
+
+
+
diff --git a/BPA.SAAS.KitChenManage.Core/BPA.SAAS.KitChenManage.Core.xml b/BPA.SAAS.KitChenManage.Core/BPA.SAAS.KitChenManage.Core.xml
index 97f099a..9f05f2e 100644
--- a/BPA.SAAS.KitChenManage.Core/BPA.SAAS.KitChenManage.Core.xml
+++ b/BPA.SAAS.KitChenManage.Core/BPA.SAAS.KitChenManage.Core.xml
@@ -67,7 +67,7 @@
- 下发状态 1成功 2失败
+ 下发状态 0下发中 1成功 2失败
diff --git a/BPA.SAAS.KitChenManage.Core/DbContext.cs b/BPA.SAAS.KitChenManage.Core/DbContext.cs
index 05e15ce..de697d7 100644
--- a/BPA.SAAS.KitChenManage.Core/DbContext.cs
+++ b/BPA.SAAS.KitChenManage.Core/DbContext.cs
@@ -38,7 +38,7 @@ namespace BPA.SAAS.KitChenManage.Core
//过滤已删除数据
db.QueryFilter.AddTableFilter(it => it.IsDeleted == 0);
//db.QueryFilter.AddTableFilter(it => it.Status == 0);
- if (App.User.FindFirst(ClaimConst.CLAINM_SUPERADMIN)?.Value != null)
+ if (App.User?.FindFirst(ClaimConst.CLAINM_SUPERADMIN)?.Value != null)
{
//非管理员账户过滤加盟商数据
var groupId = App.User?.FindFirst(ClaimConst.GroupId)?.Value;
diff --git a/BPA.SAAS.KitChenManage.Core/Model/BPA_DevicePushRecode.cs b/BPA.SAAS.KitChenManage.Core/Model/BPA_DevicePushRecode.cs
index 18a331c..93aaba9 100644
--- a/BPA.SAAS.KitChenManage.Core/Model/BPA_DevicePushRecode.cs
+++ b/BPA.SAAS.KitChenManage.Core/Model/BPA_DevicePushRecode.cs
@@ -21,10 +21,14 @@ namespace BPA.SAAS.KitChenManage.Core.Model
public string Topic { get; set; }
public string DataResore { get; set; }
///
- /// 下发状态 1成功 2失败
+ /// 下发状态 0下发中 1成功 2失败
///
public int Status { get; set; }
public int DeviceAutoKey { get; set; }
public string Description { get; set; }
+ public int MessageId { get; set; }
+ public string TopicRely { get; set; }
+ public string DataResoreRely { get; set; }
+ public string DescriptionRely { get; set; }
}
}
diff --git a/BPA.SAAS.KitChenManage.Web.Core/BPA.SAAS.KitChenManage.Web.Core.csproj b/BPA.SAAS.KitChenManage.Web.Core/BPA.SAAS.KitChenManage.Web.Core.csproj
index 92f71a1..97b5e18 100644
--- a/BPA.SAAS.KitChenManage.Web.Core/BPA.SAAS.KitChenManage.Web.Core.csproj
+++ b/BPA.SAAS.KitChenManage.Web.Core/BPA.SAAS.KitChenManage.Web.Core.csproj
@@ -17,6 +17,7 @@
+
diff --git a/BPA.SAAS.KitChenManage.Web.Core/Startup.cs b/BPA.SAAS.KitChenManage.Web.Core/Startup.cs
index 825b54b..b5124fd 100644
--- a/BPA.SAAS.KitChenManage.Web.Core/Startup.cs
+++ b/BPA.SAAS.KitChenManage.Web.Core/Startup.cs
@@ -7,6 +7,7 @@ using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using MQTTnet.Client.Connecting;
using MQTTnet.Client.Disconnecting;
+using ProtoBuf.Meta;
using System;
using System.Threading.Tasks;
@@ -50,6 +51,7 @@ namespace BPA.SAAS.KitChenManage.Web.Core
});
});
// services.GetService();
+ services.AddTaskServices();
services.AddCorsAccessor();
services.AddRemoteRequest();
services.AddSqlsugarSetup(App.Configuration);