gwbvipvip pirms 7 mēnešiem
vecāks
revīzija
426bd349d5
13 mainītis faili ar 341 papildinājumiem un 4 dzēšanām
  1. +5
    -1
      BPA.KitChen.StoreManagement.Application/BPA.KitChen.StoreManagement.Application.csproj
  2. +18
    -0
      BPA.KitChen.StoreManagement.Application/BaseDto/PushData.cs
  3. +12
    -0
      BPA.KitChen.StoreManagement.Application/Service/Device/Dtos/Class1.cs
  4. +17
    -0
      BPA.KitChen.StoreManagement.Application/Service/Device/Dtos/DevicePushRecodeDtoInput.cs
  5. +17
    -0
      BPA.KitChen.StoreManagement.Application/Service/Device/Dtos/DevicePushRecodeDtoPageInput.cs
  6. +12
    -0
      BPA.KitChen.StoreManagement.Application/Service/Device/Services/Class1.cs
  7. +160
    -0
      BPA.KitChen.StoreManagement.Application/Service/Device/Services/DevicePushRecodeService.cs
  8. +30
    -0
      BPA.KitChen.StoreManagement.Application/Service/Device/Services/IDevicePushRecodeService.cs
  9. +1
    -0
      BPA.KitChen.StoreManagement.Core/BPA.KitChen.StoreManagement.Core.csproj
  10. +26
    -0
      BPA.KitChen.StoreManagement.Core/Entity/BPA_DevicePushRecode.cs
  11. +2
    -1
      BPA.KitChen.StoreManagement/BPA.KitChen.StoreManagement.csproj
  12. +33
    -1
      BPA.KitChen.StoreManagement/Program.cs
  13. +8
    -1
      BPA.KitChen.StoreManagement/appsettings.json

+ 5
- 1
BPA.KitChen.StoreManagement.Application/BPA.KitChen.StoreManagement.Application.csproj Parādīt failu

@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
@@ -6,6 +6,10 @@
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="BPA.Message" Version="1.0.105" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\BPA.KitChen.StoreManagement.Core\BPA.KitChen.StoreManagement.Core.csproj" />
<ProjectReference Include="..\BPA.KitChen.StoreManagement.SqlSugar\BPA.KitChen.StoreManagement.SqlSugar.csproj" />


+ 18
- 0
BPA.KitChen.StoreManagement.Application/BaseDto/PushData.cs Parādīt failu

@@ -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.KitChen.StoreManagement.Application.BaseDto
{
public class PushData: IMessage
{
public object Data { get; set; }
/// <summary>
/// 设备AutoKey
/// </summary>
public int DeviceId { get; set; }
}
}

+ 12
- 0
BPA.KitChen.StoreManagement.Application/Service/Device/Dtos/Class1.cs Parādīt failu

@@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BPA.KitChen.StoreManagement.Application.Service.Device.Dtos
{
internal class Class1
{
}
}

+ 17
- 0
BPA.KitChen.StoreManagement.Application/Service/Device/Dtos/DevicePushRecodeDtoInput.cs Parādīt failu

@@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BPA.KitChen.StoreManagement.Application.Service.Device.Dtos
{
public class DevicePushRecodeDtoInput
{
public string DeviceId { get; set; }
public string DeviceName { get; set; }
public int DeviceAutoKey { get; set; }
public object Data { get; set; }
public int Type { get; set; }
}
}

+ 17
- 0
BPA.KitChen.StoreManagement.Application/Service/Device/Dtos/DevicePushRecodeDtoPageInput.cs Parādīt failu

@@ -0,0 +1,17 @@
using BPA.KitChen.StoreManagement.Application.BaseDto;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BPA.KitChen.StoreManagement.Application.Service.Device.Dtos
{
public class DevicePushRecodeDtoPageInput: PageInputBase
{
/// <summary>
/// 下发类型1商品 2物料 3配方
/// </summary>
public int Type { get; set; }
}
}

+ 12
- 0
BPA.KitChen.StoreManagement.Application/Service/Device/Services/Class1.cs Parādīt failu

@@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BPA.KitChen.StoreManagement.Application.Service.Device.Services
{
internal class Class1
{
}
}

+ 160
- 0
BPA.KitChen.StoreManagement.Application/Service/Device/Services/DevicePushRecodeService.cs Parādīt failu

@@ -0,0 +1,160 @@

using BPA.KitChen.StoreManagement.Application.BaseDto;
using BPA.KitChen.StoreManagement.Application.Service.Device.Dtos;
using BPA.KitChen.StoreManagement.Core.Entity;
using BPA.KitChen.StoreManagement.SqlSugar;
using BPA.Message;
using BPA.Message.IOT;
using Furion.DependencyInjection;
using Furion.DynamicApiController;
using Furion.FriendlyException;
using Furion.LinqBuilder;
using Mapster;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Hosting;
using MQTTnet;
using MQTTnet.Client;
using Newtonsoft.Json;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http.Json;
using System.Text;
using System.Threading.Tasks;

