使用DataHash验证消息重复

This commit is contained in:
李鹏鹏 2024-12-20 17:12:42 +08:00
parent 10ca96e5c1
commit 510cde319f
9 changed files with 25 additions and 7 deletions

View File

@ -195,7 +195,7 @@ namespace Waste.Application
public int Len { get; set; } = 0;
/// <summary>
/// IMEI
/// IMEI/设备编号
/// </summary>
public string IMEI { get; set; } = string.Empty;
@ -337,6 +337,7 @@ namespace Waste.Application
public string ID6 { get; set; } = string.Empty;
public string ID7 { get; set; } = string.Empty;
public string ID8 { get; set; } = string.Empty;
public string DataHash { get; set; } = "";
}
/// <summary>

View File

@ -468,6 +468,9 @@ namespace Waste.Application
ID6 = myPackage.ID6,
ID7 = myPackage.ID7,
ID8 = myPackage.ID8,
CreatedTime = DateTime.Now,
DataHash = myPackage.DataHash
}).ExecuteCommandAsync();
}
await SendMessageToThird(new SendThirdMessageSubscribeS2SDto

View File

@ -308,7 +308,9 @@ namespace Waste.Application.SubscribeInfo
var services = scope.ServiceProvider;
var mresultrep = services.GetService<ISqlSugarRepository<W_MeasureResult>>();
//如果uuid不为空,并且以存在记录,则忽略
if (!myPackage.IsHeart && !myPackage.UUID.IsEmpty() && await mresultrep.AnyAsync(x => x.UUID == myPackage.UUID))
if (!myPackage.IsHeart && !myPackage.UUID.IsEmpty() && await mresultrep
.Where(x => x.CreatedTime > DateTime.Now.AddMinutes(-1) && x.DataHash == myPackage.DataHash)//1分钟内不能重复
.AnyAsync())
{
return;
}

View File

@ -1764,7 +1764,7 @@
</member>
<member name="P:Waste.Application.MyPackage.IMEI">
<summary>
IMEI
IMEI/设备编号
</summary>
</member>
<member name="P:Waste.Application.MyPackage.ICCID">

View File

@ -39,12 +39,11 @@ namespace Waste.Domain
[SugarColumn(ColumnDescription = "操作员", ColumnDataType = "nvarchar(100)")]
public string OpUser { get; set; }
/// <summary>
/// 唯一消息ID
/// 消息ID
/// </summary>
[SugarColumn(ColumnDescription = "唯一消息ID", ColumnDataType = "varchar(50)",IndexGroupNameList =new string[] { "index_uuid"})]
[SugarColumn(ColumnDescription = "消息ID", ColumnDataType = "varchar(50)",IndexGroupNameList =new string[] { "index_uuid"})]
public string UUID { get; set; }
/// <summary>
/// 设备出厂序列号/设备出厂编号
/// </summary>
@ -73,5 +72,7 @@ namespace Waste.Domain
public string ID6 { get; set; }
public string ID7 { get; set; }
public string ID8 { get; set; }
public DateTime? CreatedTime { get; set; }
public string DataHash { get; set; }
}
}

View File

@ -21,7 +21,7 @@ namespace Waste.SocketService
/// </summary>
public int Len { get; set; } = 0;
/// <summary>
/// IMEI
/// IMEI/设备编号
/// </summary>
public string IMEI { get; set; } = "";
/// <summary>
@ -146,5 +146,6 @@ namespace Waste.SocketService
public string ID6 { get; set; }
public string ID7 { get; set; }
public string ID8 { get; set; }
public string DataHash { get; set; } = "";
}
}

View File

@ -12,6 +12,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Furion.DataEncryption.Extensions;
namespace Waste.SocketService
{
@ -144,6 +145,7 @@ namespace Waste.SocketService
_logger.Information(msg);
if (package.Key == "A8")
{
package.DataHash = $"{package.Str}".ToMD5Encrypt();
await _capBus.PublishAsync("result.service.inserta84g", package);
if (!session.Channel.IsClosed)
{

View File

@ -37,6 +37,11 @@ namespace Waste.Web.Entry
new string('-', 50);//输出模板
///1.输出所有restrictedToMinimumLevelLogEventLevel类型
config
.Enrich.WithProperty("Application", typeof(Program).Assembly.GetName().Name)
.Enrich.WithProcessId()
.Enrich.WithProcessName()
.Enrich.WithMachineName()
.Enrich.WithEnvironmentUserName()
.WriteTo.Seq("http://localhost:5341/")
//.MinimumLevel.Debug() // 所有Sink的最小记录级别
//.MinimumLevel.Override("Microsoft", LogEventLevel.Fatal)

View File

@ -18,10 +18,13 @@
<ItemGroup>
<PackageReference Include="BuildBundlerMinifier" Version="3.2.449" />
<PackageReference Include="Serilog.Enrichers.Environment" Version="2.3.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Waste.Web.Core\Waste.Web.Core.csproj" />
<PackageReference Include="Serilog.Enrichers.Process" Version="2.0.2" />
</ItemGroup>
<ProjectExtensions><VisualStudio><UserProperties appsettings_1json__JsonSchema="" /></VisualStudio></ProjectExtensions>