diff --git a/BPA.SAAS.KitChenManage.Application/BPA.SAAS.KitChenManage.Application.csproj b/BPA.SAAS.KitChenManage.Application/BPA.SAAS.KitChenManage.Application.csproj
index 70e45f7..f89edf0 100644
--- a/BPA.SAAS.KitChenManage.Application/BPA.SAAS.KitChenManage.Application.csproj
+++ b/BPA.SAAS.KitChenManage.Application/BPA.SAAS.KitChenManage.Application.csproj
@@ -14,6 +14,13 @@
+
+
+
+
+
+
+
diff --git a/BPA.SAAS.KitChenManage.Application/BPA.SAAS.KitChenManage.Application.xml b/BPA.SAAS.KitChenManage.Application/BPA.SAAS.KitChenManage.Application.xml
index e3ed43a..502db6c 100644
--- a/BPA.SAAS.KitChenManage.Application/BPA.SAAS.KitChenManage.Application.xml
+++ b/BPA.SAAS.KitChenManage.Application/BPA.SAAS.KitChenManage.Application.xml
@@ -4,6 +4,90 @@
BPA.SAAS.KitChenManage.Application
+
+
+ 分页
+
+
+
+
+
+
+ 添加
+
+
+
+
+
+
+ 修改
+
+
+
+
+
+
+ 删除
+
+
+
+
+
+
+ 分页
+
+
+
+
+
+
+ 添加
+
+
+
+
+
+
+ 修改
+
+
+
+
+
+
+ 删除
+
+
+
+
+
+
+ 分页
+
+
+
+
+
+
+ 添加
+
+
+
+
+
+
+ 修改
+
+
+
+
+
+
+ 删除
+
+
+
+
商品菜品id
diff --git a/BPA.SAAS.KitChenManage.Application/Device/DevicePushRecodeServices.cs b/BPA.SAAS.KitChenManage.Application/Device/DevicePushRecodeServices.cs
new file mode 100644
index 0000000..fba8cc0
--- /dev/null
+++ b/BPA.SAAS.KitChenManage.Application/Device/DevicePushRecodeServices.cs
@@ -0,0 +1,61 @@
+using BPA.SAAS.KitChenManage.Application.Device.Dtos;
+using BPA.SAAS.KitChenManage.Application.Device.Services;
+using BPA.SAAS.KitChenManage.Core.Base;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace BPA.SAAS.KitChenManage.Application.Device
+{
+ [ApiDescriptionSettings("DevicePushRecode", Tag = "设备下发")]
+ public class DevicePushRecodeServices: IDynamicApiController
+ {
+ IDevicePushRecodeService _devicePushRecodeService;
+ public DevicePushRecodeServices(IDevicePushRecodeService devicePushRecodeService)
+ {
+ _devicePushRecodeService= devicePushRecodeService;
+ }
+ ///
+ /// 分页
+ ///
+ ///
+ ///
+ [HttpPost("/api/devicepushrecode/page")]
+ public async Task Page(DevicePushRecodeDtoPageInput input)
+ {
+ return await _devicePushRecodeService.Page(input);
+ }
+ ///
+ /// 添加
+ ///
+ ///
+ ///
+ [HttpPost("/api/devicepushrecode/add")]
+ public async Task Add(DevicePushRecodeDtoInput input)
+ {
+ return await _devicePushRecodeService.Add(input);
+ }
+ ///
+ /// 修改
+ ///
+ ///
+ ///
+ [HttpPost("/api/devicepushrecode/update")]
+ public async Task Update(DevicePushRecodeDtoInput input)
+ {
+ return await _devicePushRecodeService.Update(input);
+ }
+ ///
+ /// 删除
+ ///
+ ///
+ ///
+ [HttpPost("/api/devicepushrecode/delete")]
+ public async Task Delete(List input)
+ {
+ return await _devicePushRecodeService.Delete(input);
+ }
+ }
+}
diff --git a/BPA.SAAS.KitChenManage.Application/Device/Dtos/DevicePushRecodeDtoInput.cs b/BPA.SAAS.KitChenManage.Application/Device/Dtos/DevicePushRecodeDtoInput.cs
new file mode 100644
index 0000000..4af7410
--- /dev/null
+++ b/BPA.SAAS.KitChenManage.Application/Device/Dtos/DevicePushRecodeDtoInput.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.Device.Dtos
+{
+ public class DevicePushRecodeDtoInput
+ {
+ public string Id { get; set; }
+ public string DeviceId { get; set; }
+ public string Type { get; set; }
+ }
+}
diff --git a/BPA.SAAS.KitChenManage.Application/Device/Dtos/DevicePushRecodeDtoPageInput.cs b/BPA.SAAS.KitChenManage.Application/Device/Dtos/DevicePushRecodeDtoPageInput.cs
new file mode 100644
index 0000000..3921383
--- /dev/null
+++ b/BPA.SAAS.KitChenManage.Application/Device/Dtos/DevicePushRecodeDtoPageInput.cs
@@ -0,0 +1,13 @@
+using BPA.SAAS.KitChenManage.Core.Base;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace BPA.SAAS.KitChenManage.Application.Device.Dtos
+{
+ public class DevicePushRecodeDtoPageInput: PageInputBase
+ {
+ }
+}
diff --git a/BPA.SAAS.KitChenManage.Application/Device/Dtos/PushData.cs b/BPA.SAAS.KitChenManage.Application/Device/Dtos/PushData.cs
new file mode 100644
index 0000000..25acd13
--- /dev/null
+++ b/BPA.SAAS.KitChenManage.Application/Device/Dtos/PushData.cs
@@ -0,0 +1,18 @@
+using BPA.Message;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace BPA.SAAS.KitChenManage.Application.Device.Dtos
+{
+ public class PushData: IMessage
+ {
+ public object Data { get; set; }
+ ///
+ /// 设备AutoKey
+ ///
+ public int DeviceId { get; set; }
+ }
+}
diff --git a/BPA.SAAS.KitChenManage.Application/Device/Services/DevicePushRecodeService.cs b/BPA.SAAS.KitChenManage.Application/Device/Services/DevicePushRecodeService.cs
new file mode 100644
index 0000000..ffdb954
--- /dev/null
+++ b/BPA.SAAS.KitChenManage.Application/Device/Services/DevicePushRecodeService.cs
@@ -0,0 +1,125 @@
+using BPA.Message;
+using BPA.SAAS.KitChenManage.Application.Device.Dtos;
+using BPA.SAAS.KitChenManage.Application.Store.Dtos;
+using BPA.SAAS.KitChenManage.Core.Base;
+using BPA.SAAS.KitChenManage.Core.Model;
+using Furion.LinqBuilder;
+using MQTTnet;
+using MQTTnet.Client;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace BPA.SAAS.KitChenManage.Application.Device.Services
+{
+ public class DevicePushRecodeService: IDevicePushRecodeService, ITransient
+ {
+ private readonly ISqlSugarClient _db;
+ private readonly IMqttClient _mqttClient;
+ public DevicePushRecodeService(ISqlSugarClient db, IMqttClient mqttClient)
+ {
+ _db = db;
+ _mqttClient=mqttClient;
+ }
+ ///
+ /// 分页
+ ///
+ ///
+ ///
+ public async Task Page(DevicePushRecodeDtoPageInput input)
+ {
+ RefAsync total = 0;
+ var res = await _db.Queryable()
+ .Select(t => new
+ {
+ CreateAt = t.CreateAt,
+ Id = t.Id,
+ DeviceId = t.DeviceId,
+ Type=t.Type
+ }).OrderBy(x => x.CreateAt, OrderByType.Desc).ToPageListAsync(input.Current, input.PageSize, total);
+ PageUtil util = new PageUtil()
+ {
+ Total = total,
+ Data = res
+
+ };
+ return util;
+ }
+ ///
+ /// 添加
+ ///
+ ///
+ ///
+ public async Task Add(DevicePushRecodeDtoInput input)
+ {
+ var Store = input.Adapt();
+ // role.DataScopeType = DataScopeType.ALL;
+ await Push(0, null);
+ return await _db.Insertable(Store).CallEntityMethod(t => t.Create()).ExecuteCommandAsync() > 0;
+ }
+ ///
+ /// 修改
+ ///
+ ///
+ ///
+ public async Task Update(DevicePushRecodeDtoInput input)
+ {
+ var BPA_Store = await _db.Queryable().Where(a => a.Id == input.Id).FirstAsync();
+
+ var Store = await _db.Queryable().Where(a => a.Id == input.Id).FirstAsync();
+ Store.DeviceId = input.DeviceId;
+ Store.Type = input.Type;
+ return _db.Updateable(Store).ExecuteCommandHasChange();
+
+ }
+ ///
+ /// 删除
+ ///
+ ///
+ ///
+ public async Task Delete(List input)
+ {
+ try
+ {
+ // 查询数据库中是否存在未删除的活动信息
+ var resEntitites = _db.Queryable().In(input).ToList();
+ var res = await _db.Deleteable(resEntitites).ExecuteCommandAsync();
+ return res > 0;
+
+ }
+ catch (Exception)
+ {
+ throw Oops.Oh("删除失败");
+ }
+ }
+ private async Task Push(int AutoKey, PushData data)
+ {
+ try
+ {
+ string Topic = "";
+ // Topic = TOPIC.GetInstance.GetBusinessTopic(x, storeInfo.FirstOrDefault(a => a.Id == item.OrgId).AutoKey) + "/" + item.AutoKey;
+ BPAPackage bPAPackage = new BPAPackage
+ {
+ MessageId = MessageID.TMC_PUSH_INGREDIENTS,
+ ClientId = AutoKey,
+ //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();
+ _mqttClient.PublishAsync(applictionmessage);
+ return true;
+ }
+ catch (Exception)
+ {
+ return false;
+ }
+ }
+ }
+}
diff --git a/BPA.SAAS.KitChenManage.Application/Device/Services/IDevicePushRecodeService.cs b/BPA.SAAS.KitChenManage.Application/Device/Services/IDevicePushRecodeService.cs
new file mode 100644
index 0000000..5cc5e00
--- /dev/null
+++ b/BPA.SAAS.KitChenManage.Application/Device/Services/IDevicePushRecodeService.cs
@@ -0,0 +1,38 @@
+using BPA.SAAS.KitChenManage.Application.Device.Dtos;
+using BPA.SAAS.KitChenManage.Core.Base;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace BPA.SAAS.KitChenManage.Application.Device.Services
+{
+ public interface IDevicePushRecodeService
+ {
+ ///
+ /// 分页
+ ///
+ ///
+ ///
+ Task Page(DevicePushRecodeDtoPageInput input);
+ ///
+ /// 添加
+ ///
+ ///
+ ///
+ Task Add(DevicePushRecodeDtoInput input);
+ ///
+ /// 修改
+ ///
+ ///
+ ///
+ Task Update(DevicePushRecodeDtoInput input);
+ ///
+ /// 删除
+ ///
+ ///
+ ///
+ Task Delete(List input);
+ }
+}
diff --git a/BPA.SAAS.KitChenManage.Core/Model/BPA_DevicePushRecode.cs b/BPA.SAAS.KitChenManage.Core/Model/BPA_DevicePushRecode.cs
new file mode 100644
index 0000000..02a2c8e
--- /dev/null
+++ b/BPA.SAAS.KitChenManage.Core/Model/BPA_DevicePushRecode.cs
@@ -0,0 +1,18 @@
+using BPA.SAAS.KitChenManage.Core.Base;
+using SqlSugar;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace BPA.SAAS.KitChenManage.Core.Model
+{
+ [SugarTable("bpa_devicepushrecode")]
+ public class BPA_DevicePushRecode : IBaseEntity, IGroupId
+ {
+ public string DeviceId { get; set; }
+ public string Type { get; set; }
+ public string GroupId { 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 5b7ffb4..92f71a1 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
@@ -13,6 +13,13 @@
+
+
+
+
+
+
+
diff --git a/BPA.SAAS.KitChenManage.Web.Core/Startup.cs b/BPA.SAAS.KitChenManage.Web.Core/Startup.cs
index 5fceaf1..a18ef1a 100644
--- a/BPA.SAAS.KitChenManage.Web.Core/Startup.cs
+++ b/BPA.SAAS.KitChenManage.Web.Core/Startup.cs
@@ -1,9 +1,14 @@
-using BPA.SAAS.KitChenManage.Core;
+using BPA.MQTTClient;
+using BPA.SAAS.KitChenManage.Core;
using Furion;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
+using MQTTnet.Client.Connecting;
+using MQTTnet.Client.Disconnecting;
+using System;
+using System.Threading.Tasks;
namespace BPA.SAAS.KitChenManage.Web.Core
{
@@ -13,7 +18,37 @@ namespace BPA.SAAS.KitChenManage.Web.Core
{
services.AddConsoleFormatter();
services.AddJwt();
+ services.AddMqttClientHostedService(op =>
+ {
+ op.Port = int.Parse(App.Configuration["dev1_brokerHostSettings:Port"]);
+ op.Server = App.Configuration["dev1_brokerHostSettings:Host"];
+ op.UserName = App.Configuration["MqttClientSettings:UserName"];
+ op.Password = App.Configuration["MqttClientSettings:Password"];
+ op.mqttClientConnectedHandlerDelegate = new MqttClientConnectedHandlerDelegate(async e =>
+ {
+ Console.WriteLine("MQTT连接成功");
+ });
+ op.mqttClientDisconnectedHandlerDelegate = new MqttClientDisconnectedHandlerDelegate(async e =>
+ {
+ Console.WriteLine("MQTT断开连接");
+ await Task.Delay(TimeSpan.FromSeconds(5));
+ try
+ {
+ //var options = op.Server.GetService();
+ //await op.Server.GetService().ConnectAsync(options);
+ }
+ catch (global::System.Exception)
+ {
+
+ }
+ });
+ op.MqttApplicationMessageReceivedHandler = new MQTTnet.Client.Receiving.MqttApplicationMessageReceivedHandlerDelegate(async e =>
+ {
+
+ });
+ });
+ // services.GetService();
services.AddCorsAccessor();
services.AddSqlsugarSetup(App.Configuration);
services.AddControllers()
diff --git a/BPA.SAAS.KitChenManage.Web.Entry/appsettings.json b/BPA.SAAS.KitChenManage.Web.Entry/appsettings.json
index d6921ce..2b54937 100644
--- a/BPA.SAAS.KitChenManage.Web.Entry/appsettings.json
+++ b/BPA.SAAS.KitChenManage.Web.Entry/appsettings.json
@@ -14,5 +14,13 @@
"DbType": "Mysql",
"IsAutoCloseConnection": true
}
- ]
+ ],
+ "dev1_brokerHostSettings": {
+ "Port": 8083,
+ "Host": "10.2.1.21"
+ },
+ "MqttClientSettings": {
+ "UserName": "emqx_u_block",
+ "Password": "emqx_p_admin8765490789"
+ }
}
\ No newline at end of file