namespace BPA.KitChen.StoreManagement.Application.Service.Device.Services
{

[ApiDescriptionSettings("设备下发", Tag = "设备下发", SplitCamelCase = false)]
public class DevicePushRecodeService: IDynamicApiController, ITransient, IDevicePushRecodeService
{
private readonly SqlSugarScope _db;
private readonly IMqttClient _mqttClient;
public DevicePushRecodeService(ISqlSugarClient db, IMqttClient mqttClient)
{
_db = SqlSugarDb.Db;
_mqttClient=mqttClient;
}


/// <summary>
/// 分页
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpPost("/api/devicepushrecode/page")]
public async Task<PageUtil> Page(DevicePushRecodeDtoPageInput input)
{
RefAsync<int> total = 0;
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,
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()
{
Total = total,
Data = res

};
return util;
}


/// <summary>
/// 添加
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpPost("/api/devicepushrecode/add")]
public async Task<bool> Add(DevicePushRecodeDtoInput input)
{
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>
/// 删除
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpPost("/api/devicepushrecode/delete")]
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(string Topic, PushData data)
{
try
{
// 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 = 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 true;
}
catch (Exception e)
{
throw Oops.Oh("下发错误,错误信息:"+e.Message);
}
}
private string GetTopic(int type,string deviceKey)
{
string topic = "";
switch (type)
{
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;
}
}
}

+ 30
- 0
BPA.KitChen.StoreManagement.Application/Service/Device/Services/IDevicePushRecodeService.cs Parādīt failu

@@ -0,0 +1,30 @@


using BPA.KitChen.StoreManagement.Application.BaseDto;
using BPA.KitChen.StoreManagement.Application.Service.Device.Dtos;

namespace BPA.KitChen.StoreManagement.Application.Service.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> Delete(List<string> input);
}
}

+ 1
- 0
BPA.KitChen.StoreManagement.Core/BPA.KitChen.StoreManagement.Core.csproj Parādīt failu

@@ -7,6 +7,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="BPA.MQTTClient" Version="1.0.11" />
<PackageReference Include="Furion" Version="4.9.1.18" />
<PackageReference Include="Furion.Extras.Authentication.JwtBearer" Version="4.9.1.15" />
<PackageReference Include="Furion.Extras.DatabaseAccessor.SqlSugar" Version="4.9.1.18" />


+ 26
- 0
BPA.KitChen.StoreManagement.Core/Entity/BPA_DevicePushRecode.cs Parādīt failu

@@ -0,0 +1,26 @@


using BPA.KitChen.StoreManagement.Core.Entity.Base;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BPA.KitChen.StoreManagement.Core.Entity
{
[SugarTable("bpa_devicepushrecode")]
public class BPA_DevicePushRecode : IBaseGroupIdEntity
{
public string DeviceId { 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; }
}
}

+ 2
- 1
BPA.KitChen.StoreManagement/BPA.KitChen.StoreManagement.csproj Parādīt failu

@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
@@ -9,6 +9,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="BPA.Message" Version="1.0.105" />
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.18.1" />
</ItemGroup>



+ 33
- 1
BPA.KitChen.StoreManagement/Program.cs Parādīt failu

@@ -2,7 +2,10 @@
using BPA.KitChen.StoreManagement.Core.Common;
using BPA.KitChen.StoreManagement.Handlers;
using BPA.KitChen.StoreManagement.SqlSugar;
using BPA.MQTTClient;
using Furion;
using MQTTnet.Client.Connecting;
using MQTTnet.Client.Disconnecting;
using Newtonsoft.Json.Linq;
using SqlSugar;

@@ -11,7 +14,36 @@ var builder = WebApplication.CreateBuilder(args).Inject();
//JWT¼øȨ
builder.Services.AddJwt<JwtHandler>(enableGlobalAuthorize: true);


builder.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 =>
{

});
});

CosConfig.cosInfoOptions = new CosInfoOptions(App.Configuration["cos_config:AppId"],
App.Configuration["cos_config:Region"], App.Configuration["cos_config:Bucket"],


+ 8
- 1
BPA.KitChen.StoreManagement/appsettings.json Parādīt failu

@@ -13,7 +13,14 @@
"SecretId": "AKIDa4KQIvKUP6bw4ye6JI3a8lCPN7cswnV3",
"SecretKey": "ObaLtCH9nCNPFrFQO7ex2sTqyxlLgnfJ"
},

"dev1_brokerHostSettings": {
"Port": 1883,
"Host": "10.2.1.21"
},
"MqttClientSettings": {
"UserName": "emqx_u_block",
"Password": "emqx_p_admin8765490789"
},
//"SAAS_Manage": "http://10.2.1.26:21995/saasbase/",
"SAAS_Manage": "http://192.168.1.50:5006",



Notiek ielāde…
Atcelt
Saglabāt