上传配方文件时,增加上传字段属性功能
This commit is contained in:
parent
ae30c33f44
commit
3f24aacb1d
|
@ -75,6 +75,11 @@ public static class Topics
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public const string RemoteControl = $"down/{SN}/402/{Version}";
|
public const string RemoteControl = $"down/{SN}/402/{Version}";
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 上报配置字典数据
|
||||||
|
/// </summary>
|
||||||
|
public const string ReportConfigDictionary = $"up/{SN}/403/{Version}";
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 下发OTA包
|
/// 下发OTA包
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
|
@ -1,8 +1,6 @@
|
||||||
using MasstransferCommon.Atrributes;
|
using MasstransferCommon.Atrributes;
|
||||||
using MasstransferCommon.Events;
|
using MasstransferCommon.Events;
|
||||||
using MasstransferCommon.Model.Constant;
|
|
||||||
using MasstransferCommon.Utils;
|
using MasstransferCommon.Utils;
|
||||||
using MasstransferCommunicate.Mqtt.Client;
|
|
||||||
using MasstransferExporter.DataExporter.Model;
|
using MasstransferExporter.DataExporter.Model;
|
||||||
using Masuit.Tools;
|
using Masuit.Tools;
|
||||||
|
|
||||||
|
@ -26,13 +24,9 @@ public class ConfigService : Instant
|
||||||
/// 处理接收到的配置下发事件,根据配置类型执行不同的操作
|
/// 处理接收到的配置下发事件,根据配置类型执行不同的操作
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="topic"></param>
|
/// <param name="topic"></param>
|
||||||
/// <param name="payload"></param>
|
/// <param name="data"></param>
|
||||||
private static void HandleConfigIssuedEvent(string topic, string payload)
|
private static void HandleConfigIssuedEvent(string topic, ConfigData data)
|
||||||
{
|
{
|
||||||
if (payload.IsNullOrEmpty()) return;
|
|
||||||
|
|
||||||
var data = JsonUtil.FromJson<ConfigData>(payload);
|
|
||||||
|
|
||||||
if (data.IsNullOrEmpty()) return;
|
if (data.IsNullOrEmpty()) return;
|
||||||
|
|
||||||
var type = data.Type;
|
var type = data.Type;
|
||||||
|
|
|
@ -1,4 +1,7 @@
|
||||||
using MasstransferCommon.Model.Constant;
|
using System.ComponentModel;
|
||||||
|
using System.Reflection;
|
||||||
|
using MasstransferCommon.Model.Constant;
|
||||||
|
using MasstransferCommon.Model.Entity;
|
||||||
using MasstransferCommon.Utils;
|
using MasstransferCommon.Utils;
|
||||||
using MasstransferCommunicate.Mqtt.Client;
|
using MasstransferCommunicate.Mqtt.Client;
|
||||||
using MasstransferCore.Model.Entity;
|
using MasstransferCore.Model.Entity;
|
||||||
|
@ -249,6 +252,14 @@ public class FormulaService
|
||||||
{
|
{
|
||||||
var formulas = GetAllFormulas();
|
var formulas = GetAllFormulas();
|
||||||
|
|
||||||
|
var dto = formulas[0];
|
||||||
|
|
||||||
|
// 推送配方字段名称字典内容
|
||||||
|
var mapping = new Dictionary<string, object>();
|
||||||
|
GetFormulaFieldNameMapping(dto.GetType(), mapping);
|
||||||
|
|
||||||
|
await MessageQueueHelper.Publish(Topics.ReportConfigDictionary, mapping);
|
||||||
|
|
||||||
foreach (var formula in formulas)
|
foreach (var formula in formulas)
|
||||||
{
|
{
|
||||||
var formulaDto = GetFormulaById(formula.Id);
|
var formulaDto = GetFormulaById(formula.Id);
|
||||||
|
@ -268,4 +279,32 @@ public class FormulaService
|
||||||
Console.WriteLine($"定时上报配方数据失败: {e}");
|
Console.WriteLine($"定时上报配方数据失败: {e}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获取配方字段名称映射
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
private static void GetFormulaFieldNameMapping(Type type, IDictionary<string, object> mapping)
|
||||||
|
{
|
||||||
|
var fields = type.GetProperties();
|
||||||
|
foreach (var field in fields)
|
||||||
|
{
|
||||||
|
// 判定当前的属性是否为 Entity的子类
|
||||||
|
if (field.PropertyType.IsSubclassOf(typeof(Entity)))
|
||||||
|
{
|
||||||
|
var subMapping = new Dictionary<string, object>();
|
||||||
|
GetFormulaFieldNameMapping(field.PropertyType, subMapping);
|
||||||
|
mapping.Add(field.Name, subMapping);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var description = field.GetCustomAttribute<DescriptionAttribute>();
|
||||||
|
if (description != null)
|
||||||
|
{
|
||||||
|
mapping.Add(field.Name, description.Description);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -1,4 +1,5 @@
|
||||||
using MasstransferCore.Model.Entity;
|
using System.ComponentModel;
|
||||||
|
using MasstransferCore.Model.Entity;
|
||||||
|
|
||||||
namespace MasstransferExporter.DataExporter.Model;
|
namespace MasstransferExporter.DataExporter.Model;
|
||||||
|
|
||||||
|
@ -7,15 +8,15 @@ namespace MasstransferExporter.DataExporter.Model;
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class FormulaDTO
|
public class FormulaDTO
|
||||||
{
|
{
|
||||||
public string Id { get; set; }
|
[Description("配方id")] public string Id { get; set; }
|
||||||
|
|
||||||
public string Name { get; set; }
|
[Description("配方名称")] public string Name { get; set; }
|
||||||
|
|
||||||
public string Code { get; set; }
|
[Description("配方编号")] public string Code { get; set; }
|
||||||
|
|
||||||
public string Description { get; set; }
|
[Description("配方描述")] public string Description { get; set; }
|
||||||
|
|
||||||
public bool Selected { get; set; }
|
[Description("是否启用")] public bool Selected { get; set; }
|
||||||
|
|
||||||
public WorkBenchSetting? WorkBenchSetting { get; set; }
|
public WorkBenchSetting? WorkBenchSetting { get; set; }
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,6 @@
|
||||||
using MasstransferCommon.Atrributes;
|
using MasstransferCommon.Atrributes;
|
||||||
using MasstransferCommon.Events;
|
using MasstransferCommon.Events;
|
||||||
using MasstransferCommon.Model.Constant;
|
using MasstransferCommon.Model.Constant;
|
||||||
using MasstransferCommon.Utils;
|
|
||||||
using MasstransferCommunicate.Minio;
|
using MasstransferCommunicate.Minio;
|
||||||
using MasstransferCommunicate.Mqtt.Client;
|
using MasstransferCommunicate.Mqtt.Client;
|
||||||
using MasstransferExporter.DataExporter.Model;
|
using MasstransferExporter.DataExporter.Model;
|
||||||
|
@ -31,12 +30,8 @@ public class ImageService : Instant
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 处理图片查询请求
|
/// 处理图片查询请求
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private static async Task HandleImageQueryEvent(string topic, string payload)
|
private static async Task HandleImageQueryEvent(string topic, ImageQueryDTO queryDto)
|
||||||
{
|
{
|
||||||
if (payload == null) return;
|
|
||||||
|
|
||||||
var queryDto = JsonUtil.FromJson<ImageQueryDTO>(payload);
|
|
||||||
|
|
||||||
if (queryDto == null) return;
|
if (queryDto == null) return;
|
||||||
|
|
||||||
var batchNumber = queryDto.batchNumber;
|
var batchNumber = queryDto.batchNumber;
|
||||||
|
@ -130,14 +125,14 @@ public class ImageService : Instant
|
||||||
// 获取文件夹下所有文件的信息
|
// 获取文件夹下所有文件的信息
|
||||||
var fs = dir.GetFiles();
|
var fs = dir.GetFiles();
|
||||||
|
|
||||||
if (fs != null && fs.Length > 0)
|
if (fs.Length > 0)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
foreach (var file in fs)
|
foreach (var file in fs)
|
||||||
{
|
{
|
||||||
if (file.Name.EndsWith(".bmp") && !file.Name.Contains("_thumbnail"))
|
if (!file.Name.EndsWith(".bmp") || file.Name.Contains("_thumbnail")) continue;
|
||||||
{
|
|
||||||
// 判断是否已经存在缩略图,如果存在的话,则跳过生成过程
|
// 判断是否已经存在缩略图,如果存在的话,则跳过生成过程
|
||||||
var thumbnailFilePath = file.FullName.Replace(".bmp", "_thumbnail.bmp");
|
var thumbnailFilePath = file.FullName.Replace(".bmp", "_thumbnail.bmp");
|
||||||
if (!File.Exists(thumbnailFilePath))
|
if (!File.Exists(thumbnailFilePath))
|
||||||
|
@ -146,7 +141,6 @@ public class ImageService : Instant
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
Console.WriteLine(e);
|
Console.WriteLine(e);
|
||||||
|
|
|
@ -42,8 +42,8 @@ class Program
|
||||||
// 启动完成后,广播启动通知
|
// 启动完成后,广播启动通知
|
||||||
EventBus<bool>.Publish(EventType.StartUp, true);
|
EventBus<bool>.Publish(EventType.StartUp, true);
|
||||||
|
|
||||||
// DelayScheduler.Delay(async () => await FormulaService.FormulaDataExporter(),
|
DelayScheduler.Delay(async () => await FormulaService.FormulaDataExporter(),
|
||||||
// TimeSpan.FromSeconds(5));
|
TimeSpan.FromSeconds(5));
|
||||||
|
|
||||||
// 启动与主程序的通信
|
// 启动与主程序的通信
|
||||||
ProcessHelper.Init();
|
ProcessHelper.Init();
|
||||||
|
|
|
@ -8,7 +8,7 @@ using MQTTnet;
|
||||||
using MQTTnet.Client;
|
using MQTTnet.Client;
|
||||||
using MQTTnet.Protocol;
|
using MQTTnet.Protocol;
|
||||||
using Serilog;
|
using Serilog;
|
||||||
using MqttClient = MasstransferInfrastructure.Mqtt.Client.MqttClient;
|
using MqttClient = MasstransferCommunicate.Mqtt.Client.MqttClient;
|
||||||
|
|
||||||
namespace MasstransferCommunicate.Mqtt.Client;
|
namespace MasstransferCommunicate.Mqtt.Client;
|
||||||
|
|
||||||
|
|
|
@ -4,18 +4,17 @@ using MasstransferCommon.Utils;
|
||||||
using MasstransferCommunicate.Mqtt.Model;
|
using MasstransferCommunicate.Mqtt.Model;
|
||||||
using MasstransferInfrastructure.Mqtt.Model;
|
using MasstransferInfrastructure.Mqtt.Model;
|
||||||
using MasstransferSecurity.Utils;
|
using MasstransferSecurity.Utils;
|
||||||
using Masuit.Tools.Systems;
|
|
||||||
using MQTTnet;
|
using MQTTnet;
|
||||||
using MQTTnet.Client;
|
using MQTTnet.Client;
|
||||||
using MQTTnet.Protocol;
|
using MQTTnet.Protocol;
|
||||||
|
|
||||||
namespace MasstransferInfrastructure.Mqtt.Client;
|
namespace MasstransferCommunicate.Mqtt.Client;
|
||||||
|
|
||||||
class MqttClient
|
internal class MqttClient
|
||||||
{
|
{
|
||||||
private IMqttClient? _client;
|
private IMqttClient? _client;
|
||||||
|
|
||||||
public event EventHandler<MqttApplicationMessageReceivedEventArgs> MessageReceived;
|
public event EventHandler<MqttApplicationMessageReceivedEventArgs>? MessageReceived;
|
||||||
|
|
||||||
private static readonly DateTime Epoch = new DateTime(2024, 1, 1, 0, 0, 0, DateTimeKind.Utc);
|
private static readonly DateTime Epoch = new DateTime(2024, 1, 1, 0, 0, 0, DateTimeKind.Utc);
|
||||||
|
|
||||||
|
@ -30,11 +29,6 @@ class MqttClient
|
||||||
{
|
{
|
||||||
var clientId = DeviceInfoUtil.GenerateUniqueID();
|
var clientId = DeviceInfoUtil.GenerateUniqueID();
|
||||||
|
|
||||||
// var caCert = GetCertificate(options.CaCert);
|
|
||||||
// var clientCert = GetCertificate(options.ClientCert);
|
|
||||||
//
|
|
||||||
// var chain = new X509Certificate2Collection(new[] { caCert, clientCert });
|
|
||||||
|
|
||||||
return new MqttClientOptionsBuilder()
|
return new MqttClientOptionsBuilder()
|
||||||
.WithTcpServer(options.ServerAddress, options.Port)
|
.WithTcpServer(options.ServerAddress, options.Port)
|
||||||
// .WithCredentials(options.UserName, options.Password)
|
// .WithCredentials(options.UserName, options.Password)
|
||||||
|
@ -45,7 +39,6 @@ class MqttClient
|
||||||
{
|
{
|
||||||
o.UseTls(options.EnableTls);
|
o.UseTls(options.EnableTls);
|
||||||
o.WithSslProtocols(options.Protocols);
|
o.WithSslProtocols(options.Protocols);
|
||||||
// o.WithTrustChain(chain);
|
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
.Build();
|
.Build();
|
||||||
|
|
Loading…
Reference in New Issue