@@ -14,6 +14,13 @@ | |||||
<None Remove="BPA.SAAS.KitChenManage.Application.xml" /> | <None Remove="BPA.SAAS.KitChenManage.Application.xml" /> | ||||
</ItemGroup> | </ItemGroup> | ||||
<ItemGroup> | |||||
<PackageReference Include="BPA.Message" Version="1.0.105" /> | |||||
<PackageReference Include="BPA.MQTTClient" Version="1.0.11" /> | |||||
</ItemGroup> | |||||
<ItemGroup> | <ItemGroup> | ||||
<ProjectReference Include="..\BPA.SAAS.KitChenManage.Core\BPA.SAAS.KitChenManage.Core.csproj" /> | <ProjectReference Include="..\BPA.SAAS.KitChenManage.Core\BPA.SAAS.KitChenManage.Core.csproj" /> | ||||
</ItemGroup> | </ItemGroup> | ||||
@@ -4,6 +4,90 @@ | |||||
<name>BPA.SAAS.KitChenManage.Application</name> | <name>BPA.SAAS.KitChenManage.Application</name> | ||||
</assembly> | </assembly> | ||||
<members> | <members> | ||||
<member name="M:BPA.SAAS.KitChenManage.Application.Device.DevicePushRecodeServices.Page(BPA.SAAS.KitChenManage.Application.Device.Dtos.DevicePushRecodeDtoPageInput)"> | |||||
<summary> | |||||
分页 | |||||
</summary> | |||||
<param name="input"></param> | |||||
<returns></returns> | |||||
</member> | |||||
<member name="M:BPA.SAAS.KitChenManage.Application.Device.DevicePushRecodeServices.Add(BPA.SAAS.KitChenManage.Application.Device.Dtos.DevicePushRecodeDtoInput)"> | |||||
<summary> | |||||
添加 | |||||
</summary> | |||||
<param name="input"></param> | |||||
<returns></returns> | |||||
</member> | |||||
<member name="M:BPA.SAAS.KitChenManage.Application.Device.DevicePushRecodeServices.Update(BPA.SAAS.KitChenManage.Application.Device.Dtos.DevicePushRecodeDtoInput)"> | |||||
<summary> | |||||
修改 | |||||
</summary> | |||||
<param name="input"></param> | |||||
<returns></returns> | |||||
</member> | |||||
<member name="M:BPA.SAAS.KitChenManage.Application.Device.DevicePushRecodeServices.Delete(System.Collections.Generic.List{System.String})"> | |||||
<summary> | |||||
删除 | |||||
</summary> | |||||
<param name="input"></param> | |||||
<returns></returns> | |||||
</member> | |||||
<member name="M:BPA.SAAS.KitChenManage.Application.Device.Services.DevicePushRecodeService.Page(BPA.SAAS.KitChenManage.Application.Device.Dtos.DevicePushRecodeDtoPageInput)"> | |||||
<summary> | |||||
分页 | |||||
</summary> | |||||
<param name="input"></param> | |||||
<returns></returns> | |||||
</member> | |||||
<member name="M:BPA.SAAS.KitChenManage.Application.Device.Services.DevicePushRecodeService.Add(BPA.SAAS.KitChenManage.Application.Device.Dtos.DevicePushRecodeDtoInput)"> | |||||
<summary> | |||||
添加 | |||||
</summary> | |||||
<param name="input"></param> | |||||
<returns></returns> | |||||
</member> | |||||
<member name="M:BPA.SAAS.KitChenManage.Application.Device.Services.DevicePushRecodeService.Update(BPA.SAAS.KitChenManage.Application.Device.Dtos.DevicePushRecodeDtoInput)"> | |||||
<summary> | |||||
修改 | |||||
</summary> | |||||
<param name="input"></param> | |||||
<returns></returns> | |||||
</member> | |||||
<member name="M:BPA.SAAS.KitChenManage.Application.Device.Services.DevicePushRecodeService.Delete(System.Collections.Generic.List{System.String})"> | |||||
<summary> | |||||
删除 | |||||
</summary> | |||||
<param name="input"></param> | |||||
<returns></returns> | |||||
</member> | |||||
<member name="M:BPA.SAAS.KitChenManage.Application.Device.Services.IDevicePushRecodeService.Page(BPA.SAAS.KitChenManage.Application.Device.Dtos.DevicePushRecodeDtoPageInput)"> | |||||
<summary> | |||||
分页 | |||||
</summary> | |||||
<param name="input"></param> | |||||
<returns></returns> | |||||
</member> | |||||
<member name="M:BPA.SAAS.KitChenManage.Application.Device.Services.IDevicePushRecodeService.Add(BPA.SAAS.KitChenManage.Application.Device.Dtos.DevicePushRecodeDtoInput)"> | |||||
<summary> | |||||
添加 | |||||
</summary> | |||||
<param name="input"></param> | |||||
<returns></returns> | |||||
</member> | |||||
<member name="M:BPA.SAAS.KitChenManage.Application.Device.Services.IDevicePushRecodeService.Update(BPA.SAAS.KitChenManage.Application.Device.Dtos.DevicePushRecodeDtoInput)"> | |||||
<summary> | |||||
修改 | |||||
</summary> | |||||
<param name="input"></param> | |||||
<returns></returns> | |||||
</member> | |||||
<member name="M:BPA.SAAS.KitChenManage.Application.Device.Services.IDevicePushRecodeService.Delete(System.Collections.Generic.List{System.String})"> | |||||
<summary> | |||||
删除 | |||||
</summary> | |||||
<param name="input"></param> | |||||
<returns></returns> | |||||
</member> | |||||
<member name="P:BPA.SAAS.KitChenManage.Application.Food.Dtos.FoodMenuBaseDto.GoodsIds"> | <member name="P:BPA.SAAS.KitChenManage.Application.Food.Dtos.FoodMenuBaseDto.GoodsIds"> | ||||
<summary> | <summary> | ||||
商品菜品id | 商品菜品id | ||||
@@ -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; | |||||
} | |||||
/// <summary> | |||||
/// 分页 | |||||
/// </summary> | |||||
/// <param name="input"></param> | |||||
/// <returns></returns> | |||||
[HttpPost("/api/devicepushrecode/page")] | |||||
public async Task<PageUtil> Page(DevicePushRecodeDtoPageInput input) | |||||
{ | |||||
return await _devicePushRecodeService.Page(input); | |||||
} | |||||
/// <summary> | |||||
/// 添加 | |||||
/// </summary> | |||||
/// <param name="input"></param> | |||||
/// <returns></returns> | |||||
[HttpPost("/api/devicepushrecode/add")] | |||||
public async Task<bool> Add(DevicePushRecodeDtoInput input) | |||||
{ | |||||
return await _devicePushRecodeService.Add(input); | |||||
} | |||||
/// <summary> | |||||
/// 修改 | |||||
/// </summary> | |||||
/// <param name="input"></param> | |||||
/// <returns></returns> | |||||
[HttpPost("/api/devicepushrecode/update")] | |||||
public async Task<bool> Update(DevicePushRecodeDtoInput input) | |||||
{ | |||||
return await _devicePushRecodeService.Update(input); | |||||
} | |||||
/// <summary> | |||||
/// 删除 | |||||
/// </summary> | |||||
/// <param name="input"></param> | |||||
/// <returns></returns> | |||||
[HttpPost("/api/devicepushrecode/delete")] | |||||
public async Task<bool> Delete(List<string> input) | |||||
{ | |||||
return await _devicePushRecodeService.Delete(input); | |||||
} | |||||
} | |||||
} |
@@ -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; } | |||||
} | |||||
} |
@@ -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 | |||||
{ | |||||
} | |||||
} |
@@ -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; } | |||||
/// <summary> | |||||
/// 设备AutoKey | |||||
/// </summary> | |||||
public int DeviceId { get; set; } | |||||
} | |||||
} |
@@ -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; | |||||
} | |||||
/// <summary> | |||||
/// 分页 | |||||
/// </summary> | |||||
/// <param name="input"></param> | |||||
/// <returns></returns> | |||||
public async Task<PageUtil> Page(DevicePushRecodeDtoPageInput input) | |||||
{ | |||||
RefAsync<int> total = 0; | |||||
var res = await _db.Queryable<BPA_DevicePushRecode>() | |||||
.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; | |||||
} | |||||
/// <summary> | |||||
/// 添加 | |||||
/// </summary> | |||||
/// <param name="input"></param> | |||||
/// <returns></returns> | |||||
public async Task<bool> Add(DevicePushRecodeDtoInput input) | |||||
{ | |||||
var Store = input.Adapt<BPA_DevicePushRecode>(); | |||||
// role.DataScopeType = DataScopeType.ALL; | |||||
await Push(0, null); | |||||
return await _db.Insertable(Store).CallEntityMethod(t => t.Create()).ExecuteCommandAsync() > 0; | |||||
} | |||||
/// <summary> | |||||
/// 修改 | |||||
/// </summary> | |||||
/// <param name="input"></param> | |||||
/// <returns></returns> | |||||
public async Task<bool> Update(DevicePushRecodeDtoInput input) | |||||
{ | |||||
var BPA_Store = await _db.Queryable<BPA_DevicePushRecode>().Where(a => a.Id == input.Id).FirstAsync(); | |||||
var Store = await _db.Queryable<BPA_DevicePushRecode>().Where(a => a.Id == input.Id).FirstAsync(); | |||||
Store.DeviceId = input.DeviceId; | |||||
Store.Type = input.Type; | |||||
return _db.Updateable(Store).ExecuteCommandHasChange(); | |||||
} | |||||
/// <summary> | |||||
/// 删除 | |||||
/// </summary> | |||||
/// <param name="input"></param> | |||||
/// <returns></returns> | |||||
public async Task<bool> Delete(List<string> input) | |||||
{ | |||||
try | |||||
{ | |||||
// 查询数据库中是否存在未删除的活动信息 | |||||
var resEntitites = _db.Queryable<BPA_DevicePushRecode>().In(input).ToList(); | |||||
var res = await _db.Deleteable(resEntitites).ExecuteCommandAsync(); | |||||
return res > 0; | |||||
} | |||||
catch (Exception) | |||||
{ | |||||
throw Oops.Oh("删除失败"); | |||||
} | |||||
} | |||||
private async Task<bool> 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; | |||||
} | |||||
} | |||||
} | |||||
} |
@@ -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 | |||||
{ | |||||
/// <summary> | |||||
/// 分页 | |||||
/// </summary> | |||||
/// <param name="input"></param> | |||||
/// <returns></returns> | |||||
Task<PageUtil> Page(DevicePushRecodeDtoPageInput input); | |||||
/// <summary> | |||||
/// 添加 | |||||
/// </summary> | |||||
/// <param name="input"></param> | |||||
/// <returns></returns> | |||||
Task<bool> Add(DevicePushRecodeDtoInput input); | |||||
/// <summary> | |||||
/// 修改 | |||||
/// </summary> | |||||
/// <param name="input"></param> | |||||
/// <returns></returns> | |||||
Task<bool> Update(DevicePushRecodeDtoInput input); | |||||
/// <summary> | |||||
/// 删除 | |||||
/// </summary> | |||||
/// <param name="input"></param> | |||||
/// <returns></returns> | |||||
Task<bool> Delete(List<string> input); | |||||
} | |||||
} |
@@ -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; } | |||||
} | |||||
} |
@@ -13,6 +13,13 @@ | |||||
<None Remove="BPA.SAAS.KitChenManage.Web.Core.xml" /> | <None Remove="BPA.SAAS.KitChenManage.Web.Core.xml" /> | ||||
</ItemGroup> | </ItemGroup> | ||||
<ItemGroup> | |||||
<PackageReference Include="BPA.MQTTClient" Version="1.0.11" /> | |||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" /> | |||||
</ItemGroup> | |||||
<ItemGroup> | <ItemGroup> | ||||
<ProjectReference Include="..\BPA.SAAS.KitChenManage.Application\BPA.SAAS.KitChenManage.Application.csproj" /> | <ProjectReference Include="..\BPA.SAAS.KitChenManage.Application\BPA.SAAS.KitChenManage.Application.csproj" /> | ||||
</ItemGroup> | </ItemGroup> | ||||
@@ -1,9 +1,14 @@ | |||||
using BPA.SAAS.KitChenManage.Core; | |||||
using BPA.MQTTClient; | |||||
using BPA.SAAS.KitChenManage.Core; | |||||
using Furion; | using Furion; | ||||
using Microsoft.AspNetCore.Builder; | using Microsoft.AspNetCore.Builder; | ||||
using Microsoft.AspNetCore.Hosting; | using Microsoft.AspNetCore.Hosting; | ||||
using Microsoft.Extensions.DependencyInjection; | using Microsoft.Extensions.DependencyInjection; | ||||
using Microsoft.Extensions.Hosting; | using Microsoft.Extensions.Hosting; | ||||
using MQTTnet.Client.Connecting; | |||||
using MQTTnet.Client.Disconnecting; | |||||
using System; | |||||
using System.Threading.Tasks; | |||||
namespace BPA.SAAS.KitChenManage.Web.Core | namespace BPA.SAAS.KitChenManage.Web.Core | ||||
{ | { | ||||
@@ -13,7 +18,37 @@ namespace BPA.SAAS.KitChenManage.Web.Core | |||||
{ | { | ||||
services.AddConsoleFormatter(); | services.AddConsoleFormatter(); | ||||
services.AddJwt<JwtHandler>(); | services.AddJwt<JwtHandler>(); | ||||
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<IMqttClientOptions>(); | |||||
//await op.Server.GetService<IMqttClient>().ConnectAsync(options); | |||||
} | |||||
catch (global::System.Exception) | |||||
{ | |||||
} | |||||
}); | |||||
op.MqttApplicationMessageReceivedHandler = new MQTTnet.Client.Receiving.MqttApplicationMessageReceivedHandlerDelegate(async e => | |||||
{ | |||||
}); | |||||
}); | |||||
// services.GetService<IMqttClientOptions>(); | |||||
services.AddCorsAccessor(); | services.AddCorsAccessor(); | ||||
services.AddSqlsugarSetup(App.Configuration); | services.AddSqlsugarSetup(App.Configuration); | ||||
services.AddControllers() | services.AddControllers() | ||||
@@ -14,5 +14,13 @@ | |||||
"DbType": "Mysql", | "DbType": "Mysql", | ||||
"IsAutoCloseConnection": true | "IsAutoCloseConnection": true | ||||
} | } | ||||
] | |||||
], | |||||
"dev1_brokerHostSettings": { | |||||
"Port": 8083, | |||||
"Host": "10.2.1.21" | |||||
}, | |||||
"MqttClientSettings": { | |||||
"UserName": "emqx_u_block", | |||||
"Password": "emqx_p_admin8765490789" | |||||
} | |||||
} | } |