@@ -18,19 +18,22 @@ | |||
<param name="input"></param> | |||
<returns></returns> | |||
</member> | |||
<member name="M:BPA.SAAS.KitChenManage.Application.Device.DevicePushRecodeServices.Update(BPA.SAAS.KitChenManage.Application.Device.Dtos.DevicePushRecodeDtoInput)"> | |||
<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.DevicePushRecodeServices.Delete(System.Collections.Generic.List{System.String})"> | |||
<member name="P:BPA.SAAS.KitChenManage.Application.Device.Dtos.DevicePushRecodeDtoPageInput.Type"> | |||
<summary> | |||
删除 | |||
下发类型1商品 2物料 3配方 | |||
</summary> | |||
</member> | |||
<member name="P:BPA.SAAS.KitChenManage.Application.Device.Dtos.PushData.DeviceId"> | |||
<summary> | |||
设备AutoKey | |||
</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> | |||
@@ -46,13 +49,6 @@ | |||
<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> | |||
删除 | |||
@@ -74,13 +70,6 @@ | |||
<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> | |||
删除 | |||
@@ -37,16 +37,7 @@ namespace BPA.SAAS.KitChenManage.Application.Device | |||
{ | |||
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> | |||
@@ -8,8 +8,10 @@ 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; } | |||
public string DeviceName { get; set; } | |||
public int DeviceAutoKey { get; set; } | |||
public object Data { get; set; } | |||
public int Type { get; set; } | |||
} | |||
} |
@@ -9,5 +9,9 @@ namespace BPA.SAAS.KitChenManage.Application.Device.Dtos | |||
{ | |||
public class DevicePushRecodeDtoPageInput: PageInputBase | |||
{ | |||
/// <summary> | |||
/// 下发类型1商品 2物料 3配方 | |||
/// </summary> | |||
public int Type { get; set; } | |||
} | |||
} |
@@ -1,14 +1,18 @@ | |||
using BPA.Message; | |||
using BPA.Message.IOT; | |||
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 Microsoft.Extensions.Hosting; | |||
using MQTTnet; | |||
using MQTTnet.Client; | |||
using Newtonsoft.Json; | |||
using System; | |||
using System.Collections.Generic; | |||
using System.Linq; | |||
using System.Net.Http.Json; | |||
using System.Text; | |||
using System.Threading.Tasks; | |||
@@ -31,13 +35,17 @@ namespace BPA.SAAS.KitChenManage.Application.Device.Services | |||
public async Task<PageUtil> Page(DevicePushRecodeDtoPageInput input) | |||
{ | |||
RefAsync<int> total = 0; | |||
var res = await _db.Queryable<BPA_DevicePushRecode>() | |||
var res = await _db.Queryable<BPA_DevicePushRecode>().Where(x=>x.Type== input.Type) | |||
.Select(t => new | |||
{ | |||
CreateAt = t.CreateAt, | |||
CreateBy = t.CreateBy, | |||
Id = t.Id, | |||
DeviceId = t.DeviceId, | |||
Type=t.Type | |||
DeviceName= t.DeviceName, | |||
Type =t.Type, | |||
Topic=t.Topic, | |||
DataResore=t.DataResore, | |||
}).OrderBy(x => x.CreateAt, OrderByType.Desc).ToPageListAsync(input.Current, input.PageSize, total); | |||
PageUtil util = new PageUtil() | |||
{ | |||
@@ -54,25 +62,17 @@ namespace BPA.SAAS.KitChenManage.Application.Device.Services | |||
/// <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(); | |||
var data = input.Adapt<BPA_DevicePushRecode>(); | |||
string Topic = GetTopic(input.Type, input.DeviceAutoKey.ToString()); | |||
if (string.IsNullOrEmpty(Topic)) throw Oops.Oh("请配置相关topic"); | |||
data.Topic= Topic; | |||
data.DataResore = JsonConvert.SerializeObject(JsonConvert.DeserializeObject<dynamic>(input.Data.ToString())); | |||
var res=await Push(Topic, new PushData() { Data=input.Data, DeviceId= input.DeviceAutoKey }); | |||
if (res) | |||
{ | |||
await _db.Insertable(data).CallEntityMethod(t => t.Create()).ExecuteCommandAsync(); | |||
} | |||
return res; | |||
} | |||
/// <summary> | |||
/// 删除 | |||
@@ -94,16 +94,16 @@ namespace BPA.SAAS.KitChenManage.Application.Device.Services | |||
throw Oops.Oh("删除失败"); | |||
} | |||
} | |||
private async Task<bool> Push(int AutoKey, PushData data) | |||
private async Task<bool> Push(string Topic,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, | |||
ClientId = data.DeviceId, | |||
//ClientType = Procuct | |||
MessageVersion = 0x30, | |||
Timestamp = DateTime.Now, | |||
@@ -113,13 +113,30 @@ namespace BPA.SAAS.KitChenManage.Application.Device.Services | |||
// Thread.Sleep(200); | |||
//string aa = bPAPackage.Serialize(false); | |||
var applictionmessage = new MqttApplicationMessageBuilder().WithTopic(Topic).WithPayload(bPAPackage.Serialize(false)).WithAtLeastOnceQoS().Build(); | |||
_mqttClient.PublishAsync(applictionmessage); | |||
await _mqttClient.PublishAsync(applictionmessage); | |||
return true; | |||
} | |||
catch (Exception) | |||
catch (Exception e) | |||
{ | |||
throw Oops.Oh("下发错误,错误信息:"+e.Message); | |||
} | |||
} | |||
private string GetTopic(int type,string deviceKey) | |||
{ | |||
string topic = ""; | |||
switch (type) | |||
{ | |||
return false; | |||
case 1: //商品下发 | |||
topic = $"/da4bfff042c656210/${deviceKey}/use/goodspush"; | |||
break; | |||
case 2://物料下发 | |||
topic = $"/da4bfff042c656210/${deviceKey}/use/batvhingpush"; | |||
break; | |||
case 4: | |||
topic = $"/da4bfff042c656210/${deviceKey}/use/chnologypush"; | |||
break; | |||
} | |||
return topic; | |||
} | |||
} | |||
} |
@@ -22,12 +22,7 @@ namespace BPA.SAAS.KitChenManage.Application.Device.Services | |||
/// <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> | |||
@@ -28,7 +28,7 @@ namespace BPA.SAAS.KitChenManage.Application.Store.Services | |||
var res = await _db.Queryable<BPA_Store>() | |||
.WhereIF(!input.OrgName.IsNullOrEmpty(), t => t.OrgId.Contains(input.OrgName)) | |||
.WhereIF(!input.Name.IsNullOrEmpty(), t => t.Name.Contains(input.Name)) | |||
.WhereIF(!input.Phone.IsNullOrEmpty(), t => t.Phone.Contains(input.Phone)) | |||
.Select(t => new StoreDtoOutput | |||
{ | |||
CreateAt = t.CreateAt, | |||
@@ -60,6 +60,11 @@ | |||
</summary> | |||
</member> | |||
<!-- Badly formed XML comment ignored for member "M:BPA.SAAS.KitChenManage.Core.DbContext.IsSuperAdmin" --> | |||
<member name="P:BPA.SAAS.KitChenManage.Core.Model.BPA_DevicePushRecode.Type"> | |||
<summary> | |||
下发类型1商品 2物料 3配方 4工艺 | |||
</summary> | |||
</member> | |||
<member name="P:BPA.SAAS.KitChenManage.Core.Model.BPA_FoodMenuGoods.FoodMenuId"> | |||
<summary> | |||
菜谱id | |||
@@ -35,6 +35,15 @@ namespace BPA.SAAS.KitChenManage.Core | |||
SqlSugarScope sqlSugar = new SqlSugarScope(configConnection, | |||
db => | |||
{ | |||
//过滤已删除数据 | |||
db.QueryFilter.AddTableFilter<IDeleted>(it => it.IsDeleted == 0); | |||
//db.QueryFilter.AddTableFilter<IStatus>(it => it.Status == 0); | |||
if (App.User.FindFirst(ClaimConst.CLAINM_SUPERADMIN)?.Value != null) | |||
{ | |||
//非管理员账户过滤加盟商数据 | |||
var groupId = App.User?.FindFirst(ClaimConst.GroupId)?.Value; | |||
db.QueryFilter.AddTableFilter<IGroupId>(it => it.GroupId == groupId); | |||
} | |||
db.Aop.DataExecuting = (oldValue, entityInfo) => | |||
{ | |||
//新增添加加盟商id赋值 | |||
@@ -51,15 +60,8 @@ namespace BPA.SAAS.KitChenManage.Core | |||
//单例参数配置,所有上下文生效 | |||
db.Aop.OnLogExecuting = (sql, pars) => | |||
{ | |||
//过滤已删除数据 | |||
db.QueryFilter.AddTableFilter<IDeleted>(it => it.IsDeleted == 0); | |||
if (!IsSuperAdmin()) | |||
{ | |||
//非管理员账户过滤加盟商数据 | |||
var groupId = App.User?.FindFirst(ClaimConst.GroupId)?.Value; | |||
db.QueryFilter.AddTableFilter<IGroupId>(it => it.GroupId == groupId); | |||
} | |||
//Console.WriteLine(sql);//输出sql | |||
Console.WriteLine($"当前SQL语句:【{sql}】,参数:【{string.Join(",", pars.Select(t => t.Value))}】"); | |||
@@ -12,7 +12,13 @@ namespace BPA.SAAS.KitChenManage.Core.Model | |||
public class BPA_DevicePushRecode : IBaseEntity, IGroupId | |||
{ | |||
public string DeviceId { get; set; } | |||
public string Type { get; set; } | |||
public string DeviceName { get; set; } | |||
/// <summary> | |||
/// 下发类型1商品 2物料 3配方 4工艺 | |||
/// </summary> | |||
public int Type { get; set; } | |||
public string GroupId { get; set; } | |||
public string Topic { get; set; } | |||
public string DataResore { get; set; } | |||
} | |||
} |
@@ -18,6 +18,7 @@ namespace BPA.SAAS.KitChenManage.Web.Core | |||
{ | |||
services.AddConsoleFormatter(); | |||
services.AddJwt<JwtHandler>(); | |||
services.AddMqttClientHostedService(op => | |||
{ | |||
op.Port = int.Parse(App.Configuration["dev1_brokerHostSettings:Port"]); | |||
@@ -16,7 +16,7 @@ | |||
} | |||
], | |||
"dev1_brokerHostSettings": { | |||
"Port": 8083, | |||
"Port": 1883, | |||
"Host": "10.2.1.21" | |||
}, | |||
"MqttClientSettings": { | |||